Skip to content

Commit 88bb40b

Browse files
Li Weigregkh
authored andcommitted
ipv4: fix error handling in icmp_protocol.
[ Upstream commit 5b05204 ] Now we handle icmp errors in each transport protocol's err_handler, for icmp protocols, that is ping_err. Since this handler only care of those icmp errors triggered by echo request, errors triggered by echo reply(which sent by kernel) are sliently ignored. So wrap ping_err() with icmp_err() to deal with those icmp errors. Signed-off-by: Li Wei <lw@cn.fujitsu.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e122d3 commit 88bb40b

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎include/net/icmp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct net;
4141

4242
extern void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info);
4343
extern int icmp_rcv(struct sk_buff *skb);
44+
extern void icmp_err(struct sk_buff *, u32 info);
4445
extern int icmp_init(void);
4546
extern void icmp_out_count(struct net *net, unsigned char type);
4647

‎net/ipv4/af_inet.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ static const struct net_offload udp_offload = {
15951595

15961596
static const struct net_protocol icmp_protocol = {
15971597
.handler = icmp_rcv,
1598-
.err_handler = ping_err,
1598+
.err_handler = icmp_err,
15991599
.no_policy = 1,
16001600
.netns_ok = 1,
16011601
};

‎net/ipv4/icmp.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,29 @@ int icmp_rcv(struct sk_buff *skb)
934934
goto drop;
935935
}
936936

937+
void icmp_err(struct sk_buff *skb, u32 info)
938+
{
939+
struct iphdr *iph = (struct iphdr *)skb->data;
940+
struct icmphdr *icmph = (struct icmphdr *)(skb->data+(iph->ihl<<2));
941+
int type = icmp_hdr(skb)->type;
942+
int code = icmp_hdr(skb)->code;
943+
struct net *net = dev_net(skb->dev);
944+
945+
/*
946+
* Use ping_err to handle all icmp errors except those
947+
* triggered by ICMP_ECHOREPLY which sent from kernel.
948+
*/
949+
if (icmph->type != ICMP_ECHOREPLY) {
950+
ping_err(skb, info);
951+
return;
952+
}
953+
954+
if (type == ICMP_DEST_UNREACH && code == ICMP_FRAG_NEEDED)
955+
ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ICMP, 0);
956+
else if (type == ICMP_REDIRECT)
957+
ipv4_redirect(skb, net, 0, 0, IPPROTO_ICMP, 0);
958+
}
959+
937960
/*
938961
* This table is the definition of how we handle ICMP.
939962
*/

0 commit comments

Comments
 (0)