Blame SOURCES/0069-ip-xfrm-Respect-family-in-deleteall-and-list-command.patch

8def76
From 2f95b860ca09f8dc798204514b06b69cdfa0bd61 Mon Sep 17 00:00:00 2001
8def76
From: Andrea Claudi <aclaudi@redhat.com>
8def76
Date: Fri, 14 Jun 2019 11:04:17 +0200
8def76
Subject: [PATCH] ip-xfrm: Respect family in deleteall and list commands
8def76
8def76
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1656717
8def76
Upstream Status: iproute2.git commit cd21ae40130b4
8def76
Conflicts: on ip xfrm manpage due to missing commit a6af9f2e6195d
8def76
           ("xfrm: add option to hide keys in state output")
8def76
8def76
commit cd21ae40130b4d1ddb3ef500800840e35e7bfad1
8def76
Author: Phil Sutter <phil@nwl.cc>
8def76
Date:   Mon May 6 19:09:56 2019 +0200
8def76
8def76
    ip-xfrm: Respect family in deleteall and list commands
8def76
8def76
    Allow to limit 'ip xfrm {state|policy} list' output to a certain address
8def76
    family and to delete all states/policies by family.
8def76
8def76
    Although preferred_family was already set in filters, the filter
8def76
    function ignored it. To enable filtering despite the lack of other
8def76
    selectors, filter.use has to be set if family is not AF_UNSPEC.
8def76
8def76
    Signed-off-by: Phil Sutter <phil@nwl.cc>
8def76
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
8def76
---
8def76
 ip/xfrm_policy.c   | 6 +++++-
8def76
 ip/xfrm_state.c    | 6 +++++-
8def76
 man/man8/ip-xfrm.8 | 4 ++--
8def76
 3 files changed, 12 insertions(+), 4 deletions(-)
8def76
8def76
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
8def76
index d54402691ca0a..5bb3e873d2e8c 100644
8def76
--- a/ip/xfrm_policy.c
8def76
+++ b/ip/xfrm_policy.c
8def76
@@ -400,6 +400,10 @@ static int xfrm_policy_filter_match(struct xfrm_userpolicy_info *xpinfo,
8def76
 	if (!filter.use)
8def76
 		return 1;
8def76
 
8def76
+	if (filter.xpinfo.sel.family != AF_UNSPEC &&
8def76
+	    filter.xpinfo.sel.family != xpinfo->sel.family)
8def76
+		return 0;
8def76
+
8def76
 	if ((xpinfo->dir^filter.xpinfo.dir)&filter.dir_mask)
8def76
 		return 0;
8def76
 
8def76
@@ -773,7 +777,7 @@ static int xfrm_policy_list_or_deleteall(int argc, char **argv, int deleteall)
8def76
 	char *selp = NULL;
8def76
 	struct rtnl_handle rth;
8def76
 
8def76
-	if (argc > 0)
8def76
+	if (argc > 0 || preferred_family != AF_UNSPEC)
8def76
 		filter.use = 1;
8def76
 	filter.xpinfo.sel.family = preferred_family;
8def76
 
8def76
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
8def76
index 85d959cc4f44f..2441959e98992 100644
8def76
--- a/ip/xfrm_state.c
8def76
+++ b/ip/xfrm_state.c
8def76
@@ -876,6 +876,10 @@ static int xfrm_state_filter_match(struct xfrm_usersa_info *xsinfo)
8def76
 	if (!filter.use)
8def76
 		return 1;
8def76
 
8def76
+	if (filter.xsinfo.family != AF_UNSPEC &&
8def76
+	    filter.xsinfo.family != xsinfo->family)
8def76
+		return 0;
8def76
+
8def76
 	if (filter.id_src_mask)
8def76
 		if (xfrm_addr_match(&xsinfo->saddr, &filter.xsinfo.saddr,
8def76
 				    filter.id_src_mask))
8def76
@@ -1140,7 +1144,7 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
8def76
 	char *idp = NULL;
8def76
 	struct rtnl_handle rth;
8def76
 
8def76
-	if (argc > 0)
8def76
+	if (argc > 0 || preferred_family != AF_UNSPEC)
8def76
 		filter.use = 1;
8def76
 	filter.xsinfo.family = preferred_family;
8def76
 
8def76
diff --git a/man/man8/ip-xfrm.8 b/man/man8/ip-xfrm.8
8def76
index 988cc6aa61d14..d5b9f083147c4 100644
8def76
--- a/man/man8/ip-xfrm.8
8def76
+++ b/man/man8/ip-xfrm.8
8def76
@@ -87,7 +87,7 @@ ip-xfrm \- transform configuration
8def76
 .IR MASK " ] ]"
8def76
 
8def76
 .ti -8
8def76
-.BR "ip xfrm state" " { " deleteall " | " list " } ["
8def76
+.BR ip " [ " -4 " | " -6 " ] " "xfrm state" " { " deleteall " | " list " } ["
8def76
 .IR ID " ]"
8def76
 .RB "[ " mode
8def76
 .IR MODE " ]"
8def76
@@ -244,7 +244,7 @@ ip-xfrm \- transform configuration
8def76
 .IR PTYPE " ]"
8def76
 
8def76
 .ti -8
8def76
-.BR "ip xfrm policy" " { " deleteall " | " list " }"
8def76
+.BR ip " [ " -4 " | " -6 " ] " "xfrm policy" " { " deleteall " | " list " }"
8def76
 .RB "[ " nosock " ]"
8def76
 .RI "[ " SELECTOR " ]"
8def76
 .RB "[ " dir
8def76
-- 
8def76
2.20.1
8def76