9#include <linux/netlink.h>
11#include <netlink/cli/utils.h>
12#include <netlink/cli/link.h>
14static struct nl_sock *sock;
18 " changes := [link LINK]\n"
19 " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
20 " [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
21 " [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
22 " [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
25static void print_usage(
void)
28 "Usage: nl-link-set [OPTION]... [LINK]\n"
31 " -q, --quiet Do not print informal notifications\n"
32 " -h, --help Show this help\n"
33 " -v, --version Show versioning information\n"
35 "Selecting the Link\n"
36 " -n, --name=NAME link name\n"
37 " -i, --index interface index\n"
39 " --rename=NAME rename interface\n"
40 " --mtu=NUM MTU value\n"
41 " --txqlen=NUM TX queue length\n"
42 " --weight=NUM weight\n"
43 " --ifalias=NAME alias name (SNMP IfAlias)\n"
44 " --state=up/down set interface up/down\n"
49static void set_cb(
struct nl_object *obj,
void *arg)
51 struct rtnl_link *link = nl_object_priv(obj);
69int main(
int argc,
char *argv[])
71 struct nl_cache *link_cache;
75 sock = nl_cli_alloc_socket();
76 nl_cli_connect(sock, NETLINK_ROUTE);
77 link_cache = nl_cli_link_alloc_cache(sock);
78 link = nl_cli_link_alloc();
79 change = nl_cli_link_alloc();
91 static struct option long_opts[] = {
92 {
"quiet", 0, 0,
'q' },
93 {
"help", 0, 0,
'h' },
94 {
"version", 0, 0,
'v' },
95 {
"name", 1, 0,
'n' },
96 {
"index", 1, 0,
'i' },
97 {
"rename", 1, 0, ARG_RENAME },
98 {
"mtu", 1, 0, ARG_MTU },
99 {
"txqlen", 1, 0, ARG_TXQLEN },
100 {
"weight", 1, 0, ARG_WEIGHT },
101 {
"ifalias", 1, 0, ARG_IFALIAS },
102 {
"state", 1, 0, ARG_STATE },
106 c = getopt_long(argc, argv,
"qhvn:i:", long_opts, &optidx);
111 case 'q': quiet = 1;
break;
112 case 'h': print_usage();
break;
113 case 'v': nl_cli_print_version();
break;
114 case 'n': ok++; nl_cli_link_parse_name(link, optarg);
break;
115 case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg);
break;
116 case ARG_RENAME: nl_cli_link_parse_name(change, optarg);
break;
117 case ARG_MTU: nl_cli_link_parse_mtu(change, optarg);
break;
118 case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg);
break;
119 case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg);
break;
120 case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg);
break;
122 if(!strcmp(optarg,
"up"))
124 else if(!strcmp(optarg,
"down"))
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void rtnl_link_unset_flags(struct rtnl_link *link, unsigned int flags)
Unset flags of link object.
void rtnl_link_set_flags(struct rtnl_link *link, unsigned int flags)
Set flags of link object.
int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *orig, struct rtnl_link *changes, int flags)
Change link.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.