blob: 617810f1a21e9bb8dcfc1dbff8577cff756dbd38 [file] [log] [blame]
Jesse Grossccb13522011-10-25 19:26:31 -07001/*
Andy Zhou03f0d912013-08-07 20:01:00 -07002 * Copyright (c) 2007-2013 Nicira, Inc.
Jesse Grossccb13522011-10-25 19:26:31 -07003 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA
17 */
18
19#include "flow.h"
20#include "datapath.h"
21#include <linux/uaccess.h>
22#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/if_ether.h>
25#include <linux/if_vlan.h>
26#include <net/llc_pdu.h>
27#include <linux/kernel.h>
28#include <linux/jhash.h>
29#include <linux/jiffies.h>
30#include <linux/llc.h>
31#include <linux/module.h>
32#include <linux/in.h>
33#include <linux/rcupdate.h>
34#include <linux/if_arp.h>
Jesse Grossccb13522011-10-25 19:26:31 -070035#include <linux/ip.h>
36#include <linux/ipv6.h>
Joe Stringera175a722013-08-22 12:30:48 -070037#include <linux/sctp.h>
Jesse Grossccb13522011-10-25 19:26:31 -070038#include <linux/tcp.h>
39#include <linux/udp.h>
40#include <linux/icmp.h>
41#include <linux/icmpv6.h>
42#include <linux/rculist.h>
43#include <net/ip.h>
Pravin B Shelar7d5437c2013-06-17 17:50:18 -070044#include <net/ip_tunnels.h>
Jesse Grossccb13522011-10-25 19:26:31 -070045#include <net/ipv6.h>
46#include <net/ndisc.h>
47
Pravin B Shelare6445712013-10-03 18:16:47 -070048u64 ovs_flow_used_time(unsigned long flow_jiffies)
Andy Zhou03f0d912013-08-07 20:01:00 -070049{
Pravin B Shelare6445712013-10-03 18:16:47 -070050 struct timespec cur_ts;
51 u64 cur_ms, idle_ms;
Andy Zhou03f0d912013-08-07 20:01:00 -070052
Pravin B Shelare6445712013-10-03 18:16:47 -070053 ktime_get_ts(&cur_ts);
54 idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
55 cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
56 cur_ts.tv_nsec / NSEC_PER_MSEC;
Andy Zhou03f0d912013-08-07 20:01:00 -070057
Pravin B Shelare6445712013-10-03 18:16:47 -070058 return cur_ms - idle_ms;
Andy Zhou03f0d912013-08-07 20:01:00 -070059}
60
Pravin B Shelare6445712013-10-03 18:16:47 -070061#define TCP_FLAGS_OFFSET 13
62#define TCP_FLAG_MASK 0x3f
Andy Zhou03f0d912013-08-07 20:01:00 -070063
Pravin B Shelare6445712013-10-03 18:16:47 -070064void ovs_flow_used(struct sw_flow *flow, struct sk_buff *skb)
Andy Zhou5828cd92013-08-27 13:02:21 -070065{
Pravin B Shelare6445712013-10-03 18:16:47 -070066 u8 tcp_flags = 0;
Andy Zhou5828cd92013-08-27 13:02:21 -070067
Pravin B Shelare6445712013-10-03 18:16:47 -070068 if ((flow->key.eth.type == htons(ETH_P_IP) ||
69 flow->key.eth.type == htons(ETH_P_IPV6)) &&
70 flow->key.ip.proto == IPPROTO_TCP &&
71 likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) {
72 u8 *tcp = (u8 *)tcp_hdr(skb);
73 tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK;
Andy Zhou03f0d912013-08-07 20:01:00 -070074 }
75
Pravin B Shelare6445712013-10-03 18:16:47 -070076 spin_lock(&flow->lock);
77 flow->used = jiffies;
78 flow->packet_count++;
79 flow->byte_count += skb->len;
80 flow->tcp_flags |= tcp_flags;
81 spin_unlock(&flow->lock);
Andy Zhou03f0d912013-08-07 20:01:00 -070082}
83
Jesse Grossccb13522011-10-25 19:26:31 -070084static int check_header(struct sk_buff *skb, int len)
85{
86 if (unlikely(skb->len < len))
87 return -EINVAL;
88 if (unlikely(!pskb_may_pull(skb, len)))
89 return -ENOMEM;
90 return 0;
91}
92
93static bool arphdr_ok(struct sk_buff *skb)
94{
95 return pskb_may_pull(skb, skb_network_offset(skb) +
96 sizeof(struct arp_eth_header));
97}
98
99static int check_iphdr(struct sk_buff *skb)
100{
101 unsigned int nh_ofs = skb_network_offset(skb);
102 unsigned int ip_len;
103 int err;
104
105 err = check_header(skb, nh_ofs + sizeof(struct iphdr));
106 if (unlikely(err))
107 return err;
108
109 ip_len = ip_hdrlen(skb);
110 if (unlikely(ip_len < sizeof(struct iphdr) ||
111 skb->len < nh_ofs + ip_len))
112 return -EINVAL;
113
114 skb_set_transport_header(skb, nh_ofs + ip_len);
115 return 0;
116}
117
118static bool tcphdr_ok(struct sk_buff *skb)
119{
120 int th_ofs = skb_transport_offset(skb);
121 int tcp_len;
122
123 if (unlikely(!pskb_may_pull(skb, th_ofs + sizeof(struct tcphdr))))
124 return false;
125
126 tcp_len = tcp_hdrlen(skb);
127 if (unlikely(tcp_len < sizeof(struct tcphdr) ||
128 skb->len < th_ofs + tcp_len))
129 return false;
130
131 return true;
132}
133
134static bool udphdr_ok(struct sk_buff *skb)
135{
136 return pskb_may_pull(skb, skb_transport_offset(skb) +
137 sizeof(struct udphdr));
138}
139
Joe Stringera175a722013-08-22 12:30:48 -0700140static bool sctphdr_ok(struct sk_buff *skb)
141{
142 return pskb_may_pull(skb, skb_transport_offset(skb) +
143 sizeof(struct sctphdr));
144}
145
Jesse Grossccb13522011-10-25 19:26:31 -0700146static bool icmphdr_ok(struct sk_buff *skb)
147{
148 return pskb_may_pull(skb, skb_transport_offset(skb) +
149 sizeof(struct icmphdr));
150}
151
Andy Zhou03f0d912013-08-07 20:01:00 -0700152static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key)
Jesse Grossccb13522011-10-25 19:26:31 -0700153{
154 unsigned int nh_ofs = skb_network_offset(skb);
155 unsigned int nh_len;
156 int payload_ofs;
157 struct ipv6hdr *nh;
158 uint8_t nexthdr;
159 __be16 frag_off;
160 int err;
161
Jesse Grossccb13522011-10-25 19:26:31 -0700162 err = check_header(skb, nh_ofs + sizeof(*nh));
163 if (unlikely(err))
164 return err;
165
166 nh = ipv6_hdr(skb);
167 nexthdr = nh->nexthdr;
168 payload_ofs = (u8 *)(nh + 1) - skb->data;
169
170 key->ip.proto = NEXTHDR_NONE;
171 key->ip.tos = ipv6_get_dsfield(nh);
172 key->ip.ttl = nh->hop_limit;
173 key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
174 key->ipv6.addr.src = nh->saddr;
175 key->ipv6.addr.dst = nh->daddr;
176
177 payload_ofs = ipv6_skip_exthdr(skb, payload_ofs, &nexthdr, &frag_off);
178 if (unlikely(payload_ofs < 0))
179 return -EINVAL;
180
181 if (frag_off) {
182 if (frag_off & htons(~0x7))
183 key->ip.frag = OVS_FRAG_TYPE_LATER;
184 else
185 key->ip.frag = OVS_FRAG_TYPE_FIRST;
186 }
187
188 nh_len = payload_ofs - nh_ofs;
189 skb_set_transport_header(skb, nh_ofs + nh_len);
190 key->ip.proto = nexthdr;
191 return nh_len;
192}
193
194static bool icmp6hdr_ok(struct sk_buff *skb)
195{
196 return pskb_may_pull(skb, skb_transport_offset(skb) +
197 sizeof(struct icmp6hdr));
198}
199
Jesse Grossccb13522011-10-25 19:26:31 -0700200static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
201{
202 struct qtag_prefix {
203 __be16 eth_type; /* ETH_P_8021Q */
204 __be16 tci;
205 };
206 struct qtag_prefix *qp;
207
208 if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
209 return 0;
210
211 if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
212 sizeof(__be16))))
213 return -ENOMEM;
214
215 qp = (struct qtag_prefix *) skb->data;
216 key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
217 __skb_pull(skb, sizeof(struct qtag_prefix));
218
219 return 0;
220}
221
222static __be16 parse_ethertype(struct sk_buff *skb)
223{
224 struct llc_snap_hdr {
225 u8 dsap; /* Always 0xAA */
226 u8 ssap; /* Always 0xAA */
227 u8 ctrl;
228 u8 oui[3];
229 __be16 ethertype;
230 };
231 struct llc_snap_hdr *llc;
232 __be16 proto;
233
234 proto = *(__be16 *) skb->data;
235 __skb_pull(skb, sizeof(__be16));
236
Simon Hormane5c5d222013-03-28 13:38:25 +0900237 if (ntohs(proto) >= ETH_P_802_3_MIN)
Jesse Grossccb13522011-10-25 19:26:31 -0700238 return proto;
239
240 if (skb->len < sizeof(struct llc_snap_hdr))
241 return htons(ETH_P_802_2);
242
243 if (unlikely(!pskb_may_pull(skb, sizeof(struct llc_snap_hdr))))
244 return htons(0);
245
246 llc = (struct llc_snap_hdr *) skb->data;
247 if (llc->dsap != LLC_SAP_SNAP ||
248 llc->ssap != LLC_SAP_SNAP ||
249 (llc->oui[0] | llc->oui[1] | llc->oui[2]) != 0)
250 return htons(ETH_P_802_2);
251
252 __skb_pull(skb, sizeof(struct llc_snap_hdr));
Rich Lane17b682a2013-02-19 11:10:30 -0800253
Simon Hormane5c5d222013-03-28 13:38:25 +0900254 if (ntohs(llc->ethertype) >= ETH_P_802_3_MIN)
Rich Lane17b682a2013-02-19 11:10:30 -0800255 return llc->ethertype;
256
257 return htons(ETH_P_802_2);
Jesse Grossccb13522011-10-25 19:26:31 -0700258}
259
260static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
Andy Zhou03f0d912013-08-07 20:01:00 -0700261 int nh_len)
Jesse Grossccb13522011-10-25 19:26:31 -0700262{
263 struct icmp6hdr *icmp = icmp6_hdr(skb);
Jesse Grossccb13522011-10-25 19:26:31 -0700264
265 /* The ICMPv6 type and code fields use the 16-bit transport port
266 * fields, so we need to store them in 16-bit network byte order.
267 */
268 key->ipv6.tp.src = htons(icmp->icmp6_type);
269 key->ipv6.tp.dst = htons(icmp->icmp6_code);
Jesse Grossccb13522011-10-25 19:26:31 -0700270
271 if (icmp->icmp6_code == 0 &&
272 (icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION ||
273 icmp->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT)) {
274 int icmp_len = skb->len - skb_transport_offset(skb);
275 struct nd_msg *nd;
276 int offset;
277
Jesse Grossccb13522011-10-25 19:26:31 -0700278 /* In order to process neighbor discovery options, we need the
279 * entire packet.
280 */
281 if (unlikely(icmp_len < sizeof(*nd)))
Andy Zhou03f0d912013-08-07 20:01:00 -0700282 return 0;
283
284 if (unlikely(skb_linearize(skb)))
285 return -ENOMEM;
Jesse Grossccb13522011-10-25 19:26:31 -0700286
287 nd = (struct nd_msg *)skb_transport_header(skb);
288 key->ipv6.nd.target = nd->target;
Jesse Grossccb13522011-10-25 19:26:31 -0700289
290 icmp_len -= sizeof(*nd);
291 offset = 0;
292 while (icmp_len >= 8) {
293 struct nd_opt_hdr *nd_opt =
294 (struct nd_opt_hdr *)(nd->opt + offset);
295 int opt_len = nd_opt->nd_opt_len * 8;
296
297 if (unlikely(!opt_len || opt_len > icmp_len))
Andy Zhou03f0d912013-08-07 20:01:00 -0700298 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700299
300 /* Store the link layer address if the appropriate
301 * option is provided. It is considered an error if
302 * the same link layer option is specified twice.
303 */
304 if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
305 && opt_len == 8) {
306 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
307 goto invalid;
308 memcpy(key->ipv6.nd.sll,
309 &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
310 } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
311 && opt_len == 8) {
312 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
313 goto invalid;
314 memcpy(key->ipv6.nd.tll,
315 &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
316 }
317
318 icmp_len -= opt_len;
319 offset += opt_len;
320 }
321 }
322
Andy Zhou03f0d912013-08-07 20:01:00 -0700323 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700324
325invalid:
326 memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
327 memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
328 memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
329
Andy Zhou03f0d912013-08-07 20:01:00 -0700330 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700331}
332
333/**
334 * ovs_flow_extract - extracts a flow key from an Ethernet frame.
335 * @skb: sk_buff that contains the frame, with skb->data pointing to the
336 * Ethernet header
337 * @in_port: port number on which @skb was received.
338 * @key: output flow key
Jesse Grossccb13522011-10-25 19:26:31 -0700339 *
340 * The caller must ensure that skb->len >= ETH_HLEN.
341 *
342 * Returns 0 if successful, otherwise a negative errno value.
343 *
344 * Initializes @skb header pointers as follows:
345 *
346 * - skb->mac_header: the Ethernet header.
347 *
348 * - skb->network_header: just past the Ethernet header, or just past the
349 * VLAN header, to the first byte of the Ethernet payload.
350 *
Lorand Jakab34d94f22013-06-03 10:01:14 -0700351 * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6
Jesse Grossccb13522011-10-25 19:26:31 -0700352 * on output, then just past the IP header, if one is present and
353 * of a correct length, otherwise the same as skb->network_header.
Lorand Jakab34d94f22013-06-03 10:01:14 -0700354 * For other key->eth.type values it is left untouched.
Jesse Grossccb13522011-10-25 19:26:31 -0700355 */
Andy Zhou03f0d912013-08-07 20:01:00 -0700356int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key)
Jesse Grossccb13522011-10-25 19:26:31 -0700357{
Andy Zhou03f0d912013-08-07 20:01:00 -0700358 int error;
Jesse Grossccb13522011-10-25 19:26:31 -0700359 struct ethhdr *eth;
360
361 memset(key, 0, sizeof(*key));
362
363 key->phy.priority = skb->priority;
Pravin B Shelar7d5437c2013-06-17 17:50:18 -0700364 if (OVS_CB(skb)->tun_key)
365 memcpy(&key->tun_key, OVS_CB(skb)->tun_key, sizeof(key->tun_key));
Jesse Grossccb13522011-10-25 19:26:31 -0700366 key->phy.in_port = in_port;
Ansis Atteka39c7caeb2012-11-26 11:24:11 -0800367 key->phy.skb_mark = skb->mark;
Jesse Grossccb13522011-10-25 19:26:31 -0700368
369 skb_reset_mac_header(skb);
370
371 /* Link layer. We are guaranteed to have at least the 14 byte Ethernet
372 * header in the linear data area.
373 */
374 eth = eth_hdr(skb);
375 memcpy(key->eth.src, eth->h_source, ETH_ALEN);
376 memcpy(key->eth.dst, eth->h_dest, ETH_ALEN);
377
378 __skb_pull(skb, 2 * ETH_ALEN);
Pravin B Shelarb34df5e2013-06-13 11:11:44 -0700379 /* We are going to push all headers that we pull, so no need to
380 * update skb->csum here.
381 */
Jesse Grossccb13522011-10-25 19:26:31 -0700382
383 if (vlan_tx_tag_present(skb))
384 key->eth.tci = htons(skb->vlan_tci);
385 else if (eth->h_proto == htons(ETH_P_8021Q))
386 if (unlikely(parse_vlan(skb, key)))
387 return -ENOMEM;
388
389 key->eth.type = parse_ethertype(skb);
390 if (unlikely(key->eth.type == htons(0)))
391 return -ENOMEM;
392
393 skb_reset_network_header(skb);
394 __skb_push(skb, skb->data - skb_mac_header(skb));
395
396 /* Network layer. */
397 if (key->eth.type == htons(ETH_P_IP)) {
398 struct iphdr *nh;
399 __be16 offset;
400
Jesse Grossccb13522011-10-25 19:26:31 -0700401 error = check_iphdr(skb);
402 if (unlikely(error)) {
403 if (error == -EINVAL) {
404 skb->transport_header = skb->network_header;
405 error = 0;
406 }
Andy Zhou03f0d912013-08-07 20:01:00 -0700407 return error;
Jesse Grossccb13522011-10-25 19:26:31 -0700408 }
409
410 nh = ip_hdr(skb);
411 key->ipv4.addr.src = nh->saddr;
412 key->ipv4.addr.dst = nh->daddr;
413
414 key->ip.proto = nh->protocol;
415 key->ip.tos = nh->tos;
416 key->ip.ttl = nh->ttl;
417
418 offset = nh->frag_off & htons(IP_OFFSET);
419 if (offset) {
420 key->ip.frag = OVS_FRAG_TYPE_LATER;
Andy Zhou03f0d912013-08-07 20:01:00 -0700421 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700422 }
423 if (nh->frag_off & htons(IP_MF) ||
424 skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
425 key->ip.frag = OVS_FRAG_TYPE_FIRST;
426
427 /* Transport layer. */
428 if (key->ip.proto == IPPROTO_TCP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700429 if (tcphdr_ok(skb)) {
430 struct tcphdr *tcp = tcp_hdr(skb);
431 key->ipv4.tp.src = tcp->source;
432 key->ipv4.tp.dst = tcp->dest;
433 }
434 } else if (key->ip.proto == IPPROTO_UDP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700435 if (udphdr_ok(skb)) {
436 struct udphdr *udp = udp_hdr(skb);
437 key->ipv4.tp.src = udp->source;
438 key->ipv4.tp.dst = udp->dest;
439 }
Joe Stringera175a722013-08-22 12:30:48 -0700440 } else if (key->ip.proto == IPPROTO_SCTP) {
441 if (sctphdr_ok(skb)) {
442 struct sctphdr *sctp = sctp_hdr(skb);
443 key->ipv4.tp.src = sctp->source;
444 key->ipv4.tp.dst = sctp->dest;
445 }
Jesse Grossccb13522011-10-25 19:26:31 -0700446 } else if (key->ip.proto == IPPROTO_ICMP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700447 if (icmphdr_ok(skb)) {
448 struct icmphdr *icmp = icmp_hdr(skb);
449 /* The ICMP type and code fields use the 16-bit
450 * transport port fields, so we need to store
451 * them in 16-bit network byte order. */
452 key->ipv4.tp.src = htons(icmp->type);
453 key->ipv4.tp.dst = htons(icmp->code);
454 }
455 }
456
Mehak Mahajanc0618532012-11-02 14:14:31 -0700457 } else if ((key->eth.type == htons(ETH_P_ARP) ||
458 key->eth.type == htons(ETH_P_RARP)) && arphdr_ok(skb)) {
Jesse Grossccb13522011-10-25 19:26:31 -0700459 struct arp_eth_header *arp;
460
461 arp = (struct arp_eth_header *)skb_network_header(skb);
462
463 if (arp->ar_hrd == htons(ARPHRD_ETHER)
464 && arp->ar_pro == htons(ETH_P_IP)
465 && arp->ar_hln == ETH_ALEN
466 && arp->ar_pln == 4) {
467
468 /* We only match on the lower 8 bits of the opcode. */
469 if (ntohs(arp->ar_op) <= 0xff)
470 key->ip.proto = ntohs(arp->ar_op);
Mehak Mahajand04d3822012-10-30 15:50:28 -0700471 memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
472 memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
473 memcpy(key->ipv4.arp.sha, arp->ar_sha, ETH_ALEN);
474 memcpy(key->ipv4.arp.tha, arp->ar_tha, ETH_ALEN);
Jesse Grossccb13522011-10-25 19:26:31 -0700475 }
476 } else if (key->eth.type == htons(ETH_P_IPV6)) {
477 int nh_len; /* IPv6 Header + Extensions */
478
Andy Zhou03f0d912013-08-07 20:01:00 -0700479 nh_len = parse_ipv6hdr(skb, key);
Jesse Grossccb13522011-10-25 19:26:31 -0700480 if (unlikely(nh_len < 0)) {
Andy Zhou03f0d912013-08-07 20:01:00 -0700481 if (nh_len == -EINVAL) {
Jesse Grossccb13522011-10-25 19:26:31 -0700482 skb->transport_header = skb->network_header;
Andy Zhou03f0d912013-08-07 20:01:00 -0700483 error = 0;
484 } else {
Jesse Grossccb13522011-10-25 19:26:31 -0700485 error = nh_len;
Andy Zhou03f0d912013-08-07 20:01:00 -0700486 }
487 return error;
Jesse Grossccb13522011-10-25 19:26:31 -0700488 }
489
490 if (key->ip.frag == OVS_FRAG_TYPE_LATER)
Andy Zhou03f0d912013-08-07 20:01:00 -0700491 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700492 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
493 key->ip.frag = OVS_FRAG_TYPE_FIRST;
494
495 /* Transport layer. */
496 if (key->ip.proto == NEXTHDR_TCP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700497 if (tcphdr_ok(skb)) {
498 struct tcphdr *tcp = tcp_hdr(skb);
499 key->ipv6.tp.src = tcp->source;
500 key->ipv6.tp.dst = tcp->dest;
501 }
502 } else if (key->ip.proto == NEXTHDR_UDP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700503 if (udphdr_ok(skb)) {
504 struct udphdr *udp = udp_hdr(skb);
505 key->ipv6.tp.src = udp->source;
506 key->ipv6.tp.dst = udp->dest;
507 }
Joe Stringera175a722013-08-22 12:30:48 -0700508 } else if (key->ip.proto == NEXTHDR_SCTP) {
509 if (sctphdr_ok(skb)) {
510 struct sctphdr *sctp = sctp_hdr(skb);
511 key->ipv6.tp.src = sctp->source;
512 key->ipv6.tp.dst = sctp->dest;
513 }
Jesse Grossccb13522011-10-25 19:26:31 -0700514 } else if (key->ip.proto == NEXTHDR_ICMP) {
Jesse Grossccb13522011-10-25 19:26:31 -0700515 if (icmp6hdr_ok(skb)) {
Andy Zhou03f0d912013-08-07 20:01:00 -0700516 error = parse_icmpv6(skb, key, nh_len);
517 if (error)
518 return error;
Jesse Grossccb13522011-10-25 19:26:31 -0700519 }
520 }
521 }
522
Andy Zhou03f0d912013-08-07 20:01:00 -0700523 return 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700524}