summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ratfs/misc.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/misc.c
parent168dabc142d40a1cdce87e836806a9913bb6534e (diff)
ratfs: implement ipv6 support, replace v4parsecidr() with parseipandmask()
Diffstat (limited to 'sys/src/cmd/ratfs/misc.c')
-rw-r--r--sys/src/cmd/ratfs/misc.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/sys/src/cmd/ratfs/misc.c b/sys/src/cmd/ratfs/misc.c
index ae2b4bb94..cc717926b 100644
--- a/sys/src/cmd/ratfs/misc.c
+++ b/sys/src/cmd/ratfs/misc.c
@@ -1,5 +1,4 @@
#include "ratfs.h"
-#include <ip.h>
enum {
Maxdoms = 10, /* max domains in a path */
@@ -9,7 +8,7 @@ enum {
static int accountmatch(char*, char**, int, char*);
static Node* acctwalk(char*, Node*);
static int dommatch(char*, char*);
-static Address* ipsearch(ulong, Address*, int);
+static Address* ipsearch(uchar*, Address*, int);
static Node* ipwalk(char*, Node*);
static Node* trwalk(char*, Node*);
static int usermatch(char*, char*);
@@ -78,16 +77,17 @@ dirwalk(char *name, Node *np)
static Node*
trwalk(char *name, Node *np)
{
+ uchar addr[IPaddrlen], net[IPaddrlen];
Node *p;
- ulong peerip;
- uchar addr[IPv4addrlen];
- v4parseip(addr, name);
- peerip = nhgetl(addr);
+ parseip(addr, name);
- for(p = np->children; p; p = p->sibs)
- if((peerip&p->ip.mask) == p->ip.ipaddr)
+ for(p = np->children; p; p = p->sibs){
+ maskip(addr, p->ip.mask, net);
+ if(ipcmp(net, p->ip.ipaddr) == 0)
break;
+ }
+
return p;
}
@@ -97,17 +97,15 @@ trwalk(char *name, Node *np)
static Node*
ipwalk(char *name, Node *np)
{
+ uchar addr[IPaddrlen];
Address *ap;
- ulong peerip;
- uchar addr[IPv4addrlen];
- v4parseip(addr, name);
- peerip = nhgetl(addr);
+ parseip(addr, name);
if(debugfd >= 0)
- fprint(debugfd, "%d.%d.%d.%d - ", addr[0]&0xff, addr[1]&0xff,
- addr[2]&0xff, addr[3]&0xff);
- ap = ipsearch(peerip, np->addrs, np->count);
+ fprint(debugfd, "%I - ", addr);
+
+ ap = ipsearch(addr, np->addrs, np->count);
if(ap == 0)
return 0;
@@ -156,8 +154,9 @@ acctwalk(char *name, Node *np)
*/
static Address*
-ipsearch(ulong addr, Address *base, int n)
+ipsearch(uchar *addr, Address *base, int n)
{
+ uchar net[IPaddrlen];
ulong top, bot, mid;
Address *ap;
@@ -165,11 +164,12 @@ ipsearch(ulong addr, Address *base, int n)
top = n;
for (mid = (bot+top)/2; mid < top; mid = (bot+top)/2) {
ap = &base[mid];
- if((addr&ap->ip.mask) == ap->ip.ipaddr)
+ maskip(addr, ap->ip.mask, net);
+ if(ipcmp(net, ap->ip.ipaddr) == 0)
return ap;
- if(addr < ap->ip.ipaddr)
+ if(ipcmp(addr, ap->ip.ipaddr) < 0)
top = mid;
- else if(mid != n-1 && addr >= base[mid+1].ip.ipaddr)
+ else if(mid != n-1 && ipcmp(addr, base[mid+1].ip.ipaddr) >= 0)
bot = mid;
else
break;