hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/net/ipv6/ip6_tunnel.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * IPv6 tunneling device
34 * Linux INET6 implementation
....@@ -10,12 +11,6 @@
1011 * linux/net/ipv6/sit.c and linux/net/ipv4/ipip.c
1112 *
1213 * RFC 2473
13
- *
14
- * This program is free software; you can redistribute it and/or
15
- * modify it under the terms of the GNU General Public License
16
- * as published by the Free Software Foundation; either version
17
- * 2 of the License, or (at your option) any later version.
18
- *
1914 */
2015
2116 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -94,6 +89,11 @@
9489 struct ip6_tnl __rcu *collect_md_tun;
9590 };
9691
92
+static inline int ip6_tnl_mpls_supported(void)
93
+{
94
+ return IS_ENABLED(CONFIG_MPLS);
95
+}
96
+
9797 static struct net_device_stats *ip6_get_stats(struct net_device *dev)
9898 {
9999 struct pcpu_sw_netstats tmp, sum = { 0 };
....@@ -124,8 +124,13 @@
124124 return &dev->stats;
125125 }
126126
127
+#define for_each_ip6_tunnel_rcu(start) \
128
+ for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
129
+
127130 /**
128131 * ip6_tnl_lookup - fetch tunnel matching the end-point addresses
132
+ * @net: network namespace
133
+ * @link: ifindex of underlying interface
129134 * @remote: the address of the tunnel exit-point
130135 * @local: the address of the tunnel entry-point
131136 *
....@@ -135,40 +140,56 @@
135140 * else %NULL
136141 **/
137142
138
-#define for_each_ip6_tunnel_rcu(start) \
139
- for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
140
-
141143 static struct ip6_tnl *
142
-ip6_tnl_lookup(struct net *net, const struct in6_addr *remote, const struct in6_addr *local)
144
+ip6_tnl_lookup(struct net *net, int link,
145
+ const struct in6_addr *remote, const struct in6_addr *local)
143146 {
144147 unsigned int hash = HASH(remote, local);
145
- struct ip6_tnl *t;
148
+ struct ip6_tnl *t, *cand = NULL;
146149 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
147150 struct in6_addr any;
148151
149152 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
150
- if (ipv6_addr_equal(local, &t->parms.laddr) &&
151
- ipv6_addr_equal(remote, &t->parms.raddr) &&
152
- (t->dev->flags & IFF_UP))
153
+ if (!ipv6_addr_equal(local, &t->parms.laddr) ||
154
+ !ipv6_addr_equal(remote, &t->parms.raddr) ||
155
+ !(t->dev->flags & IFF_UP))
156
+ continue;
157
+
158
+ if (link == t->parms.link)
153159 return t;
160
+ else
161
+ cand = t;
154162 }
155163
156164 memset(&any, 0, sizeof(any));
157165 hash = HASH(&any, local);
158166 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
159
- if (ipv6_addr_equal(local, &t->parms.laddr) &&
160
- ipv6_addr_any(&t->parms.raddr) &&
161
- (t->dev->flags & IFF_UP))
167
+ if (!ipv6_addr_equal(local, &t->parms.laddr) ||
168
+ !ipv6_addr_any(&t->parms.raddr) ||
169
+ !(t->dev->flags & IFF_UP))
170
+ continue;
171
+
172
+ if (link == t->parms.link)
162173 return t;
174
+ else if (!cand)
175
+ cand = t;
163176 }
164177
165178 hash = HASH(remote, &any);
166179 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
167
- if (ipv6_addr_equal(remote, &t->parms.raddr) &&
168
- ipv6_addr_any(&t->parms.laddr) &&
169
- (t->dev->flags & IFF_UP))
180
+ if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
181
+ !ipv6_addr_any(&t->parms.laddr) ||
182
+ !(t->dev->flags & IFF_UP))
183
+ continue;
184
+
185
+ if (link == t->parms.link)
170186 return t;
187
+ else if (!cand)
188
+ cand = t;
171189 }
190
+
191
+ if (cand)
192
+ return cand;
172193
173194 t = rcu_dereference(ip6n->collect_md_tun);
174195 if (t && t->dev->flags & IFF_UP)
....@@ -281,8 +302,8 @@
281302
282303 /**
283304 * ip6_tnl_create - create a new tunnel
305
+ * @net: network namespace
284306 * @p: tunnel parameters
285
- * @pt: pointer to new tunnel
286307 *
287308 * Description:
288309 * Create tunnel matching given parameters.
....@@ -330,6 +351,7 @@
330351
331352 /**
332353 * ip6_tnl_locate - find or create tunnel matching given parameters
354
+ * @net: network namespace
333355 * @p: tunnel parameters
334356 * @create: != 0 if allowed to create new tunnel if no match found
335357 *
....@@ -355,7 +377,8 @@
355377 (t = rtnl_dereference(*tp)) != NULL;
356378 tp = &t->next) {
357379 if (ipv6_addr_equal(local, &t->parms.laddr) &&
358
- ipv6_addr_equal(remote, &t->parms.raddr)) {
380
+ ipv6_addr_equal(remote, &t->parms.raddr) &&
381
+ p->link == t->parms.link) {
359382 if (create)
360383 return ERR_PTR(-EEXIST);
361384
....@@ -420,7 +443,7 @@
420443 break;
421444 optlen = 8;
422445 } else if (nexthdr == NEXTHDR_AUTH) {
423
- optlen = (hdr->hdrlen + 2) << 2;
446
+ optlen = ipv6_authlen(hdr);
424447 } else {
425448 optlen = ipv6_optlen(hdr);
426449 }
....@@ -489,7 +512,7 @@
489512 processing of the error. */
490513
491514 rcu_read_lock();
492
- t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->daddr, &ipv6h->saddr);
515
+ t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->daddr, &ipv6h->saddr);
493516 if (!t)
494517 goto out;
495518
....@@ -500,8 +523,6 @@
500523 err = 0;
501524
502525 switch (*type) {
503
- struct ipv6_tlv_tnl_enc_lim *tel;
504
- __u32 mtu, teli;
505526 case ICMPV6_DEST_UNREACH:
506527 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
507528 t->parms.name);
....@@ -514,7 +535,10 @@
514535 rel_msg = 1;
515536 }
516537 break;
517
- case ICMPV6_PARAMPROB:
538
+ case ICMPV6_PARAMPROB: {
539
+ struct ipv6_tlv_tnl_enc_lim *tel;
540
+ __u32 teli;
541
+
518542 teli = 0;
519543 if ((*code) == ICMPV6_HDR_FIELD)
520544 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
....@@ -531,7 +555,10 @@
531555 t->parms.name);
532556 }
533557 break;
534
- case ICMPV6_PKT_TOOBIG:
558
+ }
559
+ case ICMPV6_PKT_TOOBIG: {
560
+ __u32 mtu;
561
+
535562 ip6_update_pmtu(skb, net, htonl(*info), 0, 0,
536563 sock_net_uid(net, NULL));
537564 mtu = *info - offset;
....@@ -545,6 +572,7 @@
545572 rel_msg = 1;
546573 }
547574 break;
575
+ }
548576 case NDISC_REDIRECT:
549577 ip6_redirect(skb, net, skb->dev->ifindex, 0,
550578 sock_net_uid(net, NULL));
....@@ -696,6 +724,20 @@
696724 return 0;
697725 }
698726
727
+static int
728
+mplsip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
729
+ u8 type, u8 code, int offset, __be32 info)
730
+{
731
+ __u32 rel_info = ntohl(info);
732
+ int err, rel_msg = 0;
733
+ u8 rel_type = type;
734
+ u8 rel_code = code;
735
+
736
+ err = ip6_tnl_err(skb, IPPROTO_MPLS, opt, &rel_type, &rel_code,
737
+ &rel_msg, &rel_info, offset);
738
+ return err;
739
+}
740
+
699741 static int ip4ip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
700742 const struct ipv6hdr *ipv6h,
701743 struct sk_buff *skb)
....@@ -716,6 +758,14 @@
716758 ipv6_copy_dscp(ipv6_get_dsfield(ipv6h), ipv6_hdr(skb));
717759
718760 return IP6_ECN_decapsulate(ipv6h, skb);
761
+}
762
+
763
+static inline int mplsip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
764
+ const struct ipv6hdr *ipv6h,
765
+ struct sk_buff *skb)
766
+{
767
+ /* ECN is not supported in AF_MPLS */
768
+ return 0;
719769 }
720770
721771 __u32 ip6_tnl_get_cap(struct ip6_tnl *t,
....@@ -887,6 +937,11 @@
887937 .proto = htons(ETH_P_IP),
888938 };
889939
940
+static const struct tnl_ptk_info tpi_mpls = {
941
+ /* no tunnel info required for mplsip6. */
942
+ .proto = htons(ETH_P_MPLS_UC),
943
+};
944
+
890945 static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,
891946 const struct tnl_ptk_info *tpi,
892947 int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
....@@ -899,7 +954,7 @@
899954 int ret = -1;
900955
901956 rcu_read_lock();
902
- t = ip6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr, &ipv6h->daddr);
957
+ t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->saddr, &ipv6h->daddr);
903958
904959 if (t) {
905960 u8 tproto = READ_ONCE(t->parms.proto);
....@@ -942,6 +997,12 @@
942997 {
943998 return ipxip6_rcv(skb, IPPROTO_IPV6, &tpi_v6,
944999 ip6ip6_dscp_ecn_decapsulate);
1000
+}
1001
+
1002
+static int mplsip6_rcv(struct sk_buff *skb)
1003
+{
1004
+ return ipxip6_rcv(skb, IPPROTO_MPLS, &tpi_mpls,
1005
+ mplsip6_dscp_ecn_decapsulate);
9451006 }
9461007
9471008 struct ipv6_tel_txoption {
....@@ -1206,8 +1267,8 @@
12061267 */
12071268 max_headroom = LL_RESERVED_SPACE(dst->dev) + sizeof(struct ipv6hdr)
12081269 + dst->header_len + t->hlen;
1209
- if (max_headroom > dev->needed_headroom)
1210
- dev->needed_headroom = max_headroom;
1270
+ if (max_headroom > READ_ONCE(dev->needed_headroom))
1271
+ WRITE_ONCE(dev->needed_headroom, max_headroom);
12111272
12121273 err = ip6_tnl_encap(skb, t, &proto, fl6);
12131274 if (err)
....@@ -1239,22 +1300,22 @@
12391300 EXPORT_SYMBOL(ip6_tnl_xmit);
12401301
12411302 static inline int
1242
-ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1303
+ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
1304
+ u8 protocol)
12431305 {
12441306 struct ip6_tnl *t = netdev_priv(dev);
1307
+ struct ipv6hdr *ipv6h;
12451308 const struct iphdr *iph;
12461309 int encap_limit = -1;
1310
+ __u16 offset;
12471311 struct flowi6 fl6;
1248
- __u8 dsfield;
1312
+ __u8 dsfield, orig_dsfield;
12491313 __u32 mtu;
12501314 u8 tproto;
12511315 int err;
12521316
1253
- iph = ip_hdr(skb);
1254
- memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1255
-
12561317 tproto = READ_ONCE(t->parms.proto);
1257
- if (tproto != IPPROTO_IPIP && tproto != 0)
1318
+ if (tproto != protocol && tproto != 0)
12581319 return -1;
12591320
12601321 if (t->parms.collect_md) {
....@@ -1267,129 +1328,102 @@
12671328 return -1;
12681329 key = &tun_info->key;
12691330 memset(&fl6, 0, sizeof(fl6));
1270
- fl6.flowi6_proto = IPPROTO_IPIP;
1331
+ fl6.flowi6_proto = protocol;
12711332 fl6.saddr = key->u.ipv6.src;
12721333 fl6.daddr = key->u.ipv6.dst;
12731334 fl6.flowlabel = key->label;
12741335 dsfield = key->tos;
1336
+ switch (protocol) {
1337
+ case IPPROTO_IPIP:
1338
+ iph = ip_hdr(skb);
1339
+ orig_dsfield = ipv4_get_dsfield(iph);
1340
+ break;
1341
+ case IPPROTO_IPV6:
1342
+ ipv6h = ipv6_hdr(skb);
1343
+ orig_dsfield = ipv6_get_dsfield(ipv6h);
1344
+ break;
1345
+ default:
1346
+ orig_dsfield = dsfield;
1347
+ break;
1348
+ }
12751349 } else {
12761350 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
12771351 encap_limit = t->parms.encap_limit;
1352
+ if (protocol == IPPROTO_IPV6) {
1353
+ offset = ip6_tnl_parse_tlv_enc_lim(skb,
1354
+ skb_network_header(skb));
1355
+ /* ip6_tnl_parse_tlv_enc_lim() might have
1356
+ * reallocated skb->head
1357
+ */
1358
+ if (offset > 0) {
1359
+ struct ipv6_tlv_tnl_enc_lim *tel;
12781360
1279
- memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
1280
- fl6.flowi6_proto = IPPROTO_IPIP;
1281
-
1282
- if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1283
- dsfield = ipv4_get_dsfield(iph);
1284
- else
1285
- dsfield = ip6_tclass(t->parms.flowinfo);
1286
- if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
1287
- fl6.flowi6_mark = skb->mark;
1288
- else
1289
- fl6.flowi6_mark = t->parms.fwmark;
1290
- }
1291
-
1292
- fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
1293
- dsfield = INET_ECN_encapsulate(dsfield, ipv4_get_dsfield(iph));
1294
-
1295
- if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
1296
- return -1;
1297
-
1298
- skb_set_inner_ipproto(skb, IPPROTO_IPIP);
1299
-
1300
- err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1301
- IPPROTO_IPIP);
1302
- if (err != 0) {
1303
- /* XXX: send ICMP error even if DF is not set. */
1304
- if (err == -EMSGSIZE)
1305
- icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
1306
- htonl(mtu));
1307
- return -1;
1308
- }
1309
-
1310
- return 0;
1311
-}
1312
-
1313
-static inline int
1314
-ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1315
-{
1316
- struct ip6_tnl *t = netdev_priv(dev);
1317
- struct ipv6hdr *ipv6h;
1318
- int encap_limit = -1;
1319
- __u16 offset;
1320
- struct flowi6 fl6;
1321
- __u8 dsfield;
1322
- __u32 mtu;
1323
- u8 tproto;
1324
- int err;
1325
-
1326
- ipv6h = ipv6_hdr(skb);
1327
- tproto = READ_ONCE(t->parms.proto);
1328
- if ((tproto != IPPROTO_IPV6 && tproto != 0) ||
1329
- ip6_tnl_addr_conflict(t, ipv6h))
1330
- return -1;
1331
-
1332
- if (t->parms.collect_md) {
1333
- struct ip_tunnel_info *tun_info;
1334
- const struct ip_tunnel_key *key;
1335
-
1336
- tun_info = skb_tunnel_info(skb);
1337
- if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
1338
- ip_tunnel_info_af(tun_info) != AF_INET6))
1339
- return -1;
1340
- key = &tun_info->key;
1341
- memset(&fl6, 0, sizeof(fl6));
1342
- fl6.flowi6_proto = IPPROTO_IPV6;
1343
- fl6.saddr = key->u.ipv6.src;
1344
- fl6.daddr = key->u.ipv6.dst;
1345
- fl6.flowlabel = key->label;
1346
- dsfield = key->tos;
1347
- } else {
1348
- offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb));
1349
- /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
1350
- ipv6h = ipv6_hdr(skb);
1351
- if (offset > 0) {
1352
- struct ipv6_tlv_tnl_enc_lim *tel;
1353
-
1354
- tel = (void *)&skb_network_header(skb)[offset];
1355
- if (tel->encap_limit == 0) {
1356
- icmpv6_send(skb, ICMPV6_PARAMPROB,
1357
- ICMPV6_HDR_FIELD, offset + 2);
1358
- return -1;
1361
+ tel = (void *)&skb_network_header(skb)[offset];
1362
+ if (tel->encap_limit == 0) {
1363
+ icmpv6_ndo_send(skb, ICMPV6_PARAMPROB,
1364
+ ICMPV6_HDR_FIELD, offset + 2);
1365
+ return -1;
1366
+ }
1367
+ encap_limit = tel->encap_limit - 1;
13591368 }
1360
- encap_limit = tel->encap_limit - 1;
1361
- } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) {
1362
- encap_limit = t->parms.encap_limit;
13631369 }
13641370
13651371 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
1366
- fl6.flowi6_proto = IPPROTO_IPV6;
1372
+ fl6.flowi6_proto = protocol;
13671373
1368
- if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1369
- dsfield = ipv6_get_dsfield(ipv6h);
1370
- else
1371
- dsfield = ip6_tclass(t->parms.flowinfo);
1372
- if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
1373
- fl6.flowlabel |= ip6_flowlabel(ipv6h);
13741374 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
13751375 fl6.flowi6_mark = skb->mark;
13761376 else
13771377 fl6.flowi6_mark = t->parms.fwmark;
1378
+ switch (protocol) {
1379
+ case IPPROTO_IPIP:
1380
+ iph = ip_hdr(skb);
1381
+ orig_dsfield = ipv4_get_dsfield(iph);
1382
+ if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1383
+ dsfield = orig_dsfield;
1384
+ else
1385
+ dsfield = ip6_tclass(t->parms.flowinfo);
1386
+ break;
1387
+ case IPPROTO_IPV6:
1388
+ ipv6h = ipv6_hdr(skb);
1389
+ orig_dsfield = ipv6_get_dsfield(ipv6h);
1390
+ if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1391
+ dsfield = orig_dsfield;
1392
+ else
1393
+ dsfield = ip6_tclass(t->parms.flowinfo);
1394
+ if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
1395
+ fl6.flowlabel |= ip6_flowlabel(ipv6h);
1396
+ break;
1397
+ default:
1398
+ orig_dsfield = dsfield = ip6_tclass(t->parms.flowinfo);
1399
+ break;
1400
+ }
13781401 }
13791402
13801403 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
1381
- dsfield = INET_ECN_encapsulate(dsfield, ipv6_get_dsfield(ipv6h));
1404
+ dsfield = INET_ECN_encapsulate(dsfield, orig_dsfield);
13821405
13831406 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
13841407 return -1;
13851408
1386
- skb_set_inner_ipproto(skb, IPPROTO_IPV6);
1409
+ skb_set_inner_ipproto(skb, protocol);
13871410
13881411 err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1389
- IPPROTO_IPV6);
1412
+ protocol);
13901413 if (err != 0) {
1414
+ /* XXX: send ICMP error even if DF is not set. */
13911415 if (err == -EMSGSIZE)
1392
- icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
1416
+ switch (protocol) {
1417
+ case IPPROTO_IPIP:
1418
+ icmp_ndo_send(skb, ICMP_DEST_UNREACH,
1419
+ ICMP_FRAG_NEEDED, htonl(mtu));
1420
+ break;
1421
+ case IPPROTO_IPV6:
1422
+ icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
1423
+ break;
1424
+ default:
1425
+ break;
1426
+ }
13931427 return -1;
13941428 }
13951429
....@@ -1401,6 +1435,7 @@
14011435 {
14021436 struct ip6_tnl *t = netdev_priv(dev);
14031437 struct net_device_stats *stats = &t->dev->stats;
1438
+ u8 ipproto;
14041439 int ret;
14051440
14061441 if (!pskb_inet_may_pull(skb))
....@@ -1408,15 +1443,21 @@
14081443
14091444 switch (skb->protocol) {
14101445 case htons(ETH_P_IP):
1411
- ret = ip4ip6_tnl_xmit(skb, dev);
1446
+ ipproto = IPPROTO_IPIP;
14121447 break;
14131448 case htons(ETH_P_IPV6):
1414
- ret = ip6ip6_tnl_xmit(skb, dev);
1449
+ if (ip6_tnl_addr_conflict(t, ipv6_hdr(skb)))
1450
+ goto tx_err;
1451
+ ipproto = IPPROTO_IPV6;
1452
+ break;
1453
+ case htons(ETH_P_MPLS_UC):
1454
+ ipproto = IPPROTO_MPLS;
14151455 break;
14161456 default:
14171457 goto tx_err;
14181458 }
14191459
1460
+ ret = ipxip6_tnl_xmit(skb, dev, ipproto);
14201461 if (ret < 0)
14211462 goto tx_err;
14221463
....@@ -1432,9 +1473,11 @@
14321473 static void ip6_tnl_link_config(struct ip6_tnl *t)
14331474 {
14341475 struct net_device *dev = t->dev;
1476
+ struct net_device *tdev = NULL;
14351477 struct __ip6_tnl_parm *p = &t->parms;
14361478 struct flowi6 *fl6 = &t->fl.u.ip6;
14371479 int t_hlen;
1480
+ int mtu;
14381481
14391482 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
14401483 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
....@@ -1469,22 +1512,26 @@
14691512 struct rt6_info *rt = rt6_lookup(t->net,
14701513 &p->raddr, &p->laddr,
14711514 p->link, NULL, strict);
1472
-
1473
- if (!rt)
1474
- return;
1475
-
1476
- if (rt->dst.dev) {
1477
- dev->hard_header_len = rt->dst.dev->hard_header_len +
1478
- t_hlen;
1479
-
1480
- dev->mtu = rt->dst.dev->mtu - t_hlen;
1481
- if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1482
- dev->mtu -= 8;
1483
-
1484
- if (dev->mtu < IPV6_MIN_MTU)
1485
- dev->mtu = IPV6_MIN_MTU;
1515
+ if (rt) {
1516
+ tdev = rt->dst.dev;
1517
+ ip6_rt_put(rt);
14861518 }
1487
- ip6_rt_put(rt);
1519
+
1520
+ if (!tdev && p->link)
1521
+ tdev = __dev_get_by_index(t->net, p->link);
1522
+
1523
+ if (tdev) {
1524
+ dev->hard_header_len = tdev->hard_header_len + t_hlen;
1525
+ mtu = min_t(unsigned int, tdev->mtu, IP6_MAX_MTU);
1526
+
1527
+ mtu = mtu - t_hlen;
1528
+ if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1529
+ mtu -= 8;
1530
+
1531
+ if (mtu < IPV6_MIN_MTU)
1532
+ mtu = IPV6_MIN_MTU;
1533
+ WRITE_ONCE(dev->mtu, mtu);
1534
+ }
14881535 }
14891536 }
14901537
....@@ -1809,6 +1856,7 @@
18091856 static void ip6_tnl_dev_setup(struct net_device *dev)
18101857 {
18111858 dev->netdev_ops = &ip6_tnl_netdev_ops;
1859
+ dev->header_ops = &ip_tunnel_header_ops;
18121860 dev->needs_free_netdev = true;
18131861 dev->priv_destructor = ip6_dev_free;
18141862
....@@ -2199,6 +2247,12 @@
21992247 .priority = 1,
22002248 };
22012249
2250
+static struct xfrm6_tunnel mplsip6_handler __read_mostly = {
2251
+ .handler = mplsip6_rcv,
2252
+ .err_handler = mplsip6_err,
2253
+ .priority = 1,
2254
+};
2255
+
22022256 static void __net_exit ip6_tnl_destroy_tunnels(struct net *net, struct list_head *list)
22032257 {
22042258 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
....@@ -2323,6 +2377,15 @@
23232377 pr_err("%s: can't register ip6ip6\n", __func__);
23242378 goto out_ip6ip6;
23252379 }
2380
+
2381
+ if (ip6_tnl_mpls_supported()) {
2382
+ err = xfrm6_tunnel_register(&mplsip6_handler, AF_MPLS);
2383
+ if (err < 0) {
2384
+ pr_err("%s: can't register mplsip6\n", __func__);
2385
+ goto out_mplsip6;
2386
+ }
2387
+ }
2388
+
23262389 err = rtnl_link_register(&ip6_link_ops);
23272390 if (err < 0)
23282391 goto rtnl_link_failed;
....@@ -2330,6 +2393,9 @@
23302393 return 0;
23312394
23322395 rtnl_link_failed:
2396
+ if (ip6_tnl_mpls_supported())
2397
+ xfrm6_tunnel_deregister(&mplsip6_handler, AF_MPLS);
2398
+out_mplsip6:
23332399 xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6);
23342400 out_ip6ip6:
23352401 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
....@@ -2352,6 +2418,9 @@
23522418 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
23532419 pr_info("%s: can't deregister ip6ip6\n", __func__);
23542420
2421
+ if (ip6_tnl_mpls_supported() &&
2422
+ xfrm6_tunnel_deregister(&mplsip6_handler, AF_MPLS))
2423
+ pr_info("%s: can't deregister mplsip6\n", __func__);
23552424 unregister_pernet_device(&ip6_tnl_net_ops);
23562425 }
23572426