Skip to content

Commit

Permalink
Add option "-o subnet-advertise"
Browse files Browse the repository at this point in the history
when network create like
docker network create -d ipvlan --subnet=192.168.1.0/24 -o subnet-advertise -o ipvlan_mode=l3 -o bgp-neighbor=10.0.1.1 -o vrf=100 -o parent=eth0 -o asnum=65001 -o rasnum=65002 vrf100
BGP Advertise network subnet (now 192.168.1.0/24) instead of /32.

Signed-off-by: YujiOshima <[email protected]>
  • Loading branch information
YujiOshima committed Apr 1, 2016
1 parent 449b415 commit a72fc78
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
19 changes: 10 additions & 9 deletions drivers/ipvlan/ipvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions drivers/ipvlan/ipvlan_joinleave.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 38 additions & 2 deletions drivers/ipvlan/ipvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/ipvlan/ipvlan_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type configuration struct {
VrfID string
ASnum string
RemoteASnum string
SubnetAdvertise string
}

type ipv4Subnet struct {
Expand Down

0 comments on commit a72fc78

Please sign in to comment.