-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement VRF route leaking #160
Changes from all commits
7569bb8
6327fa7
0522207
55d806b
1a3dc65
99c7bbd
bd942df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier:Apache-2.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general the pattern seems to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I have been missing the comments that I need to reword before submit the code review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
|
||
package address | ||
|
||
import ( | ||
"net" | ||
|
||
"go.universe.tf/e2etest/pkg/ipfamily" | ||
) | ||
|
||
func FilterForFamily(ips []string, family ipfamily.Family) []string { | ||
if family == ipfamily.DualStack { | ||
return ips | ||
} | ||
var res []string | ||
for _, ip := range ips { | ||
parsedIP, _, _ := net.ParseCIDR(ip) | ||
if parsedIP == nil { | ||
panic("invalid ip") // it's a test after all, should never happen | ||
} | ||
isV4 := (parsedIP.To4() != nil) | ||
if family == ipfamily.IPv4 && isV4 { | ||
res = append(res, ip) | ||
continue | ||
} | ||
if family == ipfamily.IPv6 && !isV4 { | ||
res = append(res, ip) | ||
continue | ||
} | ||
} | ||
return res | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ package routes | |
|
||
import ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About the commit message: note: I did not understood that flag means the return bool value, is it valid term? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this done |
||
"bytes" | ||
"errors" | ||
"fmt" | ||
"net" | ||
|
||
|
@@ -18,55 +17,52 @@ import ( | |
|
||
// PodHasPrefixFromContainer tells if the given frr-k8s pod has recevied a route for | ||
// the given prefix from the given container. | ||
func PodHasPrefixFromContainer(pod *v1.Pod, frr frrcontainer.FRR, prefix string) bool { | ||
func PodHasPrefixFromContainer(pod *v1.Pod, frr frrcontainer.FRR, vrf, prefix string) bool { | ||
_, cidr, _ := net.ParseCIDR(prefix) | ||
ipFamily := ipfamily.ForCIDR(cidr) | ||
nextHop := frr.Ipv4 | ||
if ipFamily == ipfamily.IPv6 { | ||
nextHop = frr.Ipv6 | ||
} | ||
vrf := frr.RouterConfig.VRF | ||
return hasPrefix(pod, ipFamily, cidr, nextHop, vrf) | ||
} | ||
|
||
// CheckNeighborHasPrefix tells if the given frr container has a route toward the given prefix | ||
// via the set of node passed to this function. | ||
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1.Node) (bool, error) { | ||
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, vrf, prefix string, nodes []v1.Node) error { | ||
routesV4, routesV6, err := frr.Routes(neighbor) | ||
if err != nil { | ||
return false, err | ||
return err | ||
} | ||
|
||
_, cidr, err := net.ParseCIDR(prefix) | ||
if err != nil { | ||
return false, err | ||
return err | ||
} | ||
|
||
route, err := routeForCIDR(cidr, routesV4, routesV6) | ||
var notFound RouteNotFoundError | ||
if errors.As(err, ¬Found) { | ||
return false, nil | ||
} | ||
if err != nil { | ||
return false, err | ||
return err | ||
} | ||
|
||
cidrFamily := ipfamily.ForCIDR(cidr) | ||
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, neighbor.RouterConfig.VRF) | ||
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, vrf) | ||
if err != nil { | ||
return false, nil | ||
return err | ||
} | ||
return true, nil | ||
return nil | ||
} | ||
|
||
func cidrsAreEqual(a, b *net.IPNet) bool { | ||
return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask) | ||
} | ||
|
||
type RouteNotFoundError string | ||
type RouteNotFoundError struct { | ||
Route string | ||
} | ||
|
||
func (e RouteNotFoundError) Error() string { | ||
return string(e) | ||
return fmt.Sprintf("route not found %s", e.Route) | ||
} | ||
|
||
func routeForCIDR(cidr *net.IPNet, routesV4 map[string]frr.Route, routesV6 map[string]frr.Route) (frr.Route, error) { | ||
|
@@ -80,7 +76,7 @@ func routeForCIDR(cidr *net.IPNet, routesV4 map[string]frr.Route, routesV6 map[s | |
return route, nil | ||
} | ||
} | ||
return frr.Route{}, RouteNotFoundError(fmt.Sprintf("route %s not found", cidr)) | ||
return frr.Route{}, RouteNotFoundError{Route: cidr.String()} | ||
} | ||
|
||
func hasPrefix(pod *v1.Pod, pairingFamily ipfamily.Family, prefix *net.IPNet, nextHop, vrf string) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
Imports []string
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because frr allows more complex imports than that, and I wanted to leave the door open in case we want to extend. If we stick with []string, we'll have to another field even if it semantically belongs to the imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you name for my knowledge which complex imports you have in mind? I am in favor comment the reasoning why not
[]string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's the import from l2vpn logic frr provides. I just don't want to prevent that and make the api extensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.frrouting.org/en/latest/bgp.html#clicmd-rt-vpn-import-export-both-RTLIST...