Skip to contentSkip to conversation

Add support for xfrm state direction attribute

PATCH Applied Christian Hopps 3 participants 6 messages May 23, 2024 – Jun 5, 2024

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

cover Add support for xfrm state direction attribute

Summary of Changes:

This patchset adds support for setting the new xfrm state direction attribute.

The change also takes into account the existing "offload" direction atttribute. If the user is already setting the direction when enabling offload then that direciton value is used, and the general "dir in|out" need not additionally be specified.

This work was started based on an earlier patch from "Antony Antony" <[email protected]>

Patchset Changes:

  4 files changed, 57 insertions(+), 16 deletions(-)
  include/uapi/linux/xfrm.h |  6 ++++++
  ip/ipxfrm.c               | 12 ++++++++++++
  ip/xfrm_state.c           | 49 +++++++++++++++++++++++++++++++----------------
  man/man8/ip-xfrm.8        |  6 ++++++
#1 lore raw

PATCH 1/2 xfrm: add SA direction attribute

Add support for new SA direction netlink attribute.

---
 include/uapi/linux/xfrm.h |  6 +++++
 ip/ipxfrm.c               | 12 ++++++++++
 ip/xfrm_state.c           | 49 ++++++++++++++++++++++++++-------------
 3 files changed, 51 insertions(+), 16 deletions(-)
include/uapi/linux/xfrm.h +6 -0
index 43efaeca..dccfd437 100644
@@ -141,6 +141,11 @@ enum {
 	XFRM_POLICY_MAX	= 3
 };
 
+enum xfrm_sa_dir {
+	XFRM_SA_DIR_IN	= 1,
+	XFRM_SA_DIR_OUT = 2
+};
+
 enum {
 	XFRM_SHARE_ANY,		/* No limitations */
 	XFRM_SHARE_SESSION,	/* For this session only */
@@ -315,6 +320,7 @@ enum xfrm_attr_type_t {
 	XFRMA_SET_MARK_MASK,	/* __u32 */
 	XFRMA_IF_ID,		/* __u32 */
 	XFRMA_MTIMER_THRESH,	/* __u32 in seconds for input SA */
+	XFRMA_SA_DIR,		/* __u8 */
 	__XFRMA_MAX
 
 #define XFRMA_OUTPUT_MARK XFRMA_SET_MARK	/* Compatibility */
ip/ipxfrm.c +12 -0
index b78c712d..90d25aac 100644
@@ -904,6 +904,18 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, FILE *fp,
 		fprintf(fp, "tfcpad %u", tfcpad);
 		fprintf(fp, "%s", _SL_);
 	}
+	if (tb[XFRMA_SA_DIR]) {
+		__u8 dir = rta_getattr_u8(tb[XFRMA_SA_DIR]);
+
+		fprintf(fp, "\tdir ");
+		if (dir == XFRM_SA_DIR_IN)
+			fprintf(fp, "in");
+		else if (dir == XFRM_SA_DIR_OUT)
+			fprintf(fp, "out");
+		else
+			fprintf(fp, "other (%d)", dir);
+		fprintf(fp, "%s", _SL_);
+	}
 }
 
 static int xfrm_selector_iszero(struct xfrm_selector *s)
ip/xfrm_state.c +33 -16

126 lines not on this page · raw message

Signature · 1 line
2.45.1
Applied
#2 lore raw

Re: [PATCH iproute-next v1 1/2] xfrm: add SA direction attribute

Quoted 30 lines · Christian Hopps

Add support for new SA direction netlink attribute.

---
 include/uapi/linux/xfrm.h |  6 +++++
 ip/ipxfrm.c               | 12 ++++++++++
 ip/xfrm_state.c           | 49 ++++++++++++++++++++++++++-------------
 3 files changed, 51 insertions(+), 16 deletions(-)
ip/xfrm_state.c +3 -3
@@ -251,22 +251,20 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a
 	return 0;
 }
 
-static bool xfrm_offload_dir_parse(__u8 *dir, int *argcp, char ***argvp)
+static void xfrm_dir_parse(__u8 *dir, int *argcp, char ***argvp)
 {
 	int argc = *argcp;
 	char **argv = *argvp;
 
 	if (strcmp(*argv, "in") == 0)
-		*dir = XFRM_OFFLOAD_INBOUND;
+		*dir = XFRM_SA_DIR_IN;
 	else if (strcmp(*argv, "out") == 0)
-		*dir = 0;
+		*dir = XFRM_SA_DIR_OUT;
 	else

ip/xfrm_state.c static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a · line 270

Quoted 10 lines
ip/xfrm_state.c +1 -3
-		return false;
+		invarg("DIR value is not \"in\" or \"out\"", *argv);
 
 	*argcp = argc;
 	*argvp = argv;
-
-	return true;
 }
 
 static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)

next time send a refactoring patch when changing existing code like this. I wasted a lot of time trying to figure out if you are changing ABI with the move from XFRM_OFFLOAD_INBOUND to XFRM_SA_DIR_IN/OUT here.

applied to iproute2-next

#3 lore raw

Re: [PATCH iproute-next v1 1/2] xfrm: add SA direction attribute

Thanks!

I'm new to this process so I'd certainly like to do this the right way next time. Should I have labeled the patch as "refactoring" as well? Without the addition of the new attribute value though there was nothing to refactor (be shared) so not sure how I would have split the patch up into 2 patches if that is what you were asking for.

Thanks for your patience and time,
Chris.

Quoted 50 lines · David Ahern
Quoted 33 lines · Christian Hopps

Add support for new SA direction netlink attribute.

---

include/uapi/linux/xfrm.h |  6 +++++
ip/ipxfrm.c               | 12 ++++++++++
ip/xfrm_state.c           | 49 ++++++++++++++++++++++++++-------------
3 files changed, 51 insertions(+), 16 deletions(-)
ip/xfrm_state.c +3 -3
@@ -251,22 +251,20 @@ static int xfrm_state_extra_flag_parse(__u32 *extra_flags, int *argcp, char ***a
 return 0;
 }
 
-static bool xfrm_offload_dir_parse(__u8 *dir, int *argcp, char ***argvp)
+static void xfrm_dir_parse(__u8 *dir, int *argcp, char ***argvp)
 {
 int argc = *argcp;
 char **argv = *argvp;
 
 if (strcmp(*argv, "in") == 0)
- *dir = XFRM_OFFLOAD_INBOUND;
+ *dir = XFRM_SA_DIR_IN;
 else if (strcmp(*argv, "out") == 0)
- *dir = 0;
+ *dir = XFRM_SA_DIR_OUT;

else
- return false;
+ invarg("DIR value is not \"in\" or \"out\"", *argv);

Quoted 7 lines

*argcp = argc;
*argvp = argv;
-
- return true;
}

static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)

next time send a refactoring patch when changing existing code like this. I wasted a lot of time trying to figure out if you are changing ABI with the move from XFRM_OFFLOAD_INBOUND to XFRM_SA_DIR_IN/OUT here.

applied to iproute2-next

#4 lore raw

PATCH 2/2 xfrm: document new SA direction option

In reply to Christian Hopps
---
 man/man8/ip-xfrm.8 | 6 ++++++
 1 file changed, 6 insertions(+)
man/man8/ip-xfrm.8 +6 -0
index 6dc73d23..960779dd 100644
@@ -36,6 +36,8 @@ ip-xfrm \- transform configuration
 .IR MASK " ] ]"
 .RB "[ " reqid
 .IR REQID " ]"
+.RB "[ " dir
+.IR SA-DIR " ]"
 .RB "[ " seq
 .IR SEQ " ]"
 .RB "[ " replay-window
@@ -165,6 +167,10 @@ ip-xfrm \- transform configuration
 .IR MODE " := "
 .BR transport " | " tunnel " | " beet " | " ro " | " in_trigger
 
+.ti -8
+.IR SA-DIR " := "
+.BR in " | " out
+
 .ti -8
 .IR FLAG-LIST " := [ " FLAG-LIST " ] " FLAG
 
Signature · 1 line
2.45.1
#5 lore raw
In reply to Christian Hopps
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 11 lines · On Thu, 23 May 2024 11:17:05 -0400 you wrote:

Summary of Changes:

This patchset adds support for setting the new xfrm state direction attribute.

The change also takes into account the existing "offload" direction atttribute. If the user is already setting the direction when enabling offload then that direciton value is used, and the general "dir in|out" need not additionally be specified.

[...]

Here is the summary with links:
- [iproute-next,v1,1/2] xfrm: add SA direction attribute (no matching commit)
- [iproute-next,v1,2/2] xfrm: document new SA direction option

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=7cf98ef28b61

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html