|
|
049c96 |
From 03fe9d9ea9d8bf2635d12669d6cc7a80c2c8db1e Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Tue, 16 Feb 2016 22:14:05 +0100
|
|
|
049c96 |
Subject: [PATCH] xfrm: add command for configuring SPD hash table
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1212026
|
|
|
049c96 |
Upstream Status: commit 025fa9dc7a4fe
|
|
|
049c96 |
Conflicts: Adjusted call to rtnl_talk due to previously backported
|
|
|
049c96 |
c079e121a73af ("libnetlink: add size argument to rtnl_talk")
|
|
|
049c96 |
|
|
|
049c96 |
commit 025fa9dc7a4fee971c7040aeb84b4dac2ae08b3b
|
|
|
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
|
|
|
049c96 |
|
|
|
a4b897 |
add a new command to configure the SPD hash table:
|
|
|
a4b897 |
ip xfrm policy set [ hthresh4 LBITS RBITS ] [ hthresh6 LBITS RBITS ]
|
|
|
049c96 |
|
|
|
a4b897 |
and code to display the SPD hash configuration:
|
|
|
a4b897 |
ip -s -s xfrm policy count
|
|
|
049c96 |
|
|
|
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.
|
|
|
049c96 |
|
|
|
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.
|
|
|
049c96 |
|
|
|
a4b897 |
Example:
|
|
|
049c96 |
|
|
|
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
|
|
|
049c96 |
|
|
|
a4b897 |
% ip xfrm pol set hthresh4 24 16 hthresh6 64 56
|
|
|
049c96 |
|
|
|
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
|
|
|
049c96 |
|
|
|
a4b897 |
Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
|
|
|
049c96 |
---
|
|
|
049c96 |
ip/xfrm_policy.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
|
|
|
049c96 |
1 file changed, 102 insertions(+), 3 deletions(-)
|
|
|
a4b897 |
|
|
|
a4b897 |
diff --git a/ip/xfrm_policy.c b/ip/xfrm_policy.c
|
|
|
049c96 |
index 3ff734e..e66a4fa 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 |
+
|
|
|
049c96 |
+ if (rtnl_talk(&rth, &req.n, NULL, 0) < 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);
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
a4b897 |
|