13 #include <netlink/cli/utils.h> 15 #include <linux/rtnetlink.h> 17 static void print_usage(
void)
20 "Usage: nl-fib-lookup [options] <addr>\n" 22 " -t, --table <table> Table id\n" 23 " -f, --fwmark <int> Firewall mark\n" 24 " -s, --scope <scope> Routing scope\n" 25 " -T, --tos <int> Type of Service\n");
29 int main(
int argc,
char *argv[])
32 struct nl_cache *result;
33 struct flnl_request *request;
39 int table = RT_TABLE_UNSPEC, scope = RT_SCOPE_UNIVERSE;
44 static struct option long_opts[] = {
46 {
"fwmark", 1, 0,
'f'},
54 c = getopt_long(argc, argv,
"t:f:s:T:h", long_opts, &idx);
60 table = strtoul(optarg, NULL, 0);
63 fwmark = strtoul(optarg, NULL, 0);
66 scope = strtoul(optarg, NULL, 0);
69 tos = strtoul(optarg, NULL, 0);
79 nlh = nl_cli_alloc_socket();
82 nl_cli_fatal(err,
"Unable to parse address \"%s\": %s\n",
83 argv[optind], nl_geterror(err));
89 request = flnl_request_alloc();
93 flnl_request_set_table(request, table);
94 flnl_request_set_fwmark(request, fwmark);
95 flnl_request_set_scope(request, scope);
96 flnl_request_set_tos(request, tos);
98 err = flnl_request_set_addr(request, addr);
101 nl_cli_fatal(err,
"Unable to send request: %s", nl_geterror(err));
103 nl_cli_connect(nlh, NETLINK_FIB_LOOKUP);
107 nl_cli_fatal(err,
"Unable to lookup: %s\n", nl_geterror(err));
FILE * dp_fd
File descriptor the dumping output should go to.
int nl_addr_parse(const char *addrstr, int hint, struct nl_addr **result)
Allocate abstract address based on character string.
Dump all attributes but no statistics.
int flnl_lookup(struct nl_sock *sk, struct flnl_request *req, struct nl_cache *cache)
Perform FIB Lookup.
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.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
struct nl_cache * flnl_result_alloc_cache(void)
Allocate lookup result cache.