net: flower: add cfm support
Subsystems (5)
v2 cover net: flower: add cfm support
From: Zahari Doychev <[email protected]>
The first patch adds cfm support to the flower classifier. The second adds a selftest for the flower cfm functionality.
iproute2 changes will come in follow up patches.
---
v1->v2:
- add missing comments
- improve cfm packet dissection
- move defines to header file
- fix code formatting
- remove unneeded attribute defines
rfc->v1:
- add selftest to the makefile TEST_PROGS.
Zahari Doychev (2):
net: flower: add support for matching cfm fields
selftests: net: add tc flower cfm test
include/net/flow_dissector.h | 21 +++ include/uapi/linux/pkt_cls.h | 9 + net/core/flow_dissector.c | 29 +++ net/sched/cls_flower.c | 108 ++++++++++- .../testing/selftests/net/forwarding/Makefile | 1 + .../selftests/net/forwarding/tc_flower_cfm.sh | 175 ++++++++++++++++++ 6 files changed, 342 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/forwarding/tc_flower_cfm.sh
Signature · 1 line
2.40.0
PATCH v2 1/2 net: flower: add support for matching cfm fields
From: Zahari Doychev <[email protected]>
Add support to the tc flower classifier to match based on fields in CFM information elements like level and opcode.
tc filter add dev ens6 ingress protocol 802.1q \
flower vlan_id 698 vlan_ethtype 0x8902 cfm mdl 5 op 46 \ action drop
--- include/net/flow_dissector.h | 21 +++++++ include/uapi/linux/pkt_cls.h | 9 +++ net/core/flow_dissector.c | 29 ++++++++++ net/sched/cls_flower.c | 108 ++++++++++++++++++++++++++++++++++- 4 files changed, 166 insertions(+), 1 deletion(-)
include/net/flow_dissector.h +21 -0
@@ -297,6 +297,26 @@ struct flow_dissector_key_l2tpv3 {__be32 session_id; }; +/** +* struct flow_dissector_key_cfm +* @mdl_ver: maintenance domain level(mdl) and cfm protocol version +* @opcode: code specifying a type of cfm protocol packet +* +* See 802.1ag, ITU-T G.8013/Y.1731 +* 1 2 +* |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| +* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +* | mdl | version | opcode | +* +-----+---------+-+-+-+-+-+-+-+-+ +*/ +struct flow_dissector_key_cfm { +u8 mdl_ver; +u8 opcode; +}; + +#define FLOW_DIS_CFM_MDL_MASK 7 +#define FLOW_DIS_CFM_MDL_SHIFT 5 +enum flow_dissector_key_id {FLOW_DISSECTOR_KEY_CONTROL ,/* struct flow_dissector_key_control */ FLOW_DISSECTOR_KEY_BASIC ,/* struct flow_dissector_key_basic */
@@ -329,6 +349,7 @@ enum flow_dissector_key_id {FLOW_DISSECTOR_KEY_NUM_OF_VLANS ,/* struct flow_dissector_key_num_of_vlans */ FLOW_DISSECTOR_KEY_PPPOE ,/* struct flow_dissector_key_pppoe */ FLOW_DISSECTOR_KEY_L2TPV3 ,/* struct flow_dissector_key_l2tpv3 */ +FLOW_DISSECTOR_KEY_CFM ,/* struct flow_dissector_key_cfm */ FLOW_DISSECTOR_KEY_MAX, };
include/uapi/linux/pkt_cls.h +9 -0
@@ -594,6 +594,8 @@ enum {TCA_FLOWER_KEY_L2TPV3_SID ,/* be32 */ +TCA_FLOWER_KEY_CFM ,/* nested */ + __TCA_FLOWER_MAX, };
@@ -702,6 +704,13 @@ enum { TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1), }; +enum { +TCA_FLOWER_KEY_CFM_OPT_UNSPEC , +TCA_FLOWER_KEY_CFM_MD_LEVEL , +TCA_FLOWER_KEY_CFM_OPCODE , +TCA_FLOWER_KEY_CFM_OPT_MAX , +}; +#define TCA_FLOWER_MASK_FLAGS_RANGE (1 << 0)/* Range-based match */ /* Match-all classifier */
net/core/flow_dissector.c +29 -0
@@ -547,6 +547,29 @@ __skb_flow_dissect_arp(const struct sk_buff *skb,return FLOW_DISSECT_RET_OUT_GOOD ; } +static enum flow_dissect_ret +__skb_flow_dissect_cfm (const struct sk_buff *skb, +struct flow_dissector *flow_dissector, +void *target_container,const void *data, +int nhoff,int hlen) +{ +struct flow_dissector_key_cfm *key, *hdr, _hdr; + +if (!dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_CFM )) +return FLOW_DISSECT_RET_OUT_GOOD ; + + hdr =__skb_header_pointer (skb, nhoff,sizeof (*key), data, hlen, &_hdr); +if (!hdr) +return FLOW_DISSECT_RET_OUT_BAD ; + + key =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_CFM , + target_container); + + *key = *hdr; + +return FLOW_DISSECT_RET_OUT_GOOD ; +} + static enum flow_dissect_ret __skb_flow_dissect_gre(const struct sk_buff *skb, struct flow_dissector_key_control *key_control,
@@ -1390,6 +1413,12 @@ bool __skb_flow_dissect(const struct net *net,break ; } +case htons (ETH_P_CFM ): { + fdret =__skb_flow_dissect_cfm (skb, flow_dissector, + target_container, data, + nhoff, hlen); +break ; + }default : fdret =FLOW_DISSECT_RET_OUT_BAD ;break ;
net/sched/cls_flower.c +107 -1
156 lines not on this page · raw message
Signature · 1 line
2.40.0
Re: [PATCH net-next v2 1/2] net: flower: add support for matching cfm fields
Quoted 10 lines · Zahari Doychev
From: Zahari Doychev <[email protected]>
Add support to the tc flower classifier to match based on fields in CFM information elements like level and opcode.
tc filter add dev ens6 ingress protocol 802.1q \
flower vlan_id 698 vlan_ethtype 0x8902 cfm mdl 5 op 46 \ action dropSigned-off-by Zahari Doychev <[email protected]>
Hi Zahari,
thanks for your patch.
Some initial feedback from my side follows.
Quoted 6 lines
--- include/net/flow_dissector.h | 21 +++++++ include/uapi/linux/pkt_cls.h | 9 +++ net/core/flow_dissector.c | 29 ++++++++++ net/sched/cls_flower.c | 108 ++++++++++++++++++++++++++++++++++- 4 files changed, 166 insertions(+), 1 deletion(-)
FWIIW I would have split the flow dissector and cls flower changes into separate patches.
Quoted 18 lines
include/net/flow_dissector.h +9
-0@@ -297,6 +297,26 @@ struct flow_dissector_key_l2tpv3 {__be32 session_id; }; +/** +* struct flow_dissector_key_cfm +* @mdl_ver: maintenance domain level(mdl) and cfm protocol version +* @opcode: code specifying a type of cfm protocol packet +* +* See 802.1ag, ITU-T G.8013/Y.1731 +* 1 2 +* |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| +* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
include/net/flow_dissector.h struct flow_dissector_key_l2tpv3 { · line 318
Quoted 10 lines
include/net/flow_dissector.h +10
-0+* | mdl | version | opcode | +* +-----+---------+-+-+-+-+-+-+-+-+ +*/ +struct flow_dissector_key_cfm { +u8 mdl_ver; +u8 opcode; +}; + +#define FLOW_DIS_CFM_MDL_MASK 7 +#define FLOW_DIS_CFM_MDL_SHIFT 5
I think that if you used GENMASK to create the mask, and then FIELD_PREP/FIELD_GET to use the mask you could avoid _SHIFT entirely. Which might be cleaner.
...
Quoted 17 lines
net/core/flow_dissector.c +9
-0@@ -547,6 +547,29 @@ __skb_flow_dissect_arp(const struct sk_buff *skb,return FLOW_DISSECT_RET_OUT_GOOD ; } +static enum flow_dissect_ret +__skb_flow_dissect_cfm (const struct sk_buff *skb, +struct flow_dissector *flow_dissector, +void *target_container,const void *data, +int nhoff,int hlen) +{ +struct flow_dissector_key_cfm *key, *hdr, _hdr; + +if (!dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_CFM ))
net/core/flow_dissector.c __skb_flow_dissect_arp(const struct sk_buff *skb, · line 568
Quoted 10 lines
net/core/flow_dissector.c +10
-0+return FLOW_DISSECT_RET_OUT_GOOD ; + + hdr =__skb_header_pointer (skb, nhoff,sizeof (*key), data, hlen, &_hdr); +if (!hdr) +return FLOW_DISSECT_RET_OUT_BAD ; + + key =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_CFM , + target_container); + + *key = *hdr;
It is unusual to just copy the header directly to the key. But as both are two u8 values I guess it is fine.
Quoted 8 lines
net/core/flow_dissector.c +4
-0+ +return FLOW_DISSECT_RET_OUT_GOOD ; +} + static enum flow_dissect_ret __skb_flow_dissect_gre(const struct sk_buff *skb, struct flow_dissector_key_control *key_control,
net/core/flow_dissector.c bool __skb_flow_dissect(const struct net *net, · line 1419
Quoted 7 lines
net/core/flow_dissector.c +4
-0@@ -1390,6 +1413,12 @@ bool __skb_flow_dissect(const struct net *net,break ; } +case htons (ETH_P_CFM ): { + fdret =__skb_flow_dissect_cfm (skb, flow_dissector, + target_container, data, + nhoff, hlen);
I do like that you moved the handling into it's own function. But I do also note that this style differs from adjacent code in this file.
Quoted 5 lines
net/core/flow_dissector.c +2
-0+break ; + }default : fdret =FLOW_DISSECT_RET_OUT_BAD ;break ;
...
Re: [PATCH net-next v2 1/2] net: flower: add support for matching cfm fields
Quoted 24 lines · Simon Horman
Quoted 10 lines · Zahari Doychev
From: Zahari Doychev <[email protected]>
Add support to the tc flower classifier to match based on fields in CFM information elements like level and opcode.
tc filter add dev ens6 ingress protocol 802.1q \
flower vlan_id 698 vlan_ethtype 0x8902 cfm mdl 5 op 46 \ action dropSigned-off-by Zahari Doychev <[email protected]>Hi Zahari,
thanks for your patch.
Some initial feedback from my side follows.Quoted 6 lines
--- include/net/flow_dissector.h | 21 +++++++ include/uapi/linux/pkt_cls.h | 9 +++ net/core/flow_dissector.c | 29 ++++++++++ net/sched/cls_flower.c | 108 ++++++++++++++++++++++++++++++++++- 4 files changed, 166 insertions(+), 1 deletion(-)
Quoted 2 lines
FWIIW I would have split the flow dissector and cls flower changes into separate patches.
I think it makes sense so I would do it.
Quoted 25 lines
Quoted 25 lines
include/net/flow_dissector.h +15
-0@@ -297,6 +297,26 @@ struct flow_dissector_key_l2tpv3 {__be32 session_id; }; +/** +* struct flow_dissector_key_cfm +* @mdl_ver: maintenance domain level(mdl) and cfm protocol version +* @opcode: code specifying a type of cfm protocol packet +* +* See 802.1ag, ITU-T G.8013/Y.1731 +* 1 2 +* |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| +* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +* | mdl | version | opcode | +* +-----+---------+-+-+-+-+-+-+-+-+ +*/ +struct flow_dissector_key_cfm { +u8 mdl_ver; +u8 opcode;
Quoted 8 lines
include/net/flow_dissector.h struct flow_dissector_key_l2tpv3 { · line 318
Quoted 4 lines
include/net/flow_dissector.h +4
-0+}; + +#define FLOW_DIS_CFM_MDL_MASK 7 +#define FLOW_DIS_CFM_MDL_SHIFT 5I think that if you used GENMASK to create the mask, and then FIELD_PREP/FIELD_GET to use the mask you could avoid
_SHIFTentirely. Which might be cleaner.
It was proposed in the previous version for different part but it applies here as well so I would change it.
Quoted 25 lines
...
Quoted 22 lines
net/core/flow_dissector.c +14
-0@@ -547,6 +547,29 @@ __skb_flow_dissect_arp(const struct sk_buff *skb,return FLOW_DISSECT_RET_OUT_GOOD ; } +static enum flow_dissect_ret +__skb_flow_dissect_cfm (const struct sk_buff *skb, +struct flow_dissector *flow_dissector, +void *target_container,const void *data, +int nhoff,int hlen) +{ +struct flow_dissector_key_cfm *key, *hdr, _hdr; + +if (!dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_CFM )) +return FLOW_DISSECT_RET_OUT_GOOD ; + + hdr =__skb_header_pointer (skb, nhoff,sizeof (*key), data, hlen, &_hdr); +if (!hdr) +return FLOW_DISSECT_RET_OUT_BAD ;
Quoted 8 lines
net/core/flow_dissector.c __skb_flow_dissect_arp(const struct sk_buff *skb, · line 568
Quoted 5 lines
net/core/flow_dissector.c +5
-0+ + key =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_CFM , + target_container); + + *key = *hdr;It is unusual to just copy the header directly to the key. But as both are two u8 values I guess it is fine.
I was wondering about this so I would use the fields here.
Quoted 12 lines
Quoted 12 lines
net/core/flow_dissector.c +4
-0+ +return FLOW_DISSECT_RET_OUT_GOOD ; +} + static enum flow_dissect_ret __skb_flow_dissect_gre(const struct sk_buff *skb, struct flow_dissector_key_control *key_control,@@ -1390,6 +1413,12 @@ bool __skb_flow_dissect(const struct net *net,break ; }
Quoted 8 lines
net/core/flow_dissector.c bool __skb_flow_dissect(const struct net *net, · line 1419
Quoted 4 lines
net/core/flow_dissector.c +4
-0+case htons (ETH_P_CFM ): { + fdret =__skb_flow_dissect_cfm (skb, flow_dissector, + target_container, data, + nhoff, hlen);I do like that you moved the handling into it's own function. But I do also note that this style differs from adjacent code in this file.
I would prefer to have an own function here as I find __skb_flow_dissect long enough already. But if you insist I am okay to change it.
Thanks
Zahari
Quoted 8 lines
Quoted 6 lines
net/core/flow_dissector.c +2
-0+break ; + }default : fdret =FLOW_DISSECT_RET_OUT_BAD ;break ;...
Re: [PATCH net-next v2 1/2] net: flower: add support for matching cfm fields
Quoted 3 lines · Zahari Doychev
Quoted 2 lines · Simon Horman
Quoted 1 line · Zahari Doychev
From: Zahari Doychev <[email protected]>
...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1390,6 +1413,12 @@ bool __skb_flow_dissect(const struct net *net, break; }Quoted 8 lines
net/core/flow_dissector.c bool __skb_flow_dissect(const struct net *net, · line 1419
Quoted 4 lines
net/core/flow_dissector.c +4
-0+case htons (ETH_P_CFM ): { + fdret =__skb_flow_dissect_cfm (skb, flow_dissector, + target_container, data, + nhoff, hlen);I do like that you moved the handling into it's own function. But I do also note that this style differs from adjacent code in this file.
Quoted 2 lines
I would prefer to have an own function here as I find
__skb_flow_dissectlong enough already. But if you insist I am okay to change it.
I don't insist.
I like it the way it is.
PATCH v2 2/2 selftests: net: add tc flower cfm test
In reply to Zahari DoychevFrom: Zahari Doychev <[email protected]>
New cfm flower test case is added to the net forwarding selfttests.
--- .../testing/selftests/net/forwarding/Makefile | 1 + .../selftests/net/forwarding/tc_flower_cfm.sh | 175 ++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/tc_flower_cfm.sh
tools/testing/selftests/net/forwarding/Makefile +1 -0
@@ -82,6 +82,7 @@ TEST_PROGS = bridge_igmp.sh \ tc_chains.sh \ tc_flower_router.sh \ tc_flower.sh \ + tc_flower_cfm.sh \ tc_mpls_l2vpn.sh \ tc_police.sh \ tc_shblocks.sh \
tools/testing/selftests/net/forwarding/tc_flower_cfm.sh new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
2.40.0
Re: [PATCH net-next v2 2/2] selftests: net: add tc flower cfm test
Quoted 5 lines · Zahari Doychev
From: Zahari Doychev <[email protected]>
New cfm flower test case is added to the net forwarding selfttests.
Signed-off-by Zahari Doychev <[email protected]>
...
tools/testing/selftests/net/forwarding/tc_flower_cfm.sh line 100
Quoted 2 lines
tools/testing/selftests/net/forwarding/tc_flower_cfm.sh new file +2
-0+ tc_check_packets "dev $h2 ingress" 103 1 + check_err $? "Did not match on corret level"
Hi Zahari,
if you need to repost for some reason you may consider correcting the spelling of 'corret'.
...
Re: [PATCH net-next v2 2/2] selftests: net: add tc flower cfm test
Quoted 9 lines · Simon Horman
Quoted 5 lines · Zahari Doychev
From: Zahari Doychev <[email protected]>
New cfm flower test case is added to the net forwarding selfttests.
Signed-off-by Zahari Doychev <[email protected]>...
Quoted 7 lines
tools/testing/selftests/net/forwarding/tc_flower_cfm.sh line 100
Quoted 2 lines
tools/testing/selftests/net/forwarding/tc_flower_cfm.sh new file +2
-0+ tc_check_packets "dev $h2 ingress" 103 1 + check_err $? "Did not match on corret level"Hi Zahari,
if you need to repost for some reason you may consider correcting the spelling of 'corret'.
thanks, I will correct it.
Quoted 2 lines
...