Skip to content

Commit fc5535f

Browse files
committed
Add MarkOffsetBits to support the qos-scripts to work together
* The qos-scripts using 8 bits marks (0x01 - 0xff) for their classification purpose which it has overlapped with the wifidog marks. Therefore, MarkOffsetBits should be specified in the config file for the proper offset, in this case of the qos-scripts is 8 bits and the wifidog mark then left shifted as below, 0x1 => 0x100 0x2 => 0x200 0xfe => 0xfe00 The default value of MarkOffsetBits is 0 that is no offset.
1 parent 1188232 commit fc5535f

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

src/conf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef enum {
102102
oSSLPeerVerification,
103103
oSSLCertPath,
104104
oSSLAllowedCipherList,
105+
oMarkOffsetBits,
105106
} OpCodes;
106107

107108
/** @internal
@@ -147,6 +148,7 @@ static const struct {
147148
"sslpeerverification", oSSLPeerVerification}, {
148149
"sslcertpath", oSSLCertPath}, {
149150
"sslallowedcipherlist", oSSLAllowedCipherList}, {
151+
"markoffsetbits", oMarkOffsetBits}, {
150152
NULL, oBadOption},};
151153

152154
static void config_notnull(const void *, const char *);
@@ -201,6 +203,7 @@ config_init(void)
201203
config.ssl_verify = DEFAULT_AUTHSERVSSLPEERVER;
202204
config.ssl_cipher_list = NULL;
203205
config.arp_table_path = safe_strdup(DEFAULT_ARPTABLE);
206+
config.markoffsetbits = DEFAULT_MARKOFFSETBITS;
204207

205208
debugconf.log_stderr = 1;
206209
debugconf.debuglevel = DEFAULT_DEBUGLEVEL;
@@ -785,6 +788,10 @@ config_read(const char *filename)
785788
debug(LOG_WARNING, "SSLAllowedCipherList is set but no SSL compiled in. Ignoring!");
786789
#endif
787790
break;
791+
case oMarkOffsetBits:
792+
sscanf(p1, "%u", &config.markoffsetbits);
793+
config.markoffsetbits = config.markoffsetbits > 31 ? 0 : config.markoffsetbits;
794+
break;
788795
case oBadOption:
789796
/* FALL THROUGH */
790797
default:

src/conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#define DEFAULT_AUTHSERVSSLPEERVER 1 /* 0 means: Enable peer verification */
6868
#define DEFAULT_ARPTABLE "/proc/net/arp"
6969
/*@}*/
70+
#define DEFAULT_MARKOFFSETBITS 0
7071

7172
/*@{*/
7273
/** Defines for firewall rule sets. */
@@ -192,6 +193,8 @@ typedef struct {
192193
char *arp_table_path; /**< @brief Path to custom ARP table, formatted
193194
like /proc/net/arp */
194195
t_popular_server *popular_servers; /**< @brief list of popular servers */
196+
unsigned int markoffsetbits; /**< @brief bits, left shifted mark values
197+
for n bits */
195198
} s_config;
196199

197200
/** @brief Get the current gateway configuration */

src/fw_iptables.c

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ iptables_fw_init(void)
287287
iptables_do_command("-t mangle -I POSTROUTING 1 -o %s -j " CHAIN_INCOMING, config->gw_interface);
288288

289289
for (p = config->trustedmaclist; p != NULL; p = p->next)
290-
iptables_do_command("-t mangle -A " CHAIN_TRUSTED " -m mac --mac-source %s -j MARK --set-mark %d", p->mac,
291-
FW_MARK_KNOWN);
290+
iptables_do_command("-t mangle -A " CHAIN_TRUSTED " -m mac --mac-source %s -j MARK --set-mark 0x%x", p->mac,
291+
FW_MARK_KNOWN << config->markoffsetbits);
292292

293293
/*
294294
*
@@ -317,22 +317,32 @@ iptables_fw_init(void)
317317
if ((proxy_port = config_get_config()->proxy_port) != 0) {
318318
debug(LOG_DEBUG, "Proxy port set, setting proxy rule");
319319
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET
320-
" -p tcp --dport 80 -m mark --mark 0x%u -j REDIRECT --to-port %u", FW_MARK_KNOWN,
320+
" -p tcp --dport 80 -m mark --mark 0x%x/0x%x -j REDIRECT --to-port %u",
321+
FW_MARK_KNOWN << config->markoffsetbits,
322+
FW_MARK_KNOWN << config->markoffsetbits,
321323
proxy_port);
322324
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET
323-
" -p tcp --dport 80 -m mark --mark 0x%u -j REDIRECT --to-port %u", FW_MARK_PROBATION,
325+
" -p tcp --dport 80 -m mark --mark 0x%x/0x%x -j REDIRECT --to-port %u",
326+
FW_MARK_PROBATION << config->markoffsetbits,
327+
FW_MARK_PROBATION << config->markoffsetbits,
324328
proxy_port);
325329
}
326330

327-
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j ACCEPT", FW_MARK_KNOWN);
328-
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j ACCEPT", FW_MARK_PROBATION);
331+
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j ACCEPT",
332+
FW_MARK_KNOWN << config->markoffsetbits,
333+
FW_MARK_KNOWN << config->markoffsetbits);
334+
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j ACCEPT",
335+
FW_MARK_PROBATION << config->markoffsetbits,
336+
FW_MARK_PROBATION << config->markoffsetbits);
329337
iptables_do_command("-t nat -A " CHAIN_TO_INTERNET " -j " CHAIN_UNKNOWN);
330338

331339
iptables_do_command("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_AUTHSERVERS);
332340
iptables_do_command("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_GLOBAL);
333341
if (got_authdown_ruleset) {
334342
iptables_do_command("-t nat -A " CHAIN_UNKNOWN " -j " CHAIN_AUTH_IS_DOWN);
335-
iptables_do_command("-t nat -A " CHAIN_AUTH_IS_DOWN " -m mark --mark 0x%u -j ACCEPT", FW_MARK_AUTH_IS_DOWN);
343+
iptables_do_command("-t nat -A " CHAIN_AUTH_IS_DOWN " -m mark --mark 0x%x/0x%x -j ACCEPT",
344+
FW_MARK_AUTH_IS_DOWN << config->markoffsetbits,
345+
FW_MARK_AUTH_IS_DOWN << config->markoffsetbits);
336346
}
337347
iptables_do_command("-t nat -A " CHAIN_UNKNOWN " -p tcp --dport 80 -j REDIRECT --to-ports %d", gw_port);
338348

@@ -374,22 +384,29 @@ iptables_fw_init(void)
374384
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -j " CHAIN_AUTHSERVERS);
375385
iptables_fw_set_authservers();
376386

377-
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_LOCKED, FW_MARK_LOCKED);
387+
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j " CHAIN_LOCKED,
388+
FW_MARK_LOCKED << config->markoffsetbits,
389+
FW_MARK_LOCKED << config->markoffsetbits);
378390
iptables_load_ruleset("filter", FWRULESET_LOCKED_USERS, CHAIN_LOCKED);
379391

380392
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -j " CHAIN_GLOBAL);
381393
iptables_load_ruleset("filter", FWRULESET_GLOBAL, CHAIN_GLOBAL);
382394
iptables_load_ruleset("nat", FWRULESET_GLOBAL, CHAIN_GLOBAL);
383395

384-
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_VALIDATE, FW_MARK_PROBATION);
396+
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j " CHAIN_VALIDATE,
397+
FW_MARK_PROBATION << config->markoffsetbits,
398+
FW_MARK_PROBATION << config->markoffsetbits);
385399
iptables_load_ruleset("filter", FWRULESET_VALIDATING_USERS, CHAIN_VALIDATE);
386400

387-
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_KNOWN, FW_MARK_KNOWN);
401+
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j " CHAIN_KNOWN,
402+
FW_MARK_KNOWN << config->markoffsetbits,
403+
FW_MARK_KNOWN << config->markoffsetbits);
388404
iptables_load_ruleset("filter", FWRULESET_KNOWN_USERS, CHAIN_KNOWN);
389405

390406
if (got_authdown_ruleset) {
391-
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%u -j " CHAIN_AUTH_IS_DOWN,
392-
FW_MARK_AUTH_IS_DOWN);
407+
iptables_do_command("-t filter -A " CHAIN_TO_INTERNET " -m mark --mark 0x%x/0x%x -j " CHAIN_AUTH_IS_DOWN,
408+
FW_MARK_AUTH_IS_DOWN << config->markoffsetbits,
409+
FW_MARK_AUTH_IS_DOWN << config->markoffsetbits);
393410
iptables_load_ruleset("filter", FWRULESET_AUTH_IS_DOWN, CHAIN_AUTH_IS_DOWN);
394411
}
395412

@@ -554,20 +571,21 @@ iptables_fw_destroy_mention(const char *table, const char *chain, const char *me
554571
int
555572
iptables_fw_access(fw_access_t type, const char *ip, const char *mac, int tag)
556573
{
574+
const s_config *config = config_get_config ();
557575
int rc;
558576

559577
fw_quiet = 0;
560578

561579
switch (type) {
562580
case FW_ACCESS_ALLOW:
563-
iptables_do_command("-t mangle -A " CHAIN_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip,
564-
mac, tag);
581+
iptables_do_command("-t mangle -A " CHAIN_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark 0x%x", ip,
582+
mac, tag << config->markoffsetbits);
565583
rc = iptables_do_command("-t mangle -A " CHAIN_INCOMING " -d %s -j ACCEPT", ip);
566584
break;
567585
case FW_ACCESS_DENY:
568586
/* XXX Add looping to really clear? */
569-
iptables_do_command("-t mangle -D " CHAIN_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip,
570-
mac, tag);
587+
iptables_do_command("-t mangle -D " CHAIN_OUTGOING " -s %s -m mac --mac-source %s -j MARK --set-mark 0x%x", ip,
588+
mac, tag << config->markoffsetbits);
571589
rc = iptables_do_command("-t mangle -D " CHAIN_INCOMING " -d %s -j ACCEPT", ip);
572590
break;
573591
default:
@@ -606,9 +624,11 @@ iptables_fw_access_host(fw_access_t type, const char *host)
606624
int
607625
iptables_fw_auth_unreachable(int tag)
608626
{
627+
const s_config *config = config_get_config ();
609628
int got_authdown_ruleset = NULL == get_ruleset(FWRULESET_AUTH_IS_DOWN) ? 0 : 1;
610629
if (got_authdown_ruleset)
611-
return iptables_do_command("-t mangle -A " CHAIN_AUTH_IS_DOWN " -j MARK --set-mark 0x%u", tag);
630+
return iptables_do_command("-t mangle -A " CHAIN_AUTH_IS_DOWN " -j MARK --set-mark 0x%x",
631+
tag << config->markoffsetbits);
612632
else
613633
return 1;
614634
}

0 commit comments

Comments
 (0)