ref: 7102a23245a07bf0a9517b3731f70e0475daf39b
parent: b1c9ddb3f0757d900e3d51c82f73b196d5631ef7
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Feb 11 18:43:14 EST 2019
devip: use parseipandmask() for ipifc and route control message parsing
--- a/sys/src/9/ip/ip.h
+++ b/sys/src/9/ip/ip.h
@@ -623,6 +623,7 @@
extern int parseether(uchar*, char*);
extern vlong parseip(uchar*, char*);
extern vlong parseipmask(uchar*, char*);
+extern vlong parseipandmask(uchar*, uchar*, char*, char*);
extern char* v4parseip(uchar*, char*);
extern void maskip(uchar *from, uchar *mask, uchar *to);
extern int parsemac(uchar *to, char *from, int len);
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -455,15 +455,13 @@
mtu = strtoul(argv[4], 0, 0);
/* fall through */
case 4:
- if (parseip(ip, argv[1]) == -1 || parseip(rem, argv[3]) == -1)
+ if (parseipandmask(ip, mask, argv[1], argv[2]) == -1 || parseip(rem, argv[3]) == -1)
return Ebadip;
- parseipmask(mask, argv[2]);
maskip(rem, mask, net);
break;
case 3:
- if (parseip(ip, argv[1]) == -1)
+ if (parseipandmask(ip, mask, argv[1], argv[2]) == -1)
return Ebadip;
- parseipmask(mask, argv[2]);
maskip(ip, mask, rem);
maskip(rem, mask, net);
break;
@@ -691,9 +689,8 @@
if(argc < 3)
return Ebadarg;
- if(parseip(ip, argv[1]) == -1)
+ if(parseipandmask(ip, mask, argv[1], argv[2]) == -1)
return Ebadip;
- parseipmask(mask, argv[2]);
if(argc < 4)
maskip(ip, mask, rem);
else if(parseip(rem, argv[3]) == -1)
--- a/sys/src/9/ip/iproute.c
+++ b/sys/src/9/ip/iproute.c
@@ -917,9 +917,8 @@
if(argc < 3)
error(Ebadctl);
- if(parseip(addr, argv[1]) == -1)
+ if(parseipandmask(addr, mask, argv[1], argv[2]) == -1)
error(Ebadip);
- parseipmask(mask, argv[2]);
if(strcmp(argv[0], "add") == 0 || (argc > 3 && argc != 5)){
if(argc < 4)
@@ -928,9 +927,8 @@
error(Ebadip);
}
if(argc > 4 && (strcmp(argv[0], "add") != 0 || argc != 5)){
- if(parseip(src, argv[argc-2]) == -1)
+ if(parseipandmask(src, smask, argv[argc-2], argv[argc-1]) == -1)
error(Ebadip);
- parseipmask(smask, argv[argc-1]);
}
if(argc == 5 && strcmp(argv[0], "add") == 0)
ifc = findipifcstr(f, argv[4]);