X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv-utils.git;a=blobdiff_plain;f=ipif%2Fservice.c;h=3a59b2b24c4e29ce0bd53db4384721c2489e1944;hp=4137794797185fb69ed80b531726ebbe5466b9f6;hb=e6a01344866b5b008ba9efb7c6d446911b9e1588;hpb=f21c3bcf37d069a38980430471fa492e1147cd49 diff --git a/ipif/service.c b/ipif/service.c index 4137794..3a59b2b 100644 --- a/ipif/service.c +++ b/ipif/service.c @@ -59,7 +59,7 @@ * Reads a file which contains lines which are each * items. * - * ,[=]/[,] + * ,[=][-|+]/(-|+/...)[,] * * Indicates that may allocate addresses in the relevant address * range ( is ignored). must be numeric. To specify a @@ -67,6 +67,13 @@ * specified then the specific subrange is only allowed for the local * endpoint address, but not for remote addresses. * + * More than one range may be given, with each range prefixed + * by + or -. In this case each address range in the rule will + * scanned in order, and the first range in the rule that matches + * any desired rule will count: if that first matching range is + * prefixed by `+' (or nothing) then the rule applies, if it + * is prefixed by `-' (or nothing matches), the rule does not. + * * * * Means that anything is to be permitted. This should not appear in * /etc/userv/ipif-networks, as that would permit any user on the @@ -128,11 +135,12 @@ static const int signals[]= { SIGHUP, SIGINT, SIGTERM, 0 }; static const char *configstr, *proto; static unsigned long localaddr, peeraddr, mtu; +static int localpming, peerpming; static int localallow, peerallow, allallow; static int nexroutes; static struct exroute { unsigned long prefix, mask; - int allow; + int allow, pming; char prefixtxt[ATXTLEN], masktxt[ATXTLEN]; } exroutes[MAXEXROUTES]; @@ -290,12 +298,17 @@ static unsigned long eat_number(const char **argp, const char *what, return rv; } -static void addrnet_mustdiffer(const char *w1, unsigned long p1, unsigned long m1, - const char *w2, unsigned long p2, unsigned long m2) { +static int addrnet_overlap(unsigned long p1, unsigned long m1, + unsigned long p2, unsigned long m2) { unsigned long mask; mask= m1&m2; - if ((p1 & mask) != (p2 & mask)) return; + return (p1 & mask) == (p2 & mask); +} + +static void addrnet_mustdiffer(const char *w1, unsigned long p1, unsigned long m1, + const char *w2, unsigned long p2, unsigned long m2) { + if (!addrnet_overlap(p1,m1,p2,m2)) return; badusage("%s %08lx/%08lx overlaps/clashes with %s %08lx/%08lx", w1,p1,m1, w2,p2,m2); } @@ -341,35 +354,66 @@ static int addrnet_isin(unsigned long prefix, unsigned long mask, unsigned long mprefix, unsigned long mmask) { return !(~mask & mmask) && (prefix & mmask) == mprefix; } + +/* Totally hideous algorithm for parsing the config file lines. + * For each config file line, we first see if its gid applies. If not + * we skip it. Otherwise, we do + * permit_begin + * which sets pming to 1 + * for each range. pming may be 0 if we've determined that + * this line does not apply to . + * permit_range + * which calls permit_range_thing for each + * which checks to see if is inside the relevant + * range (for +) or overlaps it (for -) and updates + * allow and pming. + */ + +static void permit_begin(void) { + int i; + localpming= peerpming= 1; + for (i=0; i