From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net, eric@regit.org, tomasz.bursztyka@linux.intel.com
Subject: [PATCH 3/5] meta: use if_nametoindex and if_indextoname
Date: Fri, 21 Jun 2013 16:42:17 +0200 [thread overview]
Message-ID: <1371825739-3669-3-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1371825739-3669-1-git-send-email-pablo@netfilter.org>
Instead of having a cache of ifindex based on libnl. Those functions
basically use rtnetlink as well to perform the translation.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/meta.c | 48 ++++--------------------------------------------
1 file changed, 4 insertions(+), 44 deletions(-)
diff --git a/src/meta.c b/src/meta.c
index 54d4d64..c5719b9 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
+#include <net/if.h>
#include <net/if_arp.h>
#include <pwd.h>
#include <grp.h>
@@ -96,43 +97,13 @@ static const struct datatype tchandle_type = {
.parse = tchandle_type_parse,
};
-static struct nl_cache *link_cache;
-
-static int link_cache_init(void)
-{
- struct nl_sock *rt_sock;
- int err;
-
- rt_sock = nl_socket_alloc();
- if (rt_sock == NULL)
- memory_allocation_error();
-
- err = nl_connect(rt_sock, NETLINK_ROUTE);
- if (err < 0)
- goto err;
- err = rtnl_link_alloc_cache(rt_sock, &link_cache);
- if (err < 0)
- goto err;
- nl_cache_mngt_provide(link_cache);
- nl_socket_free(rt_sock);
- return 0;
-
-err:
- nl_socket_free(rt_sock);
- return err;
-}
-
static void ifindex_type_print(const struct expr *expr)
{
char name[IFNAMSIZ];
int ifindex;
- if (link_cache == NULL)
- link_cache_init();
-
ifindex = mpz_get_uint32(expr->value);
- if (link_cache != NULL &&
- rtnl_link_i2name(link_cache, ifindex, name, sizeof(name)))
+ if (if_indextoname(ifindex, name))
printf("%s", name);
else
printf("%d", ifindex);
@@ -141,15 +112,9 @@ static void ifindex_type_print(const struct expr *expr)
static struct error_record *ifindex_type_parse(const struct expr *sym,
struct expr **res)
{
- int ifindex, err;
-
- if (link_cache == NULL &&
- (err = link_cache_init()) < 0)
- return error(&sym->location,
- "Could not initialize link cache: %s",
- nl_geterror(err));
+ int ifindex;
- ifindex = rtnl_link_name2i(link_cache, sym->identifier);
+ ifindex = if_nametoindex(sym->identifier);
if (ifindex == 0)
return error(&sym->location, "Interface does not exist");
@@ -159,11 +124,6 @@ static struct error_record *ifindex_type_parse(const struct expr *sym,
return NULL;
}
-static void __exit ifindex_table_free(void)
-{
- nl_cache_free(link_cache);
-}
-
static const struct datatype ifindex_type = {
.type = TYPE_IFINDEX,
.name = "ifindex",
--
1.7.10.4
next prev parent reply other threads:[~2013-06-21 14:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-21 14:42 [PATCH 1/5] src: get it sync with current include/linux/netfilter/nf_tables.h Pablo Neira Ayuso
2013-06-21 14:42 ` [PATCH 2/5] rule: family field in struct handle is unsigned Pablo Neira Ayuso
2013-06-21 14:42 ` Pablo Neira Ayuso [this message]
2013-06-21 14:42 ` [PATCH 4/5] meta: replace rtnl_tc_handle2str and rtnl_tc_str2handle Pablo Neira Ayuso
2013-06-21 14:42 ` [PATCH 5/5] src: use libnftables Pablo Neira Ayuso
2013-06-28 8:03 ` [PATCH 1/5] src: get it sync with current include/linux/netfilter/nf_tables.h Giuseppe Longo
2013-06-28 10:58 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371825739-3669-3-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=eric@regit.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=tomasz.bursztyka@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).