Add flow label support to ip-rule and route get
Subsystems (3)
Ido Schimmel
maintainerv2 cover Add flow label support to ip-rule and route get
Add IPv6 flow label support to ip-rule and route get requests following kernel support that was added in kernel commit 6b3099ebca13 ("Merge branch 'net-fib_rules-add-flow-label-selector-support'").
v2:
* Remove new line from invarg() invocations.
Ido Schimmel (3):
Sync uAPI headers
ip: route: Add IPv6 flow label support
iprule: Add flow label support
include/uapi/linux/fib_rules.h | 2 ++ include/uapi/linux/rtnetlink.h | 1 + ip/iproute.c | 10 +++++- ip/iprule.c | 66 +++++++++++++++++++++++++++++++++- man/man8/ip-route.8.in | 8 ++++- man/man8/ip-rule.8.in | 8 ++++- 6 files changed, 91 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.1
Ido Schimmel
maintainerPATCH v2 1/3 Sync uAPI headers
--- include/uapi/linux/fib_rules.h | 2 ++ include/uapi/linux/rtnetlink.h | 1 + 2 files changed, 3 insertions(+)
include/uapi/linux/fib_rules.h +2 -0
@@ -68,6 +68,8 @@ enum {FRA_SPORT_RANGE ,/* sport */ FRA_DPORT_RANGE ,/* dport */ FRA_DSCP ,/* dscp */ +FRA_FLOWLABEL ,/* flowlabel */ +FRA_FLOWLABEL_MASK ,/* flowlabel mask */ __FRA_MAX };
include/uapi/linux/rtnetlink.h +1 -0
@@ -393,6 +393,7 @@ enum rtattr_type_t {RTA_SPORT ,RTA_DPORT ,RTA_NH_ID , +RTA_FLOWLABEL , __RTA_MAX };
Signature · 1 line
2.47.1
Ido Schimmel
maintainerPATCH v2 2/3 ip: route: Add IPv6 flow label support
In reply to Ido SchimmelAllow specifying an IPv6 flow label when performing a route lookup.
--- ip/iproute.c | 10 +++++++++- man/man8/ip-route.8.in | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-)
ip/iproute.c +9 -1
@@ -67,7 +67,7 @@ static void usage(void)" [ mark NUMBER ] [ vrf NAME ]\n" " [ uid NUMBER ] [ ipproto PROTOCOL ]\n" " [ sport NUMBER ] [ dport NUMBER ]\n" -" [ as ADDRESS ]\n" +" [ as ADDRESS ] [ flowlabel FLOWLABEL ]\n" " ip route { add | del | change | append | replace } ROUTE\n" "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n" " [ table TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ]\n"
@@ -2129,6 +2129,14 @@ static int iproute_get(int argc, char **argv)invarg ("Invalid \"ipproto\" value\n" , *argv);addattr8 (&req.n,sizeof (req),RTA_IP_PROTO , ipproto); + }else if (strcmp (*argv,"flowlabel" ) ==0 ) { +__be32 flowlabel; + +NEXT_ARG (); +if (get_be32 (&flowlabel, *argv,0 )) +invarg ("invalid flowlabel" , *argv); +addattr32 (&req.n,sizeof (req),RTA_FLOWLABEL , + flowlabel); }else {inet_prefix addr;
man/man8/ip-route.8.in +7 -1
@@ -47,7 +47,9 @@ ip-route \- routing table management .B dport .IR NUMBER " ] [" .B as -.IR ADDRESS " ]" +.IR ADDRESS " ] [" +.B flowlabel +.IR FLOWLABEL " ] .ti -8 .BR "ip route" " { " add " | " del " | " change " | " append " | "\
@@ -1316,6 +1318,10 @@ was given, relookup the route with the source set to the preferred address received from the first lookup. If policy routing is used, it may be a different route. +.TP +.BI flowlabel " FLOWLABEL" +ipv6 flow label as seen by the route lookup + .P Note that this operation is not equivalent to .BR "ip route show" .
Signature · 1 line
2.47.1
Re: [PATCH iproute2-next v2 2/3] ip: route: Add IPv6 flow label support
Quoted 5 lines · On Mon, 30 Dec 2024 10:58:09 +0200 Ido Schimmel <[email protected]> wrote:
ip/iproute.c +1
-0@@ -2129,6 +2129,14 @@ static int iproute_get(int argc, char **argv)invarg ("Invalid \"ipproto\" value\n" , *argv);addattr8 (&req.n,sizeof (req),RTA_IP_PROTO , ipproto); + }else if (strcmp (*argv,"flowlabel" ) ==0 ) {
ip/iproute.c static int iproute_get(int argc, char **argv) · line 2142
Quoted 10 lines
ip/iproute.c +7
-0+__be32 flowlabel; + +NEXT_ARG (); +if (get_be32 (&flowlabel, *argv,0 )) +invarg ("invalid flowlabel" , *argv); +addattr32 (&req.n,sizeof (req),RTA_FLOWLABEL , + flowlabel); }else {inet_prefix addr;
What about displaying flow label with the ip route command?
Ido Schimmel
maintainerRe: [PATCH iproute2-next v2 2/3] ip: route: Add IPv6 flow label support
Quoted 12 lines · Stephen Hemminger
Quoted 9 lines · On Mon, 30 Dec 2024 10:58:09 +0200 Ido Schimmel <[email protected]> wrote:
ip/iproute.c +5
-0@@ -2129,6 +2129,14 @@ static int iproute_get(int argc, char **argv)invarg ("Invalid \"ipproto\" value\n" , *argv);addattr8 (&req.n,sizeof (req),RTA_IP_PROTO , ipproto); + }else if (strcmp (*argv,"flowlabel" ) ==0 ) { +__be32 flowlabel; + +NEXT_ARG (); +if (get_be32 (&flowlabel, *argv,0 ))
Quoted 8 lines
ip/iproute.c static int iproute_get(int argc, char **argv) · line 2142
Quoted 6 lines
ip/iproute.c +3
-0+invarg ("invalid flowlabel" , *argv); +addattr32 (&req.n,sizeof (req),RTA_FLOWLABEL , + flowlabel); }else {inet_prefix addr;What about displaying flow label with the ip route command?
The flow label is not a route attribute and it is not present in RTM_NEWROUTE messages. It is provided as an input to the route lookup process in RTM_GETROUTE messages.
Ido Schimmel
maintainerPATCH v2 3/3 iprule: Add flow label support
In reply to Ido SchimmelAdd support for 'flowlabel' selector in ip-rule.
Rules can be added with or without a mask in which case exact match is used:
# ip -6 rule add flowlabel 0x12345 table 100 # ip -6 rule add flowlabel 0x11/0xff table 200 # ip -6 rule add flowlabel 0x54321 table 300 # ip -6 rule del flowlabel 0x54321 table 300
Dump output:
$ ip -6 rule show 0: from all lookup local 32764: from all lookup 200 flowlabel 0x11/0xff 32765: from all lookup 100 flowlabel 0x12345 32766: from all lookup main
Dump can be filtered by flow label value and mask:
$ ip -6 rule show flowlabel 0x12345 32765: from all lookup 100 flowlabel 0x12345 $ ip -6 rule show flowlabel 0x11/0xff 32764: from all lookup 200 flowlabel 0x11/0xff
JSON output:
$ ip -6 -j -p rule show flowlabel 0x12345
[ {
"priority": 32765,
"src": "all",
"table": "100",
"flowlabel": "0x12345",
"flowlabel_mask": "0xfffff"
} ]
$ ip -6 -j -p rule show flowlabel 0x11/0xff
[ {
"priority": 32764,
"src": "all",
"table": "200",
"flowlabel": "0x11",
"flowlabel_mask": "0xff"
} ]--- ip/iprule.c | 66 ++++++++++++++++++++++++++++++++++++++++++- man/man8/ip-rule.8.in | 8 +++++- 2 files changed, 72 insertions(+), 2 deletions(-)
ip/iprule.c +65 -1
@@ -46,7 +46,7 @@ static void usage(void)" [ ipproto PROTOCOL ]\n" " [ sport [ NUMBER | NUMBER-NUMBER ]\n" " [ dport [ NUMBER | NUMBER-NUMBER ] ]\n" -" [ dscp DSCP ]\n" +" [ dscp DSCP ] [ flowlabel FLOWLABEL[/MASK] ]\n" "ACTION := [ table TABLE_ID ]\n" " [ protocol PROTO ]\n" " [ nat ADDRESS ]\n"
@@ -69,6 +69,7 @@ static structunsigned int pref, prefmask;unsigned int fwmark, fwmask;unsigned int dscp, dscpmask; +__u32 flowlabel, flowlabel_mask;uint64_t tun_id;char iif[IFNAMSIZ ];char oif[IFNAMSIZ ];
@@ -232,6 +233,19 @@ static bool filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len) } } +if (filter.flowlabel_mask) { +__u32 flowlabel, flowlabel_mask; + +if (!tb[FRA_FLOWLABEL ] || !tb[FRA_FLOWLABEL_MASK ]) +return false; + flowlabel =rta_getattr_be32 (tb[FRA_FLOWLABEL ]); + flowlabel_mask =rta_getattr_be32 (tb[FRA_FLOWLABEL_MASK ]); + +if (filter.flowlabel != flowlabel || + filter.flowlabel_mask != flowlabel_mask) +return false; + } + table =frh_get_table (frh, tb);if (filter.tb >0 && filter.tb ^ table)return false;
@@ -489,6 +503,23 @@ int print_rule(struct nlmsghdr *n, void *arg) rtnl_dscp_n2a(dscp, b1, sizeof(b1))); } +/* The kernel will either provide both attributes, or none */ +if (tb[FRA_FLOWLABEL ] && tb[FRA_FLOWLABEL_MASK ]) { +__u32 flowlabel, flowlabel_mask; + + flowlabel =rta_getattr_be32 (tb[FRA_FLOWLABEL ]); + flowlabel_mask =rta_getattr_be32 (tb[FRA_FLOWLABEL_MASK ]); + +print_0xhex (PRINT_ANY ,"flowlabel" ," flowlabel %#llx" , + flowlabel); +if (flowlabel_mask ==LABEL_MAX_MASK ) +print_0xhex (PRINT_JSON ,"flowlabel_mask" ,NULL , + flowlabel_mask); +else +print_0xhex (PRINT_ANY ,"flowlabel_mask" ,"/%#llx" , + flowlabel_mask); + } +print_string (PRINT_FP ,NULL ,"\n" ,"" );close_json_object ();fflush (fp);
@@ -569,6 +600,24 @@ static int flush_rule(struct nlmsghdr *n, void *arg)return 0 ; } +static void iprule_flowlabel_parse (char *arg,__u32 *flowlabel, +__u32 *flowlabel_mask) +{ +char *slash; + + slash =strchr (arg,'/' ); +if (slash !=NULL ) + *slash ='\0' ; +if (get_u32 (flowlabel, arg,0 )) +invarg ("invalid flowlabel" , arg); +if (slash) { +if (get_u32 (flowlabel_mask, slash +1 ,0 )) +invarg ("invalid flowlabel mask" , slash +1 ); + }else { + *flowlabel_mask =LABEL_MAX_MASK ; + } +} +static int iprule_list_flush_or_save (int argc,char **argv,int action) {rtnl_filter_t filter_fn;
@@ -726,6 +775,11 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action)invarg ("invalid dscp\n" , *argv); filter.dscp = dscp; filter.dscpmask =1 ; + }else if (strcmp (*argv,"flowlabel" ) ==0 ) { +NEXT_ARG (); + +iprule_flowlabel_parse (*argv, &filter.flowlabel, + &filter.flowlabel_mask); }else {if (matches (*argv,"dst" ) ==0 ||matches (*argv,"to" ) ==0 ) {
@@ -1011,6 +1065,16 @@ static int iprule_modify(int cmd, int argc, char **argv)if (rtnl_dscp_a2n (&dscp, *argv))invarg ("invalid dscp\n" , *argv);addattr8 (&req.n,sizeof (req),FRA_DSCP , dscp); + }else if (strcmp (*argv,"flowlabel" ) ==0 ) { +__u32 flowlabel, flowlabel_mask; + +NEXT_ARG (); +iprule_flowlabel_parse (*argv, &flowlabel, + &flowlabel_mask); +addattr32 (&req.n,sizeof (req),FRA_FLOWLABEL , +htonl (flowlabel)); +addattr32 (&req.n,sizeof (req),FRA_FLOWLABEL_MASK , +htonl (flowlabel_mask)); }else {int type;
man/man8/ip-rule.8.in +7 -1
@@ -58,7 +58,9 @@ ip-rule \- routing policy database management .IR NUMBER " | " .IR NUMBER "-" NUMBER " ] ] [ " .B tun_id -.IR TUN_ID " ]" +.IR TUN_ID " ] [ " +.B flowlabel +.IR FLOWLABEL\fR[\fB/\fIMASK "] ]" .BR
@@ -322,6 +324,10 @@ In the last case the router does not translate the packets, but masquerades them to this address. Using map-to instead of nat means the same thing. +.TP +.BI flowlabel " FLOWLABEL\fR[\fB/\fIMASK\fR]" +select the IPv6 flow label to match with an optional mask. + .B Warning: Changes to the RPDB made with these commands do not become active immediately. It is assumed that after a script finishes a batch of
Signature · 1 line
2.47.1
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 8 lines · On Mon, 30 Dec 2024 10:58:07 +0200 you wrote:
Add IPv6 flow label support to ip-rule and route get requests following kernel support that was added in kernel commit
6b3099ebca13("Merge branch 'net-fib_rules-add-flow-label-selector-support'").v2:
* Remove new line frominvarg()invocations.[...]
Here is the summary with links:
- [iproute2-next,v2,1/3] Sync uAPI headers
(no matching commit)
- [iproute2-next,v2,2/3] ip: route: Add IPv6 flow label support
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=35ae138e2c94 - [iproute2-next,v2,3/3] iprule: Add flow label support https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=0bd19d4645ce
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html