John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1 | /* |
| 2 | * GENEVE: Generic Network Virtualization Encapsulation |
| 3 | * |
| 4 | * Copyright (c) 2015 Red Hat, Inc. |
| 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 | |
| 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <linux/hash.h> |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 18 | #include <net/dst_metadata.h> |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 19 | #include <net/gro_cells.h> |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 20 | #include <net/rtnetlink.h> |
| 21 | #include <net/geneve.h> |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 22 | #include <net/protocol.h> |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 23 | |
| 24 | #define GENEVE_NETDEV_VER "0.6" |
| 25 | |
| 26 | #define GENEVE_UDP_PORT 6081 |
| 27 | |
| 28 | #define GENEVE_N_VID (1u << 24) |
| 29 | #define GENEVE_VID_MASK (GENEVE_N_VID - 1) |
| 30 | |
| 31 | #define VNI_HASH_BITS 10 |
| 32 | #define VNI_HASH_SIZE (1<<VNI_HASH_BITS) |
| 33 | |
| 34 | static bool log_ecn_error = true; |
| 35 | module_param(log_ecn_error, bool, 0644); |
| 36 | MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); |
| 37 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 38 | #define GENEVE_VER 0 |
| 39 | #define GENEVE_BASE_HLEN (sizeof(struct udphdr) + sizeof(struct genevehdr)) |
| 40 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 41 | /* per-network namespace private data for this module */ |
| 42 | struct geneve_net { |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 43 | struct list_head geneve_list; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 44 | struct list_head sock_list; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 47 | static int geneve_net_id; |
| 48 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 49 | union geneve_addr { |
| 50 | struct sockaddr_in sin; |
| 51 | struct sockaddr_in6 sin6; |
| 52 | struct sockaddr sa; |
| 53 | }; |
| 54 | |
| 55 | static union geneve_addr geneve_remote_unspec = { .sa.sa_family = AF_UNSPEC, }; |
| 56 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 57 | /* Pseudo network device */ |
| 58 | struct geneve_dev { |
| 59 | struct hlist_node hlist; /* vni hash table */ |
| 60 | struct net *net; /* netns for packet i/o */ |
| 61 | struct net_device *dev; /* netdev for geneve tunnel */ |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 62 | struct geneve_sock *sock4; /* IPv4 socket used for geneve tunnel */ |
| 63 | #if IS_ENABLED(CONFIG_IPV6) |
| 64 | struct geneve_sock *sock6; /* IPv6 socket used for geneve tunnel */ |
| 65 | #endif |
John W. Linville | 8760ce5 | 2015-06-01 15:51:34 -0400 | [diff] [blame] | 66 | u8 vni[3]; /* virtual network ID for tunnel */ |
| 67 | u8 ttl; /* TTL override */ |
John W. Linville | d895112 | 2015-06-01 15:51:35 -0400 | [diff] [blame] | 68 | u8 tos; /* TOS override */ |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 69 | union geneve_addr remote; /* IP address for link partner */ |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 70 | struct list_head next; /* geneve's per namespace list */ |
Pravin B Shelar | cd7918b | 2015-08-26 23:46:51 -0700 | [diff] [blame] | 71 | __be16 dst_port; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 72 | bool collect_md; |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 73 | struct gro_cells gro_cells; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 74 | }; |
| 75 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 76 | struct geneve_sock { |
| 77 | bool collect_md; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 78 | struct list_head list; |
| 79 | struct socket *sock; |
| 80 | struct rcu_head rcu; |
| 81 | int refcnt; |
| 82 | struct udp_offload udp_offloads; |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 83 | struct hlist_head vni_list[VNI_HASH_SIZE]; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 84 | }; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 85 | |
| 86 | static inline __u32 geneve_net_vni_hash(u8 vni[3]) |
| 87 | { |
| 88 | __u32 vnid; |
| 89 | |
| 90 | vnid = (vni[0] << 16) | (vni[1] << 8) | vni[2]; |
| 91 | return hash_32(vnid, VNI_HASH_BITS); |
| 92 | } |
| 93 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 94 | static __be64 vni_to_tunnel_id(const __u8 *vni) |
| 95 | { |
| 96 | #ifdef __BIG_ENDIAN |
| 97 | return (vni[0] << 16) | (vni[1] << 8) | vni[2]; |
| 98 | #else |
| 99 | return (__force __be64)(((__force u64)vni[0] << 40) | |
| 100 | ((__force u64)vni[1] << 48) | |
| 101 | ((__force u64)vni[2] << 56)); |
| 102 | #endif |
| 103 | } |
| 104 | |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 105 | static struct geneve_dev *geneve_lookup(struct geneve_sock *gs, |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 106 | __be32 addr, u8 vni[]) |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 107 | { |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 108 | struct hlist_head *vni_list_head; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 109 | struct geneve_dev *geneve; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 110 | __u32 hash; |
| 111 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 112 | /* Find the device for this VNI */ |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 113 | hash = geneve_net_vni_hash(vni); |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 114 | vni_list_head = &gs->vni_list[hash]; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 115 | hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) { |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 116 | if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) && |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 117 | addr == geneve->remote.sin.sin_addr.s_addr) |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 118 | return geneve; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 119 | } |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 120 | return NULL; |
| 121 | } |
| 122 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 123 | #if IS_ENABLED(CONFIG_IPV6) |
| 124 | static struct geneve_dev *geneve6_lookup(struct geneve_sock *gs, |
| 125 | struct in6_addr addr6, u8 vni[]) |
| 126 | { |
| 127 | struct hlist_head *vni_list_head; |
| 128 | struct geneve_dev *geneve; |
| 129 | __u32 hash; |
| 130 | |
| 131 | /* Find the device for this VNI */ |
| 132 | hash = geneve_net_vni_hash(vni); |
| 133 | vni_list_head = &gs->vni_list[hash]; |
| 134 | hlist_for_each_entry_rcu(geneve, vni_list_head, hlist) { |
| 135 | if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) && |
| 136 | ipv6_addr_equal(&addr6, &geneve->remote.sin6.sin6_addr)) |
| 137 | return geneve; |
| 138 | } |
| 139 | return NULL; |
| 140 | } |
| 141 | #endif |
| 142 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 143 | static inline struct genevehdr *geneve_hdr(const struct sk_buff *skb) |
| 144 | { |
| 145 | return (struct genevehdr *)(udp_hdr(skb) + 1); |
| 146 | } |
| 147 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 148 | /* geneve receive/decap routine */ |
| 149 | static void geneve_rx(struct geneve_sock *gs, struct sk_buff *skb) |
| 150 | { |
| 151 | struct genevehdr *gnvh = geneve_hdr(skb); |
| 152 | struct metadata_dst *tun_dst = NULL; |
| 153 | struct geneve_dev *geneve = NULL; |
| 154 | struct pcpu_sw_netstats *stats; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 155 | struct iphdr *iph = NULL; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 156 | __be32 addr; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 157 | static u8 zero_vni[3]; |
| 158 | u8 *vni; |
| 159 | int err = 0; |
| 160 | sa_family_t sa_family; |
| 161 | #if IS_ENABLED(CONFIG_IPV6) |
| 162 | struct ipv6hdr *ip6h = NULL; |
| 163 | struct in6_addr addr6; |
| 164 | static struct in6_addr zero_addr6; |
| 165 | #endif |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 166 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 167 | sa_family = gs->sock->sk->sk_family; |
John W. Linville | 08399ef | 2015-09-21 10:29:09 -0400 | [diff] [blame] | 168 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 169 | if (sa_family == AF_INET) { |
| 170 | iph = ip_hdr(skb); /* outer IP header... */ |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 171 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 172 | if (gs->collect_md) { |
| 173 | vni = zero_vni; |
| 174 | addr = 0; |
| 175 | } else { |
| 176 | vni = gnvh->vni; |
| 177 | |
| 178 | addr = iph->saddr; |
| 179 | } |
| 180 | |
| 181 | geneve = geneve_lookup(gs, addr, vni); |
| 182 | #if IS_ENABLED(CONFIG_IPV6) |
| 183 | } else if (sa_family == AF_INET6) { |
| 184 | ip6h = ipv6_hdr(skb); /* outer IPv6 header... */ |
| 185 | |
| 186 | if (gs->collect_md) { |
| 187 | vni = zero_vni; |
| 188 | addr6 = zero_addr6; |
| 189 | } else { |
| 190 | vni = gnvh->vni; |
| 191 | |
| 192 | addr6 = ip6h->saddr; |
| 193 | } |
| 194 | |
| 195 | geneve = geneve6_lookup(gs, addr6, vni); |
| 196 | #endif |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 197 | } |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 198 | if (!geneve) |
| 199 | goto drop; |
| 200 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 201 | if (ip_tunnel_collect_metadata() || gs->collect_md) { |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 202 | __be16 flags; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 203 | |
| 204 | flags = TUNNEL_KEY | TUNNEL_GENEVE_OPT | |
| 205 | (gnvh->oam ? TUNNEL_OAM : 0) | |
| 206 | (gnvh->critical ? TUNNEL_CRIT_OPT : 0); |
| 207 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 208 | tun_dst = udp_tun_rx_dst(skb, sa_family, flags, |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 209 | vni_to_tunnel_id(gnvh->vni), |
| 210 | gnvh->opt_len * 4); |
| 211 | if (!tun_dst) |
| 212 | goto drop; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 213 | /* Update tunnel dst according to Geneve options. */ |
Pravin B Shelar | 4c22279 | 2015-08-30 18:09:38 -0700 | [diff] [blame] | 214 | ip_tunnel_info_opts_set(&tun_dst->u.tun_info, |
| 215 | gnvh->options, gnvh->opt_len * 4); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 216 | } else { |
| 217 | /* Drop packets w/ critical options, |
| 218 | * since we don't support any... |
| 219 | */ |
| 220 | if (gnvh->critical) |
| 221 | goto drop; |
| 222 | } |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 223 | |
| 224 | skb_reset_mac_header(skb); |
| 225 | skb_scrub_packet(skb, !net_eq(geneve->net, dev_net(geneve->dev))); |
| 226 | skb->protocol = eth_type_trans(skb, geneve->dev); |
| 227 | skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN); |
| 228 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 229 | if (tun_dst) |
| 230 | skb_dst_set(skb, &tun_dst->dst); |
| 231 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 232 | /* Ignore packet loops (and multicast echo) */ |
| 233 | if (ether_addr_equal(eth_hdr(skb)->h_source, geneve->dev->dev_addr)) |
| 234 | goto drop; |
| 235 | |
| 236 | skb_reset_network_header(skb); |
| 237 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 238 | if (iph) |
| 239 | err = IP_ECN_decapsulate(iph, skb); |
| 240 | #if IS_ENABLED(CONFIG_IPV6) |
| 241 | if (ip6h) |
| 242 | err = IP6_ECN_decapsulate(ip6h, skb); |
| 243 | #endif |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 244 | |
| 245 | if (unlikely(err)) { |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 246 | if (log_ecn_error) { |
| 247 | if (iph) |
| 248 | net_info_ratelimited("non-ECT from %pI4 " |
| 249 | "with TOS=%#x\n", |
| 250 | &iph->saddr, iph->tos); |
| 251 | #if IS_ENABLED(CONFIG_IPV6) |
| 252 | if (ip6h) |
| 253 | net_info_ratelimited("non-ECT from %pI6\n", |
| 254 | &ip6h->saddr); |
| 255 | #endif |
| 256 | } |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 257 | if (err > 1) { |
| 258 | ++geneve->dev->stats.rx_frame_errors; |
| 259 | ++geneve->dev->stats.rx_errors; |
| 260 | goto drop; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | stats = this_cpu_ptr(geneve->dev->tstats); |
| 265 | u64_stats_update_begin(&stats->syncp); |
| 266 | stats->rx_packets++; |
| 267 | stats->rx_bytes += skb->len; |
| 268 | u64_stats_update_end(&stats->syncp); |
| 269 | |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 270 | gro_cells_receive(&geneve->gro_cells, skb); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 271 | return; |
| 272 | drop: |
| 273 | /* Consume bad packet */ |
| 274 | kfree_skb(skb); |
| 275 | } |
| 276 | |
| 277 | /* Setup stats when device is created */ |
| 278 | static int geneve_init(struct net_device *dev) |
| 279 | { |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 280 | struct geneve_dev *geneve = netdev_priv(dev); |
| 281 | int err; |
| 282 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 283 | dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
| 284 | if (!dev->tstats) |
| 285 | return -ENOMEM; |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 286 | |
| 287 | err = gro_cells_init(&geneve->gro_cells, dev); |
| 288 | if (err) { |
| 289 | free_percpu(dev->tstats); |
| 290 | return err; |
| 291 | } |
| 292 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static void geneve_uninit(struct net_device *dev) |
| 297 | { |
Jesse Gross | 8e816df | 2015-08-28 16:54:40 -0700 | [diff] [blame] | 298 | struct geneve_dev *geneve = netdev_priv(dev); |
| 299 | |
| 300 | gro_cells_destroy(&geneve->gro_cells); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 301 | free_percpu(dev->tstats); |
| 302 | } |
| 303 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 304 | /* Callback from net/ipv4/udp.c to receive packets */ |
| 305 | static int geneve_udp_encap_recv(struct sock *sk, struct sk_buff *skb) |
| 306 | { |
| 307 | struct genevehdr *geneveh; |
| 308 | struct geneve_sock *gs; |
| 309 | int opts_len; |
| 310 | |
| 311 | /* Need Geneve and inner Ethernet header to be present */ |
| 312 | if (unlikely(!pskb_may_pull(skb, GENEVE_BASE_HLEN))) |
| 313 | goto error; |
| 314 | |
| 315 | /* Return packets with reserved bits set */ |
| 316 | geneveh = geneve_hdr(skb); |
| 317 | if (unlikely(geneveh->ver != GENEVE_VER)) |
| 318 | goto error; |
| 319 | |
| 320 | if (unlikely(geneveh->proto_type != htons(ETH_P_TEB))) |
| 321 | goto error; |
| 322 | |
| 323 | opts_len = geneveh->opt_len * 4; |
| 324 | if (iptunnel_pull_header(skb, GENEVE_BASE_HLEN + opts_len, |
| 325 | htons(ETH_P_TEB))) |
| 326 | goto drop; |
| 327 | |
| 328 | gs = rcu_dereference_sk_user_data(sk); |
| 329 | if (!gs) |
| 330 | goto drop; |
| 331 | |
| 332 | geneve_rx(gs, skb); |
| 333 | return 0; |
| 334 | |
| 335 | drop: |
| 336 | /* Consume bad packet */ |
| 337 | kfree_skb(skb); |
| 338 | return 0; |
| 339 | |
| 340 | error: |
| 341 | /* Let the UDP layer deal with the skb */ |
| 342 | return 1; |
| 343 | } |
| 344 | |
| 345 | static struct socket *geneve_create_sock(struct net *net, bool ipv6, |
| 346 | __be16 port) |
| 347 | { |
| 348 | struct socket *sock; |
| 349 | struct udp_port_cfg udp_conf; |
| 350 | int err; |
| 351 | |
| 352 | memset(&udp_conf, 0, sizeof(udp_conf)); |
| 353 | |
| 354 | if (ipv6) { |
| 355 | udp_conf.family = AF_INET6; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 356 | udp_conf.ipv6_v6only = 1; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 357 | } else { |
| 358 | udp_conf.family = AF_INET; |
| 359 | udp_conf.local_ip.s_addr = htonl(INADDR_ANY); |
| 360 | } |
| 361 | |
| 362 | udp_conf.local_udp_port = port; |
| 363 | |
| 364 | /* Open UDP socket */ |
| 365 | err = udp_sock_create(net, &udp_conf, &sock); |
| 366 | if (err < 0) |
| 367 | return ERR_PTR(err); |
| 368 | |
| 369 | return sock; |
| 370 | } |
| 371 | |
| 372 | static void geneve_notify_add_rx_port(struct geneve_sock *gs) |
| 373 | { |
| 374 | struct sock *sk = gs->sock->sk; |
| 375 | sa_family_t sa_family = sk->sk_family; |
| 376 | int err; |
| 377 | |
| 378 | if (sa_family == AF_INET) { |
Hannes Frederic Sowa | 787d7ac | 2016-01-07 14:28:39 +0100 | [diff] [blame^] | 379 | err = udp_add_offload(sock_net(sk), &gs->udp_offloads); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 380 | if (err) |
| 381 | pr_warn("geneve: udp_add_offload failed with status %d\n", |
| 382 | err); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static int geneve_hlen(struct genevehdr *gh) |
| 387 | { |
| 388 | return sizeof(*gh) + gh->opt_len * 4; |
| 389 | } |
| 390 | |
| 391 | static struct sk_buff **geneve_gro_receive(struct sk_buff **head, |
| 392 | struct sk_buff *skb, |
| 393 | struct udp_offload *uoff) |
| 394 | { |
| 395 | struct sk_buff *p, **pp = NULL; |
| 396 | struct genevehdr *gh, *gh2; |
| 397 | unsigned int hlen, gh_len, off_gnv; |
| 398 | const struct packet_offload *ptype; |
| 399 | __be16 type; |
| 400 | int flush = 1; |
| 401 | |
| 402 | off_gnv = skb_gro_offset(skb); |
| 403 | hlen = off_gnv + sizeof(*gh); |
| 404 | gh = skb_gro_header_fast(skb, off_gnv); |
| 405 | if (skb_gro_header_hard(skb, hlen)) { |
| 406 | gh = skb_gro_header_slow(skb, hlen, off_gnv); |
| 407 | if (unlikely(!gh)) |
| 408 | goto out; |
| 409 | } |
| 410 | |
| 411 | if (gh->ver != GENEVE_VER || gh->oam) |
| 412 | goto out; |
| 413 | gh_len = geneve_hlen(gh); |
| 414 | |
| 415 | hlen = off_gnv + gh_len; |
| 416 | if (skb_gro_header_hard(skb, hlen)) { |
| 417 | gh = skb_gro_header_slow(skb, hlen, off_gnv); |
| 418 | if (unlikely(!gh)) |
| 419 | goto out; |
| 420 | } |
| 421 | |
| 422 | flush = 0; |
| 423 | |
| 424 | for (p = *head; p; p = p->next) { |
| 425 | if (!NAPI_GRO_CB(p)->same_flow) |
| 426 | continue; |
| 427 | |
| 428 | gh2 = (struct genevehdr *)(p->data + off_gnv); |
| 429 | if (gh->opt_len != gh2->opt_len || |
| 430 | memcmp(gh, gh2, gh_len)) { |
| 431 | NAPI_GRO_CB(p)->same_flow = 0; |
| 432 | continue; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | type = gh->proto_type; |
| 437 | |
| 438 | rcu_read_lock(); |
| 439 | ptype = gro_find_receive_by_type(type); |
| 440 | if (!ptype) { |
| 441 | flush = 1; |
| 442 | goto out_unlock; |
| 443 | } |
| 444 | |
| 445 | skb_gro_pull(skb, gh_len); |
| 446 | skb_gro_postpull_rcsum(skb, gh, gh_len); |
| 447 | pp = ptype->callbacks.gro_receive(head, skb); |
| 448 | |
| 449 | out_unlock: |
| 450 | rcu_read_unlock(); |
| 451 | out: |
| 452 | NAPI_GRO_CB(skb)->flush |= flush; |
| 453 | |
| 454 | return pp; |
| 455 | } |
| 456 | |
| 457 | static int geneve_gro_complete(struct sk_buff *skb, int nhoff, |
| 458 | struct udp_offload *uoff) |
| 459 | { |
| 460 | struct genevehdr *gh; |
| 461 | struct packet_offload *ptype; |
| 462 | __be16 type; |
| 463 | int gh_len; |
| 464 | int err = -ENOSYS; |
| 465 | |
| 466 | udp_tunnel_gro_complete(skb, nhoff); |
| 467 | |
| 468 | gh = (struct genevehdr *)(skb->data + nhoff); |
| 469 | gh_len = geneve_hlen(gh); |
| 470 | type = gh->proto_type; |
| 471 | |
| 472 | rcu_read_lock(); |
| 473 | ptype = gro_find_complete_by_type(type); |
| 474 | if (ptype) |
| 475 | err = ptype->callbacks.gro_complete(skb, nhoff + gh_len); |
| 476 | |
| 477 | rcu_read_unlock(); |
| 478 | return err; |
| 479 | } |
| 480 | |
| 481 | /* Create new listen socket if needed */ |
| 482 | static struct geneve_sock *geneve_socket_create(struct net *net, __be16 port, |
| 483 | bool ipv6) |
| 484 | { |
| 485 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
| 486 | struct geneve_sock *gs; |
| 487 | struct socket *sock; |
| 488 | struct udp_tunnel_sock_cfg tunnel_cfg; |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 489 | int h; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 490 | |
| 491 | gs = kzalloc(sizeof(*gs), GFP_KERNEL); |
| 492 | if (!gs) |
| 493 | return ERR_PTR(-ENOMEM); |
| 494 | |
| 495 | sock = geneve_create_sock(net, ipv6, port); |
| 496 | if (IS_ERR(sock)) { |
| 497 | kfree(gs); |
| 498 | return ERR_CAST(sock); |
| 499 | } |
| 500 | |
| 501 | gs->sock = sock; |
| 502 | gs->refcnt = 1; |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 503 | for (h = 0; h < VNI_HASH_SIZE; ++h) |
| 504 | INIT_HLIST_HEAD(&gs->vni_list[h]); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 505 | |
| 506 | /* Initialize the geneve udp offloads structure */ |
| 507 | gs->udp_offloads.port = port; |
| 508 | gs->udp_offloads.callbacks.gro_receive = geneve_gro_receive; |
| 509 | gs->udp_offloads.callbacks.gro_complete = geneve_gro_complete; |
| 510 | geneve_notify_add_rx_port(gs); |
| 511 | |
| 512 | /* Mark socket as an encapsulation socket */ |
| 513 | tunnel_cfg.sk_user_data = gs; |
| 514 | tunnel_cfg.encap_type = 1; |
| 515 | tunnel_cfg.encap_rcv = geneve_udp_encap_recv; |
| 516 | tunnel_cfg.encap_destroy = NULL; |
| 517 | setup_udp_tunnel_sock(net, sock, &tunnel_cfg); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 518 | list_add(&gs->list, &gn->sock_list); |
| 519 | return gs; |
| 520 | } |
| 521 | |
| 522 | static void geneve_notify_del_rx_port(struct geneve_sock *gs) |
| 523 | { |
| 524 | struct sock *sk = gs->sock->sk; |
| 525 | sa_family_t sa_family = sk->sk_family; |
| 526 | |
| 527 | if (sa_family == AF_INET) |
| 528 | udp_del_offload(&gs->udp_offloads); |
| 529 | } |
| 530 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 531 | static void __geneve_sock_release(struct geneve_sock *gs) |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 532 | { |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 533 | if (!gs || --gs->refcnt) |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 534 | return; |
| 535 | |
| 536 | list_del(&gs->list); |
| 537 | geneve_notify_del_rx_port(gs); |
| 538 | udp_tunnel_sock_release(gs->sock); |
| 539 | kfree_rcu(gs, rcu); |
| 540 | } |
| 541 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 542 | static void geneve_sock_release(struct geneve_dev *geneve) |
| 543 | { |
| 544 | __geneve_sock_release(geneve->sock4); |
| 545 | #if IS_ENABLED(CONFIG_IPV6) |
| 546 | __geneve_sock_release(geneve->sock6); |
| 547 | #endif |
| 548 | } |
| 549 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 550 | static struct geneve_sock *geneve_find_sock(struct geneve_net *gn, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 551 | sa_family_t family, |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 552 | __be16 dst_port) |
| 553 | { |
| 554 | struct geneve_sock *gs; |
| 555 | |
| 556 | list_for_each_entry(gs, &gn->sock_list, list) { |
| 557 | if (inet_sk(gs->sock->sk)->inet_sport == dst_port && |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 558 | inet_sk(gs->sock->sk)->sk.sk_family == family) { |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 559 | return gs; |
| 560 | } |
| 561 | } |
| 562 | return NULL; |
| 563 | } |
| 564 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 565 | static int geneve_sock_add(struct geneve_dev *geneve, bool ipv6) |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 566 | { |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 567 | struct net *net = geneve->net; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 568 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 569 | struct geneve_sock *gs; |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 570 | __u32 hash; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 571 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 572 | gs = geneve_find_sock(gn, ipv6 ? AF_INET6 : AF_INET, geneve->dst_port); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 573 | if (gs) { |
| 574 | gs->refcnt++; |
| 575 | goto out; |
| 576 | } |
| 577 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 578 | gs = geneve_socket_create(net, geneve->dst_port, ipv6); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 579 | if (IS_ERR(gs)) |
| 580 | return PTR_ERR(gs); |
| 581 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 582 | out: |
| 583 | gs->collect_md = geneve->collect_md; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 584 | #if IS_ENABLED(CONFIG_IPV6) |
| 585 | if (ipv6) |
| 586 | geneve->sock6 = gs; |
| 587 | else |
| 588 | #endif |
| 589 | geneve->sock4 = gs; |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 590 | |
| 591 | hash = geneve_net_vni_hash(geneve->vni); |
| 592 | hlist_add_head_rcu(&geneve->hlist, &gs->vni_list[hash]); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 596 | static int geneve_open(struct net_device *dev) |
| 597 | { |
| 598 | struct geneve_dev *geneve = netdev_priv(dev); |
| 599 | bool ipv6 = geneve->remote.sa.sa_family == AF_INET6; |
| 600 | bool metadata = geneve->collect_md; |
| 601 | int ret = 0; |
| 602 | |
| 603 | geneve->sock4 = NULL; |
| 604 | #if IS_ENABLED(CONFIG_IPV6) |
| 605 | geneve->sock6 = NULL; |
| 606 | if (ipv6 || metadata) |
| 607 | ret = geneve_sock_add(geneve, true); |
| 608 | #endif |
| 609 | if (!ret && (!ipv6 || metadata)) |
| 610 | ret = geneve_sock_add(geneve, false); |
| 611 | if (ret < 0) |
| 612 | geneve_sock_release(geneve); |
| 613 | |
| 614 | return ret; |
| 615 | } |
| 616 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 617 | static int geneve_stop(struct net_device *dev) |
| 618 | { |
| 619 | struct geneve_dev *geneve = netdev_priv(dev); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 620 | |
Pravin B Shelar | 66d4700 | 2015-08-26 23:46:55 -0700 | [diff] [blame] | 621 | if (!hlist_unhashed(&geneve->hlist)) |
| 622 | hlist_del_rcu(&geneve->hlist); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 623 | geneve_sock_release(geneve); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 624 | return 0; |
| 625 | } |
| 626 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 627 | static void geneve_build_header(struct genevehdr *geneveh, |
| 628 | __be16 tun_flags, u8 vni[3], |
| 629 | u8 options_len, u8 *options) |
| 630 | { |
| 631 | geneveh->ver = GENEVE_VER; |
| 632 | geneveh->opt_len = options_len / 4; |
| 633 | geneveh->oam = !!(tun_flags & TUNNEL_OAM); |
| 634 | geneveh->critical = !!(tun_flags & TUNNEL_CRIT_OPT); |
| 635 | geneveh->rsvd1 = 0; |
| 636 | memcpy(geneveh->vni, vni, 3); |
| 637 | geneveh->proto_type = htons(ETH_P_TEB); |
| 638 | geneveh->rsvd2 = 0; |
| 639 | |
| 640 | memcpy(geneveh->options, options, options_len); |
| 641 | } |
| 642 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 643 | static int geneve_build_skb(struct rtable *rt, struct sk_buff *skb, |
| 644 | __be16 tun_flags, u8 vni[3], u8 opt_len, u8 *opt, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 645 | bool csum, bool xnet) |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 646 | { |
| 647 | struct genevehdr *gnvh; |
| 648 | int min_headroom; |
| 649 | int err; |
| 650 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 651 | skb_scrub_packet(skb, xnet); |
| 652 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 653 | min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len |
| 654 | + GENEVE_BASE_HLEN + opt_len + sizeof(struct iphdr); |
| 655 | err = skb_cow_head(skb, min_headroom); |
| 656 | if (unlikely(err)) { |
| 657 | kfree_skb(skb); |
| 658 | goto free_rt; |
| 659 | } |
| 660 | |
| 661 | skb = udp_tunnel_handle_offloads(skb, csum); |
| 662 | if (IS_ERR(skb)) { |
| 663 | err = PTR_ERR(skb); |
| 664 | goto free_rt; |
| 665 | } |
| 666 | |
| 667 | gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 668 | geneve_build_header(gnvh, tun_flags, vni, opt_len, opt); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 669 | |
| 670 | skb_set_inner_protocol(skb, htons(ETH_P_TEB)); |
| 671 | return 0; |
| 672 | |
| 673 | free_rt: |
| 674 | ip_rt_put(rt); |
| 675 | return err; |
| 676 | } |
| 677 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 678 | #if IS_ENABLED(CONFIG_IPV6) |
| 679 | static int geneve6_build_skb(struct dst_entry *dst, struct sk_buff *skb, |
| 680 | __be16 tun_flags, u8 vni[3], u8 opt_len, u8 *opt, |
| 681 | bool csum, bool xnet) |
| 682 | { |
| 683 | struct genevehdr *gnvh; |
| 684 | int min_headroom; |
| 685 | int err; |
| 686 | |
| 687 | skb_scrub_packet(skb, xnet); |
| 688 | |
| 689 | min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len |
| 690 | + GENEVE_BASE_HLEN + opt_len + sizeof(struct ipv6hdr); |
| 691 | err = skb_cow_head(skb, min_headroom); |
| 692 | if (unlikely(err)) { |
| 693 | kfree_skb(skb); |
| 694 | goto free_dst; |
| 695 | } |
| 696 | |
| 697 | skb = udp_tunnel_handle_offloads(skb, csum); |
| 698 | if (IS_ERR(skb)) { |
| 699 | err = PTR_ERR(skb); |
| 700 | goto free_dst; |
| 701 | } |
| 702 | |
| 703 | gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len); |
| 704 | geneve_build_header(gnvh, tun_flags, vni, opt_len, opt); |
| 705 | |
| 706 | skb_set_inner_protocol(skb, htons(ETH_P_TEB)); |
| 707 | return 0; |
| 708 | |
| 709 | free_dst: |
| 710 | dst_release(dst); |
| 711 | return err; |
| 712 | } |
| 713 | #endif |
| 714 | |
| 715 | static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, |
| 716 | struct net_device *dev, |
| 717 | struct flowi4 *fl4, |
| 718 | struct ip_tunnel_info *info) |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 719 | { |
| 720 | struct geneve_dev *geneve = netdev_priv(dev); |
| 721 | struct rtable *rt = NULL; |
| 722 | __u8 tos; |
| 723 | |
| 724 | memset(fl4, 0, sizeof(*fl4)); |
| 725 | fl4->flowi4_mark = skb->mark; |
| 726 | fl4->flowi4_proto = IPPROTO_UDP; |
| 727 | |
| 728 | if (info) { |
| 729 | fl4->daddr = info->key.u.ipv4.dst; |
| 730 | fl4->saddr = info->key.u.ipv4.src; |
| 731 | fl4->flowi4_tos = RT_TOS(info->key.tos); |
| 732 | } else { |
| 733 | tos = geneve->tos; |
| 734 | if (tos == 1) { |
| 735 | const struct iphdr *iip = ip_hdr(skb); |
| 736 | |
| 737 | tos = ip_tunnel_get_dsfield(iip, skb); |
| 738 | } |
| 739 | |
| 740 | fl4->flowi4_tos = RT_TOS(tos); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 741 | fl4->daddr = geneve->remote.sin.sin_addr.s_addr; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | rt = ip_route_output_key(geneve->net, fl4); |
| 745 | if (IS_ERR(rt)) { |
| 746 | netdev_dbg(dev, "no route to %pI4\n", &fl4->daddr); |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 747 | return ERR_PTR(-ENETUNREACH); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 748 | } |
| 749 | if (rt->dst.dev == dev) { /* is this necessary? */ |
| 750 | netdev_dbg(dev, "circular route to %pI4\n", &fl4->daddr); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 751 | ip_rt_put(rt); |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 752 | return ERR_PTR(-ELOOP); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 753 | } |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 754 | return rt; |
| 755 | } |
| 756 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 757 | #if IS_ENABLED(CONFIG_IPV6) |
| 758 | static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, |
| 759 | struct net_device *dev, |
| 760 | struct flowi6 *fl6, |
| 761 | struct ip_tunnel_info *info) |
| 762 | { |
| 763 | struct geneve_dev *geneve = netdev_priv(dev); |
| 764 | struct geneve_sock *gs6 = geneve->sock6; |
| 765 | struct dst_entry *dst = NULL; |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 766 | __u8 prio; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 767 | |
| 768 | memset(fl6, 0, sizeof(*fl6)); |
| 769 | fl6->flowi6_mark = skb->mark; |
| 770 | fl6->flowi6_proto = IPPROTO_UDP; |
| 771 | |
| 772 | if (info) { |
| 773 | fl6->daddr = info->key.u.ipv6.dst; |
| 774 | fl6->saddr = info->key.u.ipv6.src; |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 775 | fl6->flowi6_tos = RT_TOS(info->key.tos); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 776 | } else { |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 777 | prio = geneve->tos; |
| 778 | if (prio == 1) { |
| 779 | const struct iphdr *iip = ip_hdr(skb); |
| 780 | |
| 781 | prio = ip_tunnel_get_dsfield(iip, skb); |
| 782 | } |
| 783 | |
| 784 | fl6->flowi6_tos = RT_TOS(prio); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 785 | fl6->daddr = geneve->remote.sin6.sin6_addr; |
| 786 | } |
| 787 | |
| 788 | if (ipv6_stub->ipv6_dst_lookup(geneve->net, gs6->sock->sk, &dst, fl6)) { |
| 789 | netdev_dbg(dev, "no route to %pI6\n", &fl6->daddr); |
| 790 | return ERR_PTR(-ENETUNREACH); |
| 791 | } |
| 792 | if (dst->dev == dev) { /* is this necessary? */ |
| 793 | netdev_dbg(dev, "circular route to %pI6\n", &fl6->daddr); |
| 794 | dst_release(dst); |
| 795 | return ERR_PTR(-ELOOP); |
| 796 | } |
| 797 | |
| 798 | return dst; |
| 799 | } |
| 800 | #endif |
| 801 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 802 | /* Convert 64 bit tunnel ID to 24 bit VNI. */ |
| 803 | static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni) |
| 804 | { |
| 805 | #ifdef __BIG_ENDIAN |
| 806 | vni[0] = (__force __u8)(tun_id >> 16); |
| 807 | vni[1] = (__force __u8)(tun_id >> 8); |
| 808 | vni[2] = (__force __u8)tun_id; |
| 809 | #else |
| 810 | vni[0] = (__force __u8)((__force u64)tun_id >> 40); |
| 811 | vni[1] = (__force __u8)((__force u64)tun_id >> 48); |
| 812 | vni[2] = (__force __u8)((__force u64)tun_id >> 56); |
| 813 | #endif |
| 814 | } |
| 815 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 816 | static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, |
| 817 | struct ip_tunnel_info *info) |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 818 | { |
| 819 | struct geneve_dev *geneve = netdev_priv(dev); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 820 | struct geneve_sock *gs4 = geneve->sock4; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 821 | struct rtable *rt = NULL; |
John W. Linville | 08399ef | 2015-09-21 10:29:09 -0400 | [diff] [blame] | 822 | const struct iphdr *iip; /* interior IP header */ |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 823 | int err = -EINVAL; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 824 | struct flowi4 fl4; |
John W. Linville | 8760ce5 | 2015-06-01 15:51:34 -0400 | [diff] [blame] | 825 | __u8 tos, ttl; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 826 | __be16 sport; |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 827 | bool udp_csum; |
| 828 | __be16 df; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 829 | bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 830 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 831 | if (geneve->collect_md) { |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 832 | if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 833 | netdev_dbg(dev, "no tunnel metadata\n"); |
| 834 | goto tx_error; |
| 835 | } |
Jiri Benc | 7f9562a | 2015-08-28 20:48:20 +0200 | [diff] [blame] | 836 | if (info && ip_tunnel_info_af(info) != AF_INET) |
| 837 | goto tx_error; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 838 | } |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 839 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 840 | rt = geneve_get_v4_rt(skb, dev, &fl4, info); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 841 | if (IS_ERR(rt)) { |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 842 | err = PTR_ERR(rt); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 843 | goto tx_error; |
| 844 | } |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 845 | |
| 846 | sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 847 | skb_reset_mac_header(skb); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 848 | |
John W. Linville | 08399ef | 2015-09-21 10:29:09 -0400 | [diff] [blame] | 849 | iip = ip_hdr(skb); |
| 850 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 851 | if (info) { |
| 852 | const struct ip_tunnel_key *key = &info->key; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 853 | u8 *opts = NULL; |
| 854 | u8 vni[3]; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 855 | |
| 856 | tunnel_id_to_vni(key->tun_id, vni); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 857 | if (key->tun_flags & TUNNEL_GENEVE_OPT) |
Pravin B Shelar | 4c22279 | 2015-08-30 18:09:38 -0700 | [diff] [blame] | 858 | opts = ip_tunnel_info_opts(info); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 859 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 860 | udp_csum = !!(key->tun_flags & TUNNEL_CSUM); |
| 861 | err = geneve_build_skb(rt, skb, key->tun_flags, vni, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 862 | info->options_len, opts, udp_csum, xnet); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 863 | if (unlikely(err)) |
| 864 | goto err; |
| 865 | |
John W. Linville | 08399ef | 2015-09-21 10:29:09 -0400 | [diff] [blame] | 866 | tos = ip_tunnel_ecn_encap(key->tos, iip, skb); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 867 | ttl = key->ttl; |
| 868 | df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 869 | } else { |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 870 | udp_csum = false; |
| 871 | err = geneve_build_skb(rt, skb, 0, geneve->vni, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 872 | 0, NULL, udp_csum, xnet); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 873 | if (unlikely(err)) |
| 874 | goto err; |
| 875 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 876 | tos = ip_tunnel_ecn_encap(fl4.flowi4_tos, iip, skb); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 877 | ttl = geneve->ttl; |
| 878 | if (!ttl && IN_MULTICAST(ntohl(fl4.daddr))) |
| 879 | ttl = 1; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 880 | ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 881 | df = 0; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 882 | } |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 883 | err = udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, fl4.saddr, fl4.daddr, |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 884 | tos, ttl, df, sport, geneve->dst_port, |
| 885 | !net_eq(geneve->net, dev_net(geneve->dev)), |
| 886 | !udp_csum); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 887 | |
| 888 | iptunnel_xmit_stats(err, &dev->stats, dev->tstats); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 889 | return NETDEV_TX_OK; |
| 890 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 891 | tx_error: |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 892 | dev_kfree_skb(skb); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 893 | err: |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 894 | if (err == -ELOOP) |
| 895 | dev->stats.collisions++; |
| 896 | else if (err == -ENETUNREACH) |
| 897 | dev->stats.tx_carrier_errors++; |
| 898 | else |
| 899 | dev->stats.tx_errors++; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 900 | return NETDEV_TX_OK; |
| 901 | } |
| 902 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 903 | #if IS_ENABLED(CONFIG_IPV6) |
| 904 | static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev, |
| 905 | struct ip_tunnel_info *info) |
| 906 | { |
| 907 | struct geneve_dev *geneve = netdev_priv(dev); |
| 908 | struct geneve_sock *gs6 = geneve->sock6; |
| 909 | struct dst_entry *dst = NULL; |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 910 | const struct iphdr *iip; /* interior IP header */ |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 911 | int err = -EINVAL; |
| 912 | struct flowi6 fl6; |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 913 | __u8 prio, ttl; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 914 | __be16 sport; |
| 915 | bool udp_csum; |
| 916 | bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); |
| 917 | |
| 918 | if (geneve->collect_md) { |
| 919 | if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { |
| 920 | netdev_dbg(dev, "no tunnel metadata\n"); |
| 921 | goto tx_error; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | dst = geneve_get_v6_dst(skb, dev, &fl6, info); |
| 926 | if (IS_ERR(dst)) { |
| 927 | err = PTR_ERR(dst); |
| 928 | goto tx_error; |
| 929 | } |
| 930 | |
| 931 | sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); |
| 932 | skb_reset_mac_header(skb); |
| 933 | |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 934 | iip = ip_hdr(skb); |
| 935 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 936 | if (info) { |
| 937 | const struct ip_tunnel_key *key = &info->key; |
| 938 | u8 *opts = NULL; |
| 939 | u8 vni[3]; |
| 940 | |
| 941 | tunnel_id_to_vni(key->tun_id, vni); |
| 942 | if (key->tun_flags & TUNNEL_GENEVE_OPT) |
| 943 | opts = ip_tunnel_info_opts(info); |
| 944 | |
| 945 | udp_csum = !!(key->tun_flags & TUNNEL_CSUM); |
| 946 | err = geneve6_build_skb(dst, skb, key->tun_flags, vni, |
| 947 | info->options_len, opts, |
| 948 | udp_csum, xnet); |
| 949 | if (unlikely(err)) |
| 950 | goto err; |
| 951 | |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 952 | prio = ip_tunnel_ecn_encap(key->tos, iip, skb); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 953 | ttl = key->ttl; |
| 954 | } else { |
| 955 | udp_csum = false; |
| 956 | err = geneve6_build_skb(dst, skb, 0, geneve->vni, |
| 957 | 0, NULL, udp_csum, xnet); |
| 958 | if (unlikely(err)) |
| 959 | goto err; |
| 960 | |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 961 | prio = ip_tunnel_ecn_encap(fl6.flowi6_tos, iip, skb); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 962 | ttl = geneve->ttl; |
| 963 | if (!ttl && ipv6_addr_is_multicast(&fl6.daddr)) |
| 964 | ttl = 1; |
| 965 | ttl = ttl ? : ip6_dst_hoplimit(dst); |
| 966 | } |
| 967 | err = udp_tunnel6_xmit_skb(dst, gs6->sock->sk, skb, dev, |
John W. Linville | 3a56f86 | 2015-10-26 17:01:45 -0400 | [diff] [blame] | 968 | &fl6.saddr, &fl6.daddr, prio, ttl, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 969 | sport, geneve->dst_port, !udp_csum); |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 970 | return NETDEV_TX_OK; |
| 971 | |
| 972 | tx_error: |
| 973 | dev_kfree_skb(skb); |
| 974 | err: |
| 975 | if (err == -ELOOP) |
| 976 | dev->stats.collisions++; |
| 977 | else if (err == -ENETUNREACH) |
| 978 | dev->stats.tx_carrier_errors++; |
| 979 | else |
| 980 | dev->stats.tx_errors++; |
| 981 | return NETDEV_TX_OK; |
| 982 | } |
| 983 | #endif |
| 984 | |
| 985 | static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev) |
| 986 | { |
| 987 | struct geneve_dev *geneve = netdev_priv(dev); |
| 988 | struct ip_tunnel_info *info = NULL; |
| 989 | |
| 990 | if (geneve->collect_md) |
| 991 | info = skb_tunnel_info(skb); |
| 992 | |
| 993 | #if IS_ENABLED(CONFIG_IPV6) |
| 994 | if ((info && ip_tunnel_info_af(info) == AF_INET6) || |
| 995 | (!info && geneve->remote.sa.sa_family == AF_INET6)) |
| 996 | return geneve6_xmit_skb(skb, dev, info); |
| 997 | #endif |
| 998 | return geneve_xmit_skb(skb, dev, info); |
| 999 | } |
| 1000 | |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1001 | static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) |
| 1002 | { |
| 1003 | struct ip_tunnel_info *info = skb_tunnel_info(skb); |
| 1004 | struct geneve_dev *geneve = netdev_priv(dev); |
| 1005 | struct rtable *rt; |
| 1006 | struct flowi4 fl4; |
John W. Linville | b8812fa | 2015-10-27 09:49:00 -0400 | [diff] [blame] | 1007 | #if IS_ENABLED(CONFIG_IPV6) |
| 1008 | struct dst_entry *dst; |
| 1009 | struct flowi6 fl6; |
| 1010 | #endif |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1011 | |
John W. Linville | b8812fa | 2015-10-27 09:49:00 -0400 | [diff] [blame] | 1012 | if (ip_tunnel_info_af(info) == AF_INET) { |
| 1013 | rt = geneve_get_v4_rt(skb, dev, &fl4, info); |
| 1014 | if (IS_ERR(rt)) |
| 1015 | return PTR_ERR(rt); |
| 1016 | |
| 1017 | ip_rt_put(rt); |
| 1018 | info->key.u.ipv4.src = fl4.saddr; |
| 1019 | #if IS_ENABLED(CONFIG_IPV6) |
| 1020 | } else if (ip_tunnel_info_af(info) == AF_INET6) { |
| 1021 | dst = geneve_get_v6_dst(skb, dev, &fl6, info); |
| 1022 | if (IS_ERR(dst)) |
| 1023 | return PTR_ERR(dst); |
| 1024 | |
| 1025 | dst_release(dst); |
| 1026 | info->key.u.ipv6.src = fl6.saddr; |
| 1027 | #endif |
| 1028 | } else { |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1029 | return -EINVAL; |
John W. Linville | b8812fa | 2015-10-27 09:49:00 -0400 | [diff] [blame] | 1030 | } |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1031 | |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1032 | info->key.tp_src = udp_flow_src_port(geneve->net, skb, |
| 1033 | 1, USHRT_MAX, true); |
| 1034 | info->key.tp_dst = geneve->dst_port; |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1038 | static const struct net_device_ops geneve_netdev_ops = { |
| 1039 | .ndo_init = geneve_init, |
| 1040 | .ndo_uninit = geneve_uninit, |
| 1041 | .ndo_open = geneve_open, |
| 1042 | .ndo_stop = geneve_stop, |
| 1043 | .ndo_start_xmit = geneve_xmit, |
| 1044 | .ndo_get_stats64 = ip_tunnel_get_stats64, |
| 1045 | .ndo_change_mtu = eth_change_mtu, |
| 1046 | .ndo_validate_addr = eth_validate_addr, |
| 1047 | .ndo_set_mac_address = eth_mac_addr, |
Pravin B Shelar | fc4099f | 2015-10-22 18:17:16 -0700 | [diff] [blame] | 1048 | .ndo_fill_metadata_dst = geneve_fill_metadata_dst, |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1049 | }; |
| 1050 | |
| 1051 | static void geneve_get_drvinfo(struct net_device *dev, |
| 1052 | struct ethtool_drvinfo *drvinfo) |
| 1053 | { |
| 1054 | strlcpy(drvinfo->version, GENEVE_NETDEV_VER, sizeof(drvinfo->version)); |
| 1055 | strlcpy(drvinfo->driver, "geneve", sizeof(drvinfo->driver)); |
| 1056 | } |
| 1057 | |
| 1058 | static const struct ethtool_ops geneve_ethtool_ops = { |
| 1059 | .get_drvinfo = geneve_get_drvinfo, |
| 1060 | .get_link = ethtool_op_get_link, |
| 1061 | }; |
| 1062 | |
| 1063 | /* Info for udev, that this is a virtual tunnel endpoint */ |
| 1064 | static struct device_type geneve_type = { |
| 1065 | .name = "geneve", |
| 1066 | }; |
| 1067 | |
| 1068 | /* Initialize the device structure. */ |
| 1069 | static void geneve_setup(struct net_device *dev) |
| 1070 | { |
| 1071 | ether_setup(dev); |
| 1072 | |
| 1073 | dev->netdev_ops = &geneve_netdev_ops; |
| 1074 | dev->ethtool_ops = &geneve_ethtool_ops; |
| 1075 | dev->destructor = free_netdev; |
| 1076 | |
| 1077 | SET_NETDEV_DEVTYPE(dev, &geneve_type); |
| 1078 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1079 | dev->features |= NETIF_F_LLTX; |
| 1080 | dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; |
| 1081 | dev->features |= NETIF_F_RXCSUM; |
| 1082 | dev->features |= NETIF_F_GSO_SOFTWARE; |
| 1083 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1084 | dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM; |
| 1085 | dev->hw_features |= NETIF_F_GSO_SOFTWARE; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1086 | |
| 1087 | netif_keep_dst(dev); |
Phil Sutter | ed961ac | 2015-08-18 10:30:31 +0200 | [diff] [blame] | 1088 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_NO_QUEUE; |
Pravin B Shelar | 87cd3dc | 2015-08-26 23:46:48 -0700 | [diff] [blame] | 1089 | eth_hw_addr_random(dev); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | static const struct nla_policy geneve_policy[IFLA_GENEVE_MAX + 1] = { |
| 1093 | [IFLA_GENEVE_ID] = { .type = NLA_U32 }, |
| 1094 | [IFLA_GENEVE_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) }, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1095 | [IFLA_GENEVE_REMOTE6] = { .len = sizeof(struct in6_addr) }, |
John W. Linville | 8760ce5 | 2015-06-01 15:51:34 -0400 | [diff] [blame] | 1096 | [IFLA_GENEVE_TTL] = { .type = NLA_U8 }, |
John W. Linville | d895112 | 2015-06-01 15:51:35 -0400 | [diff] [blame] | 1097 | [IFLA_GENEVE_TOS] = { .type = NLA_U8 }, |
Pravin B Shelar | cd7918b | 2015-08-26 23:46:51 -0700 | [diff] [blame] | 1098 | [IFLA_GENEVE_PORT] = { .type = NLA_U16 }, |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1099 | [IFLA_GENEVE_COLLECT_METADATA] = { .type = NLA_FLAG }, |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | static int geneve_validate(struct nlattr *tb[], struct nlattr *data[]) |
| 1103 | { |
| 1104 | if (tb[IFLA_ADDRESS]) { |
| 1105 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 1109 | return -EADDRNOTAVAIL; |
| 1110 | } |
| 1111 | |
| 1112 | if (!data) |
| 1113 | return -EINVAL; |
| 1114 | |
| 1115 | if (data[IFLA_GENEVE_ID]) { |
| 1116 | __u32 vni = nla_get_u32(data[IFLA_GENEVE_ID]); |
| 1117 | |
| 1118 | if (vni >= GENEVE_VID_MASK) |
| 1119 | return -ERANGE; |
| 1120 | } |
| 1121 | |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1125 | static struct geneve_dev *geneve_find_dev(struct geneve_net *gn, |
| 1126 | __be16 dst_port, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1127 | union geneve_addr *remote, |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1128 | u8 vni[], |
| 1129 | bool *tun_on_same_port, |
| 1130 | bool *tun_collect_md) |
| 1131 | { |
| 1132 | struct geneve_dev *geneve, *t; |
| 1133 | |
| 1134 | *tun_on_same_port = false; |
| 1135 | *tun_collect_md = false; |
| 1136 | t = NULL; |
| 1137 | list_for_each_entry(geneve, &gn->geneve_list, next) { |
| 1138 | if (geneve->dst_port == dst_port) { |
| 1139 | *tun_collect_md = geneve->collect_md; |
| 1140 | *tun_on_same_port = true; |
| 1141 | } |
| 1142 | if (!memcmp(vni, geneve->vni, sizeof(geneve->vni)) && |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1143 | !memcmp(remote, &geneve->remote, sizeof(geneve->remote)) && |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1144 | dst_port == geneve->dst_port) |
| 1145 | t = geneve; |
| 1146 | } |
| 1147 | return t; |
| 1148 | } |
| 1149 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1150 | static int geneve_configure(struct net *net, struct net_device *dev, |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1151 | union geneve_addr *remote, |
| 1152 | __u32 vni, __u8 ttl, __u8 tos, __be16 dst_port, |
| 1153 | bool metadata) |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1154 | { |
| 1155 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1156 | struct geneve_dev *t, *geneve = netdev_priv(dev); |
| 1157 | bool tun_collect_md, tun_on_same_port; |
Paolo Abeni | 184fc8b | 2015-12-23 16:54:27 +0100 | [diff] [blame] | 1158 | int err, encap_len; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1159 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1160 | if (!remote) |
| 1161 | return -EINVAL; |
| 1162 | if (metadata && |
| 1163 | (remote->sa.sa_family != AF_UNSPEC || vni || tos || ttl)) |
| 1164 | return -EINVAL; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1165 | |
| 1166 | geneve->net = net; |
| 1167 | geneve->dev = dev; |
| 1168 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1169 | geneve->vni[0] = (vni & 0x00ff0000) >> 16; |
| 1170 | geneve->vni[1] = (vni & 0x0000ff00) >> 8; |
| 1171 | geneve->vni[2] = vni & 0x000000ff; |
| 1172 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1173 | if ((remote->sa.sa_family == AF_INET && |
| 1174 | IN_MULTICAST(ntohl(remote->sin.sin_addr.s_addr))) || |
| 1175 | (remote->sa.sa_family == AF_INET6 && |
| 1176 | ipv6_addr_is_multicast(&remote->sin6.sin6_addr))) |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1177 | return -EINVAL; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1178 | geneve->remote = *remote; |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1179 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1180 | geneve->ttl = ttl; |
| 1181 | geneve->tos = tos; |
John W. Linville | 7bbe33f | 2015-09-22 13:09:32 -0400 | [diff] [blame] | 1182 | geneve->dst_port = dst_port; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1183 | geneve->collect_md = metadata; |
| 1184 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1185 | t = geneve_find_dev(gn, dst_port, remote, geneve->vni, |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1186 | &tun_on_same_port, &tun_collect_md); |
| 1187 | if (t) |
| 1188 | return -EBUSY; |
| 1189 | |
Paolo Abeni | 184fc8b | 2015-12-23 16:54:27 +0100 | [diff] [blame] | 1190 | /* make enough headroom for basic scenario */ |
| 1191 | encap_len = GENEVE_BASE_HLEN + ETH_HLEN; |
| 1192 | if (remote->sa.sa_family == AF_INET) |
| 1193 | encap_len += sizeof(struct iphdr); |
| 1194 | else |
| 1195 | encap_len += sizeof(struct ipv6hdr); |
| 1196 | dev->needed_headroom = encap_len + ETH_HLEN; |
| 1197 | |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1198 | if (metadata) { |
| 1199 | if (tun_on_same_port) |
| 1200 | return -EPERM; |
| 1201 | } else { |
| 1202 | if (tun_collect_md) |
| 1203 | return -EPERM; |
| 1204 | } |
| 1205 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1206 | err = register_netdevice(dev); |
| 1207 | if (err) |
| 1208 | return err; |
| 1209 | |
| 1210 | list_add(&geneve->next, &gn->geneve_list); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1211 | return 0; |
| 1212 | } |
| 1213 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1214 | static int geneve_newlink(struct net *net, struct net_device *dev, |
| 1215 | struct nlattr *tb[], struct nlattr *data[]) |
| 1216 | { |
John W. Linville | 7bbe33f | 2015-09-22 13:09:32 -0400 | [diff] [blame] | 1217 | __be16 dst_port = htons(GENEVE_UDP_PORT); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1218 | __u8 ttl = 0, tos = 0; |
| 1219 | bool metadata = false; |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1220 | union geneve_addr remote = geneve_remote_unspec; |
Jesse Gross | e277de5 | 2015-10-16 16:36:00 -0700 | [diff] [blame] | 1221 | __u32 vni = 0; |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1222 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1223 | if (data[IFLA_GENEVE_REMOTE] && data[IFLA_GENEVE_REMOTE6]) |
| 1224 | return -EINVAL; |
| 1225 | |
| 1226 | if (data[IFLA_GENEVE_REMOTE]) { |
| 1227 | remote.sa.sa_family = AF_INET; |
| 1228 | remote.sin.sin_addr.s_addr = |
| 1229 | nla_get_in_addr(data[IFLA_GENEVE_REMOTE]); |
| 1230 | } |
| 1231 | |
| 1232 | if (data[IFLA_GENEVE_REMOTE6]) { |
| 1233 | if (!IS_ENABLED(CONFIG_IPV6)) |
| 1234 | return -EPFNOSUPPORT; |
| 1235 | |
| 1236 | remote.sa.sa_family = AF_INET6; |
| 1237 | remote.sin6.sin6_addr = |
| 1238 | nla_get_in6_addr(data[IFLA_GENEVE_REMOTE6]); |
| 1239 | |
| 1240 | if (ipv6_addr_type(&remote.sin6.sin6_addr) & |
| 1241 | IPV6_ADDR_LINKLOCAL) { |
| 1242 | netdev_dbg(dev, "link-local remote is unsupported\n"); |
| 1243 | return -EINVAL; |
| 1244 | } |
| 1245 | } |
| 1246 | |
Jesse Gross | e277de5 | 2015-10-16 16:36:00 -0700 | [diff] [blame] | 1247 | if (data[IFLA_GENEVE_ID]) |
| 1248 | vni = nla_get_u32(data[IFLA_GENEVE_ID]); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1249 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1250 | if (data[IFLA_GENEVE_TTL]) |
| 1251 | ttl = nla_get_u8(data[IFLA_GENEVE_TTL]); |
| 1252 | |
| 1253 | if (data[IFLA_GENEVE_TOS]) |
| 1254 | tos = nla_get_u8(data[IFLA_GENEVE_TOS]); |
| 1255 | |
| 1256 | if (data[IFLA_GENEVE_PORT]) |
John W. Linville | 7bbe33f | 2015-09-22 13:09:32 -0400 | [diff] [blame] | 1257 | dst_port = nla_get_be16(data[IFLA_GENEVE_PORT]); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1258 | |
| 1259 | if (data[IFLA_GENEVE_COLLECT_METADATA]) |
| 1260 | metadata = true; |
| 1261 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1262 | return geneve_configure(net, dev, &remote, vni, ttl, tos, dst_port, |
| 1263 | metadata); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1266 | static void geneve_dellink(struct net_device *dev, struct list_head *head) |
| 1267 | { |
| 1268 | struct geneve_dev *geneve = netdev_priv(dev); |
| 1269 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1270 | list_del(&geneve->next); |
| 1271 | unregister_netdevice_queue(dev, head); |
| 1272 | } |
| 1273 | |
| 1274 | static size_t geneve_get_size(const struct net_device *dev) |
| 1275 | { |
| 1276 | return nla_total_size(sizeof(__u32)) + /* IFLA_GENEVE_ID */ |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1277 | nla_total_size(sizeof(struct in6_addr)) + /* IFLA_GENEVE_REMOTE{6} */ |
John W. Linville | 8760ce5 | 2015-06-01 15:51:34 -0400 | [diff] [blame] | 1278 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TTL */ |
John W. Linville | d895112 | 2015-06-01 15:51:35 -0400 | [diff] [blame] | 1279 | nla_total_size(sizeof(__u8)) + /* IFLA_GENEVE_TOS */ |
John W. Linville | 7bbe33f | 2015-09-22 13:09:32 -0400 | [diff] [blame] | 1280 | nla_total_size(sizeof(__be16)) + /* IFLA_GENEVE_PORT */ |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1281 | nla_total_size(0) + /* IFLA_GENEVE_COLLECT_METADATA */ |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1282 | 0; |
| 1283 | } |
| 1284 | |
| 1285 | static int geneve_fill_info(struct sk_buff *skb, const struct net_device *dev) |
| 1286 | { |
| 1287 | struct geneve_dev *geneve = netdev_priv(dev); |
| 1288 | __u32 vni; |
| 1289 | |
| 1290 | vni = (geneve->vni[0] << 16) | (geneve->vni[1] << 8) | geneve->vni[2]; |
| 1291 | if (nla_put_u32(skb, IFLA_GENEVE_ID, vni)) |
| 1292 | goto nla_put_failure; |
| 1293 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1294 | if (geneve->remote.sa.sa_family == AF_INET) { |
| 1295 | if (nla_put_in_addr(skb, IFLA_GENEVE_REMOTE, |
| 1296 | geneve->remote.sin.sin_addr.s_addr)) |
| 1297 | goto nla_put_failure; |
| 1298 | #if IS_ENABLED(CONFIG_IPV6) |
| 1299 | } else { |
| 1300 | if (nla_put_in6_addr(skb, IFLA_GENEVE_REMOTE6, |
| 1301 | &geneve->remote.sin6.sin6_addr)) |
| 1302 | goto nla_put_failure; |
| 1303 | #endif |
| 1304 | } |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1305 | |
John W. Linville | d895112 | 2015-06-01 15:51:35 -0400 | [diff] [blame] | 1306 | if (nla_put_u8(skb, IFLA_GENEVE_TTL, geneve->ttl) || |
| 1307 | nla_put_u8(skb, IFLA_GENEVE_TOS, geneve->tos)) |
John W. Linville | 8760ce5 | 2015-06-01 15:51:34 -0400 | [diff] [blame] | 1308 | goto nla_put_failure; |
| 1309 | |
John W. Linville | 7bbe33f | 2015-09-22 13:09:32 -0400 | [diff] [blame] | 1310 | if (nla_put_be16(skb, IFLA_GENEVE_PORT, geneve->dst_port)) |
Pravin B Shelar | cd7918b | 2015-08-26 23:46:51 -0700 | [diff] [blame] | 1311 | goto nla_put_failure; |
| 1312 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1313 | if (geneve->collect_md) { |
| 1314 | if (nla_put_flag(skb, IFLA_GENEVE_COLLECT_METADATA)) |
| 1315 | goto nla_put_failure; |
| 1316 | } |
| 1317 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1318 | return 0; |
| 1319 | |
| 1320 | nla_put_failure: |
| 1321 | return -EMSGSIZE; |
| 1322 | } |
| 1323 | |
| 1324 | static struct rtnl_link_ops geneve_link_ops __read_mostly = { |
| 1325 | .kind = "geneve", |
| 1326 | .maxtype = IFLA_GENEVE_MAX, |
| 1327 | .policy = geneve_policy, |
| 1328 | .priv_size = sizeof(struct geneve_dev), |
| 1329 | .setup = geneve_setup, |
| 1330 | .validate = geneve_validate, |
| 1331 | .newlink = geneve_newlink, |
| 1332 | .dellink = geneve_dellink, |
| 1333 | .get_size = geneve_get_size, |
| 1334 | .fill_info = geneve_fill_info, |
| 1335 | }; |
| 1336 | |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1337 | struct net_device *geneve_dev_create_fb(struct net *net, const char *name, |
| 1338 | u8 name_assign_type, u16 dst_port) |
| 1339 | { |
| 1340 | struct nlattr *tb[IFLA_MAX + 1]; |
| 1341 | struct net_device *dev; |
| 1342 | int err; |
| 1343 | |
| 1344 | memset(tb, 0, sizeof(tb)); |
| 1345 | dev = rtnl_create_link(net, name, name_assign_type, |
| 1346 | &geneve_link_ops, tb); |
| 1347 | if (IS_ERR(dev)) |
| 1348 | return dev; |
| 1349 | |
John W. Linville | 8ed66f0 | 2015-10-26 17:01:44 -0400 | [diff] [blame] | 1350 | err = geneve_configure(net, dev, &geneve_remote_unspec, |
| 1351 | 0, 0, 0, htons(dst_port), true); |
Pravin B Shelar | e305ac6 | 2015-08-26 23:46:52 -0700 | [diff] [blame] | 1352 | if (err) { |
| 1353 | free_netdev(dev); |
| 1354 | return ERR_PTR(err); |
| 1355 | } |
| 1356 | return dev; |
| 1357 | } |
| 1358 | EXPORT_SYMBOL_GPL(geneve_dev_create_fb); |
| 1359 | |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1360 | static __net_init int geneve_init_net(struct net *net) |
| 1361 | { |
| 1362 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1363 | |
| 1364 | INIT_LIST_HEAD(&gn->geneve_list); |
Pravin B Shelar | 371bd10 | 2015-08-26 23:46:54 -0700 | [diff] [blame] | 1365 | INIT_LIST_HEAD(&gn->sock_list); |
John W. Linville | 2d07dc7 | 2015-05-13 12:57:30 -0400 | [diff] [blame] | 1366 | return 0; |
| 1367 | } |
| 1368 | |
| 1369 | static void __net_exit geneve_exit_net(struct net *net) |
| 1370 | { |
| 1371 | struct geneve_net *gn = net_generic(net, geneve_net_id); |
| 1372 | struct geneve_dev *geneve, *next; |
| 1373 | struct net_device *dev, *aux; |
| 1374 | LIST_HEAD(list); |
| 1375 | |
| 1376 | rtnl_lock(); |
| 1377 | |
| 1378 | /* gather any geneve devices that were moved into this ns */ |
| 1379 | for_each_netdev_safe(net, dev, aux) |
| 1380 | if (dev->rtnl_link_ops == &geneve_link_ops) |
| 1381 | unregister_netdevice_queue(dev, &list); |
| 1382 | |
| 1383 | /* now gather any other geneve devices that were created in this ns */ |
| 1384 | list_for_each_entry_safe(geneve, next, &gn->geneve_list, next) { |
| 1385 | /* If geneve->dev is in the same netns, it was already added |
| 1386 | * to the list by the previous loop. |
| 1387 | */ |
| 1388 | if (!net_eq(dev_net(geneve->dev), net)) |
| 1389 | unregister_netdevice_queue(geneve->dev, &list); |
| 1390 | } |
| 1391 | |
| 1392 | /* unregister the devices gathered above */ |
| 1393 | unregister_netdevice_many(&list); |
| 1394 | rtnl_unlock(); |
| 1395 | } |
| 1396 | |
| 1397 | static struct pernet_operations geneve_net_ops = { |
| 1398 | .init = geneve_init_net, |
| 1399 | .exit = geneve_exit_net, |
| 1400 | .id = &geneve_net_id, |
| 1401 | .size = sizeof(struct geneve_net), |
| 1402 | }; |
| 1403 | |
| 1404 | static int __init geneve_init_module(void) |
| 1405 | { |
| 1406 | int rc; |
| 1407 | |
| 1408 | rc = register_pernet_subsys(&geneve_net_ops); |
| 1409 | if (rc) |
| 1410 | goto out1; |
| 1411 | |
| 1412 | rc = rtnl_link_register(&geneve_link_ops); |
| 1413 | if (rc) |
| 1414 | goto out2; |
| 1415 | |
| 1416 | return 0; |
| 1417 | out2: |
| 1418 | unregister_pernet_subsys(&geneve_net_ops); |
| 1419 | out1: |
| 1420 | return rc; |
| 1421 | } |
| 1422 | late_initcall(geneve_init_module); |
| 1423 | |
| 1424 | static void __exit geneve_cleanup_module(void) |
| 1425 | { |
| 1426 | rtnl_link_unregister(&geneve_link_ops); |
| 1427 | unregister_pernet_subsys(&geneve_net_ops); |
| 1428 | } |
| 1429 | module_exit(geneve_cleanup_module); |
| 1430 | |
| 1431 | MODULE_LICENSE("GPL"); |
| 1432 | MODULE_VERSION(GENEVE_NETDEV_VER); |
| 1433 | MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>"); |
| 1434 | MODULE_DESCRIPTION("Interface driver for GENEVE encapsulated traffic"); |
| 1435 | MODULE_ALIAS_RTNL_LINK("geneve"); |