* [PATCH iproute2 v2] Add "show" subcommand to "ip fou"
@ 2017-11-17 0:53 Greg Greenway
2017-11-17 1:06 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Greg Greenway @ 2017-11-17 0:53 UTC (permalink / raw)
To: Linux Kernel Network Developers; +Cc: Stephen Hemminger, Tom Herbert
Sample output:
$ sudo ./ip/ip fou add port 111 ipproto 11
$ sudo ./ip/ip fou add port 222 ipproto 22 -6
$ ./ip/ip fou show
port 222 ipproto 22 -6
port 111 ipproto 11
Signed-off-by: Greg Greenway <ggreenway@apple.com>
---
ip/ipfou.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/ip/ipfou.c b/ip/ipfou.c
index 00dbe15..ecbaf11 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -28,6 +28,7 @@ static void usage(void)
fprintf(stderr, "Usage: ip fou add port PORT "
"{ ipproto PROTO | gue } [ -6 ]\n");
fprintf(stderr, " ip fou del port PORT [ -6 ]\n");
+ fprintf(stderr, " ip fou show\n");
fprintf(stderr, "\n");
fprintf(stderr, "Where: PROTO { ipproto-name | 1..255 }\n");
fprintf(stderr, " PORT { 1..65535 }\n");
@@ -134,6 +135,63 @@ static int do_del(int argc, char **argv)
return 0;
}
+static int print_fou_mapping(const struct sockaddr_nl *who,
+ struct nlmsghdr *n, void *arg)
+{
+ FILE *fp = (FILE *)arg;
+ struct genlmsghdr *ghdr;
+ struct rtattr *tb[FOU_ATTR_MAX + 1];
+ int len = n->nlmsg_len;
+ unsigned family;
+
+ if (n->nlmsg_type != genl_family)
+ return 0;
+
+ len -= NLMSG_LENGTH(GENL_HDRLEN);
+ if (len < 0)
+ return -1;
+
+ ghdr = NLMSG_DATA(n);
+ parse_rtattr(tb, FOU_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
+
+ if (tb[FOU_ATTR_PORT])
+ fprintf(fp, "port %u", ntohs(rta_getattr_u16(tb[FOU_ATTR_PORT])));
+ if (tb[FOU_ATTR_TYPE] && rta_getattr_u8(tb[FOU_ATTR_TYPE]) == FOU_ENCAP_GUE)
+ fprintf(fp, " gue");
+ else if (tb[FOU_ATTR_IPPROTO])
+ fprintf(fp, " ipproto %u", rta_getattr_u8(tb[FOU_ATTR_IPPROTO]));
+ if (tb[FOU_ATTR_AF]) {
+ family = rta_getattr_u8(tb[FOU_ATTR_AF]);
+ if (family == AF_INET6)
+ fprintf(fp, " -6");
+ }
+ fprintf(fp, "\n");
+
+ return 0;
+}
+
+static int do_show(int argc, char **argv)
+{
+ FOU_REQUEST(req, 4096, FOU_CMD_GET, NLM_F_REQUEST | NLM_F_DUMP);
+
+ if (argc > 0) {
+ fprintf(stderr, "\"ip fou show\" does not take any arguments.\n");
+ return -1;
+ }
+
+ if (rtnl_send(&genl_rth, &req.n, req.n.nlmsg_len) < 0) {
+ perror("Cannot send show request");
+ exit(1);
+ }
+
+ if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
+ fprintf(stderr, "Dump terminated\n");
+ return 1;
+ }
+
+ return 0;
+}
+
int do_ipfou(int argc, char **argv)
{
if (argc < 1)
@@ -149,6 +207,8 @@ int do_ipfou(int argc, char **argv)
return do_add(argc-1, argv+1);
if (matches(*argv, "delete") == 0)
return do_del(argc-1, argv+1);
+ if (matches(*argv, "show") == 0)
+ return do_show(argc-1, argv+1);
fprintf(stderr, "Command \"%s\" is unknown, try \"ip fou help\".\n", *argv);
exit(-1);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH iproute2 v2] Add "show" subcommand to "ip fou"
2017-11-17 0:53 [PATCH iproute2 v2] Add "show" subcommand to "ip fou" Greg Greenway
@ 2017-11-17 1:06 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2017-11-17 1:06 UTC (permalink / raw)
To: Greg Greenway; +Cc: Linux Kernel Network Developers, Tom Herbert
On Thu, 16 Nov 2017 16:53:22 -0800
Greg Greenway <ggreenway@apple.com> wrote:
> Sample output:
>
> $ sudo ./ip/ip fou add port 111 ipproto 11
> $ sudo ./ip/ip fou add port 222 ipproto 22 -6
> $ ./ip/ip fou show
> port 222 ipproto 22 -6
> port 111 ipproto 11
>
> Signed-off-by: Greg Greenway <ggreenway@apple.com>
Applied, thanks. Sorry for the annoying procedural problem.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-17 1:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-17 0:53 [PATCH iproute2 v2] Add "show" subcommand to "ip fou" Greg Greenway
2017-11-17 1:06 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).