]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Fix IPv4 generated addresses (whilst I believe they translate to same IP (in text...
authorPaul <redacted>
Sun, 3 Jun 2007 00:12:41 +0000 (00:12 +0000)
committerPaul <redacted>
Sun, 3 Jun 2007 00:12:41 +0000 (00:12 +0000)
An IP node, now contains a int of the number of users on a host as well as the number of times the ipnode is referenced

lib/patricia.h
localuser/localuser.c
nick/nick.c
nick/nickhandlers.c
nodecount/Makefile [new file with mode: 0644]
nodecount/nodecount.c [new file with mode: 0644]
trojanscan/trojanscan.c

index ea08a3b7fa6f6178fe2d115eadf29ef88baa2899..4b3ea9f5502b34a16f55935246b59504c1fb0bb1 100644 (file)
@@ -55,6 +55,7 @@ typedef struct _prefix_t {
 
 typedef struct _patricia_node_t {
    unsigned char bit;          /* flag if this node used */
+   int usercount;               /* number of users on a given node */
    prefix_t *prefix;           /* who we are in patricia tree */
    struct _patricia_node_t *l, *r;     /* left and right children */
    struct _patricia_node_t *parent;/* may be used */
index b79250b73c8da9bb18e274695aa6ad429336e7f5..064adc866126c68264271905c7f044f4629fc611 100644 (file)
@@ -102,12 +102,14 @@ nick *registerlocaluserwithuserid(char *nickname, char *ident, char *host, char
   newuser->umodes=umodes;
   
   memset(&ipaddress, 0, sizeof(ipaddress));
-  ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+  ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
   ((unsigned short *)(ipaddress.in6_16))[6] = 127;
   ((unsigned char *)(ipaddress.in6_16))[14] = 1;
   ((unsigned char *)(ipaddress.in6_16))[15] = (currentlocalunum%253)+1;
 
   newuser->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
+  newuser->ipnode->usercount++;
+
   newuser->timestamp=getnettime();
   newuser->shident=NULL;
   newuser->sethost=NULL;
index 0e7083c3579bcc229058e0193906da0da725e81d..3106527af75cf3f2495f804d697483976166899f 100644 (file)
@@ -168,6 +168,7 @@ void deletenick(nick *np) {
   freesstring(np->shident); /* freesstring(NULL) is OK */
   freesstring(np->sethost); 
 
+  np->ipnode->usercount--;
   derefnode(iptree, np->ipnode);
   
   /* TODO: figure out how to cleanly remove nodes without affecting other modules */
index 6d5196f543ff4d280c085a659bdffccfd2aef83e..dbcaa6457da48b387b1abbdfe7b6c86812518160 100644 (file)
@@ -140,6 +140,7 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     base64toip(cargv[cargc-3], &ipaddress);
     /* todo: use a single node for /64 prefixes */
     np->ipnode = refnode(iptree, &ipaddress, irc_in_addr_is_ipv4(&ipaddress) ? PATRICIA_MAXBITS : 64);
+    np->ipnode->usercount++;
 
     np->shident=NULL;
     np->sethost=NULL;
diff --git a/nodecount/Makefile b/nodecount/Makefile
new file mode 100644 (file)
index 0000000..0591fab
--- /dev/null
@@ -0,0 +1,7 @@
+CFLAGS=-g -Wall\r
+\r
+.PHONY: all\r
+all: nodecount.so\r
+\r
+nodecount.so: nodecount.o\r
+       ld -shared -Bdynamic -o $@ $^\r
diff --git a/nodecount/nodecount.c b/nodecount/nodecount.c
new file mode 100644 (file)
index 0000000..b2ed47d
--- /dev/null
@@ -0,0 +1,48 @@
+#include "../core/schedule.h"
+#include "../lib/irc_string.h"
+#include "../localuser/localuserchannel.h"
+#include "../control/control.h"
+
+int nc_cmd_nodecount(void *source, int cargc, char **cargv);
+
+void _init(void) {
+  registercontrolcmd("nodecount", 10, 1, &nc_cmd_nodecount);
+}
+
+void _fini(void) {
+  deregistercontrolcmd("nodecount", &nc_cmd_nodecount);
+}
+
+int nc_cmd_nodecount(void *source, int cargc, char **cargv) {
+  nick *np = (nick *)source;
+  struct irc_in_addr sin;
+  unsigned char bits;
+  patricia_node_t *head, *node;
+  int count;
+
+  if (cargc < 1) {
+    controlreply(np, "Syntax: nodecount <IP>");
+    return CMD_OK;
+  }
+  
+  if (ipmask_parse(cargv[0], &sin, &bits) == 0) {
+    controlreply(np, "Invalid mask.");
+
+    return CMD_OK;
+  }
+
+  head = refnode(iptree, &sin, bits);
+
+  count = 0;
+  
+  PATRICIA_WALK(head, node) {
+    count += node->usercount;
+  } PATRICIA_WALK_END;
+
+  derefnode(iptree, head);
+  
+  controlreply(np, "%d user(s) found.", count);
+
+  return CMD_OK;
+}
+
index 318985d43a2b3426f99a66c48908c69a35ef8241..71a8579bdf3931c405c982abe616c4806ee8d201 100644 (file)
@@ -2121,7 +2121,7 @@ void trojanscan_genhost(char *ptc, char size, patricia_node_t **fakeipnode) {
   ptc[i] = '\0';
 
   memset(&ipaddress, 0, sizeof(ipaddress));
-  ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+  ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
   ((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
   ((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);
 
@@ -2252,7 +2252,7 @@ void trojanscan_generatehost(char *buf, int maxsize, patricia_node_t **fakeip) {
          patricia_ref_prefix(hp->nicks->ipnode->prefix);
         } else {
           memset(&ipaddress, 0, sizeof(ipaddress));
-         ((unsigned short *)(ipaddress.in6_16))[5] = 0
+         ((unsigned short *)(ipaddress.in6_16))[5] = 65535
           ((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
           ((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);
 
@@ -2298,7 +2298,7 @@ void trojanscan_generatehost(char *buf, int maxsize, patricia_node_t **fakeip) {
     free(lengths);
 
     memset(&ipaddress, 0, sizeof(ipaddress));
-    ((unsigned short *)(ipaddress.in6_16))[5] = 0;
+    ((unsigned short *)(ipaddress.in6_16))[5] = 65535;
     ((unsigned short *)(ipaddress.in6_16))[6] = trojanscan_minmaxrand(0, 65535);
     ((unsigned short *)(ipaddress.in6_16))[7] = trojanscan_minmaxrand(0, 65535);