Merge pull request #1713 from MaxRink/fix/fix-mpbgp-family

fix(bgp): validate MP-BGP fixed-address family
This commit is contained in:
Daniel Finneran
2026-09-02 17:28:58 +01:00
committed by GitHub
2 changed files with 40 additions and 3 deletions

View File

@@ -2,7 +2,6 @@ package kubevip
import (
"fmt"
"net"
"strconv"
"strings"
@@ -260,12 +259,12 @@ func (p *BGPPeer) FindMpbgpAddresses(ap *api.Peer, server *BGPConfig) (string, s
}
if ipv4 != "" {
if net.ParseIP(ipv4) == nil {
if !utils.IsIPv4(ipv4) {
return "", "", fmt.Errorf("provided address '%s' is not a valid IPv4 address", ipv4)
}
}
if ipv6 != "" {
if net.ParseIP(ipv6) == nil {
if !utils.IsIPv6(ipv6) {
return "", "", fmt.Errorf("provided address '%s' is not a valid IPv6 address", ipv6)
}
}

View File

@@ -0,0 +1,38 @@
package kubevip
import (
"testing"
api "github.com/osrg/gobgp/v4/api"
)
func TestFindMpbgpAddressesRejectsFixedAddressFamilyMismatches(t *testing.T) {
tests := []struct {
name string
peer BGPPeer
}{
{
name: "IPv6 value in IPv4 field",
peer: BGPPeer{
MpbgpNexthop: "fixed",
MpbgpIPv4: "2001:db8::20",
},
},
{
name: "IPv4 value in IPv6 field",
peer: BGPPeer{
MpbgpNexthop: "fixed",
MpbgpIPv6: "192.0.2.20",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, _, err := tt.peer.FindMpbgpAddresses(&api.Peer{Transport: &api.Transport{}}, &BGPConfig{})
if err == nil {
t.Fatal("FindMpbgpAddresses() error = nil, want address-family error")
}
})
}
}