Skip to contentSkip to conversation

include/linux: update xfrm.h

PATCH Superseded Nicolas Dichtel 2 participants 5 messages Mar 19, 2014 – Mar 20, 2014

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 include/linux: update xfrm.h

---

Note that this patch is based on net-next.

 include/linux/xfrm.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/xfrm.h +10 -0
index 341c3c951dac..fa2ecb2eb998 100644
@@ -298,6 +298,8 @@ enum xfrm_attr_type_t {
 	XFRMA_TFCPAD,		/* __u32 */
 	XFRMA_REPLAY_ESN_VAL,	/* struct xfrm_replay_esn */
 	XFRMA_SA_EXTRA_FLAGS,	/* __u32 */
+	XFRMA_PROTO,		/* __u8 */
+	XFRMA_ADDRESS_FILTER,	/* struct xfrm_address_filter */
 	__XFRMA_MAX
 
 #define XFRMA_MAX (__XFRMA_MAX - 1)
@@ -474,6 +476,14 @@ struct xfrm_user_mapping {
 	__be16				new_sport;
 };
 
+struct xfrm_address_filter {
+	xfrm_address_t			saddr;
+	xfrm_address_t			daddr;
+	__u16				family;
+	__u8				splen;
+	__u8				dplen;
+};
+
 /* backwards compatibility for userspace */
 #define XFRMGRP_ACQUIRE		1
 #define XFRMGRP_EXPIRE		2
Signature · 1 line
1.8.5.4
#1 lore raw

PATCH v2 2/2 ipxfrm: allow to setup filter when dumping SA

It's now possible to filter SA directly into the kernel by specifying XFRMA_PROTO and/or XFRMA_ADDRESS_FILTER.

---

Note that this patch is intended to work with net-next.

 ip/xfrm_state.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
ip/xfrm_state.c +29 -1
index 140a4503b799..8295223f8118 100644
@@ -1136,7 +1136,35 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
 		}
 
 	} else {
-		if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETSA) < 0) {
+		struct xfrm_address_filter addrfilter;
+		struct {
+			struct nlmsghdr n;
+			char buf[NLMSG_BUF_SIZE];
+		} req;
+
+		memset(&addrfilter, 0, sizeof(addrfilter));
+		addrfilter.family = filter.xsinfo.family;
+		memcpy(&addrfilter.saddr, &filter.xsinfo.saddr,
+		       sizeof(xfrm_address_t));
+		addrfilter.splen = filter.id_src_mask;
+		memcpy(&addrfilter.daddr, &filter.xsinfo.id.daddr,
+		       sizeof(xfrm_address_t));
+		addrfilter.dplen = filter.id_dst_mask;
+
+		memset(&req, 0, sizeof(req));
+		req.n.nlmsg_len = NLMSG_HDRLEN;
+		req.n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
+		req.n.nlmsg_type = XFRM_MSG_GETSA;
+		req.n.nlmsg_pid = 0;
+		req.n.nlmsg_seq = rth.dump = ++rth.seq;
+
+		if (filter.xsinfo.id.proto)
+			addattr8(&req.n, sizeof(req), XFRMA_PROTO,
+				 filter.xsinfo.id.proto);
+		addattr_l(&req.n, sizeof(req), XFRMA_ADDRESS_FILTER,
+			  &addrfilter, sizeof(addrfilter));
+
+		if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
Signature · 1 line
1.8.5.4
#2 lore raw

Re: [PATCH v2 iproute2 -next 2/2] ipxfrm: allow to setup filter when dumping SA

Quoted 14 lines · On Wed, 19 Mar 2014 17:52:08 +0100 Nicolas Dichtel <[email protected]>…
ip/xfrm_state.c +5 -1
index 140a4503b799..8295223f8118 100644
@@ -1136,7 +1136,35 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
 		}
 
 	} else {
-		if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETSA) < 0) {
+		struct xfrm_address_filter addrfilter;
+		struct {
+			struct nlmsghdr n;
+			char buf[NLMSG_BUF_SIZE];
+		} req;

ip/xfrm_state.c static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall) · line 1153

Quoted 10 lines
ip/xfrm_state.c +10 -0
+
+		memset(&addrfilter, 0, sizeof(addrfilter));
+		addrfilter.family = filter.xsinfo.family;
+		memcpy(&addrfilter.saddr, &filter.xsinfo.saddr,
+		       sizeof(xfrm_address_t));
+		addrfilter.splen = filter.id_src_mask;
+		memcpy(&addrfilter.daddr, &filter.xsinfo.id.daddr,
+		       sizeof(xfrm_address_t));
+		addrfilter.dplen = filter.id_dst_mask;
+

I prefer to see C99 initializers for stack variables when possible instead of using memset().

#3 lore raw

PATCH v3 1/2 include/linux: update xfrm.h

---
Note that this patch is based on net-next.

v3: use C99 initializers

 include/linux/xfrm.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/xfrm.h +10 -0
index 341c3c951dac..fa2ecb2eb998 100644
@@ -298,6 +298,8 @@ enum xfrm_attr_type_t {
 	XFRMA_TFCPAD,		/* __u32 */
 	XFRMA_REPLAY_ESN_VAL,	/* struct xfrm_replay_esn */
 	XFRMA_SA_EXTRA_FLAGS,	/* __u32 */
+	XFRMA_PROTO,		/* __u8 */
+	XFRMA_ADDRESS_FILTER,	/* struct xfrm_address_filter */
 	__XFRMA_MAX
 
 #define XFRMA_MAX (__XFRMA_MAX - 1)
@@ -474,6 +476,14 @@ struct xfrm_user_mapping {
 	__be16				new_sport;
 };
 
+struct xfrm_address_filter {
+	xfrm_address_t			saddr;
+	xfrm_address_t			daddr;
+	__u16				family;
+	__u8				splen;
+	__u8				dplen;
+};
+
 /* backwards compatibility for userspace */
 #define XFRMGRP_ACQUIRE		1
 #define XFRMGRP_EXPIRE		2
Signature · 1 line
1.8.5.4
#4 lore raw

PATCH v3 2/2 ipxfrm: allow to setup filter when dumping SA

It's now possible to filter SA directly into the kernel by specifying XFRMA_PROTO and/or XFRMA_ADDRESS_FILTER.

---
Note that this patch is intended to work with net-next.

v3: use C99 initializers

 ip/xfrm_state.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
ip/xfrm_state.c +26 -1
index 140a4503b799..0cd5c2f43065 100644
@@ -1136,7 +1136,32 @@ static int xfrm_state_list_or_deleteall(int argc, char **argv, int deleteall)
 		}
 
 	} else {
-		if (rtnl_wilddump_request(&rth, preferred_family, XFRM_MSG_GETSA) < 0) {
+		struct xfrm_address_filter addrfilter = {
+			.saddr = filter.xsinfo.saddr,
+			.daddr = filter.xsinfo.id.daddr,
+			.family = filter.xsinfo.family,
+			.splen = filter.id_src_mask,
+			.dplen = filter.id_dst_mask,
+		};
+		struct {
+			struct nlmsghdr n;
+			char buf[NLMSG_BUF_SIZE];
+		} req;
+
+		memset(&req, 0, sizeof(req));
+		req.n.nlmsg_len = NLMSG_HDRLEN;
+		req.n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
+		req.n.nlmsg_type = XFRM_MSG_GETSA;
+		req.n.nlmsg_pid = 0;
+		req.n.nlmsg_seq = rth.dump = ++rth.seq;
+
+		if (filter.xsinfo.id.proto)
+			addattr8(&req.n, sizeof(req), XFRMA_PROTO,
+				 filter.xsinfo.id.proto);
+		addattr_l(&req.n, sizeof(req), XFRMA_ADDRESS_FILTER,
+			  &addrfilter, sizeof(addrfilter));
+
+		if (rtnl_send(&rth, (void *)&req, req.n.nlmsg_len) < 0) {
 			perror("Cannot send dump request");
 			exit(1);
 		}
Signature · 1 line
1.8.5.4