[mirrorbrain-commits] r8040 - /trunk/mod_mirrorbrain/mod_mirrorbrain.c

From: <poeml_at_mirrorbrain.org>
Date: Fri, 23 Apr 2010 01:53:49 -0000
Author: poeml
Date: Fri Apr 23 03:53:47 2010
New Revision: 8040

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8040&view=rev
Log:
mod_mirrorbrain:
- when a client IP's network prefix did not match a mirror's network prefix
  exactly, the assignment of the client to this mirror would fail, even though
  the client IP was (also) contained in the mirror's network prefix. This has
  been rectified by properly checking for containment of the IP, fixing issue #52.

Modified:
    trunk/mod_mirrorbrain/mod_mirrorbrain.c

Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mod_mirrorbrain/mod_mirrorbrain.c?rev=8040&r1=8039&r2=8040&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Fri Apr 23 03:53:47 2010
_at_@ -186,6 +186,7 @@
     const char *country_code; /* 2-letter-string */
     const char *as;           /* autonomous system number as string */
     const char *prefix;       /* network prefix xxx.xxx.xxx.xxx/yy */
+    apr_ipsubnet_t *ipsub;   /* ip-subnet representation of the network prefix  */
     unsigned char region_only;
     unsigned char country_only;
     unsigned char as_only;
_at_@ -483,6 +484,7 @@
     new->other_countries = NULL;
     new->as = NULL;
     new->prefix = NULL;
+    new->ipsub = NULL;
     new->region_only = 0;
     new->country_only = 0;
     new->as_only = 0;
_at_@ -1634,6 +1636,7 @@
         new->other_countries = NULL;
         new->as = NULL;
         new->prefix = NULL;
+        new->ipsub = NULL;
         new->region_only = 0;
         new->country_only = 0;
         new->as_only = 0;
_at_@ -1675,8 +1678,21 @@
         /* network prefix */
         if ((val = apr_dbd_get_entry(dbd->driver, row, col++)) == NULL)
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_mirrorbrain] apr_dbd_get_entry found NULL for network prefix");
-        else
+        else {
+            char *s;
             new->prefix = apr_pstrdup(r->pool, val);
+            if ((s = ap_strchr(val, '/'))) {
+                *s++ = '\0';
+                rv = apr_ipsubnet_create(&new->ipsub, val, s, r->pool);
+                if(APR_STATUS_IS_EINVAL(rv) || (rv != APR_SUCCESS)) {
+                    /* looked nothing like an IP address, or could not be converted */
+                    new->ipsub = NULL;
+                    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_mirrorbrain] "
+                            "Error in parsing network prefix of %s: %s/%s", 
+                            new->identifier, val, s);
+                }
+            }
+        }
 
         /* score */
         if ((val = apr_dbd_get_entry(dbd->driver, row, col++)) == NULL) {
_at_@ -1772,7 +1788,8 @@
         }
 
         /* same prefix? */
-        else if (strcmp(new->prefix, prefix) == 0) {
+        else if (new->ipsub 
+                && apr_ipsubnet_test(new->ipsub, r->connection->remote_addr)) {
             *(void **)apr_array_push(mirrors_same_prefix) = new;
         }
 
_at_@ -2490,7 +2507,7 @@
 
         /* prefix */
         if (mirrors_same_prefix->nelts) {
-            ap_rprintf(r, "\n  <h3>Found %d mirror%s within the same network prefix :-) (%s):</h3>\n", 
+            ap_rprintf(r, "\n  <h3>Found %d mirror%s directly nearby (within the same network prefix: %s :-)</h3>\n", 
                        mirrors_same_prefix->nelts, 
                        (mirrors_same_prefix->nelts == 1) ? "" : "s",
                        prefix);
_at_@ -2509,7 +2526,7 @@
 
         /* AS */
         if (mirrors_same_as->nelts) {
-            ap_rprintf(r, "\n  <h3>Found %d mirror%s within the same autonomous system :-) (AS%s):</h3>\n", 
+            ap_rprintf(r, "\n  <h3>Found %d mirror%s very close (within the same autonomous system (AS%s):</h3>\n", 
                        mirrors_same_as->nelts, 
                        (mirrors_same_as->nelts == 1) ? "" : "s",
                        as);




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Fri Apr 23 2010 - 01:53:52 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT