Skip to content

[misc] buf cli proto lint, format and generate #3470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 99 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
f6a71f4
[management] add openapi specs and generate types for port forwarding…
pascal-fischer Jan 27, 2025
26693e4
Feature/port forwarding client ingress (#3242)
pappz Jan 29, 2025
a76ca8c
Merge branch 'main' into feature/port-forwarding
pascal-fischer Jan 29, 2025
6344e34
[management] renamed ingress port endpoints (#3263)
pascal-fischer Jan 31, 2025
829e40d
Fix ingress manager unnecessary creation
pappz Feb 1, 2025
a85ea1d
[manager] ingress ports manager support (#3268)
pascal-fischer Feb 3, 2025
1b011a2
[client] Manage the IP forwarding sysctl setting in global way (#3270)
pappz Feb 3, 2025
9ec6120
[management] Add support for filtering peers by name and IP (#3279)
bcmmbaga Feb 4, 2025
b2a5b29
Merge branch 'main' into feature/port-forwarding
lixmal Feb 5, 2025
035c5d9
[management merge only unique entries on network map merge (#3277)
pascal-fischer Feb 5, 2025
afec455
[management] copy port info (#3283)
pascal-fischer Feb 5, 2025
48675f5
Merge branch 'main' into feature/port-forwarding
lixmal Feb 5, 2025
9930913
Merge branch 'main' into feature/port-forwarding
lixmal Feb 5, 2025
a789e9e
[management] fix duplication detection (#3286)
pascal-fischer Feb 5, 2025
88a864c
[relay] Use new upstream for nhooyr.io/websocket package (#3287)
paralin Feb 5, 2025
206420c
[client] Fix grouping of peer ACLs with different port ranges (#3289)
lixmal Feb 5, 2025
eb69f2d
Fix nil pointer exception when load empty list and try to cast it (#3…
pappz Feb 6, 2025
e6d4653
[management] add cloud tag to get ingress ports api spec (#3300)
pascal-fischer Feb 12, 2025
8755211
Merge branch 'main' into feature/port-forwarding
lixmal Feb 20, 2025
fcc9641
Merge branch 'main' into feature/port-forwarding
lixmal Feb 20, 2025
597f1d4
fix management test suite
pascal-fischer Feb 20, 2025
ea469d2
Merge branch 'main' into feature/port-forwarding
lixmal Feb 20, 2025
630edf2
Remove unused var
lixmal Feb 20, 2025
4ebf141
[management] Add support to allocate same port for public and interna…
bcmmbaga Feb 21, 2025
62b978c
[management] Add support for tcp/udp allocations (#3381)
bcmmbaga Feb 25, 2025
f8fd65a
Merge branch 'main' into feature/port-forwarding
lixmal Feb 25, 2025
81ee172
Fix route conflict
lixmal Feb 25, 2025
fbdfe45
fix merge conflicts on management
pascal-fischer Feb 25, 2025
aa3aa8c
[management] flow proto
pnmcosta Feb 25, 2025
1e534ce
[management] Add flow proto (#3384)
pascal-fischer Feb 25, 2025
1756747
Add memory flow store (#3386)
mlsmaycon Feb 25, 2025
6a77521
rename flow proto messages
pnmcosta Feb 25, 2025
e943203
Add event fields (#3390)
lixmal Feb 26, 2025
eee0d12
[management] add flow settings and credentials (#3389)
pascal-fischer Feb 27, 2025
59e2432
Add event proto fields (#3397)
lixmal Feb 27, 2025
994b923
Move proto and rename port and icmp info (#3399)
lixmal Feb 27, 2025
8276236
Add netflow manager (#3398)
mlsmaycon Feb 27, 2025
6838f53
add getPeerByIp store method
pascal-fischer Feb 27, 2025
f48cfd5
fix logger stop (#3403)
mlsmaycon Feb 28, 2025
2021463
update flow proto package name
mlsmaycon Feb 28, 2025
cccc615
update flow proto package generated code
mlsmaycon Feb 28, 2025
fa748a7
Add userspace flow implementation (#3393)
lixmal Feb 28, 2025
e3ed01c
go mod tidy
bcmmbaga Feb 28, 2025
f6d7bcc
Add flow client with sender/receiver (#3405)
mlsmaycon Feb 28, 2025
c72e13d
Add conntrack flows (#3406)
lixmal Feb 28, 2025
637c0c8
Add icmp type and code (#3409)
lixmal Feb 28, 2025
c138807
remove log message
pascal-fischer Feb 28, 2025
0db65a8
Add routed packet drop flow (#3410)
lixmal Feb 28, 2025
6ead0ff
Fix log format
lixmal Feb 28, 2025
aa613ab
Update golang.org/x/crypto/ssh
bcmmbaga Feb 28, 2025
7e69589
Update management-integrations
bcmmbaga Feb 28, 2025
36e3641
Fix forwarder log displaying (#3411)
lixmal Feb 28, 2025
d19c26d
Fix log direction (#3412)
lixmal Feb 28, 2025
96d5190
Add icmp type and code to forwarder flow event (#3413)
lixmal Feb 28, 2025
1e10c17
Fix tcp state (#3431)
lixmal Mar 4, 2025
c4945cd
add cleanup scheduler + metrics
pascal-fischer Mar 4, 2025
9a713a0
Merge branch 'feature/port-forwarding' into feature/flow
mlsmaycon Mar 4, 2025
619c549
sync port forwarding
mlsmaycon Mar 4, 2025
8c81a82
Add flow ACL IDs (#3421)
lixmal Mar 4, 2025
acf172b
Add kernel conntrack counters (#3434)
lixmal Mar 4, 2025
2d4fcaf
Fix proto numbering (#3436)
lixmal Mar 4, 2025
419ed27
Handle TCP RST flag to transition connection state to closed (#3432)
hakansa Mar 5, 2025
e9f11fb
Replace net.IP with netip.Addr (#3425)
lixmal Mar 5, 2025
0a042ac
Fix merge conflict
lixmal Mar 5, 2025
b180edb
Track icmp with id only (#3447)
lixmal Mar 6, 2025
5ff77b3
Add flow userspace counters (#3438)
lixmal Mar 6, 2025
3c3a454
Fix merge regression
lixmal Mar 6, 2025
54be772
Handle flow updates (#3455)
lixmal Mar 7, 2025
8b07f21
Don't track intercepted packets (#3448)
lixmal Mar 7, 2025
e8d8bd8
Add peer traffic rule IDs to allowed connections in flows (#3442)
lixmal Mar 7, 2025
cb16d0f
Align packet tracer behavior with actual code paths (#3424)
lixmal Mar 7, 2025
86370a0
Use bytes for flows event id (#3439)
lixmal Mar 7, 2025
36da464
Fix tracer test
lixmal Mar 7, 2025
fd62665
Merge branch 'main' into feature/flow
mlsmaycon Mar 9, 2025
3482852
sync proto and sum
mlsmaycon Mar 9, 2025
036cecb
update integrations and go mod
mlsmaycon Mar 9, 2025
16fffdb
sync changes from #3426
mlsmaycon Mar 9, 2025
a2962b4
sync go.sum
mlsmaycon Mar 9, 2025
8430139
fix missing method
mlsmaycon Mar 9, 2025
d8bcf74
update integrations
mlsmaycon Mar 9, 2025
cc8f6bc
[management] Fix tests circular dependency (#3460)
bcmmbaga Mar 10, 2025
47dcf8d
Fix forwarder IP source/destination (#3463)
lixmal Mar 10, 2025
0c2a3dd
Merge branch 'main' into feature/flow
lixmal Mar 10, 2025
11828a0
Fix conflict
lixmal Mar 10, 2025
76d7354
Fix more conflicts
lixmal Mar 10, 2025
18871b5
Merge branch 'main' into feature/flow
bcmmbaga Mar 11, 2025
78b86e0
[management] fix force-push to feature/flow branch (#3500)
hakansa Mar 13, 2025
64f27ae
[client] add resource id fields to netflow events (#3445)
hakansa Mar 14, 2025
17ff313
[management] Export resource constants (#3508)
pascal-fischer Mar 14, 2025
1a87f6e
[management] Flow settings (#3509)
pascal-fischer Mar 14, 2025
fe16a16
remove log from store
pascal-fischer Mar 14, 2025
671e77c
Fix squashed policy ID (#3512)
lixmal Mar 14, 2025
0051fac
Merge branch 'main' into feature/flow
mlsmaycon Mar 15, 2025
4ee8b66
[client] refactor: optimize forwarder initialization checks in packet…
hakansa Mar 17, 2025
7f17cd3
Merge branch 'main' into feature/flow
hakansa Mar 17, 2025
2e3fde4
remove log from getPeerByID
pascal-fischer Mar 17, 2025
40d932e
[management] peer update on extra settings change (#3513)
pascal-fischer Mar 17, 2025
f88b93e
[client] Add DNS and Exit Node collection configuration to Netflow (#…
hakansa Mar 17, 2025
3bf0025
[misc] buf cli proto lint, format and gen
pnmcosta Mar 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# For details on buf.gen.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-gen-yaml/
version: v2
plugins:
- remote: buf.build/protocolbuffers/go:v1.35.1
out: .
- remote: buf.build/grpc/go:v1.5.1
out: .
10 changes: 10 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
modules:
- path: proto
lint:
use:
- BASIC
breaking:
use:
- FILE
4 changes: 2 additions & 2 deletions client/cmd/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ func startManagement(t *testing.T, config *mgmt.Config, testFile string) (*grpc.
metrics, err := telemetry.NewDefaultAppMetrics(context.Background())
require.NoError(t, err)

accountManager, err := mgmt.BuildManager(context.Background(), store, peersUpdateManager, nil, "", "netbird.selfhosted", eventStore, nil, false, iv, metrics, port_forwarding.NewControllerMock())
accountManager, err := mgmt.BuildManager(context.Background(), store, peersUpdateManager, nil, "", "netbird.selfhosted", eventStore, nil, false, iv, metrics, port_forwarding.NewControllerMock(), settings.NewManagerMock())
if err != nil {
t.Fatal(err)
}

secretsManager := mgmt.NewTimeBasedAuthSecretsManager(peersUpdateManager, config.TURNConfig, config.Relay)
mgmtServer, err := mgmt.NewServer(context.Background(), config, accountManager, settings.NewManager(store), peersUpdateManager, secretsManager, nil, nil, nil)
mgmtServer, err := mgmt.NewServer(context.Background(), config, accountManager, settings.NewManagerMock(), peersUpdateManager, secretsManager, nil, nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions client/firewall/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import (

firewall "github.com/netbirdio/netbird/client/firewall/manager"
"github.com/netbirdio/netbird/client/firewall/uspfilter"
nftypes "github.com/netbirdio/netbird/client/internal/netflow/types"
"github.com/netbirdio/netbird/client/internal/statemanager"
)

// NewFirewall creates a firewall manager instance
func NewFirewall(iface IFaceMapper, _ *statemanager.Manager, disableServerRoutes bool) (firewall.Manager, error) {
func NewFirewall(iface IFaceMapper, _ *statemanager.Manager, flowLogger nftypes.FlowLogger, disableServerRoutes bool) (firewall.Manager, error) {
if !iface.IsUserspaceBind() {
return nil, fmt.Errorf("not implemented for this OS: %s", runtime.GOOS)
}

// use userspace packet filtering firewall
fm, err := uspfilter.Create(iface, disableServerRoutes)
fm, err := uspfilter.Create(iface, disableServerRoutes, flowLogger)
if err != nil {
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions client/firewall/create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
firewall "github.com/netbirdio/netbird/client/firewall/manager"
nbnftables "github.com/netbirdio/netbird/client/firewall/nftables"
"github.com/netbirdio/netbird/client/firewall/uspfilter"
nftypes "github.com/netbirdio/netbird/client/internal/netflow/types"
"github.com/netbirdio/netbird/client/internal/statemanager"
)

Expand All @@ -33,7 +34,7 @@ const SKIP_NFTABLES_ENV = "NB_SKIP_NFTABLES_CHECK"
// FWType is the type for the firewall type
type FWType int

func NewFirewall(iface IFaceMapper, stateManager *statemanager.Manager, disableServerRoutes bool) (firewall.Manager, error) {
func NewFirewall(iface IFaceMapper, stateManager *statemanager.Manager, flowLogger nftypes.FlowLogger, disableServerRoutes bool) (firewall.Manager, error) {
// on the linux system we try to user nftables or iptables
// in any case, because we need to allow netbird interface traffic
// so we use AllowNetbird traffic from these firewall managers
Expand All @@ -47,7 +48,7 @@ func NewFirewall(iface IFaceMapper, stateManager *statemanager.Manager, disableS
if err != nil {
log.Warnf("failed to create native firewall: %v. Proceeding with userspace", err)
}
return createUserspaceFirewall(iface, fm, disableServerRoutes)
return createUserspaceFirewall(iface, fm, disableServerRoutes, flowLogger)
}

func createNativeFirewall(iface IFaceMapper, stateManager *statemanager.Manager, routes bool) (firewall.Manager, error) {
Expand Down Expand Up @@ -77,12 +78,12 @@ func createFW(iface IFaceMapper) (firewall.Manager, error) {
}
}

func createUserspaceFirewall(iface IFaceMapper, fm firewall.Manager, disableServerRoutes bool) (firewall.Manager, error) {
func createUserspaceFirewall(iface IFaceMapper, fm firewall.Manager, disableServerRoutes bool, flowLogger nftypes.FlowLogger) (firewall.Manager, error) {
var errUsp error
if fm != nil {
fm, errUsp = uspfilter.CreateWithNativeFirewall(iface, fm, disableServerRoutes)
fm, errUsp = uspfilter.CreateWithNativeFirewall(iface, fm, disableServerRoutes, flowLogger)
} else {
fm, errUsp = uspfilter.Create(iface, disableServerRoutes)
fm, errUsp = uspfilter.Create(iface, disableServerRoutes, flowLogger)
}

if errUsp != nil {
Expand Down
1 change: 1 addition & 0 deletions client/firewall/iptables/acl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (m *aclManager) init(stateManager *statemanager.Manager) error {
}

func (m *aclManager) AddPeerFiltering(
id []byte,
ip net.IP,
protocol firewall.Protocol,
sPort *firewall.Port,
Expand Down
11 changes: 6 additions & 5 deletions client/firewall/iptables/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,22 @@ func (m *Manager) Init(stateManager *statemanager.Manager) error {
//
// Comment will be ignored because some system this feature is not supported
func (m *Manager) AddPeerFiltering(
id []byte,
ip net.IP,
protocol firewall.Protocol,
proto firewall.Protocol,
sPort *firewall.Port,
dPort *firewall.Port,
action firewall.Action,
ipsetName string,
_ string,
) ([]firewall.Rule, error) {
m.mutex.Lock()
defer m.mutex.Unlock()

return m.aclMgr.AddPeerFiltering(ip, protocol, sPort, dPort, action, ipsetName)
return m.aclMgr.AddPeerFiltering(id, ip, proto, sPort, dPort, action, ipsetName)
}

func (m *Manager) AddRouteFiltering(
id []byte,
sources []netip.Prefix,
destination netip.Prefix,
proto firewall.Protocol,
Expand All @@ -125,7 +126,7 @@ func (m *Manager) AddRouteFiltering(
return nil, fmt.Errorf("unsupported IP version: %s", destination.Addr().String())
}

return m.router.AddRouteFiltering(sources, destination, proto, sPort, dPort, action)
return m.router.AddRouteFiltering(id, sources, destination, proto, sPort, dPort, action)
}

// DeletePeerRule from the firewall by rule definition
Expand Down Expand Up @@ -196,13 +197,13 @@ func (m *Manager) AllowNetbird() error {
}

_, err := m.AddPeerFiltering(
nil,
net.IP{0, 0, 0, 0},
"all",
nil,
nil,
firewall.ActionAccept,
"",
"",
)
if err != nil {
return fmt.Errorf("allow netbird interface traffic: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions client/firewall/iptables/manager_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestIptablesManager(t *testing.T) {
IsRange: true,
Values: []uint16{8043, 8046},
}
rule2, err = manager.AddPeerFiltering(ip, "tcp", port, nil, fw.ActionAccept, "", "accept HTTPS traffic from ports range")
rule2, err = manager.AddPeerFiltering(nil, ip, "tcp", port, nil, fw.ActionAccept, "")
require.NoError(t, err, "failed to add rule")

for _, r := range rule2 {
Expand All @@ -97,7 +97,7 @@ func TestIptablesManager(t *testing.T) {
// add second rule
ip := net.ParseIP("10.20.0.3")
port := &fw.Port{Values: []uint16{5353}}
_, err = manager.AddPeerFiltering(ip, "udp", nil, port, fw.ActionAccept, "", "accept Fake DNS traffic")
_, err = manager.AddPeerFiltering(nil, ip, "udp", nil, port, fw.ActionAccept, "")
require.NoError(t, err, "failed to add rule")

err = manager.Close(nil)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestIptablesManagerIPSet(t *testing.T) {
port := &fw.Port{
Values: []uint16{443},
}
rule2, err = manager.AddPeerFiltering(ip, "tcp", port, nil, fw.ActionAccept, "default", "accept HTTPS traffic from ports range")
rule2, err = manager.AddPeerFiltering(nil, ip, "tcp", port, nil, fw.ActionAccept, "default")
for _, r := range rule2 {
require.NoError(t, err, "failed to add rule")
require.Equal(t, r.(*Rule).ipsetName, "default-sport", "ipset name must be set")
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestIptablesCreatePerformance(t *testing.T) {
start := time.Now()
for i := 0; i < testMax; i++ {
port := &fw.Port{Values: []uint16{uint16(1000 + i)}}
_, err = manager.AddPeerFiltering(ip, "tcp", nil, port, fw.ActionAccept, "", "accept HTTP traffic")
_, err = manager.AddPeerFiltering(nil, ip, "tcp", nil, port, fw.ActionAccept, "")

require.NoError(t, err, "failed to add rule")
}
Expand Down
5 changes: 3 additions & 2 deletions client/firewall/iptables/router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

nberrors "github.com/netbirdio/netbird/client/errors"
firewall "github.com/netbirdio/netbird/client/firewall/manager"
"github.com/netbirdio/netbird/client/internal/acl/id"
nbid "github.com/netbirdio/netbird/client/internal/acl/id"
"github.com/netbirdio/netbird/client/internal/routemanager/ipfwdstate"
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
"github.com/netbirdio/netbird/client/internal/statemanager"
Expand Down Expand Up @@ -121,14 +121,15 @@ func (r *router) init(stateManager *statemanager.Manager) error {
}

func (r *router) AddRouteFiltering(
id []byte,
sources []netip.Prefix,
destination netip.Prefix,
proto firewall.Protocol,
sPort *firewall.Port,
dPort *firewall.Port,
action firewall.Action,
) (firewall.Rule, error) {
ruleKey := id.GenerateRouteRuleKey(sources, destination, proto, sPort, dPort, action)
ruleKey := nbid.GenerateRouteRuleKey(sources, destination, proto, sPort, dPort, action)
if _, ok := r.rules[string(ruleKey)]; ok {
return ruleKey, nil
}
Expand Down
2 changes: 1 addition & 1 deletion client/firewall/iptables/router_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestRouter_AddRouteFiltering(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ruleKey, err := r.AddRouteFiltering(tt.sources, tt.destination, tt.proto, tt.sPort, tt.dPort, tt.action)
ruleKey, err := r.AddRouteFiltering(nil, tt.sources, tt.destination, tt.proto, tt.sPort, tt.dPort, tt.action)
require.NoError(t, err, "AddRouteFiltering failed")

// Check if the rule is in the internal map
Expand Down
12 changes: 10 additions & 2 deletions client/firewall/manager/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ type Manager interface {
// If comment argument is empty firewall manager should set
// rule ID as comment for the rule
AddPeerFiltering(
id []byte,
ip net.IP,
proto Protocol,
sPort *Port,
dPort *Port,
action Action,
ipsetName string,
comment string,
) ([]Rule, error)

// DeletePeerRule from the firewall by rule definition
Expand All @@ -80,7 +80,15 @@ type Manager interface {
// IsServerRouteSupported returns true if the firewall supports server side routing operations
IsServerRouteSupported() bool

AddRouteFiltering(source []netip.Prefix, destination netip.Prefix, proto Protocol, sPort *Port, dPort *Port, action Action) (Rule, error)
AddRouteFiltering(
id []byte,
sources []netip.Prefix,
destination netip.Prefix,
proto Protocol,
sPort *Port,
dPort *Port,
action Action,
) (Rule, error)

// DeleteRouteRule deletes a routing rule
DeleteRouteRule(rule Rule) error
Expand Down
7 changes: 3 additions & 4 deletions client/firewall/nftables/acl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (m *AclManager) init(workTable *nftables.Table) error {
// If comment argument is empty firewall manager should set
// rule ID as comment for the rule
func (m *AclManager) AddPeerFiltering(
id []byte,
ip net.IP,
proto firewall.Protocol,
sPort *firewall.Port,
dPort *firewall.Port,
action firewall.Action,
ipsetName string,
comment string,
) ([]firewall.Rule, error) {
var ipset *nftables.Set
if ipsetName != "" {
Expand All @@ -102,7 +102,7 @@ func (m *AclManager) AddPeerFiltering(
}

newRules := make([]firewall.Rule, 0, 2)
ioRule, err := m.addIOFiltering(ip, proto, sPort, dPort, action, ipset, comment)
ioRule, err := m.addIOFiltering(ip, proto, sPort, dPort, action, ipset)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -256,7 +256,6 @@ func (m *AclManager) addIOFiltering(
dPort *firewall.Port,
action firewall.Action,
ipset *nftables.Set,
comment string,
) (*Rule, error) {
ruleId := generatePeerRuleId(ip, sPort, dPort, action, ipset)
if r, ok := m.rules[ruleId]; ok {
Expand Down Expand Up @@ -338,7 +337,7 @@ func (m *AclManager) addIOFiltering(
mainExpressions = append(mainExpressions, &expr.Verdict{Kind: expr.VerdictDrop})
}

userData := []byte(strings.Join([]string{ruleId, comment}, " "))
userData := []byte(ruleId)

chain := m.chainInputRules
nftRule := m.rConn.AddRule(&nftables.Rule{
Expand Down
7 changes: 4 additions & 3 deletions client/firewall/nftables/manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ func (m *Manager) Init(stateManager *statemanager.Manager) error {
// If comment argument is empty firewall manager should set
// rule ID as comment for the rule
func (m *Manager) AddPeerFiltering(
id []byte,
ip net.IP,
proto firewall.Protocol,
sPort *firewall.Port,
dPort *firewall.Port,
action firewall.Action,
ipsetName string,
comment string,
) ([]firewall.Rule, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
Expand All @@ -129,10 +129,11 @@ func (m *Manager) AddPeerFiltering(
return nil, fmt.Errorf("unsupported IP version: %s", ip.String())
}

return m.aclManager.AddPeerFiltering(ip, proto, sPort, dPort, action, ipsetName, comment)
return m.aclManager.AddPeerFiltering(id, ip, proto, sPort, dPort, action, ipsetName)
}

func (m *Manager) AddRouteFiltering(
id []byte,
sources []netip.Prefix,
destination netip.Prefix,
proto firewall.Protocol,
Expand All @@ -147,7 +148,7 @@ func (m *Manager) AddRouteFiltering(
return nil, fmt.Errorf("unsupported IP version: %s", destination.Addr().String())
}

return m.router.AddRouteFiltering(sources, destination, proto, sPort, dPort, action)
return m.router.AddRouteFiltering(id, sources, destination, proto, sPort, dPort, action)
}

// DeletePeerRule from the firewall by rule definition
Expand Down
7 changes: 4 additions & 3 deletions client/firewall/nftables/manager_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNftablesManager(t *testing.T) {

testClient := &nftables.Conn{}

rule, err := manager.AddPeerFiltering(ip, fw.ProtocolTCP, nil, &fw.Port{Values: []uint16{53}}, fw.ActionDrop, "", "")
rule, err := manager.AddPeerFiltering(nil, ip, fw.ProtocolTCP, nil, &fw.Port{Values: []uint16{53}}, fw.ActionDrop, "")
require.NoError(t, err, "failed to add rule")

err = manager.Flush()
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestNFtablesCreatePerformance(t *testing.T) {
start := time.Now()
for i := 0; i < testMax; i++ {
port := &fw.Port{Values: []uint16{uint16(1000 + i)}}
_, err = manager.AddPeerFiltering(ip, "tcp", nil, port, fw.ActionAccept, "", "accept HTTP traffic")
_, err = manager.AddPeerFiltering(nil, ip, "tcp", nil, port, fw.ActionAccept, "")
require.NoError(t, err, "failed to add rule")

if i%100 == 0 {
Expand Down Expand Up @@ -283,10 +283,11 @@ func TestNftablesManagerCompatibilityWithIptables(t *testing.T) {
})

ip := net.ParseIP("100.96.0.1")
_, err = manager.AddPeerFiltering(ip, fw.ProtocolTCP, nil, &fw.Port{Values: []uint16{80}}, fw.ActionAccept, "", "test rule")
_, err = manager.AddPeerFiltering(nil, ip, fw.ProtocolTCP, nil, &fw.Port{Values: []uint16{80}}, fw.ActionAccept, "")
require.NoError(t, err, "failed to add peer filtering rule")

_, err = manager.AddRouteFiltering(
nil,
[]netip.Prefix{netip.MustParsePrefix("192.168.2.0/24")},
netip.MustParsePrefix("10.1.0.0/24"),
fw.ProtocolTCP,
Expand Down
5 changes: 3 additions & 2 deletions client/firewall/nftables/router_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

nberrors "github.com/netbirdio/netbird/client/errors"
firewall "github.com/netbirdio/netbird/client/firewall/manager"
"github.com/netbirdio/netbird/client/internal/acl/id"
nbid "github.com/netbirdio/netbird/client/internal/acl/id"
"github.com/netbirdio/netbird/client/internal/routemanager/ipfwdstate"
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
nbnet "github.com/netbirdio/netbird/util/net"
Expand Down Expand Up @@ -228,6 +228,7 @@ func (r *router) createContainers() error {

// AddRouteFiltering appends a nftables rule to the routing chain
func (r *router) AddRouteFiltering(
id []byte,
sources []netip.Prefix,
destination netip.Prefix,
proto firewall.Protocol,
Expand All @@ -236,7 +237,7 @@ func (r *router) AddRouteFiltering(
action firewall.Action,
) (firewall.Rule, error) {

ruleKey := id.GenerateRouteRuleKey(sources, destination, proto, sPort, dPort, action)
ruleKey := nbid.GenerateRouteRuleKey(sources, destination, proto, sPort, dPort, action)
if _, ok := r.rules[string(ruleKey)]; ok {
return ruleKey, nil
}
Expand Down
Loading
Loading