xfrm: enable to manage default policies
Subsystems (3)
PATCH 1/1 xfrm: enable to manage default policies
Two new commands to manage default policies:
- ip xfrm policy setdefault
- ip xfrm policy getdefault
And the corresponding part in 'ip xfrm monitor'.
--- include/uapi/linux/xfrm.h | 15 +++-- ip/xfrm.h | 1 + ip/xfrm_monitor.c | 3 + ip/xfrm_policy.c | 121 ++++++++++++++++++++++++++++++++++++++ man/man8/ip-xfrm.8 | 12 ++++ 5 files changed, 146 insertions(+), 6 deletions(-)
include/uapi/linux/xfrm.h +9 -6
@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask; -__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };/* backwards compatibility for userspace */
ip/xfrm.h +1 -0
@@ -132,6 +132,7 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,void xfrm_policy_info_print (struct xfrm_userpolicy_info *xpinfo,struct rtattr *tb[],FILE *fp,const char *prefix,const char *title); +int xfrm_policy_default_print (struct nlmsghdr *n,FILE *fp);int xfrm_id_parse (xfrm_address_t *saddr,struct xfrm_id *id,__u16 *family,int loose,int *argcp,char ***argvp);int xfrm_mode_parse (__u8 *mode,int *argcp,char ***argvp);
ip/xfrm_monitor.c +3 -0
@@ -323,6 +323,9 @@ static int xfrm_accept_msg(struct rtnl_ctrl_data *ctrl,case XFRM_MSG_MAPPING :xfrm_mapping_print (n, arg);return 0 ; +case XFRM_MSG_GETDEFAULT : +xfrm_policy_default_print (n, arg); +return 0 ;default :break ; }
ip/xfrm_policy.c +121 -0
139 lines not on this page · raw message
man/man8/ip-xfrm.8 +12 -0
@@ -298,6 +298,18 @@ ip-xfrm \- transform configuration .RB "[ " hthresh6 .IR LBITS " " RBITS " ]" +.ti -8 +.B "ip xfrm policy setdefault" +.IR DIR +.IR ACTION " [ " +.IR DIR +.IR ACTION " ] [ " +.IR DIR +.IR ACTION " ]" + +.ti -8 +.B "ip xfrm policy getdefault" + .ti -8 .IR SELECTOR " :=" .RB "[ " src
Signature · 1 line
2.33.0
PATCH v2 1/1 xfrm: enable to manage default policies
Two new commands to manage default policies:
- ip xfrm policy setdefault
- ip xfrm policy getdefault
And the corresponding part in 'ip xfrm monitor'.
---
v1 -> v2:
rebase and resent (kernel patches are now in Linus's tree)
include/uapi/linux/xfrm.h | 15 +++-- ip/xfrm.h | 1 + ip/xfrm_monitor.c | 3 + ip/xfrm_policy.c | 121 ++++++++++++++++++++++++++++++++++++++ man/man8/ip-xfrm.8 | 12 ++++ 5 files changed, 146 insertions(+), 6 deletions(-)
include/uapi/linux/xfrm.h +9 -6
@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)
@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask; -__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };/* backwards compatibility for userspace */
ip/xfrm.h +1 -0
@@ -132,6 +132,7 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,void xfrm_policy_info_print (struct xfrm_userpolicy_info *xpinfo,struct rtattr *tb[],FILE *fp,const char *prefix,const char *title); +int xfrm_policy_default_print (struct nlmsghdr *n,FILE *fp);int xfrm_id_parse (xfrm_address_t *saddr,struct xfrm_id *id,__u16 *family,int loose,int *argcp,char ***argvp);int xfrm_mode_parse (__u8 *mode,int *argcp,char ***argvp);
ip/xfrm_monitor.c +3 -0
@@ -323,6 +323,9 @@ static int xfrm_accept_msg(struct rtnl_ctrl_data *ctrl,case XFRM_MSG_MAPPING :xfrm_mapping_print (n, arg);return 0 ; +case XFRM_MSG_GETDEFAULT : +xfrm_policy_default_print (n, arg); +return 0 ;default :break ; }
ip/xfrm_policy.c +121 -0
139 lines not on this page · raw message
man/man8/ip-xfrm.8 +12 -0
@@ -298,6 +298,18 @@ ip-xfrm \- transform configuration .RB "[ " hthresh6 .IR LBITS " " RBITS " ]" +.ti -8 +.B "ip xfrm policy setdefault" +.IR DIR +.IR ACTION " [ " +.IR DIR +.IR ACTION " ] [ " +.IR DIR +.IR ACTION " ]" + +.ti -8 +.B "ip xfrm policy getdefault" + .ti -8 .IR SELECTOR " :=" .RB "[ " src
Signature · 1 line
2.33.0
Quoted 27 lines · Nicolas Dichtel
include/uapi/linux/xfrm.h +3
-5@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask;
include/uapi/linux/xfrm.h struct xfrm_user_offload { · line 525
Quoted 10 lines
include/uapi/linux/xfrm.h +6
-1-__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };/* backwards compatibility for userspace */
that is already updated in iproute2-next.
Quoted 86 lines
ip/xfrm_policy.c +78
-0@@ -1124,6 +1126,121 @@ static int xfrm_spd_getinfo(int argc, char **argv)return 0 ; } +static int xfrm_spd_setdefault (int argc,char **argv) +{ +struct rtnl_handle rth; +struct { +struct nlmsghdr n; +struct xfrm_userpolicy_default up; + } req = { + .n.nlmsg_len =NLMSG_LENGTH (sizeof (struct xfrm_userpolicy_default )), + .n.nlmsg_flags =NLM_F_REQUEST , + .n.nlmsg_type =XFRM_MSG_SETDEFAULT , + }; + +while (argc >0 ) { +if (strcmp (*argv,"in" ) ==0 ) { +if (req.up.in) +duparg ("in" , *argv); + +NEXT_ARG (); +if (strcmp (*argv,"block" ) ==0 ) + req.up.in =XFRM_USERPOLICY_BLOCK ; +else if (strcmp (*argv,"accept" ) ==0 ) + req.up.in =XFRM_USERPOLICY_ACCEPT ; +else +invarg ("in policy value is invalid" , *argv); + }else if (strcmp (*argv,"fwd" ) ==0 ) { +if (req.up.fwd) +duparg ("fwd" , *argv); + +NEXT_ARG (); +if (strcmp (*argv,"block" ) ==0 ) + req.up.fwd =XFRM_USERPOLICY_BLOCK ; +else if (strcmp (*argv,"accept" ) ==0 ) + req.up.fwd =XFRM_USERPOLICY_ACCEPT ; +else +invarg ("fwd policy value is invalid" , *argv); + }else if (strcmp (*argv,"out" ) ==0 ) { +if (req.up.out) +duparg ("out" , *argv); + +NEXT_ARG (); +if (strcmp (*argv,"block" ) ==0 ) + req.up.out =XFRM_USERPOLICY_BLOCK ; +else if (strcmp (*argv,"accept" ) ==0 ) + req.up.out =XFRM_USERPOLICY_ACCEPT ; +else +invarg ("out policy value is invalid" , *argv); + }else { +invarg ("unknown direction" , *argv); + } + + argc--; argv++; + } + +if (rtnl_open_byproto (&rth,0 ,NETLINK_XFRM ) <0 ) +exit (1 ); + +if (rtnl_talk (&rth, &req.n,NULL ) <0 ) +exit (2 ); + +rtnl_close (&rth); + +return 0 ; +} + +int xfrm_policy_default_print (struct nlmsghdr *n,FILE *fp) +{ +struct xfrm_userpolicy_default *up =NLMSG_DATA (n); +int len = n->nlmsg_len -NLMSG_SPACE (sizeof (*up)); + +if (len <0 ) { +fprintf (stderr, +"BUG: short nlmsg len %u (expect %lu) for XFRM_MSG_GETDEFAULT\n" , + n->nlmsg_len,NLMSG_SPACE (sizeof (*up))); +return -1 ; + } + +fprintf (fp,"Default policies:\n" ); + fprintf(fp, " in: %s\n",
ip/xfrm_policy.c static int xfrm_spd_getinfo(int argc, char **argv) · line 1216
Quoted 10 lines
ip/xfrm_policy.c +10
-0+ up->in == XFRM_USERPOLICY_BLOCK ? "block" : "accept"); +fprintf (fp," fwd: %s\n" , + up->fwd ==XFRM_USERPOLICY_BLOCK ?"block" :"accept" ); +fprintf (fp," out: %s\n" , + up->out ==XFRM_USERPOLICY_BLOCK ?"block" :"accept" ); +fflush (fp); + +return 0 ; +} +
create xfrm_str_to_policy and xfrm_policy_to_str helpers for the conversions between "block" and "accept" to XFRM_USERPOLICY_BLOCK and XFRM_USERPOLICY_ACCEPT and back.
Le 21/10/2021 à 16:55, David Ahern a écrit :
Quoted 37 lines · Nicolas Dichtel
Quoted 36 lines
include/uapi/linux/xfrm.h +9
-6@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask; -__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };
Quoted 3 lines
include/uapi/linux/xfrm.h struct xfrm_user_offload { · line 525
Quoted 1 line
include/uapi/linux/xfrm.h +0
-0/* backwards compatibility for userspace */ that is already updated in iproute2-next.
But this is needed for the iproute2 also. These will be in the linux v5.15 release.
[snip]
Quoted 4 lines
create
xfrm_str_to_policyandxfrm_policy_to_strhelpers for the conversions between "block" and "accept" toXFRM_USERPOLICY_BLOCKandXFRM_USERPOLICY_ACCEPTand back.
Ok.
Quoted 40 lines · Nicolas Dichtel
Le 21/10/2021 à 16:55, David Ahern a écrit :
Quoted 37 lines · Nicolas Dichtel
Quoted 36 lines
include/uapi/linux/xfrm.h +9
-6@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask; -__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };
Quoted 4 lines
Quoted 3 lines
include/uapi/linux/xfrm.h struct xfrm_user_offload { · line 525
Quoted 1 line
include/uapi/linux/xfrm.h +0
-0/* backwards compatibility for userspace */ that is already updated in iproute2-next.
But this is needed for the iproute2 also. These will be in the linux v5.15 release.
new functionality is added to -next first; that's why it exists.
Quoted 9 lines
[snip]
Quoted 4 lines
create
xfrm_str_to_policyandxfrm_policy_to_strhelpers for the conversions between "block" and "accept" toXFRM_USERPOLICY_BLOCKandXFRM_USERPOLICY_ACCEPTand back.Ok.
Le 22/10/2021 à 00:10, David Ahern a écrit :
[snip]
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
that is already updated in iproute2-next.
But this is needed for the iproute2 also. These will be in the linux v5.15 release.
new functionality is added to -next first; that's why it exists.
My point was that uapi from iproute2/main was not in sync with linus tree. This is now fixed.
Regards,
Nicolas
Quoted 38 lines · On Thu, 21 Oct 2021 23:23:01 +0200 Nicolas Dichtel <[email protected]>…
Le 21/10/2021 à 16:55, David Ahern a écrit :
Quoted 37 lines · Nicolas Dichtel
Quoted 36 lines
include/uapi/linux/xfrm.h +9
-6@@ -213,13 +213,13 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_MAPPING, +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING + XFRM_MSG_SETDEFAULT,#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT XFRM_MSG_GETDEFAULT,#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT - - XFRM_MSG_MAPPING, -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX };#define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1)@@ -514,9 +514,12 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { -#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8) -__u8 dirmask; -__u8 action; +#define XFRM_USERPOLICY_UNSPEC 0 +#define XFRM_USERPOLICY_BLOCK 1 +#define XFRM_USERPOLICY_ACCEPT 2 +__u8 in; +__u8 fwd; +__u8 out; };
Quoted 4 lines
Quoted 3 lines
include/uapi/linux/xfrm.h struct xfrm_user_offload { · line 525
Quoted 1 line
include/uapi/linux/xfrm.h +0
-0/* backwards compatibility for userspace */ that is already updated in iproute2-next.
But this is needed for the iproute2 also. These will be in the linux v5.15 release.
Yes the header is already in iproute2 just not the code to use it.
PS: Need a volunteer to update ip xfrm to print in JSON like the rest of ip sub commands.
PATCH v2 1/1 xfrm: enable to manage default policies
In reply to David AhernTwo new commands to manage default policies:
- ip xfrm policy setdefault
- ip xfrm policy getdefault
And the corresponding part in 'ip xfrm monitor'.
---
v1 -> v2: introduce xfrm_str_to_policy/xfrm_policy_to_str
ip/xfrm.h | 1 + ip/xfrm_monitor.c | 3 + ip/xfrm_policy.c | 133 +++++++++++++++++++++++++++++++++++++++++++++ man/man8/ip-xfrm.8 | 12 ++++ 4 files changed, 149 insertions(+)
ip/xfrm.h +1 -0
@@ -132,6 +132,7 @@ void xfrm_state_info_print(struct xfrm_usersa_info *xsinfo,void xfrm_policy_info_print (struct xfrm_userpolicy_info *xpinfo,struct rtattr *tb[],FILE *fp,const char *prefix,const char *title); +int xfrm_policy_default_print (struct nlmsghdr *n,FILE *fp);int xfrm_id_parse (xfrm_address_t *saddr,struct xfrm_id *id,__u16 *family,int loose,int *argcp,char ***argvp);int xfrm_mode_parse (__u8 *mode,int *argcp,char ***argvp);
ip/xfrm_monitor.c +3 -0
@@ -323,6 +323,9 @@ static int xfrm_accept_msg(struct rtnl_ctrl_data *ctrl,case XFRM_MSG_MAPPING :xfrm_mapping_print (n, arg);return 0 ; +case XFRM_MSG_GETDEFAULT : +xfrm_policy_default_print (n, arg); +return 0 ;default :break ; }
ip/xfrm_policy.c +133 -0
151 lines not on this page · raw message
man/man8/ip-xfrm.8 +12 -0
@@ -298,6 +298,18 @@ ip-xfrm \- transform configuration .RB "[ " hthresh6 .IR LBITS " " RBITS " ]" +.ti -8 +.B "ip xfrm policy setdefault" +.IR DIR +.IR ACTION " [ " +.IR DIR +.IR ACTION " ] [ " +.IR DIR +.IR ACTION " ]" + +.ti -8 +.B "ip xfrm policy getdefault" + .ti -8 .IR SELECTOR " :=" .RB "[ " src
Signature · 1 line
2.33.0
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 9 lines · On Mon, 25 Oct 2021 10:17:06 +0200 you wrote:
Two new commands to manage default policies:
- ip xfrm policy setdefault
- ip xfrm policy getdefaultAnd the corresponding part in 'ip xfrm monitor'.
Signed-off-by Nicolas Dichtel <[email protected]>[...]
Here is the summary with links:
- [iproute2-next,v2] xfrm: enable to manage default policies
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=76b30805f9f6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html