2 * Distributed under the terms of the GNU GPL version 2.
3 * Copyright (c) 2007, 2008, 2009, 2010, 2011 Nicira Networks.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
11 #include <asm/uaccess.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/if_ether.h>
15 #include <linux/if_vlan.h>
16 #include <net/llc_pdu.h>
17 #include <linux/kernel.h>
18 #include <linux/jhash.h>
19 #include <linux/jiffies.h>
20 #include <linux/llc.h>
21 #include <linux/module.h>
23 #include <linux/rcupdate.h>
24 #include <linux/if_arp.h>
25 #include <linux/if_ether.h>
27 #include <linux/ipv6.h>
28 #include <linux/tcp.h>
29 #include <linux/udp.h>
30 #include <linux/icmp.h>
31 #include <linux/icmpv6.h>
32 #include <linux/rculist.h>
33 #include <net/inet_ecn.h>
36 #include <net/ndisc.h>
40 static struct kmem_cache *flow_cache;
41 static unsigned int hash_seed __read_mostly;
43 static int check_header(struct sk_buff *skb, int len)
45 if (unlikely(skb->len < len))
47 if (unlikely(!pskb_may_pull(skb, len)))
52 static inline bool arphdr_ok(struct sk_buff *skb)
54 return pskb_may_pull(skb, skb_network_offset(skb) +
55 sizeof(struct arp_eth_header));
58 static inline int check_iphdr(struct sk_buff *skb)
60 unsigned int nh_ofs = skb_network_offset(skb);
64 err = check_header(skb, nh_ofs + sizeof(struct iphdr));
68 ip_len = ip_hdrlen(skb);
69 if (unlikely(ip_len < sizeof(struct iphdr) ||
70 skb->len < nh_ofs + ip_len))
73 skb_set_transport_header(skb, nh_ofs + ip_len);
77 static inline bool tcphdr_ok(struct sk_buff *skb)
79 int th_ofs = skb_transport_offset(skb);
82 if (unlikely(!pskb_may_pull(skb, th_ofs + sizeof(struct tcphdr))))
85 tcp_len = tcp_hdrlen(skb);
86 if (unlikely(tcp_len < sizeof(struct tcphdr) ||
87 skb->len < th_ofs + tcp_len))
93 static inline bool udphdr_ok(struct sk_buff *skb)
95 return pskb_may_pull(skb, skb_transport_offset(skb) +
96 sizeof(struct udphdr));
99 static inline bool icmphdr_ok(struct sk_buff *skb)
101 return pskb_may_pull(skb, skb_transport_offset(skb) +
102 sizeof(struct icmphdr));
105 u64 flow_used_time(unsigned long flow_jiffies)
107 struct timespec cur_ts;
110 ktime_get_ts(&cur_ts);
111 idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
112 cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
113 cur_ts.tv_nsec / NSEC_PER_MSEC;
115 return cur_ms - idle_ms;
118 #define SW_FLOW_KEY_OFFSET(field) \
119 offsetof(struct sw_flow_key, field) + \
120 FIELD_SIZEOF(struct sw_flow_key, field)
123 * skip_exthdr - skip any IPv6 extension headers
124 * @skb: skbuff to parse
125 * @start: offset of first extension header
126 * @nexthdrp: Initially, points to the type of the extension header at @start.
127 * This function updates it to point to the extension header at the final
129 * @tos_frag: Points to the @tos_frag member in a &struct sw_flow_key. This
130 * function sets an appropriate %OVS_FRAG_TYPE_* value.
132 * This is based on ipv6_skip_exthdr() but adds the updates to *@tos_frag.
134 * When there is more than one fragment header, this version reports whether
135 * the final fragment header that it examines is a first fragment.
137 * Returns the final payload offset, or -1 on error.
139 static int skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp,
142 u8 nexthdr = *nexthdrp;
144 while (ipv6_ext_hdr(nexthdr)) {
145 struct ipv6_opt_hdr _hdr, *hp;
148 if (nexthdr == NEXTHDR_NONE)
150 hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
153 if (nexthdr == NEXTHDR_FRAGMENT) {
154 __be16 _frag_off, *fp;
155 fp = skb_header_pointer(skb,
156 start+offsetof(struct frag_hdr,
163 *tos_frag &= ~OVS_FRAG_TYPE_MASK;
164 if (ntohs(*fp) & ~0x7) {
165 *tos_frag |= OVS_FRAG_TYPE_LATER;
168 *tos_frag |= OVS_FRAG_TYPE_FIRST;
170 } else if (nexthdr == NEXTHDR_AUTH)
171 hdrlen = (hp->hdrlen+2)<<2;
173 hdrlen = ipv6_optlen(hp);
175 nexthdr = hp->nexthdr;
183 static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key,
186 unsigned int nh_ofs = skb_network_offset(skb);
193 *key_lenp = SW_FLOW_KEY_OFFSET(ipv6.addr);
195 err = check_header(skb, nh_ofs + sizeof(*nh));
200 nexthdr = nh->nexthdr;
201 payload_ofs = (u8 *)(nh + 1) - skb->data;
203 key->ip.proto = NEXTHDR_NONE;
204 key->ip.tos_frag = ipv6_get_dsfield(nh) & ~INET_ECN_MASK;
205 ipv6_addr_copy(&key->ipv6.addr.src, &nh->saddr);
206 ipv6_addr_copy(&key->ipv6.addr.dst, &nh->daddr);
208 payload_ofs = skip_exthdr(skb, payload_ofs, &nexthdr, &key->ip.tos_frag);
209 if (unlikely(payload_ofs < 0))
212 nh_len = payload_ofs - nh_ofs;
213 skb_set_transport_header(skb, nh_ofs + nh_len);
214 key->ip.proto = nexthdr;
218 static bool icmp6hdr_ok(struct sk_buff *skb)
220 return pskb_may_pull(skb, skb_transport_offset(skb) +
221 sizeof(struct icmp6hdr));
224 #define TCP_FLAGS_OFFSET 13
225 #define TCP_FLAG_MASK 0x3f
227 void flow_used(struct sw_flow *flow, struct sk_buff *skb)
231 if (flow->key.eth.type == htons(ETH_P_IP) &&
232 flow->key.ip.proto == IPPROTO_TCP) {
233 u8 *tcp = (u8 *)tcp_hdr(skb);
234 tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK;
237 spin_lock(&flow->lock);
238 flow->used = jiffies;
239 flow->packet_count++;
240 flow->byte_count += skb->len;
241 flow->tcp_flags |= tcp_flags;
242 spin_unlock(&flow->lock);
245 struct sw_flow_actions *flow_actions_alloc(const struct nlattr *actions)
247 int actions_len = nla_len(actions);
248 struct sw_flow_actions *sfa;
250 /* At least DP_MAX_PORTS actions are required to be able to flood a
251 * packet to every port. Factor of 2 allows for setting VLAN tags,
253 if (actions_len > 2 * DP_MAX_PORTS * nla_total_size(4))
254 return ERR_PTR(-EINVAL);
256 sfa = kmalloc(sizeof(*sfa) + actions_len, GFP_KERNEL);
258 return ERR_PTR(-ENOMEM);
260 sfa->actions_len = actions_len;
261 memcpy(sfa->actions, nla_data(actions), actions_len);
265 struct sw_flow *flow_alloc(void)
267 struct sw_flow *flow;
269 flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
271 return ERR_PTR(-ENOMEM);
273 spin_lock_init(&flow->lock);
274 atomic_set(&flow->refcnt, 1);
275 flow->sf_acts = NULL;
281 static struct hlist_head __rcu *find_bucket(struct flow_table * table, u32 hash)
283 return flex_array_get(table->buckets,
284 (hash & (table->n_buckets - 1)));
287 static struct flex_array __rcu *alloc_buckets(unsigned int n_buckets)
289 struct flex_array __rcu * buckets;
292 buckets = flex_array_alloc(sizeof(struct hlist_head *),
293 n_buckets, GFP_KERNEL);
297 err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL);
299 flex_array_free(buckets);
303 for (i = 0; i < n_buckets; i++)
304 INIT_HLIST_HEAD((struct hlist_head *)
305 flex_array_get(buckets, i));
310 static void free_buckets(struct flex_array * buckets)
312 flex_array_free(buckets);
315 struct flow_table *flow_tbl_alloc(int new_size)
317 struct flow_table *table = kmalloc(sizeof(*table), GFP_KERNEL);
322 table->buckets = alloc_buckets(new_size);
324 if (!table->buckets) {
328 table->n_buckets = new_size;
334 static void flow_free(struct sw_flow *flow)
340 void flow_tbl_destroy(struct flow_table *table)
347 for (i = 0; i < table->n_buckets; i++) {
348 struct sw_flow *flow;
349 struct hlist_head *head = flex_array_get(table->buckets, i);
350 struct hlist_node *node, *n;
352 hlist_for_each_entry_safe(flow, node, n, head, hash_node) {
353 hlist_del_init_rcu(&flow->hash_node);
358 free_buckets(table->buckets);
362 static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)
364 struct flow_table *table = container_of(rcu, struct flow_table, rcu);
366 flow_tbl_destroy(table);
369 void flow_tbl_deferred_destroy(struct flow_table *table)
374 call_rcu(&table->rcu, flow_tbl_destroy_rcu_cb);
377 struct sw_flow *flow_tbl_next(struct flow_table *table, u32 *bucket, u32 *last)
379 struct sw_flow *flow;
380 struct hlist_head *head;
381 struct hlist_node *n;
384 while (*bucket < table->n_buckets) {
386 head = flex_array_get(table->buckets, *bucket);
387 hlist_for_each_entry_rcu(flow, n, head, hash_node) {
402 struct flow_table *flow_tbl_expand(struct flow_table *table)
404 struct flow_table *new_table;
405 int n_buckets = table->n_buckets * 2;
408 new_table = flow_tbl_alloc(n_buckets);
410 return ERR_PTR(-ENOMEM);
412 for (i = 0; i < table->n_buckets; i++) {
413 struct sw_flow *flow;
414 struct hlist_head *head;
415 struct hlist_node *n, *pos;
417 head = flex_array_get(table->buckets, i);
419 hlist_for_each_entry_safe(flow, n, pos, head, hash_node) {
420 hlist_del_init_rcu(&flow->hash_node);
421 flow_tbl_insert(new_table, flow);
428 /* RCU callback used by flow_deferred_free. */
429 static void rcu_free_flow_callback(struct rcu_head *rcu)
431 struct sw_flow *flow = container_of(rcu, struct sw_flow, rcu);
437 /* Schedules 'flow' to be freed after the next RCU grace period.
438 * The caller must hold rcu_read_lock for this to be sensible. */
439 void flow_deferred_free(struct sw_flow *flow)
441 call_rcu(&flow->rcu, rcu_free_flow_callback);
444 void flow_hold(struct sw_flow *flow)
446 atomic_inc(&flow->refcnt);
449 void flow_put(struct sw_flow *flow)
454 if (atomic_dec_and_test(&flow->refcnt)) {
455 kfree((struct sf_flow_acts __force *)flow->sf_acts);
456 kmem_cache_free(flow_cache, flow);
460 /* RCU callback used by flow_deferred_free_acts. */
461 static void rcu_free_acts_callback(struct rcu_head *rcu)
463 struct sw_flow_actions *sf_acts = container_of(rcu,
464 struct sw_flow_actions, rcu);
468 /* Schedules 'sf_acts' to be freed after the next RCU grace period.
469 * The caller must hold rcu_read_lock for this to be sensible. */
470 void flow_deferred_free_acts(struct sw_flow_actions *sf_acts)
472 call_rcu(&sf_acts->rcu, rcu_free_acts_callback);
475 static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
478 __be16 eth_type; /* ETH_P_8021Q */
481 struct qtag_prefix *qp;
483 if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
487 qp = (struct qtag_prefix *) skb->data;
488 key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
489 __skb_pull(skb, sizeof(struct qtag_prefix));
494 static __be16 parse_ethertype(struct sk_buff *skb)
496 struct llc_snap_hdr {
497 u8 dsap; /* Always 0xAA */
498 u8 ssap; /* Always 0xAA */
503 struct llc_snap_hdr *llc;
506 proto = *(__be16 *) skb->data;
507 __skb_pull(skb, sizeof(__be16));
509 if (ntohs(proto) >= 1536)
512 if (skb->len < sizeof(struct llc_snap_hdr))
513 return htons(ETH_P_802_2);
515 if (unlikely(!pskb_may_pull(skb, sizeof(struct llc_snap_hdr))))
518 llc = (struct llc_snap_hdr *) skb->data;
519 if (llc->dsap != LLC_SAP_SNAP ||
520 llc->ssap != LLC_SAP_SNAP ||
521 (llc->oui[0] | llc->oui[1] | llc->oui[2]) != 0)
522 return htons(ETH_P_802_2);
524 __skb_pull(skb, sizeof(struct llc_snap_hdr));
525 return llc->ethertype;
528 static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
529 int *key_lenp, int nh_len)
531 struct icmp6hdr *icmp = icmp6_hdr(skb);
535 /* The ICMPv6 type and code fields use the 16-bit transport port
536 * fields, so we need to store them in 16-bit network byte order.
538 key->ipv6.tp.src = htons(icmp->icmp6_type);
539 key->ipv6.tp.dst = htons(icmp->icmp6_code);
540 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
542 if (icmp->icmp6_code == 0 &&
543 (icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION ||
544 icmp->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT)) {
545 int icmp_len = skb->len - skb_transport_offset(skb);
549 key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
551 /* In order to process neighbor discovery options, we need the
554 if (unlikely(icmp_len < sizeof(*nd)))
556 if (unlikely(skb_linearize(skb))) {
561 nd = (struct nd_msg *)skb_transport_header(skb);
562 ipv6_addr_copy(&key->ipv6.nd.target, &nd->target);
563 key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
565 icmp_len -= sizeof(*nd);
567 while (icmp_len >= 8) {
568 struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)(nd->opt + offset);
569 int opt_len = nd_opt->nd_opt_len * 8;
571 if (unlikely(!opt_len || opt_len > icmp_len))
574 /* Store the link layer address if the appropriate
575 * option is provided. It is considered an error if
576 * the same link layer option is specified twice.
578 if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
580 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
582 memcpy(key->ipv6.nd.sll,
583 &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
584 } else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
586 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
588 memcpy(key->ipv6.nd.tll,
589 &nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
600 memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
601 memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
602 memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
610 * flow_extract - extracts a flow key from an Ethernet frame.
611 * @skb: sk_buff that contains the frame, with skb->data pointing to the
613 * @in_port: port number on which @skb was received.
614 * @key: output flow key
615 * @key_lenp: length of output flow key
617 * The caller must ensure that skb->len >= ETH_HLEN.
619 * Returns 0 if successful, otherwise a negative errno value.
621 * Initializes @skb header pointers as follows:
623 * - skb->mac_header: the Ethernet header.
625 * - skb->network_header: just past the Ethernet header, or just past the
626 * VLAN header, to the first byte of the Ethernet payload.
628 * - skb->transport_header: If key->dl_type is ETH_P_IP or ETH_P_IPV6
629 * on output, then just past the IP header, if one is present and
630 * of a correct length, otherwise the same as skb->network_header.
631 * For other key->dl_type values it is left untouched.
633 int flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key,
637 int key_len = SW_FLOW_KEY_OFFSET(eth);
640 memset(key, 0, sizeof(*key));
642 key->phy.priority = skb->priority;
643 key->phy.tun_id = OVS_CB(skb)->tun_id;
644 key->phy.in_port = in_port;
646 skb_reset_mac_header(skb);
648 /* Link layer. We are guaranteed to have at least the 14 byte Ethernet
649 * header in the linear data area.
652 memcpy(key->eth.src, eth->h_source, ETH_ALEN);
653 memcpy(key->eth.dst, eth->h_dest, ETH_ALEN);
655 __skb_pull(skb, 2 * ETH_ALEN);
657 if (vlan_tx_tag_present(skb))
658 key->eth.tci = htons(vlan_get_tci(skb));
659 else if (eth->h_proto == htons(ETH_P_8021Q))
660 if (unlikely(parse_vlan(skb, key)))
663 key->eth.type = parse_ethertype(skb);
664 if (unlikely(key->eth.type == htons(0)))
667 skb_reset_network_header(skb);
668 __skb_push(skb, skb->data - skb_mac_header(skb));
671 if (key->eth.type == htons(ETH_P_IP)) {
675 key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
677 error = check_iphdr(skb);
678 if (unlikely(error)) {
679 if (error == -EINVAL) {
680 skb->transport_header = skb->network_header;
687 key->ipv4.addr.src = nh->saddr;
688 key->ipv4.addr.dst = nh->daddr;
690 key->ip.proto = nh->protocol;
691 key->ip.tos_frag = nh->tos & ~INET_ECN_MASK;
693 offset = nh->frag_off & htons(IP_OFFSET);
695 key->ip.tos_frag |= OVS_FRAG_TYPE_LATER;
698 if (nh->frag_off & htons(IP_MF) ||
699 skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
700 key->ip.tos_frag |= OVS_FRAG_TYPE_FIRST;
702 /* Transport layer. */
703 if (key->ip.proto == IPPROTO_TCP) {
704 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
705 if (tcphdr_ok(skb)) {
706 struct tcphdr *tcp = tcp_hdr(skb);
707 key->ipv4.tp.src = tcp->source;
708 key->ipv4.tp.dst = tcp->dest;
710 } else if (key->ip.proto == IPPROTO_UDP) {
711 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
712 if (udphdr_ok(skb)) {
713 struct udphdr *udp = udp_hdr(skb);
714 key->ipv4.tp.src = udp->source;
715 key->ipv4.tp.dst = udp->dest;
717 } else if (key->ip.proto == IPPROTO_ICMP) {
718 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
719 if (icmphdr_ok(skb)) {
720 struct icmphdr *icmp = icmp_hdr(skb);
721 /* The ICMP type and code fields use the 16-bit
722 * transport port fields, so we need to store them
723 * in 16-bit network byte order. */
724 key->ipv4.tp.src = htons(icmp->type);
725 key->ipv4.tp.dst = htons(icmp->code);
729 } else if (key->eth.type == htons(ETH_P_ARP) && arphdr_ok(skb)) {
730 struct arp_eth_header *arp;
732 arp = (struct arp_eth_header *)skb_network_header(skb);
734 if (arp->ar_hrd == htons(ARPHRD_ETHER)
735 && arp->ar_pro == htons(ETH_P_IP)
736 && arp->ar_hln == ETH_ALEN
737 && arp->ar_pln == 4) {
739 /* We only match on the lower 8 bits of the opcode. */
740 if (ntohs(arp->ar_op) <= 0xff)
741 key->ip.proto = ntohs(arp->ar_op);
743 if (key->ip.proto == ARPOP_REQUEST
744 || key->ip.proto == ARPOP_REPLY) {
745 memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
746 memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
747 memcpy(key->ipv4.arp.sha, arp->ar_sha, ETH_ALEN);
748 memcpy(key->ipv4.arp.tha, arp->ar_tha, ETH_ALEN);
749 key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
752 } else if (key->eth.type == htons(ETH_P_IPV6)) {
753 int nh_len; /* IPv6 Header + Extensions */
755 nh_len = parse_ipv6hdr(skb, key, &key_len);
756 if (unlikely(nh_len < 0)) {
757 if (nh_len == -EINVAL)
758 skb->transport_header = skb->network_header;
764 if ((key->ip.tos_frag & OVS_FRAG_TYPE_MASK) == OVS_FRAG_TYPE_LATER)
766 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
767 key->ip.tos_frag |= OVS_FRAG_TYPE_FIRST;
769 /* Transport layer. */
770 if (key->ip.proto == NEXTHDR_TCP) {
771 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
772 if (tcphdr_ok(skb)) {
773 struct tcphdr *tcp = tcp_hdr(skb);
774 key->ipv6.tp.src = tcp->source;
775 key->ipv6.tp.dst = tcp->dest;
777 } else if (key->ip.proto == NEXTHDR_UDP) {
778 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
779 if (udphdr_ok(skb)) {
780 struct udphdr *udp = udp_hdr(skb);
781 key->ipv6.tp.src = udp->source;
782 key->ipv6.tp.dst = udp->dest;
784 } else if (key->ip.proto == NEXTHDR_ICMP) {
785 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
786 if (icmp6hdr_ok(skb)) {
787 error = parse_icmpv6(skb, key, &key_len, nh_len);
799 u32 flow_hash(const struct sw_flow_key *key, int key_len)
801 return jhash2((u32*)key, DIV_ROUND_UP(key_len, sizeof(u32)), hash_seed);
804 struct sw_flow * flow_tbl_lookup(struct flow_table *table,
805 struct sw_flow_key *key, int key_len)
807 struct sw_flow *flow;
808 struct hlist_node *n;
809 struct hlist_head *head;
812 hash = flow_hash(key, key_len);
814 head = find_bucket(table, hash);
815 hlist_for_each_entry_rcu(flow, n, head, hash_node) {
817 if (flow->hash == hash &&
818 !memcmp(&flow->key, key, key_len)) {
825 void flow_tbl_insert(struct flow_table *table, struct sw_flow *flow)
827 struct hlist_head *head;
829 head = find_bucket(table, flow->hash);
830 hlist_add_head_rcu(&flow->hash_node, head);
834 void flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)
836 if (!hlist_unhashed(&flow->hash_node)) {
837 hlist_del_init_rcu(&flow->hash_node);
839 BUG_ON(table->count < 0);
843 static int parse_tos_frag(struct sw_flow_key *swkey, u8 tos, u8 frag)
845 if (tos & INET_ECN_MASK || frag > OVS_FRAG_TYPE_MAX)
848 swkey->ip.tos_frag = tos | frag;
852 /* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute. */
853 const u32 ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
854 [OVS_KEY_ATTR_PRIORITY] = 4,
855 [OVS_KEY_ATTR_TUN_ID] = 8,
856 [OVS_KEY_ATTR_IN_PORT] = 4,
857 [OVS_KEY_ATTR_ETHERNET] = sizeof(struct ovs_key_ethernet),
858 [OVS_KEY_ATTR_8021Q] = sizeof(struct ovs_key_8021q),
859 [OVS_KEY_ATTR_ETHERTYPE] = 2,
860 [OVS_KEY_ATTR_IPV4] = sizeof(struct ovs_key_ipv4),
861 [OVS_KEY_ATTR_IPV6] = sizeof(struct ovs_key_ipv6),
862 [OVS_KEY_ATTR_TCP] = sizeof(struct ovs_key_tcp),
863 [OVS_KEY_ATTR_UDP] = sizeof(struct ovs_key_udp),
864 [OVS_KEY_ATTR_ICMP] = sizeof(struct ovs_key_icmp),
865 [OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6),
866 [OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp),
867 [OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd),
871 * flow_from_nlattrs - parses Netlink attributes into a flow key.
872 * @swkey: receives the extracted flow key.
873 * @key_lenp: number of bytes used in @swkey.
874 * @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
877 * This state machine accepts the following forms, with [] for optional
878 * elements and | for alternatives:
880 * [priority] [tun_id] [in_port] ethernet [8021q] [ethertype \
881 * [IPv4 [TCP|UDP|ICMP] | IPv6 [TCP|UDP|ICMPv6 [ND]] | ARP]]
883 * except that IPv4 or IPv6 terminates the sequence if its @ipv4_frag or
884 * @ipv6_frag member, respectively, equals %OVS_FRAG_TYPE_LATER.
886 int flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp,
887 const struct nlattr *attr)
890 enum ovs_frag_type frag_type;
891 const struct nlattr *nla;
896 memset(swkey, 0, sizeof(*swkey));
897 swkey->phy.in_port = USHRT_MAX;
898 swkey->eth.type = htons(ETH_P_802_2);
899 key_len = SW_FLOW_KEY_OFFSET(eth);
901 prev_type = OVS_KEY_ATTR_UNSPEC;
902 nla_for_each_nested(nla, attr, rem) {
903 const struct ovs_key_ethernet *eth_key;
904 const struct ovs_key_8021q *q_key;
905 const struct ovs_key_ipv4 *ipv4_key;
906 const struct ovs_key_ipv6 *ipv6_key;
907 const struct ovs_key_tcp *tcp_key;
908 const struct ovs_key_udp *udp_key;
909 const struct ovs_key_icmp *icmp_key;
910 const struct ovs_key_icmpv6 *icmpv6_key;
911 const struct ovs_key_arp *arp_key;
912 const struct ovs_key_nd *nd_key;
914 int type = nla_type(nla);
916 if (type > OVS_KEY_ATTR_MAX || nla_len(nla) != ovs_key_lens[type])
919 #define TRANSITION(PREV_TYPE, TYPE) (((PREV_TYPE) << 16) | (TYPE))
920 switch (TRANSITION(prev_type, type)) {
921 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_PRIORITY):
922 swkey->phy.priority = nla_get_u32(nla);
925 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_TUN_ID):
926 case TRANSITION(OVS_KEY_ATTR_PRIORITY, OVS_KEY_ATTR_TUN_ID):
927 swkey->phy.tun_id = nla_get_be64(nla);
930 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_IN_PORT):
931 case TRANSITION(OVS_KEY_ATTR_PRIORITY, OVS_KEY_ATTR_IN_PORT):
932 case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_IN_PORT):
933 if (nla_get_u32(nla) >= DP_MAX_PORTS)
935 swkey->phy.in_port = nla_get_u32(nla);
938 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_ETHERNET):
939 case TRANSITION(OVS_KEY_ATTR_PRIORITY, OVS_KEY_ATTR_ETHERNET):
940 case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_ETHERNET):
941 case TRANSITION(OVS_KEY_ATTR_IN_PORT, OVS_KEY_ATTR_ETHERNET):
942 eth_key = nla_data(nla);
943 memcpy(swkey->eth.src, eth_key->eth_src, ETH_ALEN);
944 memcpy(swkey->eth.dst, eth_key->eth_dst, ETH_ALEN);
947 case TRANSITION(OVS_KEY_ATTR_ETHERNET, OVS_KEY_ATTR_8021Q):
948 q_key = nla_data(nla);
949 /* Only standard 0x8100 VLANs currently supported. */
950 if (q_key->q_tpid != htons(ETH_P_8021Q))
952 if (q_key->q_tci & htons(VLAN_TAG_PRESENT))
954 swkey->eth.tci = q_key->q_tci | htons(VLAN_TAG_PRESENT);
957 case TRANSITION(OVS_KEY_ATTR_8021Q, OVS_KEY_ATTR_ETHERTYPE):
958 case TRANSITION(OVS_KEY_ATTR_ETHERNET, OVS_KEY_ATTR_ETHERTYPE):
959 swkey->eth.type = nla_get_be16(nla);
960 if (ntohs(swkey->eth.type) < 1536)
964 case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_IPV4):
965 key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
966 if (swkey->eth.type != htons(ETH_P_IP))
968 ipv4_key = nla_data(nla);
969 swkey->ip.proto = ipv4_key->ipv4_proto;
970 if (parse_tos_frag(swkey, ipv4_key->ipv4_tos,
971 ipv4_key->ipv4_frag))
973 swkey->ipv4.addr.src = ipv4_key->ipv4_src;
974 swkey->ipv4.addr.dst = ipv4_key->ipv4_dst;
977 case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_IPV6):
978 key_len = SW_FLOW_KEY_OFFSET(ipv6.addr);
979 if (swkey->eth.type != htons(ETH_P_IPV6))
981 ipv6_key = nla_data(nla);
982 swkey->ip.proto = ipv6_key->ipv6_proto;
983 if (parse_tos_frag(swkey, ipv6_key->ipv6_tos,
984 ipv6_key->ipv6_frag))
986 memcpy(&swkey->ipv6.addr.src, ipv6_key->ipv6_src,
987 sizeof(swkey->ipv6.addr.src));
988 memcpy(&swkey->ipv6.addr.dst, ipv6_key->ipv6_dst,
989 sizeof(swkey->ipv6.addr.dst));
992 case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_TCP):
993 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
994 if (swkey->ip.proto != IPPROTO_TCP)
996 tcp_key = nla_data(nla);
997 swkey->ipv4.tp.src = tcp_key->tcp_src;
998 swkey->ipv4.tp.dst = tcp_key->tcp_dst;
1001 case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_TCP):
1002 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
1003 if (swkey->ip.proto != IPPROTO_TCP)
1005 tcp_key = nla_data(nla);
1006 swkey->ipv6.tp.src = tcp_key->tcp_src;
1007 swkey->ipv6.tp.dst = tcp_key->tcp_dst;
1010 case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_UDP):
1011 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
1012 if (swkey->ip.proto != IPPROTO_UDP)
1014 udp_key = nla_data(nla);
1015 swkey->ipv4.tp.src = udp_key->udp_src;
1016 swkey->ipv4.tp.dst = udp_key->udp_dst;
1019 case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_UDP):
1020 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
1021 if (swkey->ip.proto != IPPROTO_UDP)
1023 udp_key = nla_data(nla);
1024 swkey->ipv6.tp.src = udp_key->udp_src;
1025 swkey->ipv6.tp.dst = udp_key->udp_dst;
1028 case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_ICMP):
1029 key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
1030 if (swkey->ip.proto != IPPROTO_ICMP)
1032 icmp_key = nla_data(nla);
1033 swkey->ipv4.tp.src = htons(icmp_key->icmp_type);
1034 swkey->ipv4.tp.dst = htons(icmp_key->icmp_code);
1037 case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_ICMPV6):
1038 key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
1039 if (swkey->ip.proto != IPPROTO_ICMPV6)
1041 icmpv6_key = nla_data(nla);
1042 swkey->ipv6.tp.src = htons(icmpv6_key->icmpv6_type);
1043 swkey->ipv6.tp.dst = htons(icmpv6_key->icmpv6_code);
1046 case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_ARP):
1047 key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
1048 if (swkey->eth.type != htons(ETH_P_ARP))
1050 arp_key = nla_data(nla);
1051 swkey->ipv4.addr.src = arp_key->arp_sip;
1052 swkey->ipv4.addr.dst = arp_key->arp_tip;
1053 if (arp_key->arp_op & htons(0xff00))
1055 swkey->ip.proto = ntohs(arp_key->arp_op);
1056 memcpy(swkey->ipv4.arp.sha, arp_key->arp_sha, ETH_ALEN);
1057 memcpy(swkey->ipv4.arp.tha, arp_key->arp_tha, ETH_ALEN);
1060 case TRANSITION(OVS_KEY_ATTR_ICMPV6, OVS_KEY_ATTR_ND):
1061 key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
1062 if (swkey->ipv6.tp.src != htons(NDISC_NEIGHBOUR_SOLICITATION)
1063 && swkey->ipv6.tp.src != htons(NDISC_NEIGHBOUR_ADVERTISEMENT))
1065 nd_key = nla_data(nla);
1066 memcpy(&swkey->ipv6.nd.target, nd_key->nd_target,
1067 sizeof(swkey->ipv6.nd.target));
1068 memcpy(swkey->ipv6.nd.sll, nd_key->nd_sll, ETH_ALEN);
1069 memcpy(swkey->ipv6.nd.tll, nd_key->nd_tll, ETH_ALEN);
1081 frag_type = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
1082 switch (prev_type) {
1083 case OVS_KEY_ATTR_UNSPEC:
1086 case OVS_KEY_ATTR_PRIORITY:
1087 case OVS_KEY_ATTR_TUN_ID:
1088 case OVS_KEY_ATTR_IN_PORT:
1091 case OVS_KEY_ATTR_ETHERNET:
1092 case OVS_KEY_ATTR_8021Q:
1095 case OVS_KEY_ATTR_ETHERTYPE:
1096 if (swkey->eth.type == htons(ETH_P_IP) ||
1097 swkey->eth.type == htons(ETH_P_IPV6) ||
1098 swkey->eth.type == htons(ETH_P_ARP))
1102 case OVS_KEY_ATTR_IPV4:
1103 if (frag_type == OVS_FRAG_TYPE_LATER)
1105 if (swkey->ip.proto == IPPROTO_TCP ||
1106 swkey->ip.proto == IPPROTO_UDP ||
1107 swkey->ip.proto == IPPROTO_ICMP)
1111 case OVS_KEY_ATTR_IPV6:
1112 if (frag_type == OVS_FRAG_TYPE_LATER)
1114 if (swkey->ip.proto == IPPROTO_TCP ||
1115 swkey->ip.proto == IPPROTO_UDP ||
1116 swkey->ip.proto == IPPROTO_ICMPV6)
1120 case OVS_KEY_ATTR_ICMPV6:
1121 if (swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_SOLICITATION) ||
1122 swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT) ||
1123 frag_type == OVS_FRAG_TYPE_LATER)
1127 case OVS_KEY_ATTR_TCP:
1128 case OVS_KEY_ATTR_UDP:
1129 case OVS_KEY_ATTR_ICMP:
1130 case OVS_KEY_ATTR_ND:
1131 if (frag_type == OVS_FRAG_TYPE_LATER)
1135 case OVS_KEY_ATTR_ARP:
1146 *key_lenp = key_len;
1151 * flow_metadata_from_nlattrs - parses Netlink attributes into a flow key.
1152 * @in_port: receives the extracted input port.
1153 * @tun_id: receives the extracted tunnel ID.
1154 * @key: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
1157 * This parses a series of Netlink attributes that form a flow key, which must
1158 * take the same form accepted by flow_from_nlattrs(), but only enough of it to
1159 * get the metadata, that is, the parts of the flow key that cannot be
1160 * extracted from the packet itself.
1162 int flow_metadata_from_nlattrs(u32 *priority, u16 *in_port, __be64 *tun_id,
1163 const struct nlattr *attr)
1165 const struct nlattr *nla;
1169 *in_port = USHRT_MAX;
1173 prev_type = OVS_KEY_ATTR_UNSPEC;
1174 nla_for_each_nested(nla, attr, rem) {
1175 int type = nla_type(nla);
1177 if (type > OVS_KEY_ATTR_MAX || nla_len(nla) != ovs_key_lens[type])
1180 switch (TRANSITION(prev_type, type)) {
1181 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_PRIORITY):
1182 *priority = nla_get_u32(nla);
1185 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_TUN_ID):
1186 case TRANSITION(OVS_KEY_ATTR_PRIORITY, OVS_KEY_ATTR_TUN_ID):
1187 *tun_id = nla_get_be64(nla);
1190 case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_IN_PORT):
1191 case TRANSITION(OVS_KEY_ATTR_PRIORITY, OVS_KEY_ATTR_IN_PORT):
1192 case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_IN_PORT):
1193 if (nla_get_u32(nla) >= DP_MAX_PORTS)
1195 *in_port = nla_get_u32(nla);
1209 int flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)
1211 struct ovs_key_ethernet *eth_key;
1214 /* This is an imperfect sanity-check that FLOW_BUFSIZE doesn't need
1215 * to be updated, but will at least raise awareness when new
1216 * datapath key types are added. */
1217 BUILD_BUG_ON(__OVS_KEY_ATTR_MAX != 15);
1219 if (swkey->phy.priority)
1220 NLA_PUT_U32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority);
1222 if (swkey->phy.tun_id != cpu_to_be64(0))
1223 NLA_PUT_BE64(skb, OVS_KEY_ATTR_TUN_ID, swkey->phy.tun_id);
1225 if (swkey->phy.in_port != USHRT_MAX)
1226 NLA_PUT_U32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port);
1228 nla = nla_reserve(skb, OVS_KEY_ATTR_ETHERNET, sizeof(*eth_key));
1230 goto nla_put_failure;
1231 eth_key = nla_data(nla);
1232 memcpy(eth_key->eth_src, swkey->eth.src, ETH_ALEN);
1233 memcpy(eth_key->eth_dst, swkey->eth.dst, ETH_ALEN);
1235 if (swkey->eth.tci != htons(0)) {
1236 struct ovs_key_8021q q_key;
1238 q_key.q_tpid = htons(ETH_P_8021Q);
1239 q_key.q_tci = swkey->eth.tci & ~htons(VLAN_TAG_PRESENT);
1240 NLA_PUT(skb, OVS_KEY_ATTR_8021Q, sizeof(q_key), &q_key);
1243 if (swkey->eth.type == htons(ETH_P_802_2))
1246 NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, swkey->eth.type);
1248 if (swkey->eth.type == htons(ETH_P_IP)) {
1249 struct ovs_key_ipv4 *ipv4_key;
1251 nla = nla_reserve(skb, OVS_KEY_ATTR_IPV4, sizeof(*ipv4_key));
1253 goto nla_put_failure;
1254 ipv4_key = nla_data(nla);
1255 memset(ipv4_key, 0, sizeof(struct ovs_key_ipv4));
1256 ipv4_key->ipv4_src = swkey->ipv4.addr.src;
1257 ipv4_key->ipv4_dst = swkey->ipv4.addr.dst;
1258 ipv4_key->ipv4_proto = swkey->ip.proto;
1259 ipv4_key->ipv4_tos = swkey->ip.tos_frag & ~INET_ECN_MASK;
1260 ipv4_key->ipv4_frag = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
1261 } else if (swkey->eth.type == htons(ETH_P_IPV6)) {
1262 struct ovs_key_ipv6 *ipv6_key;
1264 nla = nla_reserve(skb, OVS_KEY_ATTR_IPV6, sizeof(*ipv6_key));
1266 goto nla_put_failure;
1267 ipv6_key = nla_data(nla);
1268 memset(ipv6_key, 0, sizeof(struct ovs_key_ipv6));
1269 memcpy(ipv6_key->ipv6_src, &swkey->ipv6.addr.src,
1270 sizeof(ipv6_key->ipv6_src));
1271 memcpy(ipv6_key->ipv6_dst, &swkey->ipv6.addr.dst,
1272 sizeof(ipv6_key->ipv6_dst));
1273 ipv6_key->ipv6_proto = swkey->ip.proto;
1274 ipv6_key->ipv6_tos = swkey->ip.tos_frag & ~INET_ECN_MASK;
1275 ipv6_key->ipv6_frag = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
1276 } else if (swkey->eth.type == htons(ETH_P_ARP)) {
1277 struct ovs_key_arp *arp_key;
1279 nla = nla_reserve(skb, OVS_KEY_ATTR_ARP, sizeof(*arp_key));
1281 goto nla_put_failure;
1282 arp_key = nla_data(nla);
1283 memset(arp_key, 0, sizeof(struct ovs_key_arp));
1284 arp_key->arp_sip = swkey->ipv4.addr.src;
1285 arp_key->arp_tip = swkey->ipv4.addr.dst;
1286 arp_key->arp_op = htons(swkey->ip.proto);
1287 memcpy(arp_key->arp_sha, swkey->ipv4.arp.sha, ETH_ALEN);
1288 memcpy(arp_key->arp_tha, swkey->ipv4.arp.tha, ETH_ALEN);
1291 if ((swkey->eth.type == htons(ETH_P_IP) ||
1292 swkey->eth.type == htons(ETH_P_IPV6)) &&
1293 (swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK) != OVS_FRAG_TYPE_LATER) {
1295 if (swkey->ip.proto == IPPROTO_TCP) {
1296 struct ovs_key_tcp *tcp_key;
1298 nla = nla_reserve(skb, OVS_KEY_ATTR_TCP, sizeof(*tcp_key));
1300 goto nla_put_failure;
1301 tcp_key = nla_data(nla);
1302 if (swkey->eth.type == htons(ETH_P_IP)) {
1303 tcp_key->tcp_src = swkey->ipv4.tp.src;
1304 tcp_key->tcp_dst = swkey->ipv4.tp.dst;
1305 } else if (swkey->eth.type == htons(ETH_P_IPV6)) {
1306 tcp_key->tcp_src = swkey->ipv6.tp.src;
1307 tcp_key->tcp_dst = swkey->ipv6.tp.dst;
1309 } else if (swkey->ip.proto == IPPROTO_UDP) {
1310 struct ovs_key_udp *udp_key;
1312 nla = nla_reserve(skb, OVS_KEY_ATTR_UDP, sizeof(*udp_key));
1314 goto nla_put_failure;
1315 udp_key = nla_data(nla);
1316 if (swkey->eth.type == htons(ETH_P_IP)) {
1317 udp_key->udp_src = swkey->ipv4.tp.src;
1318 udp_key->udp_dst = swkey->ipv4.tp.dst;
1319 } else if (swkey->eth.type == htons(ETH_P_IPV6)) {
1320 udp_key->udp_src = swkey->ipv6.tp.src;
1321 udp_key->udp_dst = swkey->ipv6.tp.dst;
1323 } else if (swkey->eth.type == htons(ETH_P_IP) &&
1324 swkey->ip.proto == IPPROTO_ICMP) {
1325 struct ovs_key_icmp *icmp_key;
1327 nla = nla_reserve(skb, OVS_KEY_ATTR_ICMP, sizeof(*icmp_key));
1329 goto nla_put_failure;
1330 icmp_key = nla_data(nla);
1331 icmp_key->icmp_type = ntohs(swkey->ipv4.tp.src);
1332 icmp_key->icmp_code = ntohs(swkey->ipv4.tp.dst);
1333 } else if (swkey->eth.type == htons(ETH_P_IPV6) &&
1334 swkey->ip.proto == IPPROTO_ICMPV6) {
1335 struct ovs_key_icmpv6 *icmpv6_key;
1337 nla = nla_reserve(skb, OVS_KEY_ATTR_ICMPV6,
1338 sizeof(*icmpv6_key));
1340 goto nla_put_failure;
1341 icmpv6_key = nla_data(nla);
1342 icmpv6_key->icmpv6_type = ntohs(swkey->ipv6.tp.src);
1343 icmpv6_key->icmpv6_code = ntohs(swkey->ipv6.tp.dst);
1345 if (icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_SOLICITATION ||
1346 icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_ADVERTISEMENT) {
1347 struct ovs_key_nd *nd_key;
1349 nla = nla_reserve(skb, OVS_KEY_ATTR_ND, sizeof(*nd_key));
1351 goto nla_put_failure;
1352 nd_key = nla_data(nla);
1353 memcpy(nd_key->nd_target, &swkey->ipv6.nd.target,
1354 sizeof(nd_key->nd_target));
1355 memcpy(nd_key->nd_sll, swkey->ipv6.nd.sll, ETH_ALEN);
1356 memcpy(nd_key->nd_tll, swkey->ipv6.nd.tll, ETH_ALEN);
1367 /* Initializes the flow module.
1368 * Returns zero if successful or a negative error code. */
1371 flow_cache = kmem_cache_create("sw_flow", sizeof(struct sw_flow), 0,
1373 if (flow_cache == NULL)
1376 get_random_bytes(&hash_seed, sizeof(hash_seed));
1381 /* Uninitializes the flow module. */
1382 void flow_exit(void)
1384 kmem_cache_destroy(flow_cache);