Skip to content

Commit

Permalink
flow_dissector: skip the ICMP dissector for non ICMP packets
Browse files Browse the repository at this point in the history
FLOW_DISSECTOR_KEY_ICMP is checked for every packet, not only ICMP ones.
Even if the test overhead is probably negligible, move the
ICMP dissector code under the big 'switch(ip_proto)' so it gets called
only for ICMP packets.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Matteo Croce authored and David S. Miller committed Oct 31, 2019
1 parent 98298e6 commit 3b336d6
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions net/core/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,25 @@ __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
}
EXPORT_SYMBOL(__skb_flow_get_ports);

/* If FLOW_DISSECTOR_KEY_ICMP is set, get the Type and Code from an ICMP packet
* using skb_flow_get_be16().
*/
static void __skb_flow_dissect_icmp(const struct sk_buff *skb,
struct flow_dissector *flow_dissector,
void *target_container,
void *data, int thoff, int hlen)
{
struct flow_dissector_key_icmp *key_icmp;

if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ICMP))
return;

key_icmp = skb_flow_dissector_target(flow_dissector,
FLOW_DISSECTOR_KEY_ICMP,
target_container);
key_icmp->icmp = skb_flow_get_be16(skb, thoff, data, hlen);
}

void skb_flow_dissect_meta(const struct sk_buff *skb,
struct flow_dissector *flow_dissector,
void *target_container)
Expand Down Expand Up @@ -884,7 +903,6 @@ bool __skb_flow_dissect(const struct net *net,
struct flow_dissector_key_basic *key_basic;
struct flow_dissector_key_addrs *key_addrs;
struct flow_dissector_key_ports *key_ports;
struct flow_dissector_key_icmp *key_icmp;
struct flow_dissector_key_tags *key_tags;
struct flow_dissector_key_vlan *key_vlan;
struct bpf_prog *attached = NULL;
Expand Down Expand Up @@ -1329,6 +1347,12 @@ bool __skb_flow_dissect(const struct net *net,
data, nhoff, hlen);
break;

case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
__skb_flow_dissect_icmp(skb, flow_dissector, target_container,
data, nhoff, hlen);
break;

default:
break;
}
Expand All @@ -1342,14 +1366,6 @@ bool __skb_flow_dissect(const struct net *net,
data, hlen);
}

if (dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_ICMP)) {
key_icmp = skb_flow_dissector_target(flow_dissector,
FLOW_DISSECTOR_KEY_ICMP,
target_container);
key_icmp->icmp = skb_flow_get_be16(skb, nhoff, data, hlen);
}

/* Process result of IP proto processing */
switch (fdret) {
case FLOW_DISSECT_RET_PROTO_AGAIN:
Expand Down

0 comments on commit 3b336d6

Please sign in to comment.