8#include <linux/rtnetlink.h>
10#include <netlink/cli/utils.h>
12static void print_usage(
void)
15 "Usage: nl-fib-lookup [options] <addr>\n"
17 " -t, --table <table> Table id\n"
18 " -f, --fwmark <int> Firewall mark\n"
19 " -s, --scope <scope> Routing scope\n"
20 " -T, --tos <int> Type of Service\n");
24int main(
int argc,
char *argv[])
27 struct nl_cache *result;
28 struct flnl_request *request;
34 int table = RT_TABLE_UNSPEC, scope = RT_SCOPE_UNIVERSE;
39 static struct option long_opts[] = {
41 {
"fwmark", 1, 0,
'f'},
49 c = getopt_long(argc, argv,
"t:f:s:T:h", long_opts, &idx);
55 table = strtoul(optarg, NULL, 0);
58 fwmark = strtoul(optarg, NULL, 0);
61 scope = strtoul(optarg, NULL, 0);
64 tos = strtoul(optarg, NULL, 0);
74 nlh = nl_cli_alloc_socket();
77 nl_cli_fatal(err,
"Unable to parse address \"%s\": %s\n",
78 argv[optind], nl_geterror(err));
84 request = flnl_request_alloc();
88 flnl_request_set_table(request, table);
89 flnl_request_set_fwmark(request, fwmark);
90 flnl_request_set_scope(request, scope);
91 flnl_request_set_tos(request, tos);
93 err = flnl_request_set_addr(request, addr);
96 nl_cli_fatal(err,
"Unable to send request: %s", nl_geterror(err));
98 nl_cli_connect(nlh, NETLINK_FIB_LOOKUP);
102 nl_cli_fatal(err,
"Unable to lookup: %s\n", nl_geterror(err));
int nl_addr_parse(const char *addrstr, int hint, struct nl_addr **result)
Allocate abstract address based on character string.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
struct nl_cache * flnl_result_alloc_cache(void)
Allocate lookup result cache.
int flnl_lookup(struct nl_sock *sk, struct flnl_request *req, struct nl_cache *cache)
Perform FIB Lookup.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
FILE * dp_fd
File descriptor the dumping output should go to.