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 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 19 | struct fou { |
| 20 | struct socket *sock; |
| 21 | u8 protocol; |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 22 | u8 flags; |
WANG Cong | 4cbcdf2 | 2015-04-10 12:00:28 -0700 | [diff] [blame] | 23 | __be16 port; |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 24 | u8 family; |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 25 | u16 type; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 26 | struct list_head list; |
Hannes Frederic Sowa | 3036fac | 2015-12-15 21:01:53 +0100 | [diff] [blame] | 27 | struct rcu_head rcu; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 30 | #define FOU_F_REMCSUM_NOPARTIAL BIT(0) |
| 31 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 32 | struct fou_cfg { |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 33 | u16 type; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 34 | u8 protocol; |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 35 | u8 flags; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 36 | struct udp_port_cfg udp_config; |
| 37 | }; |
| 38 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 39 | static unsigned int fou_net_id; |
| 40 | |
| 41 | struct fou_net { |
| 42 | struct list_head fou_list; |
| 43 | struct mutex fou_lock; |
| 44 | }; |
| 45 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 46 | static inline struct fou *fou_from_sock(struct sock *sk) |
| 47 | { |
| 48 | return sk->sk_user_data; |
| 49 | } |
| 50 | |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 51 | static int fou_recv_pull(struct sk_buff *skb, struct fou *fou, size_t len) |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 52 | { |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 53 | /* Remove 'len' bytes from the packet (UDP header and |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 54 | * FOU header if present). |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 55 | */ |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 56 | if (fou->family == AF_INET) |
| 57 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len); |
| 58 | else |
| 59 | ipv6_hdr(skb)->payload_len = |
| 60 | htons(ntohs(ipv6_hdr(skb)->payload_len) - len); |
| 61 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 62 | __skb_pull(skb, len); |
| 63 | skb_postpull_rcsum(skb, udp_hdr(skb), len); |
| 64 | skb_reset_transport_header(skb); |
Jesse Gross | a09a4c8 | 2016-03-19 09:32:02 -0700 | [diff] [blame] | 65 | return iptunnel_pull_offloads(skb); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static int fou_udp_recv(struct sock *sk, struct sk_buff *skb) |
| 69 | { |
| 70 | struct fou *fou = fou_from_sock(sk); |
| 71 | |
| 72 | if (!fou) |
| 73 | return 1; |
| 74 | |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 75 | if (fou_recv_pull(skb, fou, sizeof(struct udphdr))) |
Jesse Gross | a09a4c8 | 2016-03-19 09:32:02 -0700 | [diff] [blame] | 76 | goto drop; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 77 | |
| 78 | return -fou->protocol; |
Jesse Gross | a09a4c8 | 2016-03-19 09:32:02 -0700 | [diff] [blame] | 79 | |
| 80 | drop: |
| 81 | kfree_skb(skb); |
| 82 | return 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 85 | static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr, |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 86 | void *data, size_t hdrlen, u8 ipproto, |
| 87 | bool nopartial) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 88 | { |
| 89 | __be16 *pd = data; |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 90 | size_t start = ntohs(pd[0]); |
| 91 | size_t offset = ntohs(pd[1]); |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 92 | size_t plen = sizeof(struct udphdr) + hdrlen + |
| 93 | max_t(size_t, offset + sizeof(u16), start); |
| 94 | |
| 95 | if (skb->remcsum_offload) |
| 96 | return guehdr; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 97 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 98 | if (!pskb_may_pull(skb, plen)) |
| 99 | return NULL; |
| 100 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
| 101 | |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 102 | skb_remcsum_process(skb, (void *)guehdr + hdrlen, |
| 103 | start, offset, nopartial); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 104 | |
| 105 | return guehdr; |
| 106 | } |
| 107 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 108 | static int gue_control_message(struct sk_buff *skb, struct guehdr *guehdr) |
| 109 | { |
| 110 | /* No support yet */ |
| 111 | kfree_skb(skb); |
| 112 | return 0; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 115 | static int gue_udp_recv(struct sock *sk, struct sk_buff *skb) |
| 116 | { |
| 117 | struct fou *fou = fou_from_sock(sk); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 118 | size_t len, optlen, hdrlen; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 119 | struct guehdr *guehdr; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 120 | void *data; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 121 | u16 doffset = 0; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 122 | |
| 123 | if (!fou) |
| 124 | return 1; |
| 125 | |
| 126 | len = sizeof(struct udphdr) + sizeof(struct guehdr); |
| 127 | if (!pskb_may_pull(skb, len)) |
| 128 | goto drop; |
| 129 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 130 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 131 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 132 | optlen = guehdr->hlen << 2; |
| 133 | len += optlen; |
| 134 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 135 | if (!pskb_may_pull(skb, len)) |
| 136 | goto drop; |
| 137 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 138 | /* guehdr may change after pull */ |
| 139 | guehdr = (struct guehdr *)&udp_hdr(skb)[1]; |
Li RongQing | d8f00d2 | 2014-10-17 16:53:47 +0800 | [diff] [blame] | 140 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 141 | hdrlen = sizeof(struct guehdr) + optlen; |
| 142 | |
| 143 | if (guehdr->version != 0 || validate_gue_flags(guehdr, optlen)) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 144 | goto drop; |
| 145 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 146 | hdrlen = sizeof(struct guehdr) + optlen; |
| 147 | |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 148 | if (fou->family == AF_INET) |
| 149 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(skb)->tot_len) - len); |
| 150 | else |
| 151 | ipv6_hdr(skb)->payload_len = |
| 152 | htons(ntohs(ipv6_hdr(skb)->payload_len) - len); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 153 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 154 | /* Pull csum through the guehdr now . This can be used if |
| 155 | * there is a remote checksum offload. |
| 156 | */ |
| 157 | skb_postpull_rcsum(skb, udp_hdr(skb), len); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 158 | |
| 159 | data = &guehdr[1]; |
| 160 | |
| 161 | if (guehdr->flags & GUE_FLAG_PRIV) { |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 162 | __be32 flags = *(__be32 *)(data + doffset); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 163 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 164 | doffset += GUE_LEN_PRIV; |
| 165 | |
| 166 | if (flags & GUE_PFLAG_REMCSUM) { |
| 167 | guehdr = gue_remcsum(skb, guehdr, data + doffset, |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 168 | hdrlen, guehdr->proto_ctype, |
| 169 | !!(fou->flags & |
| 170 | FOU_F_REMCSUM_NOPARTIAL)); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 171 | if (!guehdr) |
| 172 | goto drop; |
| 173 | |
| 174 | data = &guehdr[1]; |
| 175 | |
| 176 | doffset += GUE_PLEN_REMCSUM; |
| 177 | } |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 180 | if (unlikely(guehdr->control)) |
| 181 | return gue_control_message(skb, guehdr); |
| 182 | |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 183 | __skb_pull(skb, sizeof(struct udphdr) + hdrlen); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 184 | skb_reset_transport_header(skb); |
| 185 | |
Jesse Gross | a09a4c8 | 2016-03-19 09:32:02 -0700 | [diff] [blame] | 186 | if (iptunnel_pull_offloads(skb)) |
| 187 | goto drop; |
| 188 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 189 | return -guehdr->proto_ctype; |
| 190 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 191 | drop: |
| 192 | kfree_skb(skb); |
| 193 | return 0; |
| 194 | } |
| 195 | |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 196 | static struct sk_buff **fou_gro_receive(struct sock *sk, |
| 197 | struct sk_buff **head, |
| 198 | struct sk_buff *skb) |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 199 | { |
| 200 | const struct net_offload *ops; |
| 201 | struct sk_buff **pp = NULL; |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 202 | u8 proto = fou_from_sock(sk)->protocol; |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 203 | const struct net_offload **offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 204 | |
Alexander Duyck | c348338 | 2016-03-29 14:55:22 -0700 | [diff] [blame] | 205 | /* We can clear the encap_mark for FOU as we are essentially doing |
| 206 | * one of two possible things. We are either adding an L4 tunnel |
| 207 | * header to the outer L3 tunnel header, or we are are simply |
| 208 | * treating the GRE tunnel header as though it is a UDP protocol |
| 209 | * specific header such as VXLAN or GENEVE. |
| 210 | */ |
| 211 | NAPI_GRO_CB(skb)->encap_mark = 0; |
| 212 | |
Alexander Duyck | a0ca153 | 2016-04-05 09:13:39 -0700 | [diff] [blame] | 213 | /* Flag this frame as already having an outer encap header */ |
| 214 | NAPI_GRO_CB(skb)->is_fou = 1; |
| 215 | |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 216 | rcu_read_lock(); |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 217 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 218 | ops = rcu_dereference(offloads[proto]); |
| 219 | if (!ops || !ops->callbacks.gro_receive) |
| 220 | goto out_unlock; |
| 221 | |
| 222 | pp = ops->callbacks.gro_receive(head, skb); |
| 223 | |
| 224 | out_unlock: |
| 225 | rcu_read_unlock(); |
| 226 | |
| 227 | return pp; |
| 228 | } |
| 229 | |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 230 | static int fou_gro_complete(struct sock *sk, struct sk_buff *skb, |
| 231 | int nhoff) |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 232 | { |
| 233 | const struct net_offload *ops; |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 234 | u8 proto = fou_from_sock(sk)->protocol; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 235 | int err = -ENOSYS; |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 236 | const struct net_offload **offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 237 | |
| 238 | rcu_read_lock(); |
Tom Herbert | efc98d0 | 2014-10-03 15:48:08 -0700 | [diff] [blame] | 239 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 240 | ops = rcu_dereference(offloads[proto]); |
| 241 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) |
| 242 | goto out_unlock; |
| 243 | |
| 244 | err = ops->callbacks.gro_complete(skb, nhoff); |
| 245 | |
Jarno Rajahalme | 229740c | 2016-05-03 16:10:21 -0700 | [diff] [blame] | 246 | skb_set_inner_mac_header(skb, nhoff); |
| 247 | |
Tom Herbert | afe9332 | 2014-09-17 12:25:57 -0700 | [diff] [blame] | 248 | out_unlock: |
| 249 | rcu_read_unlock(); |
| 250 | |
| 251 | return err; |
| 252 | } |
| 253 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 254 | static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off, |
| 255 | struct guehdr *guehdr, void *data, |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 256 | size_t hdrlen, struct gro_remcsum *grc, |
| 257 | bool nopartial) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 258 | { |
| 259 | __be16 *pd = data; |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 260 | size_t start = ntohs(pd[0]); |
| 261 | size_t offset = ntohs(pd[1]); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 262 | |
| 263 | if (skb->remcsum_offload) |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 264 | return guehdr; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 265 | |
Tom Herbert | 4fd671d | 2014-11-25 11:21:20 -0800 | [diff] [blame] | 266 | if (!NAPI_GRO_CB(skb)->csum_valid) |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 267 | return NULL; |
| 268 | |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 269 | guehdr = skb_gro_remcsum_process(skb, (void *)guehdr, off, hdrlen, |
| 270 | start, offset, grc, nopartial); |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 271 | |
| 272 | skb->remcsum_offload = 1; |
| 273 | |
| 274 | return guehdr; |
| 275 | } |
| 276 | |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 277 | static struct sk_buff **gue_gro_receive(struct sock *sk, |
| 278 | struct sk_buff **head, |
| 279 | struct sk_buff *skb) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 280 | { |
| 281 | const struct net_offload **offloads; |
| 282 | const struct net_offload *ops; |
| 283 | struct sk_buff **pp = NULL; |
| 284 | struct sk_buff *p; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 285 | struct guehdr *guehdr; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 286 | size_t len, optlen, hdrlen, off; |
| 287 | void *data; |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 288 | u16 doffset = 0; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 289 | int flush = 1; |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 290 | struct fou *fou = fou_from_sock(sk); |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame] | 291 | struct gro_remcsum grc; |
| 292 | |
| 293 | skb_gro_remcsum_init(&grc); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 294 | |
| 295 | off = skb_gro_offset(skb); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 296 | len = off + sizeof(*guehdr); |
| 297 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 298 | guehdr = skb_gro_header_fast(skb, off); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 299 | if (skb_gro_header_hard(skb, len)) { |
| 300 | guehdr = skb_gro_header_slow(skb, len, off); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 301 | if (unlikely(!guehdr)) |
| 302 | goto out; |
| 303 | } |
| 304 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 305 | optlen = guehdr->hlen << 2; |
| 306 | len += optlen; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 307 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 308 | if (skb_gro_header_hard(skb, len)) { |
| 309 | guehdr = skb_gro_header_slow(skb, len, off); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 310 | if (unlikely(!guehdr)) |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 311 | goto out; |
| 312 | } |
| 313 | |
| 314 | if (unlikely(guehdr->control) || guehdr->version != 0 || |
| 315 | validate_gue_flags(guehdr, optlen)) |
| 316 | goto out; |
| 317 | |
| 318 | hdrlen = sizeof(*guehdr) + optlen; |
| 319 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 320 | /* Adjust NAPI_GRO_CB(skb)->csum to account for guehdr, |
| 321 | * this is needed if there is a remote checkcsum offload. |
| 322 | */ |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 323 | skb_gro_postpull_rcsum(skb, guehdr, hdrlen); |
| 324 | |
| 325 | data = &guehdr[1]; |
| 326 | |
| 327 | if (guehdr->flags & GUE_FLAG_PRIV) { |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 328 | __be32 flags = *(__be32 *)(data + doffset); |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 329 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 330 | doffset += GUE_LEN_PRIV; |
| 331 | |
| 332 | if (flags & GUE_PFLAG_REMCSUM) { |
| 333 | guehdr = gue_gro_remcsum(skb, off, guehdr, |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 334 | data + doffset, hdrlen, &grc, |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 335 | !!(fou->flags & |
| 336 | FOU_F_REMCSUM_NOPARTIAL)); |
Tom Herbert | b7fe10e | 2015-08-19 17:07:32 -0700 | [diff] [blame] | 337 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 338 | if (!guehdr) |
| 339 | goto out; |
| 340 | |
| 341 | data = &guehdr[1]; |
| 342 | |
| 343 | doffset += GUE_PLEN_REMCSUM; |
| 344 | } |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Tom Herbert | a8d31c1 | 2014-11-04 09:06:57 -0800 | [diff] [blame] | 347 | skb_gro_pull(skb, hdrlen); |
| 348 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 349 | for (p = *head; p; p = p->next) { |
| 350 | const struct guehdr *guehdr2; |
| 351 | |
| 352 | if (!NAPI_GRO_CB(p)->same_flow) |
| 353 | continue; |
| 354 | |
| 355 | guehdr2 = (struct guehdr *)(p->data + off); |
| 356 | |
| 357 | /* Compare base GUE header to be equal (covers |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 358 | * hlen, version, proto_ctype, and flags. |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 359 | */ |
| 360 | if (guehdr->word != guehdr2->word) { |
| 361 | NAPI_GRO_CB(p)->same_flow = 0; |
| 362 | continue; |
| 363 | } |
| 364 | |
| 365 | /* Compare optional fields are the same. */ |
| 366 | if (guehdr->hlen && memcmp(&guehdr[1], &guehdr2[1], |
| 367 | guehdr->hlen << 2)) { |
| 368 | NAPI_GRO_CB(p)->same_flow = 0; |
| 369 | continue; |
| 370 | } |
| 371 | } |
| 372 | |
Alexander Duyck | c348338 | 2016-03-29 14:55:22 -0700 | [diff] [blame] | 373 | /* We can clear the encap_mark for GUE as we are essentially doing |
| 374 | * one of two possible things. We are either adding an L4 tunnel |
| 375 | * header to the outer L3 tunnel header, or we are are simply |
| 376 | * treating the GRE tunnel header as though it is a UDP protocol |
| 377 | * specific header such as VXLAN or GENEVE. |
| 378 | */ |
| 379 | NAPI_GRO_CB(skb)->encap_mark = 0; |
| 380 | |
Alexander Duyck | a0ca153 | 2016-04-05 09:13:39 -0700 | [diff] [blame] | 381 | /* Flag this frame as already having an outer encap header */ |
| 382 | NAPI_GRO_CB(skb)->is_fou = 1; |
| 383 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 384 | rcu_read_lock(); |
| 385 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
| 386 | ops = rcu_dereference(offloads[guehdr->proto_ctype]); |
Tom Herbert | 2701366 | 2015-08-19 17:07:34 -0700 | [diff] [blame] | 387 | if (WARN_ON_ONCE(!ops || !ops->callbacks.gro_receive)) |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 388 | goto out_unlock; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 389 | |
| 390 | pp = ops->callbacks.gro_receive(head, skb); |
Alexander Duyck | c194cf9 | 2016-03-09 09:24:23 -0800 | [diff] [blame] | 391 | flush = 0; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 392 | |
| 393 | out_unlock: |
| 394 | rcu_read_unlock(); |
| 395 | out: |
| 396 | NAPI_GRO_CB(skb)->flush |= flush; |
Tom Herbert | 26c4f7d | 2015-02-10 16:30:27 -0800 | [diff] [blame] | 397 | skb_gro_remcsum_cleanup(skb, &grc); |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 398 | |
| 399 | return pp; |
| 400 | } |
| 401 | |
Tom Herbert | d92283e | 2016-04-05 08:22:54 -0700 | [diff] [blame] | 402 | static int gue_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff) |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 403 | { |
| 404 | const struct net_offload **offloads; |
| 405 | struct guehdr *guehdr = (struct guehdr *)(skb->data + nhoff); |
| 406 | const struct net_offload *ops; |
| 407 | unsigned int guehlen; |
| 408 | u8 proto; |
| 409 | int err = -ENOENT; |
| 410 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 411 | proto = guehdr->proto_ctype; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 412 | |
| 413 | guehlen = sizeof(*guehdr) + (guehdr->hlen << 2); |
| 414 | |
| 415 | rcu_read_lock(); |
| 416 | offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; |
| 417 | ops = rcu_dereference(offloads[proto]); |
| 418 | if (WARN_ON(!ops || !ops->callbacks.gro_complete)) |
| 419 | goto out_unlock; |
| 420 | |
| 421 | err = ops->callbacks.gro_complete(skb, nhoff + guehlen); |
| 422 | |
Jarno Rajahalme | 229740c | 2016-05-03 16:10:21 -0700 | [diff] [blame] | 423 | skb_set_inner_mac_header(skb, nhoff + guehlen); |
| 424 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 425 | out_unlock: |
| 426 | rcu_read_unlock(); |
| 427 | return err; |
| 428 | } |
| 429 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 430 | static int fou_add_to_port_list(struct net *net, struct fou *fou) |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 431 | { |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 432 | struct fou_net *fn = net_generic(net, fou_net_id); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 433 | struct fou *fout; |
| 434 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 435 | mutex_lock(&fn->fou_lock); |
| 436 | list_for_each_entry(fout, &fn->fou_list, list) { |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 437 | if (fou->port == fout->port && |
| 438 | fou->family == fout->family) { |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 439 | mutex_unlock(&fn->fou_lock); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 440 | return -EALREADY; |
| 441 | } |
| 442 | } |
| 443 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 444 | list_add(&fou->list, &fn->fou_list); |
| 445 | mutex_unlock(&fn->fou_lock); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static void fou_release(struct fou *fou) |
| 451 | { |
| 452 | struct socket *sock = fou->sock; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 453 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 454 | list_del(&fou->list); |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 455 | udp_tunnel_sock_release(sock); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 456 | |
Hannes Frederic Sowa | 3036fac | 2015-12-15 21:01:53 +0100 | [diff] [blame] | 457 | kfree_rcu(fou, rcu); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static int fou_create(struct net *net, struct fou_cfg *cfg, |
| 461 | struct socket **sockp) |
| 462 | { |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 463 | struct socket *sock = NULL; |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 464 | struct fou *fou = NULL; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 465 | struct sock *sk; |
Tom Herbert | 440924b | 2016-05-18 09:06:14 -0700 | [diff] [blame] | 466 | struct udp_tunnel_sock_cfg tunnel_cfg; |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 467 | int err; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 468 | |
| 469 | /* Open UDP socket */ |
| 470 | err = udp_sock_create(net, &cfg->udp_config, &sock); |
| 471 | if (err < 0) |
| 472 | goto error; |
| 473 | |
| 474 | /* Allocate FOU port structure */ |
| 475 | fou = kzalloc(sizeof(*fou), GFP_KERNEL); |
| 476 | if (!fou) { |
| 477 | err = -ENOMEM; |
| 478 | goto error; |
| 479 | } |
| 480 | |
| 481 | sk = sock->sk; |
| 482 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 483 | fou->port = cfg->udp_config.local_udp_port; |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 484 | fou->family = cfg->udp_config.family; |
| 485 | fou->flags = cfg->flags; |
Tom Herbert | 440924b | 2016-05-18 09:06:14 -0700 | [diff] [blame] | 486 | fou->type = cfg->type; |
| 487 | fou->sock = sock; |
| 488 | |
| 489 | memset(&tunnel_cfg, 0, sizeof(tunnel_cfg)); |
| 490 | tunnel_cfg.encap_type = 1; |
| 491 | tunnel_cfg.sk_user_data = fou; |
| 492 | tunnel_cfg.encap_destroy = NULL; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 493 | |
| 494 | /* Initial for fou type */ |
| 495 | switch (cfg->type) { |
| 496 | case FOU_ENCAP_DIRECT: |
Tom Herbert | 440924b | 2016-05-18 09:06:14 -0700 | [diff] [blame] | 497 | tunnel_cfg.encap_rcv = fou_udp_recv; |
| 498 | tunnel_cfg.gro_receive = fou_gro_receive; |
| 499 | tunnel_cfg.gro_complete = fou_gro_complete; |
| 500 | fou->protocol = cfg->protocol; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 501 | break; |
| 502 | case FOU_ENCAP_GUE: |
Tom Herbert | 440924b | 2016-05-18 09:06:14 -0700 | [diff] [blame] | 503 | tunnel_cfg.encap_rcv = gue_udp_recv; |
| 504 | tunnel_cfg.gro_receive = gue_gro_receive; |
| 505 | tunnel_cfg.gro_complete = gue_gro_complete; |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 506 | break; |
| 507 | default: |
| 508 | err = -EINVAL; |
| 509 | goto error; |
| 510 | } |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 511 | |
Tom Herbert | 440924b | 2016-05-18 09:06:14 -0700 | [diff] [blame] | 512 | setup_udp_tunnel_sock(net, sock, &tunnel_cfg); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 513 | |
| 514 | sk->sk_allocation = GFP_ATOMIC; |
| 515 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 516 | err = fou_add_to_port_list(net, fou); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 517 | if (err) |
| 518 | goto error; |
| 519 | |
| 520 | if (sockp) |
| 521 | *sockp = sock; |
| 522 | |
| 523 | return 0; |
| 524 | |
| 525 | error: |
| 526 | kfree(fou); |
| 527 | if (sock) |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 528 | udp_tunnel_sock_release(sock); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 529 | |
| 530 | return err; |
| 531 | } |
| 532 | |
| 533 | static int fou_destroy(struct net *net, struct fou_cfg *cfg) |
| 534 | { |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 535 | struct fou_net *fn = net_generic(net, fou_net_id); |
WANG Cong | 4cbcdf2 | 2015-04-10 12:00:28 -0700 | [diff] [blame] | 536 | __be16 port = cfg->udp_config.local_udp_port; |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 537 | u8 family = cfg->udp_config.family; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 538 | int err = -EINVAL; |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 539 | struct fou *fou; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 540 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 541 | mutex_lock(&fn->fou_lock); |
| 542 | list_for_each_entry(fou, &fn->fou_list, list) { |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 543 | if (fou->port == port && fou->family == family) { |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 544 | fou_release(fou); |
| 545 | err = 0; |
| 546 | break; |
| 547 | } |
| 548 | } |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 549 | mutex_unlock(&fn->fou_lock); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 550 | |
| 551 | return err; |
| 552 | } |
| 553 | |
| 554 | static struct genl_family fou_nl_family = { |
| 555 | .id = GENL_ID_GENERATE, |
| 556 | .hdrsize = 0, |
| 557 | .name = FOU_GENL_NAME, |
| 558 | .version = FOU_GENL_VERSION, |
| 559 | .maxattr = FOU_ATTR_MAX, |
| 560 | .netnsok = true, |
| 561 | }; |
| 562 | |
| 563 | static struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = { |
| 564 | [FOU_ATTR_PORT] = { .type = NLA_U16, }, |
| 565 | [FOU_ATTR_AF] = { .type = NLA_U8, }, |
| 566 | [FOU_ATTR_IPPROTO] = { .type = NLA_U8, }, |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 567 | [FOU_ATTR_TYPE] = { .type = NLA_U8, }, |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 568 | [FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, }, |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | static int parse_nl_config(struct genl_info *info, |
| 572 | struct fou_cfg *cfg) |
| 573 | { |
| 574 | memset(cfg, 0, sizeof(*cfg)); |
| 575 | |
| 576 | cfg->udp_config.family = AF_INET; |
| 577 | |
| 578 | if (info->attrs[FOU_ATTR_AF]) { |
| 579 | u8 family = nla_get_u8(info->attrs[FOU_ATTR_AF]); |
| 580 | |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 581 | switch (family) { |
| 582 | case AF_INET: |
| 583 | break; |
| 584 | case AF_INET6: |
| 585 | cfg->udp_config.ipv6_v6only = 1; |
| 586 | break; |
| 587 | default: |
| 588 | return -EAFNOSUPPORT; |
| 589 | } |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 590 | |
| 591 | cfg->udp_config.family = family; |
| 592 | } |
| 593 | |
| 594 | if (info->attrs[FOU_ATTR_PORT]) { |
WANG Cong | 4cbcdf2 | 2015-04-10 12:00:28 -0700 | [diff] [blame] | 595 | __be16 port = nla_get_be16(info->attrs[FOU_ATTR_PORT]); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 596 | |
| 597 | cfg->udp_config.local_udp_port = port; |
| 598 | } |
| 599 | |
| 600 | if (info->attrs[FOU_ATTR_IPPROTO]) |
| 601 | cfg->protocol = nla_get_u8(info->attrs[FOU_ATTR_IPPROTO]); |
| 602 | |
Tom Herbert | 37dd024 | 2014-10-03 15:48:09 -0700 | [diff] [blame] | 603 | if (info->attrs[FOU_ATTR_TYPE]) |
| 604 | cfg->type = nla_get_u8(info->attrs[FOU_ATTR_TYPE]); |
| 605 | |
Tom Herbert | fe881ef | 2015-02-10 16:30:33 -0800 | [diff] [blame] | 606 | if (info->attrs[FOU_ATTR_REMCSUM_NOPARTIAL]) |
| 607 | cfg->flags |= FOU_F_REMCSUM_NOPARTIAL; |
| 608 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info) |
| 613 | { |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 614 | struct net *net = genl_info_net(info); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 615 | struct fou_cfg cfg; |
| 616 | int err; |
| 617 | |
| 618 | err = parse_nl_config(info, &cfg); |
| 619 | if (err) |
| 620 | return err; |
| 621 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 622 | return fou_create(net, &cfg, NULL); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info) |
| 626 | { |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 627 | struct net *net = genl_info_net(info); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 628 | struct fou_cfg cfg; |
WANG Cong | 6727063 | 2015-04-10 12:00:27 -0700 | [diff] [blame] | 629 | int err; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 630 | |
WANG Cong | 6727063 | 2015-04-10 12:00:27 -0700 | [diff] [blame] | 631 | err = parse_nl_config(info, &cfg); |
| 632 | if (err) |
| 633 | return err; |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 634 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 635 | return fou_destroy(net, &cfg); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 636 | } |
| 637 | |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 638 | static int fou_fill_info(struct fou *fou, struct sk_buff *msg) |
| 639 | { |
| 640 | if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) || |
| 641 | nla_put_be16(msg, FOU_ATTR_PORT, fou->port) || |
| 642 | nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) || |
| 643 | nla_put_u8(msg, FOU_ATTR_TYPE, fou->type)) |
| 644 | return -1; |
| 645 | |
| 646 | if (fou->flags & FOU_F_REMCSUM_NOPARTIAL) |
| 647 | if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL)) |
| 648 | return -1; |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | static int fou_dump_info(struct fou *fou, u32 portid, u32 seq, |
| 653 | u32 flags, struct sk_buff *skb, u8 cmd) |
| 654 | { |
| 655 | void *hdr; |
| 656 | |
| 657 | hdr = genlmsg_put(skb, portid, seq, &fou_nl_family, flags, cmd); |
| 658 | if (!hdr) |
| 659 | return -ENOMEM; |
| 660 | |
| 661 | if (fou_fill_info(fou, skb) < 0) |
| 662 | goto nla_put_failure; |
| 663 | |
| 664 | genlmsg_end(skb, hdr); |
| 665 | return 0; |
| 666 | |
| 667 | nla_put_failure: |
| 668 | genlmsg_cancel(skb, hdr); |
| 669 | return -EMSGSIZE; |
| 670 | } |
| 671 | |
| 672 | static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info) |
| 673 | { |
| 674 | struct net *net = genl_info_net(info); |
| 675 | struct fou_net *fn = net_generic(net, fou_net_id); |
| 676 | struct sk_buff *msg; |
| 677 | struct fou_cfg cfg; |
| 678 | struct fou *fout; |
| 679 | __be16 port; |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 680 | u8 family; |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 681 | int ret; |
| 682 | |
| 683 | ret = parse_nl_config(info, &cfg); |
| 684 | if (ret) |
| 685 | return ret; |
| 686 | port = cfg.udp_config.local_udp_port; |
| 687 | if (port == 0) |
| 688 | return -EINVAL; |
| 689 | |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 690 | family = cfg.udp_config.family; |
| 691 | if (family != AF_INET && family != AF_INET6) |
| 692 | return -EINVAL; |
| 693 | |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 695 | if (!msg) |
| 696 | return -ENOMEM; |
| 697 | |
| 698 | ret = -ESRCH; |
| 699 | mutex_lock(&fn->fou_lock); |
| 700 | list_for_each_entry(fout, &fn->fou_list, list) { |
Tom Herbert | 5f914b6 | 2016-05-18 09:06:16 -0700 | [diff] [blame] | 701 | if (port == fout->port && family == fout->family) { |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 702 | ret = fou_dump_info(fout, info->snd_portid, |
| 703 | info->snd_seq, 0, msg, |
| 704 | info->genlhdr->cmd); |
| 705 | break; |
| 706 | } |
| 707 | } |
| 708 | mutex_unlock(&fn->fou_lock); |
| 709 | if (ret < 0) |
| 710 | goto out_free; |
| 711 | |
| 712 | return genlmsg_reply(msg, info); |
| 713 | |
| 714 | out_free: |
| 715 | nlmsg_free(msg); |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 720 | { |
| 721 | struct net *net = sock_net(skb->sk); |
| 722 | struct fou_net *fn = net_generic(net, fou_net_id); |
| 723 | struct fou *fout; |
| 724 | int idx = 0, ret; |
| 725 | |
| 726 | mutex_lock(&fn->fou_lock); |
| 727 | list_for_each_entry(fout, &fn->fou_list, list) { |
| 728 | if (idx++ < cb->args[0]) |
| 729 | continue; |
| 730 | ret = fou_dump_info(fout, NETLINK_CB(cb->skb).portid, |
| 731 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 732 | skb, FOU_CMD_GET); |
| 733 | if (ret) |
WANG Cong | 540207a | 2015-04-15 11:48:49 -0700 | [diff] [blame] | 734 | break; |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 735 | } |
| 736 | mutex_unlock(&fn->fou_lock); |
| 737 | |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 738 | cb->args[0] = idx; |
| 739 | return skb->len; |
| 740 | } |
| 741 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 742 | static const struct genl_ops fou_nl_ops[] = { |
| 743 | { |
| 744 | .cmd = FOU_CMD_ADD, |
| 745 | .doit = fou_nl_cmd_add_port, |
| 746 | .policy = fou_nl_policy, |
| 747 | .flags = GENL_ADMIN_PERM, |
| 748 | }, |
| 749 | { |
| 750 | .cmd = FOU_CMD_DEL, |
| 751 | .doit = fou_nl_cmd_rm_port, |
| 752 | .policy = fou_nl_policy, |
| 753 | .flags = GENL_ADMIN_PERM, |
| 754 | }, |
WANG Cong | 7a6c8c3 | 2015-04-10 12:00:30 -0700 | [diff] [blame] | 755 | { |
| 756 | .cmd = FOU_CMD_GET, |
| 757 | .doit = fou_nl_cmd_get_port, |
| 758 | .dumpit = fou_nl_dump, |
| 759 | .policy = fou_nl_policy, |
| 760 | }, |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 761 | }; |
| 762 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 763 | size_t fou_encap_hlen(struct ip_tunnel_encap *e) |
| 764 | { |
| 765 | return sizeof(struct udphdr); |
| 766 | } |
| 767 | EXPORT_SYMBOL(fou_encap_hlen); |
| 768 | |
| 769 | size_t gue_encap_hlen(struct ip_tunnel_encap *e) |
| 770 | { |
| 771 | size_t len; |
| 772 | bool need_priv = false; |
| 773 | |
| 774 | len = sizeof(struct udphdr) + sizeof(struct guehdr); |
| 775 | |
| 776 | if (e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) { |
| 777 | len += GUE_PLEN_REMCSUM; |
| 778 | need_priv = true; |
| 779 | } |
| 780 | |
| 781 | len += need_priv ? GUE_LEN_PRIV : 0; |
| 782 | |
| 783 | return len; |
| 784 | } |
| 785 | EXPORT_SYMBOL(gue_encap_hlen); |
| 786 | |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 787 | static void fou_build_udp(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 788 | struct flowi4 *fl4, u8 *protocol, __be16 sport) |
| 789 | { |
| 790 | struct udphdr *uh; |
| 791 | |
| 792 | skb_push(skb, sizeof(struct udphdr)); |
| 793 | skb_reset_transport_header(skb); |
| 794 | |
| 795 | uh = udp_hdr(skb); |
| 796 | |
| 797 | uh->dest = e->dport; |
| 798 | uh->source = sport; |
| 799 | uh->len = htons(skb->len); |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 800 | udp_set_csum(!(e->flags & TUNNEL_ENCAP_FLAG_CSUM), skb, |
| 801 | fl4->saddr, fl4->daddr, skb->len); |
| 802 | |
| 803 | *protocol = IPPROTO_UDP; |
| 804 | } |
| 805 | |
Tom Herbert | dc969b8 | 2016-05-18 09:06:15 -0700 | [diff] [blame] | 806 | int __fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 807 | u8 *protocol, __be16 *sport, int type) |
| 808 | { |
| 809 | int err; |
| 810 | |
| 811 | err = iptunnel_handle_offloads(skb, type); |
| 812 | if (err) |
| 813 | return err; |
| 814 | |
| 815 | *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), |
| 816 | skb, 0, 0, false); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | EXPORT_SYMBOL(__fou_build_header); |
| 821 | |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 822 | int fou_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 823 | u8 *protocol, struct flowi4 *fl4) |
| 824 | { |
Edward Cree | 06f6229 | 2016-02-11 21:00:16 +0000 | [diff] [blame] | 825 | int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : |
| 826 | SKB_GSO_UDP_TUNNEL; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 827 | __be16 sport; |
Alexander Duyck | aed069d | 2016-04-14 15:33:37 -0400 | [diff] [blame] | 828 | int err; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 829 | |
Tom Herbert | dc969b8 | 2016-05-18 09:06:15 -0700 | [diff] [blame] | 830 | err = __fou_build_header(skb, e, protocol, &sport, type); |
Alexander Duyck | aed069d | 2016-04-14 15:33:37 -0400 | [diff] [blame] | 831 | if (err) |
| 832 | return err; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 833 | |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 834 | fou_build_udp(skb, e, fl4, protocol, sport); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | EXPORT_SYMBOL(fou_build_header); |
| 839 | |
Tom Herbert | dc969b8 | 2016-05-18 09:06:15 -0700 | [diff] [blame] | 840 | int __gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 841 | u8 *protocol, __be16 *sport, int type) |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 842 | { |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 843 | struct guehdr *guehdr; |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 844 | size_t hdrlen, optlen = 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 845 | void *data; |
| 846 | bool need_priv = false; |
Alexander Duyck | aed069d | 2016-04-14 15:33:37 -0400 | [diff] [blame] | 847 | int err; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 848 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 849 | if ((e->flags & TUNNEL_ENCAP_FLAG_REMCSUM) && |
| 850 | skb->ip_summed == CHECKSUM_PARTIAL) { |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 851 | optlen += GUE_PLEN_REMCSUM; |
| 852 | type |= SKB_GSO_TUNNEL_REMCSUM; |
| 853 | need_priv = true; |
| 854 | } |
| 855 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 856 | optlen += need_priv ? GUE_LEN_PRIV : 0; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 857 | |
Alexander Duyck | aed069d | 2016-04-14 15:33:37 -0400 | [diff] [blame] | 858 | err = iptunnel_handle_offloads(skb, type); |
| 859 | if (err) |
| 860 | return err; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 861 | |
| 862 | /* Get source port (based on flow hash) before skb_push */ |
Tom Herbert | dc969b8 | 2016-05-18 09:06:15 -0700 | [diff] [blame] | 863 | *sport = e->sport ? : udp_flow_src_port(dev_net(skb->dev), |
| 864 | skb, 0, 0, false); |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 865 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 866 | hdrlen = sizeof(struct guehdr) + optlen; |
| 867 | |
| 868 | skb_push(skb, hdrlen); |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 869 | |
| 870 | guehdr = (struct guehdr *)skb->data; |
| 871 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 872 | guehdr->control = 0; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 873 | guehdr->version = 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 874 | guehdr->hlen = optlen >> 2; |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 875 | guehdr->flags = 0; |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 876 | guehdr->proto_ctype = *protocol; |
| 877 | |
| 878 | data = &guehdr[1]; |
| 879 | |
| 880 | if (need_priv) { |
| 881 | __be32 *flags = data; |
| 882 | |
| 883 | guehdr->flags |= GUE_FLAG_PRIV; |
| 884 | *flags = 0; |
| 885 | data += GUE_LEN_PRIV; |
| 886 | |
Tom Herbert | b17f709 | 2014-11-04 09:06:56 -0800 | [diff] [blame] | 887 | if (type & SKB_GSO_TUNNEL_REMCSUM) { |
| 888 | u16 csum_start = skb_checksum_start_offset(skb); |
| 889 | __be16 *pd = data; |
| 890 | |
| 891 | if (csum_start < hdrlen) |
| 892 | return -EINVAL; |
| 893 | |
| 894 | csum_start -= hdrlen; |
| 895 | pd[0] = htons(csum_start); |
| 896 | pd[1] = htons(csum_start + skb->csum_offset); |
| 897 | |
| 898 | if (!skb_is_gso(skb)) { |
| 899 | skb->ip_summed = CHECKSUM_NONE; |
| 900 | skb->encapsulation = 0; |
| 901 | } |
| 902 | |
| 903 | *flags |= GUE_PFLAG_REMCSUM; |
| 904 | data += GUE_PLEN_REMCSUM; |
| 905 | } |
| 906 | |
Tom Herbert | 5024c33 | 2014-11-04 09:06:53 -0800 | [diff] [blame] | 907 | } |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 908 | |
Tom Herbert | dc969b8 | 2016-05-18 09:06:15 -0700 | [diff] [blame] | 909 | return 0; |
| 910 | } |
| 911 | EXPORT_SYMBOL(__gue_build_header); |
| 912 | |
| 913 | int gue_build_header(struct sk_buff *skb, struct ip_tunnel_encap *e, |
| 914 | u8 *protocol, struct flowi4 *fl4) |
| 915 | { |
| 916 | int type = e->flags & TUNNEL_ENCAP_FLAG_CSUM ? SKB_GSO_UDP_TUNNEL_CSUM : |
| 917 | SKB_GSO_UDP_TUNNEL; |
| 918 | __be16 sport; |
| 919 | int err; |
| 920 | |
| 921 | err = __gue_build_header(skb, e, protocol, &sport, type); |
| 922 | if (err) |
| 923 | return err; |
| 924 | |
Tom Herbert | 63487ba | 2014-11-04 09:06:51 -0800 | [diff] [blame] | 925 | fou_build_udp(skb, e, fl4, protocol, sport); |
| 926 | |
| 927 | return 0; |
| 928 | } |
| 929 | EXPORT_SYMBOL(gue_build_header); |
| 930 | |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 931 | #ifdef CONFIG_NET_FOU_IP_TUNNELS |
| 932 | |
Andi Kleen | 5eeb292 | 2015-04-08 06:04:31 -0700 | [diff] [blame] | 933 | static const struct ip_tunnel_encap_ops fou_iptun_ops = { |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 934 | .encap_hlen = fou_encap_hlen, |
| 935 | .build_header = fou_build_header, |
| 936 | }; |
| 937 | |
Andi Kleen | 5eeb292 | 2015-04-08 06:04:31 -0700 | [diff] [blame] | 938 | static const struct ip_tunnel_encap_ops gue_iptun_ops = { |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 939 | .encap_hlen = gue_encap_hlen, |
| 940 | .build_header = gue_build_header, |
| 941 | }; |
| 942 | |
| 943 | static int ip_tunnel_encap_add_fou_ops(void) |
| 944 | { |
| 945 | int ret; |
| 946 | |
| 947 | ret = ip_tunnel_encap_add_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 948 | if (ret < 0) { |
| 949 | pr_err("can't add fou ops\n"); |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | ret = ip_tunnel_encap_add_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); |
| 954 | if (ret < 0) { |
| 955 | pr_err("can't add gue ops\n"); |
| 956 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static void ip_tunnel_encap_del_fou_ops(void) |
| 964 | { |
| 965 | ip_tunnel_encap_del_ops(&fou_iptun_ops, TUNNEL_ENCAP_FOU); |
| 966 | ip_tunnel_encap_del_ops(&gue_iptun_ops, TUNNEL_ENCAP_GUE); |
| 967 | } |
| 968 | |
| 969 | #else |
| 970 | |
| 971 | static int ip_tunnel_encap_add_fou_ops(void) |
| 972 | { |
| 973 | return 0; |
| 974 | } |
| 975 | |
Thomas Graf | 882288c | 2014-11-13 12:48:21 +0100 | [diff] [blame] | 976 | static void ip_tunnel_encap_del_fou_ops(void) |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 977 | { |
| 978 | } |
| 979 | |
| 980 | #endif |
| 981 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 982 | static __net_init int fou_init_net(struct net *net) |
| 983 | { |
| 984 | struct fou_net *fn = net_generic(net, fou_net_id); |
| 985 | |
| 986 | INIT_LIST_HEAD(&fn->fou_list); |
| 987 | mutex_init(&fn->fou_lock); |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static __net_exit void fou_exit_net(struct net *net) |
| 992 | { |
| 993 | struct fou_net *fn = net_generic(net, fou_net_id); |
| 994 | struct fou *fou, *next; |
| 995 | |
| 996 | /* Close all the FOU sockets */ |
| 997 | mutex_lock(&fn->fou_lock); |
| 998 | list_for_each_entry_safe(fou, next, &fn->fou_list, list) |
| 999 | fou_release(fou); |
| 1000 | mutex_unlock(&fn->fou_lock); |
| 1001 | } |
| 1002 | |
| 1003 | static struct pernet_operations fou_net_ops = { |
| 1004 | .init = fou_init_net, |
| 1005 | .exit = fou_exit_net, |
| 1006 | .id = &fou_net_id, |
| 1007 | .size = sizeof(struct fou_net), |
| 1008 | }; |
| 1009 | |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 1010 | static int __init fou_init(void) |
| 1011 | { |
| 1012 | int ret; |
| 1013 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 1014 | ret = register_pernet_device(&fou_net_ops); |
| 1015 | if (ret) |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 1016 | goto exit; |
| 1017 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 1018 | ret = genl_register_family_with_ops(&fou_nl_family, |
| 1019 | fou_nl_ops); |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 1020 | if (ret < 0) |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 1021 | goto unregister; |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 1022 | |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 1023 | ret = ip_tunnel_encap_add_fou_ops(); |
| 1024 | if (ret == 0) |
| 1025 | return 0; |
| 1026 | |
| 1027 | genl_unregister_family(&fou_nl_family); |
| 1028 | unregister: |
| 1029 | unregister_pernet_device(&fou_net_ops); |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 1030 | exit: |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | static void __exit fou_fini(void) |
| 1035 | { |
Tom Herbert | a8c5f90 | 2014-11-12 11:54:09 -0800 | [diff] [blame] | 1036 | ip_tunnel_encap_del_fou_ops(); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 1037 | genl_unregister_family(&fou_nl_family); |
WANG Cong | 02d793c | 2015-04-10 12:00:29 -0700 | [diff] [blame] | 1038 | unregister_pernet_device(&fou_net_ops); |
Tom Herbert | 2346155 | 2014-09-17 12:25:56 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | module_init(fou_init); |
| 1042 | module_exit(fou_fini); |
| 1043 | MODULE_AUTHOR("Tom Herbert <therbert@google.com>"); |
| 1044 | MODULE_LICENSE("GPL"); |