(I'm assuming all interested developers are _also_ on the -users list...) I've just hit the problem others have hit before about the ippool shrinking for no apparent reason. I'm not sure what does it exactly, as I'm more interested in the rewrite of rlm_ippool I proposed earlier and someone else actually _did_, which I'm now more motivated to test, and write transition code for. (I was earlier waiting for the 0.9.0 release, which is now done. :-)
Anyway, in order to get my services back up and running, I modified ippooltool 1.0 to also be able to _add_ entries, as well as remove them. I deleted the pool dbs, restarted radius to recreate the DBs, stopped radius, and then used this plus the info from radwho to rebuild the ippool DBs. The code currents assumes that you've -r'd the IP address already, if neccessary. (If not, it does nothing, happily) It also assumes you're wanting the 'num' set to 1. (That's the number of ports that IP's assigned to. It's for the (broken, AFAIK) multilink allocation) I realise this code could be neater, but I was in a hurry. :-) Tested fine here, and deals with ports > 0x7fffffff. -n then -r produces expected results, and people are once again dialling in here... I know that's good 'cause if I send the NAS an IP address it already thinks I've allocated, then it will reject me. So I'm happy this works. Oh, all the debugging output says 'iptool2' since that's what I was calling the file. :-) Here's my patch to ippooltool... There was some discussion of ippooltool being added to the FreeRADIUS CVS earlier. Was that ever decided for or against? --- iptool.c 2003-05-23 23:09:21.000000000 +1000 +++ iptool2.c 2003-07-26 15:10:07.000000000 +1000 @@ -41,6 +41,7 @@ int cflag=0; int rflag=0; int vflag=0; +int nflag=0; typedef struct ippool_info { uint32_t ipaddr; @@ -58,6 +59,150 @@ #define MATCH_IP(ip1,ip2) ((ip1)==NULL || strcmp((ip1),(ip2))==0) #define MATCH_ACTIVE(info) ((info).active==1 || !aflag) +void addip(char *sessiondbname,char *indexdbname,char *ipaddress, char* NASname, char*NASport) { + GDBM_FILE sessiondb; + GDBM_FILE indexdb; + datum key_datum,keynext_datum,data_datum; + datum nextkey; + ippool_key key; + ippool_info entry; + struct in_addr ipaddr; + int num; + int mode=GDBM_WRITER; + int rcode; + char *cli = NULL; + int delete = 0; + + sessiondb=gdbm_open(sessiondbname,512,mode,0,NULL); + indexdb=gdbm_open(indexdbname,512,mode,0,NULL); + + if (inet_aton(ipaddress, &ipaddr) == 0) + { + printf("iptool2: Unable to convert IP address '%s'\n", ipaddress); + return; + } + + if (sessiondb==NULL) + { + printf("iptools: Unable to open DB '%s'\n", sessiondbname); + return; + } + + if (indexdb==NULL) + { + printf("iptools: Unable to open DB '%s'\n", indexdbname); + return; + } + + /* Basically from rlm_ippool.c */ + + memset(key.nas,0,MAX_NAS_NAME_SIZE); + strncpy(key.nas,NASname,MAX_NAS_NAME_SIZE -1 ); + key.port = strtoul(NASport,NULL,0); + key_datum.dptr = (char *) &key; + key_datum.dsize = sizeof(ippool_key); + + key_datum = gdbm_firstkey(sessiondb); + while(key_datum.dptr){ + data_datum = gdbm_fetch(sessiondb, key_datum); + if (data_datum.dptr){ + memcpy(&entry,data_datum.dptr, sizeof(ippool_info)); + free(data_datum.dptr); + /* Found our entry? */ + if (entry.ipaddr == ipaddr.s_addr){ + datum tmp; + + tmp.dptr = (char *) &entry.ipaddr; + tmp.dsize = sizeof(uint32_t); + data_datum = gdbm_fetch(indexdb, tmp); + + /* + * If we find an entry in the ip index and the number is zero (meaning + * that we haven't allocated the same ip address to another nas/port pair) + * or if we don't find an entry then delete the session entry so + * that we can change the key (nas/port) + * Else we don't delete the session entry since we haven't yet deallocated the + * corresponding ip address and we continue our search. + */ + + if (data_datum.dptr){ + memcpy(&num,data_datum.dptr, sizeof(int)); + free(data_datum.dptr); + if (num == 0){ + delete = 1; + break; + } + } + else{ + delete = 1; + break; + } + } + } + nextkey = gdbm_nextkey(sessiondb, key_datum); + free(key_datum.dptr); + key_datum = nextkey; + } + /* + * If we have found our entry set active to 1 + */ + if (key_datum.dptr){ + entry.active = 1; + data_datum.dptr = (char *) &entry; + data_datum.dsize = sizeof(ippool_info); + + if (delete){ + /* + * Delete the entry so that we can change the key + */ + gdbm_delete(sessiondb, key_datum); + } + free(key_datum.dptr); + memset(key.nas,0,MAX_NAS_NAME_SIZE); + strncpy(key.nas,NASname,MAX_NAS_NAME_SIZE -1 ); + key.port = strtoul(NASport,NULL,0); + key_datum.dptr = (char *) &key; + key_datum.dsize = sizeof(ippool_key); + + printf("iptool2: Allocating ip to nas/port: %s/%u\n",key.nas,key.port); + rcode = gdbm_store(sessiondb, key_datum, data_datum, GDBM_REPLACE); + if (rcode < 0) { + printf("iptool2: Failed storing data to %s: %s\n", + sessiondbname, gdbm_strerror(gdbm_errno)); + gdbm_close(indexdb); + gdbm_close(sessiondb); + return; + } + + /* Increase the ip index count */ + key_datum.dptr = (char *) &entry.ipaddr; + key_datum.dsize = sizeof(uint32_t); + data_datum = gdbm_fetch(indexdb, key_datum); + if (data_datum.dptr){ + memcpy(&num,data_datum.dptr,sizeof(int)); + free(data_datum.dptr); + } + num=1; + printf("iptool2: num: %d\n",num); + data_datum.dptr = (char *) # + data_datum.dsize = sizeof(int); + rcode = gdbm_store(indexdb, key_datum, data_datum, GDBM_REPLACE); + if (rcode < 0) { + printf("iptool2: Failed storing data to %s: %s\n", + indexdbname, gdbm_strerror(gdbm_errno)); + gdbm_close(indexdb); + gdbm_close(sessiondb); + return; + } + + + printf("iptool2: Allocated ip %s to client on nas %s,port %u\n",ipaddress, + key.nas,strtoul(NASport,NULL,0)); + } + gdbm_close(indexdb); + gdbm_close(sessiondb); +} + void viewdb(char *sessiondbname,char *indexdbname,char *ipaddress) { GDBM_FILE sessiondb; GDBM_FILE indexdb; @@ -147,13 +292,16 @@ } void usage(char *argv0) { - printf("Usage: %s [-a] [-c] [-v] <session-db> <index-db> [ipaddress]\n",argv0); + printf("Usage: %s [-a] [-c] [-v] <session-db> <index-db> [ipaddress] [nasIP] [nasPort]\n",argv0); + printf("\t2 or 3 parameters:\n"); printf("-a: print all active entries\n"); printf("-c: report number of active entries\n"); printf("-r: remove active entries\n"); printf("-v: verbose report of all entries\n"); printf("If an ipaddress is specified then only that address is used to\n"); printf("limit the actions or output to that address only.\n"); + printf("\t5 parameters:\n"); + printf("-n: Mark the entry nasIP/nasPort as having ipaddress\n"); exit(0); } @@ -161,21 +309,29 @@ int ch; char *argv0=argv[0]; - while ((ch=getopt(argc,argv,"acrv"))!=-1) + while ((ch=getopt(argc,argv,"acrvn"))!=-1) switch (ch) { case 'a': aflag++;break; case 'c': cflag++;break; case 'r': rflag++;break; case 'v': vflag=1;break; + case 'n': nflag=1;break; default: usage(argv0); } argc -= optind; argv += optind; - if (argc!=2 && argc!=3) - usage(argv0); - else - viewdb(argv[0],argv[1],argv[2]); + if ((argc==2 || argc==3) && !nflag) + { + printf("ViewDB\n"); + viewdb(argv[0],argv[1],argv[2]); + } else + if (argc==5 && nflag) + { + printf("AddIP\n"); + addip(argv[0],argv[1],argv[2],argv[3],argv[4]); + } else + usage(argv0); if (cflag) printf("%d\n",active); return 0; } -- ========================================================= Paul "TBBle" Hampson Bubblesworth Pty Ltd (ABN: 51 095 284 361) [EMAIL PROTECTED] This is a one line proof...if we start sufficiently far to the left. -- Cambridge University Math Department --------------------------------------------------------- Random signature generator 3.0 by Paul "TBBle" Hampson ========================================================= - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html