* <peer-addr> is the address of the point-to-point peer.
* <prefix>/<mask>,<prefix>/<mask>,...
* List of additional routes to add for this interface.
- * May be the empty argument.
+ * May be the empty argument, or `-' if this is problematic.
*
* <config> is either
* <gid>,<prefix>/<len>[,<junk>]
*
* Should be run from userv with no-disconnect-hup.
*/
+/*
+ * Copyright (C) 1999 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv-utils; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
#include <stdio.h>
#include <string.h>
#define NARGS 4
#define MAXEXROUTES 5
-#define ATXTLEN 12
+#define ATXTLEN 16
static const unsigned long gidmaxval= (unsigned long)((gid_t)-2);
static const char *const protos_ok[]= { "slip", "cslip", "adaptive", 0 };
char *ep;
int endchar;
- if (!*argp) { badusage("missing number %s\n",what); }
+ if (!*argp) { badusage("missing number %s",what); }
rv= strtoul(*argp,&ep,0);
if ((endchar= *ep)) {
- if (!endchars) badusage("junk after number %s\n",what);
+ if (!endchars) badusage("junk after number %s",what);
if (!strchr(endchars,endchar))
badusage("invalid character or delimiter `%c' in or after number, %s:"
- " expected %s (or none?)\n", endchar,what,endchars);
+ " expected %s (or none?)", endchar,what,endchars);
*argp= ep+1;
} else {
*argp= 0;
len= eat_number(argp,whatbuf, 0,32, endchars,endchar_r);
mask= (~0UL << (32-len));
- if (prefix & ~mask) badusage("%s prefix %08lx not fully contained in mask %08lx\n",
+ if (prefix & ~mask) badusage("%s prefix %08lx not fully contained in mask %08lx",
what,prefix,mask);
*prefix_r= prefix;
if (mask_r) *mask_r= mask;
int i, any;
assert(!(pprefix & ~pmask));
+ any= 0;
if (!proto) fputs("permits",stdout);
if (addrnet_isin(localaddr,~0UL, pprefix,pmask)) {
}
}
if (!proto) {
- if (!any) fputs(" nothing!",stderr);
+ if (!any) fputs(" nothing",stdout);
putchar('\n');
}
}
addrnet_mustdiffer("local-addr",localaddr,~0UL, "peer-addr",peeraddr,~0UL);
carg= *++argv;
- for (nexroutes=0;
- carg;
- nexroutes++) {
- if (nexroutes == MAXEXROUTES)
- fatal("too many extra routes (only %d allowed)",MAXEXROUTES);
- sprintf(erwhatbuf,"route#%d",nexroutes);
+ if (strcmp(carg,"-")) {
+ for (nexroutes=0;
+ carg && *carg;
+ nexroutes++) {
+ if (nexroutes == MAXEXROUTES)
+ fatal("too many extra routes (only %d allowed)",MAXEXROUTES);
+ sprintf(erwhatbuf,"route#%d",nexroutes);
- eat_prefixmask(&carg,erwhatbuf, ",",0, &routeaddr,&routemask,0);
- if (routemask == ~0UL) {
- addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "local-addr",localaddr,~0UL);
- addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "peer-addr",peeraddr,~0UL);
- }
- for (i=0; i<nexroutes; i++) {
- sprintf(erwhatbuf2,"route#%d",i);
- addrnet_mustdiffer(erwhatbuf,routeaddr,routemask,
- erwhatbuf2,exroutes[i].prefix,exroutes[i].mask);
+ eat_prefixmask(&carg,erwhatbuf, ",",0, &routeaddr,&routemask,0);
+ if (routemask == ~0UL) {
+ addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "local-addr",localaddr,~0UL);
+ addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "peer-addr",peeraddr,~0UL);
+ }
+ for (i=0; i<nexroutes; i++) {
+ sprintf(erwhatbuf2,"route#%d",i);
+ addrnet_mustdiffer(erwhatbuf,routeaddr,routemask,
+ erwhatbuf2,exroutes[i].prefix,exroutes[i].mask);
+ }
+ exroutes[nexroutes].prefix= routeaddr;
+ exroutes[nexroutes].mask= routemask;
+ exroutes[nexroutes].allow= 0;
+ ip2txt(routeaddr,exroutes[nexroutes].prefixtxt);
+ ip2txt(routemask,exroutes[nexroutes].masktxt);
}
- exroutes[nexroutes].prefix= routeaddr;
- exroutes[nexroutes].mask= routemask;
- exroutes[nexroutes].allow= 0;
- ip2txt(routeaddr,exroutes[nexroutes].prefixtxt);
- ip2txt(routemask,exroutes[nexroutes].masktxt);
}
+
ip2txt(localaddr,localtxt);
ip2txt(peeraddr,peertxt);
}
}
setsigmask(&fullset);
l= strlen(ifnbuf);
- if (l<0 || ifnbuf[l-1] != '\n') fatal("slattach gave strange output `%s'",ifnbuf);
+ if (l<=0 || ifnbuf[l-1] != '\n') fatal("slattach gave strange output `%s'",ifnbuf);
ifnbuf[l-1]= 0;
for (k=l; k>0 && ifnbuf[k-1]!=' '; k--);
ifname= ifnbuf+k;