summaryrefslogtreecommitdiffstats
path: root/filter
diff options
context:
space:
mode:
authorEric Leblond <eric@inl.fr>2009-03-02 22:40:09 +0100
committerEric Leblond <eric@inl.fr>2009-03-06 20:31:23 +0100
commit411da4d946a68d59005fece7fcdb0c48a228166b (patch)
treeb3571be86111be1084f16cd5a43838ff4c1c1637 /filter
parentbaa74c54acc5a244ccc27b8919568618019fcfaa (diff)
ifindex: avoid memory allocation
This patch modifies the interp function to avoid to do an explicit allocation of memory.
Diffstat (limited to 'filter')
-rw-r--r--filter/ulogd_filter_IFINDEX.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/filter/ulogd_filter_IFINDEX.c b/filter/ulogd_filter_IFINDEX.c
index f56ee0b..152c26d 100644
--- a/filter/ulogd_filter_IFINDEX.c
+++ b/filter/ulogd_filter_IFINDEX.c
@@ -30,12 +30,14 @@
static struct ulogd_key ifindex_keys[] = {
{
.type = ULOGD_RET_STRING,
- .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
+ .len = IFNAMSIZ,
+ .flags = ULOGD_RETF_NONE,
.name = "oob.in",
},
{
.type = ULOGD_RET_STRING,
- .flags = ULOGD_RETF_NONE | ULOGD_RETF_FREE,
+ .len = IFNAMSIZ,
+ .flags = ULOGD_RETF_NONE,
.name = "oob.out",
},
};
@@ -62,25 +64,18 @@ static int interp_ifindex(struct ulogd_pluginstance *pi)
{
struct ulogd_key *ret = pi->output.keys;
struct ulogd_key *inp = pi->input.keys;
- void *ptr;
-
- ptr = calloc(IFNAMSIZ, sizeof(char));
- if (!ptr)
- return ULOGD_IRET_ERR;
-
- nlif_index2name(nlif_inst, ikey_get_u32(&inp[0]), ptr);
- if (((char *)ptr)[0] == '*')
- ((char *)(ptr))[0] = 0;
- okey_set_ptr(&ret[0], ptr);
-
- ptr = calloc(IFNAMSIZ, sizeof(char));
- if (!ptr)
- return ULOGD_IRET_ERR;
-
- nlif_index2name(nlif_inst, ikey_get_u32(&inp[1]), ptr);
- if (((char *)ptr)[0] == '*')
- ((char *)(ptr))[0] = 0;
- okey_set_ptr(&ret[1], ptr);
+ static char indev[IFNAMSIZ];
+ static char outdev[IFNAMSIZ];
+
+ nlif_index2name(nlif_inst, ikey_get_u32(&inp[0]), indev);
+ if (indev[0] == '*')
+ indev[0] = 0;
+ okey_set_ptr(&ret[0], indev);
+
+ nlif_index2name(nlif_inst, ikey_get_u32(&inp[1]), outdev);
+ if (outdev[0] == '*')
+ outdev[0] = 0;
+ okey_set_ptr(&ret[1], outdev);
return ULOGD_IRET_OK;
}