diff options
author | Jeremy Sowden <jeremy@azazel.net> | 2021-11-30 10:55:32 +0000 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-11-30 20:55:17 +0100 |
commit | 659926bf6ccc614757981dda5ebf51b02aab0050 (patch) | |
tree | 1dd4ab5783260bdbbd10e0211a9bb2eaf8218314 /filter/ulogd_filter_HWHDR.c | |
parent | b612f69e558bb9dad8140c1d793955e1fb2d9332 (diff) |
filter: HWHDR: re-order KEY_RAW_MAC checks
Currently, in `interp_mac2str` we have:
if (/* KEY_RAW_MAC is valid */) {
/*
* set mac type
*/
}
if (/* mac type is ethernet */)
// parse ethernet
if (/* KEY_RAW_MAC is not valid */)
// return early.
The MAC type will not be set to ethernet unless KEY_RAW_MAC is valid,
so we can move the last check up and drop the first one:
if (/* KEY_RAW_MAC is not valid */)
// return early.
/*
* set mac type
*/
if (/* mac type is ethernet */)
// parse ethernet
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'filter/ulogd_filter_HWHDR.c')
-rw-r--r-- | filter/ulogd_filter_HWHDR.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/filter/ulogd_filter_HWHDR.c b/filter/ulogd_filter_HWHDR.c index d756d35..0151215 100644 --- a/filter/ulogd_filter_HWHDR.c +++ b/filter/ulogd_filter_HWHDR.c @@ -191,28 +191,26 @@ 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; + + 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); - 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]), |