network: firewall integration with NFT sets
New directives `NFTSet=`, `IPv4NFTSet=` and `IPv6NFTSet=` provide a method for
integrating configuration of dynamic networks into firewall rules with NFT
sets.
/etc/systemd/network/eth.network
```
[DHCPv4]
...
NFTSet=netdev:filter:eth_ipv4_address
```
```
table netdev filter {
set eth_ipv4_address {
type ipv4_addr
flags interval
}
chain eth_ingress {
type filter hook ingress device "eth0" priority filter; policy drop;
ip saddr != @eth_ipv4_address drop
accept
}
}
```
```
sudo nft list set netdev filter eth_ipv4_address
table netdev filter {
set eth_ipv4_address {
type ipv4_addr
flags interval
elements = { 10.0.0.0/24 }
}
}
```
This commit is contained in:
committed by
Topi Miettinen
parent
e8f1b50f27
commit
ab51fd9dbd
@@ -750,3 +750,38 @@ int parse_loadavg_fixed_point(const char *s, loadavg_t *ret) {
|
||||
|
||||
return store_loadavg_fixed_point(i, f, ret);
|
||||
}
|
||||
|
||||
static bool nft_first_char_bad(const char c) {
|
||||
if ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool nft_next_char_bad(const char c) {
|
||||
if ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
c == '/' || c == '\\' || c == '_' || c == '.')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Limitations are described in https://www.netfilter.org/projects/nftables/manpage.html and
|
||||
* https://bugzilla.netfilter.org/show_bug.cgi?id=1175 */
|
||||
bool nft_identifier_bad(const char *id) {
|
||||
assert(id);
|
||||
|
||||
size_t len;
|
||||
len = strlen(id);
|
||||
if (len == 0 || len > 31)
|
||||
return true;
|
||||
|
||||
if (nft_first_char_bad(id[0]))
|
||||
return true;
|
||||
|
||||
for (size_t i = 1; i < len; i++)
|
||||
if (nft_next_char_bad(id[i]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user