]> mj.ucw.cz Git - libucw.git/commitdiff
IP access lists now accept both netmasks and prefix lengths.
authorMartin Mares <mj@ucw.cz>
Fri, 23 Jan 2004 17:16:32 +0000 (17:16 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 23 Jan 2004 17:16:32 +0000 (17:16 +0000)
lib/ipaccess.c

index dec639209390a6b59cfb2b814313c970789b7ef3..d00ac54ab4501e0079f03defc3288a2f536f877c 100644 (file)
@@ -14,6 +14,7 @@
 #include "lib/ipaccess.h"
 
 #include <string.h>
+#include <stdlib.h>
 
 struct ipaccess_list {
   list l;
@@ -61,19 +62,25 @@ parse_ip(byte *x, u32 *a)
 byte *
 ipaccess_parse(struct ipaccess_list *l, byte *c, int is_allow)
 {
-  byte *p = strchr(c, '/');
-  byte *q;
+  char *p = strchr(c, '/');
+  char *q;
   struct ipaccess_entry *a = cfg_malloc(sizeof(struct ipaccess_entry));
+  unsigned long pxlen;
 
   a->allow = is_allow;
+  a->mask = ~0U;
   if (p)
     {
       *p++ = 0;
-      if (q = parse_ip(p, &a->mask))
+      pxlen = strtoul(p, &q, 10);
+      if ((!q || !*q) && pxlen <= 32)
+       {
+         if (pxlen != 32)
+           a->mask = ~(~0U >> (uns) pxlen);
+       }
+      else if (q = parse_ip(p, &a->mask))
        return q;
     }
-  else
-    a->mask = ~0;
   add_tail(&l->l, &a->n);
   return parse_ip(c, &a->addr);
 }