12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/link.h>
15 static struct nl_sock *sock;
19 " changes := [link LINK]\n"
20 " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
21 " [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
22 " [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
23 " [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
26 static void print_usage(
void)
29 "Usage: nl-link-set [OPTION]... [LINK]\n"
32 " -q, --quiet Do not print informal notifications\n"
33 " -h, --help Show this help\n"
34 " -v, --version Show versioning information\n"
36 "Selecting the Link\n"
37 " -n, --name=NAME link name\n"
38 " -i, --index interface index\n"
40 " --rename=NAME rename interface\n"
41 " --mtu=NUM MTU value\n"
42 " --txqlen=NUM TX queue length\n"
43 " --weight=NUM weight\n"
44 " --ifalias=NAME alias name (SNMP IfAlias)\n"
45 " --state=up/down set interface up/down\n"
50 static void set_cb(
struct nl_object *obj,
void *arg)
52 struct rtnl_link *link = nl_object_priv(obj);
70 int main(
int argc,
char *argv[])
72 struct nl_cache *link_cache;
76 sock = nl_cli_alloc_socket();
77 nl_cli_connect(sock, NETLINK_ROUTE);
78 link_cache = nl_cli_link_alloc_cache(sock);
79 link = nl_cli_link_alloc();
80 change = nl_cli_link_alloc();
92 static struct option long_opts[] = {
93 {
"quiet", 0, 0,
'q' },
94 {
"help", 0, 0,
'h' },
95 {
"version", 0, 0,
'v' },
96 {
"name", 1, 0,
'n' },
97 {
"index", 1, 0,
'i' },
98 {
"rename", 1, 0, ARG_RENAME },
99 {
"mtu", 1, 0, ARG_MTU },
100 {
"txqlen", 1, 0, ARG_TXQLEN },
101 {
"weight", 1, 0, ARG_WEIGHT },
102 {
"ifalias", 1, 0, ARG_IFALIAS },
103 {
"state", 1, 0, ARG_STATE },
107 c = getopt_long(argc, argv,
"qhvn:i:", long_opts, &optidx);
112 case 'q': quiet = 1;
break;
113 case 'h': print_usage();
break;
114 case 'v': nl_cli_print_version();
break;
115 case 'n': ok++; nl_cli_link_parse_name(link, optarg);
break;
116 case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg);
break;
117 case ARG_RENAME: nl_cli_link_parse_name(change, optarg);
break;
118 case ARG_MTU: nl_cli_link_parse_mtu(change, optarg);
break;
119 case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg);
break;
120 case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg);
break;
121 case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg);
break;
123 if(!strcmp(optarg,
"up"))
125 else if(!strcmp(optarg,
"down"))