Commit fd4b3558 authored by David S. Miller's avatar David S. Miller

Merge branch 'icmp-move-duplicate-code-in-helper-functions'

Matteo Croce says:

====================
icmp: move duplicate code in helper functions

Remove some duplicate code by moving it in two helper functions.
First patch adds the helpers, the second one uses it.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b8fed591 54074f1d
...@@ -20,4 +20,19 @@ static inline struct icmphdr *icmp_hdr(const struct sk_buff *skb) ...@@ -20,4 +20,19 @@ static inline struct icmphdr *icmp_hdr(const struct sk_buff *skb)
{ {
return (struct icmphdr *)skb_transport_header(skb); return (struct icmphdr *)skb_transport_header(skb);
} }
static inline bool icmp_is_err(int type)
{
switch (type) {
case ICMP_DEST_UNREACH:
case ICMP_SOURCE_QUENCH:
case ICMP_REDIRECT:
case ICMP_TIME_EXCEEDED:
case ICMP_PARAMETERPROB:
return true;
}
return false;
}
#endif /* _LINUX_ICMP_H */ #endif /* _LINUX_ICMP_H */
...@@ -46,4 +46,18 @@ extern void icmpv6_flow_init(struct sock *sk, ...@@ -46,4 +46,18 @@ extern void icmpv6_flow_init(struct sock *sk,
const struct in6_addr *saddr, const struct in6_addr *saddr,
const struct in6_addr *daddr, const struct in6_addr *daddr,
int oif); int oif);
static inline bool icmpv6_is_err(int type)
{
switch (type) {
case ICMPV6_DEST_UNREACH:
case ICMPV6_PKT_TOOBIG:
case ICMPV6_TIME_EXCEED:
case ICMPV6_PARAMPROB:
return true;
}
return false;
}
#endif #endif
...@@ -31,16 +31,8 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol, ...@@ -31,16 +31,8 @@ extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
if (icmph == NULL) if (icmph == NULL)
return 1; return 1;
switch (icmph->type) { if (!icmp_is_err(icmph->type))
case ICMP_DEST_UNREACH:
case ICMP_SOURCE_QUENCH:
case ICMP_REDIRECT:
case ICMP_TIME_EXCEEDED:
case ICMP_PARAMETERPROB:
break;
default:
return 1; return 1;
}
inside_iph = skb_header_pointer(skb, outside_hdrlen + inside_iph = skb_header_pointer(skb, outside_hdrlen +
sizeof(struct icmphdr), sizeof(struct icmphdr),
......
...@@ -1894,10 +1894,7 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb, ...@@ -1894,10 +1894,7 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb,
if (!icmph) if (!icmph)
goto out; goto out;
if (icmph->type != ICMP_DEST_UNREACH && if (!icmp_is_err(icmph->type))
icmph->type != ICMP_REDIRECT &&
icmph->type != ICMP_TIME_EXCEEDED &&
icmph->type != ICMP_PARAMETERPROB)
goto out; goto out;
inner_iph = skb_header_pointer(skb, inner_iph = skb_header_pointer(skb,
......
...@@ -2291,10 +2291,7 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb, ...@@ -2291,10 +2291,7 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb,
if (!icmph) if (!icmph)
goto out; goto out;
if (icmph->icmp6_type != ICMPV6_DEST_UNREACH && if (!icmpv6_is_err(icmph->icmp6_type))
icmph->icmp6_type != ICMPV6_PKT_TOOBIG &&
icmph->icmp6_type != ICMPV6_TIME_EXCEED &&
icmph->icmp6_type != ICMPV6_PARAMPROB)
goto out; goto out;
inner_iph = skb_header_pointer(skb, inner_iph = skb_header_pointer(skb,
......
...@@ -235,11 +235,7 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl, ...@@ -235,11 +235,7 @@ int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
} }
/* Need to track icmp error message? */ /* Need to track icmp error message? */
if (icmph->type != ICMP_DEST_UNREACH && if (!icmp_is_err(icmph->type))
icmph->type != ICMP_SOURCE_QUENCH &&
icmph->type != ICMP_TIME_EXCEEDED &&
icmph->type != ICMP_PARAMETERPROB &&
icmph->type != ICMP_REDIRECT)
return NF_ACCEPT; return NF_ACCEPT;
memset(&outer_daddr, 0, sizeof(outer_daddr)); memset(&outer_daddr, 0, sizeof(outer_daddr));
......
...@@ -239,11 +239,7 @@ static int get_inner_hdr(const struct sk_buff *skb, int iphsz, int *nhoff) ...@@ -239,11 +239,7 @@ static int get_inner_hdr(const struct sk_buff *skb, int iphsz, int *nhoff)
return 0; return 0;
/* Error message? */ /* Error message? */
if (icmph->type != ICMP_DEST_UNREACH && if (!icmp_is_err(icmph->type))
icmph->type != ICMP_SOURCE_QUENCH &&
icmph->type != ICMP_TIME_EXCEEDED &&
icmph->type != ICMP_PARAMETERPROB &&
icmph->type != ICMP_REDIRECT)
return 0; return 0;
*nhoff += iphsz + sizeof(_ih); *nhoff += iphsz + sizeof(_ih);
......
...@@ -206,9 +206,7 @@ static int tcf_nat_act(struct sk_buff *skb, const struct tc_action *a, ...@@ -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); icmph = (void *)(skb_network_header(skb) + ihl);
if ((icmph->type != ICMP_DEST_UNREACH) && if (!icmp_is_err(icmph->type))
(icmph->type != ICMP_TIME_EXCEEDED) &&
(icmph->type != ICMP_PARAMETERPROB))
break; break;
if (!pskb_may_pull(skb, ihl + sizeof(*icmph) + sizeof(*iph) + if (!pskb_may_pull(skb, ihl + sizeof(*icmph) + sizeof(*iph) +
......
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