Changeset 278

Show
Ignore:
Timestamp:
11/18/04 17:23:29 (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.

Location:
branches/WIFIDOG_1_0_X/wifidog
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • branches/WIFIDOG_1_0_X/wifidog/ChangeLog

    r275 r278  
    11# $Header$ 
     2 
    232004-11-18 Alexandre Carmel-Veilleux <acv@acv.ca> 
    34        * src/fw_iptables.[ch]: Merged in phil's patch 
     5        * src/*: Added ping_thread hooks to reset authserver table in the 
     6          firewall if it notices the auth_servers changing IPs. 
    47 
    582004-11-10 Alexandre Carmel-Veilleux <acv@acv.ca> 
  • branches/WIFIDOG_1_0_X/wifidog/src/conf.c

    r252 r278  
    4242#include "http.h" 
    4343#include "auth.h" 
     44#include "firewall.h" 
    4445 
    4546/** @internal 
     
    649650 
    650651        pthread_mutex_unlock(&config_mutex); 
    651 } 
     652 
     653        fw_clear_authservers(); 
     654        fw_set_authservers(); 
     655} 
  • branches/WIFIDOG_1_0_X/wifidog/src/conf.h

    r256 r278  
    6262                                     listens on */ 
    6363    int authserv_use_ssl;       /**< @brief Use SSL or not */ 
     64    struct in_addr *last_ip;    /**< @brief Last IP of the authserver */ 
    6465    struct _auth_serv_t *next; 
    6566} t_auth_serv; 
  • branches/WIFIDOG_1_0_X/wifidog/src/firewall.c

    r256 r278  
    4141 
    4242#include <string.h> 
     43 
     44#include "httpd.h" 
    4345 
    4446#include "debug.h" 
     
    123125    debug(LOG_INFO, "Initializing Firewall"); 
    124126    return iptables_fw_init(); 
     127} 
     128 
     129/** Clear the authserver rules 
     130 */ 
     131void 
     132fw_clear_authservers(void) 
     133{ 
     134        debug(LOG_INFO, "Clearing the authservers list"); 
     135        iptables_fw_clear_authservers(); 
     136} 
     137 
     138/** Set the authservers rules 
     139 */ 
     140void 
     141fw_set_authservers(void) 
     142{ 
     143        debug(LOG_INFO, "Setting the authservers list"); 
     144        iptables_fw_set_authservers(); 
    125145} 
    126146 
  • branches/WIFIDOG_1_0_X/wifidog/src/firewall.h

    r170 r278  
    3939int fw_init(void); 
    4040 
     41/** @brief Clears the authservers list */ 
     42void fw_clear_authservers(void); 
     43 
     44/** @brief Sets the authservers list */ 
     45void fw_set_authservers(void); 
     46 
    4147/** @brief Destroy the firewall */ 
    4248int fw_destroy(void); 
  • branches/WIFIDOG_1_0_X/wifidog/src/fw_iptables.c

    r275 r278  
    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); 
  • branches/WIFIDOG_1_0_X/wifidog/src/fw_iptables.h

    r275 r278  
    5151int iptables_fw_init(void); 
    5252 
     53/** @brief Initializes the authservers table */ 
     54void iptables_fw_set_authservers(void); 
     55 
     56/** @brief Clears the authservers table */ 
     57void iptables_fw_clear_authservers(void); 
     58 
    5359/** @brief Destroy the firewall */ 
    5460int iptables_fw_destroy(void); 
  • branches/WIFIDOG_1_0_X/wifidog/src/ping_thread.c

    r260 r278  
    4747#include "debug.h" 
    4848#include "ping_thread.h" 
     49#include "util.h" 
    4950 
    5051static void ping(void); 
     
    9394        int                     sockfd, 
    9495                                nfds, 
    95                                 done; 
     96                                done, 
     97                                i; 
    9698        t_auth_serv             *auth_server; 
    9799        char                    request[MAX_BUF]; 
     
    124126        } 
    125127 
     128        if (auth_server->last_ip == NULL) { 
     129                auth_server->last_ip = (struct in_addr *)malloc( 
     130                                sizeof(struct in_addr)); 
     131                if (auth_server->last_ip == NULL) { 
     132                        debug(LOG_CRIT, "Could not allocate memory, Banzai!"); 
     133                        exit(-1); 
     134                } 
     135                memcpy(auth_server->last_ip, h_addr, sizeof(struct in_addr)); 
     136        } else { 
     137                for (i = 0; i < sizeof(struct in_addr) 
     138                                && (*((char *)auth_server->last_ip + i) 
     139                                        == *((char *)h_addr + i)); i++); 
     140                if (i < sizeof(struct in_addr)) { 
     141                        fw_clear_authservers(); 
     142                        fw_set_authservers(); 
     143                } 
     144        } 
    126145        their_addr.sin_family = AF_INET; 
    127146        their_addr.sin_port = htons(auth_server->authserv_http_port);