From 35195e2711ad7e9070d46d2ee81ed77d680f619a Mon Sep 17 00:00:00 2001 From: Lars Ekman Date: Mon, 19 Nov 2018 10:58:34 +0100 Subject: [PATCH] Make ipv6 routing to pods (CNI routing) work for ipv6 --- pkg/controllers/routing/bgp_peers.go | 22 ++++++++++ .../routing/network_routes_controller.go | 43 +++++++++++++++---- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/pkg/controllers/routing/bgp_peers.go b/pkg/controllers/routing/bgp_peers.go index a120011e6..97245f916 100644 --- a/pkg/controllers/routing/bgp_peers.go +++ b/pkg/controllers/routing/bgp_peers.go @@ -120,6 +120,17 @@ func (nrc *NetworkRoutingController) syncInternalPeers() { }, }, }, + { + Config: config.AfiSafiConfig{ + AfiSafiName: config.AFI_SAFI_TYPE_IPV6_UNICAST, + Enabled: true, + }, + MpGracefulRestart: config.MpGracefulRestart{ + Config: config.MpGracefulRestartConfig{ + Enabled: true, + }, + }, + }, } } @@ -204,6 +215,17 @@ func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*config. }, }, }, + { + Config: config.AfiSafiConfig{ + AfiSafiName: config.AFI_SAFI_TYPE_IPV6_UNICAST, + Enabled: true, + }, + MpGracefulRestart: config.MpGracefulRestart{ + Config: config.MpGracefulRestartConfig{ + Enabled: true, + }, + }, + }, } } if peerMultihopTtl > 1 { diff --git a/pkg/controllers/routing/network_routes_controller.go b/pkg/controllers/routing/network_routes_controller.go index b4b027811..eda219861 100644 --- a/pkg/controllers/routing/network_routes_controller.go +++ b/pkg/controllers/routing/network_routes_controller.go @@ -350,18 +350,43 @@ func (nrc *NetworkRoutingController) advertisePodRoute() error { cidrStr := strings.Split(cidr, "/") subnet := cidrStr[0] cidrLen, _ := strconv.Atoi(cidrStr[1]) - attrs := []bgp.PathAttributeInterface{ - bgp.NewPathAttributeOrigin(0), - bgp.NewPathAttributeNextHop(nrc.nodeIP.String()), - } + if nrc.isIpv6 { + prefixes := []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(uint8(cidrLen), subnet)} + attrs := []bgp.PathAttributeInterface{ + bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP), + // This requires some research. + // For ipv6 what should be next-hop value? According to this https://www.noction.com/blog/bgp-next-hop + // using the link-local address may be more appropriate. + bgp.NewPathAttributeMpReachNLRI(nrc.nodeIP.String(), prefixes), + &bgp.PathAttributeNextHop{ + PathAttribute: bgp.PathAttribute{ + Flags: bgp.PathAttrFlags[bgp.BGP_ATTR_TYPE_NEXT_HOP], + Type: bgp.BGP_ATTR_TYPE_NEXT_HOP, + Length: 16, + }, + Value: nrc.nodeIP, + }, + } + + glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers using attribute: %+q", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String(), attrs) + + if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPv6AddrPrefix(uint8(cidrLen), + subnet), false, attrs, time.Now(), false)}); err != nil { + return fmt.Errorf(err.Error()) + } + } else { + attrs := []bgp.PathAttributeInterface{ + bgp.NewPathAttributeOrigin(0), + bgp.NewPathAttributeNextHop(nrc.nodeIP.String()), + } - glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String()) + glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String()) - if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(uint8(cidrLen), - subnet), false, attrs, time.Now(), false)}); err != nil { - return fmt.Errorf(err.Error()) + if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(uint8(cidrLen), + subnet), false, attrs, time.Now(), false)}); err != nil { + return fmt.Errorf(err.Error()) + } } - return nil }