]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
xfrm_{state, policy}: Allow to deleteall polices/states with marks
authorThomas Egerer <thomas.egerer@secunet.com>
Mon, 30 Oct 2017 18:11:46 +0000 (19:11 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 7 Nov 2017 02:12:30 +0000 (11:12 +0900)
Using 'ip deleteall' with policies that have marks, fails unless you
eplicitely specify the mark values. This is very uncomfortable when
bulk-deleting policies and states. With this patch all relevant states
and policies are wiped by 'ip deleteall' regardless of their mark
values.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
ip/xfrm_policy.c
ip/xfrm_state.c

index e716a7d0fe77ab32c69517cc81b05715d1ea3409..09f96dbb567c6e0b93c91c787b5a3a14afc20795 100644 (file)
@@ -753,6 +753,15 @@ static int xfrm_policy_keep(const struct sockaddr_nl *who,
        xpid->dir = xpinfo->dir;
        xpid->index = xpinfo->index;
 
+       if (tb[XFRMA_MARK]) {
+               int r = addattr_l(new_n, xb->size, XFRMA_MARK,
+                               (void *)RTA_DATA(tb[XFRMA_MARK]), tb[XFRMA_MARK]->rta_len);
+               if (r < 0) {
+                       fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
+                       exit(1);
+               }
+       }
+
        xb->offset += new_n->nlmsg_len;
        xb->nlmsg_count++;
 
index 99fdec2325ec026856b458484865bbf4c939450a..ba5d6639dab87792375ab4bab85a23129b7a9773 100644 (file)
@@ -1080,6 +1080,7 @@ static int xfrm_state_keep(const struct sockaddr_nl *who,
        int len = n->nlmsg_len;
        struct nlmsghdr *new_n;
        struct xfrm_usersa_id *xsid;
+       struct rtattr *tb[XFRMA_MAX+1];
 
        if (n->nlmsg_type != XFRM_MSG_NEWSA) {
                fprintf(stderr, "Not a state: %08x %08x %08x\n",
@@ -1116,6 +1117,17 @@ static int xfrm_state_keep(const struct sockaddr_nl *who,
        addattr_l(new_n, xb->size, XFRMA_SRCADDR, &xsinfo->saddr,
                  sizeof(xsid->daddr));
 
+       parse_rtattr(tb, XFRMA_MAX, XFRMS_RTA(xsinfo), len);
+
+       if (tb[XFRMA_MARK]) {
+               int r = addattr_l(new_n, xb->size, XFRMA_MARK,
+                               (void *)RTA_DATA(tb[XFRMA_MARK]), tb[XFRMA_MARK]->rta_len);
+               if (r < 0) {
+                       fprintf(stderr, "%s: XFRMA_MARK failed\n", __func__);
+                       exit(1);
+               }
+       }
+
        xb->offset += new_n->nlmsg_len;
        xb->nlmsg_count++;