6#include <netlink/cli/utils.h>
7#include <netlink/cli/link.h>
10#include <linux/netlink.h>
12static struct nl_sock *sock;
16 " changes := [link LINK]\n"
17 " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n"
18 " [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n"
19 " [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n"
20 " [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
23static void print_usage(
void)
26 "Usage: nl-link-set [OPTION]... [LINK]\n"
29 " -q, --quiet Do not print informal notifications\n"
30 " -h, --help Show this help\n"
31 " -v, --version Show versioning information\n"
33 "Selecting the Link\n"
34 " -n, --name=NAME link name\n"
35 " -i, --index interface index\n"
37 " --rename=NAME rename interface\n"
38 " --mtu=NUM MTU value\n"
39 " --txqlen=NUM TX queue length\n"
40 " --weight=NUM weight\n"
41 " --ifalias=NAME alias name (SNMP IfAlias)\n"
42 " --state=up/down set interface up/down\n"
47static void set_cb(
struct nl_object *obj,
void *arg)
49 struct rtnl_link *link = nl_object_priv(obj);
67int main(
int argc,
char *argv[])
69 struct nl_cache *link_cache;
73 sock = nl_cli_alloc_socket();
74 nl_cli_connect(sock, NETLINK_ROUTE);
75 link_cache = nl_cli_link_alloc_cache(sock);
76 link = nl_cli_link_alloc();
77 change = nl_cli_link_alloc();
89 static struct option long_opts[] = {
90 {
"quiet", 0, 0,
'q' },
91 {
"help", 0, 0,
'h' },
92 {
"version", 0, 0,
'v' },
93 {
"name", 1, 0,
'n' },
94 {
"index", 1, 0,
'i' },
95 {
"rename", 1, 0, ARG_RENAME },
96 {
"mtu", 1, 0, ARG_MTU },
97 {
"txqlen", 1, 0, ARG_TXQLEN },
98 {
"weight", 1, 0, ARG_WEIGHT },
99 {
"ifalias", 1, 0, ARG_IFALIAS },
100 {
"state", 1, 0, ARG_STATE },
104 c = getopt_long(argc, argv,
"qhvn:i:", long_opts, &optidx);
109 case 'q': quiet = 1;
break;
110 case 'h': print_usage();
break;
111 case 'v': nl_cli_print_version();
break;
112 case 'n': ok++; nl_cli_link_parse_name(link, optarg);
break;
113 case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg);
break;
114 case ARG_RENAME: nl_cli_link_parse_name(change, optarg);
break;
115 case ARG_MTU: nl_cli_link_parse_mtu(change, optarg);
break;
116 case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg);
break;
117 case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg);
break;
118 case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg);
break;
120 if(!strcmp(optarg,
"up"))
122 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.