mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
libnet/pmapi: remove firewaller arg from Map/UnmapPorts
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -102,13 +102,13 @@ func (n *bridgeNetwork) mapPorts(ctx context.Context, pms *drvregistry.PortMappe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bindings, err := pm.MapPorts(ctx, reqs, n.firewallerNetwork)
|
||||
bindings, err := pm.MapPorts(ctx, reqs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := pm.UnmapPorts(ctx, bindings, n.firewallerNetwork); err != nil {
|
||||
if err := pm.UnmapPorts(ctx, bindings); err != nil {
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"bindings": bindings,
|
||||
"error": err,
|
||||
@@ -413,7 +413,7 @@ func (n *bridgeNetwork) unmapPBs(ctx context.Context, bindings []portmapperapi.P
|
||||
continue
|
||||
}
|
||||
|
||||
if err := pm.UnmapPorts(ctx, []portmapperapi.PortBinding{b}, n.firewallerNetwork); err != nil {
|
||||
if err := pm.UnmapPorts(ctx, []portmapperapi.PortBinding{b}); err != nil {
|
||||
errs = append(errs, fmt.Errorf("unmapping port binding %s: %w", b.PortBinding, err))
|
||||
}
|
||||
if b.StopProxy != nil {
|
||||
|
||||
@@ -990,7 +990,7 @@ type stubPortMapper struct {
|
||||
mapped []portmapperapi.PortBinding
|
||||
}
|
||||
|
||||
func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortBindingReq, _ portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
||||
func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
||||
if len(reqs) == 0 {
|
||||
return []portmapperapi.PortBinding{}, nil
|
||||
}
|
||||
@@ -1002,7 +1002,7 @@ func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortB
|
||||
return pbs, nil
|
||||
}
|
||||
|
||||
func (pm *stubPortMapper) UnmapPorts(_ context.Context, reqs []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
||||
func (pm *stubPortMapper) UnmapPorts(_ context.Context, reqs []portmapperapi.PortBinding) error {
|
||||
for _, req := range reqs {
|
||||
// We're only checking for the PortBinding here, not any other
|
||||
// property of [portmapperapi.PortBinding].
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
type fakePortMapper struct{}
|
||||
|
||||
func (f fakePortMapper) MapPorts(_ context.Context, _ []portmapperapi.PortBindingReq, _ portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
||||
func (f fakePortMapper) MapPorts(_ context.Context, _ []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f fakePortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
||||
func (f fakePortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ type PortMapper interface {
|
||||
// When an ephemeral port, or a single port from a range is requested
|
||||
// MapPorts should attempt a few times to find a free port available
|
||||
// across all IP addresses.
|
||||
MapPorts(ctx context.Context, reqs []PortBindingReq, fwn Firewaller) ([]PortBinding, error)
|
||||
MapPorts(ctx context.Context, reqs []PortBindingReq) ([]PortBinding, error)
|
||||
|
||||
// UnmapPorts takes a list of port bindings to unmap.
|
||||
UnmapPorts(ctx context.Context, pbs []PortBinding, fwn Firewaller) error
|
||||
UnmapPorts(ctx context.Context, pbs []PortBinding) error
|
||||
}
|
||||
|
||||
type PortBindingReq struct {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package portmapperapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/moby/v2/daemon/libnetwork/types"
|
||||
)
|
||||
|
||||
type Firewaller interface {
|
||||
// AddPorts adds the configuration needed for NATing ports.
|
||||
AddPorts(ctx context.Context, pbs []types.PortBinding) error
|
||||
// DelPorts deletes the configuration needed for NATing ports.
|
||||
DelPorts(ctx context.Context, pbs []types.PortBinding) error
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func NewPortMapper(cfg Config) PortMapper {
|
||||
// MapPorts allocates and binds host ports for the given cfg. The caller is
|
||||
// responsible for ensuring that all entries in cfg have the same proto,
|
||||
// container port, and host port range (their host addresses must differ).
|
||||
func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindingReq, fwn portmapperapi.Firewaller) (_ []portmapperapi.PortBinding, retErr error) {
|
||||
func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindingReq) (_ []portmapperapi.PortBinding, retErr error) {
|
||||
if len(cfg) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindi
|
||||
bindings := make([]portmapperapi.PortBinding, 0, len(cfg))
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
if err := pm.UnmapPorts(ctx, bindings, fwn); err != nil {
|
||||
if err := pm.UnmapPorts(ctx, bindings); err != nil {
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"pbs": bindings,
|
||||
"error": err,
|
||||
@@ -107,7 +107,7 @@ func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindi
|
||||
return bindings, nil
|
||||
}
|
||||
|
||||
func (pm PortMapper) UnmapPorts(ctx context.Context, pbs []portmapperapi.PortBinding, fwn portmapperapi.Firewaller) error {
|
||||
func (pm PortMapper) UnmapPorts(ctx context.Context, pbs []portmapperapi.PortBinding) error {
|
||||
var errs []error
|
||||
for _, pb := range pbs {
|
||||
if pb.BoundSocket != nil {
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestBindHostPortsError(t *testing.T) {
|
||||
},
|
||||
}
|
||||
pm := &PortMapper{}
|
||||
pbs, err := pm.MapPorts(context.Background(), cfg, nil)
|
||||
pbs, err := pm.MapPorts(context.Background(), cfg)
|
||||
assert.Check(t, is.Error(err, "port binding mismatch 80/tcp:8080-8080, 80/tcp:8080-8081"))
|
||||
assert.Check(t, is.Nil(pbs))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func NewPortMapper() PortMapper {
|
||||
|
||||
// MapPorts returns a PortBinding for every PortBindingReq received, with Forwarding enabled for each. If a HostPort is
|
||||
// specified, it's logged and ignored.
|
||||
func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBindingReq, fwn portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
||||
func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
||||
if len(reqs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -45,6 +45,6 @@ func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBind
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (pm PortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
||||
func (pm PortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user