]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
filter: HWHDR: re-order KEY_RAW_MAC checks
authorJeremy Sowden <jeremy@azazel.net>
Tue, 30 Nov 2021 10:55:32 +0000 (10:55 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 30 Nov 2021 19:55:17 +0000 (20:55 +0100)
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>
filter/ulogd_filter_HWHDR.c

index d756d35577f061c12adfcf082d8bafb2395844f1..015121511b08dbd24dd99726ec5fae92543295f7 100644 (file)
@@ -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]),