Skip to content

Commit 176bb6f

Browse files
author
Christian Korber
committed
firewall4: enable mac ranges for rule
nft supports handling mac ranges and therefore this commit changes fw4 to support that feature. The src_mac is now allowed to be a range of two addresses. If no range is given, the old logic is applied. So this is now possible: ``` option src_mac '00:11:AA:00:00:00-00:11:AA:FF:FF:FF' ``` This is done by changing the regex to parse for an additional MAC address if '-' is matched after the first MAC address. Also negation with '!' at the beginning to block every MAC not in the range is possible. Signed-off-by: Christian Korber <ck@dev.tdt.de>
1 parent b6e5157 commit 176bb6f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

root/usr/share/ucode/fw4.uc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,22 @@ return {
11891189

11901190
parse_mac: function(val) {
11911191
let mac = this.parse_invert(val);
1192-
let m = mac ? match(mac.val, /^([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})$/i) : null;
1192+
let m = mac ? match(mac.val, /^([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})(\-?([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2})[:-]([0-9a-f]{1,2}))?$/i) : null;
11931193

11941194
if (!m)
11951195
return null;
11961196

1197-
mac.mac = sprintf('%02x:%02x:%02x:%02x:%02x:%02x',
1197+
if ('-' === m[7]) {
1198+
mac.mac = sprintf('%02x:%02x:%02x:%02x:%02x:%02x-%02x:%02x:%02x:%02x:%02x:%02x',
1199+
hex(m[1]), hex(m[2]), hex(m[3]),
1200+
hex(m[4]), hex(m[5]), hex(m[6]),
1201+
hex(m[8]), hex(m[9]), hex(m[10]),
1202+
hex(m[11]), hex(m[12]), hex(m[13]));
1203+
} else {
1204+
mac.mac = sprintf('%02x:%02x:%02x:%02x:%02x:%02x',
11981205
hex(m[1]), hex(m[2]), hex(m[3]),
11991206
hex(m[4]), hex(m[5]), hex(m[6]));
1207+
}
12001208

12011209
return mac;
12021210
},

0 commit comments

Comments
 (0)