]> git.pld-linux.org Git - packages/iproute2.git/blame - iproute2-fou_show.patch
- add `ip fou show' command
[packages/iproute2.git] / iproute2-fou_show.patch
CommitLineData
d888f718
AO
1diff -ruNp iproute2-4.14.1.orig/ip/ipfou.c iproute2-4.14.1/ip/ipfou.c
2--- iproute2-4.14.1.orig/ip/ipfou.c 2017-11-13 19:09:57.000000000 +0100
3+++ iproute2-4.14.1/ip/ipfou.c 2018-02-19 15:49:27.105945493 +0100
4@@ -28,6 +28,7 @@ static void usage(void)
5 fprintf(stderr, "Usage: ip fou add port PORT "
6 "{ ipproto PROTO | gue } [ -6 ]\n");
7 fprintf(stderr, " ip fou del port PORT [ -6 ]\n");
8+ fprintf(stderr, " ip fou show\n");
9 fprintf(stderr, "\n");
10 fprintf(stderr, "Where: PROTO { ipproto-name | 1..255 }\n");
11 fprintf(stderr, " PORT { 1..65535 }\n");
12@@ -134,6 +135,63 @@ static int do_del(int argc, char **argv)
13 return 0;
14 }
15
16+static int print_fou_mapping(const struct sockaddr_nl *who,
17+ struct nlmsghdr *n, void *arg)
18+{
19+ FILE *fp = (FILE *)arg;
20+ struct genlmsghdr *ghdr;
21+ struct rtattr *tb[FOU_ATTR_MAX + 1];
22+ int len = n->nlmsg_len;
23+ unsigned family;
24+
25+ if (n->nlmsg_type != genl_family)
26+ return 0;
27+
28+ len -= NLMSG_LENGTH(GENL_HDRLEN);
29+ if (len < 0)
30+ return -1;
31+
32+ ghdr = NLMSG_DATA(n);
33+ parse_rtattr(tb, FOU_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
34+
35+ if (tb[FOU_ATTR_PORT])
36+ fprintf(fp, "port %u", ntohs(rta_getattr_u16(tb[FOU_ATTR_PORT])));
37+ if (tb[FOU_ATTR_TYPE] && rta_getattr_u8(tb[FOU_ATTR_TYPE]) == FOU_ENCAP_GUE)
38+ fprintf(fp, " gue");
39+ else if (tb[FOU_ATTR_IPPROTO])
40+ fprintf(fp, " ipproto %u", rta_getattr_u8(tb[FOU_ATTR_IPPROTO]));
41+ if (tb[FOU_ATTR_AF]) {
42+ family = rta_getattr_u8(tb[FOU_ATTR_AF]);
43+ if (family == AF_INET6)
44+ fprintf(fp, " -6");
45+ }
46+ fprintf(fp, "\n");
47+
48+ return 0;
49+}
50+
51+static int do_show(int argc, char **argv)
52+{
53+ FOU_REQUEST(req, 4096, FOU_CMD_GET, NLM_F_REQUEST | NLM_F_DUMP);
54+
55+ if (argc > 0) {
56+ fprintf(stderr, "\"ip fou show\" does not take any arguments.\n");
57+ return -1;
58+ }
59+
60+ if (rtnl_send(&genl_rth, &req.n, req.n.nlmsg_len) < 0) {
61+ perror("Cannot send show request");
62+ exit(1);
63+ }
64+
65+ if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
66+ fprintf(stderr, "Dump terminated\n");
67+ return 1;
68+ }
69+
70+ return 0;
71+}
72+
73 int do_ipfou(int argc, char **argv)
74 {
75 if (argc < 1)
76@@ -149,6 +207,8 @@ int do_ipfou(int argc, char **argv)
77 return do_add(argc-1, argv+1);
78 if (matches(*argv, "delete") == 0)
79 return do_del(argc-1, argv+1);
80+ if (matches(*argv, "show") == 0)
81+ return do_show(argc-1, argv+1);
82 fprintf(stderr, "Command \"%s\" is unknown, try \"ip fou help\".\n", *argv);
83 exit(-1);
84 }
85diff -ruNp iproute2-4.14.1.orig/man/man8/ip-fou.8 iproute2-4.14.1/man/man8/ip-fou.8
86--- iproute2-4.14.1.orig/man/man8/ip-fou.8 2017-11-13 19:09:57.000000000 +0100
87+++ iproute2-4.14.1/man/man8/ip-fou.8 2018-02-19 15:49:23.558962613 +0100
88@@ -29,6 +29,9 @@ ip-gue \- Generic UDP Encapsulation rece
89 .BR "ip fou del"
90 .B port
91 .IR PORT
92+.br
93+.ti -8
94+.B ip fou show
95 .SH DESCRIPTION
96 The
97 .B ip fou
This page took 0.12958 seconds and 4 git commands to generate.