Skip to content

Commit

Permalink
feat: improve nftables backend
Browse files Browse the repository at this point in the history
Many changes to the nftables backend which will be used in the follow-up
PR with siderolabs#4421.

1. Add support for chain policy: drop/accept.
2. Properly handle match on all IPs in the set (`0.0.0.0/0` like).
3. Implement conntrack state matching.
4. Implement multiple ifname matching in a single rule.
5. Implement anonymous counters.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Nov 29, 2023
1 parent db4e253 commit 9a85217
Show file tree
Hide file tree
Showing 21 changed files with 2,710 additions and 1,169 deletions.
Binary file modified api/api.descriptors
Binary file not shown.
11 changes: 11 additions & 0 deletions api/resource/definitions/enums/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ enum NethelpersBondXmitHashPolicy {
BOND_XMIT_POLICY_ENCAP34 = 4;
}

// NethelpersConntrackState is a conntrack state.
enum NethelpersConntrackState {
NETHELPERS_CONNTRACKSTATE_UNSPECIFIED = 0;
CONNTRACK_STATE_NEW = 8;
CONNTRACK_STATE_RELATED = 4;
CONNTRACK_STATE_ESTABLISHED = 2;
CONNTRACK_STATE_INVALID = 1;
}

// NethelpersDuplex wraps ethtool.Duplex for YAML marshaling.
enum NethelpersDuplex {
HALF = 0;
Expand Down Expand Up @@ -259,8 +268,10 @@ enum NethelpersPrimaryReselect {
// NethelpersProtocol is a inet protocol.
enum NethelpersProtocol {
NETHELPERS_PROTOCOL_UNSPECIFIED = 0;
PROTOCOL_ICMP = 1;
PROTOCOL_TCP = 6;
PROTOCOL_UDP = 17;
PROTOCOL_ICM_PV6 = 58;
}

// NethelpersRouteFlag wraps RTM_F_* constants.
Expand Down
16 changes: 15 additions & 1 deletion api/resource/definitions/network/network.proto
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ message NfTablesChainSpec {
talos.resource.definitions.enums.NethelpersNfTablesChainHook hook = 2;
talos.resource.definitions.enums.NethelpersNfTablesChainPriority priority = 3;
repeated NfTablesRule rules = 4;
talos.resource.definitions.enums.NethelpersNfTablesVerdict policy = 5;
}

// NfTablesClampMSS describes the TCP MSS clamping operation.
Expand All @@ -190,10 +191,15 @@ message NfTablesClampMSS {
fixed32 mtu = 1;
}

// NfTablesConntrackStateMatch describes the match on the connection tracking state.
message NfTablesConntrackStateMatch {
repeated uint32 states = 1;
}

// NfTablesIfNameMatch describes the match on the interface name.
message NfTablesIfNameMatch {
string interface_name = 1;
talos.resource.definitions.enums.NethelpersMatchOperator operator = 2;
repeated string interface_names = 3;
}

// NfTablesLayer4Match describes the match on the transport layer protocol.
Expand All @@ -203,6 +209,11 @@ message NfTablesLayer4Match {
NfTablesPortMatch match_destination_port = 3;
}

// NfTablesLimitMatch describes the match on the packet rate.
message NfTablesLimitMatch {
uint64 packet_rate_per_second = 1;
}

// NfTablesMark encodes packet mark match/update operation.
//
// When used as a match computes the following condition:
Expand Down Expand Up @@ -232,6 +243,9 @@ message NfTablesRule {
NfTablesLayer4Match match_layer4 = 7;
NfTablesIfNameMatch match_i_if_name = 8;
NfTablesClampMSS clamp_mss = 9;
NfTablesLimitMatch match_limit = 10;
NfTablesConntrackStateMatch match_conntrack_state = 11;
bool anon_counter = 12;
}

// NodeAddressFilterSpec describes a filter for NodeAddresses.
Expand Down
Loading

0 comments on commit 9a85217

Please sign in to comment.