Skip to contentSkip to conversation

flower2: Add flower2 classifier based on PANDA parser in kernel

RFC PATCH New Felipe Magno de Almeida 1 participant 1 message Sep 16, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 flower2: Add flower2 classifier based on PANDA parser in kernel

This patch adds the flower2 classifier which utilizes the PANDA parser.

The syntax remains the same as in flower with the exception of addition of pppoe tuple parsing, which is currently not available in the kernel flow dissector and tc flower.

Some usage examples of the flower2 classifier:

To show how flower2 is compatible with current flower classifier, let's see how we would create a filter for the following packet:

```
(oui Ethernet) > Broadcast, ethertype IPv4 (0x0800), length 60:   \
  localhost.22 > localhost.80: Flags [S], seq 0, win 8192, length
```

As you can expect, the line command is almost identical for flower2:

```
tc filter add dev lo parent ffff: protocol ip prio 1 flower2 \
  ip_proto tcp dst_port 80 action drop
```

Which will create the following filter:

```
filter protocol ip flower2 chain 0
filter protocol ip flower2 chain 0 handle 0x1
  eth_type ipv4
  ip_proto tcp
  dst_port 80
  not_in_hw
        action order 1: gact action drop
         random type none pass val 0
         index 1 ref 1 bind 1 installed 4 sec used 4 sec
        Action statistics:
        Sent 46 bytes 1 pkt (dropped 1, overlimits 0 requeues 0)
        backlog 0b 0p requeues 0
```

However, by using PANDA, flower2 is not limited by the intricacies of the flow dissector and can be extended to be used for more complex cases, such as already implemented in flower2 which can create a single filter for following packet:

```
(oui Ethernet) > Broadcast, ethertype 802.1Q (0x8100), length 85: \
  vlan 2, p 0, ethertype PPPoE S (0x8864), PPPoE  IP6 (0x0057),   \
  length 61: localhost.ftp-data > localhost.http: Flags [S],      \
  seq 0, win 8192, length 0
```

The above packet has three encapsulation layers, and can be filtered in flower2 by creating a filter the following command:

```
tc filter add dev lo parent ffff: protocol 802.1Q prio 1 flower2 \
  vlan_id 2 vlan_ethtype 0x8864 ppp_proto ppp_ipv6 dst_ip ::1    \
  action drop
```

Which will create the following filter:

```
filter protocol 802.1Q flower2 chain 0
filter protocol 802.1Q flower2 chain 0 handle 0x1
  ppp_proto ppp_ipv6
  vlan_id 2
  vlan_ethtype ppp_ses
  eth_type 8864
  dst_ip ::1
  not_in_hw
        action order 1: gact action drop
         random type none pass val 0
         index 1 ref 1 bind 1 installed 59 sec used 36 sec firstused 36 sec
        Action statistics:
        Sent 67 bytes 1 pkt (dropped 1, overlimits 0 requeues 0)
        backlog 0b 0p requeues 0
```

Another example showing how to filter a TCP packet with specific destination port within a complex encapsulation, this is the packet we want to filter:

```
(oui Ethernet) > Broadcast, ethertype PPPoE S (0x8864), length 61: \
  PPPoE  IP (0x0021), length 41: localhost.20 > localhost.80:      \
  Flags [S], seq 0, win 8192, length 0
```

The above packet can be filtered with the following syntax, which is not currently possible with flower because it doesn't implement ppp_proto and flow dissector has several issues that makes implementing this a problem[1]:

```
tc filter add dev lo parent ffff: protocol 0x8864 prio 1 flower2  \
  ppp_proto ppp_ip ip_proto tcp dst_port 80                       \
  action drop
```

[1]: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

---
 include/rt_names.h           |    3 +
 include/uapi/linux/pkt_cls.h |    2 +
 lib/ll_proto.c               |   61 +-
 tc/Makefile                  |    1 +
 tc/f_flower2.c               | 2842 ++++++++++++++++++++++++++++++++++
 5 files changed, 2908 insertions(+), 1 deletion(-)
 create mode 100644 tc/f_flower2.c
include/rt_names.h +3 -0
index 1835f3be..1f06e783 100644
@@ -31,6 +31,9 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg);
 const char * ll_proto_n2a(unsigned short id, char *buf, int len);
 int ll_proto_a2n(unsigned short *id, const char *buf);
 
+const char * ll_proto_ppp2a(unsigned short id, char *buf, int len);
+int ll_proto_a2ppp(unsigned short *id, const char *buf);
+
 const char *nl_proto_n2a(int id, char *buf, int len);
 int nl_proto_a2n(__u32 *id, const char *arg);
 
include/uapi/linux/pkt_cls.h +2 -0
index 7ea59cfe..76ad6a4a 100644
@@ -581,6 +581,8 @@ enum {
 	TCA_FLOWER_KEY_HASH,		/* u32 */
 	TCA_FLOWER_KEY_HASH_MASK,	/* u32 */
 
+	TCA_FLOWER_KEY_PPP_PROTO, 	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
lib/ll_proto.c +60 -1

70 lines not on this page · raw message

tc/Makefile +1 -0
index 5a517af2..e7b3ecc8 100644
@@ -29,6 +29,7 @@ TCMODULES += f_bpf.o
 TCMODULES += f_flow.o
 TCMODULES += f_cgroup.o
 TCMODULES += f_flower.o
+TCMODULES += f_flower2.o
 TCMODULES += q_dsmark.o
 TCMODULES += q_gred.o
 TCMODULES += f_tcindex.o
tc/f_flower2.c new file +2842 -0

2,842 lines not on this page · raw message

Signature · 1 line
2.33.0