Skip to content

Commit

Permalink
bgp: do not advertise ipv6 prefixes via metallb
Browse files Browse the repository at this point in the history
When using metallb as BGP speaker, if IPv6 advertisement is made - metallb will return error as unsupported.
This error is logged and error is returned to control loop, which continues retrying causing log flooding and high CPU.
This change filters out IPv6 prefixes before sending them to metallb library and logs one time error message.

Signed-off-by: harsimran pabla <hpabla@isovalent.com>
  • Loading branch information
harsimran-pabla authored and michi-covalent committed Apr 25, 2023
1 parent da35eb0 commit 922aa1b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/bgp/speaker/pod_cidr.go
Expand Up @@ -27,12 +27,27 @@ type CidrSlice []string
// If a cidr cannot be parsed it is omitted from the array of Advertisements
// returned an an error is logged.
func (cs CidrSlice) ToAdvertisements() []*metallbbgp.Advertisement {
var (
l = log.WithFields(logrus.Fields{
"component": "CidrSlice.ToAdvertisements",
})
)

adverts := make([]*metallbbgp.Advertisement, 0, len(cs))
for _, c := range cs {
parsed, err := cidr.ParseCIDR(c)
if err != nil {
continue
}

// only advertise ipv4 addresses
if parsed.IP.To4() == nil {
// log error and continue
l.WithField("advertisement", parsed.IP.String()).
Error("cannot advertise non-v4 prefix")
continue
}

adverts = append(adverts, &metallbbgp.Advertisement{
Prefix: parsed.IPNet,
})
Expand Down

0 comments on commit 922aa1b

Please sign in to comment.