|
Packit Service |
f991dd |
/* SPDX-License-Identifier: LGPL-2.1-only */
|
|
Packit Service |
f991dd |
/*
|
|
Packit Service |
f991dd |
* src/nl-link-dump.c Dump link attributes
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
f991dd |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
f991dd |
* License as published by the Free Software Foundation version 2.1
|
|
Packit Service |
f991dd |
* of the License.
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
|
|
Packit Service |
f991dd |
*/
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <netlink/cli/utils.h>
|
|
Packit Service |
f991dd |
#include <netlink/cli/link.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <linux/netlink.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
static void print_usage(void)
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
printf(
|
|
Packit Service |
f991dd |
"Usage: nl-link-list [OPTIONS]... \n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
"OPTIONS\n"
|
|
Packit Service |
f991dd |
" --details Show detailed information of each link\n"
|
|
Packit Service |
f991dd |
" --stats Show statistics, implies --details\n"
|
|
Packit Service |
f991dd |
" -h, --help Show this help text.\n"
|
|
Packit Service |
f991dd |
" -v, --version Show versioning information.\n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
" -n, --name=NAME Name of link\n"
|
|
Packit Service |
f991dd |
" -i, --index Interface index (unique identifier)\n"
|
|
Packit Service |
f991dd |
" --family=NAME Link address family\n"
|
|
Packit Service |
f991dd |
" --mtu=NUM MTU value\n"
|
|
Packit Service |
f991dd |
" --txqlen=NUM TX queue length\n"
|
|
Packit Service |
f991dd |
" --weight=NUM Weight\n"
|
|
Packit Service |
f991dd |
);
|
|
Packit Service |
f991dd |
exit(0);
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
int main(int argc, char *argv[])
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
struct nl_sock *sock;
|
|
Packit Service |
f991dd |
struct nl_cache *link_cache;
|
|
Packit Service |
f991dd |
struct rtnl_link *link;
|
|
Packit Service |
f991dd |
struct nl_dump_params params = {
|
|
Packit Service |
f991dd |
.dp_type = NL_DUMP_LINE,
|
|
Packit Service |
f991dd |
.dp_fd = stdout,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
sock = nl_cli_alloc_socket();
|
|
Packit Service |
f991dd |
nl_cli_connect(sock, NETLINK_ROUTE);
|
|
Packit Service |
f991dd |
link = nl_cli_link_alloc();
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
for (;;) {
|
|
Packit Service |
f991dd |
int c, optidx = 0;
|
|
Packit Service |
f991dd |
enum {
|
|
Packit Service |
f991dd |
ARG_FAMILY = 257,
|
|
Packit Service |
f991dd |
ARG_MTU = 258,
|
|
Packit Service |
f991dd |
ARG_TXQLEN,
|
|
Packit Service |
f991dd |
ARG_WEIGHT,
|
|
Packit Service |
f991dd |
ARG_DETAILS,
|
|
Packit Service |
f991dd |
ARG_STATS,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
static struct option long_opts[] = {
|
|
Packit Service |
f991dd |
{ "details", 0, 0, ARG_DETAILS },
|
|
Packit Service |
f991dd |
{ "stats", 0, 0, ARG_STATS },
|
|
Packit Service |
f991dd |
{ "help", 0, 0, 'h' },
|
|
Packit Service |
f991dd |
{ "version", 0, 0, 'v' },
|
|
Packit Service |
f991dd |
{ "name", 1, 0, 'n' },
|
|
Packit Service |
f991dd |
{ "index", 1, 0, 'i' },
|
|
Packit Service |
f991dd |
{ "family", 1, 0, ARG_FAMILY },
|
|
Packit Service |
f991dd |
{ "mtu", 1, 0, ARG_MTU },
|
|
Packit Service |
f991dd |
{ "txqlen", 1, 0, ARG_TXQLEN },
|
|
Packit Service |
f991dd |
{ "weight", 1, 0, ARG_WEIGHT },
|
|
Packit Service |
f991dd |
{ 0, 0, 0, 0 }
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
c = getopt_long(argc, argv, "hvn:i:", long_opts, &optidx);
|
|
Packit Service |
f991dd |
if (c == -1)
|
|
Packit Service |
f991dd |
break;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
switch (c) {
|
|
Packit Service |
f991dd |
case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break;
|
|
Packit Service |
f991dd |
case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
|
|
Packit Service |
f991dd |
case 'h': print_usage(); break;
|
|
Packit Service |
f991dd |
case 'v': nl_cli_print_version(); break;
|
|
Packit Service |
f991dd |
case 'n': nl_cli_link_parse_name(link, optarg); break;
|
|
Packit Service |
f991dd |
case 'i': nl_cli_link_parse_ifindex(link, optarg); break;
|
|
Packit Service |
f991dd |
case ARG_FAMILY: nl_cli_link_parse_family(link, optarg); break;
|
|
Packit Service |
f991dd |
case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break;
|
|
Packit Service |
f991dd |
case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break;
|
|
Packit Service |
f991dd |
case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break;
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
link_cache = nl_cli_link_alloc_cache_family(sock,
|
|
Packit Service |
f991dd |
rtnl_link_get_family(link));
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
nl_cache_dump_filter(link_cache, ¶ms, OBJ_CAST(link));
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
return 0;
|
|
Packit Service |
f991dd |
}
|