ipv4: Add redirect support to all protocol icmp error handlers.
authorDavid S. Miller <davem@davemloft.net>
Thu, 12 Jul 2012 04:27:49 +0000 (21:27 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 12 Jul 2012 04:27:49 +0000 (21:27 -0700)
Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
net/dccp/ipv4.c
net/ipv4/ah4.c
net/ipv4/esp4.c
net/ipv4/ip_gre.c
net/ipv4/ipcomp.c
net/ipv4/ipip.c
net/ipv4/ping.c
net/ipv4/raw.c
net/ipv4/tcp_ipv4.c
net/ipv4/udp.c
net/ipv4/xfrm4_policy.c
net/sctp/input.c

index 3eb76b5f221acdfa182d0526ccbe713d35bf7545..8f41a31908584b9f935dba30fab39d465188aa5e 100644 (file)
@@ -195,6 +195,14 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
        } /* else let the usual retransmit timer handle it */
 }
 
+static void dccp_do_redirect(struct sk_buff *skb, struct sock *sk)
+{
+       struct dst_entry *dst = __sk_dst_check(sk, 0);
+
+       if (dst && dst->ops->redirect)
+               dst->ops->redirect(dst, skb);
+}
+
 /*
  * This routine is called by the ICMP module when it gets some sort of error
  * condition. If err < 0 then the socket should be closed and the error
@@ -259,6 +267,9 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
        }
 
        switch (type) {
+       case ICMP_REDIRECT:
+               dccp_do_redirect(skb, sk);
+               goto out;
        case ICMP_SOURCE_QUENCH:
                /* Just silently ignore these. */
                goto out;
index 916d5ecaf6c698fcce1c71006ac3c2edf187ff0f..a0d8392491c3c3e947876c943457227e4ed4ad92 100644 (file)
@@ -398,17 +398,25 @@ static void ah4_err(struct sk_buff *skb, u32 info)
        struct ip_auth_hdr *ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
        struct xfrm_state *x;
 
-       if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
-           icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+       switch (icmp_hdr(skb)->type) {
+       case ICMP_DEST_UNREACH:
+               if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+                       return;
+       case ICMP_REDIRECT:
+               break;
+       default:
                return;
+       }
 
        x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
                              ah->spi, IPPROTO_AH, AF_INET);
        if (!x)
                return;
-       pr_debug("pmtu discovery on SA AH/%08x/%08x\n",
-                ntohl(ah->spi), ntohl(iph->daddr));
-       ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
+
+       if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
+               ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
+       else
+               ipv4_redirect(skb, net, 0, 0, IPPROTO_AH, 0);
        xfrm_state_put(x);
 }
 
index 7b95b49a36cea37d2a18720b7e13c10fadb4506d..b61e9deb7c7ecc9cae92ab0365b871a773627cc4 100644 (file)
@@ -484,17 +484,25 @@ static void esp4_err(struct sk_buff *skb, u32 info)
        struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data+(iph->ihl<<2));
        struct xfrm_state *x;
 
-       if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
-           icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+       switch (icmp_hdr(skb)->type) {
+       case ICMP_DEST_UNREACH:
+               if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+                       return;
+       case ICMP_REDIRECT:
+               break;
+       default:
                return;
+       }
 
        x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
                              esph->spi, IPPROTO_ESP, AF_INET);
        if (!x)
                return;
-       NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n",
-                ntohl(esph->spi), ntohl(iph->daddr));
-       ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
+
+       if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
+               ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
+       else
+               ipv4_redirect(skb, net, 0, 0, IPPROTO_ESP, 0);
        xfrm_state_put(x);
 }
 
index 594cec35ac4df198b4afb956104c1e5120c8c0ed..0c3123566d76ddef7269367d8df9e5c62d2ae54e 100644 (file)
@@ -528,6 +528,9 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
                if (code != ICMP_EXC_TTL)
                        return;
                break;
+
+       case ICMP_REDIRECT:
+               break;
        }
 
        rcu_read_lock();
@@ -543,7 +546,11 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
                                 t->parms.link, 0, IPPROTO_GRE, 0);
                goto out;
        }
-
+       if (type == ICMP_REDIRECT) {
+               ipv4_redirect(skb, dev_net(skb->dev), t->parms.link, 0,
+                             IPPROTO_GRE, 0);
+               goto out;
+       }
        if (t->parms.iph.daddr == 0 ||
            ipv4_is_multicast(t->parms.iph.daddr))
                goto out;
index b91375482d844c9f9cfa0011faef541462c7349f..d3ab47e19a896277161c2bf1b87706c20ebd73be 100644 (file)
@@ -31,18 +31,26 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
        struct ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
        struct xfrm_state *x;
 
-       if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
-           icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+       switch (icmp_hdr(skb)->type) {
+       case ICMP_DEST_UNREACH:
+               if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
+                       return;
+       case ICMP_REDIRECT:
+               break;
+       default:
                return;
+       }
 
        spi = htonl(ntohs(ipch->cpi));
        x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
                              spi, IPPROTO_COMP, AF_INET);
        if (!x)
                return;
-       NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%pI4\n",
-                spi, &iph->daddr);
-       ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
+
+       if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
+               ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
+       else
+               ipv4_redirect(skb, net, 0, 0, IPPROTO_COMP, 0);
        xfrm_state_put(x);
 }
 
index 715338a1b205a07195e31878f50cdbef31864c86..c2d0e6d8baafb43984873c982a7c2c70f537551a 100644 (file)
@@ -360,6 +360,8 @@ static int ipip_err(struct sk_buff *skb, u32 info)
                if (code != ICMP_EXC_TTL)
                        return 0;
                break;
+       case ICMP_REDIRECT:
+               break;
        }
 
        err = -ENOENT;
@@ -376,6 +378,13 @@ static int ipip_err(struct sk_buff *skb, u32 info)
                goto out;
        }
 
+       if (type == ICMP_REDIRECT) {
+               ipv4_redirect(skb, dev_net(skb->dev), t->dev->ifindex, 0,
+                             IPPROTO_IPIP, 0);
+               err = 0;
+               goto out;
+       }
+
        if (t->parms.iph.daddr == 0)
                goto out;
 
index 340fcf29a966399c596dac530f27fb1fb3651974..6232d476f37e952add50d1cbec69c316b879a27a 100644 (file)
@@ -387,6 +387,7 @@ void ping_err(struct sk_buff *skb, u32 info)
                break;
        case ICMP_REDIRECT:
                /* See ICMP_SOURCE_QUENCH */
+               ipv4_sk_redirect(skb, sk);
                err = EREMOTEIO;
                break;
        }
index 659ddfb109477112fd1216e82167ac2a22793fd3..ff0f071969ea77dbdb6797584765e32bc958203f 100644 (file)
@@ -218,6 +218,8 @@ static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info)
 
        if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
                ipv4_sk_update_pmtu(skb, sk, info);
+       else if (type == ICMP_REDIRECT)
+               ipv4_sk_redirect(skb, sk);
 
        /* Report error on raw socket, if:
           1. User requested ip_recverr.
index 01545a3fc0f25e38b1f1ad130246211179a27eb3..087a8488843f3f6cc70a43c2fb2721474d6a36f6 100644 (file)
@@ -321,6 +321,14 @@ static void do_pmtu_discovery(struct sock *sk, const struct iphdr *iph, u32 mtu)
        } /* else let the usual retransmit timer handle it */
 }
 
+static void do_redirect(struct sk_buff *skb, struct sock *sk)
+{
+       struct dst_entry *dst = __sk_dst_check(sk, 0);
+
+       if (dst && dst->ops->redirect)
+               dst->ops->redirect(dst, skb);
+}
+
 /*
  * This routine is called by the ICMP module when it gets some
  * sort of error condition.  If err < 0 then the socket should
@@ -394,6 +402,9 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
        }
 
        switch (type) {
+       case ICMP_REDIRECT:
+               do_redirect(icmp_skb, sk);
+               goto out;
        case ICMP_SOURCE_QUENCH:
                /* Just silently ignore these. */
                goto out;
index ee37d47d472e20e8fa0e75655b8611e8656fea1d..b4c3582a991f94db7f6047d5b514b062ccf7e43d 100644 (file)
@@ -630,6 +630,9 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
                        err = icmp_err_convert[code].errno;
                }
                break;
+       case ICMP_REDIRECT:
+               ipv4_sk_redirect(skb, sk);
+               break;
        }
 
        /*
index 87d3fcc302d402c469b0332dfc57de6dfec38843..258ebd7b268b3f2207a812fb49b094e02fb5fde8 100644 (file)
@@ -202,6 +202,15 @@ static void xfrm4_update_pmtu(struct dst_entry *dst, u32 mtu)
        path->ops->update_pmtu(path, mtu);
 }
 
+static void xfrm4_redirect(struct dst_entry *dst, struct sk_buff *skb)
+{
+       struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
+       struct dst_entry *path = xdst->route;
+
+       if (path->ops->redirect)
+               path->ops->redirect(path, skb);
+}
+
 static void xfrm4_dst_destroy(struct dst_entry *dst)
 {
        struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
@@ -225,6 +234,7 @@ static struct dst_ops xfrm4_dst_ops = {
        .protocol =             cpu_to_be16(ETH_P_IP),
        .gc =                   xfrm4_garbage_collect,
        .update_pmtu =          xfrm4_update_pmtu,
+       .redirect =             xfrm4_redirect,
        .cow_metrics =          dst_cow_metrics_generic,
        .destroy =              xfrm4_dst_destroy,
        .ifdown =               xfrm4_dst_ifdown,
index 80564fe03024634dc479280a8fe8d60ea643e1cc..9fb4247f9a99830e67fc6722301e7f040ac19a6b 100644 (file)
@@ -423,6 +423,18 @@ void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
        sctp_retransmit(&asoc->outqueue, t, SCTP_RTXR_PMTUD);
 }
 
+static void sctp_icmp_redirect(struct sock *sk, struct sctp_transport *t,
+                              struct sk_buff *skb)
+{
+       struct dst_entry *dst;
+
+       if (!t)
+               return;
+       dst = sctp_transport_dst_check(t);
+       if (dst && dst->ops->redirect)
+               dst->ops->redirect(dst, skb);
+}
+
 /*
  * SCTP Implementer's Guide, 2.37 ICMP handling procedures
  *
@@ -628,6 +640,10 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
 
                err = EHOSTUNREACH;
                break;
+       case ICMP_REDIRECT:
+               sctp_icmp_redirect(sk, transport, skb);
+               err = 0;
+               break;
        default:
                goto out_unlock;
        }