13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/link.h> 16 static struct nl_sock *sock;
20 " changes := [link LINK]\n" 21 " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n" 22 " [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n" 23 " [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n" 24 " [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
27 static void print_usage(
void)
30 "Usage: nl-link-set [OPTION]... [LINK]\n" 33 " -q, --quiet Do not print informal notifications\n" 34 " -h, --help Show this help\n" 35 " -v, --version Show versioning information\n" 37 "Selecting the Link\n" 38 " -n, --name=NAME link name\n" 39 " -i, --index interface index\n" 41 " --rename=NAME rename interface\n" 42 " --mtu=NUM MTU value\n" 43 " --txqlen=NUM TX queue length\n" 44 " --weight=NUM weight\n" 45 " --ifalias=NAME alias name (SNMP IfAlias)\n" 46 " --state=up/down set interface up/down\n" 51 static void set_cb(
struct nl_object *obj,
void *arg)
53 struct rtnl_link *link = nl_object_priv(obj);
71 int main(
int argc,
char *argv[])
73 struct nl_cache *link_cache;
77 sock = nl_cli_alloc_socket();
78 nl_cli_connect(sock, NETLINK_ROUTE);
79 link_cache = nl_cli_link_alloc_cache(sock);
80 link = nl_cli_link_alloc();
81 change = nl_cli_link_alloc();
93 static struct option long_opts[] = {
94 {
"quiet", 0, 0,
'q' },
95 {
"help", 0, 0,
'h' },
96 {
"version", 0, 0,
'v' },
97 {
"name", 1, 0,
'n' },
98 {
"index", 1, 0,
'i' },
99 {
"rename", 1, 0, ARG_RENAME },
100 {
"mtu", 1, 0, ARG_MTU },
101 {
"txqlen", 1, 0, ARG_TXQLEN },
102 {
"weight", 1, 0, ARG_WEIGHT },
103 {
"ifalias", 1, 0, ARG_IFALIAS },
104 {
"state", 1, 0, ARG_STATE },
108 c = getopt_long(argc, argv,
"qhvn:i:", long_opts, &optidx);
113 case 'q': quiet = 1;
break;
114 case 'h': print_usage();
break;
115 case 'v': nl_cli_print_version();
break;
116 case 'n': ok++; nl_cli_link_parse_name(link, optarg);
break;
117 case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg);
break;
118 case ARG_RENAME: nl_cli_link_parse_name(change, optarg);
break;
119 case ARG_MTU: nl_cli_link_parse_mtu(change, optarg);
break;
120 case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg);
break;
121 case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg);
break;
122 case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg);
break;
124 if(!strcmp(optarg,
"up"))
126 else if(!strcmp(optarg,
"down"))
Dump object briefly on one line.
void rtnl_link_unset_flags(struct rtnl_link *link, unsigned int flags)
Unset flags of link object.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *orig, struct rtnl_link *changes, int flags)
Change link.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void rtnl_link_set_flags(struct rtnl_link *link, unsigned int flags)
Set flags of link object.