All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mariusz Mazur <mmazur@axeos.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] ebtables printing of ipv6 masks
Date: Fri, 11 Apr 2014 15:28:41 +0200	[thread overview]
Message-ID: <201404111528.42153.mmazur@axeos.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 246 bytes --]

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

[-- Attachment #2: ipv6_netmask_printing_fix.patch --]
[-- Type: text/x-patch, Size: 2009 bytes --]

diff --git a/extensions/ebt_ip6.c b/extensions/ebt_ip6.c
index 0465e77..52a8448 100644
--- a/extensions/ebt_ip6.c
+++ b/extensions/ebt_ip6.c
@@ -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 ");
diff --git a/include/ebtables_u.h b/include/ebtables_u.h
index ab615c1..35a5bcc 100644
--- a/include/ebtables_u.h
+++ b/include/ebtables_u.h
@@ -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,
diff --git a/useful_functions.c b/useful_functions.c
index d20b68e..2f73589 100644
--- a/useful_functions.c
+++ b/useful_functions.c
@@ -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;
+}

             reply	other threads:[~2014-04-11 13:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11 13:28 Mariusz Mazur [this message]
2014-04-14 20:14 ` [PATCH] ebtables printing of ipv6 masks Bart De Schuymer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201404111528.42153.mmazur@axeos.com \
    --to=mmazur@axeos.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.