[isf-wifidog] gateway id from mac address patch

Saul Albert saul at twenteenthcentury.com
Sam 4 Juin 01:54:19 EDT 2005


hi mina, all,

a week or so ago I posted about getting the gatewayid from the wireless
interface mac address of the box.. well we got that working, so here's
the functioning patch. Hope you're still interested in using it - as we
would love to be able to use wifidog without forking it!

Oh, there's also a patch here for the configuration file - just so you
can see what we're doing with it.

Cheers,

Saul.

-------------- next part --------------
diff -Naur wifidog/src/conf.c wifidog-mac/src/conf.c
--- wifidog/src/conf.c	2005-03-08 03:51:41.000000000 +0000
+++ wifidog-mac/src/conf.c	2005-05-30 22:46:37.603143440 +0100
@@ -707,7 +707,8 @@
 void
 config_validate(void)
 {
-	config_notnull(config.gw_id, "GatewayID");
+	// this isn't necessary if we can take the gateway ID from the internal MAC address
+	// config_notnull(config.gw_id, "GatewayID");
 	config_notnull(config.gw_interface, "GatewayInterface");
 	config_notnull(config.auth_servers, "AuthServer");
 
diff -Naur wifidog/src/conf.h wifidog-mac/src/conf.h
--- wifidog/src/conf.h	2004-11-22 21:45:57.000000000 +0000
+++ wifidog-mac/src/conf.h	2005-05-30 22:46:57.943996901 +0100
@@ -33,7 +33,7 @@
 #define DEFAULT_DAEMON 1
 #define DEFAULT_DEBUGLEVEL LOG_INFO
 #define DEFAULT_HTTPDMAXCONN 10
-#define DEFAULT_GATEWAYID "default"
+#define DEFAULT_GATEWAYID NULL
 #define DEFAULT_GATEWAYPORT 2060
 #define DEFAULT_HTTPDNAME "WiFiDog"
 #define DEFAULT_CLIENTTIMEOUT 5
diff -Naur wifidog/src/gateway.c wifidog-mac/src/gateway.c
--- wifidog/src/gateway.c	2005-03-12 22:16:38.000000000 +0000
+++ wifidog-mac/src/gateway.c	2005-05-30 22:46:37.605143032 +0100
@@ -198,6 +198,16 @@
         debug(LOG_DEBUG, "%s = %s", config->gw_interface, config->gw_address);
     }
 
+    /* If we don't have the Gateway ID, construct it from the internal MAC address. Can't fail. */
+    if (!config->gw_id) {
+        debug(LOG_DEBUG, "Finding MAC address of %s", config->gw_interface);
+        if ((config->gw_id = get_iface_mac(config->gw_interface)) == NULL) {
+	    debug(LOG_ERR, "Could not get MAC address information of %s, exiting...", config->gw_interface);
+            exit(1);
+        }
+        debug(LOG_DEBUG, "%s = %s", config->gw_interface, config->gw_id);
+    }
+
 	/* Initializes the web server */
 	debug(LOG_NOTICE, "Creating web server on %s:%d", 
 			config->gw_address, config->gw_port);
diff -Naur wifidog/src/util.c wifidog-mac/src/util.c
--- wifidog/src/util.c	2005-03-12 02:02:01.000000000 +0000
+++ wifidog-mac/src/util.c	2005-05-30 22:46:37.608142421 +0100
@@ -172,6 +172,43 @@
 #endif
 }
 
+char *get_iface_mac (char *ifname) {
+#ifdef __linux__
+    int r, s;
+    struct ifreq ifr;
+    char *hwaddr, mac[13];
+    
+    strcpy( ifr.ifr_name, ifname );
+
+    s = socket( PF_INET, SOCK_DGRAM, 0 );
+    if (s == -1) {
+	debug(LOG_ERR, "get_iface_mac socket: %s", strerror(errno));
+	return NULL;
+    }
+
+    r = ioctl( s, SIOCGIFHWADDR, &ifr );
+    if (r == -1) {
+	debug(LOG_ERR, "get_iface_mac ioctl(SIOCGIFHWADDR): %s", strerror(errno));
+	close(s);
+	return NULL;
+    }
+
+    hwaddr = ifr.ifr_hwaddr.sa_data;
+    snprintf( mac, 13, "%02X%02X%02X%02X%02X%02X", 
+	hwaddr[0] & 0xFF,
+	hwaddr[1] & 0xFF,
+	hwaddr[2] & 0xFF,
+	hwaddr[3] & 0xFF,
+	hwaddr[4] & 0xFF,
+	hwaddr[5] & 0xFF);
+	
+    close(s);
+    return safe_strdup(mac);
+#else
+    return NULL;
+#endif
+}
+
 void mark_online() {
 	int before;
 	int after;
diff -Naur wifidog/src/util.h wifidog-mac/src/util.h
--- wifidog/src/util.h	2005-03-12 02:02:02.000000000 +0000
+++ wifidog-mac/src/util.h	2005-05-30 22:46:37.609142217 +0100
@@ -37,6 +37,10 @@
 /* @brief Get IP address of an interface */
 char *get_iface_ip(char *ifname);
 
+/* @brief Get MAC address of an interface */
+char *get_iface_mac(char *ifname);
+
+
 /* @brief Sets hint that an online action (dns/connect/etc using WAN) succeeded */
 void mark_online();
 /* @brief Sets hint that an online action (dns/connect/etc using WAN) failed */
-------------- next part --------------
--- wifidog.conf	2005-05-30 22:50:09.555122894 +0100
+++ wifidog-wlon.conf	2005-05-30 23:28:02.754287557 +0100
@@ -9,7 +9,7 @@
 # this is used to give a customized login page to the clients
 # If none is supplied, the default login page will be used.
 
-GatewayID default
+# GatewayID default
 
 # Parameter: ExternalInterface
 # Default: NONE
@@ -17,7 +17,7 @@
 #
 # Set this to the external interface.  Typically vlan1 for OpenWrt, and eth0 or ppp0 otherwise
 
-# ExternalInterface eth0
+ExternalInterface vlan1
 
 # Parameter: GatewayInterface
 # Default: NONE
@@ -25,7 +25,7 @@
 #
 # Set this to the internal interface.    Typically br0 for OpenWrt, and eth1 otherwise
 
-GatewayInterface eth1
+GatewayInterface br0
 
 # Parameter: GatewayAddress
 # Default: Find it from GatewayInterface
@@ -43,7 +43,7 @@
 # this number should be equal to the number of AuthServer lines in this
 # configuration but it should probably not exceed 3.
 
-# AuthServMaxTries 3
+AuthServMaxTries 3
 
 # Parameter: AuthServer
 # Default: NONE
@@ -60,11 +60,11 @@
 #	Path wifidog/ (Optional; Default: /wifidog/ Note:  The path must be both prefixed and suffixed by /.  Use a single / for server root.)
 #}
 
-#AuthServer {
-#    Hostname auth.ilesansfil.org
-#    SSLAvailable yes
-#    Path /
-#}
+AuthServer {
+    Hostname map.wirelesslondon.info
+    SSLAvailable no
+    Path /map/wl2/auth/
+}
 
 #AuthServer {
 #    Hostname auth2.ilesansfil.org


More information about the WiFiDog mailing list