hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/net/ipv4/ipip.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Linux NET3: IP/IP protocol decoder.
34 *
....@@ -16,12 +17,6 @@
1617 * Carlos Picoto : GRE over IP support
1718 * Alexey Kuznetsov: Reworked. Really, now it is truncated version of ipv4/ip_gre.c.
1819 * I do not want to merge them together.
19
- *
20
- * This program is free software; you can redistribute it and/or
21
- * modify it under the terms of the GNU General Public License
22
- * as published by the Free Software Foundation; either version
23
- * 2 of the License, or (at your option) any later version.
24
- *
2520 */
2621
2722 /* tunnel.c: an IP tunnel driver
....@@ -140,6 +135,13 @@
140135 struct ip_tunnel *t;
141136 int err = 0;
142137
138
+ t = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
139
+ iph->daddr, iph->saddr, 0);
140
+ if (!t) {
141
+ err = -ENOENT;
142
+ goto out;
143
+ }
144
+
143145 switch (type) {
144146 case ICMP_DEST_UNREACH:
145147 switch (code) {
....@@ -167,21 +169,13 @@
167169 goto out;
168170 }
169171
170
- t = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
171
- iph->daddr, iph->saddr, 0);
172
- if (!t) {
173
- err = -ENOENT;
174
- goto out;
175
- }
176
-
177172 if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED) {
178
- ipv4_update_pmtu(skb, net, info, t->parms.link, 0,
179
- iph->protocol, 0);
173
+ ipv4_update_pmtu(skb, net, info, t->parms.link, iph->protocol);
180174 goto out;
181175 }
182176
183177 if (type == ICMP_REDIRECT) {
184
- ipv4_redirect(skb, net, t->parms.link, 0, iph->protocol, 0);
178
+ ipv4_redirect(skb, net, t->parms.link, iph->protocol);
185179 goto out;
186180 }
187181
....@@ -306,7 +300,7 @@
306300 skb_set_inner_ipproto(skb, ipproto);
307301
308302 if (tunnel->collect_md)
309
- ip_md_tunnel_xmit(skb, dev, ipproto);
303
+ ip_md_tunnel_xmit(skb, dev, ipproto, 0);
310304 else
311305 ip_tunnel_xmit(skb, dev, tiph, ipproto);
312306 return NETDEV_TX_OK;
....@@ -333,41 +327,29 @@
333327 }
334328
335329 static int
336
-ipip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
330
+ipip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd)
337331 {
338
- int err = 0;
339
- struct ip_tunnel_parm p;
340
-
341
- if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
342
- return -EFAULT;
343
-
344332 if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
345
- if (p.iph.version != 4 ||
346
- !ipip_tunnel_ioctl_verify_protocol(p.iph.protocol) ||
347
- p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
333
+ if (p->iph.version != 4 ||
334
+ !ipip_tunnel_ioctl_verify_protocol(p->iph.protocol) ||
335
+ p->iph.ihl != 5 || (p->iph.frag_off & htons(~IP_DF)))
348336 return -EINVAL;
349337 }
350338
351
- p.i_key = p.o_key = 0;
352
- p.i_flags = p.o_flags = 0;
353
- err = ip_tunnel_ioctl(dev, &p, cmd);
354
- if (err)
355
- return err;
356
-
357
- if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
358
- return -EFAULT;
359
-
360
- return 0;
339
+ p->i_key = p->o_key = 0;
340
+ p->i_flags = p->o_flags = 0;
341
+ return ip_tunnel_ctl(dev, p, cmd);
361342 }
362343
363344 static const struct net_device_ops ipip_netdev_ops = {
364345 .ndo_init = ipip_tunnel_init,
365346 .ndo_uninit = ip_tunnel_uninit,
366347 .ndo_start_xmit = ipip_tunnel_xmit,
367
- .ndo_do_ioctl = ipip_tunnel_ioctl,
348
+ .ndo_do_ioctl = ip_tunnel_ioctl,
368349 .ndo_change_mtu = ip_tunnel_change_mtu,
369350 .ndo_get_stats64 = ip_tunnel_get_stats64,
370351 .ndo_get_iflink = ip_tunnel_get_iflink,
352
+ .ndo_tunnel_ctl = ipip_tunnel_ctl,
371353 };
372354
373355 #define IPIP_FEATURES (NETIF_F_SG | \
....@@ -379,6 +361,7 @@
379361 static void ipip_tunnel_setup(struct net_device *dev)
380362 {
381363 dev->netdev_ops = &ipip_netdev_ops;
364
+ dev->header_ops = &ip_tunnel_header_ops;
382365
383366 dev->type = ARPHRD_TUNNEL;
384367 dev->flags = IFF_NOARP;