Skip to content

Commit f521086

Browse files
committed
bug fixes
1 parent 7077d8c commit f521086

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

docker/core/core.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ func (c *Core) Uncache(poolid string) {
117117
c.delNrInCache(pool)
118118
}
119119

120-
func (c *Core) connectIfNotConnected(addr, nrID string) error {
120+
func (c *Core) connectIfNotConnected(addr, nrID string) (bool, error) {
121121
ip := net.ParseIP(addr)
122122
numRoutes, err := host.VxroutesTo(ip)
123123
if err != nil {
124-
return err
124+
return false, err
125125
}
126126
if numRoutes > 0 {
127-
return nil
127+
return false, nil
128128
}
129129
nr, err := c.getNetworkResourceByID(nrID)
130130
if err != nil {
131-
return err
131+
return false, err
132132
}
133133
_, err = c.connectAndGetAddress(ip, nr)
134-
return err
134+
return true, err
135135
}
136136

137137
// ConnectAndGetAddress connects the host to the network for the

docker/core/reconcile.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
log "github.com/Sirupsen/logrus"
55

66
"context"
7+
"net"
78

89
"github.com/TrilliumIT/vxrouter/host"
910
"github.com/docker/docker/api/types"
1011
)
1112

1213
// Reconcile adds missing routes and deletes orphaned routes
1314
func (c *Core) Reconcile() {
14-
log := log.WithField("func", "DelOrphanedRoutes()")
15+
log := log.WithField("func", "Reconcile()")
1516

1617
// This is possibly racy, if a container starts up after containers are listed
1718
// I might delete it's routes
@@ -23,10 +24,14 @@ func (c *Core) Reconcile() {
2324

2425
// Make sure all containers are connected
2526
for ip, subnet := range es {
26-
err = c.connectIfNotConnected(ip, subnet)
27+
var connected bool
28+
connected, err = c.connectIfNotConnected(ip, subnet)
2729
if err != nil {
2830
log.WithError(err).Error("Error connecting container")
2931
}
32+
if connected {
33+
log.WithField("ip", ip).Debug("added missing route")
34+
}
3035
}
3136

3237
// remove errant routes
@@ -37,9 +42,10 @@ func (c *Core) Reconcile() {
3742
}
3843

3944
for _, n := range nets {
40-
if _, ok := es[n.String()]; ok {
45+
if _, ok := es[n.IP.String()]; ok {
4146
continue
4247
}
48+
log.WithField("IP", n.IP.String()).Debug("Deleting orphaned Route")
4349
err = c.deleteRoute(n.IP)
4450
if err != nil {
4551
log.WithError(err).Error("error deleting orphaned route")
@@ -87,10 +93,21 @@ func (c *Core) getContainerIPsAndSubnets() (map[string]string, error) {
8793
if es.IPAMConfig == nil {
8894
continue
8995
}
90-
if es.IPAMConfig.IPv4Address == "" {
91-
continue
96+
// This is necessary because docker is stupid, this could be
97+
// "10.1.141.01" for example
98+
ip := net.ParseIP(es.IPAMConfig.IPv4Address)
99+
if ip != nil {
100+
ret[ip.String()] = es.NetworkID
101+
log.WithField("Container", ctr.Names[0]).WithField("net", es.NetworkID).
102+
WithField("ip", ip.String()).Debug("Appending to es list")
103+
}
104+
105+
ip = net.ParseIP(es.IPAddress)
106+
if ip != nil {
107+
ret[ip.String()] = es.NetworkID
108+
log.WithField("Container", ctr.Names[0]).WithField("net", es.NetworkID).
109+
WithField("ip", ip.String()).Debug("Appending to es list")
92110
}
93-
ret[es.IPAMConfig.IPv4Address] = es.NetworkID
94111
}
95112
}
96113
return ret, nil

docker/vxrnet/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func Run(ctx *cli.Context) {
9292
}
9393

9494
go func(ri time.Duration) {
95+
core.Reconcile()
9596
if ri <= 0 {
9697
return
9798
}

host/functions.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ import (
88
)
99

1010
func getIPNets(address net.IP, subnet *net.IPNet) (*net.IPNet, *net.IPNet) {
11-
var sna, a *net.IPNet
11+
sna := &net.IPNet{
12+
IP: address,
13+
Mask: address.DefaultMask(),
14+
}
1215

1316
//address in big subnet
1417
if subnet != nil {
15-
sna = &net.IPNet{
16-
IP: address,
17-
Mask: subnet.Mask,
18-
}
18+
sna.Mask = subnet.Mask
19+
}
20+
21+
if sna.Mask == nil {
22+
sna.Mask = net.CIDRMask(128, 128)
1923
}
2024

21-
//address as host route (like /32 or /128)
22-
a = &net.IPNet{IP: address}
23-
if a.IP.To4() != nil {
24-
a.Mask = net.CIDRMask(32, 32)
25-
} else {
26-
a.Mask = net.CIDRMask(128, 128)
25+
_, ml := sna.Mask.Size()
26+
a := &net.IPNet{
27+
IP: address,
28+
Mask: net.CIDRMask(ml, ml),
2729
}
2830

2931
return sna, a

host/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (hi *Interface) selectAddress(reqAddress net.IP, propTime time.Duration, xf
286286
return nil, nil
287287
}
288288

289-
log = log.WithField("ip", addrOnly.IP.String())
289+
log = log.WithField("ip", addrOnly.String())
290290

291291
// add host route to routing table
292292
log.Debug("adding route to")

0 commit comments

Comments
 (0)