Changeset 492

Show
Ignore:
Timestamp:
03/11/05 11:15:06 (8 years ago)
Author:
minaguib
Message:

* If external interface was unspecified in the conf file, try to determine it from the default route
* If external interface is known, specify it in the trigger rule in nat.PREROUTING to prevent the rule from matching traffic inbound to the router itself. This should fix the issue raised by Philippe and Pascal on the mailing list

Location:
trunk/wifidog
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/ChangeLog

    r490 r492  
    11# $Header$ 
     2 
     32005-03-11 Mina Naguib <mina@ilesansfil.org> 
     4        * If external interface was unspecified in the conf file, try to determine 
     5        it from the default route 
     6        * If external interface is known, specify it in the trigger rule in 
     7        nat.PREROUTING to prevent the rule from matching traffic inbound to the 
     8        router itself.  This should fix the issue raised by Philippe and Pascal on 
     9        the mailing list 
    210 
    3112005-03-07 Mina Naguib <mina@ilesansfil.org> 
  • trunk/wifidog/src/fw_iptables.c

    r490 r492  
    183183    s_config *config; 
    184184         char * gw_interface = NULL; 
     185         char * external_interface = NULL; 
    185186         int gw_port = 0; 
    186187    
     
    191192         gw_interface = safe_strdup(config->gw_interface); 
    192193         gw_port = config->gw_port; 
     194         if (config->external_interface) 
     195                 external_interface = safe_strdup(config->external_interface); 
    193196         UNLOCK_CONFIG(); 
    194197     
     
    219222 
    220223                        /* Assign links and rules to these new chains */ 
    221                         iptables_do_command("-t nat -I PREROUTING 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
     224                        if (external_interface) 
     225                                iptables_do_command("-t nat -I PREROUTING 1 -i %s -o %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface, external_interface); 
     226                        else 
     227                                iptables_do_command("-t nat -I PREROUTING 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
    222228                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -m mark --mark 0x%u -j RETURN", FW_MARK_KNOWN); 
    223229                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -m mark --mark 0x%u -j RETURN", FW_MARK_PROBATION); 
     
    264270 
    265271        free(gw_interface); 
     272        if (external_interface) 
     273                free(external_interface); 
    266274 
    267275    return 1; 
  • trunk/wifidog/src/gateway.c

    r488 r492  
    179179        debug(LOG_DEBUG, "%s = %s", config->gw_interface, config->gw_address); 
    180180    } 
     181         /* If we don't have the external interface, try to get it */ 
     182         if (!config->external_interface) { 
     183                 config->external_interface = get_default_iface(); 
     184                 if (!config->external_interface) { 
     185                         debug(LOG_CRIT, "Failed to determine external interface.  The firewall rules will not be up to par"); 
     186                 } 
     187         } 
     188 
    181189 
    182190        /* Initializes the web server */ 
  • trunk/wifidog/src/util.c

    r488 r492  
    4949#include <netdb.h> 
    5050 
     51#include "common.h" 
    5152#include "client_list.h" 
    5253#include "safe.h" 
     
    137138} 
    138139 
     140/* 
     141 * @return Interface name or NULL if it cannot be determined - must be free()ed by caller when no longer needed 
     142 */ 
     143char * get_default_iface() { 
     144        FILE * fh; 
     145        char * retval = NULL; 
     146        char buffer[MAX_BUF]; 
     147        char ifname[MAX_BUF]; 
     148        char mask[MAX_BUF]; 
     149        debug(LOG_INFO, "Trying to determine the default interface"); 
     150 
     151        if ((fh = fopen("/proc/net/route", "r"))) { 
     152                while (!feof(fh) && fgets(buffer, sizeof(buffer), fh)) { 
     153                        if (sscanf(buffer, "%s %s", ifname, mask) == 2 && strcmp(mask, "00000000") == 0) { 
     154                                /* Found it */ 
     155                                retval = safe_strdup(ifname); 
     156                                debug(LOG_INFO, "Determined default interface [%s]", retval); 
     157                                break; 
     158                        } 
     159                } 
     160                fclose(fh); 
     161        } 
     162        else { 
     163                debug(LOG_ERR, "Failed to open /proc/net/route"); 
     164        } 
     165 
     166        if (!retval) 
     167                debug(LOG_ERR, "Failed to determine default interface"); 
     168 
     169        return retval; 
     170} 
     171 
    139172char *get_iface_ip(char *ifname) { 
    140173#ifdef __linux__ 
  • trunk/wifidog/src/util.h

    r479 r492  
    3838char *get_iface_ip(char *ifname); 
    3939 
     40/* @Brief get the interface name used by the default route */ 
     41char * get_default_iface(); 
     42 
    4043/* @brief Sets hint that an online action (dns/connect/etc using WAN) succeeded */ 
    4144void mark_online();