6#include <netlink/cli/utils.h>
8#include <linux/rtnetlink.h>
10static void print_usage(
void)
13 "Usage: nl-fib-lookup [options] <addr>\n"
15 " -t, --table <table> Table id\n"
16 " -f, --fwmark <int> Firewall mark\n"
17 " -s, --scope <scope> Routing scope\n"
18 " -T, --tos <int> Type of Service\n");
22int main(
int argc,
char *argv[])
25 struct nl_cache *result;
26 struct flnl_request *request;
32 int table = RT_TABLE_UNSPEC, scope = RT_SCOPE_UNIVERSE;
37 static struct option long_opts[] = {
39 {
"fwmark", 1, 0,
'f'},
47 c = getopt_long(argc, argv,
"t:f:s:T:h", long_opts, &idx);
53 table = strtoul(optarg, NULL, 0);
56 fwmark = strtoul(optarg, NULL, 0);
59 scope = strtoul(optarg, NULL, 0);
62 tos = strtoul(optarg, NULL, 0);
72 nlh = nl_cli_alloc_socket();
75 nl_cli_fatal(err,
"Unable to parse address \"%s\": %s\n",
76 argv[optind], nl_geterror(err));
82 request = flnl_request_alloc();
86 flnl_request_set_table(request, table);
87 flnl_request_set_fwmark(request, fwmark);
88 flnl_request_set_scope(request, scope);
89 flnl_request_set_tos(request, tos);
91 err = flnl_request_set_addr(request, addr);
94 nl_cli_fatal(err,
"Unable to send request: %s", nl_geterror(err));
96 nl_cli_connect(nlh, NETLINK_FIB_LOOKUP);
100 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.