naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/iproute2-3.10.0-xfrm.patch

a4b897
commit f3de468299d13204f47dd8e431750fcba33fcd29
a4b897
Author: Christophe Gouault <christophe.gouault@6wind.com>
a4b897
Date:   Thu Apr 9 17:39:32 2015 +0200
a4b897
a4b897
    xfrm: add command for configuring SPD hash table
a4b897
    
a4b897
    add a new command to configure the SPD hash table:
a4b897
       ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]
a4b897
    
a4b897
    and code to display the SPD hash configuration:
a4b897
      ip -s -s xfrm policy count
a4b897
    
a4b897
    hthresh4: defines minimum local and remote IPv4 prefix lengths of
a4b897
    selectors to hash a policy. If prefix lengths are greater or equal
a4b897
    to the thresholds, then the policy is hashed, otherwise it falls back
a4b897
    in the policy_inexact chained list.
a4b897
    
a4b897
    hthresh6: defines minimum local and remote IPv6 prefix lengths of
a4b897
    selectors to hash a policy, otherwise it falls back
a4b897
    in the policy_inexact chained list.
a4b897
    
a4b897
    Example:
a4b897
    
a4b897
    % ip -s -s xfrm policy count
a4b897
             SPD IN  0 OUT 0 FWD 0 (Sock: IN 0 OUT 0 FWD 0)
a4b897
             SPD buckets: count 7 Max 1048576
a4b897
             SPD IPv4 thresholds: local 32 remote 32
a4b897
             SPD IPv6 thresholds: local 128 remote 128
a4b897
    
a4b897
    % ip xfrm pol set hthresh4 24 16 hthresh6 64 56
a4b897
    
a4b897
    % ip -s -s xfrm policy count
a4b897
             SPD IN  0 OUT 0 FWD 0 (Sock: IN 0 OUT 0 FWD 0)
a4b897
             SPD buckets: count 7 Max 1048576
a4b897
             SPD IPv4 thresholds: local 24 remote 16
a4b897
             SPD IPv6 thresholds: local 64 remote 56
a4b897
    
a4b897
    Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
a4b897
a4b897
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
a4b897
index 36e33c9..9ac4a89 100644
a4b897
--- a/ip/xfrm_policy.c
a4b897
+++ b/ip/xfrm_policy.c
a4b897
@@ -64,7 +64,8 @@ static void usage(void)
a4b897
 	fprintf(stderr, "        [ index INDEX ] [ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]\n");
a4b897
 	fprintf(stderr, "        [ flag FLAG-LIST ]\n");
a4b897
 	fprintf(stderr, "Usage: ip xfrm policy flush [ ptype PTYPE ]\n");
a4b897
-	fprintf(stderr, "Usage: ip xfrm count\n");
a4b897
+	fprintf(stderr, "Usage: ip xfrm policy count\n");
a4b897
+	fprintf(stderr, "Usage: ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]\n");
a4b897
 	fprintf(stderr, "SELECTOR := [ src ADDR[/PLEN] ] [ dst ADDR[/PLEN] ] [ dev DEV ] [ UPSPEC ]\n");
a4b897
 	fprintf(stderr, "UPSPEC := proto { { ");
a4b897
 	fprintf(stderr, "%s | ", strxf_proto(IPPROTO_TCP));
a4b897
@@ -935,7 +936,7 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
a4b897
 			fprintf(fp,")");
a4b897
 		}
a4b897
 
a4b897
-		fprintf(fp,"\n");
a4b897
+		fprintf(fp, "%s", _SL_);
a4b897
 	}
a4b897
 	if (show_stats > 1) {
a4b897
 		struct xfrmu_spdhinfo *sh;
a4b897
@@ -949,13 +950,109 @@ static int print_spdinfo( struct nlmsghdr *n, void *arg)
a4b897
 			fprintf(fp,"\t SPD buckets:");
a4b897
 			fprintf(fp," count %d", sh->spdhcnt);
a4b897
 			fprintf(fp," Max %d", sh->spdhmcnt);
a4b897
+			fprintf(fp, "%s", _SL_);
a4b897
+		}
a4b897
+		if (tb[XFRMA_SPD_IPV4_HTHRESH]) {
a4b897
+			struct xfrmu_spdhthresh *th;
a4b897
+			if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) {
a4b897
+				fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
a4b897
+				return -1;
a4b897
+			}
a4b897
+			th = RTA_DATA(tb[XFRMA_SPD_IPV4_HTHRESH]);
a4b897
+			fprintf(fp,"\t SPD IPv4 thresholds:");
a4b897
+			fprintf(fp," local %d", th->lbits);
a4b897
+			fprintf(fp," remote %d", th->rbits);
a4b897
+			fprintf(fp, "%s", _SL_);
a4b897
+
a4b897
+		}
a4b897
+		if (tb[XFRMA_SPD_IPV6_HTHRESH]) {
a4b897
+			struct xfrmu_spdhthresh *th;
a4b897
+			if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) {
a4b897
+				fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
a4b897
+				return -1;
a4b897
+			}
a4b897
+			th = RTA_DATA(tb[XFRMA_SPD_IPV6_HTHRESH]);
a4b897
+			fprintf(fp,"\t SPD IPv6 thresholds:");
a4b897
+			fprintf(fp," local %d", th->lbits);
a4b897
+			fprintf(fp," remote %d", th->rbits);
a4b897
+			fprintf(fp, "%s", _SL_);
a4b897
 		}
a4b897
 	}
a4b897
-	fprintf(fp,"\n");
a4b897
+
a4b897
+	if (oneline)
a4b897
+		fprintf(fp, "\n");
a4b897
 
a4b897
         return 0;
a4b897
 }
a4b897
 
a4b897
+static int xfrm_spd_setinfo(int argc, char **argv)
a4b897
+{
a4b897
+	struct rtnl_handle rth;
a4b897
+	struct {
a4b897
+		struct nlmsghdr			n;
a4b897
+		__u32				flags;
a4b897
+		char				buf[RTA_BUF_SIZE];
a4b897
+	} req;
a4b897
+
a4b897
+	char *thr4 = NULL;
a4b897
+	char *thr6 = NULL;
a4b897
+
a4b897
+	memset(&req, 0, sizeof(req));
a4b897
+
a4b897
+	req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
a4b897
+	req.n.nlmsg_flags = NLM_F_REQUEST;
a4b897
+	req.n.nlmsg_type = XFRM_MSG_NEWSPDINFO;
a4b897
+	req.flags = 0XFFFFFFFF;
a4b897
+
a4b897
+	while (argc > 0) {
a4b897
+		if (strcmp(*argv, "hthresh4") == 0) {
a4b897
+			struct xfrmu_spdhthresh thr;
a4b897
+
a4b897
+			if (thr4)
a4b897
+				duparg("hthresh4", *argv);
a4b897
+			thr4 = *argv;
a4b897
+			NEXT_ARG();
a4b897
+			if (get_u8(&thr.lbits, *argv, 0) || thr.lbits > 32)
a4b897
+				invarg("hthresh4 LBITS value is invalid", *argv);
a4b897
+			NEXT_ARG();
a4b897
+			if (get_u8(&thr.rbits, *argv, 0) || thr.rbits > 32)
a4b897
+				invarg("hthresh4 RBITS value is invalid", *argv);
a4b897
+
a4b897
+			addattr_l(&req.n, sizeof(req), XFRMA_SPD_IPV4_HTHRESH,
a4b897
+				  (void *)&thr, sizeof(thr));
a4b897
+		} else if (strcmp(*argv, "hthresh6") == 0) {
a4b897
+			struct xfrmu_spdhthresh thr;
a4b897
+
a4b897
+			if (thr6)
a4b897
+				duparg("hthresh6", *argv);
a4b897
+			thr6 = *argv;
a4b897
+			NEXT_ARG();
a4b897
+			if (get_u8(&thr.lbits, *argv, 0) || thr.lbits > 128)
a4b897
+				invarg("hthresh6 LBITS value is invalid", *argv);
a4b897
+			NEXT_ARG();
a4b897
+			if (get_u8(&thr.rbits, *argv, 0) || thr.rbits > 128)
a4b897
+				invarg("hthresh6 RBITS value is invalid", *argv);
a4b897
+
a4b897
+			addattr_l(&req.n, sizeof(req), XFRMA_SPD_IPV6_HTHRESH,
a4b897
+				  (void *)&thr, sizeof(thr));
a4b897
+		} else {
a4b897
+			invarg("unknown", *argv);
a4b897
+		}
a4b897
+
a4b897
+		argc--; argv++;
a4b897
+	}
a4b897
+
a4b897
+	if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
a4b897
+		exit(1);
a4b897
+
a4b897
+	if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
a4b897
+		exit(2);
a4b897
+
a4b897
+	rtnl_close(&rth);
a4b897
+
a4b897
+	return 0;
a4b897
+}
a4b897
+
a4b897
 static int xfrm_spd_getinfo(int argc, char **argv)
a4b897
 {
a4b897
 	struct rtnl_handle rth;
a4b897
@@ -1059,6 +1156,8 @@ int do_xfrm_policy(int argc, char **argv)
a4b897
 		return xfrm_policy_flush(argc-1, argv+1);
a4b897
 	if (matches(*argv, "count") == 0)
a4b897
 		return xfrm_spd_getinfo(argc, argv);
a4b897
+	if (matches(*argv, "set") == 0)
a4b897
+		return xfrm_spd_setinfo(argc-1, argv+1);
a4b897
 	if (matches(*argv, "help") == 0)
a4b897
 		usage();
a4b897
 	fprintf(stderr, "Command \"%s\" is unknown, try \"ip xfrm policy help\".\n", *argv);
a4b897
commit 0b1562a4459c59d79ecabcf919e3db423a2c321d
a4b897
Author: Christophe Gouault <christophe.gouault@6wind.com>
a4b897
Date:   Thu Apr 9 17:39:33 2015 +0200
a4b897
a4b897
    xfrm: revise man page and document ip xfrm policy set
a4b897
    
a4b897
    - document ip xfrm policy set
a4b897
    - update ip xfrm monitor documentation
a4b897
    - in DESCRIPTION section, reorganize grouping of commands
a4b897
    
a4b897
    Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
a4b897
a4b897
diff --git a/man/man8/ip-xfrm.8 b/man/man8/ip-xfrm.8
a4b897
index 2d31b4d..e305c0b 100644
a4b897
--- a/man/man8/ip-xfrm.8
a4b897
+++ b/man/man8/ip-xfrm.8
a4b897
@@ -252,6 +252,13 @@ ip-xfrm \- transform configuration
a4b897
 .B "ip xfrm policy count"
a4b897
 
a4b897
 .ti -8
a4b897
+.B "ip xfrm policy set"
a4b897
+.RB "[ " hthresh4
a4b897
+.IR LBITS " " RBITS " ]"
a4b897
+.RB "[ " hthresh6
a4b897
+.IR LBITS " " RBITS " ]"
a4b897
+
a4b897
+.ti -8
a4b897
 .IR SELECTOR " :="
a4b897
 .RB "[ " src
a4b897
 .IR ADDR "[/" PLEN "] ]"
a4b897
@@ -355,6 +362,13 @@ ip-xfrm \- transform configuration
a4b897
 .BR "ip xfrm monitor" " [ " all " |"
a4b897
 .IR LISTofXFRM-OBJECTS " ]"
a4b897
 
a4b897
+.ti -8
a4b897
+.IR LISTofXFRM-OBJECTS " := [ " LISTofXFRM-OBJECTS " ] " XFRM-OBJECT
a4b897
+
a4b897
+.ti -8
a4b897
+.IR XFRM-OBJECT " := "
a4b897
+.BR acquire " | " expire " | " SA " | " policy " | " aevent " | " report
a4b897
+
a4b897
 .in -8
a4b897
 .ad b
a4b897
 
a4b897
@@ -380,7 +394,6 @@ ip xfrm state deleteall	delete all existing state in xfrm
a4b897
 ip xfrm state list	print out the list of existing state in xfrm
a4b897
 ip xfrm state flush	flush all state in xfrm
a4b897
 ip xfrm state count	count all existing state in xfrm
a4b897
-ip xfrm monitor 	state monitoring for xfrm objects
a4b897
 .TE
a4b897
 
a4b897
 .TP
a4b897
@@ -502,7 +515,9 @@ encapsulates packets with protocol
a4b897
 .BR espinudp " or " espinudp-nonike ","
a4b897
 .RI "using source port " SPORT ", destination port "  DPORT
a4b897
 .RI ", and original address " OADDR "."
a4b897
+
a4b897
 .sp
a4b897
+.PP
a4b897
 .TS
a4b897
 l l.
a4b897
 ip xfrm policy add	add a new policy
a4b897
@@ -512,7 +527,6 @@ ip xfrm policy get	get an existing policy
a4b897
 ip xfrm policy deleteall	delete all existing xfrm policies
a4b897
 ip xfrm policy list	print out the list of xfrm policies
a4b897
 ip xfrm policy flush	flush policies
a4b897
-ip xfrm policy count	count existing policies
a4b897
 .TE
a4b897
 
a4b897
 .TP
a4b897
@@ -607,7 +621,50 @@ and inbound trigger
a4b897
 can be
a4b897
 .BR required " (default) or " use "."
a4b897
 
a4b897
+.sp
a4b897
+.PP
a4b897
+.TS
a4b897
+l l.
a4b897
+ip xfrm policy count	count existing policies
a4b897
+.TE
a4b897
+
a4b897
+.PP
a4b897
+Use one or more -s options to display more details, including policy hash table
a4b897
+information.
a4b897
+
a4b897
+.sp
a4b897
+.PP
a4b897
+.TS
a4b897
+l l.
a4b897
+ip xfrm policy set	configure the policy hash table
a4b897
+.TE
a4b897
+
a4b897
+.PP
a4b897
+Security policies whose address prefix lengths are greater than or equal
a4b897
+policy hash table thresholds are hashed. Others are stored in the
a4b897
+policy_inexact chained list.
a4b897
+
a4b897
+.TP
a4b897
+.I LBITS
a4b897
+specifies the minimum local address prefix length of policies that are
a4b897
+stored in the Security Policy Database hash table.
a4b897
+
a4b897
+.TP
a4b897
+.I RBITS
a4b897
+specifies the minimum remote address prefix length of policies that are
a4b897
+stored in the Security Policy Database hash table.
a4b897
+
a4b897
+.sp
a4b897
+.PP
a4b897
+.TS
a4b897
+l l.
a4b897
+ip xfrm monitor 	state monitoring for xfrm objects
a4b897
+.TE
a4b897
+
a4b897
+.PP
a4b897
 The xfrm objects to monitor can be optionally specified.
a4b897
 
a4b897
 .SH AUTHOR
a4b897
 Manpage revised by David Ward <david.ward@ll.mit.edu>
a4b897
+.br
a4b897
+Manpage revised by Christophe Gouault <christophe.gouault@6wind.com>
a4b897
commit 5bf9f5c5a0f2d8a0fdb06c60242ff805177a4d73
a4b897
Author: Vadim Kochan <vadim4j@gmail.com>
a4b897
Date:   Sat Feb 14 19:45:04 2015 +0200
a4b897
a4b897
    ip xfrm: Allow to specify "all" option for monitor
a4b897
    
a4b897
    Just to be aligned with the usage output.
a4b897
    
a4b897
    Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
a4b897
a4b897
diff --git a/ip/xfrm_monitor.c b/ip/xfrm_monitor.c
a4b897
index 79453e4..8aa6f49 100644
a4b897
--- a/ip/xfrm_monitor.c
a4b897
+++ b/ip/xfrm_monitor.c
a4b897
@@ -374,7 +374,7 @@ int do_xfrm_monitor(int argc, char **argv)
a4b897
 			groups = 0;
a4b897
 		} else if (matches(*argv, "help") == 0) {
a4b897
 			usage();
a4b897
-		} else {
a4b897
+		} else if (strcmp(*argv, "all")) {
a4b897
 			fprintf(stderr, "Argument \"%s\" is unknown, try \"ip xfrm monitor help\".\n", *argv);
a4b897
 			exit(-1);
a4b897
 		}