]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ipxfrm: allow to setup filter when dumping SA
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Fri, 21 Mar 2014 10:02:43 +0000 (11:02 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 21 Mar 2014 21:24:41 +0000 (14:24 -0700)
It's now possible to filter SA directly into the kernel by specifying
XFRMA_PROTO and/or XFRMA_ADDRESS_FILTER.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
ip/xfrm_state.c

index 140a4503b79927c6e3247760f81277d379079f2d..fe7708e533f3f7c59e1ceeabaab827b5834af6e4 100644 (file)
@@ -1136,7 +1136,30 @@ 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 = {
+                       .n.nlmsg_len = NLMSG_HDRLEN,
+                       .n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+                       .n.nlmsg_type = XFRM_MSG_GETSA,
+                       .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);
                }