From: Daniel Borkmann Date: Mon, 23 May 2016 22:47:38 +0000 (+0200) Subject: ip, token: add del command X-Git-Tag: v4.7.0~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8daee42a51c62490135ba1847f83e3b9832fa98;p=thirdparty%2Fiproute2.git ip, token: add del command For convenience also add a del command for deleting a token and update the man page accordingly. Signed-off-by: Daniel Borkmann --- diff --git a/ip/iptoken.c b/ip/iptoken.c index 6e1a1ab7f..722b526ad 100644 --- a/ip/iptoken.c +++ b/ip/iptoken.c @@ -38,7 +38,7 @@ static void usage(void) __attribute__((noreturn)); static void usage(void) { - fprintf(stderr, "Usage: ip token [ list | set | get ] [ TOKEN ] [ dev DEV ]\n"); + fprintf(stderr, "Usage: ip token [ list | set | del | get ] [ TOKEN ] [ dev DEV ]\n"); exit(-1); } @@ -117,7 +117,7 @@ static int iptoken_list(int argc, char **argv) return 0; } -static int iptoken_set(int argc, char **argv) +static int iptoken_set(int argc, char **argv, bool delete) { struct { struct nlmsghdr n; @@ -125,10 +125,9 @@ static int iptoken_set(int argc, char **argv) char buf[512]; } req; struct rtattr *afs, *afs6; - bool have_token = false, have_dev = false; - inet_prefix addr; + bool have_token = delete, have_dev = false; + inet_prefix addr = { .bytelen = 16, }; - memset(&addr, 0, sizeof(addr)); memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); @@ -149,13 +148,7 @@ static int iptoken_set(int argc, char **argv) if (matches(*argv, "help") == 0) usage(); if (!have_token) { - afs = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC); - afs6 = addattr_nest(&req.n, sizeof(req), AF_INET6); get_prefix(&addr, *argv, req.ifi.ifi_family); - addattr_l(&req.n, sizeof(req), IFLA_INET6_TOKEN, - &addr.data, addr.bytelen); - addattr_nest_end(&req.n, afs6); - addattr_nest_end(&req.n, afs); have_token = true; } } @@ -171,6 +164,13 @@ static int iptoken_set(int argc, char **argv) return -1; } + afs = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC); + afs6 = addattr_nest(&req.n, sizeof(req), AF_INET6); + addattr_l(&req.n, sizeof(req), IFLA_INET6_TOKEN, + &addr.data, addr.bytelen); + addattr_nest_end(&req.n, afs6); + addattr_nest_end(&req.n, afs); + if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) return -2; @@ -189,7 +189,9 @@ int do_iptoken(int argc, char **argv) return iptoken_list(argc - 1, argv + 1); } else if (matches(argv[0], "set") == 0 || matches(argv[0], "add") == 0) { - return iptoken_set(argc - 1, argv + 1); + return iptoken_set(argc - 1, argv + 1, false); + } else if (matches(argv[0], "delete") == 0) { + return iptoken_set(argc - 1, argv + 1, true); } else if (matches(argv[0], "get") == 0) { return iptoken_list(argc - 1, argv + 1); } else if (matches(argv[0], "help") == 0) diff --git a/man/man8/ip-token.8 b/man/man8/ip-token.8 index 260f366af..6505b8c51 100644 --- a/man/man8/ip-token.8 +++ b/man/man8/ip-token.8 @@ -17,6 +17,10 @@ ip-token \- tokenized interface identifier support .B dev .IR DEV +.ti -8 +.B ip token del dev +.IR DEV + .ti -8 .B ip token get .RB "[ " dev @@ -37,8 +41,7 @@ IPv6 Identifiers are described in the draft [1]: . .SS ip token set - set an interface token -set the interface token to the kernel. Once a token is set, it cannot be -removed from the interface, only overwritten. +set the interface token to the kernel. .TP .I TOKEN the interface identifier token address. @@ -46,6 +49,12 @@ the interface identifier token address. .BI dev " DEV" the networking interface. +.SS ip token del - delete an interface token +delete the interface token from the kernel. +.TP +.BI dev " DEV" +the networking interface. + .SS ip token get - get the interface token from the kernel show a tokenized interface identifier of a particular networking device. .B Arguments: