Skip to contentSkip to conversation

ebtables printing of ipv6 masks

PATCH In review Mariusz Mazur 2 participants 2 messages Apr 11, 2014 – Apr 14, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ebtables printing of ipv6 masks

Currently ebtables is smart enough to not print /255.255.255.255 for ipv4 addresses, not so however for ipv6 addresses. The attached patch fixes that.

(Not sure my kmail won't mangle it, so here it is uploaded:
http://u.42.pl/2T8O )

--mmazur

extensions/ebt_ip6.c +2 -2
index 0465e77..52a8448 100644
@@ -445,14 +445,14 @@ static void print(const struct ebt_u_entry *entry,
 		if (ipinfo->invflags & EBT_IP6_SOURCE)
 			printf("! ");
 		printf("%s", ebt_ip6_to_numeric(&ipinfo->saddr));
-		printf("/%s ", ebt_ip6_to_numeric(&ipinfo->smsk));
+		printf("%s ", ebt_ip6_mask_to_string(&ipinfo->smsk));
 	}
 	if (ipinfo->bitmask & EBT_IP6_DEST) {
 		printf("--ip6-dst ");
 		if (ipinfo->invflags & EBT_IP6_DEST)
 			printf("! ");
 		printf("%s", ebt_ip6_to_numeric(&ipinfo->daddr));
-		printf("/%s ", ebt_ip6_to_numeric(&ipinfo->dmsk));
+		printf("%s ", ebt_ip6_mask_to_string(&ipinfo->smsk));
 	}
 	if (ipinfo->bitmask & EBT_IP6_TCLASS) {
 		printf("--ip6-tclass ");
include/ebtables_u.h +1 -0
index ab615c1..35a5bcc 100644
@@ -303,6 +303,7 @@ char *ebt_mask_to_dotted(uint32_t mask);
 void ebt_parse_ip6_address(char *address, struct in6_addr *addr, 
 						   struct in6_addr *msk);
 char *ebt_ip6_to_numeric(const struct in6_addr *addrp);
+char *ebt_ip6_mask_to_string(const struct in6_addr *msk);
 
 
 int do_command(int argc, char *argv[], int exec_style,
useful_functions.c +13 -0
index d20b68e..2f73589 100644
@@ -411,3 +411,16 @@ char *ebt_ip6_to_numeric(const struct in6_addr *addrp)
 	static char buf[50+1];
 	return (char *)inet_ntop(AF_INET6, addrp, buf, sizeof(buf));
 }
+
+char *ebt_ip6_mask_to_string(const struct in6_addr *msk)
+{
+   	/* /0000:0000:0000:0000:0000:000.000.000.000
+	 * /0000:0000:0000:0000:0000:0000:0000:0000 */
+	static char buf[51+1];
+	if (msk->s6_addr32[0] == 0xFFFFFFFFL && msk->s6_addr32[1] == 0xFFFFFFFFL &&
+			msk->s6_addr32[2] == 0xFFFFFFFFL && msk->s6_addr32[3] == 0xFFFFFFFFL)
+		*buf = '\0';
+	else
+		sprintf(buf, "/%s", ebt_ip6_to_numeric(msk));
+	return buf;
+}
#1 lore raw

Mariusz Mazur schreef op 11/04/2014 15:28:

Quoted 8 lines

Currently ebtables is smart enough to not print /255.255.255.255 for ipv4 addresses, not so however for ipv6 addresses. The attached patch fixes that.

(Not sure my kmail won't mangle it, so here it is uploaded:
http://u.42.pl/2T8O )

--mmazur

Your patch introduces a bug when printing the IPv6 destination mask. I've applied a fixed version.

cheers,
Bart