Skip to content

Commit 6cdc237

Browse files
Lars Ekmanmurali-reddy
authored andcommitted
Make ipv6 routing to pods (CNI routing) work for ipv6 (#578)
1 parent 7b9291a commit 6cdc237

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

pkg/controllers/routing/bgp_peers.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ func (nrc *NetworkRoutingController) syncInternalPeers() {
123123
},
124124
},
125125
},
126+
{
127+
Config: config.AfiSafiConfig{
128+
AfiSafiName: config.AFI_SAFI_TYPE_IPV6_UNICAST,
129+
Enabled: true,
130+
},
131+
MpGracefulRestart: config.MpGracefulRestart{
132+
Config: config.MpGracefulRestartConfig{
133+
Enabled: true,
134+
},
135+
},
136+
},
126137
}
127138
}
128139

@@ -207,6 +218,17 @@ func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*config.
207218
},
208219
},
209220
},
221+
{
222+
Config: config.AfiSafiConfig{
223+
AfiSafiName: config.AFI_SAFI_TYPE_IPV6_UNICAST,
224+
Enabled: true,
225+
},
226+
MpGracefulRestart: config.MpGracefulRestart{
227+
Config: config.MpGracefulRestartConfig{
228+
Enabled: true,
229+
},
230+
},
231+
},
210232
}
211233
}
212234
if peerMultihopTtl > 1 {

pkg/controllers/routing/network_routes_controller.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,43 @@ func (nrc *NetworkRoutingController) advertisePodRoute() error {
359359
cidrStr := strings.Split(cidr, "/")
360360
subnet := cidrStr[0]
361361
cidrLen, _ := strconv.Atoi(cidrStr[1])
362-
attrs := []bgp.PathAttributeInterface{
363-
bgp.NewPathAttributeOrigin(0),
364-
bgp.NewPathAttributeNextHop(nrc.nodeIP.String()),
365-
}
362+
if nrc.isIpv6 {
363+
prefixes := []bgp.AddrPrefixInterface{bgp.NewIPv6AddrPrefix(uint8(cidrLen), subnet)}
364+
attrs := []bgp.PathAttributeInterface{
365+
bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP),
366+
// This requires some research.
367+
// For ipv6 what should be next-hop value? According to this https://www.noction.com/blog/bgp-next-hop
368+
// using the link-local address may be more appropriate.
369+
bgp.NewPathAttributeMpReachNLRI(nrc.nodeIP.String(), prefixes),
370+
&bgp.PathAttributeNextHop{
371+
PathAttribute: bgp.PathAttribute{
372+
Flags: bgp.PathAttrFlags[bgp.BGP_ATTR_TYPE_NEXT_HOP],
373+
Type: bgp.BGP_ATTR_TYPE_NEXT_HOP,
374+
Length: 16,
375+
},
376+
Value: nrc.nodeIP,
377+
},
378+
}
379+
380+
glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers using attribute: %+q", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String(), attrs)
381+
382+
if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPv6AddrPrefix(uint8(cidrLen),
383+
subnet), false, attrs, time.Now(), false)}); err != nil {
384+
return fmt.Errorf(err.Error())
385+
}
386+
} else {
387+
attrs := []bgp.PathAttributeInterface{
388+
bgp.NewPathAttributeOrigin(0),
389+
bgp.NewPathAttributeNextHop(nrc.nodeIP.String()),
390+
}
366391

367-
glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String())
392+
glog.V(2).Infof("Advertising route: '%s/%s via %s' to peers", subnet, strconv.Itoa(cidrLen), nrc.nodeIP.String())
368393

369-
if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(uint8(cidrLen),
370-
subnet), false, attrs, time.Now(), false)}); err != nil {
371-
return fmt.Errorf(err.Error())
394+
if _, err := nrc.bgpServer.AddPath("", []*table.Path{table.NewPath(nil, bgp.NewIPAddrPrefix(uint8(cidrLen),
395+
subnet), false, attrs, time.Now(), false)}); err != nil {
396+
return fmt.Errorf(err.Error())
397+
}
372398
}
373-
374399
return nil
375400
}
376401

0 commit comments

Comments
 (0)