shithub: riscv

Download patch

ref: 97d45a546856be1c45610f8aa087275c5efc8001
parent: 584343aa16e46bbae615922e00e1573f93d98a52
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Feb 11 18:33:44 EST 2019

ip/6in4: use parseipandmask(), use ipvmp() instead of equivip6()

--- a/sys/src/cmd/ip/6in4.c
+++ b/sys/src/cmd/ip/6in4.c
@@ -91,44 +91,28 @@
 static void
 procargs(int argc, char **argv)
 {
-	char *p, *loc6;
+	char *ipstr, *maskstr;
 
 	if (argc < 1)
-		loc6 = defv6addr();
+		ipstr = defv6addr();
 	else if (strcmp(argv[0], "-") == 0) {
-		loc6 = defv6addr();
-		argv++;
-		argc--;
-	} else {
-		loc6 = *argv++;
-		argc--;
-	}
-
-	/* local v6 address (mask defaults to /128) */
-	memcpy(localmask, IPallbits, sizeof localmask);
-	p = strchr(loc6, '/');
-	if (p != nil) {
-		parseipmask(localmask, p);
-		*p = 0;
-	}
-	if (parseip(local6, loc6) == -1)
-		sysfatal("bad local v6 address %s", loc6);
-	if (isv4(local6))
-		usage();
-	if (argc >= 1 && argv[0][0] == '/') {
-		parseipmask(localmask, *argv++);
-		argc--;
-	}
+		argv++, argc--;
+		ipstr = defv6addr();
+	} else
+		ipstr = *argv++, argc--;
+	maskstr = strchr(ipstr, '/');
+	if (maskstr == nil && argc >= 1 && **argv == '/')
+		maskstr = *argv++, argc--;
+	if (parseipandmask(local6, localmask, ipstr, maskstr) == -1 || isv4(local6))
+		sysfatal("bad local v6 address/mask: %s", ipstr);
 	if (debug)
 		fprint(2, "local6 %I %M\n", local6, localmask);
 
 	/* remote v4 address (defaults to anycast 6to4) */
 	if (argc >= 1) {
-		if (parseip(remote4, *argv++) == -1)
-			sysfatal("bad remote v4 address %s", argv[-1]);
 		argc--;
-		if (!isv4(remote4))
-			usage();
+		if (parseip(remote4, *argv++) == -1 || !isv4(remote4))
+			sysfatal("bad remote v4 address %s", argv[-1]);
 	} else {
 		v4tov6(remote4, anycast6to4);
 		anysender++;
@@ -138,9 +122,9 @@
 
 	/* remote v6 address (defaults to link-local w/ v4 as interface part) */
 	if (argc >= 1) {
-		if (parseip(remote6, *argv++) == -1)
-			sysfatal("bad remote v6 address %s", argv[-1]);
 		argc--;
+		if (parseip(remote6, *argv++) == -1 || isv4(remote6))
+			sysfatal("bad remote v6 address %s", argv[-1]);
 	} else {
 		remote6[0] = 0xFE;		/* link local */
 		remote6[1] = 0x80;
@@ -328,7 +312,7 @@
 				ip->src, ip->dst);
 			continue;
 		}
-		if ((!equivip6(ip->dst, remote6) && badipv6(ip->dst))) {
+		if ((ipcmp(ip->dst, remote6) != 0 && badipv6(ip->dst))) {
 			syslog(0, "6in4", "egress filtered %I -> %I; "
 				"bad dst not remote", ip->src, ip->dst);
 			continue;