@@ -258,6 +258,7 @@ iptables_fw_init(void)
258
258
t_trusted_mac * p ;
259
259
int proxy_port ;
260
260
fw_quiet = 0 ;
261
+ int got_authdown_ruleset = NULL == get_ruleset (FWRULESET_AUTH_IS_DOWN ) ? 0 : 1 ;
261
262
262
263
LOCK_CONFIG ();
263
264
config = config_get_config ();
@@ -283,10 +284,14 @@ iptables_fw_init(void)
283
284
iptables_do_command ("-t mangle -N " CHAIN_TRUSTED );
284
285
iptables_do_command ("-t mangle -N " CHAIN_OUTGOING );
285
286
iptables_do_command ("-t mangle -N " CHAIN_INCOMING );
287
+ if (got_authdown_ruleset )
288
+ iptables_do_command ("-t mangle -N " CHAIN_AUTH_IS_DOWN );
286
289
287
290
/* Assign links and rules to these new chains */
288
291
iptables_do_command ("-t mangle -I PREROUTING 1 -i %s -j " CHAIN_OUTGOING , config -> gw_interface );
289
- iptables_do_command ("-t mangle -I PREROUTING 1 -i %s -j " CHAIN_TRUSTED , config -> gw_interface );//this rule will be inserted before the prior one
292
+ iptables_do_command ("-t mangle -I PREROUTING 1 -i %s -j " CHAIN_TRUSTED , config -> gw_interface ); //this rule will be inserted before the prior one
293
+ if (got_authdown_ruleset )
294
+ iptables_do_command ("-t mangle -I PREROUTING 1 -i %s -j " CHAIN_AUTH_IS_DOWN , config -> gw_interface ); //this rule must be last in the chain
290
295
iptables_do_command ("-t mangle -I POSTROUTING 1 -o %s -j " CHAIN_INCOMING , config -> gw_interface );
291
296
292
297
for (p = config -> trustedmaclist ; p != NULL ; p = p -> next )
@@ -305,6 +310,8 @@ iptables_fw_init(void)
305
310
iptables_do_command ("-t nat -N " CHAIN_GLOBAL );
306
311
iptables_do_command ("-t nat -N " CHAIN_UNKNOWN );
307
312
iptables_do_command ("-t nat -N " CHAIN_AUTHSERVERS );
313
+ if (got_authdown_ruleset )
314
+ iptables_do_command ("-t nat -N " CHAIN_AUTH_IS_DOWN );
308
315
309
316
/* Assign links and rules to these new chains */
310
317
iptables_do_command ("-t nat -A PREROUTING -i %s -j " CHAIN_OUTGOING , config -> gw_interface );
@@ -326,7 +333,11 @@ iptables_fw_init(void)
326
333
327
334
iptables_do_command ("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_AUTHSERVERS );
328
335
iptables_do_command ("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_GLOBAL );
329
- iptables_do_command ("-t nat -A " CHAIN_UNKNOWN " -p tcp --dport 80 -j REDIRECT --to-ports %d" , gw_port );
336
+ if (got_authdown_ruleset ) {
337
+ iptables_do_command ("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_AUTH_IS_DOWN );
338
+ iptables_do_command ("-t nat -A " CHAIN_AUTH_IS_DOWN " -m mark --mark 0x%u -j ACCEPT" , FW_MARK_AUTH_IS_DOWN );
339
+ }
340
+ iptables_do_command ("-t nat -A " CHAIN_UNKNOWN " -p tcp --dport 80 -j REDIRECT --to-ports %d" , gw_port );
330
341
331
342
332
343
/*
@@ -343,6 +354,8 @@ iptables_fw_init(void)
343
354
iptables_do_command ("-t filter -N " CHAIN_VALIDATE );
344
355
iptables_do_command ("-t filter -N " CHAIN_KNOWN );
345
356
iptables_do_command ("-t filter -N " CHAIN_UNKNOWN );
357
+ if (got_authdown_ruleset )
358
+ iptables_do_command ("-t filter -N " CHAIN_AUTH_IS_DOWN );
346
359
347
360
/* Assign links and rules to these new chains */
348
361
@@ -366,20 +379,25 @@ iptables_fw_init(void)
366
379
iptables_fw_set_authservers ();
367
380
368
381
iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_LOCKED , FW_MARK_LOCKED );
369
- iptables_load_ruleset ("filter" , "locked-users" , CHAIN_LOCKED );
382
+ iptables_load_ruleset ("filter" , FWRULESET_LOCKED_USERS , CHAIN_LOCKED );
370
383
371
384
iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -j " CHAIN_GLOBAL );
372
- iptables_load_ruleset ("filter" , "global" , CHAIN_GLOBAL );
373
- iptables_load_ruleset ("nat" , "global" , CHAIN_GLOBAL );
385
+ iptables_load_ruleset ("filter" , FWRULESET_GLOBAL , CHAIN_GLOBAL );
386
+ iptables_load_ruleset ("nat" , FWRULESET_GLOBAL , CHAIN_GLOBAL );
374
387
375
388
iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_VALIDATE , FW_MARK_PROBATION );
376
- iptables_load_ruleset ("filter" , "validating-users" , CHAIN_VALIDATE );
389
+ iptables_load_ruleset ("filter" , FWRULESET_VALIDATING_USERS , CHAIN_VALIDATE );
377
390
378
391
iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_KNOWN , FW_MARK_KNOWN );
379
- iptables_load_ruleset ("filter" , "known-users" , CHAIN_KNOWN );
392
+ iptables_load_ruleset ("filter" , FWRULESET_KNOWN_USERS , CHAIN_KNOWN );
393
+
394
+ if (got_authdown_ruleset ) {
395
+ iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_AUTH_IS_DOWN , FW_MARK_AUTH_IS_DOWN );
396
+ iptables_load_ruleset ("filter" , FWRULESET_AUTH_IS_DOWN , CHAIN_AUTH_IS_DOWN );
397
+ }
380
398
381
399
iptables_do_command ("-t filter -A " CHAIN_TO_INTERNET " -j " CHAIN_UNKNOWN );
382
- iptables_load_ruleset ("filter" , "unknown-users" , CHAIN_UNKNOWN );
400
+ iptables_load_ruleset ("filter" , FWRULESET_UNKNOWN_USERS , CHAIN_UNKNOWN );
383
401
iptables_do_command ("-t filter -A " CHAIN_UNKNOWN " -j REJECT --reject-with icmp-port-unreachable" );
384
402
385
403
UNLOCK_CONFIG ();
@@ -395,6 +413,7 @@ iptables_fw_init(void)
395
413
int
396
414
iptables_fw_destroy (void )
397
415
{
416
+ int got_authdown_ruleset = NULL == get_ruleset (FWRULESET_AUTH_IS_DOWN ) ? 0 : 1 ;
398
417
fw_quiet = 1 ;
399
418
400
419
debug (LOG_DEBUG , "Destroying our iptables entries" );
@@ -407,12 +426,18 @@ iptables_fw_destroy(void)
407
426
debug (LOG_DEBUG , "Destroying chains in the MANGLE table" );
408
427
iptables_fw_destroy_mention ("mangle" , "PREROUTING" , CHAIN_TRUSTED );
409
428
iptables_fw_destroy_mention ("mangle" , "PREROUTING" , CHAIN_OUTGOING );
429
+ if (got_authdown_ruleset )
430
+ iptables_fw_destroy_mention ("mangle" , "PREROUTING" , CHAIN_AUTH_IS_DOWN );
410
431
iptables_fw_destroy_mention ("mangle" , "POSTROUTING" , CHAIN_INCOMING );
411
432
iptables_do_command ("-t mangle -F " CHAIN_TRUSTED );
412
433
iptables_do_command ("-t mangle -F " CHAIN_OUTGOING );
434
+ if (got_authdown_ruleset )
435
+ iptables_do_command ("-t mangle -F " CHAIN_AUTH_IS_DOWN );
413
436
iptables_do_command ("-t mangle -F " CHAIN_INCOMING );
414
437
iptables_do_command ("-t mangle -X " CHAIN_TRUSTED );
415
438
iptables_do_command ("-t mangle -X " CHAIN_OUTGOING );
439
+ if (got_authdown_ruleset )
440
+ iptables_do_command ("-t mangle -X " CHAIN_AUTH_IS_DOWN );
416
441
iptables_do_command ("-t mangle -X " CHAIN_INCOMING );
417
442
418
443
/*
@@ -424,12 +449,16 @@ iptables_fw_destroy(void)
424
449
iptables_fw_destroy_mention ("nat" , "PREROUTING" , CHAIN_OUTGOING );
425
450
iptables_do_command ("-t nat -F " CHAIN_AUTHSERVERS );
426
451
iptables_do_command ("-t nat -F " CHAIN_OUTGOING );
452
+ if (got_authdown_ruleset )
453
+ iptables_do_command ("-t nat -F " CHAIN_AUTH_IS_DOWN );
427
454
iptables_do_command ("-t nat -F " CHAIN_TO_ROUTER );
428
455
iptables_do_command ("-t nat -F " CHAIN_TO_INTERNET );
429
456
iptables_do_command ("-t nat -F " CHAIN_GLOBAL );
430
457
iptables_do_command ("-t nat -F " CHAIN_UNKNOWN );
431
458
iptables_do_command ("-t nat -X " CHAIN_AUTHSERVERS );
432
459
iptables_do_command ("-t nat -X " CHAIN_OUTGOING );
460
+ if (got_authdown_ruleset )
461
+ iptables_do_command ("-t nat -X " CHAIN_AUTH_IS_DOWN );
433
462
iptables_do_command ("-t nat -X " CHAIN_TO_ROUTER );
434
463
iptables_do_command ("-t nat -X " CHAIN_TO_INTERNET );
435
464
iptables_do_command ("-t nat -X " CHAIN_GLOBAL );
@@ -449,13 +478,17 @@ iptables_fw_destroy(void)
449
478
iptables_do_command ("-t filter -F " CHAIN_VALIDATE );
450
479
iptables_do_command ("-t filter -F " CHAIN_KNOWN );
451
480
iptables_do_command ("-t filter -F " CHAIN_UNKNOWN );
481
+ if (got_authdown_ruleset )
482
+ iptables_do_command ("-t filter -F " CHAIN_AUTH_IS_DOWN );
452
483
iptables_do_command ("-t filter -X " CHAIN_TO_INTERNET );
453
484
iptables_do_command ("-t filter -X " CHAIN_AUTHSERVERS );
454
485
iptables_do_command ("-t filter -X " CHAIN_LOCKED );
455
486
iptables_do_command ("-t filter -X " CHAIN_GLOBAL );
456
487
iptables_do_command ("-t filter -X " CHAIN_VALIDATE );
457
488
iptables_do_command ("-t filter -X " CHAIN_KNOWN );
458
489
iptables_do_command ("-t filter -X " CHAIN_UNKNOWN );
490
+ if (got_authdown_ruleset )
491
+ iptables_do_command ("-t filter -X " CHAIN_AUTH_IS_DOWN );
459
492
460
493
return 1 ;
461
494
}
@@ -571,6 +604,28 @@ iptables_fw_access_host(fw_access_t type, const char *host)
571
604
return rc ;
572
605
}
573
606
607
+ /** Set a mark when auth server is not reachable */
608
+ int
609
+ iptables_fw_auth_unreachable (int tag )
610
+ {
611
+ int got_authdown_ruleset = NULL == get_ruleset (FWRULESET_AUTH_IS_DOWN ) ? 0 : 1 ;
612
+ if (got_authdown_ruleset )
613
+ return iptables_do_command ("-t mangle -A " CHAIN_AUTH_IS_DOWN " -j MARK --set-mark 0x%u" , tag );
614
+ else
615
+ return 1 ;
616
+ }
617
+
618
+ /** Remove mark when auth server is reachable again */
619
+ int
620
+ iptables_fw_auth_reachable (void )
621
+ {
622
+ int got_authdown_ruleset = NULL == get_ruleset (FWRULESET_AUTH_IS_DOWN ) ? 0 : 1 ;
623
+ if (got_authdown_ruleset )
624
+ return iptables_do_command ("-t mangle -F " CHAIN_AUTH_IS_DOWN );
625
+ else
626
+ return 1 ;
627
+ }
628
+
574
629
/** Update the counters of all the clients in the client list */
575
630
int
576
631
iptables_fw_counters_update (void )
0 commit comments