Skip to content

Commit

Permalink
Support the "allowAll" flag
Browse files Browse the repository at this point in the history
The flag was not implemented, here we cover with a test and support it.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Jun 27, 2023
1 parent 2415e57 commit f7ba67a
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 9 deletions.
32 changes: 23 additions & 9 deletions internal/controller/api_to_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ func routerToFRRConfig(r v1beta1.Router) (*frr.RouterConfig, error) {
IPV6Prefixes: make([]string, 0),
}

for _, n := range r.Neighbors {
frrNeigh, err := neighborToFRR(n)
if err != nil {
return nil, err
}
res.Neighbors = append(res.Neighbors, frrNeigh)
}
for _, p := range r.Prefixes {
family := ipfamily.ForCIDRString(p)
switch family {
Expand All @@ -53,12 +46,20 @@ func routerToFRRConfig(r v1beta1.Router) (*frr.RouterConfig, error) {
case ipfamily.Unknown:
return nil, fmt.Errorf("unknown ipfamily for %s", p)
}
}

for _, n := range r.Neighbors {
frrNeigh, err := neighborToFRR(n, res.IPV4Prefixes, res.IPV6Prefixes)
if err != nil {
return nil, err
}
res.Neighbors = append(res.Neighbors, frrNeigh)
}

return res, nil
}

func neighborToFRR(n v1beta1.Neighbor) (*frr.NeighborConfig, error) {
func neighborToFRR(n v1beta1.Neighbor, ipv4Prefixes, ipv6Prefixes []string) (*frr.NeighborConfig, error) {
neighborFamily, err := ipfamily.ForAddresses(n.Address)
if err != nil {
return nil, fmt.Errorf("failed to find ipfamily for %s, %w", n.Address, err)
Expand All @@ -73,7 +74,20 @@ func neighborToFRR(n v1beta1.Neighbor) (*frr.NeighborConfig, error) {
IPFamily: neighborFamily,
EBGPMultiHop: n.EBGPMultiHop,
}
// TODO allow all

if n.ToAdvertise.Allowed.Mode == v1beta1.AllowAll {
for _, p := range ipv4Prefixes {
res.Advertisements = append(res.Advertisements, &frr.AdvertisementConfig{Prefix: p, IPFamily: ipfamily.IPv4})
res.HasV4Advertisements = true
}
for _, p := range ipv6Prefixes {
res.Advertisements = append(res.Advertisements, &frr.AdvertisementConfig{Prefix: p, IPFamily: ipfamily.IPv6})
res.HasV6Advertisements = true
}

return res, nil
}

for _, p := range n.ToAdvertise.Allowed.Prefixes {
family := ipfamily.ForCIDRString(p)
switch family {
Expand Down
99 changes: 99 additions & 0 deletions internal/controller/api_to_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,105 @@ func TestConversion(t *testing.T) {
},
err: nil,
},
{
name: "Two Neighbor with ToAdvertise, one advertise all",
fromK8s: []v1beta1.FRRConfiguration{
{
Spec: v1beta1.FRRConfigurationSpec{
BGP: v1beta1.BGPConfig{
Routers: []v1beta1.Router{
{
ASN: 65040,
ID: "192.0.2.20",
Neighbors: []v1beta1.Neighbor{
{
ASN: 65041,
Address: "192.0.2.21",
Port: 179,
ToAdvertise: v1beta1.Advertise{
Allowed: v1beta1.AllowedPrefixes{
Prefixes: []string{"192.0.2.0/24", "192.0.4.0/24"},
Mode: v1beta1.AllowRestricted,
},
},
},
{
ASN: 65041,
Address: "192.0.2.22",
Port: 179,
ToAdvertise: v1beta1.Advertise{
Allowed: v1beta1.AllowedPrefixes{
Mode: v1beta1.AllowAll,
},
},
},
},
Prefixes: []string{"192.0.2.0/24", "192.0.3.0/24", "192.0.4.0/24", "2001:db8::/64"},
},
},
},
},
},
},
expected: &frr.Config{
Routers: []*frr.RouterConfig{
{
MyASN: 65040,
RouterID: "192.0.2.20",
Neighbors: []*frr.NeighborConfig{
{
IPFamily: ipfamily.IPv4,
Name: "[email protected]",
ASN: 65041,
Addr: "192.0.2.21",
Port: 179,
Advertisements: []*frr.AdvertisementConfig{
{
IPFamily: ipfamily.IPv4,
Prefix: "192.0.2.0/24",
},
{
IPFamily: ipfamily.IPv4,
Prefix: "192.0.4.0/24",
},
},
HasV4Advertisements: true,
},
{
IPFamily: ipfamily.IPv4,
Name: "[email protected]",
ASN: 65041,
Addr: "192.0.2.22",
Port: 179,
Advertisements: []*frr.AdvertisementConfig{
{
IPFamily: ipfamily.IPv4,
Prefix: "192.0.2.0/24",
},
{
IPFamily: ipfamily.IPv4,
Prefix: "192.0.3.0/24",
},
{
IPFamily: ipfamily.IPv4,
Prefix: "192.0.4.0/24",
},
{
IPFamily: ipfamily.IPv6,
Prefix: "2001:db8::/64",
},
},
HasV4Advertisements: true,
HasV6Advertisements: true,
},
},
IPV4Prefixes: []string{"192.0.2.0/24", "192.0.3.0/24", "192.0.4.0/24"},
IPV6Prefixes: []string{"2001:db8::/64"},
},
},
},
err: nil,
},
}

for _, test := range tests {
Expand Down

0 comments on commit f7ba67a

Please sign in to comment.