Skip to content

Commit b58270d

Browse files
committed
fix gateway request error
1 parent 8484094 commit b58270d

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package vxrouter
22

33
// usefule constants for the whole project
44
const (
5-
Version = "0.0.3"
5+
Version = "0.0.4"
66
EnvPrefix = "VXR_"
77
NetworkDriver = "vxrNet"
88
IpamDriver = "vxrIpam"

docker/core/functions.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package core
22

33
import (
44
"fmt"
5+
"net"
56
"os"
67
"strconv"
78
"strings"
@@ -36,5 +37,18 @@ func getEnvIntWithDefault(val, opt string, def int) int { //nolint: unparam
3637
}
3738

3839
func poolFromID(poolid string) string {
39-
return strings.TrimPrefix(poolid, ipamDriverName+"_")
40+
return strings.TrimPrefix(poolid, ipamDriverName+"/")
41+
}
42+
43+
// IPNetFromReqInfo returns an an IPNet from an ipam request
44+
func IPNetFromReqInfo(poolid, reqAddr string) (*net.IPNet, error) {
45+
_, n, err := net.ParseCIDR(poolFromID(poolid))
46+
if err != nil {
47+
return nil, err
48+
}
49+
n.IP = net.ParseIP(reqAddr)
50+
if n.IP == nil {
51+
return nil, fmt.Errorf("invalid requested address")
52+
}
53+
return n, nil
4054
}

docker/ipam/driver.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (d *Driver) RequestPool(r *gphipam.RequestPoolRequest) (*gphipam.RequestPoo
4747
}
4848

4949
rpr := &gphipam.RequestPoolResponse{
50-
PoolID: DriverName + "_" + r.Pool,
50+
PoolID: DriverName + "/" + r.Pool,
5151
Pool: r.Pool,
5252
}
5353

@@ -65,6 +65,18 @@ func (d *Driver) ReleasePool(r *gphipam.ReleasePoolRequest) error {
6565
func (d *Driver) RequestAddress(r *gphipam.RequestAddressRequest) (*gphipam.RequestAddressResponse, error) {
6666
d.log.WithField("r", r).Debug("RequestAddress()")
6767

68+
// Always respond with the gateway address if specified
69+
// This is called on network create, and network create will fail if this returns an error
70+
if r.Options["RequestAddressType"] == "com.docker.network.gateway" && r.Address != "" {
71+
r, err := core.IPNetFromReqInfo(r.PoolID, r.Address)
72+
if err != nil {
73+
return nil, err
74+
}
75+
return &gphipam.RequestAddressResponse{
76+
Address: r.String(),
77+
}, nil
78+
}
79+
6880
addr, err := d.core.ConnectAndGetAddress(r.Address, r.PoolID)
6981
if err != nil {
7082
log.WithField("r.Address", r.Address).WithField("r.PoolID", r.PoolID).Error("failed to get address")

0 commit comments

Comments
 (0)