Skip to content

Commit ede372d

Browse files
committed
Merge branch 'net-improve-the-process-of-redirect-and-toobig-for-ipv6-tunnels'
Xin Long says: ==================== net: improve the process of redirect and toobig for ipv6 tunnels Now let's say there are 3 kinds of icmp packets to process for tunnels, toobig(needfrag), redirect, others, their process should be: - toobig(needfrag) update the lower dst's pmtu by route cache, also update sk dst's pmtu if possible, or it will be fine if sk dst pmtu will get updated on tx path. - redirect update the lower dst's gw by route cache and return, no need to send this redirect packet to user sk. - others send the packet to user's sk, or it will also be fine to use err_count to count it and report fail link on tx path. All ipv4 tunnels basically follow this while some of ipv6 tunnels are doing in different ways, like ip6gre and ip6_tunnels update tnl dev's mtu instead of updating lower dst pmtu, no redirect process on their err_handlers, which doesn't make any sense and even causes performance problems. This patchset is to improve the process of redirect and toobig for ip6gre ip4ip6, ip6ip6 tunnels, as in ipv4 tunnels. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 0d728b8 + 77552cf commit ede372d

2 files changed

Lines changed: 34 additions & 50 deletions

File tree

‎net/ipv6/ip6_gre.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static void ip6gre_tunnel_uninit(struct net_device *dev)
369369
static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
370370
u8 type, u8 code, int offset, __be32 info)
371371
{
372+
struct net *net = dev_net(skb->dev);
372373
const struct gre_base_hdr *greh;
373374
const struct ipv6hdr *ipv6h;
374375
int grehlen = sizeof(*greh);
@@ -402,9 +403,8 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
402403
return;
403404

404405
switch (type) {
405-
__u32 teli;
406406
struct ipv6_tlv_tnl_enc_lim *tel;
407-
__u32 mtu;
407+
__u32 teli;
408408
case ICMPV6_DEST_UNREACH:
409409
net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
410410
t->parms.name);
@@ -435,12 +435,11 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
435435
}
436436
return;
437437
case ICMPV6_PKT_TOOBIG:
438-
mtu = be32_to_cpu(info) - offset - t->tun_hlen;
439-
if (t->dev->type == ARPHRD_ETHER)
440-
mtu -= ETH_HLEN;
441-
if (mtu < IPV6_MIN_MTU)
442-
mtu = IPV6_MIN_MTU;
443-
t->dev->mtu = mtu;
438+
ip6_update_pmtu(skb, net, info, 0, 0, sock_net_uid(net, NULL));
439+
return;
440+
case NDISC_REDIRECT:
441+
ip6_redirect(skb, net, skb->dev->ifindex, 0,
442+
sock_net_uid(net, NULL));
444443
return;
445444
}
446445

@@ -503,7 +502,6 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
503502
__u32 *pmtu, __be16 proto)
504503
{
505504
struct ip6_tnl *tunnel = netdev_priv(dev);
506-
struct dst_entry *dst = skb_dst(skb);
507505
__be16 protocol;
508506

509507
if (dev->type == ARPHRD_ETHER)
@@ -522,10 +520,6 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
522520
gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
523521
protocol, tunnel->parms.o_key, htonl(tunnel->o_seqno));
524522

525-
/* TooBig packet may have updated dst->dev's mtu */
526-
if (dst && dst_mtu(dst) > dst->dev->mtu)
527-
dst->ops->update_pmtu(dst, NULL, skb, dst->dev->mtu);
528-
529523
return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
530524
NEXTHDR_GRE);
531525
}

‎net/ipv6/ip6_tunnel.c‎

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,16 @@ static int
471471
ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
472472
u8 *type, u8 *code, int *msg, __u32 *info, int offset)
473473
{
474-
const struct ipv6hdr *ipv6h = (const struct ipv6hdr *) skb->data;
475-
struct ip6_tnl *t;
476-
int rel_msg = 0;
474+
const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data;
475+
struct net *net = dev_net(skb->dev);
477476
u8 rel_type = ICMPV6_DEST_UNREACH;
478477
u8 rel_code = ICMPV6_ADDR_UNREACH;
479-
u8 tproto;
480478
__u32 rel_info = 0;
481-
__u16 len;
479+
struct ip6_tnl *t;
482480
int err = -ENOENT;
481+
int rel_msg = 0;
482+
u8 tproto;
483+
__u16 len;
483484

484485
/* If the packet doesn't contain the original IPv6 header we are
485486
in trouble since we might need the source address for further
@@ -497,9 +498,8 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
497498
err = 0;
498499

499500
switch (*type) {
500-
__u32 teli;
501501
struct ipv6_tlv_tnl_enc_lim *tel;
502-
__u32 mtu;
502+
__u32 mtu, teli;
503503
case ICMPV6_DEST_UNREACH:
504504
net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
505505
t->parms.name);
@@ -530,11 +530,11 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
530530
}
531531
break;
532532
case ICMPV6_PKT_TOOBIG:
533+
ip6_update_pmtu(skb, net, htonl(*info), 0, 0,
534+
sock_net_uid(net, NULL));
533535
mtu = *info - offset;
534536
if (mtu < IPV6_MIN_MTU)
535537
mtu = IPV6_MIN_MTU;
536-
t->dev->mtu = mtu;
537-
538538
len = sizeof(*ipv6h) + ntohs(ipv6h->payload_len);
539539
if (len > mtu) {
540540
rel_type = ICMPV6_PKT_TOOBIG;
@@ -543,6 +543,10 @@ ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
543543
rel_msg = 1;
544544
}
545545
break;
546+
case NDISC_REDIRECT:
547+
ip6_redirect(skb, net, skb->dev->ifindex, 0,
548+
sock_net_uid(net, NULL));
549+
break;
546550
}
547551

548552
*type = rel_type;
@@ -559,13 +563,12 @@ static int
559563
ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
560564
u8 type, u8 code, int offset, __be32 info)
561565
{
562-
int rel_msg = 0;
563-
u8 rel_type = type;
564-
u8 rel_code = code;
565566
__u32 rel_info = ntohl(info);
566-
int err;
567-
struct sk_buff *skb2;
568567
const struct iphdr *eiph;
568+
struct sk_buff *skb2;
569+
int err, rel_msg = 0;
570+
u8 rel_type = type;
571+
u8 rel_code = code;
569572
struct rtable *rt;
570573
struct flowi4 fl4;
571574

@@ -590,10 +593,6 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
590593
rel_type = ICMP_DEST_UNREACH;
591594
rel_code = ICMP_FRAG_NEEDED;
592595
break;
593-
case NDISC_REDIRECT:
594-
rel_type = ICMP_REDIRECT;
595-
rel_code = ICMP_REDIR_HOST;
596-
/* fall through */
597596
default:
598597
return 0;
599598
}
@@ -612,33 +611,26 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
612611
eiph = ip_hdr(skb2);
613612

614613
/* Try to guess incoming interface */
615-
rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL,
616-
eiph->saddr, 0,
617-
0, 0,
618-
IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
614+
rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL, eiph->saddr,
615+
0, 0, 0, IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
619616
if (IS_ERR(rt))
620617
goto out;
621618

622619
skb2->dev = rt->dst.dev;
620+
ip_rt_put(rt);
623621

624622
/* route "incoming" packet */
625623
if (rt->rt_flags & RTCF_LOCAL) {
626-
ip_rt_put(rt);
627-
rt = NULL;
628624
rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL,
629-
eiph->daddr, eiph->saddr,
630-
0, 0,
631-
IPPROTO_IPIP,
632-
RT_TOS(eiph->tos), 0);
633-
if (IS_ERR(rt) ||
634-
rt->dst.dev->type != ARPHRD_TUNNEL) {
625+
eiph->daddr, eiph->saddr, 0, 0,
626+
IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
627+
if (IS_ERR(rt) || rt->dst.dev->type != ARPHRD_TUNNEL) {
635628
if (!IS_ERR(rt))
636629
ip_rt_put(rt);
637630
goto out;
638631
}
639632
skb_dst_set(skb2, &rt->dst);
640633
} else {
641-
ip_rt_put(rt);
642634
if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos,
643635
skb2->dev) ||
644636
skb_dst(skb2)->dev->type != ARPHRD_TUNNEL)
@@ -650,10 +642,9 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
650642
if (rel_info > dst_mtu(skb_dst(skb2)))
651643
goto out;
652644

653-
skb_dst(skb2)->ops->update_pmtu(skb_dst(skb2), NULL, skb2, rel_info);
645+
skb_dst(skb2)->ops->update_pmtu(skb_dst(skb2), NULL, skb2,
646+
rel_info);
654647
}
655-
if (rel_type == ICMP_REDIRECT)
656-
skb_dst(skb2)->ops->redirect(skb_dst(skb2), NULL, skb2);
657648

658649
icmp_send(skb2, rel_type, rel_code, htonl(rel_info));
659650

@@ -666,11 +657,10 @@ static int
666657
ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
667658
u8 type, u8 code, int offset, __be32 info)
668659
{
669-
int rel_msg = 0;
660+
__u32 rel_info = ntohl(info);
661+
int err, rel_msg = 0;
670662
u8 rel_type = type;
671663
u8 rel_code = code;
672-
__u32 rel_info = ntohl(info);
673-
int err;
674664

675665
err = ip6_tnl_err(skb, IPPROTO_IPV6, opt, &rel_type, &rel_code,
676666
&rel_msg, &rel_info, offset);

0 commit comments

Comments
 (0)