net: ignore dup route errors; better handling of gw in bridge

This commit is contained in:
Eugene Yakubovich
2015-02-05 16:48:06 -08:00
parent 6720f2bbf0
commit 68ee69aa42
2 changed files with 13 additions and 13 deletions
+4 -1
View File
@@ -155,7 +155,10 @@ func ApplyIPConfig(ifName string, ipConf *IPConfig) error {
for _, dst := range ipConf.Routes {
if err = util.AddRoute(&dst, ipConf.Gateway, link); err != nil {
return err
// we skip over duplicate routes as we assume the first one wins
if !os.IsExist(err) {
return fmt.Errorf("failed to add route '%v via %v dev %v': %v", dst.String(), ipConf.Gateway, ifName, err)
}
}
}
+9 -12
View File
@@ -34,8 +34,8 @@ const defaultBrName = "rkt0"
type Net struct {
rktnet.Net
BrName string `json:"brName"`
IsGW bool `json:"isGW"`
BrName string `json:"bridgeName"`
IsGW bool `json:"isGateway"`
}
func init() {
@@ -162,19 +162,12 @@ func calcGatewayIP(ipn *net.IPNet) net.IP {
return util.NextIP(nid)
}
func setupBridge(n *Net, ipamConf *ipam.IPConfig) (*netlink.Bridge, error) {
func setupBridge(n *Net, ipConf *ipam.IPConfig) (*netlink.Bridge, error) {
var gwn *net.IPNet
if n.IsGW {
gw := net.IP{}
if ipamConf.Gateway != nil {
gw = ipamConf.Gateway
} else {
gw = calcGatewayIP(ipamConf.IP)
}
gwn = &net.IPNet{
IP: gw,
Mask: ipamConf.IP.Mask,
IP: ipConf.Gateway,
Mask: ipConf.IP.Mask,
}
}
@@ -204,6 +197,10 @@ func cmdAdd(contID, netns, netConf, ifName string) error {
return err
}
if ipConf.Gateway == nil && n.IsGW {
ipConf.Gateway = calcGatewayIP(ipConf.IP)
}
br, err := setupBridge(n, ipConf)
if err != nil {
return err