From 3ed296118a065caff5600e60d4f7ef18e137f9a0 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 9 Apr 2015 14:15:15 +0200 Subject: src: restore interface to index cache nftables used to have a cache to speed up interface name <-> index lookup, restore it using libmnl. This reduces netlink traffic since if_nametoindex() and if_indextoname() open, send a request, receive the list of interface and close a netlink socket for each call. I think this is also good for consistency since nft -f will operate with the same index number when reloading the ruleset. The cache is populated by when nft_if_nametoindex() and nft_if_indextoname() are used for first time. Then, it it released in the output path. In the interactive mode, it is invalidated after each command. Signed-off-by: Pablo Neira Ayuso --- include/iface.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/iface.h (limited to 'include/iface.h') diff --git a/include/iface.h b/include/iface.h new file mode 100644 index 00000000..f41ee8be --- /dev/null +++ b/include/iface.h @@ -0,0 +1,18 @@ +#ifndef _NFTABLES_IFACE_H_ +#define _NFTABLES_IFACE_H_ + +#include + +struct iface { + struct list_head list; + char name[IFNAMSIZ]; + uint32_t ifindex; +}; + +unsigned int nft_if_nametoindex(const char *name); +char *nft_if_indextoname(unsigned int ifindex, char *name); + +void iface_cache_update(void); +void iface_cache_release(void); + +#endif -- cgit v1.2.3