]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Treat 6to4 clients as if they're connecting via IPv4.
authorGunnar Beutner <redacted>
Mon, 17 Jun 2013 07:47:42 +0000 (09:47 +0200)
committerGunnar Beutner <redacted>
Mon, 17 Jun 2013 07:47:42 +0000 (09:47 +0200)
--HG--
branch : shroudtrusts

lib/irc_ipv6.c
lib/irc_ipv6.h
nick/nick.h
nick/nickhandlers.c
trusts/events.c

index 82d567264bc98e46efb8470e0bc40d38c6dd1e8c..d9052d3ea0b46d1870bea6340846fd1ff786c7f0 100644 (file)
@@ -485,3 +485,21 @@ int ipmask_check(const struct irc_in_addr *addr, const struct irc_in_addr *mask,
   }
   return -1;
 }
+
+/** Convert IP addresses to canonical form for comparison.  6to4 addresses
+ * are converted to IPv4 addresses. All other addresses are left alone.
+ * @param[out] out Receives canonical format for address.
+ * @param[in] in IP address to canonicalize.
+ */
+void ip_canonicalize_6to4(struct irc_in_addr *out, const struct irc_in_addr *in)
+{
+    if (in->in6_16[0] == htons(0x2002)) {
+        out->in6_16[0] = out->in6_16[1] = out->in6_16[2] = 0;
+        out->in6_16[3] = out->in6_16[4] = 0;
+        out->in6_16[5] = 0xffff;
+        out->in6_16[6] = in->in6_16[1];
+        out->in6_16[7] = in->in6_16[2];
+    } else
+        memcpy(out, in, sizeof(*out));
+}
+
index 4c51f86ff35569623c7cc6abf315defc182bc9f7..4bec9085494d8d28417c57c4fc569dac7ceb4e9b 100644 (file)
@@ -63,6 +63,7 @@ extern const char* ircd_ntoa_r(char* buf, const struct irc_in_addr* addr);
 #define ircd_aton(ADDR, STR) ipmask_parse((STR), (ADDR), NULL)
 extern int ipmask_parse(const char *in, struct irc_in_addr *mask, unsigned char *bits_ptr);
 extern int ipmask_check(const struct irc_in_addr *, const struct irc_in_addr *, unsigned char);
+void ip_canonicalize_6to4(struct irc_in_addr *out, const struct irc_in_addr *in);
 
 #define IPtostr(ipaddr) ircd_ntoa(&(ipaddr))
 #define irc_in_addr_v4_to_int(ADDR) ((ntohs((ADDR)->in6_16[6]) << 16) | ntohs((ADDR)->in6_16[7]))
index 4c9acaa4d3a89b767f8950ab41df383abf09a2fa..984d1407b0137fa352cc06e79998608d5b11417c 100644 (file)
@@ -141,6 +141,7 @@ typedef struct nick {
   time_t timestamp;
   time_t accountts;
   sstring *away;
+  struct irc_in_addr ipaddress;
   patricia_node_t *ipnode;
   unsigned int marker;
   struct nick *next;
@@ -152,7 +153,7 @@ typedef struct nick {
   void *exts[MAXNICKEXTS];
 } nick;
 
-#define p_ipaddr ipnode->prefix->sin
+#define p_ipaddr ipaddress
 
 #define NICKHASHSIZE      60000
 #define HOSTHASHSIZE      40000
index 8426bb7c4eec431bbc122dcc9431a9fb554d5507..7965680411a3d771c123ea0bfd0f029e95148d19 100644 (file)
@@ -29,7 +29,7 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
   char *fakehost;
   char *accountts;
   char *accountflags;
-  struct irc_in_addr ipaddress;
+  struct irc_in_addr ipaddress, ipaddress_canonical;
   char *accountid;
   unsigned long userid;
   
@@ -148,8 +148,10 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
     np->realname->nicks=np;
     np->timestamp=timestamp;
 
-    base64toip(cargv[cargc-3], &ipaddress);
-    np->ipnode = refnode(iptree, &ipaddress, PATRICIA_MAXBITS);
+    memcpy(&(np->ipaddress), &ipaddress, sizeof(ipaddress));
+
+    ip_canonicalize_6to4(&ipaddress_canonical, &ipaddress);
+    np->ipnode = refnode(iptree, &ipaddress_canonical, irc_in_addr_is_ipv4(&ipaddress) ? 128 : 64);
     node_increment_usercount(np->ipnode);
 
     np->away=NULL;
index b28c33e826813473d59607ba5cd7e025feb0aa9c..797fc4ba6782cfd39cb9d5b6099e3c0977899548 100644 (file)
@@ -7,9 +7,15 @@ void trusts_newnick(nick *sender, int moving) {
   uint32_t host;
   trusthost *th;
   void *arg[2];
+  struct irc_in_addr ipaddress;
 
-  host = irc_in_addr_v4_to_int(&sender->p_ipaddr);
-  th = th_getbyhost(host);
+  ip_canonicalize_6to4(&ipaddress, &sender->p_ipaddr);
+
+  if (irc_in_addr_is_ipv4(&ipaddress)) {
+    host = irc_in_addr_v4_to_int(&ipaddress);
+    th = th_getbyhost(host);
+  } else
+    th = NULL;
 
   settrusthost(sender, th);
   if(!th) {