Skip to contentSkip to conversation

f_flower: add cfm support

PATCH Superseded Zahari Doychev 4 participants 6 messages Jun 20, 2023 – Jun 26, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 f_flower: add cfm support

From: Zahari Doychev <[email protected]>

Add support for matching on CFM Maintenance Domain level and opcode.

  # tc filter add dev ens6 ingress pref 1 proto cfm \
       flower cfm op 1 mdl 5 action ok
  # tc filter show dev ens6 ingress
    filter protocol cfm pref 1 flower chain 0
    filter protocol cfm pref 1 flower chain 0 handle 0x1
      eth_type 8902
      cfm mdl 5 op 1
      not_in_hw
            action order 1: gact action pass
             random type none pass val 0
             index 1 ref 1 bind 1
  # tc -j -p filter show dev ens6 ingress
    [ {
            "protocol": "cfm",
            "pref": 1,
            "kind": "flower",
            "chain": 0
        },{
            "protocol": "cfm",
            "pref": 1,
            "kind": "flower",
            "chain": 0,
            "options": {
                "handle": 1,
                "keys": {
                    "eth_type": "8902",
                    "cfm": {
                        "mdl": 5,
                        "op": 1
                    }
                },
                "not_in_hw": true,
                "actions": [ {
                        "order": 1,
                        "kind": "gact",
                        "control_action": {
                            "type": "pass"
                        },
                        "prob": {
                            "random_type": "none",
                            "control_action": {
                                "type": "pass"
                            },
                            "val": 0
                        },
                        "index": 1,
                        "ref": 1,
                        "bind": 1
                    } ]
            }
        } ]
---
 include/uapi/linux/pkt_cls.h |  9 ++++
 lib/ll_proto.c               |  1 +
 man/man8/tc-flower.8         | 29 ++++++++++-
 tc/f_flower.c                | 98 +++++++++++++++++++++++++++++++++++-
 4 files changed, 135 insertions(+), 2 deletions(-)
include/uapi/linux/pkt_cls.h +9 -0
index 00933dda..7865f5a9 100644
@@ -596,6 +596,8 @@ enum {
 
 	TCA_FLOWER_L2_MISS,		/* u8 */
 
+	TCA_FLOWER_KEY_CFM,		/* nested */
+
 	__TCA_FLOWER_MAX,
 };
 
@@ -704,6 +706,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 */
lib/ll_proto.c +1 -0
index 526e582f..5aacb5b4 100644
@@ -78,6 +78,7 @@ __PF(8021AD,802.1ad)
 __PF(MPLS_UC,mpls_uc)
 __PF(MPLS_MC,mpls_mc)
 __PF(TEB,teb)
+__PF(CFM,cfm)
 
 { 0x8100, "802.1Q" },
 { 0x88cc, "LLDP" },
man/man8/tc-flower.8 +28 -1
index cd997450..83245813 100644
@@ -102,7 +102,9 @@ flower \- flow based traffic control filter
 .BR ip_flags
 .IR IP_FLAGS " | "
 .B l2_miss
-.IR L2_MISS " }"
+.IR L2_MISS " | "
+.BR cfm
+.IR CFM_OPTIONS " }"
 
 .ti -8
 .IR LSE_LIST " := [ " LSE_LIST " ] " LSE
@@ -120,6 +122,13 @@ flower \- flow based traffic control filter
 .B ttl
 .IR TTL " }"
 
+.ti -8
+.IR CFM " := "
+.B cfm mdl
+.IR LEVEL " | "
+.B op
+.IR OPCODE "
+
 .SH DESCRIPTION
 The
 .B flower
@@ -496,11 +505,29 @@ fragmented packet. firstfrag can be used to indicate the first fragmented
 packet. nofirstfrag can be used to indicates subsequent fragmented packets
 or non-fragmented packets.
 .TP
+
 .BI l2_miss " L2_MISS"
 Match on layer 2 miss in the bridge driver's FDB / MDB. \fIL2_MISS\fR may be 0
 or 1. When 1, match on packets that encountered a layer 2 miss. When 0, match
 on packets that were forwarded using an FDB / MDB entry. Note that broadcast
 packets do not encounter a miss since a lookup is not performed for them.
+.TP
+
+.BI cfm " CFM_OPTIONS"
+Match on Connectivity Fault Management (CFM) fields.
+.I CFM_OPTIONS
+is a list of options that describe the properties of the CFM information
+fields to match.
+.RS
+.TP
+.BI mdl " LEVEL "
+Match on the Maintenance Domain (MD) level field.
+\fILEVEL\fR is an unsigned 3 bit value in decimal format.
+.TP
+.BI op " OPCODE "
+Match on the CFM opcode field. \fIOPCODE\fR is an unsigned 8 bit value in
+decimal format.
+
 .SH NOTES
 As stated above where applicable, matches of a certain layer implicitly depend
 on the matches of the next lower layer. Precisely, layer one and two matches
tc/f_flower.c +97 -1

133 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 3 lines · Zahari Doychev

From: Zahari Doychev <[email protected]>

Add support for matching on CFM Maintenance Domain level and opcode.

[...]

Quoted 2 lines

Few comments I missed earlier

Quoted 2 lines
---
 include/uapi/linux/pkt_cls.h |  9 ++++

iproute2 maintainers sync UAPI files using a script and I believe the preference is for submitters to not touch these files or update them in a separate patch that the maintainers can easily discard.

Quoted 4 lines
 lib/ll_proto.c               |  1 +
 man/man8/tc-flower.8         | 29 ++++++++++-
 tc/f_flower.c                | 98 +++++++++++++++++++++++++++++++++++-
 4 files changed, 135 insertions(+), 2 deletions(-)

[...]

Quoted 12 lines
tc/f_flower.c +12 -0
+static void flower_print_cfm(struct rtattr *attr)
+{
+	struct rtattr *tb[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];
+	struct rtattr *v;
+	SPRINT_BUF(out);
+	size_t sz = 0;
+
+	if (!attr || !(attr->rta_type & NLA_F_NESTED))
+		return;
+
+	parse_rtattr(tb, TCA_FLOWER_KEY_CFM_OPT_MAX, RTA_DATA(attr),
+		     RTA_PAYLOAD(attr));

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2837

Quoted 10 lines
tc/f_flower.c +10 -0
+
+	print_nl();
+	print_string(PRINT_FP, NULL, "  cfm", NULL);
+	open_json_object("cfm");
+
+	v = tb[TCA_FLOWER_KEY_CFM_MD_LEVEL];
+	if (v) {
+		sz += sprintf(out, " mdl %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "mdl", NULL, rta_getattr_u8(v));
+

Unnecessary blank line

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2844

Quoted 7 lines
tc/f_flower.c +7 -0
+	}
+
+	v = tb[TCA_FLOWER_KEY_CFM_OPCODE];
+	if (v) {
+		sprintf(out + sz, " op %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "op", NULL, rta_getattr_u8(v));
+

Likewise

Quoted 5 lines
tc/f_flower.c +5 -0
+	}
+
+	close_json_object();
+	print_string(PRINT_FP, "cfm", "%s", out);
+}
#2 lore raw
Quoted 44 lines · Ido Schimmel
Quoted 3 lines · Zahari Doychev

From: Zahari Doychev <[email protected]>

Add support for matching on CFM Maintenance Domain level and opcode.

[...]

Quoted 2 lines

Few comments I missed earlier

Quoted 2 lines
---
 include/uapi/linux/pkt_cls.h |  9 ++++

iproute2 maintainers sync UAPI files using a script and I believe the preference is for submitters to not touch these files or update them in a separate patch that the maintainers can easily discard.

Quoted 4 lines
 lib/ll_proto.c               |  1 +
 man/man8/tc-flower.8         | 29 ++++++++++-
 tc/f_flower.c                | 98 +++++++++++++++++++++++++++++++++++-
 4 files changed, 135 insertions(+), 2 deletions(-)

[...]

Quoted 16 lines
tc/f_flower.c +16 -0
+static void flower_print_cfm(struct rtattr *attr)
+{
+	struct rtattr *tb[TCA_FLOWER_KEY_CFM_OPT_MAX + 1];
+	struct rtattr *v;
+	SPRINT_BUF(out);
+	size_t sz = 0;
+
+	if (!attr || !(attr->rta_type & NLA_F_NESTED))
+		return;
+
+	parse_rtattr(tb, TCA_FLOWER_KEY_CFM_OPT_MAX, RTA_DATA(attr),
+		     RTA_PAYLOAD(attr));
+
+	print_nl();
+	print_string(PRINT_FP, NULL, "  cfm", NULL);
+	open_json_object("cfm");
Quoted 8 lines

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2837

Quoted 6 lines
tc/f_flower.c +6 -0
+
+	v = tb[TCA_FLOWER_KEY_CFM_MD_LEVEL];
+	if (v) {
+		sz += sprintf(out, " mdl %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "mdl", NULL, rta_getattr_u8(v));
+

Unnecessary blank line

somehow I missed that :( I will fix it and resend.

thanks
zahari

Quoted 17 lines

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2844

Quoted 8 lines
tc/f_flower.c +7 -0
+	}
+
+	v = tb[TCA_FLOWER_KEY_CFM_OPCODE];
+	if (v) {
+		sprintf(out + sz, " op %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "op", NULL, rta_getattr_u8(v));
+

Likewise

Quoted 5 lines
tc/f_flower.c +5 -0
+	}
+
+	close_json_object();
+	print_string(PRINT_FP, "cfm", "%s", out);
+}
#3 lore raw
In reply to Ido Schimmel
Quoted 3 lines · Ido Schimmel

iproute2 maintainers sync UAPI files using a script and I believe the preference is for submitters to not touch these files or update them in a separate patch that the maintainers can easily discard.

exactly.

#4 lore raw
In reply to Zahari Doychev
Quoted 10 lines · On Tue, 20 Jun 2023 22:10:36 +0200 Zahari Doychev <[email protected]>…
tc/f_flower.c +10 -0
+	print_nl();
+	print_string(PRINT_FP, NULL, "  cfm", NULL);
+	open_json_object("cfm");
+
+	v = tb[TCA_FLOWER_KEY_CFM_MD_LEVEL];
+	if (v) {
+		sz += sprintf(out, " mdl %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "mdl", NULL, rta_getattr_u8(v));
+
+	}

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2848

Quoted 10 lines
tc/f_flower.c +10 -0
+
+	v = tb[TCA_FLOWER_KEY_CFM_OPCODE];
+	if (v) {
+		sprintf(out + sz, " op %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "op", NULL, rta_getattr_u8(v));
+
+	}
+
+	close_json_object();
+	print_string(PRINT_FP, "cfm", "%s", out);

Don't think you need to format the temporary string if you do this the easy way. Just use print_uint?

	if (tb[TCA_FLOWER_KEY_CFM_MD_LEVEL])
		print_uint(PRINT_ANY, "mdl", " mdl %u",
			rta_getattr_u8(tb[TCA_FLOWER_KEY_CFM_MD_LEVEL]);

Since argument to print_uint is unsigned, the u8 will naturally get expanded.

#5 lore raw
Quoted 26 lines · Stephen Hemminger
Quoted 10 lines · On Tue, 20 Jun 2023 22:10:36 +0200 Zahari Doychev <[email protected]>…
tc/f_flower.c +10 -0
+	print_nl();
+	print_string(PRINT_FP, NULL, "  cfm", NULL);
+	open_json_object("cfm");
+
+	v = tb[TCA_FLOWER_KEY_CFM_MD_LEVEL];
+	if (v) {
+		sz += sprintf(out, " mdl %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "mdl", NULL, rta_getattr_u8(v));
+
+	}

tc/f_flower.c static void flower_print_arp_op(const char *name, · line 2848

Quoted 10 lines
tc/f_flower.c +10 -0
+
+	v = tb[TCA_FLOWER_KEY_CFM_OPCODE];
+	if (v) {
+		sprintf(out + sz, " op %u", rta_getattr_u8(v));
+		print_hhu(PRINT_JSON, "op", NULL, rta_getattr_u8(v));
+
+	}
+
+	close_json_object();
+	print_string(PRINT_FP, "cfm", "%s", out);

Don't think you need to format the temporary string if you do this the easy way. Just use print_uint?

Quoted 6 lines
	if (tb[TCA_FLOWER_KEY_CFM_MD_LEVEL])
		print_uint(PRINT_ANY, "mdl", " mdl %u",
			rta_getattr_u8(tb[TCA_FLOWER_KEY_CFM_MD_LEVEL]);

Since argument to print_uint is unsigned, the u8 will naturally get expanded.

I think it will make it really simpler. I will try it out and send a new patch as v3 was already merged.

Thanks
Zahari