Skip to content

Commit

Permalink
Merge pull request #215 from nik-netlox/main
Browse files Browse the repository at this point in the history
PR-gobgp changes for ipv6 route advertisement
  • Loading branch information
UltraInstinct14 committed Feb 2, 2023
2 parents faaa4f0 + e6025e0 commit d74785e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion loxilb-ebpf
Submodule loxilb-ebpf updated 1 files
+26 −25 common/common.mk
38 changes: 28 additions & 10 deletions loxinet/gobgpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ func (gbh *GoBgpH) syncRoute(p *api.Path, showIdentifier bgp.BGPAddPathMode) err
}

if p.GetIsWithdraw() {
tk.LogIt(tk.LogDebug, "[GoBGP] ip route delete %s via %s", route.Dst.String(), route.Gw.String())
tk.LogIt(tk.LogDebug, "[GoBGP] ip route delete %s via %s\n", route.Dst.String(), route.Gw.String())
if err := nlp.RouteDel(route); err != nil {
tk.LogIt(tk.LogError, "[GoBGP] failed to ip route delete. err: %s\n", err.Error())
return err
}
} else {
tk.LogIt(tk.LogDebug, "[GoBGP] ip route add %s via %s", route.Dst.String(), route.Gw.String())
tk.LogIt(tk.LogDebug, "[GoBGP] ip route add %s via %s\n", route.Dst.String(), route.Gw.String())
if err := nlp.RouteAdd(route); err != nil {
tk.LogIt(tk.LogError, "[GoBGP] failed to ip route add. err: %s\n", err.Error())
return err
Expand Down Expand Up @@ -290,8 +290,8 @@ func (gbh *GoBgpH) GetRoutes(client api.GobgpApiClient) int {
}

// AdvertiseRoute - advertise a new route using goBGP
func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uint32) int {

func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uint32, ipv4 bool) int {
var apiFamily *api.Family
// add routes
//tk.LogIt(tk.LogDebug, "\n\n\n Advertising Route : %v via %v\n\n\n", rtPrefix, nh)
nlri, _ := apb.New(&api.IPAddressPrefix{
Expand All @@ -311,6 +311,12 @@ func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uin
LocalPref: pref,
})

if ipv4 == true {
apiFamily = &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST}
} else {
apiFamily = &api.Family{Afi: api.Family_AFI_IP6, Safi: api.Family_SAFI_UNICAST}
}

/*
a3, _ := apb.New(&api.AsPathAttribute{
Segments: []*api.AsSegment{
Expand All @@ -328,7 +334,7 @@ func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uin

_, err := gbh.client.AddPath(context.Background(), &api.AddPathRequest{
Path: &api.Path{
Family: &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST},
Family: apiFamily,
Nlri: nlri,
Pattrs: attrs,
},
Expand Down Expand Up @@ -486,7 +492,11 @@ func (gbh *GoBgpH) AddBGPRule(instance string, IP string) {
} else {
pref = cmn.HighLocalPref
}
gbh.AdvertiseRoute(IP, 32, "0.0.0.0", pref)
if net.ParseIP(IP).To4() != nil {
gbh.AdvertiseRoute(IP, 32, "0.0.0.0", pref, true)
} else {
gbh.AdvertiseRoute(IP, 128, "::", pref, false)
}
}

gbh.mtx.Unlock()
Expand All @@ -512,7 +522,11 @@ func (gbh *GoBgpH) DelBGPRule(instance string, IP string) {
} else {
pref = cmn.HighLocalPref
}
gbh.DelAdvertiseRoute(IP, 32, "0.0.0.0", pref)
if net.ParseIP(IP).To4() != nil {
gbh.DelAdvertiseRoute(IP, 32, "0.0.0.0", pref)
} else {
gbh.DelAdvertiseRoute(IP, 128, "::", pref)
}
}
gbh.mtx.Unlock()
}
Expand Down Expand Up @@ -546,7 +560,7 @@ func (gbh *GoBgpH) AddCurrentBgpRoutesToIPRoute() error {
for _, r := range rib {
_, dstIPN, err := net.ParseCIDR(r.GetPrefix())
if err != nil {
return fmt.Errorf("%s is invalid prefix", r.GetPrefix())
return fmt.Errorf("%s is invalid prefix\n", r.GetPrefix())
}

var nlpRoute *nlp.Route
Expand Down Expand Up @@ -597,13 +611,17 @@ func (gbh *GoBgpH) advertiseAllRoutes(instance string) {
}

if !ci.vip.IsUnspecified() {
gbh.AdvertiseRoute(ci.vip.String(), 32, "0.0.0.0", pref)
gbh.AdvertiseRoute(ci.vip.String(), 32, "0.0.0.0", pref, true)
}

for ip, valid := range ci.rules {
tk.LogIt(tk.LogDebug, "[GoBGP] connected BGP rules ip %s is valid(%v)\n", ip, valid)
if valid {
gbh.AdvertiseRoute(ip, 32, "0.0.0.0", pref)
if net.ParseIP(ip).To4() != nil {
gbh.AdvertiseRoute(ip, 32, "0.0.0.0", pref, true)
} else {
gbh.AdvertiseRoute(ip, 128, "::", pref, false)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func loxiXsyncMain() {
}
}

var version string = "0.7.9"
var version string = "0.8.2"
var buildInfo string = ""

func main() {
Expand Down

0 comments on commit d74785e

Please sign in to comment.