]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip-xfrm: add pcpu-num support
authorSabrina Dubroca <sd@queasysnail.net>
Wed, 29 Oct 2025 11:06:16 +0000 (12:06 +0100)
committerDavid Ahern <dsahern@kernel.org>
Mon, 3 Nov 2025 16:42:50 +0000 (09:42 -0700)
The kernel supports passing the XFRMA_SA_PCPU attribute when creating
a state (via NEWSA or ALLOCSPI). Add a "pcpu-num" argument, and print
XFRMA_SA_PCPU when the kernel provides it.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipxfrm.c
ip/xfrm_state.c
man/man8/ip-xfrm.8

index b15cc0002e5bdf7ac01a1b7c3949da84db3a1df6..586d24fb8594d025af8556979655b8af9a66936a 100644 (file)
@@ -919,6 +919,12 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family, FILE *fp,
                        fprintf(fp, "other (%d)", dir);
                fprintf(fp, "%s", _SL_);
        }
+       if (tb[XFRMA_SA_PCPU]) {
+               __u32 pcpu_num = rta_getattr_u32(tb[XFRMA_SA_PCPU]);
+
+               fprintf(fp, "\tpcpu-num %u", pcpu_num);
+               fprintf(fp, "%s", _SL_);
+       }
 }
 
 static int xfrm_selector_iszero(struct xfrm_selector *s)
index fbb1f91371830ec862358c090b966648dd03f556..252a7a5341943033ada792848848fec455a8a977 100644 (file)
@@ -47,9 +47,9 @@ static void usage(void)
                "        [ coa ADDR[/PLEN] ] [ ctx CTX ] [ extra-flag EXTRA-FLAG-LIST ]\n"
                "        [ offload [ crypto | packet ] dev DEV dir DIR ]\n"
                "        [ output-mark OUTPUT-MARK [ mask MASK ] ]\n"
-               "        [ if_id IF_ID ] [ tfcpad LENGTH ]\n"
+               "        [ if_id IF_ID ] [ tfcpad LENGTH ] [ pcpu-num CPUNUM ]\n"
                "Usage: ip xfrm state allocspi ID [ mode MODE ] [ mark MARK [ mask MASK ] ]\n"
-               "        [ reqid REQID ] [ dir DIR ] [ seq SEQ ] [ min SPI max SPI ]\n"
+               "        [ reqid REQID ] [ dir DIR ] [ seq SEQ ] [ min SPI max SPI ] [ pcpu-num CPUNUM ]\n"
                "Usage: ip xfrm state { delete | get } ID [ mark MARK [ mask MASK ] ]\n"
                "Usage: ip xfrm state deleteall [ ID ] [ mode MODE ] [ reqid REQID ]\n"
                "        [ flag FLAG-LIST ]\n"
@@ -307,6 +307,7 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
        } ctx = {};
        struct xfrm_mark output_mark = {0, 0};
        bool is_if_id_set = false;
+       __u32 pcpu_num = -1;
        __u32 if_id = 0;
        __u32 tfcpad = 0;
 
@@ -458,6 +459,10 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
                } else if (strcmp(*argv, "dir") == 0) {
                        NEXT_ARG();
                        xfrm_dir_parse(&dir, &argc, &argv);
+               } else if (strcmp(*argv, "pcpu-num") == 0) {
+                       NEXT_ARG();
+                       if (get_u32(&pcpu_num, *argv, 0))
+                               invarg("value after \"pcpu-num\" is invalid", *argv);
                } else {
                        /* try to assume ALGO */
                        int type = xfrm_algotype_getbyname(*argv);
@@ -767,6 +772,9 @@ static int xfrm_state_modify(int cmd, unsigned int flags, int argc, char **argv)
                }
        }
 
+       if (pcpu_num != -1)
+               addattr32(&req.n, sizeof(req.buf), XFRMA_SA_PCPU, pcpu_num);
+
        if (req.xsinfo.family == AF_UNSPEC)
                req.xsinfo.family = AF_INET;
 
@@ -796,6 +804,7 @@ static int xfrm_state_allocspi(int argc, char **argv)
        char *maxp = NULL;
        struct xfrm_mark mark = {0, 0};
        struct nlmsghdr *answer;
+       __u32 pcpu_num = -1;
        __u8 dir = 0;
 
        while (argc > 0) {
@@ -831,6 +840,10 @@ static int xfrm_state_allocspi(int argc, char **argv)
                } else if (strcmp(*argv, "dir") == 0) {
                        NEXT_ARG();
                        xfrm_dir_parse(&dir, &argc, &argv);
+               } else if (strcmp(*argv, "pcpu-num") == 0) {
+                       NEXT_ARG();
+                       if (get_u32(&pcpu_num, *argv, 0))
+                               invarg("value after \"pcpu-num\" is invalid", *argv);
                } else {
                        /* try to assume ID */
                        if (idp)
@@ -901,6 +914,9 @@ static int xfrm_state_allocspi(int argc, char **argv)
                }
        }
 
+       if (pcpu_num != -1)
+               addattr32(&req.n, sizeof(req.buf), XFRMA_SA_PCPU, pcpu_num);
+
        if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
                exit(1);
 
index 3efd617247d7f47c7b33d69ce542bb97bbaf2321..4c278ccba38c824dc474c757e0f41ba73bfdb77c 100644 (file)
@@ -76,6 +76,8 @@ ip-xfrm \- transform configuration
 .IR DIR " ]"
 .RB "[ " tfcpad
 .IR LENGTH " ]"
+.RB "[ " pcpu-num
+.IR CPUNUM " ]"
 
 .ti -8
 .B "ip xfrm state allocspi"
@@ -94,6 +96,8 @@ ip-xfrm \- transform configuration
 .I SPI
 .B max
 .IR SPI " ]"
+.RB "[ " pcpu-num
+.IR CPUNUM " ]"
 
 .ti -8
 .BR "ip xfrm state" " { " delete " | " get " } "