Skip to content

Commit 972d387

Browse files
shorman-netronomedavem330
authored andcommitted
flow dissector: ICMP support
Allow dissection of ICMP(V6) type and code. This should only occur if a packet is ICMP(V6) and the dissector has FLOW_DISSECTOR_KEY_ICMP set. There are currently no users of FLOW_DISSECTOR_KEY_ICMP. A follow-up patch will allow FLOW_DISSECTOR_KEY_ICMP to be used by the flower classifier. Signed-off-by: Simon Horman <simon.horman@netronome.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7cc99fd commit 972d387

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

include/net/flow_dissector.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ struct flow_dissector_key_ports {
104104
};
105105
};
106106

107+
/**
108+
* flow_dissector_key_icmp:
109+
* @ports: type and code of ICMP header
110+
* icmp: ICMP type (high) and code (low)
111+
* type: ICMP type
112+
* code: ICMP code
113+
*/
114+
struct flow_dissector_key_icmp {
115+
union {
116+
__be16 icmp;
117+
struct {
118+
u8 type;
119+
u8 code;
120+
};
121+
};
122+
};
107123

108124
/**
109125
* struct flow_dissector_key_eth_addrs:
@@ -122,6 +138,7 @@ enum flow_dissector_key_id {
122138
FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */
123139
FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
124140
FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */
141+
FLOW_DISSECTOR_KEY_ICMP, /* struct flow_dissector_key_icmp */
125142
FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */
126143
FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */
127144
FLOW_DISSECTOR_KEY_VLAN, /* struct flow_dissector_key_flow_vlan */

net/core/flow_dissector.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
5757
}
5858
EXPORT_SYMBOL(skb_flow_dissector_init);
5959

60+
/**
61+
* skb_flow_get_be16 - extract be16 entity
62+
* @skb: sk_buff to extract from
63+
* @poff: offset to extract at
64+
* @data: raw buffer pointer to the packet
65+
* @hlen: packet header length
66+
*
67+
* The function will try to retrieve a be32 entity at
68+
* offset poff
69+
*/
70+
__be16 skb_flow_get_be16(const struct sk_buff *skb, int poff, void *data,
71+
int hlen)
72+
{
73+
__be16 *u, _u;
74+
75+
u = __skb_header_pointer(skb, poff, sizeof(_u), data, hlen, &_u);
76+
if (u)
77+
return *u;
78+
79+
return 0;
80+
}
81+
6082
/**
6183
* __skb_flow_get_ports - extract the upper layer ports and return them
6284
* @skb: sk_buff to extract the ports from
@@ -117,6 +139,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
117139
struct flow_dissector_key_basic *key_basic;
118140
struct flow_dissector_key_addrs *key_addrs;
119141
struct flow_dissector_key_ports *key_ports;
142+
struct flow_dissector_key_icmp *key_icmp;
120143
struct flow_dissector_key_tags *key_tags;
121144
struct flow_dissector_key_vlan *key_vlan;
122145
struct flow_dissector_key_keyid *key_keyid;
@@ -546,6 +569,14 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
546569
data, hlen);
547570
}
548571

572+
if (dissector_uses_key(flow_dissector,
573+
FLOW_DISSECTOR_KEY_ICMP)) {
574+
key_icmp = skb_flow_dissector_target(flow_dissector,
575+
FLOW_DISSECTOR_KEY_ICMP,
576+
target_container);
577+
key_icmp->icmp = skb_flow_get_be16(skb, nhoff, data, hlen);
578+
}
579+
549580
out_good:
550581
ret = true;
551582

0 commit comments

Comments
 (0)