Show
Ignore:
Timestamp:
02/13/05 21:31:43 (8 years ago)
Author:
minaguib
Message:

* Bugfix previous commit of re-doing firewall - was not respecting gw_interface when it should have
* Got rid of TABLE_WIFIDOG_WIFI_TO_GW completely since it's unneeded and screwed up bytecount

Files:
1 modified

Legend:

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

    r457 r458  
    183183    s_config *config; 
    184184         char * gw_interface = NULL; 
    185          char * external_interface = NULL; 
    186185         int gw_port = 0; 
    187186    
     
    190189    config = config_get_config(); 
    191190         LOCK_CONFIG(); 
    192          if (config->gw_interface) 
    193                  gw_interface = strdup(config->gw_interface); 
    194          if (config->external_interface) 
    195                  external_interface = strdup(config->external_interface); 
     191         gw_interface = strdup(config->gw_interface); 
    196192         gw_port = config->gw_port; 
    197193         UNLOCK_CONFIG(); 
     
    209205                        /* Assign links and rules to these new chains */ 
    210206                        iptables_do_command("-t mangle -I PREROUTING 1 -i %s -j " TABLE_WIFIDOG_OUTGOING, gw_interface); 
    211  
    212                         if (external_interface) { 
    213                                 iptables_do_command("-t mangle -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_INCOMING, external_interface); 
    214                         } 
    215                         else { 
    216                                 iptables_do_command("-t mangle -I FORWARD 1 -j " TABLE_WIFIDOG_INCOMING); 
    217                         } 
     207                        iptables_do_command("-t mangle -I POSTROUTING 1 -o %s -j " TABLE_WIFIDOG_INCOMING, gw_interface); 
    218208 
    219209 
     
    229219 
    230220                        /* Assign links and rules to these new chains */ 
    231                         if (external_interface) { 
    232                                 iptables_do_command("-t nat -I PREROUTING 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
    233                         } 
    234                         else { 
    235                                 iptables_do_command("-t nat -I PREROUTING 1 -j " TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    236                         } 
    237  
     221                        iptables_do_command("-t nat -I PREROUTING 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
    238222                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -m mark --mark 0x%u -j RETURN", FW_MARK_KNOWN); 
    239223                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -m mark --mark 0x%u -j RETURN", FW_MARK_PROBATION); 
    240224                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -j " TABLE_WIFIDOG_UNKNOWN); 
     225 
    241226                        iptables_do_command("-t nat -A " TABLE_WIFIDOG_UNKNOWN " -p tcp --dport 80 -j REDIRECT --to-ports %d", gw_port); 
    242227 
     
    249234 
    250235                        /* Create new chains */ 
    251                         iptables_do_command("-t filter -N " TABLE_WIFIDOG_WIFI_TO_GW); 
    252236                        iptables_do_command("-t filter -N " TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    253237                        iptables_do_command("-t filter -N " TABLE_WIFIDOG_AUTHSERVERS); 
     
    259243 
    260244                        /* Assign links and rules to these new chains */ 
    261                         iptables_do_command("-t filter -I INPUT 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_GW, gw_interface); 
    262  
    263                         if (external_interface) { 
    264                                 iptables_do_command("-t filter -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
    265                         } 
    266                         else { 
    267                                 iptables_do_command("-t filter -I FORWARD 1 -j " TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    268                         } 
    269  
     245                        iptables_do_command("-t filter -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_INTERNET, gw_interface); 
    270246                        iptables_do_command("-t filter -A " TABLE_WIFIDOG_WIFI_TO_INTERNET " -j " TABLE_WIFIDOG_AUTHSERVERS); 
    271247                        iptables_fw_set_authservers(); 
     
    287263                        iptables_do_command("-t filter -A " TABLE_WIFIDOG_UNKNOWN " -j REJECT --reject-with icmp-port-unreachable"); 
    288264 
    289         if (gw_interface) 
    290                 free(gw_interface); 
    291         if (external_interface) 
    292                 free(external_interface); 
     265        free(gw_interface); 
    293266 
    294267    return 1; 
     
    310283          */ 
    311284         iptables_fw_destroy_mention("mangle", "PREROUTING", TABLE_WIFIDOG_OUTGOING); 
    312          iptables_fw_destroy_mention("mangle", "FORWARD", TABLE_WIFIDOG_INCOMING); 
     285         iptables_fw_destroy_mention("mangle", "POSTROUTING", TABLE_WIFIDOG_INCOMING); 
    313286    iptables_do_command("-t mangle -F " TABLE_WIFIDOG_OUTGOING); 
    314287    iptables_do_command("-t mangle -F " TABLE_WIFIDOG_INCOMING); 
     
    332305          * 
    333306          */ 
    334          iptables_fw_destroy_mention("filter", "INPUT", TABLE_WIFIDOG_WIFI_TO_GW); 
    335307         iptables_fw_destroy_mention("filter", "FORWARD", TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    336          iptables_do_command("-t filter -F " TABLE_WIFIDOG_WIFI_TO_GW); 
    337308         iptables_do_command("-t filter -F " TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    338309         iptables_do_command("-t filter -F " TABLE_WIFIDOG_AUTHSERVERS); 
     
    342313         iptables_do_command("-t filter -F " TABLE_WIFIDOG_KNOWN); 
    343314         iptables_do_command("-t filter -F " TABLE_WIFIDOG_UNKNOWN); 
    344          iptables_do_command("-t filter -X " TABLE_WIFIDOG_WIFI_TO_GW); 
    345315         iptables_do_command("-t filter -X " TABLE_WIFIDOG_WIFI_TO_INTERNET); 
    346316         iptables_do_command("-t filter -X " TABLE_WIFIDOG_AUTHSERVERS); 
     
    418388    switch(type) { 
    419389        case FW_ACCESS_ALLOW: 
    420             iptables_do_command("-t filter -A " TABLE_WIFIDOG_WIFI_TO_GW " -s %s -j ACCEPT", ip); 
    421390            iptables_do_command("-t mangle -A " TABLE_WIFIDOG_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); 
    422391            rc = iptables_do_command("-t mangle -A " TABLE_WIFIDOG_INCOMING " -d %s -j ACCEPT", ip); 
    423392            break; 
    424393        case FW_ACCESS_DENY: 
    425             iptables_do_command("-t filter -D " TABLE_WIFIDOG_WIFI_TO_GW " -s %s -j ACCEPT", ip); 
    426394            iptables_do_command("-t mangle -D " TABLE_WIFIDOG_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); 
    427395            rc = iptables_do_command("-t mangle -D " TABLE_WIFIDOG_INCOMING " -d %s -j ACCEPT", ip); 
     
    484452    pclose(output); 
    485453 
    486     /* Look for wifi-to-firewall traffic */ 
    487     asprintf(&script, "%s %s", "iptables", "-v -n -x -t filter -L " TABLE_WIFIDOG_WIFI_TO_GW); 
    488     if (!(output = popen(script, "r"))) { 
    489         debug(LOG_ERR, "popen(): %s", strerror(errno)); 
    490         return -1; 
    491     } 
    492     free(script); 
    493  
    494     /* skip the first two lines */ 
    495     while (('\n' != fgetc(output)) && !feof(output)) 
    496         ; 
    497     while (('\n' != fgetc(output)) && !feof(output)) 
    498         ; 
    499     while (output && !(feof(output))) { 
    500         rc = fscanf(output, "%*s %lu %*s %*s %*s %*s %*s %15[0-9.] %*s", &counter, ip); 
    501         if (2 == rc && EOF != rc) { 
    502                           /* Sanity*/ 
    503                           if (!inet_aton(ip, &tempaddr)) { 
    504                                   debug(LOG_WARNING, "I was supposed to read an IP address but instead got [%s] - ignoring it", ip); 
    505                                   continue; 
    506                           } 
    507             debug(LOG_DEBUG, "WIFI2FW %s Bytes=%ld", ip, counter); 
    508             LOCK_CLIENT_LIST(); 
    509             if ((p1 = client_list_find_by_ip(ip))) { 
    510                 if (p1->counters.togateway < counter) { 
    511                     p1->counters.togateway = counter; 
    512                     p1->counters.last_updated = time(NULL); 
    513                     debug(LOG_DEBUG, "%s - Updated togateway counter to %ld bytes from wifi2fw chain", ip, counter); 
    514                 } 
    515             } else { 
    516                 debug(LOG_ERR, "Could not find %s in client list", ip); 
    517             } 
    518             UNLOCK_CLIENT_LIST(); 
    519         } 
    520     } 
    521     pclose(output); 
    522  
    523454    /* Look for incoming traffic */ 
    524455    asprintf(&script, "%s %s", "iptables", "-v -n -x -t mangle -L " TABLE_WIFIDOG_INCOMING);