Commit 55be7a9c authored by David S. Miller's avatar David S. Miller

ipv4: Add redirect support to all protocol icmp error handlers.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b42597e2
...@@ -195,6 +195,14 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk, ...@@ -195,6 +195,14 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
} /* else let the usual retransmit timer handle it */ } /* 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 * 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 * 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) ...@@ -259,6 +267,9 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
} }
switch (type) { switch (type) {
case ICMP_REDIRECT:
dccp_do_redirect(skb, sk);
goto out;
case ICMP_SOURCE_QUENCH: case ICMP_SOURCE_QUENCH:
/* Just silently ignore these. */ /* Just silently ignore these. */
goto out; goto out;
......
...@@ -398,17 +398,25 @@ static void ah4_err(struct sk_buff *skb, u32 info) ...@@ -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 ip_auth_hdr *ah = (struct ip_auth_hdr *)(skb->data+(iph->ihl<<2));
struct xfrm_state *x; struct xfrm_state *x;
if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH || switch (icmp_hdr(skb)->type) {
icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) case ICMP_DEST_UNREACH:
if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
return;
case ICMP_REDIRECT:
break;
default:
return; return;
}
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr, x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
ah->spi, IPPROTO_AH, AF_INET); ah->spi, IPPROTO_AH, AF_INET);
if (!x) if (!x)
return; return;
pr_debug("pmtu discovery on SA AH/%08x/%08x\n",
ntohl(ah->spi), ntohl(iph->daddr)); if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0); 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); xfrm_state_put(x);
} }
......
...@@ -484,17 +484,25 @@ static void esp4_err(struct sk_buff *skb, u32 info) ...@@ -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 ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data+(iph->ihl<<2));
struct xfrm_state *x; struct xfrm_state *x;
if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH || switch (icmp_hdr(skb)->type) {
icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) case ICMP_DEST_UNREACH:
if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
return;
case ICMP_REDIRECT:
break;
default:
return; return;
}
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr, x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
esph->spi, IPPROTO_ESP, AF_INET); esph->spi, IPPROTO_ESP, AF_INET);
if (!x) if (!x)
return; return;
NETDEBUG(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n",
ntohl(esph->spi), ntohl(iph->daddr)); if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0); 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); xfrm_state_put(x);
} }
......
...@@ -528,6 +528,9 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -528,6 +528,9 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
if (code != ICMP_EXC_TTL) if (code != ICMP_EXC_TTL)
return; return;
break; break;
case ICMP_REDIRECT:
break;
} }
rcu_read_lock(); rcu_read_lock();
...@@ -543,7 +546,11 @@ static void ipgre_err(struct sk_buff *skb, u32 info) ...@@ -543,7 +546,11 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
t->parms.link, 0, IPPROTO_GRE, 0); t->parms.link, 0, IPPROTO_GRE, 0);
goto out; 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 || if (t->parms.iph.daddr == 0 ||
ipv4_is_multicast(t->parms.iph.daddr)) ipv4_is_multicast(t->parms.iph.daddr))
goto out; goto out;
......
...@@ -31,18 +31,26 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info) ...@@ -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 ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
struct xfrm_state *x; struct xfrm_state *x;
if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH || switch (icmp_hdr(skb)->type) {
icmp_hdr(skb)->code != ICMP_FRAG_NEEDED) case ICMP_DEST_UNREACH:
if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
return;
case ICMP_REDIRECT:
break;
default:
return; return;
}
spi = htonl(ntohs(ipch->cpi)); spi = htonl(ntohs(ipch->cpi));
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr, x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
spi, IPPROTO_COMP, AF_INET); spi, IPPROTO_COMP, AF_INET);
if (!x) if (!x)
return; return;
NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%pI4\n",
spi, &iph->daddr); if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0); 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); xfrm_state_put(x);
} }
......
...@@ -360,6 +360,8 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -360,6 +360,8 @@ static int ipip_err(struct sk_buff *skb, u32 info)
if (code != ICMP_EXC_TTL) if (code != ICMP_EXC_TTL)
return 0; return 0;
break; break;
case ICMP_REDIRECT:
break;
} }
err = -ENOENT; err = -ENOENT;
...@@ -376,6 +378,13 @@ static int ipip_err(struct sk_buff *skb, u32 info) ...@@ -376,6 +378,13 @@ static int ipip_err(struct sk_buff *skb, u32 info)
goto out; 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) if (t->parms.iph.daddr == 0)
goto out; goto out;
......
...@@ -387,6 +387,7 @@ void ping_err(struct sk_buff *skb, u32 info) ...@@ -387,6 +387,7 @@ void ping_err(struct sk_buff *skb, u32 info)
break; break;
case ICMP_REDIRECT: case ICMP_REDIRECT:
/* See ICMP_SOURCE_QUENCH */ /* See ICMP_SOURCE_QUENCH */
ipv4_sk_redirect(skb, sk);
err = EREMOTEIO; err = EREMOTEIO;
break; break;
} }
......
...@@ -218,6 +218,8 @@ static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info) ...@@ -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) if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
ipv4_sk_update_pmtu(skb, sk, info); ipv4_sk_update_pmtu(skb, sk, info);
else if (type == ICMP_REDIRECT)
ipv4_sk_redirect(skb, sk);
/* Report error on raw socket, if: /* Report error on raw socket, if:
1. User requested ip_recverr. 1. User requested ip_recverr.
......
...@@ -321,6 +321,14 @@ static void do_pmtu_discovery(struct sock *sk, const struct iphdr *iph, u32 mtu) ...@@ -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 */ } /* 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 * This routine is called by the ICMP module when it gets some
* sort of error condition. If err < 0 then the socket should * 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) ...@@ -394,6 +402,9 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
} }
switch (type) { switch (type) {
case ICMP_REDIRECT:
do_redirect(icmp_skb, sk);
goto out;
case ICMP_SOURCE_QUENCH: case ICMP_SOURCE_QUENCH:
/* Just silently ignore these. */ /* Just silently ignore these. */
goto out; goto out;
......
...@@ -630,6 +630,9 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) ...@@ -630,6 +630,9 @@ void __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
err = icmp_err_convert[code].errno; err = icmp_err_convert[code].errno;
} }
break; break;
case ICMP_REDIRECT:
ipv4_sk_redirect(skb, sk);
break;
} }
/* /*
......
...@@ -202,6 +202,15 @@ static void xfrm4_update_pmtu(struct dst_entry *dst, u32 mtu) ...@@ -202,6 +202,15 @@ static void xfrm4_update_pmtu(struct dst_entry *dst, u32 mtu)
path->ops->update_pmtu(path, 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) static void xfrm4_dst_destroy(struct dst_entry *dst)
{ {
struct xfrm_dst *xdst = (struct xfrm_dst *)dst; struct xfrm_dst *xdst = (struct xfrm_dst *)dst;
...@@ -225,6 +234,7 @@ static struct dst_ops xfrm4_dst_ops = { ...@@ -225,6 +234,7 @@ static struct dst_ops xfrm4_dst_ops = {
.protocol = cpu_to_be16(ETH_P_IP), .protocol = cpu_to_be16(ETH_P_IP),
.gc = xfrm4_garbage_collect, .gc = xfrm4_garbage_collect,
.update_pmtu = xfrm4_update_pmtu, .update_pmtu = xfrm4_update_pmtu,
.redirect = xfrm4_redirect,
.cow_metrics = dst_cow_metrics_generic, .cow_metrics = dst_cow_metrics_generic,
.destroy = xfrm4_dst_destroy, .destroy = xfrm4_dst_destroy,
.ifdown = xfrm4_dst_ifdown, .ifdown = xfrm4_dst_ifdown,
......
...@@ -423,6 +423,18 @@ void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc, ...@@ -423,6 +423,18 @@ void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
sctp_retransmit(&asoc->outqueue, t, SCTP_RTXR_PMTUD); 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 * SCTP Implementer's Guide, 2.37 ICMP handling procedures
* *
...@@ -628,6 +640,10 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info) ...@@ -628,6 +640,10 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
err = EHOSTUNREACH; err = EHOSTUNREACH;
break; break;
case ICMP_REDIRECT:
sctp_icmp_redirect(sk, transport, skb);
err = 0;
break;
default: default:
goto out_unlock; goto out_unlock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment