2 * Copyright (c) 2007-2012 Nicira Networks.
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.
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.
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
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/if_arp.h>
22 #include <linux/if_ether.h>
24 #include <linux/if_vlan.h>
25 #include <linux/igmp.h>
27 #include <linux/in_route.h>
28 #include <linux/inetdevice.h>
29 #include <linux/jhash.h>
30 #include <linux/list.h>
31 #include <linux/kernel.h>
32 #include <linux/version.h>
33 #include <linux/workqueue.h>
34 #include <linux/rculist.h>
36 #include <net/dsfield.h>
39 #include <net/inet_ecn.h>
41 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
44 #include <net/route.h>
52 #include "vport-generic.h"
53 #include "vport-internal_dev.h"
55 #ifdef NEED_CACHE_TIMEOUT
57 * On kernels where we can't quickly detect changes in the rest of the system
58 * we use an expiration time to invalidate the cache. A shorter expiration
59 * reduces the length of time that we may potentially blackhole packets while
60 * a longer time increases performance by reducing the frequency that the
61 * cache needs to be rebuilt. A variety of factors may cause the cache to be
62 * invalidated before the expiration time but this is the maximum. The time
63 * is expressed in jiffies.
65 #define MAX_CACHE_EXP HZ
69 * Interval to check for and remove caches that are no longer valid. Caches
70 * are checked for validity before they are used for packet encapsulation and
71 * old caches are removed at that time. However, if no packets are sent through
72 * the tunnel then the cache will never be destroyed. Since it holds
73 * references to a number of system objects, the cache will continue to use
74 * system resources by not allowing those objects to be destroyed. The cache
75 * cleaner is periodically run to free invalid caches. It does not
76 * significantly affect system performance. A lower interval will release
77 * resources faster but will itself consume resources by requiring more frequent
78 * checks. A longer interval may result in messages being printed to the kernel
79 * message buffer about unreleased resources. The interval is expressed in
82 #define CACHE_CLEANER_INTERVAL (5 * HZ)
84 #define CACHE_DATA_ALIGN 16
85 #define PORT_TABLE_SIZE 1024
87 static struct hlist_head *port_table __read_mostly;
88 static int port_table_count;
90 static void cache_cleaner(struct work_struct *work);
91 static DECLARE_DELAYED_WORK(cache_cleaner_wq, cache_cleaner);
94 * These are just used as an optimization: they don't require any kind of
95 * synchronization because we could have just as easily read the value before
96 * the port change happened.
98 static unsigned int key_local_remote_ports __read_mostly;
99 static unsigned int key_remote_ports __read_mostly;
100 static unsigned int key_multicast_ports __read_mostly;
101 static unsigned int local_remote_ports __read_mostly;
102 static unsigned int remote_ports __read_mostly;
103 static unsigned int multicast_ports __read_mostly;
105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
106 #define rt_dst(rt) (rt->dst)
108 #define rt_dst(rt) (rt->u.dst)
111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0)
112 static struct hh_cache *rt_hh(struct rtable *rt)
114 struct neighbour *neigh = dst_get_neighbour_noref(&rt->dst);
115 if (!neigh || !(neigh->nud_state & NUD_CONNECTED) ||
121 #define rt_hh(rt) (rt_dst(rt).hh)
124 static struct vport *tnl_vport_to_vport(const struct tnl_vport *tnl_vport)
126 return vport_from_priv(tnl_vport);
129 /* This is analogous to rtnl_dereference for the tunnel cache. It checks that
130 * cache_lock is held, so it is only for update side code.
132 static struct tnl_cache *cache_dereference(struct tnl_vport *tnl_vport)
134 return rcu_dereference_protected(tnl_vport->cache,
135 lockdep_is_held(&tnl_vport->cache_lock));
138 static void schedule_cache_cleaner(void)
140 schedule_delayed_work(&cache_cleaner_wq, CACHE_CLEANER_INTERVAL);
143 static void free_cache(struct tnl_cache *cache)
148 ovs_flow_put(cache->flow);
149 ip_rt_put(cache->rt);
153 static void free_config_rcu(struct rcu_head *rcu)
155 struct tnl_mutable_config *c = container_of(rcu, struct tnl_mutable_config, rcu);
159 static void free_cache_rcu(struct rcu_head *rcu)
161 struct tnl_cache *c = container_of(rcu, struct tnl_cache, rcu);
165 /* Frees the portion of 'mutable' that requires RTNL and thus can't happen
166 * within an RCU callback. Fortunately this part doesn't require waiting for
167 * an RCU grace period.
169 static void free_mutable_rtnl(struct tnl_mutable_config *mutable)
172 if (ipv4_is_multicast(mutable->key.daddr) && mutable->mlink) {
173 struct in_device *in_dev;
174 in_dev = inetdev_by_index(port_key_get_net(&mutable->key), mutable->mlink);
176 ip_mc_dec_group(in_dev, mutable->key.daddr);
180 static void assign_config_rcu(struct vport *vport,
181 struct tnl_mutable_config *new_config)
183 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
184 struct tnl_mutable_config *old_config;
186 old_config = rtnl_dereference(tnl_vport->mutable);
187 rcu_assign_pointer(tnl_vport->mutable, new_config);
189 free_mutable_rtnl(old_config);
190 call_rcu(&old_config->rcu, free_config_rcu);
193 static void assign_cache_rcu(struct vport *vport, struct tnl_cache *new_cache)
195 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
196 struct tnl_cache *old_cache;
198 old_cache = cache_dereference(tnl_vport);
199 rcu_assign_pointer(tnl_vport->cache, new_cache);
202 call_rcu(&old_cache->rcu, free_cache_rcu);
205 static unsigned int *find_port_pool(const struct tnl_mutable_config *mutable)
207 bool is_multicast = ipv4_is_multicast(mutable->key.daddr);
209 if (mutable->flags & TNL_F_IN_KEY_MATCH) {
210 if (mutable->key.saddr)
211 return &local_remote_ports;
212 else if (is_multicast)
213 return &multicast_ports;
215 return &remote_ports;
217 if (mutable->key.saddr)
218 return &key_local_remote_ports;
219 else if (is_multicast)
220 return &key_multicast_ports;
222 return &key_remote_ports;
226 static u32 port_hash(const struct port_lookup_key *key)
228 return jhash2((u32 *)key, (PORT_KEY_LEN / sizeof(u32)), 0);
231 static struct hlist_head *find_bucket(u32 hash)
233 return &port_table[(hash & (PORT_TABLE_SIZE - 1))];
236 static void port_table_add_port(struct vport *vport)
238 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
239 const struct tnl_mutable_config *mutable;
242 if (port_table_count == 0)
243 schedule_cache_cleaner();
245 mutable = rtnl_dereference(tnl_vport->mutable);
246 hash = port_hash(&mutable->key);
247 hlist_add_head_rcu(&tnl_vport->hash_node, find_bucket(hash));
250 (*find_port_pool(rtnl_dereference(tnl_vport->mutable)))++;
253 static void port_table_move_port(struct vport *vport,
254 struct tnl_mutable_config *new_mutable)
256 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
259 hash = port_hash(&new_mutable->key);
260 hlist_del_init_rcu(&tnl_vport->hash_node);
261 hlist_add_head_rcu(&tnl_vport->hash_node, find_bucket(hash));
263 (*find_port_pool(rtnl_dereference(tnl_vport->mutable)))--;
264 assign_config_rcu(vport, new_mutable);
265 (*find_port_pool(rtnl_dereference(tnl_vport->mutable)))++;
268 static void port_table_remove_port(struct vport *vport)
270 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
272 hlist_del_init_rcu(&tnl_vport->hash_node);
275 if (port_table_count == 0)
276 cancel_delayed_work_sync(&cache_cleaner_wq);
278 (*find_port_pool(rtnl_dereference(tnl_vport->mutable)))--;
281 static struct vport *port_table_lookup(struct port_lookup_key *key,
282 const struct tnl_mutable_config **pmutable)
284 struct hlist_node *n;
285 struct hlist_head *bucket;
286 u32 hash = port_hash(key);
287 struct tnl_vport *tnl_vport;
289 bucket = find_bucket(hash);
291 hlist_for_each_entry_rcu(tnl_vport, n, bucket, hash_node) {
292 struct tnl_mutable_config *mutable;
294 mutable = rcu_dereference_rtnl(tnl_vport->mutable);
295 if (!memcmp(&mutable->key, key, PORT_KEY_LEN)) {
297 return tnl_vport_to_vport(tnl_vport);
304 struct vport *ovs_tnl_find_port(struct net *net, __be32 saddr, __be32 daddr,
305 __be64 key, int tunnel_type,
306 const struct tnl_mutable_config **mutable)
308 struct port_lookup_key lookup;
310 bool is_multicast = ipv4_is_multicast(saddr);
312 port_key_set_net(&lookup, net);
313 lookup.saddr = saddr;
314 lookup.daddr = daddr;
316 /* First try for exact match on in_key. */
318 lookup.tunnel_type = tunnel_type | TNL_T_KEY_EXACT;
319 if (!is_multicast && key_local_remote_ports) {
320 vport = port_table_lookup(&lookup, mutable);
324 if (key_remote_ports) {
326 vport = port_table_lookup(&lookup, mutable);
330 lookup.saddr = saddr;
333 /* Then try matches that wildcard in_key. */
335 lookup.tunnel_type = tunnel_type | TNL_T_KEY_MATCH;
336 if (!is_multicast && local_remote_ports) {
337 vport = port_table_lookup(&lookup, mutable);
343 vport = port_table_lookup(&lookup, mutable);
350 lookup.daddr = saddr;
351 if (key_multicast_ports) {
352 lookup.tunnel_type = tunnel_type | TNL_T_KEY_EXACT;
354 vport = port_table_lookup(&lookup, mutable);
358 if (multicast_ports) {
359 lookup.tunnel_type = tunnel_type | TNL_T_KEY_MATCH;
361 vport = port_table_lookup(&lookup, mutable);
370 static void ecn_decapsulate(struct sk_buff *skb, u8 tos)
372 if (unlikely(INET_ECN_is_ce(tos))) {
373 __be16 protocol = skb->protocol;
375 skb_set_network_header(skb, ETH_HLEN);
377 if (protocol == htons(ETH_P_8021Q)) {
378 if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
381 protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
382 skb_set_network_header(skb, VLAN_ETH_HLEN);
385 if (protocol == htons(ETH_P_IP)) {
386 if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb)
387 + sizeof(struct iphdr))))
390 IP_ECN_set_ce(ip_hdr(skb));
392 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
393 else if (protocol == htons(ETH_P_IPV6)) {
394 if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb)
395 + sizeof(struct ipv6hdr))))
398 IP6_ECN_set_ce(ipv6_hdr(skb));
405 * ovs_tnl_rcv - ingress point for generic tunnel code
407 * @vport: port this packet was received on
408 * @skb: received packet
409 * @tos: ToS from encapsulating IP packet, used to copy ECN bits
411 * Must be called with rcu_read_lock.
413 * Packets received by this function are in the following state:
414 * - skb->data points to the inner Ethernet header.
415 * - The inner Ethernet header is in the linear data area.
416 * - skb->csum does not include the inner Ethernet header.
417 * - The layer pointers are undefined.
419 void ovs_tnl_rcv(struct vport *vport, struct sk_buff *skb, u8 tos)
423 skb_reset_mac_header(skb);
426 if (likely(ntohs(eh->h_proto) >= 1536))
427 skb->protocol = eh->h_proto;
429 skb->protocol = htons(ETH_P_802_2);
433 skb_clear_rxhash(skb);
436 ecn_decapsulate(skb, tos);
437 vlan_set_tci(skb, 0);
439 if (unlikely(compute_ip_summed(skb, false))) {
444 ovs_vport_receive(vport, skb);
447 static bool check_ipv4_address(__be32 addr)
449 if (ipv4_is_multicast(addr) || ipv4_is_lbcast(addr)
450 || ipv4_is_loopback(addr) || ipv4_is_zeronet(addr))
456 static bool ipv4_should_icmp(struct sk_buff *skb)
458 struct iphdr *old_iph = ip_hdr(skb);
460 /* Don't respond to L2 broadcast. */
461 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest))
464 /* Don't respond to L3 broadcast or invalid addresses. */
465 if (!check_ipv4_address(old_iph->daddr) ||
466 !check_ipv4_address(old_iph->saddr))
469 /* Only respond to the first fragment. */
470 if (old_iph->frag_off & htons(IP_OFFSET))
473 /* Don't respond to ICMP error messages. */
474 if (old_iph->protocol == IPPROTO_ICMP) {
475 u8 icmp_type, *icmp_typep;
477 icmp_typep = skb_header_pointer(skb, (u8 *)old_iph +
478 (old_iph->ihl << 2) +
479 offsetof(struct icmphdr, type) -
480 skb->data, sizeof(icmp_type),
486 if (*icmp_typep > NR_ICMP_TYPES
487 || (*icmp_typep <= ICMP_PARAMETERPROB
488 && *icmp_typep != ICMP_ECHOREPLY
489 && *icmp_typep != ICMP_ECHO))
496 static void ipv4_build_icmp(struct sk_buff *skb, struct sk_buff *nskb,
497 unsigned int mtu, unsigned int payload_length)
499 struct iphdr *iph, *old_iph = ip_hdr(skb);
500 struct icmphdr *icmph;
503 iph = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr));
504 icmph = (struct icmphdr *)skb_put(nskb, sizeof(struct icmphdr));
505 payload = skb_put(nskb, payload_length);
509 iph->ihl = sizeof(struct iphdr) >> 2;
510 iph->tos = (old_iph->tos & IPTOS_TOS_MASK) |
511 IPTOS_PREC_INTERNETCONTROL;
512 iph->tot_len = htons(sizeof(struct iphdr)
513 + sizeof(struct icmphdr)
515 get_random_bytes(&iph->id, sizeof(iph->id));
518 iph->protocol = IPPROTO_ICMP;
519 iph->daddr = old_iph->saddr;
520 iph->saddr = old_iph->daddr;
525 icmph->type = ICMP_DEST_UNREACH;
526 icmph->code = ICMP_FRAG_NEEDED;
527 icmph->un.gateway = htonl(mtu);
530 nskb->csum = csum_partial((u8 *)icmph, sizeof(struct icmphdr), 0);
531 nskb->csum = skb_copy_and_csum_bits(skb, (u8 *)old_iph - skb->data,
532 payload, payload_length,
534 icmph->checksum = csum_fold(nskb->csum);
537 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
538 static bool ipv6_should_icmp(struct sk_buff *skb)
540 struct ipv6hdr *old_ipv6h = ipv6_hdr(skb);
542 int payload_off = (u8 *)(old_ipv6h + 1) - skb->data;
543 u8 nexthdr = ipv6_hdr(skb)->nexthdr;
546 /* Check source address is valid. */
547 addr_type = ipv6_addr_type(&old_ipv6h->saddr);
548 if (addr_type & IPV6_ADDR_MULTICAST || addr_type == IPV6_ADDR_ANY)
551 /* Don't reply to unspecified addresses. */
552 if (ipv6_addr_type(&old_ipv6h->daddr) == IPV6_ADDR_ANY)
555 /* Don't respond to ICMP error messages. */
556 payload_off = ipv6_skip_exthdr(skb, payload_off, &nexthdr, &frag_off);
560 if (nexthdr == NEXTHDR_ICMP) {
561 u8 icmp_type, *icmp_typep;
563 icmp_typep = skb_header_pointer(skb, payload_off +
564 offsetof(struct icmp6hdr,
566 sizeof(icmp_type), &icmp_type);
568 if (!icmp_typep || !(*icmp_typep & ICMPV6_INFOMSG_MASK))
575 static void ipv6_build_icmp(struct sk_buff *skb, struct sk_buff *nskb,
576 unsigned int mtu, unsigned int payload_length)
578 struct ipv6hdr *ipv6h, *old_ipv6h = ipv6_hdr(skb);
579 struct icmp6hdr *icmp6h;
582 ipv6h = (struct ipv6hdr *)skb_put(nskb, sizeof(struct ipv6hdr));
583 icmp6h = (struct icmp6hdr *)skb_put(nskb, sizeof(struct icmp6hdr));
584 payload = skb_put(nskb, payload_length);
589 memset(&ipv6h->flow_lbl, 0, sizeof(ipv6h->flow_lbl));
590 ipv6h->payload_len = htons(sizeof(struct icmp6hdr)
592 ipv6h->nexthdr = NEXTHDR_ICMP;
593 ipv6h->hop_limit = IPV6_DEFAULT_HOPLIMIT;
594 ipv6h->daddr = old_ipv6h->saddr;
595 ipv6h->saddr = old_ipv6h->daddr;
598 icmp6h->icmp6_type = ICMPV6_PKT_TOOBIG;
599 icmp6h->icmp6_code = 0;
600 icmp6h->icmp6_cksum = 0;
601 icmp6h->icmp6_mtu = htonl(mtu);
603 nskb->csum = csum_partial((u8 *)icmp6h, sizeof(struct icmp6hdr), 0);
604 nskb->csum = skb_copy_and_csum_bits(skb, (u8 *)old_ipv6h - skb->data,
605 payload, payload_length,
607 icmp6h->icmp6_cksum = csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr,
608 sizeof(struct icmp6hdr)
610 ipv6h->nexthdr, nskb->csum);
614 bool ovs_tnl_frag_needed(struct vport *vport,
615 const struct tnl_mutable_config *mutable,
616 struct sk_buff *skb, unsigned int mtu, __be64 flow_key)
618 unsigned int eth_hdr_len = ETH_HLEN;
619 unsigned int total_length = 0, header_length = 0, payload_length;
620 struct ethhdr *eh, *old_eh = eth_hdr(skb);
621 struct sk_buff *nskb;
624 if (skb->protocol == htons(ETH_P_IP)) {
625 if (mtu < IP_MIN_MTU)
628 if (!ipv4_should_icmp(skb))
631 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
632 else if (skb->protocol == htons(ETH_P_IPV6)) {
633 if (mtu < IPV6_MIN_MTU)
637 * In theory we should do PMTUD on IPv6 multicast messages but
638 * we don't have an address to send from so just fragment.
640 if (ipv6_addr_type(&ipv6_hdr(skb)->daddr) & IPV6_ADDR_MULTICAST)
643 if (!ipv6_should_icmp(skb))
651 if (old_eh->h_proto == htons(ETH_P_8021Q))
652 eth_hdr_len = VLAN_ETH_HLEN;
654 payload_length = skb->len - eth_hdr_len;
655 if (skb->protocol == htons(ETH_P_IP)) {
656 header_length = sizeof(struct iphdr) + sizeof(struct icmphdr);
657 total_length = min_t(unsigned int, header_length +
658 payload_length, 576);
660 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
662 header_length = sizeof(struct ipv6hdr) +
663 sizeof(struct icmp6hdr);
664 total_length = min_t(unsigned int, header_length +
665 payload_length, IPV6_MIN_MTU);
669 payload_length = total_length - header_length;
671 nskb = dev_alloc_skb(NET_IP_ALIGN + eth_hdr_len + header_length +
676 skb_reserve(nskb, NET_IP_ALIGN);
678 /* Ethernet / VLAN */
679 eh = (struct ethhdr *)skb_put(nskb, eth_hdr_len);
680 memcpy(eh->h_dest, old_eh->h_source, ETH_ALEN);
681 memcpy(eh->h_source, mutable->eth_addr, ETH_ALEN);
682 nskb->protocol = eh->h_proto = old_eh->h_proto;
683 if (old_eh->h_proto == htons(ETH_P_8021Q)) {
684 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)eh;
686 vh->h_vlan_TCI = vlan_eth_hdr(skb)->h_vlan_TCI;
687 vh->h_vlan_encapsulated_proto = skb->protocol;
689 vlan_set_tci(nskb, vlan_get_tci(skb));
690 skb_reset_mac_header(nskb);
693 if (skb->protocol == htons(ETH_P_IP))
694 ipv4_build_icmp(skb, nskb, mtu, payload_length);
695 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
697 ipv6_build_icmp(skb, nskb, mtu, payload_length);
701 * Assume that flow based keys are symmetric with respect to input
702 * and output and use the key that we were going to put on the
703 * outgoing packet for the fake received packet. If the keys are
704 * not symmetric then PMTUD needs to be disabled since we won't have
705 * any way of synthesizing packets.
707 if ((mutable->flags & (TNL_F_IN_KEY_MATCH | TNL_F_OUT_KEY_ACTION)) ==
708 (TNL_F_IN_KEY_MATCH | TNL_F_OUT_KEY_ACTION))
709 OVS_CB(nskb)->tun_id = flow_key;
711 if (unlikely(compute_ip_summed(nskb, false))) {
716 ovs_vport_receive(vport, nskb);
721 static bool check_mtu(struct sk_buff *skb,
723 const struct tnl_mutable_config *mutable,
724 const struct rtable *rt, __be16 *frag_offp)
726 bool df_inherit = mutable->flags & TNL_F_DF_INHERIT;
727 bool pmtud = mutable->flags & TNL_F_PMTUD;
728 __be16 frag_off = mutable->flags & TNL_F_DF_DEFAULT ? htons(IP_DF) : 0;
730 unsigned int packet_length = skb->len - ETH_HLEN;
732 /* Allow for one level of tagging in the packet length. */
733 if (!vlan_tx_tag_present(skb) &&
734 eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
735 packet_length -= VLAN_HLEN;
740 /* The tag needs to go in packet regardless of where it
741 * currently is, so subtract it from the MTU.
743 if (vlan_tx_tag_present(skb) ||
744 eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
745 vlan_header = VLAN_HLEN;
747 mtu = dst_mtu(&rt_dst(rt))
749 - mutable->tunnel_hlen
753 if (skb->protocol == htons(ETH_P_IP)) {
754 struct iphdr *iph = ip_hdr(skb);
757 frag_off = iph->frag_off & htons(IP_DF);
759 if (pmtud && iph->frag_off & htons(IP_DF)) {
760 mtu = max(mtu, IP_MIN_MTU);
762 if (packet_length > mtu &&
763 ovs_tnl_frag_needed(vport, mutable, skb, mtu,
764 OVS_CB(skb)->tun_id))
768 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
769 else if (skb->protocol == htons(ETH_P_IPV6)) {
770 /* IPv6 requires end hosts to do fragmentation
771 * if the packet is above the minimum MTU.
773 if (df_inherit && packet_length > IPV6_MIN_MTU)
774 frag_off = htons(IP_DF);
777 mtu = max(mtu, IPV6_MIN_MTU);
779 if (packet_length > mtu &&
780 ovs_tnl_frag_needed(vport, mutable, skb, mtu,
781 OVS_CB(skb)->tun_id))
787 *frag_offp = frag_off;
791 static void create_tunnel_header(const struct vport *vport,
792 const struct tnl_mutable_config *mutable,
793 const struct rtable *rt, void *header)
795 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
796 struct iphdr *iph = header;
799 iph->ihl = sizeof(struct iphdr) >> 2;
800 iph->frag_off = htons(IP_DF);
801 iph->protocol = tnl_vport->tnl_ops->ipproto;
802 iph->tos = mutable->tos;
803 iph->daddr = rt->rt_dst;
804 iph->saddr = rt->rt_src;
805 iph->ttl = mutable->ttl;
807 iph->ttl = ip4_dst_hoplimit(&rt_dst(rt));
809 tnl_vport->tnl_ops->build_header(vport, mutable, iph + 1);
812 static void *get_cached_header(const struct tnl_cache *cache)
814 return (void *)cache + ALIGN(sizeof(struct tnl_cache), CACHE_DATA_ALIGN);
818 static inline int rt_genid(struct net *net)
820 return atomic_read(&net->ipv4.rt_genid);
824 static bool check_cache_valid(const struct tnl_cache *cache,
825 const struct tnl_mutable_config *mutable)
832 hh = rt_hh(cache->rt);
834 #ifdef NEED_CACHE_TIMEOUT
835 time_before(jiffies, cache->expiration) &&
838 rt_genid(dev_net(rt_dst(cache->rt).dev)) == cache->rt->rt_genid &&
841 hh->hh_lock.sequence == cache->hh_seq &&
843 mutable->seq == cache->mutable_seq &&
844 (!ovs_is_internal_dev(rt_dst(cache->rt).dev) ||
845 (cache->flow && !cache->flow->dead));
848 static void __cache_cleaner(struct tnl_vport *tnl_vport)
850 const struct tnl_mutable_config *mutable =
851 rcu_dereference(tnl_vport->mutable);
852 const struct tnl_cache *cache = rcu_dereference(tnl_vport->cache);
854 if (cache && !check_cache_valid(cache, mutable) &&
855 spin_trylock_bh(&tnl_vport->cache_lock)) {
856 assign_cache_rcu(tnl_vport_to_vport(tnl_vport), NULL);
857 spin_unlock_bh(&tnl_vport->cache_lock);
861 static void cache_cleaner(struct work_struct *work)
865 schedule_cache_cleaner();
868 for (i = 0; i < PORT_TABLE_SIZE; i++) {
869 struct hlist_node *n;
870 struct hlist_head *bucket;
871 struct tnl_vport *tnl_vport;
873 bucket = &port_table[i];
874 hlist_for_each_entry_rcu(tnl_vport, n, bucket, hash_node)
875 __cache_cleaner(tnl_vport);
880 static void create_eth_hdr(struct tnl_cache *cache, struct hh_cache *hh)
882 void *cache_data = get_cached_header(cache);
889 hh_seq = read_seqbegin(&hh->hh_lock);
890 hh_off = HH_DATA_ALIGN(hh->hh_len) - hh->hh_len;
891 memcpy(cache_data, (void *)hh->hh_data + hh_off, hh->hh_len);
892 cache->hh_len = hh->hh_len;
893 } while (read_seqretry(&hh->hh_lock, hh_seq));
895 cache->hh_seq = hh_seq;
897 read_lock(&hh->hh_lock);
898 hh_off = HH_DATA_ALIGN(hh->hh_len) - hh->hh_len;
899 memcpy(cache_data, (void *)hh->hh_data + hh_off, hh->hh_len);
900 cache->hh_len = hh->hh_len;
901 read_unlock(&hh->hh_lock);
905 static struct tnl_cache *build_cache(struct vport *vport,
906 const struct tnl_mutable_config *mutable,
909 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
910 struct tnl_cache *cache;
915 if (!(mutable->flags & TNL_F_HDR_CACHE))
919 * If there is no entry in the ARP cache or if this device does not
920 * support hard header caching just fall back to the IP stack.
928 * If lock is contended fall back to directly building the header.
929 * We're not going to help performance by sitting here spinning.
931 if (!spin_trylock(&tnl_vport->cache_lock))
934 cache = cache_dereference(tnl_vport);
935 if (check_cache_valid(cache, mutable))
940 cache_len = LL_RESERVED_SPACE(rt_dst(rt).dev) + mutable->tunnel_hlen;
942 cache = kzalloc(ALIGN(sizeof(struct tnl_cache), CACHE_DATA_ALIGN) +
943 cache_len, GFP_ATOMIC);
947 create_eth_hdr(cache, hh);
948 cache_data = get_cached_header(cache) + cache->hh_len;
949 cache->len = cache->hh_len + mutable->tunnel_hlen;
951 create_tunnel_header(vport, mutable, rt, cache_data);
953 cache->mutable_seq = mutable->seq;
955 #ifdef NEED_CACHE_TIMEOUT
956 cache->expiration = jiffies + tnl_vport->cache_exp_interval;
959 if (ovs_is_internal_dev(rt_dst(rt).dev)) {
960 struct sw_flow_key flow_key;
961 struct vport *dst_vport;
965 struct sw_flow *flow;
967 dst_vport = ovs_internal_dev_get_vport(rt_dst(rt).dev);
971 skb = alloc_skb(cache->len, GFP_ATOMIC);
975 __skb_put(skb, cache->len);
976 memcpy(skb->data, get_cached_header(cache), cache->len);
978 err = ovs_flow_extract(skb, dst_vport->port_no, &flow_key,
985 flow = ovs_flow_tbl_lookup(rcu_dereference(dst_vport->dp->table),
986 &flow_key, flow_key_len);
994 assign_cache_rcu(vport, cache);
997 spin_unlock(&tnl_vport->cache_lock);
1002 static struct rtable *__find_route(const struct tnl_mutable_config *mutable,
1005 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
1006 struct flowi fl = { .nl_u = { .ip4_u = {
1007 .daddr = mutable->key.daddr,
1008 .saddr = mutable->key.saddr,
1013 if (unlikely(ip_route_output_key(port_key_get_net(&mutable->key), &rt, &fl)))
1014 return ERR_PTR(-EADDRNOTAVAIL);
1018 struct flowi4 fl = { .daddr = mutable->key.daddr,
1019 .saddr = mutable->key.saddr,
1021 .flowi4_proto = ipproto };
1023 return ip_route_output_key(port_key_get_net(&mutable->key), &fl);
1027 static struct rtable *find_route(struct vport *vport,
1028 const struct tnl_mutable_config *mutable,
1029 u8 tos, struct tnl_cache **cache)
1031 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1032 struct tnl_cache *cur_cache = rcu_dereference(tnl_vport->cache);
1037 if (likely(tos == mutable->tos &&
1038 check_cache_valid(cur_cache, mutable))) {
1040 return cur_cache->rt;
1044 rt = __find_route(mutable, tnl_vport->tnl_ops->ipproto, tos);
1048 if (likely(tos == mutable->tos))
1049 *cache = build_cache(vport, mutable, rt);
1055 static bool need_linearize(const struct sk_buff *skb)
1059 if (unlikely(skb_shinfo(skb)->frag_list))
1063 * Generally speaking we should linearize if there are paged frags.
1064 * However, if all of the refcounts are 1 we know nobody else can
1065 * change them from underneath us and we can skip the linearization.
1067 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1068 if (unlikely(page_count(skb_frag_page(&skb_shinfo(skb)->frags[i])) > 1))
1074 static struct sk_buff *handle_offloads(struct sk_buff *skb,
1075 const struct tnl_mutable_config *mutable,
1076 const struct rtable *rt)
1081 min_headroom = LL_RESERVED_SPACE(rt_dst(rt).dev) + rt_dst(rt).header_len
1082 + mutable->tunnel_hlen
1083 + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
1085 if (skb_headroom(skb) < min_headroom || skb_header_cloned(skb)) {
1086 int head_delta = SKB_DATA_ALIGN(min_headroom -
1089 err = pskb_expand_head(skb, max_t(int, head_delta, 0),
1095 forward_ip_summed(skb, true);
1097 if (skb_is_gso(skb)) {
1098 struct sk_buff *nskb;
1100 nskb = skb_gso_segment(skb, 0);
1103 err = PTR_ERR(nskb);
1109 } else if (get_ip_summed(skb) == OVS_CSUM_PARTIAL) {
1110 /* Pages aren't locked and could change at any time.
1111 * If this happens after we compute the checksum, the
1112 * checksum will be wrong. We linearize now to avoid
1115 if (unlikely(need_linearize(skb))) {
1116 err = __skb_linearize(skb);
1121 err = skb_checksum_help(skb);
1126 set_ip_summed(skb, OVS_CSUM_NONE);
1133 return ERR_PTR(err);
1136 static int send_frags(struct sk_buff *skb,
1137 const struct tnl_mutable_config *mutable)
1143 struct sk_buff *next = skb->next;
1144 int frag_len = skb->len - mutable->tunnel_hlen;
1148 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
1150 err = ip_local_out(skb);
1152 if (unlikely(net_xmit_eval(err)))
1154 sent_len += frag_len;
1161 * There's no point in continuing to send fragments once one has been
1162 * dropped so just free the rest. This may help improve the congestion
1163 * that caused the first packet to be dropped.
1165 ovs_tnl_free_linked_skbs(skb);
1169 int ovs_tnl_send(struct vport *vport, struct sk_buff *skb)
1171 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1172 const struct tnl_mutable_config *mutable = rcu_dereference(tnl_vport->mutable);
1174 enum vport_err_type err = VPORT_E_TX_ERROR;
1176 struct dst_entry *unattached_dst = NULL;
1177 struct tnl_cache *cache;
1179 __be16 frag_off = 0;
1184 /* Validate the protocol headers before we try to use them. */
1185 if (skb->protocol == htons(ETH_P_8021Q) &&
1186 !vlan_tx_tag_present(skb)) {
1187 if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
1190 skb->protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
1191 skb_set_network_header(skb, VLAN_ETH_HLEN);
1194 if (skb->protocol == htons(ETH_P_IP)) {
1195 if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb)
1196 + sizeof(struct iphdr))))
1199 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1200 else if (skb->protocol == htons(ETH_P_IPV6)) {
1201 if (unlikely(!pskb_may_pull(skb, skb_network_offset(skb)
1202 + sizeof(struct ipv6hdr))))
1208 if (skb->protocol == htons(ETH_P_IP))
1209 inner_tos = ip_hdr(skb)->tos;
1210 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1211 else if (skb->protocol == htons(ETH_P_IPV6))
1212 inner_tos = ipv6_get_dsfield(ipv6_hdr(skb));
1217 if (mutable->flags & TNL_F_TOS_INHERIT)
1222 tos = INET_ECN_encapsulate(tos, inner_tos);
1225 rt = find_route(vport, mutable, tos, &cache);
1228 if (unlikely(!cache))
1229 unattached_dst = &rt_dst(rt);
1235 skb_clear_rxhash(skb);
1238 skb = handle_offloads(skb, mutable, rt);
1243 if (unlikely(!check_mtu(skb, vport, mutable, rt, &frag_off))) {
1244 err = VPORT_E_TX_DROPPED;
1249 * If we are over the MTU, allow the IP stack to handle fragmentation.
1250 * Fragmentation is a slow path anyways.
1252 if (unlikely(skb->len + mutable->tunnel_hlen > dst_mtu(&rt_dst(rt)) &&
1254 unattached_dst = &rt_dst(rt);
1255 dst_hold(unattached_dst);
1262 ttl = ip4_dst_hoplimit(&rt_dst(rt));
1264 if (mutable->flags & TNL_F_TTL_INHERIT) {
1265 if (skb->protocol == htons(ETH_P_IP))
1266 ttl = ip_hdr(skb)->ttl;
1267 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1268 else if (skb->protocol == htons(ETH_P_IPV6))
1269 ttl = ipv6_hdr(skb)->hop_limit;
1275 struct sk_buff *next_skb = skb->next;
1278 if (unlikely(vlan_deaccel_tag(skb)))
1281 if (likely(cache)) {
1282 skb_push(skb, cache->len);
1283 memcpy(skb->data, get_cached_header(cache), cache->len);
1284 skb_reset_mac_header(skb);
1285 skb_set_network_header(skb, cache->hh_len);
1288 skb_push(skb, mutable->tunnel_hlen);
1289 create_tunnel_header(vport, mutable, rt, skb->data);
1290 skb_reset_network_header(skb);
1293 skb_dst_set(skb, dst_clone(unattached_dst));
1295 skb_dst_set(skb, unattached_dst);
1296 unattached_dst = NULL;
1299 skb_set_transport_header(skb, skb_network_offset(skb) + sizeof(struct iphdr));
1304 iph->frag_off = frag_off;
1305 ip_select_ident(iph, &rt_dst(rt), NULL);
1307 skb = tnl_vport->tnl_ops->update_header(vport, mutable,
1312 if (likely(cache)) {
1313 int orig_len = skb->len - cache->len;
1314 struct vport *cache_vport;
1316 cache_vport = ovs_internal_dev_get_vport(rt_dst(rt).dev);
1317 skb->protocol = htons(ETH_P_IP);
1319 iph->tot_len = htons(skb->len - skb_network_offset(skb));
1323 if (unlikely(compute_ip_summed(skb, true))) {
1328 OVS_CB(skb)->flow = cache->flow;
1329 ovs_vport_receive(cache_vport, skb);
1330 sent_len += orig_len;
1334 skb->dev = rt_dst(rt).dev;
1335 xmit_err = dev_queue_xmit(skb);
1337 if (likely(net_xmit_eval(xmit_err) == 0))
1338 sent_len += orig_len;
1341 sent_len += send_frags(skb, mutable);
1347 if (unlikely(sent_len == 0))
1348 ovs_vport_record_error(vport, VPORT_E_TX_DROPPED);
1353 ovs_tnl_free_linked_skbs(skb);
1355 ovs_vport_record_error(vport, err);
1357 dst_release(unattached_dst);
1361 static const struct nla_policy tnl_policy[OVS_TUNNEL_ATTR_MAX + 1] = {
1362 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NLA_U32 },
1363 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NLA_U32 },
1364 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NLA_U32 },
1365 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NLA_U64 },
1366 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NLA_U64 },
1367 [OVS_TUNNEL_ATTR_TOS] = { .type = NLA_U8 },
1368 [OVS_TUNNEL_ATTR_TTL] = { .type = NLA_U8 },
1371 /* Sets OVS_TUNNEL_ATTR_* fields in 'mutable', which must initially be
1373 static int tnl_set_config(struct net *net, struct nlattr *options,
1374 const struct tnl_ops *tnl_ops,
1375 const struct vport *cur_vport,
1376 struct tnl_mutable_config *mutable)
1378 const struct vport *old_vport;
1379 const struct tnl_mutable_config *old_mutable;
1380 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
1386 err = nla_parse_nested(a, OVS_TUNNEL_ATTR_MAX, options, tnl_policy);
1390 if (!a[OVS_TUNNEL_ATTR_FLAGS] || !a[OVS_TUNNEL_ATTR_DST_IPV4])
1393 mutable->flags = nla_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_PUBLIC;
1395 port_key_set_net(&mutable->key, net);
1396 mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
1397 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
1398 if (ipv4_is_multicast(mutable->key.daddr))
1400 mutable->key.saddr = nla_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
1403 if (a[OVS_TUNNEL_ATTR_TOS]) {
1404 mutable->tos = nla_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
1405 if (mutable->tos != RT_TOS(mutable->tos))
1409 if (a[OVS_TUNNEL_ATTR_TTL])
1410 mutable->ttl = nla_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
1412 mutable->key.tunnel_type = tnl_ops->tunnel_type;
1413 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
1414 mutable->key.tunnel_type |= TNL_T_KEY_MATCH;
1415 mutable->flags |= TNL_F_IN_KEY_MATCH;
1417 mutable->key.tunnel_type |= TNL_T_KEY_EXACT;
1418 mutable->key.in_key = nla_get_be64(a[OVS_TUNNEL_ATTR_IN_KEY]);
1421 if (!a[OVS_TUNNEL_ATTR_OUT_KEY])
1422 mutable->flags |= TNL_F_OUT_KEY_ACTION;
1424 mutable->out_key = nla_get_be64(a[OVS_TUNNEL_ATTR_OUT_KEY]);
1426 mutable->tunnel_hlen = tnl_ops->hdr_len(mutable);
1427 if (mutable->tunnel_hlen < 0)
1428 return mutable->tunnel_hlen;
1430 mutable->tunnel_hlen += sizeof(struct iphdr);
1432 old_vport = port_table_lookup(&mutable->key, &old_mutable);
1433 if (old_vport && old_vport != cur_vport)
1437 if (ipv4_is_multicast(mutable->key.daddr)) {
1438 struct net_device *dev;
1441 rt = __find_route(mutable, tnl_ops->ipproto, mutable->tos);
1443 return -EADDRNOTAVAIL;
1444 dev = rt_dst(rt).dev;
1446 if (__in_dev_get_rtnl(dev) == NULL)
1447 return -EADDRNOTAVAIL;
1448 mutable->mlink = dev->ifindex;
1449 ip_mc_inc_group(__in_dev_get_rtnl(dev), mutable->key.daddr);
1455 struct vport *ovs_tnl_create(const struct vport_parms *parms,
1456 const struct vport_ops *vport_ops,
1457 const struct tnl_ops *tnl_ops)
1459 struct vport *vport;
1460 struct tnl_vport *tnl_vport;
1461 struct tnl_mutable_config *mutable;
1462 int initial_frag_id;
1465 vport = ovs_vport_alloc(sizeof(struct tnl_vport), vport_ops, parms);
1466 if (IS_ERR(vport)) {
1467 err = PTR_ERR(vport);
1471 tnl_vport = tnl_vport_priv(vport);
1473 strcpy(tnl_vport->name, parms->name);
1474 tnl_vport->tnl_ops = tnl_ops;
1476 mutable = kzalloc(sizeof(struct tnl_mutable_config), GFP_KERNEL);
1479 goto error_free_vport;
1482 random_ether_addr(mutable->eth_addr);
1484 get_random_bytes(&initial_frag_id, sizeof(int));
1485 atomic_set(&tnl_vport->frag_id, initial_frag_id);
1487 err = tnl_set_config(ovs_dp_get_net(parms->dp), parms->options, tnl_ops,
1490 goto error_free_mutable;
1492 spin_lock_init(&tnl_vport->cache_lock);
1494 #ifdef NEED_CACHE_TIMEOUT
1495 tnl_vport->cache_exp_interval = MAX_CACHE_EXP -
1496 (net_random() % (MAX_CACHE_EXP / 2));
1499 rcu_assign_pointer(tnl_vport->mutable, mutable);
1501 port_table_add_port(vport);
1505 free_mutable_rtnl(mutable);
1508 ovs_vport_free(vport);
1510 return ERR_PTR(err);
1513 int ovs_tnl_set_options(struct vport *vport, struct nlattr *options)
1515 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1516 const struct tnl_mutable_config *old_mutable;
1517 struct tnl_mutable_config *mutable;
1520 mutable = kzalloc(sizeof(struct tnl_mutable_config), GFP_KERNEL);
1526 /* Copy fields whose values should be retained. */
1527 old_mutable = rtnl_dereference(tnl_vport->mutable);
1528 mutable->seq = old_mutable->seq + 1;
1529 memcpy(mutable->eth_addr, old_mutable->eth_addr, ETH_ALEN);
1531 /* Parse the others configured by userspace. */
1532 err = tnl_set_config(ovs_dp_get_net(vport->dp), options, tnl_vport->tnl_ops,
1537 if (port_hash(&mutable->key) != port_hash(&old_mutable->key))
1538 port_table_move_port(vport, mutable);
1540 assign_config_rcu(vport, mutable);
1545 free_mutable_rtnl(mutable);
1551 int ovs_tnl_get_options(const struct vport *vport, struct sk_buff *skb)
1553 const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1554 const struct tnl_mutable_config *mutable = rcu_dereference_rtnl(tnl_vport->mutable);
1556 if (nla_put_u32(skb, OVS_TUNNEL_ATTR_FLAGS,
1557 mutable->flags & TNL_F_PUBLIC) ||
1558 nla_put_be32(skb, OVS_TUNNEL_ATTR_DST_IPV4, mutable->key.daddr))
1559 goto nla_put_failure;
1561 if (!(mutable->flags & TNL_F_IN_KEY_MATCH) &&
1562 nla_put_be64(skb, OVS_TUNNEL_ATTR_IN_KEY, mutable->key.in_key))
1563 goto nla_put_failure;
1564 if (!(mutable->flags & TNL_F_OUT_KEY_ACTION) &&
1565 nla_put_be64(skb, OVS_TUNNEL_ATTR_OUT_KEY, mutable->out_key))
1566 goto nla_put_failure;
1567 if (mutable->key.saddr &&
1568 nla_put_be32(skb, OVS_TUNNEL_ATTR_SRC_IPV4, mutable->key.saddr))
1569 goto nla_put_failure;
1570 if (mutable->tos && nla_put_u8(skb, OVS_TUNNEL_ATTR_TOS, mutable->tos))
1571 goto nla_put_failure;
1572 if (mutable->ttl && nla_put_u8(skb, OVS_TUNNEL_ATTR_TTL, mutable->ttl))
1573 goto nla_put_failure;
1581 static void free_port_rcu(struct rcu_head *rcu)
1583 struct tnl_vport *tnl_vport = container_of(rcu,
1584 struct tnl_vport, rcu);
1586 free_cache((struct tnl_cache __force *)tnl_vport->cache);
1587 kfree((struct tnl_mutable __force *)tnl_vport->mutable);
1588 ovs_vport_free(tnl_vport_to_vport(tnl_vport));
1591 void ovs_tnl_destroy(struct vport *vport)
1593 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1594 struct tnl_mutable_config *mutable;
1596 mutable = rtnl_dereference(tnl_vport->mutable);
1597 port_table_remove_port(vport);
1598 free_mutable_rtnl(mutable);
1599 call_rcu(&tnl_vport->rcu, free_port_rcu);
1602 int ovs_tnl_set_addr(struct vport *vport, const unsigned char *addr)
1604 struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1605 struct tnl_mutable_config *old_mutable, *mutable;
1607 old_mutable = rtnl_dereference(tnl_vport->mutable);
1608 mutable = kmemdup(old_mutable, sizeof(struct tnl_mutable_config), GFP_KERNEL);
1612 old_mutable->mlink = 0;
1614 memcpy(mutable->eth_addr, addr, ETH_ALEN);
1615 assign_config_rcu(vport, mutable);
1620 const char *ovs_tnl_get_name(const struct vport *vport)
1622 const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1623 return tnl_vport->name;
1626 const unsigned char *ovs_tnl_get_addr(const struct vport *vport)
1628 const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
1629 return rcu_dereference_rtnl(tnl_vport->mutable)->eth_addr;
1632 void ovs_tnl_free_linked_skbs(struct sk_buff *skb)
1635 struct sk_buff *next = skb->next;
1641 int ovs_tnl_init(void)
1645 port_table = kmalloc(PORT_TABLE_SIZE * sizeof(struct hlist_head *),
1650 for (i = 0; i < PORT_TABLE_SIZE; i++)
1651 INIT_HLIST_HEAD(&port_table[i]);
1656 void ovs_tnl_exit(void)