icmp: remove duplicate code
authorMatteo Croce <mcroce@redhat.com>
Sat, 2 Nov 2019 00:12:04 +0000 (01:12 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 5 Nov 2019 22:03:11 +0000 (14:03 -0800)
The same code which recognizes ICMP error packets is duplicated several
times. Use the icmp_is_err() and icmpv6_is_err() helpers instead, which
do the same thing.

ip_multipath_l3_keys() and tcf_nat_act() didn't check for all the error types,
assume that they should instead.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/netfilter/nf_socket_ipv4.c
net/ipv4/route.c
net/ipv6/route.c
net/netfilter/nf_conntrack_proto_icmp.c
net/netfilter/xt_HMARK.c
net/sched/act_nat.c

index 36a28d46149c8a359128fd7804aa2c7c3e72b08f..c94445b44d8cf07f394d32e54b60bb96524988b1 100644 (file)
@@ -31,16 +31,8 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
        if (icmph == NULL)
                return 1;
 
-       switch (icmph->type) {
-       case ICMP_DEST_UNREACH:
-       case ICMP_SOURCE_QUENCH:
-       case ICMP_REDIRECT:
-       case ICMP_TIME_EXCEEDED:
-       case ICMP_PARAMETERPROB:
-               break;
-       default:
+       if (!icmp_is_err(icmph->type))
                return 1;
-       }
 
        inside_iph = skb_header_pointer(skb, outside_hdrlen +
                                        sizeof(struct icmphdr),
index 621f83434b2494784ec2b92824a2743be8817e21..dcc4fa10138d499c366428a0fc8d00c6624cca1e 100644 (file)
@@ -1894,10 +1894,7 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb,
        if (!icmph)
                goto out;
 
-       if (icmph->type != ICMP_DEST_UNREACH &&
-           icmph->type != ICMP_REDIRECT &&
-           icmph->type != ICMP_TIME_EXCEEDED &&
-           icmph->type != ICMP_PARAMETERPROB)
+       if (!icmp_is_err(icmph->type))
                goto out;
 
        inner_iph = skb_header_pointer(skb,
index c7a2022e64eb9de9e4300f0311dbff66281ec0a8..bf2dac4629423c6828932df5cdc7676d818a293a 100644 (file)
@@ -2291,10 +2291,7 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb,
        if (!icmph)
                goto out;
 
-       if (icmph->icmp6_type != ICMPV6_DEST_UNREACH &&
-           icmph->icmp6_type != ICMPV6_PKT_TOOBIG &&
-           icmph->icmp6_type != ICMPV6_TIME_EXCEED &&
-           icmph->icmp6_type != ICMPV6_PARAMPROB)
+       if (!icmpv6_is_err(icmph->icmp6_type))
                goto out;
 
        inner_iph = skb_header_pointer(skb,
index 097deba7441ae672dba32a55dd6ee035cb0bab53..c2e3dff773bc76fcb4c647960b5f2471b49de8ed 100644 (file)
@@ -235,11 +235,7 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
        }
 
        /* Need to track icmp error message? */
-       if (icmph->type != ICMP_DEST_UNREACH &&
-           icmph->type != ICMP_SOURCE_QUENCH &&
-           icmph->type != ICMP_TIME_EXCEEDED &&
-           icmph->type != ICMP_PARAMETERPROB &&
-           icmph->type != ICMP_REDIRECT)
+       if (!icmp_is_err(icmph->type))
                return NF_ACCEPT;
 
        memset(&outer_daddr, 0, sizeof(outer_daddr));
index be7798a505463f7c6308791dd486f011397ffe4a..713fb38541dfcf0df7da92f56b81f376fef0c175 100644 (file)
@@ -239,11 +239,7 @@ static int get_inner_hdr(const struct sk_buff *skb, int iphsz, int *nhoff)
                return 0;
 
        /* Error message? */
-       if (icmph->type != ICMP_DEST_UNREACH &&
-           icmph->type != ICMP_SOURCE_QUENCH &&
-           icmph->type != ICMP_TIME_EXCEEDED &&
-           icmph->type != ICMP_PARAMETERPROB &&
-           icmph->type != ICMP_REDIRECT)
+       if (!icmp_is_err(icmph->type))
                return 0;
 
        *nhoff += iphsz + sizeof(_ih);
index 88a1b79a1848f84a057269c1f2765d2e96a7a36e..855a6fa16a621d8f49115f26dbc0617f1248ad3e 100644 (file)
@@ -206,9 +206,7 @@ static int tcf_nat_act(struct sk_buff *skb, const struct tc_action *a,
 
                icmph = (void *)(skb_network_header(skb) + ihl);
 
-               if ((icmph->type != ICMP_DEST_UNREACH) &&
-                   (icmph->type != ICMP_TIME_EXCEEDED) &&
-                   (icmph->type != ICMP_PARAMETERPROB))
+               if (!icmp_is_err(icmph->type))
                        break;
 
                if (!pskb_may_pull(skb, ihl + sizeof(*icmph) + sizeof(*iph) +