]> jfr.im git - solanum.git/blobdiff - ircd/hostmask.c
reject: Remember and send reasons for rejections
[solanum.git] / ircd / hostmask.c
index c342f2c203e85b5090a5051921ce6ac3c3b6ba8a..a5ca670ad462ca8bcd001356b41543596d2d8a12 100644 (file)
@@ -31,9 +31,7 @@
 #include "send.h"
 #include "match.h"
 
-#ifdef RB_IPV6
 static unsigned long hash_ipv6(struct sockaddr *, int);
-#endif
 static unsigned long hash_ipv4(struct sockaddr *, int);
 
 
@@ -65,7 +63,6 @@ parse_netmask(const char *text, struct rb_sockaddr_storage *naddr, int *nb)
        {
                return HM_HOST;
        }
-#ifdef RB_IPV6
        if(strchr(ip, ':'))
        {
                if((ptr = strchr(ip, '/')))
@@ -79,12 +76,11 @@ parse_netmask(const char *text, struct rb_sockaddr_storage *naddr, int *nb)
                                return HM_HOST;
                } else
                        *b = 128;
-               if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
+               if(rb_inet_pton_sock(ip, addr) > 0)
                        return HM_IPV6;
                else
                        return HM_HOST;
        } else
-#endif
        if(strchr(text, '.'))
        {
                if((ptr = strchr(ip, '/')))
@@ -98,7 +94,7 @@ parse_netmask(const char *text, struct rb_sockaddr_storage *naddr, int *nb)
                                return HM_HOST;
                } else
                        *b = 32;
-               if(rb_inet_pton_sock(ip, (struct sockaddr *)addr) > 0)
+               if(rb_inet_pton_sock(ip, addr) > 0)
                        return HM_IPV4;
                else
                        return HM_HOST;
@@ -139,7 +135,6 @@ hash_ipv4(struct sockaddr *saddr, int bits)
  * Output: A hash value of the IP address.
  * Side effects: None
  */
-#ifdef RB_IPV6
 static unsigned long
 hash_ipv6(struct sockaddr *saddr, int bits)
 {
@@ -162,7 +157,6 @@ hash_ipv6(struct sockaddr *saddr, int bits)
        }
        return v & (ATABLE_SIZE - 1);
 }
-#endif
 
 /* int hash_text(const char *start)
  * Input: The start of the text to hash.
@@ -204,6 +198,9 @@ get_mask_hash(const char *text)
 
 /* struct ConfItem* find_conf_by_address(const char*, struct rb_sockaddr_storage*,
  *         int type, int fam, const char *username)
+ *
+ * This process needs to be kept in sync with check_one_kline().
+ *
  * Input: The hostname, the address, the type of mask to find, the address
  *        family, the username.
  * Output: The matching value with the highest precedence.
@@ -227,7 +224,6 @@ find_conf_by_address(const char *name, const char *sockhost,
        if(addr)
        {
                /* Check for IPV6 matches... */
-#ifdef RB_IPV6
                if(fam == AF_INET6)
                {
 
@@ -249,7 +245,6 @@ find_conf_by_address(const char *name, const char *sockhost,
                        }
                }
                else
-#endif
                if(fam == AF_INET)
                {
                        for (b = 32; b >= 0; b -= 8)
@@ -369,9 +364,7 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
 {
        struct ConfItem *iconf, *kconf;
        const char *vuser;
-#ifdef RB_IPV6
        struct sockaddr_in ip4;
-#endif
 
        /* Find the best I-line... If none, return NULL -A1kmm */
        if(!(iconf = find_conf_by_address(host, sockhost, NULL, ip, CONF_CLIENT, aftype, user, auth_user)))
@@ -422,7 +415,6 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
                        return kconf;
        }
 
-#ifdef RB_IPV6
        if(ip != NULL && ip->sa_family == AF_INET6 &&
                        rb_ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)ip, &ip4))
        {
@@ -430,7 +422,6 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
                if(kconf)
                        return kconf;
        }
-#endif /* RB_IPV6 */
 
        return iconf;
 }
@@ -444,9 +435,7 @@ struct ConfItem *
 find_dline(struct sockaddr *addr, int aftype)
 {
        struct ConfItem *aconf;
-#ifdef RB_IPV6
        struct sockaddr_in addr2;
-#endif
 
        aconf = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL, NULL);
        if(aconf)
@@ -454,7 +443,6 @@ find_dline(struct sockaddr *addr, int aftype)
        aconf = find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL, NULL);
        if(aconf)
                return aconf;
-#ifdef RB_IPV6
        if(addr->sa_family == AF_INET6 &&
                        rb_ipv4_from_ipv6((const struct sockaddr_in6 *)(const void *)addr, &addr2))
        {
@@ -462,7 +450,6 @@ find_dline(struct sockaddr *addr, int aftype)
                if(aconf)
                        return aconf;
        }
-#endif
        return NULL;
 }
 
@@ -482,15 +469,12 @@ find_exact_conf_by_address(const char *address, int type, const char *username)
        if(address == NULL)
                address = "/NOMATCH!/";
        masktype = parse_netmask(address, &addr, &bits);
-#ifdef RB_IPV6
        if(masktype == HM_IPV6)
        {
                /* We have to do this, since we do not re-hash for every bit -A1kmm. */
                hv = hash_ipv6((struct sockaddr *)&addr, bits - bits % 16);
        }
-       else
-#endif
-       if(masktype == HM_IPV4)
+       else if(masktype == HM_IPV4)
        {
                /* We have to do this, since we do not re-hash for every bit -A1kmm. */
                hv = hash_ipv4((struct sockaddr *)&addr, bits - bits % 8);
@@ -539,7 +523,6 @@ add_conf_by_address(const char *address, int type, const char *username, const c
                address = "/NOMATCH!/";
        arec = rb_malloc(sizeof(struct AddressRec));
        arec->masktype = parse_netmask(address, &arec->Mask.ipa.addr, &bits);
-#ifdef RB_IPV6
        if(arec->masktype == HM_IPV6)
        {
                arec->Mask.ipa.bits = bits;
@@ -548,9 +531,7 @@ add_conf_by_address(const char *address, int type, const char *username, const c
                arec->next = atable[(hv = hash_ipv6((struct sockaddr *)&arec->Mask.ipa.addr, bits))];
                atable[hv] = arec;
        }
-       else
-#endif
-       if(arec->masktype == HM_IPV4)
+       else if(arec->masktype == HM_IPV4)
        {
                arec->Mask.ipa.bits = bits;
                /* We have to do this, since we do not re-hash for every bit -A1kmm. */
@@ -585,16 +566,13 @@ delete_one_address_conf(const char *address, struct ConfItem *aconf)
        struct AddressRec *arec, *arecl = NULL;
        struct rb_sockaddr_storage addr;
        masktype = parse_netmask(address, &addr, &bits);
-#ifdef RB_IPV6
        if(masktype == HM_IPV6)
        {
                /* We have to do this, since we do not re-hash for every bit -A1kmm. */
                bits -= bits % 16;
                hv = hash_ipv6((struct sockaddr *)&addr, bits);
        }
-       else
-#endif
-       if(masktype == HM_IPV4)
+       else if(masktype == HM_IPV4)
        {
                /* We have to do this, since we do not re-hash for every bit -A1kmm. */
                bits -= bits % 8;