summaryrefslogtreecommitdiffstats
path: root/filter/ulogd_filter_HWHDR.c
diff options
context:
space:
mode:
Diffstat (limited to 'filter/ulogd_filter_HWHDR.c')
-rw-r--r--filter/ulogd_filter_HWHDR.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/filter/ulogd_filter_HWHDR.c b/filter/ulogd_filter_HWHDR.c
index 10c95c4..a5ee60d 100644
--- a/filter/ulogd_filter_HWHDR.c
+++ b/filter/ulogd_filter_HWHDR.c
@@ -109,7 +109,7 @@ static struct ulogd_key mac2str_keys[] = {
},
};
-static char hwmac_str[MAX_KEY - START_KEY][HWADDR_LENGTH];
+static char hwmac_str[MAX_KEY - START_KEY + 1][HWADDR_LENGTH];
static int parse_mac2str(struct ulogd_key *ret, unsigned char *mac,
int okey, int len)
@@ -126,7 +126,7 @@ static int parse_mac2str(struct ulogd_key *ret, unsigned char *mac,
buf_cur = hwmac_str[okey - START_KEY];
for (i = 0; i < len; i++)
buf_cur += sprintf(buf_cur, "%02x%c", mac[i],
- i == len - 1 ? 0 : ':');
+ i == len - 1 ? 0 : ':');
okey_set_ptr(&ret[okey], hwmac_str[okey - START_KEY]);
@@ -171,7 +171,7 @@ static int interp_mac2str(struct ulogd_pluginstance *pi)
{
struct ulogd_key *ret = pi->output.keys;
struct ulogd_key *inp = pi->input.keys;
- uint16_t type = 0;
+ uint16_t type;
if (pp_is_valid(inp, KEY_OOB_PROTOCOL))
okey_set_u16(&ret[KEY_MAC_PROTOCOL],
@@ -191,35 +191,31 @@ static int interp_mac2str(struct ulogd_pluginstance *pi)
okey_set_u16(&ret[KEY_MAC_TYPE], ARPHRD_VOID);
}
- if (pp_is_valid(inp, KEY_RAW_MAC)) {
- if (! pp_is_valid(inp, KEY_RAW_MACLEN))
- return ULOGD_IRET_ERR;
- if (pp_is_valid(inp, KEY_RAW_TYPE)) {
- /* NFLOG with Linux >= 2.6.27 case */
- type = ikey_get_u16(&inp[KEY_RAW_TYPE]);
- } else {
- /* ULOG case, treat ethernet encapsulation */
- if (ikey_get_u16(&inp[KEY_RAW_MACLEN]) == ETH_HLEN)
- type = ARPHRD_ETHER;
- else
- type = ARPHRD_VOID;
- }
- okey_set_u16(&ret[KEY_MAC_TYPE], type);
- }
+ if (!pp_is_valid(inp, KEY_RAW_MAC))
+ return ULOGD_IRET_OK;
- switch (type) {
- case ARPHRD_ETHER:
- parse_ethernet(ret, inp);
- default:
- if (!pp_is_valid(inp, KEY_RAW_MAC))
- return ULOGD_IRET_OK;
- /* convert raw header to string */
- return parse_mac2str(ret,
- ikey_get_ptr(&inp[KEY_RAW_MAC]),
- KEY_MAC_ADDR,
- ikey_get_u16(&inp[KEY_RAW_MACLEN]));
- }
- return ULOGD_IRET_OK;
+ if (!pp_is_valid(inp, KEY_RAW_MACLEN))
+ return ULOGD_IRET_ERR;
+
+ if (pp_is_valid(inp, KEY_RAW_TYPE))
+ /* NFLOG with Linux >= 2.6.27 case */
+ type = ikey_get_u16(&inp[KEY_RAW_TYPE]);
+ else if (ikey_get_u16(&inp[KEY_RAW_MACLEN]) == ETH_HLEN)
+ /* ULOG case, treat ethernet encapsulation */
+ type = ARPHRD_ETHER;
+ else
+ type = ARPHRD_VOID;
+
+ okey_set_u16(&ret[KEY_MAC_TYPE], type);
+
+ if (type == ARPHRD_ETHER)
+ parse_ethernet(ret, inp);
+
+ /* convert raw header to string */
+ return parse_mac2str(ret,
+ ikey_get_ptr(&inp[KEY_RAW_MAC]),
+ KEY_MAC_ADDR,
+ ikey_get_u16(&inp[KEY_RAW_MACLEN]));
}