Added an option to manually specify which address to bind to.
authorKevin Webb <kcwebb@ucsd.edu>
Thu, 28 Jan 2010 19:34:31 +0000 (19:34 +0000)
committerKevin Webb <kcwebb@ucsd.edu>
Thu, 28 Jan 2010 19:34:31 +0000 (19:34 +0000)
drl/Manual.txt
drl/ulogd_DRL.c
drl/util.c
ulogd.conf.in

index bf5fed8..0835a56 100644 (file)
@@ -83,6 +83,10 @@ Whether or not to turn enforcement on by default at startup.  0 for off,
 anything else for on.  If unspecified, it defaults to 1.  Enforcement can be
 turned on/off at runtime with SIGUSR1.
 
 anything else for on.  If unspecified, it defaults to 1.  Enforcement can be
 turned on/off at runtime with SIGUSR1.
 
+bind_addr <IP address string>
+Can be used to optionally specify which address DRL should use when binding
+its inter-limiter communication socket.
+
 netem_loss <int>
 netem_delay <int>
 netem_slice <int|ALL>
 netem_loss <int>
 netem_delay <int>
 netem_slice <int|ALL>
index f7b0272..70f096b 100644 (file)
  * Add the config options for DRL. 
  */
 
  * Add the config options for DRL. 
  */
 
-static config_entry_t create_htb = {
+static config_entry_t bind_addr = {
     .next = NULL,
     .next = NULL,
+    .key = "bind_addr",
+    .type = CONFIG_TYPE_STRING,
+    .options = CONFIG_OPT_NONE,
+    .u = { .string = "AUTO" },
+};
+
+static config_entry_t create_htb = {
+    .next = &bind_addr,
     .key = "create_htb",
     .type = CONFIG_TYPE_INT,
     .options = CONFIG_OPT_NONE,
     .key = "create_htb",
     .type = CONFIG_TYPE_INT,
     .options = CONFIG_OPT_NONE,
@@ -1526,15 +1534,20 @@ static int init_drl(void) {
     pthread_rwlock_init(&limiter.limiter_lock,NULL);
 
     /* determine our local IP by iterating through interfaces */
     pthread_rwlock_init(&limiter.limiter_lock,NULL);
 
     /* determine our local IP by iterating through interfaces */
-    limiter.ip = get_local_ip();
-    if (limiter.ip == NULL) {
-        printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n");
-        return false;
+    if (strncmp(bind_addr.u.string, "AUTO", 4)) {
+        limiter.ip = bind_addr.u.string;
+    } else {
+        limiter.ip = get_local_ip();
+        if (limiter.ip == NULL) {
+            printlog(LOG_CRITICAL, "ulogd_DRL unable to aquire local IP address, not registering.\n");
+            return false;
+        }
     }
     limiter.localaddr = inet_addr(limiter.ip);
     limiter.port = htons(LIMITER_LISTEN_PORT);
     limiter.udp_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if (limiter.udp_socket < 0) {
     }
     limiter.localaddr = inet_addr(limiter.ip);
     limiter.port = htons(LIMITER_LISTEN_PORT);
     limiter.udp_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if (limiter.udp_socket < 0) {
+        perror("socket()");
         printlog(LOG_CRITICAL, "Failed to create UDP socket().\n");
         return false;
     }
         printlog(LOG_CRITICAL, "Failed to create UDP socket().\n");
         return false;
     }
@@ -1545,6 +1558,7 @@ static int init_drl(void) {
     server_address.sin_port = limiter.port;
 
     if (bind(limiter.udp_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0) {
     server_address.sin_port = limiter.port;
 
     if (bind(limiter.udp_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0) {
+        perror("bind()");
         printlog(LOG_CRITICAL, "Failed to bind UDP socket.\n");
         return false;
     }
         printlog(LOG_CRITICAL, "Failed to bind UDP socket.\n");
         return false;
     }
index c03eced..bf4862a 100644 (file)
@@ -301,8 +301,8 @@ char* get_local_ip(){
         } else {
             if (localip == NULL) {
                 localip = malloc(STRINGSIZE);
         } else {
             if (localip == NULL) {
                 localip = malloc(STRINGSIZE);
+                strncpy(localip, ip, STRINGSIZE);
             }
             }
-            strncpy(localip, ip, STRINGSIZE);
         }
     }
     freeifaddrs(ifp);
         }
     }
     freeifaddrs(ifp);
index 05400e8..793663a 100644 (file)
@@ -78,6 +78,9 @@ drl_configfile="@etcdir@/drl.xml"
 # When this is set to 0, identities must specify an htb_node and 
 # htb_parent property in the drl xml file.
 create_htb=0
 # When this is set to 0, identities must specify an htb_node and 
 # htb_parent property in the drl xml file.
 create_htb=0
+# Used to optionally specify which IP address DRL's communication
+# socket should attempt to bind to.
+bind_addr="AUTO"
 
 [NETFLOW]
 # PlanetLab NetFlow logging
 
 [NETFLOW]
 # PlanetLab NetFlow logging