stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1 | /* |
Rami Rosen | eb5ce43 | 2012-11-13 13:29:15 +0000 | [diff] [blame] | 2 | * VXLAN: Virtual eXtensible Local Area Network |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 3 | * |
stephen hemminger | 3b8df3c | 2013-04-27 11:31:52 +0000 | [diff] [blame] | 4 | * Copyright (c) 2012-2013 Vyatta Inc. |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * TODO |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 11 | * - IPv6 (not in RFC) |
| 12 | */ |
| 13 | |
| 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/rculist.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/in.h> |
| 25 | #include <linux/ip.h> |
| 26 | #include <linux/udp.h> |
| 27 | #include <linux/igmp.h> |
| 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/if_ether.h> |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 30 | #include <linux/hash.h> |
Yan Burman | 1b13c97 | 2013-01-29 23:43:07 +0000 | [diff] [blame] | 31 | #include <linux/ethtool.h> |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 32 | #include <net/arp.h> |
| 33 | #include <net/ndisc.h> |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 34 | #include <net/ip.h> |
Pravin B Shelar | c544193 | 2013-03-25 14:49:35 +0000 | [diff] [blame] | 35 | #include <net/ip_tunnels.h> |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 36 | #include <net/icmp.h> |
| 37 | #include <net/udp.h> |
| 38 | #include <net/rtnetlink.h> |
| 39 | #include <net/route.h> |
| 40 | #include <net/dsfield.h> |
| 41 | #include <net/inet_ecn.h> |
| 42 | #include <net/net_namespace.h> |
| 43 | #include <net/netns/generic.h> |
| 44 | |
| 45 | #define VXLAN_VERSION "0.1" |
| 46 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 47 | #define PORT_HASH_BITS 8 |
| 48 | #define PORT_HASH_SIZE (1<<PORT_HASH_BITS) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 49 | #define VNI_HASH_BITS 10 |
| 50 | #define VNI_HASH_SIZE (1<<VNI_HASH_BITS) |
| 51 | #define FDB_HASH_BITS 8 |
| 52 | #define FDB_HASH_SIZE (1<<FDB_HASH_BITS) |
| 53 | #define FDB_AGE_DEFAULT 300 /* 5 min */ |
| 54 | #define FDB_AGE_INTERVAL (10 * HZ) /* rescan interval */ |
| 55 | |
| 56 | #define VXLAN_N_VID (1u << 24) |
| 57 | #define VXLAN_VID_MASK (VXLAN_N_VID - 1) |
Alexander Duyck | 52b702f | 2012-11-09 13:35:24 +0000 | [diff] [blame] | 58 | /* IP header + UDP + VXLAN + Ethernet header */ |
| 59 | #define VXLAN_HEADROOM (20 + 8 + 8 + 14) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 60 | |
| 61 | #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ |
| 62 | |
| 63 | /* VXLAN protocol header */ |
| 64 | struct vxlanhdr { |
| 65 | __be32 vx_flags; |
| 66 | __be32 vx_vni; |
| 67 | }; |
| 68 | |
stephen hemminger | 23c578b | 2013-04-27 11:31:53 +0000 | [diff] [blame] | 69 | /* UDP port for VXLAN traffic. |
| 70 | * The IANA assigned port is 4789, but the Linux default is 8472 |
Stephen Hemminger | 234f5b7 | 2013-06-17 14:16:41 -0700 | [diff] [blame] | 71 | * for compatibility with early adopters. |
stephen hemminger | 23c578b | 2013-04-27 11:31:53 +0000 | [diff] [blame] | 72 | */ |
Stephen Hemminger | 9daaa39 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 73 | static unsigned short vxlan_port __read_mostly = 8472; |
| 74 | module_param_named(udp_port, vxlan_port, ushort, 0444); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 75 | MODULE_PARM_DESC(udp_port, "Destination UDP port"); |
| 76 | |
| 77 | static bool log_ecn_error = true; |
| 78 | module_param(log_ecn_error, bool, 0644); |
| 79 | MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); |
| 80 | |
Pravin B Shelar | 60d9d4c | 2013-06-20 00:26:31 -0700 | [diff] [blame] | 81 | static int vxlan_net_id; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 82 | |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 83 | static const u8 all_zeros_mac[ETH_ALEN]; |
| 84 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 85 | /* per UDP socket information */ |
| 86 | struct vxlan_sock { |
| 87 | struct hlist_node hlist; |
| 88 | struct rcu_head rcu; |
| 89 | struct work_struct del_work; |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 90 | atomic_t refcnt; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 91 | struct socket *sock; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 92 | struct hlist_head vni_list[VNI_HASH_SIZE]; |
| 93 | }; |
| 94 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 95 | /* per-network namespace private data for this module */ |
| 96 | struct vxlan_net { |
| 97 | struct list_head vxlan_list; |
| 98 | struct hlist_head sock_list[PORT_HASH_SIZE]; |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 99 | spinlock_t sock_lock; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 102 | struct vxlan_rdst { |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 103 | __be32 remote_ip; |
| 104 | __be16 remote_port; |
| 105 | u32 remote_vni; |
| 106 | u32 remote_ifindex; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 107 | struct list_head list; |
Mike Rapoport | bc7892b | 2013-06-25 16:01:54 +0300 | [diff] [blame] | 108 | struct rcu_head rcu; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 111 | /* Forwarding table entry */ |
| 112 | struct vxlan_fdb { |
| 113 | struct hlist_node hlist; /* linked list of entries */ |
| 114 | struct rcu_head rcu; |
| 115 | unsigned long updated; /* jiffies */ |
| 116 | unsigned long used; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 117 | struct list_head remotes; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 118 | u16 state; /* see ndm_state */ |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 119 | u8 flags; /* see ndm_flags */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 120 | u8 eth_addr[ETH_ALEN]; |
| 121 | }; |
| 122 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 123 | /* Pseudo network device */ |
| 124 | struct vxlan_dev { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 125 | struct hlist_node hlist; /* vni hash table */ |
| 126 | struct list_head next; /* vxlan's per namespace list */ |
| 127 | struct vxlan_sock *vn_sock; /* listening socket */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 128 | struct net_device *dev; |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 129 | struct vxlan_rdst default_dst; /* default destination */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 130 | __be32 saddr; /* source address */ |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 131 | __be16 dst_port; |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 132 | __u16 port_min; /* source port range */ |
| 133 | __u16 port_max; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 134 | __u8 tos; /* TOS override */ |
| 135 | __u8 ttl; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 136 | u32 flags; /* VXLAN_F_* below */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 137 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 138 | struct work_struct sock_work; |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 139 | struct work_struct igmp_work; |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 140 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 141 | unsigned long age_interval; |
| 142 | struct timer_list age_timer; |
| 143 | spinlock_t hash_lock; |
| 144 | unsigned int addrcnt; |
| 145 | unsigned int addrmax; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 146 | |
| 147 | struct hlist_head fdb_head[FDB_HASH_SIZE]; |
| 148 | }; |
| 149 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 150 | #define VXLAN_F_LEARN 0x01 |
| 151 | #define VXLAN_F_PROXY 0x02 |
| 152 | #define VXLAN_F_RSC 0x04 |
| 153 | #define VXLAN_F_L2MISS 0x08 |
| 154 | #define VXLAN_F_L3MISS 0x10 |
| 155 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 156 | /* salt for hash table */ |
| 157 | static u32 vxlan_salt __read_mostly; |
Stephen Hemminger | 758c57d | 2013-06-17 14:16:09 -0700 | [diff] [blame] | 158 | static struct workqueue_struct *vxlan_wq; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 159 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 160 | static void vxlan_sock_work(struct work_struct *work); |
| 161 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 162 | /* Virtual Network hash table head */ |
| 163 | static inline struct hlist_head *vni_head(struct vxlan_sock *vs, u32 id) |
| 164 | { |
| 165 | return &vs->vni_list[hash_32(id, VNI_HASH_BITS)]; |
| 166 | } |
| 167 | |
| 168 | /* Socket hash table head */ |
| 169 | static inline struct hlist_head *vs_head(struct net *net, __be16 port) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 170 | { |
| 171 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
| 172 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 173 | return &vn->sock_list[hash_32(ntohs(port), PORT_HASH_BITS)]; |
| 174 | } |
| 175 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 176 | /* First remote destination for a forwarding entry. |
| 177 | * Guaranteed to be non-NULL because remotes are never deleted. |
| 178 | */ |
| 179 | static inline struct vxlan_rdst *first_remote(struct vxlan_fdb *fdb) |
| 180 | { |
| 181 | return list_first_or_null_rcu(&fdb->remotes, struct vxlan_rdst, list); |
| 182 | } |
| 183 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 184 | /* Find VXLAN socket based on network namespace and UDP port */ |
| 185 | static struct vxlan_sock *vxlan_find_port(struct net *net, __be16 port) |
| 186 | { |
| 187 | struct vxlan_sock *vs; |
| 188 | |
| 189 | hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) { |
| 190 | if (inet_sk(vs->sock->sk)->inet_sport == port) |
| 191 | return vs; |
| 192 | } |
| 193 | return NULL; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* Look up VNI in a per net namespace table */ |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 197 | static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id, __be16 port) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 198 | { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 199 | struct vxlan_sock *vs; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 200 | struct vxlan_dev *vxlan; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 201 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 202 | vs = vxlan_find_port(net, port); |
| 203 | if (!vs) |
| 204 | return NULL; |
| 205 | |
| 206 | hlist_for_each_entry_rcu(vxlan, vni_head(vs, id), hlist) { |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 207 | if (vxlan->default_dst.remote_vni == id) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 208 | return vxlan; |
| 209 | } |
| 210 | |
| 211 | return NULL; |
| 212 | } |
| 213 | |
| 214 | /* Fill in neighbour message in skbuff. */ |
| 215 | static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, |
Stephen Hemminger | 234f5b7 | 2013-06-17 14:16:41 -0700 | [diff] [blame] | 216 | const struct vxlan_fdb *fdb, |
| 217 | u32 portid, u32 seq, int type, unsigned int flags, |
| 218 | const struct vxlan_rdst *rdst) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 219 | { |
| 220 | unsigned long now = jiffies; |
| 221 | struct nda_cacheinfo ci; |
| 222 | struct nlmsghdr *nlh; |
| 223 | struct ndmsg *ndm; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 224 | bool send_ip, send_eth; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 225 | |
| 226 | nlh = nlmsg_put(skb, portid, seq, type, sizeof(*ndm), flags); |
| 227 | if (nlh == NULL) |
| 228 | return -EMSGSIZE; |
| 229 | |
| 230 | ndm = nlmsg_data(nlh); |
| 231 | memset(ndm, 0, sizeof(*ndm)); |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 232 | |
| 233 | send_eth = send_ip = true; |
| 234 | |
| 235 | if (type == RTM_GETNEIGH) { |
| 236 | ndm->ndm_family = AF_INET; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 237 | send_ip = rdst->remote_ip != htonl(INADDR_ANY); |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 238 | send_eth = !is_zero_ether_addr(fdb->eth_addr); |
| 239 | } else |
| 240 | ndm->ndm_family = AF_BRIDGE; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 241 | ndm->ndm_state = fdb->state; |
| 242 | ndm->ndm_ifindex = vxlan->dev->ifindex; |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 243 | ndm->ndm_flags = fdb->flags; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 244 | ndm->ndm_type = NDA_DST; |
| 245 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 246 | if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 247 | goto nla_put_failure; |
| 248 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 249 | if (send_ip && nla_put_be32(skb, NDA_DST, rdst->remote_ip)) |
| 250 | goto nla_put_failure; |
| 251 | |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 252 | if (rdst->remote_port && rdst->remote_port != vxlan->dst_port && |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 253 | nla_put_be16(skb, NDA_PORT, rdst->remote_port)) |
| 254 | goto nla_put_failure; |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 255 | if (rdst->remote_vni != vxlan->default_dst.remote_vni && |
Pravin B Shelar | 60d9d4c | 2013-06-20 00:26:31 -0700 | [diff] [blame] | 256 | nla_put_u32(skb, NDA_VNI, rdst->remote_vni)) |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 257 | goto nla_put_failure; |
| 258 | if (rdst->remote_ifindex && |
| 259 | nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 260 | goto nla_put_failure; |
| 261 | |
| 262 | ci.ndm_used = jiffies_to_clock_t(now - fdb->used); |
| 263 | ci.ndm_confirmed = 0; |
| 264 | ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated); |
| 265 | ci.ndm_refcnt = 0; |
| 266 | |
| 267 | if (nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci)) |
| 268 | goto nla_put_failure; |
| 269 | |
| 270 | return nlmsg_end(skb, nlh); |
| 271 | |
| 272 | nla_put_failure: |
| 273 | nlmsg_cancel(skb, nlh); |
| 274 | return -EMSGSIZE; |
| 275 | } |
| 276 | |
| 277 | static inline size_t vxlan_nlmsg_size(void) |
| 278 | { |
| 279 | return NLMSG_ALIGN(sizeof(struct ndmsg)) |
| 280 | + nla_total_size(ETH_ALEN) /* NDA_LLADDR */ |
| 281 | + nla_total_size(sizeof(__be32)) /* NDA_DST */ |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 282 | + nla_total_size(sizeof(__be16)) /* NDA_PORT */ |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 283 | + nla_total_size(sizeof(__be32)) /* NDA_VNI */ |
| 284 | + nla_total_size(sizeof(__u32)) /* NDA_IFINDEX */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 285 | + nla_total_size(sizeof(struct nda_cacheinfo)); |
| 286 | } |
| 287 | |
| 288 | static void vxlan_fdb_notify(struct vxlan_dev *vxlan, |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 289 | struct vxlan_fdb *fdb, int type) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 290 | { |
| 291 | struct net *net = dev_net(vxlan->dev); |
| 292 | struct sk_buff *skb; |
| 293 | int err = -ENOBUFS; |
| 294 | |
| 295 | skb = nlmsg_new(vxlan_nlmsg_size(), GFP_ATOMIC); |
| 296 | if (skb == NULL) |
| 297 | goto errout; |
| 298 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 299 | err = vxlan_fdb_info(skb, vxlan, fdb, 0, 0, type, 0, first_remote(fdb)); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 300 | if (err < 0) { |
| 301 | /* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */ |
| 302 | WARN_ON(err == -EMSGSIZE); |
| 303 | kfree_skb(skb); |
| 304 | goto errout; |
| 305 | } |
| 306 | |
| 307 | rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC); |
| 308 | return; |
| 309 | errout: |
| 310 | if (err < 0) |
| 311 | rtnl_set_sk_err(net, RTNLGRP_NEIGH, err); |
| 312 | } |
| 313 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 314 | static void vxlan_ip_miss(struct net_device *dev, __be32 ipa) |
| 315 | { |
| 316 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Stephen Hemminger | bb3fd68 | 2013-06-17 14:16:40 -0700 | [diff] [blame] | 317 | struct vxlan_fdb f = { |
| 318 | .state = NUD_STALE, |
| 319 | }; |
| 320 | struct vxlan_rdst remote = { |
| 321 | .remote_ip = ipa, /* goes to NDA_DST */ |
| 322 | .remote_vni = VXLAN_N_VID, |
| 323 | }; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 324 | |
| 325 | INIT_LIST_HEAD(&f.remotes); |
| 326 | list_add_rcu(&remote.list, &f.remotes); |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 327 | |
| 328 | vxlan_fdb_notify(vxlan, &f, RTM_GETNEIGH); |
| 329 | } |
| 330 | |
| 331 | static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN]) |
| 332 | { |
Stephen Hemminger | bb3fd68 | 2013-06-17 14:16:40 -0700 | [diff] [blame] | 333 | struct vxlan_fdb f = { |
| 334 | .state = NUD_STALE, |
| 335 | }; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 336 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 337 | INIT_LIST_HEAD(&f.remotes); |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 338 | memcpy(f.eth_addr, eth_addr, ETH_ALEN); |
| 339 | |
| 340 | vxlan_fdb_notify(vxlan, &f, RTM_GETNEIGH); |
| 341 | } |
| 342 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 343 | /* Hash Ethernet address */ |
| 344 | static u32 eth_hash(const unsigned char *addr) |
| 345 | { |
| 346 | u64 value = get_unaligned((u64 *)addr); |
| 347 | |
| 348 | /* only want 6 bytes */ |
| 349 | #ifdef __BIG_ENDIAN |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 350 | value >>= 16; |
stephen hemminger | 321fb99 | 2012-10-09 20:35:47 +0000 | [diff] [blame] | 351 | #else |
| 352 | value <<= 16; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 353 | #endif |
| 354 | return hash_64(value, FDB_HASH_BITS); |
| 355 | } |
| 356 | |
| 357 | /* Hash chain to use given mac address */ |
| 358 | static inline struct hlist_head *vxlan_fdb_head(struct vxlan_dev *vxlan, |
| 359 | const u8 *mac) |
| 360 | { |
| 361 | return &vxlan->fdb_head[eth_hash(mac)]; |
| 362 | } |
| 363 | |
| 364 | /* Look up Ethernet address in forwarding table */ |
Sridhar Samudrala | 014be2c | 2013-05-17 06:39:07 +0000 | [diff] [blame] | 365 | static struct vxlan_fdb *__vxlan_find_mac(struct vxlan_dev *vxlan, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 366 | const u8 *mac) |
| 367 | |
| 368 | { |
| 369 | struct hlist_head *head = vxlan_fdb_head(vxlan, mac); |
| 370 | struct vxlan_fdb *f; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 371 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 372 | hlist_for_each_entry_rcu(f, head, hlist) { |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 373 | if (compare_ether_addr(mac, f->eth_addr) == 0) |
| 374 | return f; |
| 375 | } |
| 376 | |
| 377 | return NULL; |
| 378 | } |
| 379 | |
Sridhar Samudrala | 014be2c | 2013-05-17 06:39:07 +0000 | [diff] [blame] | 380 | static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan, |
| 381 | const u8 *mac) |
| 382 | { |
| 383 | struct vxlan_fdb *f; |
| 384 | |
| 385 | f = __vxlan_find_mac(vxlan, mac); |
| 386 | if (f) |
| 387 | f->used = jiffies; |
| 388 | |
| 389 | return f; |
| 390 | } |
| 391 | |
Mike Rapoport | a5e7c10 | 2013-06-25 16:01:52 +0300 | [diff] [blame] | 392 | /* caller should hold vxlan->hash_lock */ |
| 393 | static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f, |
| 394 | __be32 ip, __be16 port, |
| 395 | __u32 vni, __u32 ifindex) |
| 396 | { |
| 397 | struct vxlan_rdst *rd; |
| 398 | |
| 399 | list_for_each_entry(rd, &f->remotes, list) { |
| 400 | if (rd->remote_ip == ip && |
| 401 | rd->remote_port == port && |
| 402 | rd->remote_vni == vni && |
| 403 | rd->remote_ifindex == ifindex) |
| 404 | return rd; |
| 405 | } |
| 406 | |
| 407 | return NULL; |
| 408 | } |
| 409 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 410 | /* Add/update destinations for multicast */ |
| 411 | static int vxlan_fdb_append(struct vxlan_fdb *f, |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 412 | __be32 ip, __be16 port, __u32 vni, __u32 ifindex) |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 413 | { |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 414 | struct vxlan_rdst *rd; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 415 | |
Mike Rapoport | a5e7c10 | 2013-06-25 16:01:52 +0300 | [diff] [blame] | 416 | rd = vxlan_fdb_find_rdst(f, ip, port, vni, ifindex); |
| 417 | if (rd) |
| 418 | return 0; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 419 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 420 | rd = kmalloc(sizeof(*rd), GFP_ATOMIC); |
| 421 | if (rd == NULL) |
| 422 | return -ENOBUFS; |
| 423 | rd->remote_ip = ip; |
| 424 | rd->remote_port = port; |
| 425 | rd->remote_vni = vni; |
| 426 | rd->remote_ifindex = ifindex; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 427 | |
| 428 | list_add_tail_rcu(&rd->list, &f->remotes); |
| 429 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 430 | return 1; |
| 431 | } |
| 432 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 433 | /* Add new entry to forwarding table -- assumes lock held */ |
| 434 | static int vxlan_fdb_create(struct vxlan_dev *vxlan, |
| 435 | const u8 *mac, __be32 ip, |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 436 | __u16 state, __u16 flags, |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 437 | __be16 port, __u32 vni, __u32 ifindex, |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 438 | __u8 ndm_flags) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 439 | { |
| 440 | struct vxlan_fdb *f; |
| 441 | int notify = 0; |
| 442 | |
Sridhar Samudrala | 014be2c | 2013-05-17 06:39:07 +0000 | [diff] [blame] | 443 | f = __vxlan_find_mac(vxlan, mac); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 444 | if (f) { |
| 445 | if (flags & NLM_F_EXCL) { |
| 446 | netdev_dbg(vxlan->dev, |
| 447 | "lost race to create %pM\n", mac); |
| 448 | return -EEXIST; |
| 449 | } |
| 450 | if (f->state != state) { |
| 451 | f->state = state; |
| 452 | f->updated = jiffies; |
| 453 | notify = 1; |
| 454 | } |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 455 | if (f->flags != ndm_flags) { |
| 456 | f->flags = ndm_flags; |
| 457 | f->updated = jiffies; |
| 458 | notify = 1; |
| 459 | } |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 460 | if ((flags & NLM_F_APPEND) && |
Mike Rapoport | 58e4c76 | 2013-06-25 16:01:56 +0300 | [diff] [blame] | 461 | (is_multicast_ether_addr(f->eth_addr) || |
| 462 | is_zero_ether_addr(f->eth_addr))) { |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 463 | int rc = vxlan_fdb_append(f, ip, port, vni, ifindex); |
| 464 | |
| 465 | if (rc < 0) |
| 466 | return rc; |
| 467 | notify |= rc; |
| 468 | } |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 469 | } else { |
| 470 | if (!(flags & NLM_F_CREATE)) |
| 471 | return -ENOENT; |
| 472 | |
| 473 | if (vxlan->addrmax && vxlan->addrcnt >= vxlan->addrmax) |
| 474 | return -ENOSPC; |
| 475 | |
| 476 | netdev_dbg(vxlan->dev, "add %pM -> %pI4\n", mac, &ip); |
| 477 | f = kmalloc(sizeof(*f), GFP_ATOMIC); |
| 478 | if (!f) |
| 479 | return -ENOMEM; |
| 480 | |
| 481 | notify = 1; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 482 | f->state = state; |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 483 | f->flags = ndm_flags; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 484 | f->updated = f->used = jiffies; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 485 | INIT_LIST_HEAD(&f->remotes); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 486 | memcpy(f->eth_addr, mac, ETH_ALEN); |
| 487 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 488 | vxlan_fdb_append(f, ip, port, vni, ifindex); |
| 489 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 490 | ++vxlan->addrcnt; |
| 491 | hlist_add_head_rcu(&f->hlist, |
| 492 | vxlan_fdb_head(vxlan, mac)); |
| 493 | } |
| 494 | |
| 495 | if (notify) |
| 496 | vxlan_fdb_notify(vxlan, f, RTM_NEWNEIGH); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Mike Rapoport | bc7892b | 2013-06-25 16:01:54 +0300 | [diff] [blame] | 501 | static void vxlan_fdb_free_rdst(struct rcu_head *head) |
| 502 | { |
| 503 | struct vxlan_rdst *rd = container_of(head, struct vxlan_rdst, rcu); |
| 504 | kfree(rd); |
| 505 | } |
| 506 | |
Wei Yongjun | 6706c82 | 2013-04-11 19:00:35 +0000 | [diff] [blame] | 507 | static void vxlan_fdb_free(struct rcu_head *head) |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 508 | { |
| 509 | struct vxlan_fdb *f = container_of(head, struct vxlan_fdb, rcu); |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 510 | struct vxlan_rdst *rd, *nd; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 511 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 512 | list_for_each_entry_safe(rd, nd, &f->remotes, list) |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 513 | kfree(rd); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 514 | kfree(f); |
| 515 | } |
| 516 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 517 | static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f) |
| 518 | { |
| 519 | netdev_dbg(vxlan->dev, |
| 520 | "delete %pM\n", f->eth_addr); |
| 521 | |
| 522 | --vxlan->addrcnt; |
| 523 | vxlan_fdb_notify(vxlan, f, RTM_DELNEIGH); |
| 524 | |
| 525 | hlist_del_rcu(&f->hlist); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 526 | call_rcu(&f->rcu, vxlan_fdb_free); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Mike Rapoport | f0b074b | 2013-06-25 16:01:53 +0300 | [diff] [blame] | 529 | static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, |
| 530 | __be32 *ip, __be16 *port, u32 *vni, u32 *ifindex) |
| 531 | { |
| 532 | struct net *net = dev_net(vxlan->dev); |
| 533 | |
| 534 | if (tb[NDA_DST]) { |
| 535 | if (nla_len(tb[NDA_DST]) != sizeof(__be32)) |
| 536 | return -EAFNOSUPPORT; |
| 537 | |
| 538 | *ip = nla_get_be32(tb[NDA_DST]); |
| 539 | } else { |
| 540 | *ip = htonl(INADDR_ANY); |
| 541 | } |
| 542 | |
| 543 | if (tb[NDA_PORT]) { |
| 544 | if (nla_len(tb[NDA_PORT]) != sizeof(__be16)) |
| 545 | return -EINVAL; |
| 546 | *port = nla_get_be16(tb[NDA_PORT]); |
| 547 | } else { |
| 548 | *port = vxlan->dst_port; |
| 549 | } |
| 550 | |
| 551 | if (tb[NDA_VNI]) { |
| 552 | if (nla_len(tb[NDA_VNI]) != sizeof(u32)) |
| 553 | return -EINVAL; |
| 554 | *vni = nla_get_u32(tb[NDA_VNI]); |
| 555 | } else { |
| 556 | *vni = vxlan->default_dst.remote_vni; |
| 557 | } |
| 558 | |
| 559 | if (tb[NDA_IFINDEX]) { |
| 560 | struct net_device *tdev; |
| 561 | |
| 562 | if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32)) |
| 563 | return -EINVAL; |
| 564 | *ifindex = nla_get_u32(tb[NDA_IFINDEX]); |
| 565 | tdev = dev_get_by_index(net, *ifindex); |
| 566 | if (!tdev) |
| 567 | return -EADDRNOTAVAIL; |
| 568 | dev_put(tdev); |
| 569 | } else { |
| 570 | *ifindex = 0; |
| 571 | } |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 576 | /* Add static entry (via netlink) */ |
| 577 | static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 578 | struct net_device *dev, |
| 579 | const unsigned char *addr, u16 flags) |
| 580 | { |
| 581 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Mike Rapoport | f0b074b | 2013-06-25 16:01:53 +0300 | [diff] [blame] | 582 | /* struct net *net = dev_net(vxlan->dev); */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 583 | __be32 ip; |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 584 | __be16 port; |
| 585 | u32 vni, ifindex; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 586 | int err; |
| 587 | |
| 588 | if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_REACHABLE))) { |
| 589 | pr_info("RTM_NEWNEIGH with invalid state %#x\n", |
| 590 | ndm->ndm_state); |
| 591 | return -EINVAL; |
| 592 | } |
| 593 | |
| 594 | if (tb[NDA_DST] == NULL) |
| 595 | return -EINVAL; |
| 596 | |
Mike Rapoport | f0b074b | 2013-06-25 16:01:53 +0300 | [diff] [blame] | 597 | err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &vni, &ifindex); |
| 598 | if (err) |
| 599 | return err; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 600 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 601 | spin_lock_bh(&vxlan->hash_lock); |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 602 | err = vxlan_fdb_create(vxlan, addr, ip, ndm->ndm_state, flags, |
| 603 | port, vni, ifindex, ndm->ndm_flags); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 604 | spin_unlock_bh(&vxlan->hash_lock); |
| 605 | |
| 606 | return err; |
| 607 | } |
| 608 | |
| 609 | /* Delete entry (via netlink) */ |
Vlad Yasevich | 1690be6 | 2013-02-13 12:00:18 +0000 | [diff] [blame] | 610 | static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], |
| 611 | struct net_device *dev, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 612 | const unsigned char *addr) |
| 613 | { |
| 614 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 615 | struct vxlan_fdb *f; |
Mike Rapoport | bc7892b | 2013-06-25 16:01:54 +0300 | [diff] [blame] | 616 | struct vxlan_rdst *rd = NULL; |
| 617 | __be32 ip; |
| 618 | __be16 port; |
| 619 | u32 vni, ifindex; |
| 620 | int err; |
| 621 | |
| 622 | err = vxlan_fdb_parse(tb, vxlan, &ip, &port, &vni, &ifindex); |
| 623 | if (err) |
| 624 | return err; |
| 625 | |
| 626 | err = -ENOENT; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 627 | |
| 628 | spin_lock_bh(&vxlan->hash_lock); |
| 629 | f = vxlan_find_mac(vxlan, addr); |
Mike Rapoport | bc7892b | 2013-06-25 16:01:54 +0300 | [diff] [blame] | 630 | if (!f) |
| 631 | goto out; |
| 632 | |
| 633 | if (ip != htonl(INADDR_ANY)) { |
| 634 | rd = vxlan_fdb_find_rdst(f, ip, port, vni, ifindex); |
| 635 | if (!rd) |
| 636 | goto out; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 637 | } |
Mike Rapoport | bc7892b | 2013-06-25 16:01:54 +0300 | [diff] [blame] | 638 | |
| 639 | err = 0; |
| 640 | |
| 641 | /* remove a destination if it's not the only one on the list, |
| 642 | * otherwise destroy the fdb entry |
| 643 | */ |
| 644 | if (rd && !list_is_singular(&f->remotes)) { |
| 645 | list_del_rcu(&rd->list); |
| 646 | call_rcu(&rd->rcu, vxlan_fdb_free_rdst); |
| 647 | goto out; |
| 648 | } |
| 649 | |
| 650 | vxlan_fdb_destroy(vxlan, f); |
| 651 | |
| 652 | out: |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 653 | spin_unlock_bh(&vxlan->hash_lock); |
| 654 | |
| 655 | return err; |
| 656 | } |
| 657 | |
| 658 | /* Dump forwarding table */ |
| 659 | static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, |
| 660 | struct net_device *dev, int idx) |
| 661 | { |
| 662 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 663 | unsigned int h; |
| 664 | |
| 665 | for (h = 0; h < FDB_HASH_SIZE; ++h) { |
| 666 | struct vxlan_fdb *f; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 667 | int err; |
| 668 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 669 | hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) { |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 670 | struct vxlan_rdst *rd; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 671 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 672 | if (idx < cb->args[0]) |
| 673 | goto skip; |
| 674 | |
| 675 | list_for_each_entry_rcu(rd, &f->remotes, list) { |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 676 | err = vxlan_fdb_info(skb, vxlan, f, |
| 677 | NETLINK_CB(cb->skb).portid, |
| 678 | cb->nlh->nlmsg_seq, |
| 679 | RTM_NEWNEIGH, |
| 680 | NLM_F_MULTI, rd); |
| 681 | if (err < 0) |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 682 | goto out; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 683 | } |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 684 | skip: |
| 685 | ++idx; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 686 | } |
| 687 | } |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 688 | out: |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 689 | return idx; |
| 690 | } |
| 691 | |
| 692 | /* Watch incoming packets to learn mapping between Ethernet address |
| 693 | * and Tunnel endpoint. |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 694 | * Return true if packet is bogus and should be droppped. |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 695 | */ |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 696 | static bool vxlan_snoop(struct net_device *dev, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 697 | __be32 src_ip, const u8 *src_mac) |
| 698 | { |
| 699 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 700 | struct vxlan_fdb *f; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 701 | |
| 702 | f = vxlan_find_mac(vxlan, src_mac); |
| 703 | if (likely(f)) { |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 704 | struct vxlan_rdst *rdst = first_remote(f); |
| 705 | |
| 706 | if (likely(rdst->remote_ip == src_ip)) |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 707 | return false; |
| 708 | |
| 709 | /* Don't migrate static entries, drop packets */ |
stephen hemminger | eb064c3 | 2013-06-18 14:27:01 -0700 | [diff] [blame] | 710 | if (f->state & NUD_NOARP) |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 711 | return true; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 712 | |
| 713 | if (net_ratelimit()) |
| 714 | netdev_info(dev, |
| 715 | "%pM migrated from %pI4 to %pI4\n", |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 716 | src_mac, &rdst->remote_ip, &src_ip); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 717 | |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 718 | rdst->remote_ip = src_ip; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 719 | f->updated = jiffies; |
Stephen Hemminger | 8385f50 | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 720 | vxlan_fdb_notify(vxlan, f, RTM_NEWNEIGH); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 721 | } else { |
| 722 | /* learned new entry */ |
| 723 | spin_lock(&vxlan->hash_lock); |
stephen hemminger | 3bf74b1 | 2013-06-17 12:09:57 -0700 | [diff] [blame] | 724 | |
| 725 | /* close off race between vxlan_flush and incoming packets */ |
| 726 | if (netif_running(dev)) |
| 727 | vxlan_fdb_create(vxlan, src_mac, src_ip, |
| 728 | NUD_REACHABLE, |
| 729 | NLM_F_EXCL|NLM_F_CREATE, |
| 730 | vxlan->dst_port, |
| 731 | vxlan->default_dst.remote_vni, |
| 732 | 0, NTF_SELF); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 733 | spin_unlock(&vxlan->hash_lock); |
| 734 | } |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 735 | |
| 736 | return false; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
| 740 | /* See if multicast group is already in use by other ID */ |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 741 | static bool vxlan_group_used(struct vxlan_net *vn, __be32 remote_ip) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 742 | { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 743 | struct vxlan_dev *vxlan; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 744 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 745 | list_for_each_entry(vxlan, &vn->vxlan_list, next) { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 746 | if (!netif_running(vxlan->dev)) |
| 747 | continue; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 748 | |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 749 | if (vxlan->default_dst.remote_ip == remote_ip) |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 750 | return true; |
| 751 | } |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 752 | |
| 753 | return false; |
| 754 | } |
| 755 | |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 756 | static void vxlan_sock_hold(struct vxlan_sock *vs) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 757 | { |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 758 | atomic_inc(&vs->refcnt); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 761 | static void vxlan_sock_release(struct vxlan_net *vn, struct vxlan_sock *vs) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 762 | { |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 763 | if (!atomic_dec_and_test(&vs->refcnt)) |
| 764 | return; |
| 765 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 766 | spin_lock(&vn->sock_lock); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 767 | hlist_del_rcu(&vs->hlist); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 768 | spin_unlock(&vn->sock_lock); |
| 769 | |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 770 | queue_work(vxlan_wq, &vs->del_work); |
| 771 | } |
| 772 | |
| 773 | /* Callback to update multicast group membership. |
| 774 | * Scheduled when vxlan goes up/down. |
| 775 | */ |
| 776 | static void vxlan_igmp_work(struct work_struct *work) |
| 777 | { |
| 778 | struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_work); |
| 779 | struct vxlan_net *vn = net_generic(dev_net(vxlan->dev), vxlan_net_id); |
| 780 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 781 | struct sock *sk = vs->sock->sk; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 782 | struct ip_mreqn mreq = { |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 783 | .imr_multiaddr.s_addr = vxlan->default_dst.remote_ip, |
| 784 | .imr_ifindex = vxlan->default_dst.remote_ifindex, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 785 | }; |
| 786 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 787 | lock_sock(sk); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 788 | if (vxlan_group_used(vn, vxlan->default_dst.remote_ip)) |
| 789 | ip_mc_join_group(sk, &mreq); |
| 790 | else |
| 791 | ip_mc_leave_group(sk, &mreq); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 792 | release_sock(sk); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 793 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 794 | vxlan_sock_release(vn, vs); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 795 | dev_put(vxlan->dev); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* Callback from net/ipv4/udp.c to receive packets */ |
| 799 | static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) |
| 800 | { |
| 801 | struct iphdr *oip; |
| 802 | struct vxlanhdr *vxh; |
| 803 | struct vxlan_dev *vxlan; |
Pravin B Shelar | e817104 | 2013-03-25 14:49:46 +0000 | [diff] [blame] | 804 | struct pcpu_tstats *stats; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 805 | __be16 port; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 806 | __u32 vni; |
| 807 | int err; |
| 808 | |
| 809 | /* pop off outer UDP header */ |
| 810 | __skb_pull(skb, sizeof(struct udphdr)); |
| 811 | |
| 812 | /* Need Vxlan and inner Ethernet header to be present */ |
| 813 | if (!pskb_may_pull(skb, sizeof(struct vxlanhdr))) |
| 814 | goto error; |
| 815 | |
| 816 | /* Drop packets with reserved bits set */ |
| 817 | vxh = (struct vxlanhdr *) skb->data; |
| 818 | if (vxh->vx_flags != htonl(VXLAN_FLAGS) || |
| 819 | (vxh->vx_vni & htonl(0xff))) { |
| 820 | netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", |
| 821 | ntohl(vxh->vx_flags), ntohl(vxh->vx_vni)); |
| 822 | goto error; |
| 823 | } |
| 824 | |
| 825 | __skb_pull(skb, sizeof(struct vxlanhdr)); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 826 | |
| 827 | /* Is this VNI defined? */ |
| 828 | vni = ntohl(vxh->vx_vni) >> 8; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 829 | port = inet_sk(sk)->inet_sport; |
| 830 | vxlan = vxlan_find_vni(sock_net(sk), vni, port); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 831 | if (!vxlan) { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 832 | netdev_dbg(skb->dev, "unknown vni %d port %u\n", |
| 833 | vni, ntohs(port)); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 834 | goto drop; |
| 835 | } |
| 836 | |
| 837 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
| 838 | vxlan->dev->stats.rx_length_errors++; |
| 839 | vxlan->dev->stats.rx_errors++; |
| 840 | goto drop; |
| 841 | } |
| 842 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 843 | skb_reset_mac_header(skb); |
| 844 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 845 | /* Re-examine inner Ethernet packet */ |
| 846 | oip = ip_hdr(skb); |
| 847 | skb->protocol = eth_type_trans(skb, vxlan->dev); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 848 | |
| 849 | /* Ignore packet loops (and multicast echo) */ |
| 850 | if (compare_ether_addr(eth_hdr(skb)->h_source, |
| 851 | vxlan->dev->dev_addr) == 0) |
| 852 | goto drop; |
| 853 | |
stephen hemminger | 26a41ae6 | 2013-06-17 12:09:58 -0700 | [diff] [blame] | 854 | if ((vxlan->flags & VXLAN_F_LEARN) && |
| 855 | vxlan_snoop(skb->dev, oip->saddr, eth_hdr(skb)->h_source)) |
| 856 | goto drop; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 857 | |
| 858 | __skb_tunnel_rx(skb, vxlan->dev); |
| 859 | skb_reset_network_header(skb); |
Joseph Gasparakis | 0afb166 | 2012-12-07 14:14:18 +0000 | [diff] [blame] | 860 | |
| 861 | /* If the NIC driver gave us an encapsulated packet with |
| 862 | * CHECKSUM_UNNECESSARY and Rx checksum feature is enabled, |
| 863 | * leave the CHECKSUM_UNNECESSARY, the device checksummed it |
| 864 | * for us. Otherwise force the upper layers to verify it. |
| 865 | */ |
| 866 | if (skb->ip_summed != CHECKSUM_UNNECESSARY || !skb->encapsulation || |
| 867 | !(vxlan->dev->features & NETIF_F_RXCSUM)) |
| 868 | skb->ip_summed = CHECKSUM_NONE; |
| 869 | |
| 870 | skb->encapsulation = 0; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 871 | |
| 872 | err = IP_ECN_decapsulate(oip, skb); |
| 873 | if (unlikely(err)) { |
| 874 | if (log_ecn_error) |
| 875 | net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", |
| 876 | &oip->saddr, oip->tos); |
| 877 | if (err > 1) { |
| 878 | ++vxlan->dev->stats.rx_frame_errors; |
| 879 | ++vxlan->dev->stats.rx_errors; |
| 880 | goto drop; |
| 881 | } |
| 882 | } |
| 883 | |
Pravin B Shelar | e817104 | 2013-03-25 14:49:46 +0000 | [diff] [blame] | 884 | stats = this_cpu_ptr(vxlan->dev->tstats); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 885 | u64_stats_update_begin(&stats->syncp); |
| 886 | stats->rx_packets++; |
| 887 | stats->rx_bytes += skb->len; |
| 888 | u64_stats_update_end(&stats->syncp); |
| 889 | |
| 890 | netif_rx(skb); |
| 891 | |
| 892 | return 0; |
| 893 | error: |
| 894 | /* Put UDP header back */ |
| 895 | __skb_push(skb, sizeof(struct udphdr)); |
| 896 | |
| 897 | return 1; |
| 898 | drop: |
| 899 | /* Consume bad packet */ |
| 900 | kfree_skb(skb); |
| 901 | return 0; |
| 902 | } |
| 903 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 904 | static int arp_reduce(struct net_device *dev, struct sk_buff *skb) |
| 905 | { |
| 906 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 907 | struct arphdr *parp; |
| 908 | u8 *arpptr, *sha; |
| 909 | __be32 sip, tip; |
| 910 | struct neighbour *n; |
| 911 | |
| 912 | if (dev->flags & IFF_NOARP) |
| 913 | goto out; |
| 914 | |
| 915 | if (!pskb_may_pull(skb, arp_hdr_len(dev))) { |
| 916 | dev->stats.tx_dropped++; |
| 917 | goto out; |
| 918 | } |
| 919 | parp = arp_hdr(skb); |
| 920 | |
| 921 | if ((parp->ar_hrd != htons(ARPHRD_ETHER) && |
| 922 | parp->ar_hrd != htons(ARPHRD_IEEE802)) || |
| 923 | parp->ar_pro != htons(ETH_P_IP) || |
| 924 | parp->ar_op != htons(ARPOP_REQUEST) || |
| 925 | parp->ar_hln != dev->addr_len || |
| 926 | parp->ar_pln != 4) |
| 927 | goto out; |
| 928 | arpptr = (u8 *)parp + sizeof(struct arphdr); |
| 929 | sha = arpptr; |
| 930 | arpptr += dev->addr_len; /* sha */ |
| 931 | memcpy(&sip, arpptr, sizeof(sip)); |
| 932 | arpptr += sizeof(sip); |
| 933 | arpptr += dev->addr_len; /* tha */ |
| 934 | memcpy(&tip, arpptr, sizeof(tip)); |
| 935 | |
| 936 | if (ipv4_is_loopback(tip) || |
| 937 | ipv4_is_multicast(tip)) |
| 938 | goto out; |
| 939 | |
| 940 | n = neigh_lookup(&arp_tbl, &tip, dev); |
| 941 | |
| 942 | if (n) { |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 943 | struct vxlan_fdb *f; |
| 944 | struct sk_buff *reply; |
| 945 | |
| 946 | if (!(n->nud_state & NUD_CONNECTED)) { |
| 947 | neigh_release(n); |
| 948 | goto out; |
| 949 | } |
| 950 | |
| 951 | f = vxlan_find_mac(vxlan, n->ha); |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 952 | if (f && first_remote(f)->remote_ip == htonl(INADDR_ANY)) { |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 953 | /* bridge-local neighbor */ |
| 954 | neigh_release(n); |
| 955 | goto out; |
| 956 | } |
| 957 | |
| 958 | reply = arp_create(ARPOP_REPLY, ETH_P_ARP, sip, dev, tip, sha, |
| 959 | n->ha, sha); |
| 960 | |
| 961 | neigh_release(n); |
| 962 | |
| 963 | skb_reset_mac_header(reply); |
| 964 | __skb_pull(reply, skb_network_offset(reply)); |
| 965 | reply->ip_summed = CHECKSUM_UNNECESSARY; |
| 966 | reply->pkt_type = PACKET_HOST; |
| 967 | |
| 968 | if (netif_rx_ni(reply) == NET_RX_DROP) |
| 969 | dev->stats.rx_dropped++; |
| 970 | } else if (vxlan->flags & VXLAN_F_L3MISS) |
| 971 | vxlan_ip_miss(dev, tip); |
| 972 | out: |
| 973 | consume_skb(skb); |
| 974 | return NETDEV_TX_OK; |
| 975 | } |
| 976 | |
| 977 | static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) |
| 978 | { |
| 979 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 980 | struct neighbour *n; |
| 981 | struct iphdr *pip; |
| 982 | |
| 983 | if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) |
| 984 | return false; |
| 985 | |
| 986 | n = NULL; |
| 987 | switch (ntohs(eth_hdr(skb)->h_proto)) { |
| 988 | case ETH_P_IP: |
| 989 | if (!pskb_may_pull(skb, sizeof(struct iphdr))) |
| 990 | return false; |
| 991 | pip = ip_hdr(skb); |
| 992 | n = neigh_lookup(&arp_tbl, &pip->daddr, dev); |
| 993 | break; |
| 994 | default: |
| 995 | return false; |
| 996 | } |
| 997 | |
| 998 | if (n) { |
| 999 | bool diff; |
| 1000 | |
| 1001 | diff = compare_ether_addr(eth_hdr(skb)->h_dest, n->ha) != 0; |
| 1002 | if (diff) { |
| 1003 | memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, |
| 1004 | dev->addr_len); |
| 1005 | memcpy(eth_hdr(skb)->h_dest, n->ha, dev->addr_len); |
| 1006 | } |
| 1007 | neigh_release(n); |
| 1008 | return diff; |
| 1009 | } else if (vxlan->flags & VXLAN_F_L3MISS) |
| 1010 | vxlan_ip_miss(dev, pip->daddr); |
| 1011 | return false; |
| 1012 | } |
| 1013 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1014 | static void vxlan_sock_put(struct sk_buff *skb) |
stephen hemminger | 1cad871 | 2012-10-09 20:35:49 +0000 | [diff] [blame] | 1015 | { |
| 1016 | sock_put(skb->sk); |
| 1017 | } |
| 1018 | |
| 1019 | /* On transmit, associate with the tunnel socket */ |
| 1020 | static void vxlan_set_owner(struct net_device *dev, struct sk_buff *skb) |
| 1021 | { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1022 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1023 | struct sock *sk = vxlan->vn_sock->sock->sk; |
stephen hemminger | 1cad871 | 2012-10-09 20:35:49 +0000 | [diff] [blame] | 1024 | |
| 1025 | skb_orphan(skb); |
| 1026 | sock_hold(sk); |
| 1027 | skb->sk = sk; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1028 | skb->destructor = vxlan_sock_put; |
stephen hemminger | 1cad871 | 2012-10-09 20:35:49 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1031 | /* Compute source port for outgoing packet |
| 1032 | * first choice to use L4 flow hash since it will spread |
| 1033 | * better and maybe available from hardware |
| 1034 | * secondary choice is to use jhash on the Ethernet header |
| 1035 | */ |
stephen hemminger | 7d836a7 | 2013-04-27 11:31:56 +0000 | [diff] [blame] | 1036 | static __be16 vxlan_src_port(const struct vxlan_dev *vxlan, struct sk_buff *skb) |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1037 | { |
| 1038 | unsigned int range = (vxlan->port_max - vxlan->port_min) + 1; |
| 1039 | u32 hash; |
| 1040 | |
| 1041 | hash = skb_get_rxhash(skb); |
| 1042 | if (!hash) |
| 1043 | hash = jhash(skb->data, 2 * ETH_ALEN, |
| 1044 | (__force u32) skb->protocol); |
| 1045 | |
stephen hemminger | 7d836a7 | 2013-04-27 11:31:56 +0000 | [diff] [blame] | 1046 | return htons((((u64) hash * range) >> 32) + vxlan->port_min); |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Pravin B Shelar | 05c0db0 | 2013-03-07 13:22:36 +0000 | [diff] [blame] | 1049 | static int handle_offloads(struct sk_buff *skb) |
| 1050 | { |
| 1051 | if (skb_is_gso(skb)) { |
| 1052 | int err = skb_unclone(skb, GFP_ATOMIC); |
| 1053 | if (unlikely(err)) |
| 1054 | return err; |
| 1055 | |
Dmitry Kravkov | f6ace50 | 2013-04-28 08:16:01 +0000 | [diff] [blame] | 1056 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
Pravin B Shelar | 05c0db0 | 2013-03-07 13:22:36 +0000 | [diff] [blame] | 1057 | } else if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1058 | skb->ip_summed = CHECKSUM_NONE; |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1063 | /* Bypass encapsulation if the destination is local */ |
| 1064 | static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, |
| 1065 | struct vxlan_dev *dst_vxlan) |
| 1066 | { |
| 1067 | struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats); |
| 1068 | struct pcpu_tstats *rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats); |
| 1069 | |
| 1070 | skb->pkt_type = PACKET_HOST; |
| 1071 | skb->encapsulation = 0; |
| 1072 | skb->dev = dst_vxlan->dev; |
| 1073 | __skb_pull(skb, skb_network_offset(skb)); |
| 1074 | |
| 1075 | if (dst_vxlan->flags & VXLAN_F_LEARN) |
Mike Rapoport | 9d9f163 | 2013-04-13 23:21:39 +0000 | [diff] [blame] | 1076 | vxlan_snoop(skb->dev, htonl(INADDR_LOOPBACK), |
| 1077 | eth_hdr(skb)->h_source); |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1078 | |
| 1079 | u64_stats_update_begin(&tx_stats->syncp); |
| 1080 | tx_stats->tx_packets++; |
| 1081 | tx_stats->tx_bytes += skb->len; |
| 1082 | u64_stats_update_end(&tx_stats->syncp); |
| 1083 | |
| 1084 | if (netif_rx(skb) == NET_RX_SUCCESS) { |
| 1085 | u64_stats_update_begin(&rx_stats->syncp); |
| 1086 | rx_stats->rx_packets++; |
| 1087 | rx_stats->rx_bytes += skb->len; |
| 1088 | u64_stats_update_end(&rx_stats->syncp); |
| 1089 | } else { |
| 1090 | skb->dev->stats.rx_dropped++; |
| 1091 | } |
| 1092 | } |
| 1093 | |
Stephen Hemminger | 4ad1693 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1094 | static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, |
| 1095 | struct vxlan_rdst *rdst, bool did_rsc) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1096 | { |
| 1097 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1098 | struct rtable *rt; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1099 | const struct iphdr *old_iph; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1100 | struct vxlanhdr *vxh; |
| 1101 | struct udphdr *uh; |
| 1102 | struct flowi4 fl4; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1103 | __be32 dst; |
stephen hemminger | 7d836a7 | 2013-04-27 11:31:56 +0000 | [diff] [blame] | 1104 | __be16 src_port, dst_port; |
Stephen Hemminger | 234f5b7 | 2013-06-17 14:16:41 -0700 | [diff] [blame] | 1105 | u32 vni; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1106 | __be16 df = 0; |
| 1107 | __u8 tos, ttl; |
Pravin B Shelar | 0e6fbc5 | 2013-06-17 17:49:56 -0700 | [diff] [blame] | 1108 | int err; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1109 | |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1110 | dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1111 | vni = rdst->remote_vni; |
| 1112 | dst = rdst->remote_ip; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1113 | |
| 1114 | if (!dst) { |
| 1115 | if (did_rsc) { |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1116 | /* short-circuited back to local bridge */ |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1117 | vxlan_encap_bypass(skb, vxlan, vxlan); |
Stephen Hemminger | 4ad1693 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1118 | return; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1119 | } |
stephen hemminger | ef59feb | 2012-10-09 20:35:46 +0000 | [diff] [blame] | 1120 | goto drop; |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1121 | } |
stephen hemminger | ef59feb | 2012-10-09 20:35:46 +0000 | [diff] [blame] | 1122 | |
Joseph Gasparakis | d6727fe | 2012-12-07 14:14:16 +0000 | [diff] [blame] | 1123 | if (!skb->encapsulation) { |
| 1124 | skb_reset_inner_headers(skb); |
| 1125 | skb->encapsulation = 1; |
| 1126 | } |
| 1127 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1128 | /* Need space for new headers (invalidates iph ptr) */ |
| 1129 | if (skb_cow_head(skb, VXLAN_HEADROOM)) |
| 1130 | goto drop; |
| 1131 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1132 | old_iph = ip_hdr(skb); |
| 1133 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1134 | ttl = vxlan->ttl; |
| 1135 | if (!ttl && IN_MULTICAST(ntohl(dst))) |
| 1136 | ttl = 1; |
| 1137 | |
| 1138 | tos = vxlan->tos; |
| 1139 | if (tos == 1) |
Pravin B Shelar | 206aaaf | 2013-03-25 14:49:53 +0000 | [diff] [blame] | 1140 | tos = ip_tunnel_get_dsfield(old_iph, skb); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1141 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1142 | src_port = vxlan_src_port(vxlan, skb); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1143 | |
stephen hemminger | ca78f18 | 2012-10-09 20:35:48 +0000 | [diff] [blame] | 1144 | memset(&fl4, 0, sizeof(fl4)); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1145 | fl4.flowi4_oif = rdst->remote_ifindex; |
stephen hemminger | ca78f18 | 2012-10-09 20:35:48 +0000 | [diff] [blame] | 1146 | fl4.flowi4_tos = RT_TOS(tos); |
| 1147 | fl4.daddr = dst; |
| 1148 | fl4.saddr = vxlan->saddr; |
| 1149 | |
| 1150 | rt = ip_route_output_key(dev_net(dev), &fl4); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1151 | if (IS_ERR(rt)) { |
| 1152 | netdev_dbg(dev, "no route to %pI4\n", &dst); |
| 1153 | dev->stats.tx_carrier_errors++; |
| 1154 | goto tx_error; |
| 1155 | } |
| 1156 | |
| 1157 | if (rt->dst.dev == dev) { |
| 1158 | netdev_dbg(dev, "circular route to %pI4\n", &dst); |
| 1159 | ip_rt_put(rt); |
| 1160 | dev->stats.collisions++; |
| 1161 | goto tx_error; |
| 1162 | } |
| 1163 | |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1164 | /* Bypass encapsulation if the destination is local */ |
Mike Rapoport | ab09a6d | 2013-04-13 23:21:51 +0000 | [diff] [blame] | 1165 | if (rt->rt_flags & RTCF_LOCAL && |
| 1166 | !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) { |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1167 | struct vxlan_dev *dst_vxlan; |
| 1168 | |
| 1169 | ip_rt_put(rt); |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1170 | dst_vxlan = vxlan_find_vni(dev_net(dev), vni, dst_port); |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1171 | if (!dst_vxlan) |
| 1172 | goto tx_error; |
| 1173 | vxlan_encap_bypass(skb, vxlan, dst_vxlan); |
Stephen Hemminger | 4ad1693 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1174 | return; |
Sridhar Samudrala | 9dcc71e | 2013-04-02 12:31:52 +0000 | [diff] [blame] | 1175 | } |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1176 | vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh)); |
| 1177 | vxh->vx_flags = htonl(VXLAN_FLAGS); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1178 | vxh->vx_vni = htonl(vni << 8); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1179 | |
| 1180 | __skb_push(skb, sizeof(*uh)); |
| 1181 | skb_reset_transport_header(skb); |
| 1182 | uh = udp_hdr(skb); |
| 1183 | |
stephen hemminger | 73cf331 | 2013-04-27 11:31:54 +0000 | [diff] [blame] | 1184 | uh->dest = dst_port; |
stephen hemminger | 7d836a7 | 2013-04-27 11:31:56 +0000 | [diff] [blame] | 1185 | uh->source = src_port; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1186 | |
| 1187 | uh->len = htons(skb->len); |
| 1188 | uh->check = 0; |
| 1189 | |
stephen hemminger | 1cad871 | 2012-10-09 20:35:49 +0000 | [diff] [blame] | 1190 | vxlan_set_owner(dev, skb); |
| 1191 | |
Pravin B Shelar | 05c0db0 | 2013-03-07 13:22:36 +0000 | [diff] [blame] | 1192 | if (handle_offloads(skb)) |
| 1193 | goto drop; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1194 | |
Pravin B Shelar | 0e6fbc5 | 2013-06-17 17:49:56 -0700 | [diff] [blame] | 1195 | tos = ip_tunnel_ecn_encap(tos, old_iph, skb); |
| 1196 | ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); |
| 1197 | |
| 1198 | err = iptunnel_xmit(dev_net(dev), rt, skb, fl4.saddr, dst, |
| 1199 | IPPROTO_UDP, tos, ttl, df); |
| 1200 | iptunnel_xmit_stats(err, &dev->stats, dev->tstats); |
| 1201 | |
Stephen Hemminger | 4ad1693 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1202 | return; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1203 | |
| 1204 | drop: |
| 1205 | dev->stats.tx_dropped++; |
| 1206 | goto tx_free; |
| 1207 | |
| 1208 | tx_error: |
| 1209 | dev->stats.tx_errors++; |
| 1210 | tx_free: |
| 1211 | dev_kfree_skb(skb); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1214 | /* Transmit local packets over Vxlan |
| 1215 | * |
| 1216 | * Outer IP header inherits ECN and DF from inner header. |
| 1217 | * Outer UDP destination is the VXLAN assigned port. |
| 1218 | * source port is based on hash of flow |
| 1219 | */ |
| 1220 | static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1221 | { |
| 1222 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1223 | struct ethhdr *eth; |
| 1224 | bool did_rsc = false; |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1225 | struct vxlan_rdst *rdst; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1226 | struct vxlan_fdb *f; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1227 | |
| 1228 | skb_reset_mac_header(skb); |
| 1229 | eth = eth_hdr(skb); |
| 1230 | |
| 1231 | if ((vxlan->flags & VXLAN_F_PROXY) && ntohs(eth->h_proto) == ETH_P_ARP) |
| 1232 | return arp_reduce(dev, skb); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1233 | |
| 1234 | f = vxlan_find_mac(vxlan, eth->h_dest); |
David Stevens | ae88408 | 2013-04-19 00:36:26 +0000 | [diff] [blame] | 1235 | did_rsc = false; |
| 1236 | |
| 1237 | if (f && (f->flags & NTF_ROUTER) && (vxlan->flags & VXLAN_F_RSC) && |
| 1238 | ntohs(eth->h_proto) == ETH_P_IP) { |
| 1239 | did_rsc = route_shortcircuit(dev, skb); |
| 1240 | if (did_rsc) |
| 1241 | f = vxlan_find_mac(vxlan, eth->h_dest); |
| 1242 | } |
| 1243 | |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1244 | if (f == NULL) { |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1245 | f = vxlan_find_mac(vxlan, all_zeros_mac); |
| 1246 | if (f == NULL) { |
| 1247 | if ((vxlan->flags & VXLAN_F_L2MISS) && |
| 1248 | !is_multicast_ether_addr(eth->h_dest)) |
| 1249 | vxlan_fdb_miss(vxlan, eth->h_dest); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1250 | |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1251 | dev->stats.tx_dropped++; |
| 1252 | dev_kfree_skb(skb); |
| 1253 | return NETDEV_TX_OK; |
Stephen Hemminger | 3e61aa8 | 2013-06-17 14:16:12 -0700 | [diff] [blame] | 1254 | } |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1257 | list_for_each_entry_rcu(rdst, &f->remotes, list) { |
| 1258 | struct sk_buff *skb1; |
| 1259 | |
| 1260 | skb1 = skb_clone(skb, GFP_ATOMIC); |
| 1261 | if (skb1) |
| 1262 | vxlan_xmit_one(skb1, dev, rdst, did_rsc); |
| 1263 | } |
| 1264 | |
| 1265 | dev_kfree_skb(skb); |
Stephen Hemminger | 4ad1693 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1266 | return NETDEV_TX_OK; |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1269 | /* Walk the forwarding table and purge stale entries */ |
| 1270 | static void vxlan_cleanup(unsigned long arg) |
| 1271 | { |
| 1272 | struct vxlan_dev *vxlan = (struct vxlan_dev *) arg; |
| 1273 | unsigned long next_timer = jiffies + FDB_AGE_INTERVAL; |
| 1274 | unsigned int h; |
| 1275 | |
| 1276 | if (!netif_running(vxlan->dev)) |
| 1277 | return; |
| 1278 | |
| 1279 | spin_lock_bh(&vxlan->hash_lock); |
| 1280 | for (h = 0; h < FDB_HASH_SIZE; ++h) { |
| 1281 | struct hlist_node *p, *n; |
| 1282 | hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { |
| 1283 | struct vxlan_fdb *f |
| 1284 | = container_of(p, struct vxlan_fdb, hlist); |
| 1285 | unsigned long timeout; |
| 1286 | |
stephen hemminger | 3c17286 | 2012-10-26 06:24:34 +0000 | [diff] [blame] | 1287 | if (f->state & NUD_PERMANENT) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1288 | continue; |
| 1289 | |
| 1290 | timeout = f->used + vxlan->age_interval * HZ; |
| 1291 | if (time_before_eq(timeout, jiffies)) { |
| 1292 | netdev_dbg(vxlan->dev, |
| 1293 | "garbage collect %pM\n", |
| 1294 | f->eth_addr); |
| 1295 | f->state = NUD_STALE; |
| 1296 | vxlan_fdb_destroy(vxlan, f); |
| 1297 | } else if (time_before(timeout, next_timer)) |
| 1298 | next_timer = timeout; |
| 1299 | } |
| 1300 | } |
| 1301 | spin_unlock_bh(&vxlan->hash_lock); |
| 1302 | |
| 1303 | mod_timer(&vxlan->age_timer, next_timer); |
| 1304 | } |
| 1305 | |
| 1306 | /* Setup stats when device is created */ |
| 1307 | static int vxlan_init(struct net_device *dev) |
| 1308 | { |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1309 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1310 | struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id); |
| 1311 | struct vxlan_sock *vs; |
| 1312 | __u32 vni = vxlan->default_dst.remote_vni; |
| 1313 | |
Pravin B Shelar | e817104 | 2013-03-25 14:49:46 +0000 | [diff] [blame] | 1314 | dev->tstats = alloc_percpu(struct pcpu_tstats); |
| 1315 | if (!dev->tstats) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1316 | return -ENOMEM; |
| 1317 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1318 | spin_lock(&vn->sock_lock); |
| 1319 | vs = vxlan_find_port(dev_net(dev), vxlan->dst_port); |
| 1320 | if (vs) { |
| 1321 | /* If we have a socket with same port already, reuse it */ |
| 1322 | atomic_inc(&vs->refcnt); |
| 1323 | vxlan->vn_sock = vs; |
| 1324 | hlist_add_head_rcu(&vxlan->hlist, vni_head(vs, vni)); |
| 1325 | } else { |
| 1326 | /* otherwise make new socket outside of RTNL */ |
| 1327 | dev_hold(dev); |
| 1328 | queue_work(vxlan_wq, &vxlan->sock_work); |
| 1329 | } |
| 1330 | spin_unlock(&vn->sock_lock); |
| 1331 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1332 | return 0; |
| 1333 | } |
| 1334 | |
Stephen Hemminger | ba609e9 | 2013-06-25 17:06:01 -0700 | [diff] [blame] | 1335 | static void vxlan_fdb_delete_default(struct vxlan_dev *vxlan) |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1336 | { |
| 1337 | struct vxlan_fdb *f; |
| 1338 | |
| 1339 | spin_lock_bh(&vxlan->hash_lock); |
| 1340 | f = __vxlan_find_mac(vxlan, all_zeros_mac); |
| 1341 | if (f) |
| 1342 | vxlan_fdb_destroy(vxlan, f); |
| 1343 | spin_unlock_bh(&vxlan->hash_lock); |
| 1344 | } |
| 1345 | |
Stephen Hemminger | ebf4063 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1346 | static void vxlan_uninit(struct net_device *dev) |
| 1347 | { |
| 1348 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1349 | struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id); |
| 1350 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 1351 | |
Stephen Hemminger | ba609e9 | 2013-06-25 17:06:01 -0700 | [diff] [blame] | 1352 | vxlan_fdb_delete_default(vxlan); |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1353 | |
Stephen Hemminger | ebf4063 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1354 | if (vs) |
| 1355 | vxlan_sock_release(vn, vs); |
| 1356 | free_percpu(dev->tstats); |
| 1357 | } |
| 1358 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1359 | /* Start ageing timer and join group when device is brought up */ |
| 1360 | static int vxlan_open(struct net_device *dev) |
| 1361 | { |
| 1362 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1363 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 1364 | |
| 1365 | /* socket hasn't been created */ |
| 1366 | if (!vs) |
| 1367 | return -ENOTCONN; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1368 | |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1369 | if (IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip))) { |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1370 | vxlan_sock_hold(vs); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 1371 | dev_hold(dev); |
| 1372 | queue_work(vxlan_wq, &vxlan->igmp_work); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | if (vxlan->age_interval) |
| 1376 | mod_timer(&vxlan->age_timer, jiffies + FDB_AGE_INTERVAL); |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | /* Purge the forwarding table */ |
| 1382 | static void vxlan_flush(struct vxlan_dev *vxlan) |
| 1383 | { |
Cong Wang | 31fec5a | 2013-05-27 22:35:52 +0000 | [diff] [blame] | 1384 | unsigned int h; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1385 | |
| 1386 | spin_lock_bh(&vxlan->hash_lock); |
| 1387 | for (h = 0; h < FDB_HASH_SIZE; ++h) { |
| 1388 | struct hlist_node *p, *n; |
| 1389 | hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { |
| 1390 | struct vxlan_fdb *f |
| 1391 | = container_of(p, struct vxlan_fdb, hlist); |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1392 | /* the all_zeros_mac entry is deleted at vxlan_uninit */ |
| 1393 | if (!is_zero_ether_addr(f->eth_addr)) |
| 1394 | vxlan_fdb_destroy(vxlan, f); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | spin_unlock_bh(&vxlan->hash_lock); |
| 1398 | } |
| 1399 | |
| 1400 | /* Cleanup timer and forwarding table on shutdown */ |
| 1401 | static int vxlan_stop(struct net_device *dev) |
| 1402 | { |
| 1403 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1404 | struct vxlan_sock *vs = vxlan->vn_sock; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1405 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1406 | if (vs && IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip))) { |
| 1407 | vxlan_sock_hold(vs); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 1408 | dev_hold(dev); |
| 1409 | queue_work(vxlan_wq, &vxlan->igmp_work); |
| 1410 | } |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1411 | |
| 1412 | del_timer_sync(&vxlan->age_timer); |
| 1413 | |
| 1414 | vxlan_flush(vxlan); |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1419 | /* Stub, nothing needs to be done. */ |
| 1420 | static void vxlan_set_multicast_list(struct net_device *dev) |
| 1421 | { |
| 1422 | } |
| 1423 | |
| 1424 | static const struct net_device_ops vxlan_netdev_ops = { |
| 1425 | .ndo_init = vxlan_init, |
Stephen Hemminger | ebf4063 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1426 | .ndo_uninit = vxlan_uninit, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1427 | .ndo_open = vxlan_open, |
| 1428 | .ndo_stop = vxlan_stop, |
| 1429 | .ndo_start_xmit = vxlan_xmit, |
Pravin B Shelar | e817104 | 2013-03-25 14:49:46 +0000 | [diff] [blame] | 1430 | .ndo_get_stats64 = ip_tunnel_get_stats64, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1431 | .ndo_set_rx_mode = vxlan_set_multicast_list, |
| 1432 | .ndo_change_mtu = eth_change_mtu, |
| 1433 | .ndo_validate_addr = eth_validate_addr, |
| 1434 | .ndo_set_mac_address = eth_mac_addr, |
| 1435 | .ndo_fdb_add = vxlan_fdb_add, |
| 1436 | .ndo_fdb_del = vxlan_fdb_delete, |
| 1437 | .ndo_fdb_dump = vxlan_fdb_dump, |
| 1438 | }; |
| 1439 | |
| 1440 | /* Info for udev, that this is a virtual tunnel endpoint */ |
| 1441 | static struct device_type vxlan_type = { |
| 1442 | .name = "vxlan", |
| 1443 | }; |
| 1444 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1445 | /* Initialize the device structure. */ |
| 1446 | static void vxlan_setup(struct net_device *dev) |
| 1447 | { |
| 1448 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Cong Wang | 31fec5a | 2013-05-27 22:35:52 +0000 | [diff] [blame] | 1449 | unsigned int h; |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1450 | int low, high; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1451 | |
| 1452 | eth_hw_addr_random(dev); |
| 1453 | ether_setup(dev); |
stephen hemminger | 2840bf2 | 2012-10-09 20:35:51 +0000 | [diff] [blame] | 1454 | dev->hard_header_len = ETH_HLEN + VXLAN_HEADROOM; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1455 | |
| 1456 | dev->netdev_ops = &vxlan_netdev_ops; |
Stephen Hemminger | ebf4063 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1457 | dev->destructor = free_netdev; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1458 | SET_NETDEV_DEVTYPE(dev, &vxlan_type); |
| 1459 | |
| 1460 | dev->tx_queue_len = 0; |
| 1461 | dev->features |= NETIF_F_LLTX; |
| 1462 | dev->features |= NETIF_F_NETNS_LOCAL; |
Joseph Gasparakis | d6727fe | 2012-12-07 14:14:16 +0000 | [diff] [blame] | 1463 | dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; |
Joseph Gasparakis | 0afb166 | 2012-12-07 14:14:18 +0000 | [diff] [blame] | 1464 | dev->features |= NETIF_F_RXCSUM; |
Pravin B Shelar | 05c0db0 | 2013-03-07 13:22:36 +0000 | [diff] [blame] | 1465 | dev->features |= NETIF_F_GSO_SOFTWARE; |
Joseph Gasparakis | 0afb166 | 2012-12-07 14:14:18 +0000 | [diff] [blame] | 1466 | |
| 1467 | dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM; |
Pravin B Shelar | 05c0db0 | 2013-03-07 13:22:36 +0000 | [diff] [blame] | 1468 | dev->hw_features |= NETIF_F_GSO_SOFTWARE; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1469 | dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; |
stephen hemminger | 6602d00 | 2012-12-31 12:00:21 +0000 | [diff] [blame] | 1470 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1471 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1472 | INIT_LIST_HEAD(&vxlan->next); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1473 | spin_lock_init(&vxlan->hash_lock); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 1474 | INIT_WORK(&vxlan->igmp_work, vxlan_igmp_work); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1475 | INIT_WORK(&vxlan->sock_work, vxlan_sock_work); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1476 | |
| 1477 | init_timer_deferrable(&vxlan->age_timer); |
| 1478 | vxlan->age_timer.function = vxlan_cleanup; |
| 1479 | vxlan->age_timer.data = (unsigned long) vxlan; |
| 1480 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1481 | inet_get_local_port_range(&low, &high); |
| 1482 | vxlan->port_min = low; |
| 1483 | vxlan->port_max = high; |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1484 | vxlan->dst_port = htons(vxlan_port); |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1485 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1486 | vxlan->dev = dev; |
| 1487 | |
| 1488 | for (h = 0; h < FDB_HASH_SIZE; ++h) |
| 1489 | INIT_HLIST_HEAD(&vxlan->fdb_head[h]); |
| 1490 | } |
| 1491 | |
| 1492 | static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = { |
| 1493 | [IFLA_VXLAN_ID] = { .type = NLA_U32 }, |
stephen hemminger | 5d174dd | 2013-04-27 11:31:55 +0000 | [diff] [blame] | 1494 | [IFLA_VXLAN_GROUP] = { .len = FIELD_SIZEOF(struct iphdr, daddr) }, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1495 | [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, |
| 1496 | [IFLA_VXLAN_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) }, |
| 1497 | [IFLA_VXLAN_TOS] = { .type = NLA_U8 }, |
| 1498 | [IFLA_VXLAN_TTL] = { .type = NLA_U8 }, |
| 1499 | [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 }, |
| 1500 | [IFLA_VXLAN_AGEING] = { .type = NLA_U32 }, |
| 1501 | [IFLA_VXLAN_LIMIT] = { .type = NLA_U32 }, |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1502 | [IFLA_VXLAN_PORT_RANGE] = { .len = sizeof(struct ifla_vxlan_port_range) }, |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1503 | [IFLA_VXLAN_PROXY] = { .type = NLA_U8 }, |
| 1504 | [IFLA_VXLAN_RSC] = { .type = NLA_U8 }, |
| 1505 | [IFLA_VXLAN_L2MISS] = { .type = NLA_U8 }, |
| 1506 | [IFLA_VXLAN_L3MISS] = { .type = NLA_U8 }, |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1507 | [IFLA_VXLAN_PORT] = { .type = NLA_U16 }, |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[]) |
| 1511 | { |
| 1512 | if (tb[IFLA_ADDRESS]) { |
| 1513 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) { |
| 1514 | pr_debug("invalid link address (not ethernet)\n"); |
| 1515 | return -EINVAL; |
| 1516 | } |
| 1517 | |
| 1518 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) { |
| 1519 | pr_debug("invalid all zero ethernet address\n"); |
| 1520 | return -EADDRNOTAVAIL; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | if (!data) |
| 1525 | return -EINVAL; |
| 1526 | |
| 1527 | if (data[IFLA_VXLAN_ID]) { |
| 1528 | __u32 id = nla_get_u32(data[IFLA_VXLAN_ID]); |
| 1529 | if (id >= VXLAN_VID_MASK) |
| 1530 | return -ERANGE; |
| 1531 | } |
| 1532 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1533 | if (data[IFLA_VXLAN_PORT_RANGE]) { |
| 1534 | const struct ifla_vxlan_port_range *p |
| 1535 | = nla_data(data[IFLA_VXLAN_PORT_RANGE]); |
| 1536 | |
| 1537 | if (ntohs(p->high) < ntohs(p->low)) { |
| 1538 | pr_debug("port range %u .. %u not valid\n", |
| 1539 | ntohs(p->low), ntohs(p->high)); |
| 1540 | return -EINVAL; |
| 1541 | } |
| 1542 | } |
| 1543 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1544 | return 0; |
| 1545 | } |
| 1546 | |
Yan Burman | 1b13c97 | 2013-01-29 23:43:07 +0000 | [diff] [blame] | 1547 | static void vxlan_get_drvinfo(struct net_device *netdev, |
| 1548 | struct ethtool_drvinfo *drvinfo) |
| 1549 | { |
| 1550 | strlcpy(drvinfo->version, VXLAN_VERSION, sizeof(drvinfo->version)); |
| 1551 | strlcpy(drvinfo->driver, "vxlan", sizeof(drvinfo->driver)); |
| 1552 | } |
| 1553 | |
| 1554 | static const struct ethtool_ops vxlan_ethtool_ops = { |
| 1555 | .get_drvinfo = vxlan_get_drvinfo, |
| 1556 | .get_link = ethtool_op_get_link, |
| 1557 | }; |
| 1558 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1559 | static void vxlan_del_work(struct work_struct *work) |
| 1560 | { |
| 1561 | struct vxlan_sock *vs = container_of(work, struct vxlan_sock, del_work); |
| 1562 | |
| 1563 | sk_release_kernel(vs->sock->sk); |
| 1564 | kfree_rcu(vs, rcu); |
| 1565 | } |
| 1566 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1567 | static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port) |
| 1568 | { |
| 1569 | struct vxlan_sock *vs; |
| 1570 | struct sock *sk; |
| 1571 | struct sockaddr_in vxlan_addr = { |
| 1572 | .sin_family = AF_INET, |
| 1573 | .sin_addr.s_addr = htonl(INADDR_ANY), |
Stephen Hemminger | bb3fd68 | 2013-06-17 14:16:40 -0700 | [diff] [blame] | 1574 | .sin_port = port, |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1575 | }; |
| 1576 | int rc; |
Cong Wang | 31fec5a | 2013-05-27 22:35:52 +0000 | [diff] [blame] | 1577 | unsigned int h; |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1578 | |
| 1579 | vs = kmalloc(sizeof(*vs), GFP_KERNEL); |
| 1580 | if (!vs) |
| 1581 | return ERR_PTR(-ENOMEM); |
| 1582 | |
| 1583 | for (h = 0; h < VNI_HASH_SIZE; ++h) |
| 1584 | INIT_HLIST_HEAD(&vs->vni_list[h]); |
| 1585 | |
| 1586 | INIT_WORK(&vs->del_work, vxlan_del_work); |
| 1587 | |
| 1588 | /* Create UDP socket for encapsulation receive. */ |
| 1589 | rc = sock_create_kern(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &vs->sock); |
| 1590 | if (rc < 0) { |
| 1591 | pr_debug("UDP socket create failed\n"); |
| 1592 | kfree(vs); |
| 1593 | return ERR_PTR(rc); |
| 1594 | } |
| 1595 | |
| 1596 | /* Put in proper namespace */ |
| 1597 | sk = vs->sock->sk; |
| 1598 | sk_change_net(sk, net); |
| 1599 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1600 | rc = kernel_bind(vs->sock, (struct sockaddr *) &vxlan_addr, |
| 1601 | sizeof(vxlan_addr)); |
| 1602 | if (rc < 0) { |
| 1603 | pr_debug("bind for UDP socket %pI4:%u (%d)\n", |
| 1604 | &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc); |
| 1605 | sk_release_kernel(sk); |
| 1606 | kfree(vs); |
| 1607 | return ERR_PTR(rc); |
| 1608 | } |
| 1609 | |
| 1610 | /* Disable multicast loopback */ |
| 1611 | inet_sk(sk)->mc_loop = 0; |
| 1612 | |
| 1613 | /* Mark socket as an encapsulation socket. */ |
| 1614 | udp_sk(sk)->encap_type = 1; |
| 1615 | udp_sk(sk)->encap_rcv = vxlan_udp_encap_recv; |
| 1616 | udp_encap_enable(); |
Stephen Hemminger | 7c47ced | 2013-06-17 14:16:10 -0700 | [diff] [blame] | 1617 | atomic_set(&vs->refcnt, 1); |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1618 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1619 | return vs; |
| 1620 | } |
| 1621 | |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1622 | /* Scheduled at device creation to bind to a socket */ |
| 1623 | static void vxlan_sock_work(struct work_struct *work) |
| 1624 | { |
| 1625 | struct vxlan_dev *vxlan |
| 1626 | = container_of(work, struct vxlan_dev, sock_work); |
| 1627 | struct net_device *dev = vxlan->dev; |
| 1628 | struct net *net = dev_net(dev); |
| 1629 | __u32 vni = vxlan->default_dst.remote_vni; |
| 1630 | __be16 port = vxlan->dst_port; |
| 1631 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
| 1632 | struct vxlan_sock *nvs, *ovs; |
| 1633 | |
| 1634 | nvs = vxlan_socket_create(net, port); |
| 1635 | if (IS_ERR(nvs)) { |
| 1636 | netdev_err(vxlan->dev, "Can not create UDP socket, %ld\n", |
| 1637 | PTR_ERR(nvs)); |
| 1638 | goto out; |
| 1639 | } |
| 1640 | |
| 1641 | spin_lock(&vn->sock_lock); |
| 1642 | /* Look again to see if can reuse socket */ |
| 1643 | ovs = vxlan_find_port(net, port); |
| 1644 | if (ovs) { |
| 1645 | atomic_inc(&ovs->refcnt); |
| 1646 | vxlan->vn_sock = ovs; |
| 1647 | hlist_add_head_rcu(&vxlan->hlist, vni_head(ovs, vni)); |
| 1648 | spin_unlock(&vn->sock_lock); |
| 1649 | |
| 1650 | sk_release_kernel(nvs->sock->sk); |
| 1651 | kfree(nvs); |
| 1652 | } else { |
| 1653 | vxlan->vn_sock = nvs; |
| 1654 | hlist_add_head_rcu(&nvs->hlist, vs_head(net, port)); |
| 1655 | hlist_add_head_rcu(&vxlan->hlist, vni_head(nvs, vni)); |
| 1656 | spin_unlock(&vn->sock_lock); |
| 1657 | } |
| 1658 | out: |
| 1659 | dev_put(dev); |
| 1660 | } |
| 1661 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1662 | static int vxlan_newlink(struct net *net, struct net_device *dev, |
| 1663 | struct nlattr *tb[], struct nlattr *data[]) |
| 1664 | { |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1665 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1666 | struct vxlan_dev *vxlan = netdev_priv(dev); |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1667 | struct vxlan_rdst *dst = &vxlan->default_dst; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1668 | __u32 vni; |
| 1669 | int err; |
| 1670 | |
| 1671 | if (!data[IFLA_VXLAN_ID]) |
| 1672 | return -EINVAL; |
| 1673 | |
| 1674 | vni = nla_get_u32(data[IFLA_VXLAN_ID]); |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1675 | dst->remote_vni = vni; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1676 | |
stephen hemminger | 5d174dd | 2013-04-27 11:31:55 +0000 | [diff] [blame] | 1677 | if (data[IFLA_VXLAN_GROUP]) |
| 1678 | dst->remote_ip = nla_get_be32(data[IFLA_VXLAN_GROUP]); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1679 | |
| 1680 | if (data[IFLA_VXLAN_LOCAL]) |
| 1681 | vxlan->saddr = nla_get_be32(data[IFLA_VXLAN_LOCAL]); |
| 1682 | |
stephen hemminger | 34e02aa | 2012-10-09 20:35:53 +0000 | [diff] [blame] | 1683 | if (data[IFLA_VXLAN_LINK] && |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1684 | (dst->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]))) { |
stephen hemminger | 34e02aa | 2012-10-09 20:35:53 +0000 | [diff] [blame] | 1685 | struct net_device *lowerdev |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1686 | = __dev_get_by_index(net, dst->remote_ifindex); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1687 | |
stephen hemminger | 34e02aa | 2012-10-09 20:35:53 +0000 | [diff] [blame] | 1688 | if (!lowerdev) { |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1689 | pr_info("ifindex %d does not exist\n", dst->remote_ifindex); |
stephen hemminger | 34e02aa | 2012-10-09 20:35:53 +0000 | [diff] [blame] | 1690 | return -ENODEV; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1691 | } |
stephen hemminger | 34e02aa | 2012-10-09 20:35:53 +0000 | [diff] [blame] | 1692 | |
| 1693 | if (!tb[IFLA_MTU]) |
| 1694 | dev->mtu = lowerdev->mtu - VXLAN_HEADROOM; |
Alexander Duyck | 1ba56fb | 2012-11-13 13:10:59 +0000 | [diff] [blame] | 1695 | |
| 1696 | /* update header length based on lower device */ |
| 1697 | dev->hard_header_len = lowerdev->hard_header_len + |
| 1698 | VXLAN_HEADROOM; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | if (data[IFLA_VXLAN_TOS]) |
| 1702 | vxlan->tos = nla_get_u8(data[IFLA_VXLAN_TOS]); |
| 1703 | |
Vincent Bernat | afb9718 | 2012-10-30 10:27:16 +0000 | [diff] [blame] | 1704 | if (data[IFLA_VXLAN_TTL]) |
| 1705 | vxlan->ttl = nla_get_u8(data[IFLA_VXLAN_TTL]); |
| 1706 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1707 | if (!data[IFLA_VXLAN_LEARNING] || nla_get_u8(data[IFLA_VXLAN_LEARNING])) |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1708 | vxlan->flags |= VXLAN_F_LEARN; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1709 | |
| 1710 | if (data[IFLA_VXLAN_AGEING]) |
| 1711 | vxlan->age_interval = nla_get_u32(data[IFLA_VXLAN_AGEING]); |
| 1712 | else |
| 1713 | vxlan->age_interval = FDB_AGE_DEFAULT; |
| 1714 | |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1715 | if (data[IFLA_VXLAN_PROXY] && nla_get_u8(data[IFLA_VXLAN_PROXY])) |
| 1716 | vxlan->flags |= VXLAN_F_PROXY; |
| 1717 | |
| 1718 | if (data[IFLA_VXLAN_RSC] && nla_get_u8(data[IFLA_VXLAN_RSC])) |
| 1719 | vxlan->flags |= VXLAN_F_RSC; |
| 1720 | |
| 1721 | if (data[IFLA_VXLAN_L2MISS] && nla_get_u8(data[IFLA_VXLAN_L2MISS])) |
| 1722 | vxlan->flags |= VXLAN_F_L2MISS; |
| 1723 | |
| 1724 | if (data[IFLA_VXLAN_L3MISS] && nla_get_u8(data[IFLA_VXLAN_L3MISS])) |
| 1725 | vxlan->flags |= VXLAN_F_L3MISS; |
| 1726 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1727 | if (data[IFLA_VXLAN_LIMIT]) |
| 1728 | vxlan->addrmax = nla_get_u32(data[IFLA_VXLAN_LIMIT]); |
| 1729 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1730 | if (data[IFLA_VXLAN_PORT_RANGE]) { |
| 1731 | const struct ifla_vxlan_port_range *p |
| 1732 | = nla_data(data[IFLA_VXLAN_PORT_RANGE]); |
| 1733 | vxlan->port_min = ntohs(p->low); |
| 1734 | vxlan->port_max = ntohs(p->high); |
| 1735 | } |
| 1736 | |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1737 | if (data[IFLA_VXLAN_PORT]) |
| 1738 | vxlan->dst_port = nla_get_be16(data[IFLA_VXLAN_PORT]); |
| 1739 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1740 | if (vxlan_find_vni(net, vni, vxlan->dst_port)) { |
| 1741 | pr_info("duplicate VNI %u\n", vni); |
| 1742 | return -EEXIST; |
| 1743 | } |
| 1744 | |
Yan Burman | 1b13c97 | 2013-01-29 23:43:07 +0000 | [diff] [blame] | 1745 | SET_ETHTOOL_OPS(dev, &vxlan_ethtool_ops); |
| 1746 | |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1747 | /* create an fdb entry for default destination */ |
| 1748 | err = vxlan_fdb_create(vxlan, all_zeros_mac, |
| 1749 | vxlan->default_dst.remote_ip, |
| 1750 | NUD_REACHABLE|NUD_PERMANENT, |
| 1751 | NLM_F_EXCL|NLM_F_CREATE, |
| 1752 | vxlan->dst_port, vxlan->default_dst.remote_vni, |
| 1753 | vxlan->default_dst.remote_ifindex, NTF_SELF); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1754 | if (err) |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1755 | return err; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1756 | |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1757 | err = register_netdevice(dev); |
| 1758 | if (err) { |
Stephen Hemminger | ba609e9 | 2013-06-25 17:06:01 -0700 | [diff] [blame] | 1759 | vxlan_fdb_delete_default(vxlan); |
Mike Rapoport | afbd8ba | 2013-06-25 16:01:51 +0300 | [diff] [blame] | 1760 | return err; |
| 1761 | } |
| 1762 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1763 | list_add(&vxlan->next, &vn->vxlan_list); |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1764 | |
| 1765 | return 0; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | static void vxlan_dellink(struct net_device *dev, struct list_head *head) |
| 1769 | { |
stephen hemminger | fe5c356 | 2013-07-13 10:18:18 -0700 | [diff] [blame] | 1770 | struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1771 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1772 | |
stephen hemminger | fe5c356 | 2013-07-13 10:18:18 -0700 | [diff] [blame] | 1773 | flush_workqueue(vxlan_wq); |
| 1774 | |
| 1775 | spin_lock(&vn->sock_lock); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1776 | hlist_del_rcu(&vxlan->hlist); |
stephen hemminger | fe5c356 | 2013-07-13 10:18:18 -0700 | [diff] [blame] | 1777 | spin_unlock(&vn->sock_lock); |
| 1778 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1779 | list_del(&vxlan->next); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1780 | unregister_netdevice_queue(dev, head); |
| 1781 | } |
| 1782 | |
| 1783 | static size_t vxlan_get_size(const struct net_device *dev) |
| 1784 | { |
| 1785 | |
| 1786 | return nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_ID */ |
stephen hemminger | 5d174dd | 2013-04-27 11:31:55 +0000 | [diff] [blame] | 1787 | nla_total_size(sizeof(__be32)) +/* IFLA_VXLAN_GROUP */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1788 | nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LINK */ |
| 1789 | nla_total_size(sizeof(__be32))+ /* IFLA_VXLAN_LOCAL */ |
| 1790 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TTL */ |
| 1791 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TOS */ |
| 1792 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_LEARNING */ |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1793 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_PROXY */ |
| 1794 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_RSC */ |
| 1795 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_L2MISS */ |
| 1796 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_L3MISS */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1797 | nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_AGEING */ |
| 1798 | nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LIMIT */ |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1799 | nla_total_size(sizeof(struct ifla_vxlan_port_range)) + |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1800 | nla_total_size(sizeof(__be16))+ /* IFLA_VXLAN_PORT */ |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1801 | 0; |
| 1802 | } |
| 1803 | |
| 1804 | static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) |
| 1805 | { |
| 1806 | const struct vxlan_dev *vxlan = netdev_priv(dev); |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1807 | const struct vxlan_rdst *dst = &vxlan->default_dst; |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1808 | struct ifla_vxlan_port_range ports = { |
| 1809 | .low = htons(vxlan->port_min), |
| 1810 | .high = htons(vxlan->port_max), |
| 1811 | }; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1812 | |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1813 | if (nla_put_u32(skb, IFLA_VXLAN_ID, dst->remote_vni)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1814 | goto nla_put_failure; |
| 1815 | |
stephen hemminger | 5d174dd | 2013-04-27 11:31:55 +0000 | [diff] [blame] | 1816 | if (dst->remote_ip && nla_put_be32(skb, IFLA_VXLAN_GROUP, dst->remote_ip)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1817 | goto nla_put_failure; |
| 1818 | |
Atzm Watanabe | c7995c4 | 2013-04-16 02:50:52 +0000 | [diff] [blame] | 1819 | if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1820 | goto nla_put_failure; |
| 1821 | |
Stephen Hemminger | 7c41c42 | 2012-10-08 14:55:30 -0700 | [diff] [blame] | 1822 | if (vxlan->saddr && nla_put_be32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1823 | goto nla_put_failure; |
| 1824 | |
| 1825 | if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->ttl) || |
| 1826 | nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->tos) || |
David Stevens | e4f67ad | 2012-11-20 02:50:14 +0000 | [diff] [blame] | 1827 | nla_put_u8(skb, IFLA_VXLAN_LEARNING, |
| 1828 | !!(vxlan->flags & VXLAN_F_LEARN)) || |
| 1829 | nla_put_u8(skb, IFLA_VXLAN_PROXY, |
| 1830 | !!(vxlan->flags & VXLAN_F_PROXY)) || |
| 1831 | nla_put_u8(skb, IFLA_VXLAN_RSC, !!(vxlan->flags & VXLAN_F_RSC)) || |
| 1832 | nla_put_u8(skb, IFLA_VXLAN_L2MISS, |
| 1833 | !!(vxlan->flags & VXLAN_F_L2MISS)) || |
| 1834 | nla_put_u8(skb, IFLA_VXLAN_L3MISS, |
| 1835 | !!(vxlan->flags & VXLAN_F_L3MISS)) || |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1836 | nla_put_u32(skb, IFLA_VXLAN_AGEING, vxlan->age_interval) || |
stephen hemminger | 823aa87 | 2013-04-27 11:31:57 +0000 | [diff] [blame] | 1837 | nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->addrmax) || |
| 1838 | nla_put_be16(skb, IFLA_VXLAN_PORT, vxlan->dst_port)) |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1839 | goto nla_put_failure; |
| 1840 | |
stephen hemminger | 05f47d6 | 2012-10-09 20:35:50 +0000 | [diff] [blame] | 1841 | if (nla_put(skb, IFLA_VXLAN_PORT_RANGE, sizeof(ports), &ports)) |
| 1842 | goto nla_put_failure; |
| 1843 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1844 | return 0; |
| 1845 | |
| 1846 | nla_put_failure: |
| 1847 | return -EMSGSIZE; |
| 1848 | } |
| 1849 | |
| 1850 | static struct rtnl_link_ops vxlan_link_ops __read_mostly = { |
| 1851 | .kind = "vxlan", |
| 1852 | .maxtype = IFLA_VXLAN_MAX, |
| 1853 | .policy = vxlan_policy, |
| 1854 | .priv_size = sizeof(struct vxlan_dev), |
| 1855 | .setup = vxlan_setup, |
| 1856 | .validate = vxlan_validate, |
| 1857 | .newlink = vxlan_newlink, |
| 1858 | .dellink = vxlan_dellink, |
| 1859 | .get_size = vxlan_get_size, |
| 1860 | .fill_info = vxlan_fill_info, |
| 1861 | }; |
| 1862 | |
| 1863 | static __net_init int vxlan_init_net(struct net *net) |
| 1864 | { |
| 1865 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
Cong Wang | 31fec5a | 2013-05-27 22:35:52 +0000 | [diff] [blame] | 1866 | unsigned int h; |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1867 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1868 | INIT_LIST_HEAD(&vn->vxlan_list); |
Stephen Hemminger | 1c51a91 | 2013-06-17 14:16:11 -0700 | [diff] [blame] | 1869 | spin_lock_init(&vn->sock_lock); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1870 | |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1871 | for (h = 0; h < PORT_HASH_SIZE; ++h) |
| 1872 | INIT_HLIST_HEAD(&vn->sock_list[h]); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1873 | |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | static __net_exit void vxlan_exit_net(struct net *net) |
| 1878 | { |
| 1879 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
Zang MingJie | 9cb6cb7 | 2013-03-06 04:37:37 +0000 | [diff] [blame] | 1880 | struct vxlan_dev *vxlan; |
Zang MingJie | 9cb6cb7 | 2013-03-06 04:37:37 +0000 | [diff] [blame] | 1881 | |
| 1882 | rtnl_lock(); |
stephen hemminger | 553675f | 2013-05-16 11:35:20 +0000 | [diff] [blame] | 1883 | list_for_each_entry(vxlan, &vn->vxlan_list, next) |
| 1884 | dev_close(vxlan->dev); |
Zang MingJie | 9cb6cb7 | 2013-03-06 04:37:37 +0000 | [diff] [blame] | 1885 | rtnl_unlock(); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | static struct pernet_operations vxlan_net_ops = { |
| 1889 | .init = vxlan_init_net, |
| 1890 | .exit = vxlan_exit_net, |
| 1891 | .id = &vxlan_net_id, |
| 1892 | .size = sizeof(struct vxlan_net), |
| 1893 | }; |
| 1894 | |
| 1895 | static int __init vxlan_init_module(void) |
| 1896 | { |
| 1897 | int rc; |
| 1898 | |
Stephen Hemminger | 758c57d | 2013-06-17 14:16:09 -0700 | [diff] [blame] | 1899 | vxlan_wq = alloc_workqueue("vxlan", 0, 0); |
| 1900 | if (!vxlan_wq) |
| 1901 | return -ENOMEM; |
| 1902 | |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1903 | get_random_bytes(&vxlan_salt, sizeof(vxlan_salt)); |
| 1904 | |
| 1905 | rc = register_pernet_device(&vxlan_net_ops); |
| 1906 | if (rc) |
| 1907 | goto out1; |
| 1908 | |
| 1909 | rc = rtnl_link_register(&vxlan_link_ops); |
| 1910 | if (rc) |
| 1911 | goto out2; |
| 1912 | |
| 1913 | return 0; |
| 1914 | |
| 1915 | out2: |
| 1916 | unregister_pernet_device(&vxlan_net_ops); |
| 1917 | out1: |
Stephen Hemminger | 758c57d | 2013-06-17 14:16:09 -0700 | [diff] [blame] | 1918 | destroy_workqueue(vxlan_wq); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1919 | return rc; |
| 1920 | } |
Cong Wang | 7332a13 | 2013-05-27 22:35:53 +0000 | [diff] [blame] | 1921 | late_initcall(vxlan_init_module); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1922 | |
| 1923 | static void __exit vxlan_cleanup_module(void) |
| 1924 | { |
Stephen Hemminger | b715398 | 2013-06-17 14:16:09 -0700 | [diff] [blame] | 1925 | rtnl_link_unregister(&vxlan_link_ops); |
Stephen Hemminger | 758c57d | 2013-06-17 14:16:09 -0700 | [diff] [blame] | 1926 | destroy_workqueue(vxlan_wq); |
Pravin B Shelar | f89e57c | 2013-07-11 11:38:06 -0700 | [diff] [blame] | 1927 | unregister_pernet_device(&vxlan_net_ops); |
David Stevens | 6681712 | 2013-03-15 04:35:51 +0000 | [diff] [blame] | 1928 | rcu_barrier(); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1929 | } |
| 1930 | module_exit(vxlan_cleanup_module); |
| 1931 | |
| 1932 | MODULE_LICENSE("GPL"); |
| 1933 | MODULE_VERSION(VXLAN_VERSION); |
stephen hemminger | 3b8df3c | 2013-04-27 11:31:52 +0000 | [diff] [blame] | 1934 | MODULE_AUTHOR("Stephen Hemminger <stephen@networkplumber.org>"); |
stephen hemminger | d342894 | 2012-10-01 12:32:35 +0000 | [diff] [blame] | 1935 | MODULE_ALIAS_RTNL_LINK("vxlan"); |