Changeset 422 for trunk/wifidog/src/fw_iptables.c
- Timestamp:
- 02/03/05 16:25:33 (8 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog/src/fw_iptables.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog/src/fw_iptables.c
r308 r422 238 238 239 239 iptables_do_command("-t mangle -N " TABLE_WIFIDOG_INCOMING); 240 iptables_do_command("-t mangle -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_INCOMING, config->external_interface); 240 if (config->external_interface) { 241 iptables_do_command("-t mangle -I FORWARD 1 -i %s -j " TABLE_WIFIDOG_INCOMING, config->external_interface); 242 } else { 243 iptables_do_command("-t mangle -I FORWARD 1 -j " TABLE_WIFIDOG_INCOMING); 244 } 245 246 iptables_do_command("-t filter -N " TABLE_WIFIDOG_WIFI_TO_GW); 247 iptables_do_command("-t filter -I INPUT 1 -i %s -j " TABLE_WIFIDOG_WIFI_TO_GW, config->gw_interface); 241 248 242 249 UNLOCK_CONFIG(); … … 256 263 257 264 fw_quiet = 1; 265 iptables_do_command("-t filter -F " TABLE_WIFIDOG_WIFI_TO_GW); 258 266 iptables_do_command("-t nat -F " TABLE_WIFIDOG_CLASS); 259 267 iptables_do_command("-t mangle -F " TABLE_WIFIDOG_OUTGOING); … … 282 290 rc = 0; 283 291 while (rc == 0) { 284 rc = iptables_do_command("-t mangle -D PREROUTING -i %s -j " TABLE_WIFIDOG_OUTGOING, config->gw_interface);285 } 286 iptables_do_command("-t mangle -X " TABLE_WIFIDOG_OUTGOING);292 rc = iptables_do_command("-t filter -D INPUT -i %s -j " TABLE_WIFIDOG_WIFI_TO_GW, config->gw_interface); 293 } 294 iptables_do_command("-t filter -X " TABLE_WIFIDOG_WIFI_TO_GW); 287 295 288 296 rc = 0; 289 297 while (rc == 0) { 290 rc = iptables_do_command("-t mangle -D FORWARD -i %s -j " TABLE_WIFIDOG_INCOMING, config->external_interface); 298 rc = iptables_do_command("-t mangle -D PREROUTING -i %s -j " TABLE_WIFIDOG_OUTGOING, config->gw_interface); 299 } 300 iptables_do_command("-t mangle -X " TABLE_WIFIDOG_OUTGOING); 301 302 rc = 0; 303 while (rc == 0) { 304 if (config->external_interface) { 305 rc = iptables_do_command("-t mangle -D FORWARD -i %s -j " TABLE_WIFIDOG_INCOMING, config->external_interface); 306 } else { 307 rc = iptables_do_command("-t mangle -D FORWARD -j " TABLE_WIFIDOG_INCOMING); 308 } 291 309 } 292 310 iptables_do_command("-t mangle -X " TABLE_WIFIDOG_INCOMING); … … 305 323 switch(type) { 306 324 case FW_ACCESS_ALLOW: 325 iptables_do_command("-t filter -A " TABLE_WIFIDOG_WIFI_TO_GW " -s %s -j ACCEPT", ip); 307 326 iptables_do_command("-t mangle -A " TABLE_WIFIDOG_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); 308 327 rc = iptables_do_command("-t mangle -A " TABLE_WIFIDOG_INCOMING " -d %s -j ACCEPT", ip); 309 328 break; 310 329 case FW_ACCESS_DENY: 330 iptables_do_command("-t filter -D " TABLE_WIFIDOG_WIFI_TO_GW " -s %s -j ACCEPT", ip); 311 331 iptables_do_command("-t mangle -D " TABLE_WIFIDOG_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); 312 332 rc = iptables_do_command("-t mangle -D " TABLE_WIFIDOG_INCOMING " -d %s -j ACCEPT", ip); … … 353 373 p1->counters.outgoing = counter; 354 374 p1->counters.last_updated = time(NULL); 355 debug(LOG_DEBUG, "%s - Updated counter to %ld bytes", ip, counter); 375 debug(LOG_DEBUG, "%s - Updated outgoing counter to %ld bytes from outgoing chain", ip, counter); 376 } 377 } else { 378 debug(LOG_ERR, "Could not find %s in client list", ip); 379 } 380 UNLOCK_CLIENT_LIST(); 381 } 382 } 383 pclose(output); 384 385 /* Look for wifi-to-firewall traffic */ 386 asprintf(&script, "%s %s", "iptables", "-v -x -t filter -L " TABLE_WIFIDOG_WIFI_TO_GW); 387 if (!(output = popen(script, "r"))) { 388 debug(LOG_ERR, "popen(): %s", strerror(errno)); 389 return -1; 390 } 391 free(script); 392 393 /* skip the first two lines */ 394 while (('\n' != fgetc(output)) && !feof(output)) 395 ; 396 while (('\n' != fgetc(output)) && !feof(output)) 397 ; 398 while (output && !(feof(output))) { 399 rc = fscanf(output, "%*s %lu %*s %*s %*s %*s %*s %s %*s %*s %*s %*s %*s 0x%*u", &counter, ip); 400 if (2 == rc && EOF != rc) { 401 debug(LOG_DEBUG, "WIFI2FW %s Bytes=%ld", ip, counter); 402 LOCK_CLIENT_LIST(); 403 if ((p1 = client_list_find_by_ip(ip))) { 404 if (p1->counters.togateway < counter) { 405 p1->counters.togateway = counter; 406 p1->counters.last_updated = time(NULL); 407 debug(LOG_DEBUG, "%s - Updated togateway counter to %ld bytes from wifi2fw chain", ip, counter); 356 408 } 357 409 } else { … … 397 449 return 1; 398 450 } 399
