13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/link.h> 17 #include <linux/netlink.h> 19 static struct nl_sock *sock;
23 " changes := [link LINK]\n" 24 " [master MASTER] [qdisc QDISC] [addr ADDR] [broadcast BRD]\n" 25 " [{ up | down }] [{ arp | noarp }] [{ promisc | nopromisc }]\n" 26 " [{ dynamic | nodynamic }] [{ multicast | nomulticast }]\n" 27 " [{ trailers | notrailers }] [{ allmulticast | noallmulticast }]\n");
30 static void print_usage(
void)
33 "Usage: nl-link-set [OPTION]... [LINK]\n" 36 " -q, --quiet Do not print informal notifications\n" 37 " -h, --help Show this help\n" 38 " -v, --version Show versioning information\n" 40 "Selecting the Link\n" 41 " -n, --name=NAME link name\n" 42 " -i, --index interface index\n" 44 " --rename=NAME rename interface\n" 45 " --mtu=NUM MTU value\n" 46 " --txqlen=NUM TX queue length\n" 47 " --weight=NUM weight\n" 48 " --ifalias=NAME alias name (SNMP IfAlias)\n" 49 " --state=up/down set interface up/down\n" 54 static void set_cb(
struct nl_object *obj,
void *arg)
56 struct rtnl_link *link = nl_object_priv(obj);
74 int main(
int argc,
char *argv[])
76 struct nl_cache *link_cache;
80 sock = nl_cli_alloc_socket();
81 nl_cli_connect(sock, NETLINK_ROUTE);
82 link_cache = nl_cli_link_alloc_cache(sock);
83 link = nl_cli_link_alloc();
84 change = nl_cli_link_alloc();
96 static struct option long_opts[] = {
97 {
"quiet", 0, 0,
'q' },
98 {
"help", 0, 0,
'h' },
99 {
"version", 0, 0,
'v' },
100 {
"name", 1, 0,
'n' },
101 {
"index", 1, 0,
'i' },
102 {
"rename", 1, 0, ARG_RENAME },
103 {
"mtu", 1, 0, ARG_MTU },
104 {
"txqlen", 1, 0, ARG_TXQLEN },
105 {
"weight", 1, 0, ARG_WEIGHT },
106 {
"ifalias", 1, 0, ARG_IFALIAS },
107 {
"state", 1, 0, ARG_STATE },
111 c = getopt_long(argc, argv,
"qhvn:i:", long_opts, &optidx);
116 case 'q': quiet = 1;
break;
117 case 'h': print_usage();
break;
118 case 'v': nl_cli_print_version();
break;
119 case 'n': ok++; nl_cli_link_parse_name(link, optarg);
break;
120 case 'i': ok++; nl_cli_link_parse_ifindex(link, optarg);
break;
121 case ARG_RENAME: nl_cli_link_parse_name(change, optarg);
break;
122 case ARG_MTU: nl_cli_link_parse_mtu(change, optarg);
break;
123 case ARG_TXQLEN: nl_cli_link_parse_txqlen(change, optarg);
break;
124 case ARG_WEIGHT: nl_cli_link_parse_weight(change, optarg);
break;
125 case ARG_IFALIAS: nl_cli_link_parse_ifalias(change, optarg);
break;
127 if(!strcmp(optarg,
"up"))
129 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.