Show
Ignore:
Timestamp:
11/18/04 17:22:51 (9 years ago)
Author:
alexcv
Message:

ping_thread now detects when auth_servers change IPs and reset the firewall
rules accordingly. Additional hooks in the firewall code to do this. Also,
if we change primary auth_server, we reset the list, jsut in case the IP
for the next auth_server was stale. That's done in conf.c.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/fw_iptables.c

    r276 r277  
    7373} 
    7474 
     75void 
     76iptables_fw_clear_authservers(void) 
     77{ 
     78    iptables_do_command("-t nat -F " TABLE_WIFIDOG_AUTHSERVERS); 
     79} 
     80 
     81void 
     82iptables_fw_set_authservers(void) 
     83{ 
     84    s_config *config; 
     85    t_auth_serv *auth_server; 
     86    
     87    config = config_get_config(); 
     88     
     89    LOCK_CONFIG(); 
     90     
     91    iptables_do_command("-t nat -N " TABLE_WIFIDOG_AUTHSERVERS); 
     92    for (auth_server = config->auth_servers; auth_server != NULL; 
     93                    auth_server = auth_server->next) { 
     94        iptables_do_command("-t nat -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->authserv_hostname); 
     95    } 
     96 
     97    UNLOCK_CONFIG(); 
     98} 
     99 
    75100/** Initialize the firewall rules 
    76101 */ 
     
    79104{ 
    80105    s_config *config; 
    81     t_auth_serv *auth_server; 
    82106    
    83107    config = config_get_config(); 
    84108    fw_quiet = 0; 
    85109     
    86     LOCK_CONFIG(); 
    87      
    88     iptables_do_command("-t nat -N " TABLE_WIFIDOG_AUTHSERVERS); 
    89     for (auth_server = config->auth_servers; auth_server != NULL; 
    90                     auth_server = auth_server->next) { 
    91         iptables_do_command("-t nat -A " TABLE_WIFIDOG_AUTHSERVERS " -d %s -j ACCEPT", auth_server->authserv_hostname); 
    92     } 
    93  
    94     UNLOCK_CONFIG(); 
    95  
     110    iptables_fw_set_authservers(); 
     111 
     112    LOCK_CONFIG(); 
     113     
    96114    iptables_do_command("-t nat -N " TABLE_WIFIDOG_VALIDATE); 
    97115    iptables_do_command("-t nat -A " TABLE_WIFIDOG_VALIDATE " -j " TABLE_WIFIDOG_AUTHSERVERS); 
    98116    iptables_do_command("-t nat -A " TABLE_WIFIDOG_VALIDATE " -d %s -j ACCEPT", config->gw_address); 
     117 
     118    UNLOCK_CONFIG(); 
    99119 
    100120    /** Insert global rules BEFORE the "defaults" */ 
     
    113133    iptables_do_command("-t nat -A " TABLE_WIFIDOG_VALIDATE " -j DROP"); 
    114134 
     135    LOCK_CONFIG(); 
     136     
    115137    iptables_do_command("-t nat -N " TABLE_WIFIDOG_UNKNOWN); 
    116138    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -j " TABLE_WIFIDOG_AUTHSERVERS); 
    117139    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -d %s -j ACCEPT", config->gw_address); 
    118140 
     141    UNLOCK_CONFIG(); 
     142     
    119143    /** Insert global rules BEFORE the "defaults" */ 
    120144 
     
    122146    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -p tcp --dport 67 -j ACCEPT"); 
    123147    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -p udp --dport 53 -j ACCEPT"); 
     148 
     149    LOCK_CONFIG(); 
     150     
    124151    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -p tcp --dport 80 -j REDIRECT --to-ports %d", config->gw_port); 
     152 
     153    UNLOCK_CONFIG(); 
     154     
    125155    iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -j DROP"); 
    126156 
     
    135165 
    136166    iptables_do_command("-t nat -N " TABLE_WIFIDOG_CLASS); 
     167 
     168    LOCK_CONFIG(); 
     169     
    137170    iptables_do_command("-t nat -A " TABLE_WIFIDOG_CLASS " -i %s -m mark --mark 0x%u -j " TABLE_WIFIDOG_VALIDATE, config->gw_interface, FW_MARK_PROBATION); 
    138171    iptables_do_command("-t nat -A " TABLE_WIFIDOG_CLASS " -i %s -m mark --mark 0x%u -j " TABLE_WIFIDOG_KNOWN, config->gw_interface, FW_MARK_KNOWN); 
     
    147180    iptables_do_command("-t mangle -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_INCOMING, config->external_interface); 
    148181 
     182    UNLOCK_CONFIG(); 
     183     
    149184    return 1; 
    150185} 
     
    170205    iptables_do_command("-t nat -F " TABLE_WIFIDOG_KNOWN); 
    171206    iptables_do_command("-t nat -F " TABLE_WIFIDOG_LOCKED); 
     207    iptables_do_command("-t nat -X " TABLE_WIFIDOG_AUTHSERVERS); 
    172208    iptables_do_command("-t nat -X " TABLE_WIFIDOG_VALIDATE); 
    173209    iptables_do_command("-t nat -X " TABLE_WIFIDOG_UNKNOWN);