From 27019c5671b146fd42de352c7722d398c5740ec6 Mon Sep 17 00:00:00 2001 From: Julien BERNARD Date: Tue, 8 Oct 2013 13:04:30 +0200 Subject: [PATCH] nl-link-set: Add --state option I modified the nl-link-set.c file to be able to set the interface up or down. I joined the patch. With the new nl-link-set binary I can set the tap interface down. I am working with Ubuntu 12.04 LTS 64bits and the libnl and libnl-route packages built from libnl3-3.2.3 from ubuntu reprositories. -- Julien BERNARD Signed-off-by: Thomas Graf --- src/nl-link-set.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/nl-link-set.c b/src/nl-link-set.c index 5ff1e9d..bbb60f9 100644 --- a/src/nl-link-set.c +++ b/src/nl-link-set.c @@ -42,6 +42,7 @@ static void print_usage(void) " --txqlen=NUM TX queue length\n" " --weight=NUM weight\n" " --ifalias=NAME alias name (SNMP IfAlias)\n" + " --state=up/down set interface up/down\n" ); exit(0); } @@ -86,6 +87,7 @@ int main(int argc, char *argv[]) ARG_TXQLEN, ARG_WEIGHT, ARG_IFALIAS, + ARG_STATE, }; static struct option long_opts[] = { { "quiet", 0, 0, 'q' }, @@ -98,6 +100,7 @@ int main(int argc, char *argv[]) { "txqlen", 1, 0, ARG_TXQLEN }, { "weight", 1, 0, ARG_WEIGHT }, { "ifalias", 1, 0, ARG_IFALIAS }, + { "state", 1, 0, ARG_STATE }, { 0, 0, 0, 0 } }; @@ -116,6 +119,12 @@ int main(int argc, char *argv[]) case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg); break; case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg); break; case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg); break; + case ARG_STATE: + if(!strcmp(optarg, "up")) + rtnl_link_set_flags(change, IFF_UP); + else if(!strcmp(optarg, "down")) + rtnl_link_unset_flags(change, IFF_UP); + break; } }