]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
f_flower: Add l2_miss support
authorIdo Schimmel <idosch@nvidia.com>
Wed, 7 Jun 2023 15:35:50 +0000 (18:35 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 9 Jun 2023 21:49:33 +0000 (15:49 -0600)
Add the ability to match on packets that encountered a layer 2 miss in
bridge driver's FDB / MDB. Example:

 # tc filter add dev swp2 egress pref 1 proto all flower indev swp1 l2_miss 1 action drop
 # tc filter add dev swp2 egress pref 1 proto all flower indev swp1 l2_miss 0 action drop

 # tc filter show dev swp2 egress
 filter protocol all pref 1 flower chain 0
 filter protocol all pref 1 flower chain 0 handle 0x1
   indev swp1
   l2_miss 1
   not_in_hw
         action order 1: gact action drop
          random type none pass val 0
          index 1 ref 1 bind 1

 filter protocol all pref 1 flower chain 0 handle 0x2
   indev swp1
   l2_miss 0
   not_in_hw
         action order 1: gact action drop
          random type none pass val 0
          index 2 ref 1 bind 1

 # tc -j -p filter show dev swp2 egress
 [ {
         "protocol": "all",
         "pref": 1,
         "kind": "flower",
         "chain": 0
     },{
         "protocol": "all",
         "pref": 1,
         "kind": "flower",
         "chain": 0,
         "options": {
             "handle": 1,
             "indev": "swp1",
             "keys": {
                 "l2_miss": 1
             },
             "not_in_hw": true,
             "actions": [ {
 [...]
                 } ]
         }
     },{
         "protocol": "all",
         "pref": 1,
         "kind": "flower",
         "chain": 0,
         "options": {
             "handle": 2,
             "indev": "swp1",
             "keys": {
                 "l2_miss": 0
             },
             "not_in_hw": true,
             "actions": [ {
 [...]
                 } ]
         }
     } ]

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
man/man8/tc-flower.8
tc/f_flower.c

index fc73da93c5c3bead47ca222665d8f6286fcbe021..cd99745065cfb961091c0f4b24d61383068263a9 100644 (file)
@@ -100,7 +100,9 @@ flower \- flow based traffic control filter
 }
 .IR OPTIONS " | "
 .BR ip_flags
-.IR IP_FLAGS " }"
+.IR IP_FLAGS " | "
+.B l2_miss
+.IR L2_MISS " }"
 
 .ti -8
 .IR LSE_LIST " := [ " LSE_LIST " ] " LSE
@@ -493,6 +495,12 @@ respectively. firstfrag and nofirstfrag can be used to further distinguish
 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.
 .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
index c73c46dd234b7bd5d53810b628d127a5ce6f1135..b9fe6afb49b2f0a7feba67002a580f189aec3652 100644 (file)
@@ -91,6 +91,7 @@ static void explain(void)
                "                       erspan_opts MASKED-OPTIONS |\n"
                "                       gtp_opts MASKED-OPTIONS |\n"
                "                       ip_flags IP-FLAGS |\n"
+               "                       l2_miss L2_MISS |\n"
                "                       enc_dst_port [ port_number ] |\n"
                "                       ct_state MASKED_CT_STATE |\n"
                "                       ct_label MASKED_CT_LABEL |\n"
@@ -1520,6 +1521,15 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
                                fprintf(stderr, "Illegal \"ip_flags\"\n");
                                return -1;
                        }
+               } else if (strcmp(*argv, "l2_miss") == 0) {
+                       __u8 l2_miss;
+
+                       NEXT_ARG();
+                       if (get_u8(&l2_miss, *argv, 10)) {
+                               fprintf(stderr, "Illegal \"l2_miss\"\n");
+                               return -1;
+                       }
+                       addattr8(n, MAX_MSG, TCA_FLOWER_L2_MISS, l2_miss);
                } else if (matches(*argv, "verbose") == 0) {
                        flags |= TCA_CLS_FLAGS_VERBOSE;
                } else if (matches(*argv, "skip_hw") == 0) {
@@ -2983,6 +2993,14 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
                                    tb[TCA_FLOWER_KEY_FLAGS],
                                    tb[TCA_FLOWER_KEY_FLAGS_MASK]);
 
+       if (tb[TCA_FLOWER_L2_MISS]) {
+               struct rtattr *attr = tb[TCA_FLOWER_L2_MISS];
+
+               print_nl();
+               print_uint(PRINT_ANY, "l2_miss", "  l2_miss %u",
+                          rta_getattr_u8(attr));
+       }
+
        flower_print_ct_state(tb[TCA_FLOWER_KEY_CT_STATE],
                              tb[TCA_FLOWER_KEY_CT_STATE_MASK]);
        flower_print_ct_zone(tb[TCA_FLOWER_KEY_CT_ZONE],