• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * src/nl-link-dump.c	Dump link attributes
3  *
4  *	This library is free software; you can redistribute it and/or
5  *	modify it under the terms of the GNU Lesser General Public
6  *	License as published by the Free Software Foundation version 2.1
7  *	of the License.
8  *
9  * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #if 0
13 static void print_usage(void)
14 {
15 	printf(
16 	"Usage: nl-link-dump <mode> [<filter>]\n"
17 	"  mode := { brief | detailed | stats | xml }\n"
18 	"  filter := [dev DEV] [mtu MTU] [txqlen TXQLEN] [weight WEIGHT] [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");
23 	exit(1);
24 }
25 #endif
26 
27 #include <netlink/cli/utils.h>
28 #include <netlink/cli/link.h>
29 
print_usage(void)30 static void print_usage(void)
31 {
32 	printf(
33 	"Usage: nl-link-list [OPTION]... [Link]\n"
34 	"\n"
35 	"Options\n"
36 	" -f, --format=TYPE     Output format { brief | details | stats }\n"
37 	" -h, --help            Show this help\n"
38 	" -v, --version         Show versioning information\n"
39 	"\n"
40 	"Link Options\n"
41 	" -n, --name=NAME	link name\n"
42 	" -i, --index           interface index\n"
43 	"     --mtu=NUM         MTU value\n"
44 	"     --txqlen=NUM      TX queue length\n"
45 	"     --weight=NUM      weight\n"
46 	);
47 	exit(0);
48 }
49 
main(int argc,char * argv[])50 int main(int argc, char *argv[])
51 {
52 	struct nl_sock *sock;
53 	struct nl_cache *link_cache;
54 	struct rtnl_link *link;
55 	struct nl_dump_params params = {
56 		.dp_type = NL_DUMP_LINE,
57 		.dp_fd = stdout,
58 	};
59 
60 	sock = nl_cli_alloc_socket();
61 	nl_cli_connect(sock, NETLINK_ROUTE);
62 	link_cache = nl_cli_link_alloc_cache(sock);
63 	link = nl_cli_link_alloc();
64 
65 	for (;;) {
66 		int c, optidx = 0;
67 		enum {
68 			ARG_FAMILY = 257,
69 			ARG_MTU = 258,
70 			ARG_TXQLEN,
71 			ARG_WEIGHT,
72 		};
73 		static struct option long_opts[] = {
74 			{ "format", 1, 0, 'f' },
75 			{ "help", 0, 0, 'h' },
76 			{ "version", 0, 0, 'v' },
77 			{ "name", 1, 0, 'n' },
78 			{ "index", 1, 0, 'i' },
79 			{ "family", 1, 0, ARG_FAMILY },
80 			{ "mtu", 1, 0, ARG_MTU },
81 			{ "txqlen", 1, 0, ARG_TXQLEN },
82 			{ "weight", 1, 0, ARG_WEIGHT },
83 			{ 0, 0, 0, 0 }
84 		};
85 
86 		c = getopt_long(argc, argv, "f:hvn:i:", long_opts, &optidx);
87 		if (c == -1)
88 			break;
89 
90 		switch (c) {
91 		case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
92 		case 'h': print_usage(); break;
93 		case 'v': nl_cli_print_version(); break;
94 		case 'n': nl_cli_link_parse_name(link, optarg); break;
95 		case 'i': nl_cli_link_parse_ifindex(link, optarg); break;
96 		case ARG_FAMILY: nl_cli_link_parse_family(link, optarg); break;
97 		case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break;
98 		case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break;
99 		case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break;
100 		}
101 	}
102 
103 	nl_cache_dump_filter(link_cache, &params, OBJ_CAST(link));
104 
105 	return 0;
106 }
107