Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -102,13 +102,13 @@ func (n *bridgeNetwork) mapPorts(ctx context.Context, pms *drvregistry.PortMappe |
| 102 | 102 |
return nil, err |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 |
- bindings, err := pm.MapPorts(ctx, reqs, n.firewallerNetwork) |
|
| 105 |
+ bindings, err := pm.MapPorts(ctx, reqs) |
|
| 106 | 106 |
if err != nil {
|
| 107 | 107 |
return nil, err |
| 108 | 108 |
} |
| 109 | 109 |
defer func() {
|
| 110 | 110 |
if retErr != nil {
|
| 111 |
- if err := pm.UnmapPorts(ctx, bindings, n.firewallerNetwork); err != nil {
|
|
| 111 |
+ if err := pm.UnmapPorts(ctx, bindings); err != nil {
|
|
| 112 | 112 |
log.G(ctx).WithFields(log.Fields{
|
| 113 | 113 |
"bindings": bindings, |
| 114 | 114 |
"error": err, |
| ... | ... |
@@ -413,7 +413,7 @@ func (n *bridgeNetwork) unmapPBs(ctx context.Context, bindings []portmapperapi.P |
| 413 | 413 |
continue |
| 414 | 414 |
} |
| 415 | 415 |
|
| 416 |
- if err := pm.UnmapPorts(ctx, []portmapperapi.PortBinding{b}, n.firewallerNetwork); err != nil {
|
|
| 416 |
+ if err := pm.UnmapPorts(ctx, []portmapperapi.PortBinding{b}); err != nil {
|
|
| 417 | 417 |
errs = append(errs, fmt.Errorf("unmapping port binding %s: %w", b.PortBinding, err))
|
| 418 | 418 |
} |
| 419 | 419 |
if b.StopProxy != nil {
|
| ... | ... |
@@ -990,7 +990,7 @@ type stubPortMapper struct {
|
| 990 | 990 |
mapped []portmapperapi.PortBinding |
| 991 | 991 |
} |
| 992 | 992 |
|
| 993 |
-func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortBindingReq, _ portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
|
| 993 |
+func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
|
| 994 | 994 |
if len(reqs) == 0 {
|
| 995 | 995 |
return []portmapperapi.PortBinding{}, nil
|
| 996 | 996 |
} |
| ... | ... |
@@ -1002,7 +1002,7 @@ func (pm *stubPortMapper) MapPorts(_ context.Context, reqs []portmapperapi.PortB |
| 1002 | 1002 |
return pbs, nil |
| 1003 | 1003 |
} |
| 1004 | 1004 |
|
| 1005 |
-func (pm *stubPortMapper) UnmapPorts(_ context.Context, reqs []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
|
| 1005 |
+func (pm *stubPortMapper) UnmapPorts(_ context.Context, reqs []portmapperapi.PortBinding) error {
|
|
| 1006 | 1006 |
for _, req := range reqs {
|
| 1007 | 1007 |
// We're only checking for the PortBinding here, not any other |
| 1008 | 1008 |
// property of [portmapperapi.PortBinding]. |
| ... | ... |
@@ -10,11 +10,11 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
type fakePortMapper struct{}
|
| 12 | 12 |
|
| 13 |
-func (f fakePortMapper) MapPorts(_ context.Context, _ []portmapperapi.PortBindingReq, _ portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
|
| 13 |
+func (f fakePortMapper) MapPorts(_ context.Context, _ []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
|
| 14 | 14 |
return nil, nil |
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 |
-func (f fakePortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
|
| 17 |
+func (f fakePortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding) error {
|
|
| 18 | 18 |
return nil |
| 19 | 19 |
} |
| 20 | 20 |
|
| ... | ... |
@@ -29,10 +29,10 @@ type PortMapper interface {
|
| 29 | 29 |
// When an ephemeral port, or a single port from a range is requested |
| 30 | 30 |
// MapPorts should attempt a few times to find a free port available |
| 31 | 31 |
// across all IP addresses. |
| 32 |
- MapPorts(ctx context.Context, reqs []PortBindingReq, fwn Firewaller) ([]PortBinding, error) |
|
| 32 |
+ MapPorts(ctx context.Context, reqs []PortBindingReq) ([]PortBinding, error) |
|
| 33 | 33 |
|
| 34 | 34 |
// UnmapPorts takes a list of port bindings to unmap. |
| 35 |
- UnmapPorts(ctx context.Context, pbs []PortBinding, fwn Firewaller) error |
|
| 35 |
+ UnmapPorts(ctx context.Context, pbs []PortBinding) error |
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
type PortBindingReq struct {
|
| 39 | 39 |
deleted file mode 100644 |
| ... | ... |
@@ -1,14 +0,0 @@ |
| 1 |
-package portmapperapi |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "context" |
|
| 5 |
- |
|
| 6 |
- "github.com/moby/moby/v2/daemon/libnetwork/types" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-type Firewaller interface {
|
|
| 10 |
- // AddPorts adds the configuration needed for NATing ports. |
|
| 11 |
- AddPorts(ctx context.Context, pbs []types.PortBinding) error |
|
| 12 |
- // DelPorts deletes the configuration needed for NATing ports. |
|
| 13 |
- DelPorts(ctx context.Context, pbs []types.PortBinding) error |
|
| 14 |
-} |
| ... | ... |
@@ -47,7 +47,7 @@ func NewPortMapper(cfg Config) PortMapper {
|
| 47 | 47 |
// MapPorts allocates and binds host ports for the given cfg. The caller is |
| 48 | 48 |
// responsible for ensuring that all entries in cfg have the same proto, |
| 49 | 49 |
// container port, and host port range (their host addresses must differ). |
| 50 |
-func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindingReq, fwn portmapperapi.Firewaller) (_ []portmapperapi.PortBinding, retErr error) {
|
|
| 50 |
+func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindingReq) (_ []portmapperapi.PortBinding, retErr error) {
|
|
| 51 | 51 |
if len(cfg) == 0 {
|
| 52 | 52 |
return nil, nil |
| 53 | 53 |
} |
| ... | ... |
@@ -64,7 +64,7 @@ func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindi |
| 64 | 64 |
bindings := make([]portmapperapi.PortBinding, 0, len(cfg)) |
| 65 | 65 |
defer func() {
|
| 66 | 66 |
if retErr != nil {
|
| 67 |
- if err := pm.UnmapPorts(ctx, bindings, fwn); err != nil {
|
|
| 67 |
+ if err := pm.UnmapPorts(ctx, bindings); err != nil {
|
|
| 68 | 68 |
log.G(ctx).WithFields(log.Fields{
|
| 69 | 69 |
"pbs": bindings, |
| 70 | 70 |
"error": err, |
| ... | ... |
@@ -107,7 +107,7 @@ func (pm PortMapper) MapPorts(ctx context.Context, cfg []portmapperapi.PortBindi |
| 107 | 107 |
return bindings, nil |
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 |
-func (pm PortMapper) UnmapPorts(ctx context.Context, pbs []portmapperapi.PortBinding, fwn portmapperapi.Firewaller) error {
|
|
| 110 |
+func (pm PortMapper) UnmapPorts(ctx context.Context, pbs []portmapperapi.PortBinding) error {
|
|
| 111 | 111 |
var errs []error |
| 112 | 112 |
for _, pb := range pbs {
|
| 113 | 113 |
if pb.BoundSocket != nil {
|
| ... | ... |
@@ -30,7 +30,7 @@ func TestBindHostPortsError(t *testing.T) {
|
| 30 | 30 |
}, |
| 31 | 31 |
} |
| 32 | 32 |
pm := &PortMapper{}
|
| 33 |
- pbs, err := pm.MapPorts(context.Background(), cfg, nil) |
|
| 33 |
+ pbs, err := pm.MapPorts(context.Background(), cfg) |
|
| 34 | 34 |
assert.Check(t, is.Error(err, "port binding mismatch 80/tcp:8080-8080, 80/tcp:8080-8081")) |
| 35 | 35 |
assert.Check(t, is.Nil(pbs)) |
| 36 | 36 |
} |
| ... | ... |
@@ -22,7 +22,7 @@ func NewPortMapper() PortMapper {
|
| 22 | 22 |
|
| 23 | 23 |
// MapPorts returns a PortBinding for every PortBindingReq received, with Forwarding enabled for each. If a HostPort is |
| 24 | 24 |
// specified, it's logged and ignored. |
| 25 |
-func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBindingReq, fwn portmapperapi.Firewaller) ([]portmapperapi.PortBinding, error) {
|
|
| 25 |
+func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBindingReq) ([]portmapperapi.PortBinding, error) {
|
|
| 26 | 26 |
if len(reqs) == 0 {
|
| 27 | 27 |
return nil, nil |
| 28 | 28 |
} |
| ... | ... |
@@ -45,6 +45,6 @@ func (pm PortMapper) MapPorts(ctx context.Context, reqs []portmapperapi.PortBind |
| 45 | 45 |
return res, nil |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 |
-func (pm PortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding, _ portmapperapi.Firewaller) error {
|
|
| 48 |
+func (pm PortMapper) UnmapPorts(_ context.Context, _ []portmapperapi.PortBinding) error {
|
|
| 49 | 49 |
return nil |
| 50 | 50 |
} |