History

net/act_pedit: Support using offset relative to the conventional network headers

Extend pedit to enable the user setting offset relative to network headers. This change would enable to work with more complex header schemes (vs the simple IPv4 case) where setting a fixed offset relative to the network header is not enough. After this patch, the action has information about the exact header type and field inside this header. This information could be used later on for hardware offloading of pedit. Backward compatibility was being kept: 1. Old kernel <-> new userspace 2. New kernel <-> old userspace 3. add rule using new userspace <-> dump using old userspace 4. add rule using old userspace <-> dump using new userspace When using the extended api, new netlink attributes are being used. This way, operation will fail in (1) and (3) - and no malformed rule be added or dumped. Of course, new user space that doesn't need the new functionality can use the old netlink attributes and operation will succeed. Since action can support both api's, (2) should work, and it is easy to write the new user space to have (4) work. The action is having a strict check that only header types and commands it can handle are accepted. This way future additions will be much easier. Usage example: $ tc filter add dev enp0s9 protocol ip parent ffff: \ flower \ ip_proto tcp \ dst_port 80 \ action pedit munge tcp dport set 8080 pipe \ action mirred egress redirect dev veth0 Will forward tcp port whose original dest port is 80, while modifying the destination port to 8080.

Amir Vadai committed 9 years ago

Commit 71d0ed71 parent ea6da4f3 files · +208 −16Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/tc_act/tc_pedit.h+23−0
@@ -11,10 +11,33 @@ enum { · 10 unmodified lines
1111 TCA_PEDIT_TM,
1212 TCA_PEDIT_PARMS,
1313 TCA_PEDIT_PAD,
14+ TCA_PEDIT_PARMS_EX,
15+ TCA_PEDIT_KEYS_EX,
16+ TCA_PEDIT_KEY_EX,
1417 __TCA_PEDIT_MAX
1518 };
1619 #define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1)
1720
21+enum {
22+ TCA_PEDIT_KEY_EX_HTYPE = 1,
23+ __TCA_PEDIT_KEY_EX_MAX
24+};
25+#define TCA_PEDIT_KEY_EX_MAX (__TCA_PEDIT_KEY_EX_MAX - 1)
26+
27+ /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
28+ * means no specific header type - offset is relative to the network layer
29+ */
30+enum pedit_header_type {
31+ TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK = 0,
32+ TCA_PEDIT_KEY_EX_HDR_TYPE_ETH = 1,
33+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 = 2,
34+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP6 = 3,
35+ TCA_PEDIT_KEY_EX_HDR_TYPE_TCP = 4,
36+ TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5,
37+ __PEDIT_HDR_TYPE_MAX,
38+};
39+#define TCA_PEDIT_HDR_TYPE_MAX (__PEDIT_HDR_TYPE_MAX - 1)
40+
1841 struct tc_pedit_key {
1942 __u32 mask; /* AND */
2043 __u32 val; /*XOR */