diff --git a/drivers/ipvlan/ipvlan.go b/drivers/ipvlan/ipvlan.go index de2c20f59c..efc91ac776 100644 --- a/drivers/ipvlan/ipvlan.go +++ b/drivers/ipvlan/ipvlan.go @@ -14,15 +14,16 @@ const ( vethLen = 7 containerVethPrefix = "eth" vethPrefix = "veth" - ipvlanType = "ipvlan" // driver type name - modeL2 = "l2" // ipvlan mode l2 is the default - modeL3 = "l3" // ipvlan L3 mode - parentOpt = "parent" // parent interface -o parent - modeOpt = "_mode" // ipvlan mode ux opt suffix - bgpNeighborOpt = "bgp-neighbor" // BGP neighbor address - vrfOpt = "vrf" // BGP vrf ID - asOpt = "asnum" // BGP AS number default 65000 - remoteAsOpt = "rasnum" // BGP remote AS number dafault 65000 + ipvlanType = "ipvlan" // driver type name + modeL2 = "l2" // ipvlan mode l2 is the default + modeL3 = "l3" // ipvlan L3 mode + parentOpt = "parent" // parent interface -o parent + modeOpt = "_mode" // ipvlan mode ux opt suffix + bgpNeighborOpt = "bgp-neighbor" // BGP neighbor address + vrfOpt = "vrf" // BGP vrf ID + asOpt = "asnum" // BGP AS number default 65000 + remoteAsOpt = "rasnum" // BGP remote AS number dafault 65000 + subnetAdvertise = "subnet-advertise" // Advertise IP Subnet with BGP ) var driverModeOpt = ipvlanType + modeOpt // mode -o ipvlan_mode diff --git a/drivers/ipvlan/ipvlan_joinleave.go b/drivers/ipvlan/ipvlan_joinleave.go index 73cef17c81..09fc21102b 100644 --- a/drivers/ipvlan/ipvlan_joinleave.go +++ b/drivers/ipvlan/ipvlan_joinleave.go @@ -59,11 +59,13 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, if err := jinfo.AddStaticRoute(defaultRoute.Destination, defaultRoute.RouteType, defaultRoute.NextHop); err != nil { return fmt.Errorf("failed to set an ipvlan l3 mode ipv4 default gateway: %v", err) } - //Advertise container route as /32 route - advIP := &net.IPNet{IP: ep.addr.IP, Mask: net.IPv4Mask(255, 255, 255, 255)} - err = routemanager.AdvertiseNewRoute(advIP.String(), n.config.VrfID) - if err != nil { - return err + if n.config.SubnetAdvertise == "" { + //Advertise container route as /32 route + advIP := &net.IPNet{IP: ep.addr.IP, Mask: net.IPv4Mask(255, 255, 255, 255)} + err = routemanager.AdvertiseNewRoute(advIP.String(), n.config.VrfID) + if err != nil { + return err + } } logrus.Debugf("Ipvlan Endpoint Joined with IPv4_Addr: %s, Ipvlan_Mode: %s, Parent: %s", @@ -137,7 +139,7 @@ func (d *driver) Leave(nid, eid string) error { if err != nil { return err } - if network.config.IpvlanMode == modeL3 { + if network.config.IpvlanMode == modeL3 && network.config.SubnetAdvertise == "" { //Withdraw container route as /32 route witdIP := &net.IPNet{IP: endpoint.addr.IP, Mask: net.IPv4Mask(255, 255, 255, 255)} err = routemanager.WithdrawRoute(witdIP.String(), network.config.VrfID) diff --git a/drivers/ipvlan/ipvlan_network.go b/drivers/ipvlan/ipvlan_network.go index 582826eee6..ade6a75e20 100644 --- a/drivers/ipvlan/ipvlan_network.go +++ b/drivers/ipvlan/ipvlan_network.go @@ -120,11 +120,27 @@ func (d *driver) createNetwork(config *configuration) error { } err := routemanager.CreateVrfNetwork(config.Parent, config.VrfID) + if err != nil { + return err + } if config.BgpNeighbor != "" { routemanager.DiscoverNew(false, config.BgpNeighbor) } - if err != nil { - return err + if config.SubnetAdvertise != "" { + if config.Ipv4Subnets != nil { + for _, subnet := range config.Ipv4Subnets { + err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VrfID) + if err != nil { + return err + } + } + for _, subnet := range config.Ipv6Subnets { + err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VrfID) + if err != nil { + return err + } + } + } } } // add the *network @@ -161,6 +177,23 @@ func (d *driver) DeleteNetwork(nid string) error { } } } + if n.config.SubnetAdvertise != "" { + //Advertise container network subnet + if n.config.Ipv4Subnets != nil { + for _, subnet := range n.config.Ipv4Subnets { + err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VrfID) + if err != nil { + return err + } + } + for _, subnet := range n.config.Ipv6Subnets { + err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VrfID) + if err != nil { + return err + } + } + } + } // delete the *network d.deleteNetwork(nid) // delete the network record from persistent cache @@ -242,6 +275,9 @@ func (config *configuration) fromOptions(labels map[string]string) error { case remoteAsOpt: // parse driver options '-o rasnum' config.RemoteASnum = value + case subnetAdvertise: + // set driver options '-o subnet-advertise' + config.SubnetAdvertise = "True" } } return nil diff --git a/drivers/ipvlan/ipvlan_store.go b/drivers/ipvlan/ipvlan_store.go index f0bbd4e084..43e00e3c25 100644 --- a/drivers/ipvlan/ipvlan_store.go +++ b/drivers/ipvlan/ipvlan_store.go @@ -30,6 +30,7 @@ type configuration struct { VrfID string ASnum string RemoteASnum string + SubnetAdvertise string } type ipv4Subnet struct {