netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iproute2: support dotted-quad netmask notation.
@ 2007-12-04 13:58 Andreas Henriksson
  2007-12-06 19:53 ` Stephen Hemminger
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Henriksson @ 2007-12-04 13:58 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

Suggested patch for allowing netmask to be specified in dotted quad format.
See http://bugs.debian.org/357172

(Known problem: this will not prevent some invalid syntaxes,
ie. "255.0.255.0" will be treated as "255.255.255.0")

Comments? Suggestions? Improvements?

Signed-off-by: Andreas Henriksson <andreas@fatal.se>


diff --git a/lib/utils.c b/lib/utils.c
index 4c42dfd..277ab45 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -47,6 +47,25 @@ int get_integer(int *val, const char *arg, int base)
 	return 0;
 }
 
+int get_netmask(unsigned *val, const char *arg, int base)
+{
+	inet_prefix addr;
+
+	if (!get_unsigned(val, arg, base))
+		return 0;
+
+	/* try coverting dotted quad to CIDR */
+	if (!get_addr_1(&addr, arg, AF_INET)) {
+		u_int32_t mask;
+		*val=0;
+		for (mask = addr.data[0]; mask; mask >>= 1)
+			(*val)++;
+		return 0;
+	}
+
+	return -1;
+}
+
 int get_unsigned(unsigned *val, const char *arg, int base)
 {
 	unsigned long res;
@@ -304,7 +323,8 @@ int get_prefix_1(inet_prefix *dst, char *arg, int family)
 				dst->bitlen = 32;
 		}
 		if (slash) {
-			if (get_unsigned(&plen, slash+1, 0) || plen > dst->bitlen) {
+			if (get_netmask(&plen, slash+1, 0)
+					|| plen > dst->bitlen) {
 				err = -1;
 				goto done;
 			}

-- 
Regards,
Andreas Henriksson

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-12-12 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-04 13:58 [PATCH] iproute2: support dotted-quad netmask notation Andreas Henriksson
2007-12-06 19:53 ` Stephen Hemminger
2007-12-07 23:41   ` Andreas Henriksson
2007-12-09 17:10     ` Andreas Henriksson
2007-12-12  1:14       ` Stephen Hemminger
2007-12-12 11:55         ` Andreas Henriksson
2007-12-12 16:40           ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).