Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | #include <linux/errno.h> |
| 3 | #include <linux/socket.h> |
| 4 | #include <linux/skbuff.h> |
| 5 | #include <linux/ip.h> |
| 6 | #include <linux/udp.h> |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <net/genetlink.h> |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 10 | #include <net/gue.h> |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 11 | #include <net/ip.h> |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 12 | #include <net/protocol.h> |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 13 | #include <net/udp.h> |
| 14 | #include <net/udp_tunnel.h> |
| 15 | #include <net/xfrm.h> |
| 16 | #include <uapi/linux/fou.h> |
| 17 | #include <uapi/linux/genetlink.h> |
| 18 | |
| 19 | static DEFINE_SPINLOCK(fou_lock); |
| 20 | static LIST_HEAD(fou_list); |
| 21 | |
| 22 | struct fou { |
| 23 | struct socket *sock; |
| 24 | u8 protocol; |
| 25 | u16 port; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 26 | struct udp_offload udp_offloads; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 27 | struct list_head list; |
| 28 | }; |
| 29 | |
| 30 | struct fou_cfg { |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 31 | u16 type; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 32 | u8 protocol; |
| 33 | struct udp_port_cfg udp_config; |
| 34 | }; |
| 35 | |
| 36 | static inline struct fou *fou_from_sock(struct sock *sk) |
| 37 | { |
| 38 | return sk->sk_user_data; |
| 39 | } |
| 40 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 41 | static void fou_recv_pull(struct sk_buff *skb, size_t len) |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 42 | { |
| 43 | struct iphdr *iph = ip_hdr(skb); |
| 44 | |
| 45 | /* Remove 'len' bytes from the packet (UDP header and |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 46 | * FOU header if present). |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 47 | */ |
| 48 | iph->tot_len = htons(ntohs(iph->tot_len) - len); |
| 49 | __skb_pull(skb, len); |
| 50 | skb_postpull_rcsum(skb, udp_hdr(skb), len); |
| 51 | skb_reset_transport_header(skb); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static int fou_udp_recv(struct sock *sk, struct sk_buff *skb) |
| 55 | { |
| 56 | struct fou *fou = fou_from_sock(sk); |
| 57 | |
| 58 | if (!fou) |
| 59 | return 1; |
| 60 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 61 | fou_recv_pull(skb, sizeof(struct udphdr)); |
| 62 | |
| 63 | return -fou->protocol; |
| 64 | } |
| 65 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 66 | static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr, |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 67 | void *data, size_t hdrlen, u8 ipproto) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 68 | { |
| 69 | __be16 *pd = data; |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 70 | size_t start = ntohs(pd[0]); |
| 71 | size_t offset = ntohs(pd[1]); |
| 72 | size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 73 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 74 | if (!pskb_may_pull(skb, plen)) |
| 75 | return NULL; |
| 76 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
| 77 | |
Tom Herbert | dcdc899 | 2015-02-02 16:07:34 -0800 | [diff] [blame] | 78 | skb_remcsum_process(skb, (void *)guehdr + hdrlen, start, offset); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 79 | |
| 80 | return guehdr; |
| 81 | } |
| 82 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 83 | static int gue_control_message(struct sk_buff *skb, struct guehdr *guehdr) |
| 84 | { |
| 85 | /* No support yet */ |
| 86 | kfree_skb(skb); |
| 87 | return 0; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 90 | static int gue_udp_recv(struct sock *sk, struct sk_buff *skb) |
| 91 | { |
| 92 | struct fou *fou = fou_from_sock(sk); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 93 | size_t len, optlen, hdrlen; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 94 | struct guehdr *guehdr; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 95 | void *data; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 96 | u16 doffset = 0; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 97 | |
| 98 | if (!fou) |
| 99 | return 1; |
| 100 | |
| 101 | len = sizeof(struct udphdr) + sizeof(struct guehdr); |
| 102 | if (!pskb_may_pull(skb, len)) |
| 103 | goto drop; |
| 104 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 105 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 106 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 107 | optlen = guehdr->hlen << 2; |
| 108 | len += optlen; |
| 109 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 110 | if (!pskb_may_pull(skb, len)) |
| 111 | goto drop; |
| 112 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 113 | /* guehdr may change after pull */ |
| 114 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
Li RongQing | d8f00d2 | 2014-10-17 16:53:47 +0800 | [diff] [blame] | 115 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 116 | hdrlen = sizeof(struct guehdr) + optlen; |
| 117 | |
| 118 | if (guehdr->version != 0 || validate_gue_flags(guehdr, optlen)) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 119 | goto drop; |
| 120 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 121 | hdrlen = sizeof(struct guehdr) + optlen; |
| 122 | |
| 123 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len); |
| 124 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 125 | /* Pull csum through the guehdr now . This can be used if |
| 126 | * there is a remote checksum offload. |
| 127 | */ |
| 128 | skb_postpull_rcsum(skb, udp_hdr(skb), len); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 129 | |
| 130 | data = &guehdr[1]; |
| 131 | |
| 132 | if (guehdr->flags & GUE_FLAG_PRIV) { |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 133 | __be32 flags = *(__be32 *)(data + doffset); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 134 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 135 | doffset += GUE_LEN_PRIV; |
| 136 | |
| 137 | if (flags & GUE_PFLAG_REMCSUM) { |
| 138 | guehdr = gue_remcsum(skb, guehdr, data + doffset, |
| 139 | hdrlen, guehdr->proto_ctype); |
| 140 | if (!guehdr) |
| 141 | goto drop; |
| 142 | |
| 143 | data = &guehdr[1]; |
| 144 | |
| 145 | doffset += GUE_PLEN_REMCSUM; |
| 146 | } |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 149 | if (unlikely(guehdr->control)) |
| 150 | return gue_control_message(skb, guehdr); |
| 151 | |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 152 | __skb_pull(skb, sizeof(struct udphdr) + hdrlen); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 153 | skb_reset_transport_header(skb); |
| 154 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 155 | return -guehdr->proto_ctype; |
| 156 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 157 | drop: |
| 158 | kfree_skb(skb); |
| 159 | return 0; |
| 160 | } |
| 161 | |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 162 | static struct sk_buff **fou_gro_receive(struct sk_buff **head, |
Tom Herbert | a2b12f3 | 2015-01-12 17:00:37 -0800 | [diff] [blame] | 163 | struct sk_buff *skb, |
| 164 | struct udp_offload *uoff) |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 165 | { |
| 166 | const struct net_offload *ops; |
| 167 | struct sk_buff **pp = NULL; |
| 168 | u8 proto = NAPI_GRO_CB(skb)->proto; |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 169 | const struct net_offload **offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 170 | |
| 171 | rcu_read_lock(); |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 172 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 173 | ops = rcu_dereference(offloads[proto]); |
| 174 | if (!ops || !ops->callbacks.gro_receive) |
| 175 | goto out_unlock; |
| 176 | |
| 177 | pp = ops->callbacks.gro_receive(head, skb); |
| 178 | |
| 179 | out_unlock: |
| 180 | rcu_read_unlock(); |
| 181 | |
| 182 | return pp; |
| 183 | } |
| 184 | |
Tom Herbert | a2b12f3 | 2015-01-12 17:00:37 -0800 | [diff] [blame] | 185 | static int fou_gro_complete(struct sk_buff *skb, int nhoff, |
| 186 | struct udp_offload *uoff) |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 187 | { |
| 188 | const struct net_offload *ops; |
| 189 | u8 proto = NAPI_GRO_CB(skb)->proto; |
| 190 | int err = -ENOSYS; |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 191 | const struct net_offload **offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 192 | |
Jesse Gross | cfdf1e1 | 2014-11-10 11:45:13 -0800 | [diff] [blame] | 193 | udp_tunnel_gro_complete(skb, nhoff); |
| 194 | |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 195 | rcu_read_lock(); |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 196 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 197 | ops = rcu_dereference(offloads[proto]); |
| 198 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) |
| 199 | goto out_unlock; |
| 200 | |
| 201 | err = ops->callbacks.gro_complete(skb, nhoff); |
| 202 | |
| 203 | out_unlock: |
| 204 | rcu_read_unlock(); |
| 205 | |
| 206 | return err; |
| 207 | } |
| 208 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 209 | static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off, |
| 210 | struct guehdr *guehdr, void *data, |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 211 | size_t hdrlen, u8 ipproto, |
| 212 | struct gro_remcsum *grc) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 213 | { |
| 214 | __be16 *pd = data; |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 215 | size_t start = ntohs(pd[0]); |
| 216 | size_t offset = ntohs(pd[1]); |
| 217 | size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 218 | |
| 219 | if (skb->remcsum_offload) |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 220 | return NULL; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 221 | |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 222 | if (!NAPI_GRO_CB(skb)->csum_valid) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 223 | return NULL; |
| 224 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 225 | /* Pull checksum that will be written */ |
| 226 | if (skb_gro_header_hard(skb, off + plen)) { |
| 227 | guehdr = skb_gro_header_slow(skb, off + plen, off); |
| 228 | if (!guehdr) |
| 229 | return NULL; |
| 230 | } |
| 231 | |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 232 | skb_gro_remcsum_process(skb, (void *)guehdr + hdrlen, |
| 233 | start, offset, grc); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 234 | |
| 235 | skb->remcsum_offload = 1; |
| 236 | |
| 237 | return guehdr; |
| 238 | } |
| 239 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 240 | static struct sk_buff **gue_gro_receive(struct sk_buff **head, |
Tom Herbert | a2b12f3 | 2015-01-12 17:00:37 -0800 | [diff] [blame] | 241 | struct sk_buff *skb, |
| 242 | struct udp_offload *uoff) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 243 | { |
| 244 | const struct net_offload **offloads; |
| 245 | const struct net_offload *ops; |
| 246 | struct sk_buff **pp = NULL; |
| 247 | struct sk_buff *p; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 248 | struct guehdr *guehdr; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 249 | size_t len, optlen, hdrlen, off; |
| 250 | void *data; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 251 | u16 doffset = 0; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 252 | int flush = 1; |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 253 | struct gro_remcsum grc; |
| 254 | |
| 255 | skb_gro_remcsum_init(&grc); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 256 | |
| 257 | off = skb_gro_offset(skb); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 258 | len = off + sizeof(*guehdr); |
| 259 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 260 | guehdr = skb_gro_header_fast(skb, off); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 261 | if (skb_gro_header_hard(skb, len)) { |
| 262 | guehdr = skb_gro_header_slow(skb, len, off); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 263 | if (unlikely(!guehdr)) |
| 264 | goto out; |
| 265 | } |
| 266 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 267 | optlen = guehdr->hlen << 2; |
| 268 | len += optlen; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 269 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 270 | if (skb_gro_header_hard(skb, len)) { |
| 271 | guehdr = skb_gro_header_slow(skb, len, off); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 272 | if (unlikely(!guehdr)) |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 273 | goto out; |
| 274 | } |
| 275 | |
| 276 | if (unlikely(guehdr->control) || guehdr->version != 0 || |
| 277 | validate_gue_flags(guehdr, optlen)) |
| 278 | goto out; |
| 279 | |
| 280 | hdrlen = sizeof(*guehdr) + optlen; |
| 281 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 282 | /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr, |
| 283 | * this is needed if there is a remote checkcsum offload. |
| 284 | */ |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 285 | skb_gro_postpull_rcsum(skb, guehdr, hdrlen); |
| 286 | |
| 287 | data = &guehdr[1]; |
| 288 | |
| 289 | if (guehdr->flags & GUE_FLAG_PRIV) { |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 290 | __be32 flags = *(__be32 *)(data + doffset); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 291 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 292 | doffset += GUE_LEN_PRIV; |
| 293 | |
| 294 | if (flags & GUE_PFLAG_REMCSUM) { |
| 295 | guehdr = gue_gro_remcsum(skb, off, guehdr, |
| 296 | data + doffset, hdrlen, |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 297 | guehdr->proto_ctype, &grc); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 298 | if (!guehdr) |
| 299 | goto out; |
| 300 | |
| 301 | data = &guehdr[1]; |
| 302 | |
| 303 | doffset += GUE_PLEN_REMCSUM; |
| 304 | } |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 307 | skb_gro_pull(skb, hdrlen); |
| 308 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 309 | flush = 0; |
| 310 | |
| 311 | for (p = *head; p; p = p->next) { |
| 312 | const struct guehdr *guehdr2; |
| 313 | |
| 314 | if (!NAPI_GRO_CB(p)->same_flow) |
| 315 | continue; |
| 316 | |
| 317 | guehdr2 = (struct guehdr *)(p->data + off); |
| 318 | |
| 319 | /* Compare base GUE header to be equal (covers |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 320 | * hlen, version, proto_ctype, and flags. |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 321 | */ |
| 322 | if (guehdr->word != guehdr2->word) { |
| 323 | NAPI_GRO_CB(p)->same_flow = 0; |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | /* Compare optional fields are the same. */ |
| 328 | if (guehdr->hlen && memcmp(&guehdr[1], &guehdr2[1], |
| 329 | guehdr->hlen << 2)) { |
| 330 | NAPI_GRO_CB(p)->same_flow = 0; |
| 331 | continue; |
| 332 | } |
| 333 | } |
| 334 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 335 | rcu_read_lock(); |
| 336 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
| 337 | ops = rcu_dereference(offloads[guehdr->proto_ctype]); |
| 338 | if (WARN_ON(!ops || !ops->callbacks.gro_receive)) |
| 339 | goto out_unlock; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 340 | |
| 341 | pp = ops->callbacks.gro_receive(head, skb); |
| 342 | |
| 343 | out_unlock: |
| 344 | rcu_read_unlock(); |
| 345 | out: |
| 346 | NAPI_GRO_CB(skb)->flush |= flush; |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame^] | 347 | skb_gro_remcsum_cleanup(skb, &grc); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 348 | |
| 349 | return pp; |
| 350 | } |
| 351 | |
Tom Herbert | a2b12f3 | 2015-01-12 17:00:37 -0800 | [diff] [blame] | 352 | static int gue_gro_complete(struct sk_buff *skb, int nhoff, |
| 353 | struct udp_offload *uoff) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 354 | { |
| 355 | const struct net_offload **offloads; |
| 356 | struct guehdr *guehdr = (struct guehdr *)(skb->data + nhoff); |
| 357 | const struct net_offload *ops; |
| 358 | unsigned int guehlen; |
| 359 | u8 proto; |
| 360 | int err = -ENOENT; |
| 361 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 362 | proto = guehdr->proto_ctype; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 363 | |
| 364 | guehlen = sizeof(*guehdr) + (guehdr->hlen << 2); |
| 365 | |
| 366 | rcu_read_lock(); |
| 367 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
| 368 | ops = rcu_dereference(offloads[proto]); |
| 369 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) |
| 370 | goto out_unlock; |
| 371 | |
| 372 | err = ops->callbacks.gro_complete(skb, nhoff + guehlen); |
| 373 | |
| 374 | out_unlock: |
| 375 | rcu_read_unlock(); |
| 376 | return err; |
| 377 | } |
| 378 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 379 | static int fou_add_to_port_list(struct fou *fou) |
| 380 | { |
| 381 | struct fou *fout; |
| 382 | |
| 383 | spin_lock(&fou_lock); |
| 384 | list_for_each_entry(fout, &fou_list, list) { |
| 385 | if (fou->port == fout->port) { |
| 386 | spin_unlock(&fou_lock); |
| 387 | return -EALREADY; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | list_add(&fou->list, &fou_list); |
| 392 | spin_unlock(&fou_lock); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static void fou_release(struct fou *fou) |
| 398 | { |
| 399 | struct socket *sock = fou->sock; |
| 400 | struct sock *sk = sock->sk; |
| 401 | |
| 402 | udp_del_offload(&fou->udp_offloads); |
| 403 | |
| 404 | list_del(&fou->list); |
| 405 | |
| 406 | /* Remove hooks into tunnel socket */ |
| 407 | sk->sk_user_data = NULL; |
| 408 | |
| 409 | sock_release(sock); |
| 410 | |
| 411 | kfree(fou); |
| 412 | } |
| 413 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 414 | static int fou_encap_init(struct sock *sk, struct fou *fou, struct fou_cfg *cfg) |
| 415 | { |
| 416 | udp_sk(sk)->encap_rcv = fou_udp_recv; |
| 417 | fou->protocol = cfg->protocol; |
| 418 | fou->udp_offloads.callbacks.gro_receive = fou_gro_receive; |
| 419 | fou->udp_offloads.callbacks.gro_complete = fou_gro_complete; |
| 420 | fou->udp_offloads.port = cfg->udp_config.local_udp_port; |
| 421 | fou->udp_offloads.ipproto = cfg->protocol; |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int gue_encap_init(struct sock *sk, struct fou *fou, struct fou_cfg *cfg) |
| 427 | { |
| 428 | udp_sk(sk)->encap_rcv = gue_udp_recv; |
| 429 | fou->udp_offloads.callbacks.gro_receive = gue_gro_receive; |
| 430 | fou->udp_offloads.callbacks.gro_complete = gue_gro_complete; |
| 431 | fou->udp_offloads.port = cfg->udp_config.local_udp_port; |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 436 | static int fou_create(struct net *net, struct fou_cfg *cfg, |
| 437 | struct socket **sockp) |
| 438 | { |
| 439 | struct fou *fou = NULL; |
| 440 | int err; |
| 441 | struct socket *sock = NULL; |
| 442 | struct sock *sk; |
| 443 | |
| 444 | /* Open UDP socket */ |
| 445 | err = udp_sock_create(net, &cfg->udp_config, &sock); |
| 446 | if (err < 0) |
| 447 | goto error; |
| 448 | |
| 449 | /* Allocate FOU port structure */ |
| 450 | fou = kzalloc(sizeof(*fou), GFP_KERNEL); |
| 451 | if (!fou) { |
| 452 | err = -ENOMEM; |
| 453 | goto error; |
| 454 | } |
| 455 | |
| 456 | sk = sock->sk; |
| 457 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 458 | fou->port = cfg->udp_config.local_udp_port; |
| 459 | |
| 460 | /* Initial for fou type */ |
| 461 | switch (cfg->type) { |
| 462 | case FOU_ENCAP_DIRECT: |
| 463 | err = fou_encap_init(sk, fou, cfg); |
| 464 | if (err) |
| 465 | goto error; |
| 466 | break; |
| 467 | case FOU_ENCAP_GUE: |
| 468 | err = gue_encap_init(sk, fou, cfg); |
| 469 | if (err) |
| 470 | goto error; |
| 471 | break; |
| 472 | default: |
| 473 | err = -EINVAL; |
| 474 | goto error; |
| 475 | } |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 476 | |
| 477 | udp_sk(sk)->encap_type = 1; |
| 478 | udp_encap_enable(); |
| 479 | |
| 480 | sk->sk_user_data = fou; |
| 481 | fou->sock = sock; |
| 482 | |
Tom Herbert | 224d019 | 2015-01-05 13:56:14 -0800 | [diff] [blame] | 483 | inet_inc_convert_csum(sk); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 484 | |
| 485 | sk->sk_allocation = GFP_ATOMIC; |
| 486 | |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 487 | if (cfg->udp_config.family == AF_INET) { |
| 488 | err = udp_add_offload(&fou->udp_offloads); |
| 489 | if (err) |
| 490 | goto error; |
| 491 | } |
| 492 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 493 | err = fou_add_to_port_list(fou); |
| 494 | if (err) |
| 495 | goto error; |
| 496 | |
| 497 | if (sockp) |
| 498 | *sockp = sock; |
| 499 | |
| 500 | return 0; |
| 501 | |
| 502 | error: |
| 503 | kfree(fou); |
| 504 | if (sock) |
| 505 | sock_release(sock); |
| 506 | |
| 507 | return err; |
| 508 | } |
| 509 | |
| 510 | static int fou_destroy(struct net *net, struct fou_cfg *cfg) |
| 511 | { |
| 512 | struct fou *fou; |
| 513 | u16 port = cfg->udp_config.local_udp_port; |
| 514 | int err = -EINVAL; |
| 515 | |
| 516 | spin_lock(&fou_lock); |
| 517 | list_for_each_entry(fou, &fou_list, list) { |
| 518 | if (fou->port == port) { |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 519 | udp_del_offload(&fou->udp_offloads); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 520 | fou_release(fou); |
| 521 | err = 0; |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | spin_unlock(&fou_lock); |
| 526 | |
| 527 | return err; |
| 528 | } |
| 529 | |
| 530 | static struct genl_family fou_nl_family = { |
| 531 | .id = GENL_ID_GENERATE, |
| 532 | .hdrsize = 0, |
| 533 | .name = FOU_GENL_NAME, |
| 534 | .version = FOU_GENL_VERSION, |
| 535 | .maxattr = FOU_ATTR_MAX, |
| 536 | .netnsok = true, |
| 537 | }; |
| 538 | |
| 539 | static struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = { |
| 540 | [FOU_ATTR_PORT] = { .type = NLA_U16, }, |
| 541 | [FOU_ATTR_AF] = { .type = NLA_U8, }, |
| 542 | [FOU_ATTR_IPPROTO] = { .type = NLA_U8, }, |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 543 | [FOU_ATTR_TYPE] = { .type = NLA_U8, }, |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 544 | }; |
| 545 | |
| 546 | static int parse_nl_config(struct genl_info *info, |
| 547 | struct fou_cfg *cfg) |
| 548 | { |
| 549 | memset(cfg, 0, sizeof(*cfg)); |
| 550 | |
| 551 | cfg->udp_config.family = AF_INET; |
| 552 | |
| 553 | if (info->attrs[FOU_ATTR_AF]) { |
| 554 | u8 family = nla_get_u8(info->attrs[FOU_ATTR_AF]); |
| 555 | |
| 556 | if (family != AF_INET && family != AF_INET6) |
| 557 | return -EINVAL; |
| 558 | |
| 559 | cfg->udp_config.family = family; |
| 560 | } |
| 561 | |
| 562 | if (info->attrs[FOU_ATTR_PORT]) { |
| 563 | u16 port = nla_get_u16(info->attrs[FOU_ATTR_PORT]); |
| 564 | |
| 565 | cfg->udp_config.local_udp_port = port; |
| 566 | } |
| 567 | |
| 568 | if (info->attrs[FOU_ATTR_IPPROTO]) |
| 569 | cfg->protocol = nla_get_u8(info->attrs[FOU_ATTR_IPPROTO]); |
| 570 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 571 | if (info->attrs[FOU_ATTR_TYPE]) |
| 572 | cfg->type = nla_get_u8(info->attrs[FOU_ATTR_TYPE]); |
| 573 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info) |
| 578 | { |
| 579 | struct fou_cfg cfg; |
| 580 | int err; |
| 581 | |
| 582 | err = parse_nl_config(info, &cfg); |
| 583 | if (err) |
| 584 | return err; |
| 585 | |
| 586 | return fou_create(&init_net, &cfg, NULL); |
| 587 | } |
| 588 | |
| 589 | static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info) |
| 590 | { |
| 591 | struct fou_cfg cfg; |
| 592 | |
| 593 | parse_nl_config(info, &cfg); |
| 594 | |
| 595 | return fou_destroy(&init_net, &cfg); |
| 596 | } |
| 597 | |
| 598 | static const struct genl_ops fou_nl_ops[] = { |
| 599 | { |
| 600 | .cmd = FOU_CMD_ADD, |
| 601 | .doit = fou_nl_cmd_add_port, |
| 602 | .policy = fou_nl_policy, |
| 603 | .flags = GENL_ADMIN_PERM, |
| 604 | }, |
| 605 | { |
| 606 | .cmd = FOU_CMD_DEL, |
| 607 | .doit = fou_nl_cmd_rm_port, |
| 608 | .policy = fou_nl_policy, |
| 609 | .flags = GENL_ADMIN_PERM, |
| 610 | }, |
| 611 | }; |
| 612 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 613 | size_t fou_encap_hlen(struct ip_tunnel_encap *e) |
| 614 | { |
| 615 | return sizeof(struct udphdr); |
| 616 | } |
| 617 | EXPORT_SYMBOL(fou_encap_hlen); |
| 618 | |
| 619 | size_t gue_encap_hlen(struct ip_tunnel_encap *e) |
| 620 | { |
| 621 | size_t len; |
| 622 | bool need_priv = false; |
| 623 | |
| 624 | len = sizeof(struct udphdr) + sizeof(struct guehdr); |
| 625 | |
| 626 | if (e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) { |
| 627 | len += GUE_PLEN_REMCSUM; |
| 628 | need_priv = true; |
| 629 | } |
| 630 | |
| 631 | len += need_priv ? GUE_LEN_PRIV : 0; |
| 632 | |
| 633 | return len; |
| 634 | } |
| 635 | EXPORT_SYMBOL(gue_encap_hlen); |
| 636 | |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 637 | static void fou_build_udp(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 638 | struct flowi4 *fl4, u8 *protocol, __be16 sport) |
| 639 | { |
| 640 | struct udphdr *uh; |
| 641 | |
| 642 | skb_push(skb, sizeof(struct udphdr)); |
| 643 | skb_reset_transport_header(skb); |
| 644 | |
| 645 | uh = udp_hdr(skb); |
| 646 | |
| 647 | uh->dest = e->dport; |
| 648 | uh->source = sport; |
| 649 | uh->len = htons(skb->len); |
| 650 | uh->check = 0; |
| 651 | udp_set_csum(!(e->flags & TUNNEL_ENCAP_FLAG_CSUM), skb, |
| 652 | fl4->saddr, fl4->daddr, skb->len); |
| 653 | |
| 654 | *protocol = IPPROTO_UDP; |
| 655 | } |
| 656 | |
| 657 | int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 658 | u8 *protocol, struct flowi4 *fl4) |
| 659 | { |
| 660 | bool csum = !!(e->flags & TUNNEL_ENCAP_FLAG_CSUM); |
| 661 | int type = csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; |
| 662 | __be16 sport; |
| 663 | |
| 664 | skb = iptunnel_handle_offloads(skb, csum, type); |
| 665 | |
| 666 | if (IS_ERR(skb)) |
| 667 | return PTR_ERR(skb); |
| 668 | |
| 669 | sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), |
| 670 | skb, 0, 0, false); |
| 671 | fou_build_udp(skb, e, fl4, protocol, sport); |
| 672 | |
| 673 | return 0; |
| 674 | } |
| 675 | EXPORT_SYMBOL(fou_build_header); |
| 676 | |
| 677 | int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 678 | u8 *protocol, struct flowi4 *fl4) |
| 679 | { |
| 680 | bool csum = !!(e->flags & TUNNEL_ENCAP_FLAG_CSUM); |
| 681 | int type = csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; |
| 682 | struct guehdr *guehdr; |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 683 | size_t hdrlen, optlen = 0; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 684 | __be16 sport; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 685 | void *data; |
| 686 | bool need_priv = false; |
| 687 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 688 | if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) && |
| 689 | skb->ip_summed == CHECKSUM_PARTIAL) { |
| 690 | csum = false; |
| 691 | optlen += GUE_PLEN_REMCSUM; |
| 692 | type |= SKB_GSO_TUNNEL_REMCSUM; |
| 693 | need_priv = true; |
| 694 | } |
| 695 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 696 | optlen += need_priv ? GUE_LEN_PRIV : 0; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 697 | |
| 698 | skb = iptunnel_handle_offloads(skb, csum, type); |
| 699 | |
| 700 | if (IS_ERR(skb)) |
| 701 | return PTR_ERR(skb); |
| 702 | |
| 703 | /* Get source port (based on flow hash) before skb_push */ |
| 704 | sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), |
| 705 | skb, 0, 0, false); |
| 706 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 707 | hdrlen = sizeof(struct guehdr) + optlen; |
| 708 | |
| 709 | skb_push(skb, hdrlen); |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 710 | |
| 711 | guehdr = (struct guehdr *)skb->data; |
| 712 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 713 | guehdr->control = 0; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 714 | guehdr->version = 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 715 | guehdr->hlen = optlen >> 2; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 716 | guehdr->flags = 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 717 | guehdr->proto_ctype = *protocol; |
| 718 | |
| 719 | data = &guehdr[1]; |
| 720 | |
| 721 | if (need_priv) { |
| 722 | __be32 *flags = data; |
| 723 | |
| 724 | guehdr->flags |= GUE_FLAG_PRIV; |
| 725 | *flags = 0; |
| 726 | data += GUE_LEN_PRIV; |
| 727 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 728 | if (type & SKB_GSO_TUNNEL_REMCSUM) { |
| 729 | u16 csum_start = skb_checksum_start_offset(skb); |
| 730 | __be16 *pd = data; |
| 731 | |
| 732 | if (csum_start < hdrlen) |
| 733 | return -EINVAL; |
| 734 | |
| 735 | csum_start -= hdrlen; |
| 736 | pd[0] = htons(csum_start); |
| 737 | pd[1] = htons(csum_start + skb->csum_offset); |
| 738 | |
| 739 | if (!skb_is_gso(skb)) { |
| 740 | skb->ip_summed = CHECKSUM_NONE; |
| 741 | skb->encapsulation = 0; |
| 742 | } |
| 743 | |
| 744 | *flags |= GUE_PFLAG_REMCSUM; |
| 745 | data += GUE_PLEN_REMCSUM; |
| 746 | } |
| 747 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 748 | } |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 749 | |
| 750 | fou_build_udp(skb, e, fl4, protocol, sport); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | EXPORT_SYMBOL(gue_build_header); |
| 755 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 756 | #ifdef CONFIG_NET_FOU_IP_TUNNELS |
| 757 | |
| 758 | static const struct ip_tunnel_encap_ops __read_mostly fou_iptun_ops = { |
| 759 | .encap_hlen = fou_encap_hlen, |
| 760 | .build_header = fou_build_header, |
| 761 | }; |
| 762 | |
| 763 | static const struct ip_tunnel_encap_ops __read_mostly gue_iptun_ops = { |
| 764 | .encap_hlen = gue_encap_hlen, |
| 765 | .build_header = gue_build_header, |
| 766 | }; |
| 767 | |
| 768 | static int ip_tunnel_encap_add_fou_ops(void) |
| 769 | { |
| 770 | int ret; |
| 771 | |
| 772 | ret = ip_tunnel_encap_add_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 773 | if (ret < 0) { |
| 774 | pr_err("can't add fou ops\n"); |
| 775 | return ret; |
| 776 | } |
| 777 | |
| 778 | ret = ip_tunnel_encap_add_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); |
| 779 | if (ret < 0) { |
| 780 | pr_err("can't add gue ops\n"); |
| 781 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 782 | return ret; |
| 783 | } |
| 784 | |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | static void ip_tunnel_encap_del_fou_ops(void) |
| 789 | { |
| 790 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 791 | ip_tunnel_encap_del_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); |
| 792 | } |
| 793 | |
| 794 | #else |
| 795 | |
| 796 | static int ip_tunnel_encap_add_fou_ops(void) |
| 797 | { |
| 798 | return 0; |
| 799 | } |
| 800 | |
Thomas Graf | 882288c | 2014-11-13 12:48:21 +0100 | [diff] [blame] | 801 | static void ip_tunnel_encap_del_fou_ops(void) |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 802 | { |
| 803 | } |
| 804 | |
| 805 | #endif |
| 806 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 807 | static int __init fou_init(void) |
| 808 | { |
| 809 | int ret; |
| 810 | |
| 811 | ret = genl_register_family_with_ops(&fou_nl_family, |
| 812 | fou_nl_ops); |
| 813 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 814 | if (ret < 0) |
| 815 | goto exit; |
| 816 | |
| 817 | ret = ip_tunnel_encap_add_fou_ops(); |
| 818 | if (ret < 0) |
| 819 | genl_unregister_family(&fou_nl_family); |
| 820 | |
| 821 | exit: |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | static void __exit fou_fini(void) |
| 826 | { |
| 827 | struct fou *fou, *next; |
| 828 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 829 | ip_tunnel_encap_del_fou_ops(); |
| 830 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 831 | genl_unregister_family(&fou_nl_family); |
| 832 | |
| 833 | /* Close all the FOU sockets */ |
| 834 | |
| 835 | spin_lock(&fou_lock); |
| 836 | list_for_each_entry_safe(fou, next, &fou_list, list) |
| 837 | fou_release(fou); |
| 838 | spin_unlock(&fou_lock); |
| 839 | } |
| 840 | |
| 841 | module_init(fou_init); |
| 842 | module_exit(fou_fini); |
| 843 | MODULE_AUTHOR("Tom Herbert <therbert@google.com>"); |
| 844 | MODULE_LICENSE("GPL"); |