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 <tgraf@suug.ch>
This commit is contained in:
Julien BERNARD 2013-10-08 13:04:30 +02:00 committed by Thomas Graf
parent 20ab3bfa78
commit 27019c5671

View File

@ -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;
}
}