summaryrefslogtreecommitdiffstats
path: root/filter/ulogd_filter_IFINDEX.c
diff options
context:
space:
mode:
Diffstat (limited to 'filter/ulogd_filter_IFINDEX.c')
-rw-r--r--filter/ulogd_filter_IFINDEX.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/filter/ulogd_filter_IFINDEX.c b/filter/ulogd_filter_IFINDEX.c
index b386f4a..468a4c4 100644
--- a/filter/ulogd_filter_IFINDEX.c
+++ b/filter/ulogd_filter_IFINDEX.c
@@ -24,19 +24,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <ulogd/ulogd.h>
-
-#include "rtnl.h"
-#include "iftable.h"
+#include <libnfnetlink/libnfnetlink.h>
static struct ulogd_key ifindex_keys[] = {
{
.type = ULOGD_RET_STRING,
- .flags = ULOGD_RETF_NONE,
+ .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
.name = "oob.in",
},
{
.type = ULOGD_RET_STRING,
- .flags = ULOGD_RETF_NONE,
+ .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
.name = "oob.out",
},
};
@@ -52,31 +50,41 @@ static struct ulogd_key ifindex_inp[] = {
},
};
+/* we only need one global static cache of ifindex to ifname mappings,
+ * so all state is global (as opposed to per-instance local state in almost
+ * all other plugins */
+static struct ulogd_fd nlif_u_fd = { .fd = -1 };
+static int nlif_users;
+static struct nlif_handle *nlif_inst;
+
static int interp_ifindex(struct ulogd_pluginstance *pi)
{
struct ulogd_key *ret = pi->output.keys;
struct ulogd_key *inp = pi->input.keys;
- ret[0].u.value.ptr = ifindex_2name(inp[0].u.source->u.value.ui32);
+ ret[0].u.value.ptr = calloc(IFNAMSIZ, sizeof(char));
+ nlif_index2name(nlif_inst, inp[0].u.source->u.value.ui32,
+ ret[0].u.value.ptr);
+ if (((char *)ret[0].u.value.ptr)[0] == '*')
+ ((char *)(ret[0].u.value.ptr))[0] = 0;
ret[0].flags |= ULOGD_RETF_VALID;
- ret[1].u.value.ptr = ifindex_2name(inp[1].u.source->u.value.ui32);
+
+ ret[1].u.value.ptr = calloc(IFNAMSIZ, sizeof(char));
+ nlif_index2name(nlif_inst, inp[1].u.source->u.value.ui32,
+ ret[1].u.value.ptr);
+ if (((char *)ret[1].u.value.ptr)[0] == '*')
+ ((char *)(ret[1].u.value.ptr))[0] = 0;
ret[1].flags |= ULOGD_RETF_VALID;
return 0;
}
-/* we only need one global static cache of ifindex to ifname mappings,
- * so all state is global (as opposed to per-instance local state in almost
- * all other plugins */
-static struct ulogd_fd rtnl_fd = { .fd = -1 };
-static int rtnl_users;
-
-static int rtnl_read_cb(int fd, unsigned int what, void *param)
+static int nlif_read_cb(int fd, unsigned int what, void *param)
{
if (!(what & ULOGD_FD_READ))
return 0;
- rtnl_receive();
+ nlif_catch(nlif_inst);
}
static int ifindex_start(struct ulogd_pluginstance *upi)
@@ -84,44 +92,40 @@ static int ifindex_start(struct ulogd_pluginstance *upi)
int rc;
/* if we're already initialized, inc usage count and exit */
- if (rtnl_fd.fd >= 0) {
- rtnl_users++;
+ if (nlif_u_fd.fd >= 0) {
+ nlif_users++;
return 0;
}
/* if we reach here, we need to initialize */
- rtnl_fd.fd = rtnl_init();
- if (rtnl_fd.fd < 0)
- return rtnl_fd.fd;
-
- rc = iftable_init();
- if (rc < 0)
- goto out_rtnl;
-
- rtnl_fd.when = ULOGD_FD_READ;
- rtnl_fd.cb = &rtnl_read_cb;
- rc = ulogd_register_fd(&rtnl_fd);
+ nlif_inst = nlif_open();
+ if (nlif_inst == NULL) {
+ return nlif_u_fd.fd;
+ }
+ nlif_query(nlif_inst);
+
+ nlif_u_fd.fd = nlif_fd(nlif_inst);
+ nlif_u_fd.when = ULOGD_FD_READ;
+ nlif_u_fd.cb = &nlif_read_cb;
+ rc = ulogd_register_fd(&nlif_u_fd);
if (rc < 0)
- goto out_iftable;
+ goto out_nlif;
- rtnl_users++;
+ nlif_users++;
return 0;
-out_iftable:
- iftable_fini();
-out_rtnl:
- rtnl_fini();
- rtnl_fd.fd = -1;
+out_nlif:
+ nlif_close(nlif_inst);
+ nlif_u_fd.fd = -1;
return rc;
}
static int ifindex_fini(struct ulogd_pluginstance *upi)
{
- if (--rtnl_users == 0) {
- ulogd_unregister_fd(&rtnl_fd);
- iftable_fini();
- rtnl_fini();
- rtnl_fd.fd = -1;
+ if (--nlif_users == 0) {
+ ulogd_unregister_fd(&nlif_u_fd);
+ nlif_close(nlif_inst);
+ nlif_u_fd.fd = -1;
}
return 0;