-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-only */ | ||
/* | ||
* Copyright (c) 2022 Stanislav Zaikin <[email protected]> | ||
*/ | ||
|
||
#ifndef __NETLINK_CLI_NH_H_ | ||
#define __NETLINK_CLI_NH_H_ | ||
|
||
#include <netlink/route/nh.h> | ||
#include <netlink/cli/utils.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern struct rtnl_nh *nl_cli_nh_alloc(void); | ||
extern struct nl_cache *nl_cli_nh_alloc_cache_family(struct nl_sock *, int); | ||
extern struct nl_cache *nl_cli_nh_alloc_cache_family_flags(struct nl_sock *, int, | ||
unsigned int); | ||
extern struct nl_cache *nl_cli_nh_alloc_cache(struct nl_sock *); | ||
extern struct nl_cache *nl_cli_nh_alloc_cache_flags(struct nl_sock *, | ||
unsigned int); | ||
|
||
extern void nl_cli_nh_parse_family(struct rtnl_nh *, char *); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-only */ | ||
/* | ||
* Copyright (c) 2022 Stanislav Zaikin <[email protected]> | ||
*/ | ||
|
||
/** | ||
* @ingroup cli | ||
* @defgroup cli_nh nhs | ||
* | ||
* @{ | ||
*/ | ||
|
||
#include <netlink/cli/utils.h> | ||
#include <netlink/cli/nh.h> | ||
#include <netlink/route/nh.h> | ||
#include <linux/if.h> | ||
|
||
struct rtnl_nh *nl_cli_nh_alloc(void) | ||
{ | ||
struct rtnl_nh *nh; | ||
|
||
nh = rtnl_nh_alloc(); | ||
if (!nh) | ||
nl_cli_fatal(ENOMEM, "Unable to allocate nh object"); | ||
|
||
return nh; | ||
} | ||
|
||
struct nl_cache *nl_cli_nh_alloc_cache_family_flags(struct nl_sock *sock, | ||
int family, | ||
unsigned int flags) | ||
{ | ||
struct nl_cache *cache; | ||
int err; | ||
|
||
if ((err = rtnl_nh_alloc_cache(sock, family, &cache)) < 0) | ||
nl_cli_fatal(err, "Unable to allocate nh cache: %s", | ||
nl_geterror(err)); | ||
|
||
nl_cache_mngt_provide(cache); | ||
|
||
return cache; | ||
} | ||
|
||
struct nl_cache *nl_cli_nh_alloc_cache_family(struct nl_sock *sock, int family) | ||
{ | ||
return nl_cli_nh_alloc_cache_family_flags(sock, family, 0); | ||
} | ||
|
||
struct nl_cache *nl_cli_nh_alloc_cache(struct nl_sock *sock) | ||
{ | ||
return nl_cli_nh_alloc_cache_family(sock, AF_UNSPEC); | ||
} | ||
|
||
struct nl_cache *nl_cli_nh_alloc_cache_flags(struct nl_sock *sock, | ||
unsigned int flags) | ||
{ | ||
return nl_cli_nh_alloc_cache_family_flags(sock, AF_UNSPEC, flags); | ||
} | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-only */ | ||
/* | ||
* Copyright (c) 2003-2010 Thomas Graf <[email protected]> | ||
*/ | ||
|
||
#include <netlink/cli/utils.h> | ||
#include <netlink/cli/nh.h> | ||
|
||
#include <netlink/route/nh.h> | ||
|
||
#include <linux/netlink.h> | ||
|
||
static void print_usage(void) | ||
{ | ||
printf( | ||
"Usage: nl-nh-list [OPTIONS]... \n" | ||
"\n" | ||
"OPTIONS\n" | ||
" --details Show detailed information of each link\n" | ||
" -h, --help Show this help text.\n" | ||
" -v, --version Show versioning information.\n" | ||
"\n" | ||
" -n, --name=NAME Name of link\n" | ||
" -i, --index Interface index (unique identifier)\n" | ||
" --family=NAME Link address family\n" | ||
); | ||
exit(0); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
struct nl_sock *sock; | ||
struct nl_cache *link_cache; | ||
struct nl_dump_params params = { | ||
.dp_type = NL_DUMP_LINE, | ||
.dp_fd = stdout, | ||
}; | ||
|
||
sock = nl_cli_alloc_socket(); | ||
nl_cli_connect(sock, NETLINK_ROUTE); | ||
|
||
for (;;) { | ||
int c, optidx = 0; | ||
enum { | ||
ARG_FAMILY = 257, | ||
ARG_DETAILS, | ||
}; | ||
static struct option long_opts[] = { | ||
{ "details", 0, 0, ARG_DETAILS }, | ||
{ "help", 0, 0, 'h' }, | ||
{ "version", 0, 0, 'v' }, | ||
{ "name", 1, 0, 'n' }, | ||
{ 0, 0, 0, 0 } | ||
}; | ||
|
||
c = getopt_long(argc, argv, "hvn:i:", long_opts, &optidx); | ||
if (c == -1) | ||
break; | ||
|
||
switch (c) { | ||
case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break; | ||
case 'h': print_usage(); break; | ||
case 'v': nl_cli_print_version(); break; | ||
} | ||
} | ||
|
||
link_cache = nl_cli_nh_alloc_cache(sock); | ||
|
||
nl_cache_dump(link_cache, ¶ms); | ||
|
||
return 0; | ||
} |