flow.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * Copyright (c) 2007-2013 Nicira, Inc.
  3. *
  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. #include "flow.h"
  19. #include "datapath.h"
  20. #include <linux/uaccess.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/if_ether.h>
  24. #include <linux/if_vlan.h>
  25. #include <net/llc_pdu.h>
  26. #include <linux/kernel.h>
  27. #include <linux/jhash.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/llc.h>
  30. #include <linux/module.h>
  31. #include <linux/in.h>
  32. #include <linux/rcupdate.h>
  33. #include <linux/if_arp.h>
  34. #include <linux/ip.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/sctp.h>
  37. #include <linux/smp.h>
  38. #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>
  44. #include <net/ip_tunnels.h>
  45. #include <net/ipv6.h>
  46. #include <net/ndisc.h>
  47. u64 ovs_flow_used_time(unsigned long flow_jiffies)
  48. {
  49. struct timespec cur_ts;
  50. u64 cur_ms, idle_ms;
  51. ktime_get_ts(&cur_ts);
  52. idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
  53. cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
  54. cur_ts.tv_nsec / NSEC_PER_MSEC;
  55. return cur_ms - idle_ms;
  56. }
  57. #define TCP_FLAGS_BE16(tp) (*(__be16 *)&tcp_flag_word(tp) & htons(0x0FFF))
  58. void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
  59. {
  60. struct flow_stats *stats;
  61. __be16 tcp_flags = 0;
  62. int node = numa_node_id();
  63. stats = rcu_dereference(flow->stats[node]);
  64. if ((flow->key.eth.type == htons(ETH_P_IP) ||
  65. flow->key.eth.type == htons(ETH_P_IPV6)) &&
  66. flow->key.ip.frag != OVS_FRAG_TYPE_LATER &&
  67. flow->key.ip.proto == IPPROTO_TCP &&
  68. likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) {
  69. tcp_flags = TCP_FLAGS_BE16(tcp_hdr(skb));
  70. }
  71. /* Check if already have node-specific stats. */
  72. if (likely(stats)) {
  73. spin_lock(&stats->lock);
  74. /* Mark if we write on the pre-allocated stats. */
  75. if (node == 0 && unlikely(flow->stats_last_writer != node))
  76. flow->stats_last_writer = node;
  77. } else {
  78. stats = rcu_dereference(flow->stats[0]); /* Pre-allocated. */
  79. spin_lock(&stats->lock);
  80. /* If the current NUMA-node is the only writer on the
  81. * pre-allocated stats keep using them.
  82. */
  83. if (unlikely(flow->stats_last_writer != node)) {
  84. /* A previous locker may have already allocated the
  85. * stats, so we need to check again. If node-specific
  86. * stats were already allocated, we update the pre-
  87. * allocated stats as we have already locked them.
  88. */
  89. if (likely(flow->stats_last_writer != NUMA_NO_NODE)
  90. && likely(!rcu_dereference(flow->stats[node]))) {
  91. /* Try to allocate node-specific stats. */
  92. struct flow_stats *new_stats;
  93. new_stats =
  94. kmem_cache_alloc_node(flow_stats_cache,
  95. GFP_THISNODE |
  96. __GFP_NOMEMALLOC,
  97. node);
  98. if (likely(new_stats)) {
  99. new_stats->used = jiffies;
  100. new_stats->packet_count = 1;
  101. new_stats->byte_count = skb->len;
  102. new_stats->tcp_flags = tcp_flags;
  103. spin_lock_init(&new_stats->lock);
  104. rcu_assign_pointer(flow->stats[node],
  105. new_stats);
  106. goto unlock;
  107. }
  108. }
  109. flow->stats_last_writer = node;
  110. }
  111. }
  112. stats->used = jiffies;
  113. stats->packet_count++;
  114. stats->byte_count += skb->len;
  115. stats->tcp_flags |= tcp_flags;
  116. unlock:
  117. spin_unlock(&stats->lock);
  118. }
  119. void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
  120. unsigned long *used, __be16 *tcp_flags)
  121. {
  122. int node;
  123. *used = 0;
  124. *tcp_flags = 0;
  125. memset(ovs_stats, 0, sizeof(*ovs_stats));
  126. for_each_node(node) {
  127. struct flow_stats *stats = rcu_dereference(flow->stats[node]);
  128. if (stats) {
  129. /* Local CPU may write on non-local stats, so we must
  130. * block bottom-halves here.
  131. */
  132. spin_lock_bh(&stats->lock);
  133. if (!*used || time_after(stats->used, *used))
  134. *used = stats->used;
  135. *tcp_flags |= stats->tcp_flags;
  136. ovs_stats->n_packets += stats->packet_count;
  137. ovs_stats->n_bytes += stats->byte_count;
  138. spin_unlock_bh(&stats->lock);
  139. }
  140. }
  141. }
  142. void ovs_flow_stats_clear(struct sw_flow *flow)
  143. {
  144. int node;
  145. for_each_node(node) {
  146. struct flow_stats *stats = rcu_dereference(flow->stats[node]);
  147. if (stats) {
  148. spin_lock_bh(&stats->lock);
  149. stats->used = 0;
  150. stats->packet_count = 0;
  151. stats->byte_count = 0;
  152. stats->tcp_flags = 0;
  153. spin_unlock_bh(&stats->lock);
  154. }
  155. }
  156. }
  157. static int check_header(struct sk_buff *skb, int len)
  158. {
  159. if (unlikely(skb->len < len))
  160. return -EINVAL;
  161. if (unlikely(!pskb_may_pull(skb, len)))
  162. return -ENOMEM;
  163. return 0;
  164. }
  165. static bool arphdr_ok(struct sk_buff *skb)
  166. {
  167. return pskb_may_pull(skb, skb_network_offset(skb) +
  168. sizeof(struct arp_eth_header));
  169. }
  170. static int check_iphdr(struct sk_buff *skb)
  171. {
  172. unsigned int nh_ofs = skb_network_offset(skb);
  173. unsigned int ip_len;
  174. int err;
  175. err = check_header(skb, nh_ofs + sizeof(struct iphdr));
  176. if (unlikely(err))
  177. return err;
  178. ip_len = ip_hdrlen(skb);
  179. if (unlikely(ip_len < sizeof(struct iphdr) ||
  180. skb->len < nh_ofs + ip_len))
  181. return -EINVAL;
  182. skb_set_transport_header(skb, nh_ofs + ip_len);
  183. return 0;
  184. }
  185. static bool tcphdr_ok(struct sk_buff *skb)
  186. {
  187. int th_ofs = skb_transport_offset(skb);
  188. int tcp_len;
  189. if (unlikely(!pskb_may_pull(skb, th_ofs + sizeof(struct tcphdr))))
  190. return false;
  191. tcp_len = tcp_hdrlen(skb);
  192. if (unlikely(tcp_len < sizeof(struct tcphdr) ||
  193. skb->len < th_ofs + tcp_len))
  194. return false;
  195. return true;
  196. }
  197. static bool udphdr_ok(struct sk_buff *skb)
  198. {
  199. return pskb_may_pull(skb, skb_transport_offset(skb) +
  200. sizeof(struct udphdr));
  201. }
  202. static bool sctphdr_ok(struct sk_buff *skb)
  203. {
  204. return pskb_may_pull(skb, skb_transport_offset(skb) +
  205. sizeof(struct sctphdr));
  206. }
  207. static bool icmphdr_ok(struct sk_buff *skb)
  208. {
  209. return pskb_may_pull(skb, skb_transport_offset(skb) +
  210. sizeof(struct icmphdr));
  211. }
  212. static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key)
  213. {
  214. unsigned int nh_ofs = skb_network_offset(skb);
  215. unsigned int nh_len;
  216. int payload_ofs;
  217. struct ipv6hdr *nh;
  218. uint8_t nexthdr;
  219. __be16 frag_off;
  220. int err;
  221. err = check_header(skb, nh_ofs + sizeof(*nh));
  222. if (unlikely(err))
  223. return err;
  224. nh = ipv6_hdr(skb);
  225. nexthdr = nh->nexthdr;
  226. payload_ofs = (u8 *)(nh + 1) - skb->data;
  227. key->ip.proto = NEXTHDR_NONE;
  228. key->ip.tos = ipv6_get_dsfield(nh);
  229. key->ip.ttl = nh->hop_limit;
  230. key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
  231. key->ipv6.addr.src = nh->saddr;
  232. key->ipv6.addr.dst = nh->daddr;
  233. payload_ofs = ipv6_skip_exthdr(skb, payload_ofs, &nexthdr, &frag_off);
  234. if (unlikely(payload_ofs < 0))
  235. return -EINVAL;
  236. if (frag_off) {
  237. if (frag_off & htons(~0x7))
  238. key->ip.frag = OVS_FRAG_TYPE_LATER;
  239. else
  240. key->ip.frag = OVS_FRAG_TYPE_FIRST;
  241. }
  242. nh_len = payload_ofs - nh_ofs;
  243. skb_set_transport_header(skb, nh_ofs + nh_len);
  244. key->ip.proto = nexthdr;
  245. return nh_len;
  246. }
  247. static bool icmp6hdr_ok(struct sk_buff *skb)
  248. {
  249. return pskb_may_pull(skb, skb_transport_offset(skb) +
  250. sizeof(struct icmp6hdr));
  251. }
  252. static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
  253. {
  254. struct qtag_prefix {
  255. __be16 eth_type; /* ETH_P_8021Q */
  256. __be16 tci;
  257. };
  258. struct qtag_prefix *qp;
  259. if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
  260. return 0;
  261. if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
  262. sizeof(__be16))))
  263. return -ENOMEM;
  264. qp = (struct qtag_prefix *) skb->data;
  265. key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
  266. __skb_pull(skb, sizeof(struct qtag_prefix));
  267. return 0;
  268. }
  269. static __be16 parse_ethertype(struct sk_buff *skb)
  270. {
  271. struct llc_snap_hdr {
  272. u8 dsap; /* Always 0xAA */
  273. u8 ssap; /* Always 0xAA */
  274. u8 ctrl;
  275. u8 oui[3];
  276. __be16 ethertype;
  277. };
  278. struct llc_snap_hdr *llc;
  279. __be16 proto;
  280. proto = *(__be16 *) skb->data;
  281. __skb_pull(skb, sizeof(__be16));
  282. if (ntohs(proto) >= ETH_P_802_3_MIN)
  283. return proto;
  284. if (skb->len < sizeof(struct llc_snap_hdr))
  285. return htons(ETH_P_802_2);
  286. if (unlikely(!pskb_may_pull(skb, sizeof(struct llc_snap_hdr))))
  287. return htons(0);
  288. llc = (struct llc_snap_hdr *) skb->data;
  289. if (llc->dsap != LLC_SAP_SNAP ||
  290. llc->ssap != LLC_SAP_SNAP ||
  291. (llc->oui[0] | llc->oui[1] | llc->oui[2]) != 0)
  292. return htons(ETH_P_802_2);
  293. __skb_pull(skb, sizeof(struct llc_snap_hdr));
  294. if (ntohs(llc->ethertype) >= ETH_P_802_3_MIN)
  295. return llc->ethertype;
  296. return htons(ETH_P_802_2);
  297. }
  298. static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
  299. int nh_len)
  300. {
  301. struct icmp6hdr *icmp = icmp6_hdr(skb);
  302. /* The ICMPv6 type and code fields use the 16-bit transport port
  303. * fields, so we need to store them in 16-bit network byte order.
  304. */
  305. key->ipv6.tp.src = htons(icmp->icmp6_type);
  306. key->ipv6.tp.dst = htons(icmp->icmp6_code);
  307. if (icmp->icmp6_code == 0 &&
  308. (icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION ||
  309. icmp->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT)) {
  310. int icmp_len = skb->len - skb_transport_offset(skb);
  311. struct nd_msg *nd;
  312. int offset;
  313. /* In order to process neighbor discovery options, we need the
  314. * entire packet.
  315. */
  316. if (unlikely(icmp_len < sizeof(*nd)))
  317. return 0;
  318. if (unlikely(skb_linearize(skb)))
  319. return -ENOMEM;
  320. nd = (struct nd_msg *)skb_transport_header(skb);
  321. key->ipv6.nd.target = nd->target;
  322. icmp_len -= sizeof(*nd);
  323. offset = 0;
  324. while (icmp_len >= 8) {
  325. struct nd_opt_hdr *nd_opt =
  326. (struct nd_opt_hdr *)(nd->opt + offset);
  327. int opt_len = nd_opt->nd_opt_len * 8;
  328. if (unlikely(!opt_len || opt_len > icmp_len))
  329. return 0;
  330. /* Store the link layer address if the appropriate
  331. * option is provided. It is considered an error if
  332. * the same link layer option is specified twice.
  333. */
  334. if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
  335. && opt_len == 8) {
  336. if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
  337. goto invalid;
  338. ether_addr_copy(key->ipv6.nd.sll,
  339. &nd->opt[offset+sizeof(*nd_opt)]);
  340. } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
  341. && opt_len == 8) {
  342. if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
  343. goto invalid;
  344. ether_addr_copy(key->ipv6.nd.tll,
  345. &nd->opt[offset+sizeof(*nd_opt)]);
  346. }
  347. icmp_len -= opt_len;
  348. offset += opt_len;
  349. }
  350. }
  351. return 0;
  352. invalid:
  353. memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
  354. memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
  355. memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
  356. return 0;
  357. }
  358. /**
  359. * ovs_flow_extract - extracts a flow key from an Ethernet frame.
  360. * @skb: sk_buff that contains the frame, with skb->data pointing to the
  361. * Ethernet header
  362. * @in_port: port number on which @skb was received.
  363. * @key: output flow key
  364. *
  365. * The caller must ensure that skb->len >= ETH_HLEN.
  366. *
  367. * Returns 0 if successful, otherwise a negative errno value.
  368. *
  369. * Initializes @skb header pointers as follows:
  370. *
  371. * - skb->mac_header: the Ethernet header.
  372. *
  373. * - skb->network_header: just past the Ethernet header, or just past the
  374. * VLAN header, to the first byte of the Ethernet payload.
  375. *
  376. * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6
  377. * on output, then just past the IP header, if one is present and
  378. * of a correct length, otherwise the same as skb->network_header.
  379. * For other key->eth.type values it is left untouched.
  380. */
  381. int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key)
  382. {
  383. int error;
  384. struct ethhdr *eth;
  385. memset(key, 0, sizeof(*key));
  386. key->phy.priority = skb->priority;
  387. if (OVS_CB(skb)->tun_key)
  388. memcpy(&key->tun_key, OVS_CB(skb)->tun_key, sizeof(key->tun_key));
  389. key->phy.in_port = in_port;
  390. key->phy.skb_mark = skb->mark;
  391. skb_reset_mac_header(skb);
  392. /* Link layer. We are guaranteed to have at least the 14 byte Ethernet
  393. * header in the linear data area.
  394. */
  395. eth = eth_hdr(skb);
  396. ether_addr_copy(key->eth.src, eth->h_source);
  397. ether_addr_copy(key->eth.dst, eth->h_dest);
  398. __skb_pull(skb, 2 * ETH_ALEN);
  399. /* We are going to push all headers that we pull, so no need to
  400. * update skb->csum here.
  401. */
  402. if (vlan_tx_tag_present(skb))
  403. key->eth.tci = htons(skb->vlan_tci);
  404. else if (eth->h_proto == htons(ETH_P_8021Q))
  405. if (unlikely(parse_vlan(skb, key)))
  406. return -ENOMEM;
  407. key->eth.type = parse_ethertype(skb);
  408. if (unlikely(key->eth.type == htons(0)))
  409. return -ENOMEM;
  410. skb_reset_network_header(skb);
  411. __skb_push(skb, skb->data - skb_mac_header(skb));
  412. /* Network layer. */
  413. if (key->eth.type == htons(ETH_P_IP)) {
  414. struct iphdr *nh;
  415. __be16 offset;
  416. error = check_iphdr(skb);
  417. if (unlikely(error)) {
  418. if (error == -EINVAL) {
  419. skb->transport_header = skb->network_header;
  420. error = 0;
  421. }
  422. return error;
  423. }
  424. nh = ip_hdr(skb);
  425. key->ipv4.addr.src = nh->saddr;
  426. key->ipv4.addr.dst = nh->daddr;
  427. key->ip.proto = nh->protocol;
  428. key->ip.tos = nh->tos;
  429. key->ip.ttl = nh->ttl;
  430. offset = nh->frag_off & htons(IP_OFFSET);
  431. if (offset) {
  432. key->ip.frag = OVS_FRAG_TYPE_LATER;
  433. return 0;
  434. }
  435. if (nh->frag_off & htons(IP_MF) ||
  436. skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  437. key->ip.frag = OVS_FRAG_TYPE_FIRST;
  438. /* Transport layer. */
  439. if (key->ip.proto == IPPROTO_TCP) {
  440. if (tcphdr_ok(skb)) {
  441. struct tcphdr *tcp = tcp_hdr(skb);
  442. key->ipv4.tp.src = tcp->source;
  443. key->ipv4.tp.dst = tcp->dest;
  444. key->ipv4.tp.flags = TCP_FLAGS_BE16(tcp);
  445. }
  446. } else if (key->ip.proto == IPPROTO_UDP) {
  447. if (udphdr_ok(skb)) {
  448. struct udphdr *udp = udp_hdr(skb);
  449. key->ipv4.tp.src = udp->source;
  450. key->ipv4.tp.dst = udp->dest;
  451. }
  452. } else if (key->ip.proto == IPPROTO_SCTP) {
  453. if (sctphdr_ok(skb)) {
  454. struct sctphdr *sctp = sctp_hdr(skb);
  455. key->ipv4.tp.src = sctp->source;
  456. key->ipv4.tp.dst = sctp->dest;
  457. }
  458. } else if (key->ip.proto == IPPROTO_ICMP) {
  459. if (icmphdr_ok(skb)) {
  460. struct icmphdr *icmp = icmp_hdr(skb);
  461. /* The ICMP type and code fields use the 16-bit
  462. * transport port fields, so we need to store
  463. * them in 16-bit network byte order. */
  464. key->ipv4.tp.src = htons(icmp->type);
  465. key->ipv4.tp.dst = htons(icmp->code);
  466. }
  467. }
  468. } else if ((key->eth.type == htons(ETH_P_ARP) ||
  469. key->eth.type == htons(ETH_P_RARP)) && arphdr_ok(skb)) {
  470. struct arp_eth_header *arp;
  471. arp = (struct arp_eth_header *)skb_network_header(skb);
  472. if (arp->ar_hrd == htons(ARPHRD_ETHER)
  473. && arp->ar_pro == htons(ETH_P_IP)
  474. && arp->ar_hln == ETH_ALEN
  475. && arp->ar_pln == 4) {
  476. /* We only match on the lower 8 bits of the opcode. */
  477. if (ntohs(arp->ar_op) <= 0xff)
  478. key->ip.proto = ntohs(arp->ar_op);
  479. memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
  480. memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
  481. ether_addr_copy(key->ipv4.arp.sha, arp->ar_sha);
  482. ether_addr_copy(key->ipv4.arp.tha, arp->ar_tha);
  483. }
  484. } else if (key->eth.type == htons(ETH_P_IPV6)) {
  485. int nh_len; /* IPv6 Header + Extensions */
  486. nh_len = parse_ipv6hdr(skb, key);
  487. if (unlikely(nh_len < 0)) {
  488. if (nh_len == -EINVAL) {
  489. skb->transport_header = skb->network_header;
  490. error = 0;
  491. } else {
  492. error = nh_len;
  493. }
  494. return error;
  495. }
  496. if (key->ip.frag == OVS_FRAG_TYPE_LATER)
  497. return 0;
  498. if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
  499. key->ip.frag = OVS_FRAG_TYPE_FIRST;
  500. /* Transport layer. */
  501. if (key->ip.proto == NEXTHDR_TCP) {
  502. if (tcphdr_ok(skb)) {
  503. struct tcphdr *tcp = tcp_hdr(skb);
  504. key->ipv6.tp.src = tcp->source;
  505. key->ipv6.tp.dst = tcp->dest;
  506. key->ipv6.tp.flags = TCP_FLAGS_BE16(tcp);
  507. }
  508. } else if (key->ip.proto == NEXTHDR_UDP) {
  509. if (udphdr_ok(skb)) {
  510. struct udphdr *udp = udp_hdr(skb);
  511. key->ipv6.tp.src = udp->source;
  512. key->ipv6.tp.dst = udp->dest;
  513. }
  514. } else if (key->ip.proto == NEXTHDR_SCTP) {
  515. if (sctphdr_ok(skb)) {
  516. struct sctphdr *sctp = sctp_hdr(skb);
  517. key->ipv6.tp.src = sctp->source;
  518. key->ipv6.tp.dst = sctp->dest;
  519. }
  520. } else if (key->ip.proto == NEXTHDR_ICMP) {
  521. if (icmp6hdr_ok(skb)) {
  522. error = parse_icmpv6(skb, key, nh_len);
  523. if (error)
  524. return error;
  525. }
  526. }
  527. }
  528. return 0;
  529. }