Multiple DSCP match by "-m dscp --dscp-multi value,value,..."
Subsystems (2)
I found this is useful for me to match multiple DSCP values in a rule.
For example, if you want to handle traffic with a list of DSCP same way, instead of using this:
-A FORWARD ...condition 1... -m dscp --dscp-class AF11 -j TARGET -A FORWARD ...condition 1... -m dscp --dscp-class AF21 -j TARGET -A FORWARD ...condition 1... -m dscp --dscp-class AF31 -j TARGET -A FORWARD ...condition 2... -m dscp --dscp 10 -j TARGET -A FORWARD ...condition 2... -m dscp --dscp 10 -j TARGET
you can use:
-A FORWARD ... -m dscp --dscp-class AF11,AF21,AF31 -j TARGET
This is mainly convenient if you want to 1-to-1 mapping from your app to iptables rule.
Also you don't need to add up packet counts (for example) from multiple rules.
Does anyone have an idea whether this will be useful for others and worth to push?
Thanks.
commit 97958cdb209a6babc88fdeb10893597dcb8856d5
Author: Kyeong Yoo <[email protected]> Date: Mon Jul 27 23:46:05 2015 +1200
[NETFILTER]: support multiple DSCP value match by "-m dscp --dscp-multi"
Current "dscp" match supports one DSCP value in a rule.
This patch enhances "dscp" match with multiple values:
-m dscp --dscp-multi value,value,...
As there are 64 values possible in DSCP field (6 bits), list of values are stored in a 64-bit bitmap.
include/uapi/linux/netfilter/xt_dscp.h +7 -0
@@ -16,10 +16,17 @@#define XT_DSCP_SHIFT 2#define XT_DSCP_MAX 0x3f/* 00111111 */ +#define dscp_set_bit (bmap, idx) \ + (bmap[(idx) >> 5] |= 1U << (idx & 31)) +#define dscp_test_bit (bmap, idx) \ + (((1U << (idx & 31)) & bmap[(idx) >> 5]) != 0) +/* match info */ struct xt_dscp_info {__u8 dscp;__u8 invert; +__u8 multi; +__u32 dscp_bitmap[(XT_DSCP_MAX >>5 ) +1 ]; };struct xt_tos_match_info {
net/netfilter/xt_dscp.c +4 -0
@@ -30,6 +30,8 @@ dscp_mt(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_dscp_info *info = par->matchinfo;u_int8_t dscp =ipv4_get_dsfield (ip_hdr (skb)) >>XT_DSCP_SHIFT ; +if (info->multi) +return (dscp_test_bit (info->dscp_bitmap, dscp) !=0 ) ^ !!info->invert;return (dscp == info->dscp) ^ !!info->invert; }
@@ -39,6 +41,8 @@ dscp_mt6(const struct sk_buff *skb, struct xt_action_param *par)const struct xt_dscp_info *info = par->matchinfo;u_int8_t dscp =ipv6_get_dsfield (ipv6_hdr (skb)) >>XT_DSCP_SHIFT ; +if (info->multi) +return (dscp_test_bit (info->dscp_bitmap, dscp) !=0 ) ^ !!info->invert;return (dscp == info->dscp) ^ !!info->invert; }
commit a6370996fd612a538474209195c3fbdd7dfeef76
Author: Kyeong Yoo <[email protected]> Date: Wed Jul 29 09:38:51 2015 +1200
extensions: libxt_dscp: allow multiple DSCP value match (--dscp-multi)
Current "dscp" match supports one DSCP value in a rule.
This patch enhances "dscp" match with multiple values ("--dscp-multi" option):
-m dscp --dscp-multi value,value,...
DSCP value should be between 0 and 63 or valid DSCP name like AF11, etc.
extensions/libxt_dscp.c +79 -6
140 lines not on this page · raw message
include/linux/netfilter/xt_dscp.h +7 -0
@@ -16,10 +16,17 @@#define XT_DSCP_SHIFT 2#define XT_DSCP_MAX 0x3f/* 00111111 */ +#define dscp_set_bit (bmap, idx) \ + (bmap[(idx) >> 5] |= 1U << (idx & 31)) +#define dscp_test_bit (bmap, idx) \ + (((1U << (idx & 31)) & bmap[(idx) >> 5]) != 0) +/* match info */ struct xt_dscp_info {__u8 dscp;__u8 invert; +__u8 multi; +__u32 dscp_bitmap[(XT_DSCP_MAX >>5 ) +1 ]; };struct xt_tos_match_info {