summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ratfs/ctlfiles.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-02-11 23:38:58 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2019-02-11 23:38:58 +0100
commit50e617f8b60b61e98538cb8ccb09958740defb9a (patch)
tree4b7c197d3a998a02fbf62370d5ce6e5ab1ccd5b1 /sys/src/cmd/ratfs/ctlfiles.c
parent168dabc142d40a1cdce87e836806a9913bb6534e (diff)
ratfs: implement ipv6 support, replace v4parsecidr() with parseipandmask()
Diffstat (limited to 'sys/src/cmd/ratfs/ctlfiles.c')
-rw-r--r--sys/src/cmd/ratfs/ctlfiles.c62
1 files changed, 20 insertions, 42 deletions
diff --git a/sys/src/cmd/ratfs/ctlfiles.c b/sys/src/cmd/ratfs/ctlfiles.c
index a9f863029..f5e1a1965 100644
--- a/sys/src/cmd/ratfs/ctlfiles.c
+++ b/sys/src/cmd/ratfs/ctlfiles.c
@@ -1,5 +1,4 @@
#include "ratfs.h"
-#include <ip.h>
enum {
ACCEPT = 0, /* verbs in control file */
@@ -40,6 +39,7 @@ getconf(void)
Biobuf *bp;
char *cp;
Node *np, *dir, **l;
+ Cidraddr ip;
if(debugfd >= 0)
fprint(debugfd, "loading %s\n", conffile);
@@ -76,8 +76,10 @@ getconf(void)
break;
if (strcmp(cp, "ournets") == 0){
for(cp += strlen(cp)+1; cp && *cp; cp += strlen(cp)+1){
+ if(cidrparse(&ip, cp) == -1)
+ continue;
np = newnode(dir, cp, Trustedperm, 0111, trustedqid++);
- cidrparse(&np->ip, cp);
+ np->ip = ip;
subslash(cp);
np->d.name = atom(cp);
}
@@ -218,16 +220,12 @@ findkey(char *val, Keyword *p)
/*
* parse a cidr specification in either IP/mask or IP#mask format
*/
-void
+int
cidrparse(Cidraddr *cidr, char *cp)
{
-
- char *p, *slash;
+ uchar ip[IPaddrlen];
+ char buf[64], *p, *slash;
int c;
- ulong a, m;
- uchar addr[IPv4addrlen];
- uchar mask[IPv4addrlen];
- char buf[64];
/*
* find '/' or '#' character in the cidr specification
@@ -250,25 +248,11 @@ cidrparse(Cidraddr *cidr, char *cp)
}
*p = 0;
- v4parsecidr(addr, mask, buf);
- a = nhgetl(addr);
- m = nhgetl(mask);
- /*
- * if a mask isn't specified, we build a minimal mask
- * instead of using the default mask for that net. in this
- * case we never allow a class A mask (0xff000000).
- */
- if(slash == 0){
- m = 0xff000000;
- p = buf;
- for(p = strchr(p, '.'); p && p[1]; p = strchr(p+1, '.'))
- m = (m>>8)|0xff000000;
-
- /* force at least a class B */
- m |= 0xffff0000;
- }
- cidr->ipaddr = a;
- cidr->mask = m;
+ if(parseipandmask(ip, cidr->mask, buf, slash) == -1)
+ return -1;
+ maskip(ip, cidr->mask, cidr->ipaddr);
+
+ return 0;
}
/*
@@ -335,7 +319,9 @@ ipinsert(Node *np, char *cp)
char *tmp;
int i;
Address *ap;
- if(cp == 0 || *cp == 0)
+ Cidraddr ip;
+
+ if(cp == 0 || *cp == 0 || cidrparse(&ip, cp) == -1)
return;
np = dirwalk("ip", np);
@@ -351,27 +337,19 @@ ipinsert(Node *np, char *cp)
}
ap = &np->addrs[i]; /* new entry on end */
+ ap->ip = ip;
tmp = strdup(cp);
if(tmp == nil)
fatal("out of memory");
subslash(tmp);
ap->name = atom(tmp);
free(tmp);
- cidrparse(&ap->ip, cp);
}
-int
-ipcomp(void *a, void *b)
+static int
+ipaddrcomp(void *a, void *b)
{
- ulong aip, bip;
-
- aip = ((Address*)a)->ip.ipaddr;
- bip = ((Address*)b)->ip.ipaddr;
- if(aip > bip)
- return 1;
- if(aip < bip)
- return -1;
- return 0;
+ return ipcmp(((Address*)a)->ip.ipaddr, ((Address*)b)->ip.ipaddr);
}
/*
@@ -389,7 +367,7 @@ ipsort(void)
continue;
for(np = dir->children; np; np = np->sibs){
if(np->d.type == IPaddr && np->count && np->addrs)
- qsort(np->addrs, np->count, sizeof(Address), ipcomp);
+ qsort(np->addrs, np->count, sizeof(Address), ipaddrcomp);
np->baseqid = base;
base += np->count;
}