Skip to content

Commit 029c1ec

Browse files
Benjamin LaHaisedavem330
authored andcommitted
flow_dissector: add mpls support (v2)
Add support for parsing MPLS flows to the flow dissector in preparation for adding MPLS match support to cls_flower. Signed-off-by: Benjamin LaHaise <benjamin.lahaise@netronome.com> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Simon Horman <simon.horman@netronome.com> Cc: Jamal Hadi Salim <jhs@mojatatu.com> Cc: Cong Wang <xiyou.wangcong@gmail.com> Cc: Jiri Pirko <jiri@mellanox.com> Cc: Eric Dumazet <jhs@mojatatu.com> Cc: Hadar Hen Zion <hadarh@mellanox.com> Cc: Gao Feng <fgao@ikuai8.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3ec21b6 commit 029c1ec

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎include/linux/mpls.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33

44
#include <uapi/linux/mpls.h>
55

6+
#define MPLS_TTL_MASK (MPLS_LS_TTL_MASK >> MPLS_LS_TTL_SHIFT)
7+
#define MPLS_BOS_MASK (MPLS_LS_S_MASK >> MPLS_LS_S_SHIFT)
8+
#define MPLS_TC_MASK (MPLS_LS_TC_MASK >> MPLS_LS_TC_SHIFT)
9+
#define MPLS_LABEL_MASK (MPLS_LS_LABEL_MASK >> MPLS_LS_LABEL_SHIFT)
10+
611
#endif /* _LINUX_MPLS_H */

‎include/net/flow_dissector.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ struct flow_dissector_key_vlan {
4141
u16 padding;
4242
};
4343

44+
struct flow_dissector_key_mpls {
45+
u32 mpls_ttl:8,
46+
mpls_bos:1,
47+
mpls_tc:3,
48+
mpls_label:20;
49+
};
50+
4451
struct flow_dissector_key_keyid {
4552
__be32 keyid;
4653
};
@@ -169,6 +176,7 @@ enum flow_dissector_key_id {
169176
FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
170177
FLOW_DISSECTOR_KEY_ENC_CONTROL, /* struct flow_dissector_key_control */
171178
FLOW_DISSECTOR_KEY_ENC_PORTS, /* struct flow_dissector_key_ports */
179+
FLOW_DISSECTOR_KEY_MPLS, /* struct flow_dissector_key_mpls */
172180

173181
FLOW_DISSECTOR_KEY_MAX,
174182
};

‎net/core/flow_dissector.c‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,37 @@ __skb_flow_dissect_mpls(const struct sk_buff *skb,
126126
{
127127
struct flow_dissector_key_keyid *key_keyid;
128128
struct mpls_label *hdr, _hdr[2];
129+
u32 entry, label;
129130

130131
if (!dissector_uses_key(flow_dissector,
131-
FLOW_DISSECTOR_KEY_MPLS_ENTROPY))
132+
FLOW_DISSECTOR_KEY_MPLS_ENTROPY) &&
133+
!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS))
132134
return FLOW_DISSECT_RET_OUT_GOOD;
133135

134136
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
135137
hlen, &_hdr);
136138
if (!hdr)
137139
return FLOW_DISSECT_RET_OUT_BAD;
138140

139-
if ((ntohl(hdr[0].entry) & MPLS_LS_LABEL_MASK) >>
140-
MPLS_LS_LABEL_SHIFT == MPLS_LABEL_ENTROPY) {
141+
entry = ntohl(hdr[0].entry);
142+
label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
143+
144+
if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS)) {
145+
struct flow_dissector_key_mpls *key_mpls;
146+
147+
key_mpls = skb_flow_dissector_target(flow_dissector,
148+
FLOW_DISSECTOR_KEY_MPLS,
149+
target_container);
150+
key_mpls->mpls_label = label;
151+
key_mpls->mpls_ttl = (entry & MPLS_LS_TTL_MASK)
152+
>> MPLS_LS_TTL_SHIFT;
153+
key_mpls->mpls_tc = (entry & MPLS_LS_TC_MASK)
154+
>> MPLS_LS_TC_SHIFT;
155+
key_mpls->mpls_bos = (entry & MPLS_LS_S_MASK)
156+
>> MPLS_LS_S_SHIFT;
157+
}
158+
159+
if (label == MPLS_LABEL_ENTROPY) {
141160
key_keyid = skb_flow_dissector_target(flow_dissector,
142161
FLOW_DISSECTOR_KEY_MPLS_ENTROPY,
143162
target_container);

0 commit comments

Comments
 (0)