diff --git a/daemon/libnetwork/internal/nftables/fluentapi_linux.go b/daemon/libnetwork/internal/nftables/fluentapi_linux.go new file mode 100644 index 0000000000..fec8c3ee1c --- /dev/null +++ b/daemon/libnetwork/internal/nftables/fluentapi_linux.go @@ -0,0 +1,30 @@ +package nftables + +type chainBuilder struct { + chain string + tm *Modifier +} + +func (b BaseChain) Builder() chainBuilder { + tm := &Modifier{} + tm.create(b, 1) + return chainBuilder{chain: b.Name, tm: tm} +} + +func (c Chain) Builder() chainBuilder { + tm := &Modifier{} + tm.create(c, 1) + return chainBuilder{chain: c.Name, tm: tm} +} + +func (b chainBuilder) Rule(rule ...string) chainBuilder { + b.tm.create(Rule{ + Chain: b.chain, + Rule: rule, + }, 1) + return b +} + +func (b chainBuilder) Create(tm *Modifier) { + tm.cmds = append(tm.cmds, b.tm.cmds...) +} diff --git a/daemon/libnetwork/internal/nftables/nftables_linux.go b/daemon/libnetwork/internal/nftables/nftables_linux.go index e16cd61739..036123c2b9 100644 --- a/daemon/libnetwork/internal/nftables/nftables_linux.go +++ b/daemon/libnetwork/internal/nftables/nftables_linux.go @@ -490,7 +490,11 @@ type Modifier struct { // Create enqueues creation of object o, to be applied by tm.Apply. func (tm *Modifier) Create(o Obj) { - _, f, l, _ := runtime.Caller(1) + tm.create(o, 1) +} + +func (tm *Modifier) create(o Obj, skipFrames int) { + _, f, l, _ := runtime.Caller(skipFrames + 1) tm.cmds = append(tm.cmds, command{ obj: o, callerFile: f,