Do not rely on ether_ntoa() when formatting mac addresses.
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 29 Jun 2013 13:07:29 +0000 (15:07 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 29 Jun 2013 13:10:07 +0000 (15:10 +0200)
The ether_ntoa() in libc does not include leading zeroes in the formatted
address, this causes the address to not get recognized by iptables 1.4.10
which expects a fixed length for mac strings.

iptables.c

index 7d91452ff6f455cd3551a08cbe38c1d1590109b3..c323e45a8efb5d6e64ea4838a297c5cab640b6d4 100644 (file)
@@ -746,11 +746,17 @@ fw3_ipt_rule_sport_dport(struct fw3_ipt_rule *r,
 void
 fw3_ipt_rule_mac(struct fw3_ipt_rule *r, struct fw3_mac *mac)
 {
+       char buf[sizeof("ff:ff:ff:ff:ff:ff\0")];
+
        if (!mac)
                return;
 
+       sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
+               mac->mac[0], mac->mac[1], mac->mac[2],
+               mac->mac[3], mac->mac[4], mac->mac[5]);
+
        fw3_ipt_rule_addarg(r, false, "-m", "mac");
-       fw3_ipt_rule_addarg(r, mac->invert, "--mac-source", ether_ntoa(&mac->mac));
+       fw3_ipt_rule_addarg(r, mac->invert, "--mac-source", buf);
 }
 
 void