Skip to content

Commit

Permalink
send-max: respect configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Peim committed Mar 20, 2024
1 parent 5d5a6b9 commit 6c0e9eb
Show file tree
Hide file tree
Showing 26 changed files with 1,705 additions and 1,424 deletions.
2 changes: 1 addition & 1 deletion api/attribute.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/capability.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2,428 changes: 1,219 additions & 1,209 deletions api/gobgp.pb.go

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions api/gobgp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,16 @@ message Path {
uint32 source_asn = 10;
string source_id = 11;
bool filtered = 12;
bool stale = 13;
bool is_from_external = 14;
string neighbor_ip = 15;
bytes uuid = 16; // only paths installed by AddPath API have this
bool is_nexthop_invalid = 17;
uint32 identifier = 18;
uint32 local_identifier = 19;
bytes nlri_binary = 20;
repeated bytes pattrs_binary = 21;
bool send_max_filtered = 13;
bool stale = 14;
bool is_from_external = 15;
string neighbor_ip = 16;
bytes uuid = 17; // only paths installed by AddPath API have this
bool is_nexthop_invalid = 18;
uint32 identifier = 19;
uint32 local_identifier = 20;
bytes nlri_binary = 21;
repeated bytes pattrs_binary = 22;
}

message Destination {
Expand Down
4 changes: 0 additions & 4 deletions api/gobgp_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions cmd/gobgp/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func getPathAttributeString(nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttrib
return fmt.Sprint(s)
}

func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, showLabel, showMUP bool, showIdentifier bgp.BGPAddPathMode) []interface{} {
func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, showLabel, showMUP, showSendMaxFiltered bool, showIdentifier bgp.BGPAddPathMode) []interface{} {
nlri, _ := apiutil.GetNativeNlri(p)

// Path Symbols (e.g. "*>")
Expand Down Expand Up @@ -650,17 +650,27 @@ func makeShowRouteArgs(p *api.Path, idx int, now time.Time, showAge, showBest, s
pattrstr := getPathAttributeString(nlri, attrs)
args = append(args, pattrstr)

if showSendMaxFiltered {
if p.SendMaxFiltered {
args = append(args, "send-max-filtered")
} else if p.Filtered {
args = append(args, "policy-filtered")
} else {
args = append(args, "not filtered")
}
}

updateColumnWidth(nlri.String(), nexthop, aspathstr, label, teid, qfi, endpoint)

return args
}

func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP bool, showIdentifier bgp.BGPAddPathMode) {
func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP, showSendMaxFiltered bool, showIdentifier bgp.BGPAddPathMode) {
pathStrs := make([][]interface{}, 0, len(dsts))
now := time.Now()
for _, dst := range dsts {
for idx, p := range dst.Paths {
pathStrs = append(pathStrs, makeShowRouteArgs(p, idx, now, showAge, showBest, showLabel, showMUP, showIdentifier))
pathStrs = append(pathStrs, makeShowRouteArgs(p, idx, now, showAge, showBest, showLabel, showMUP, showSendMaxFiltered, showIdentifier))
}
}

Expand Down Expand Up @@ -691,6 +701,11 @@ func showRoute(dsts []*api.Destination, showAge, showBest, showLabel, showMUP bo
headers = append(headers, "Attrs")
format += "%-s\n"

if showSendMaxFiltered {
headers = append(headers, "Filtered")
format += "%-s\n"
}

fmt.Printf(format, headers...)
for _, pathStr := range pathStrs {
fmt.Printf(format, pathStr...)
Expand Down Expand Up @@ -839,6 +854,7 @@ func showNeighborRib(r string, name string, args []string) error {
showAge := true
showLabel := false
showMUP := false
showSendMaxFiltered := false
showIdentifier := bgp.BGP_ADD_PATH_NONE
validationTarget := ""
rd := ""
Expand All @@ -852,6 +868,7 @@ func showNeighborRib(r string, name string, args []string) error {
showBest = true
case cmdAdjOut:
showAge = false
showSendMaxFiltered = true
case cmdVRF:
def = ipv4UC
showBest = true
Expand Down Expand Up @@ -1058,7 +1075,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
}
if len(dsts) > 0 {
showRoute(dsts, showAge, showBest, showLabel, showMUP, showIdentifier)
showRoute(dsts, showAge, showBest, showLabel, showMUP, showSendMaxFiltered, showIdentifier)
} else {
fmt.Println("Network not in table")
}
Expand Down
5 changes: 1 addition & 4 deletions internal/pkg/table/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ func rsFilter(id string, as uint32, path *Path) bool {
return false
}

if id != GLOBAL_RIB_NAME && (path.GetSource().Address.String() == id || isASLoop(as, path)) {
return true
}
return false
return id != GLOBAL_RIB_NAME && (path.GetSource().Address.String() == id || isASLoop(as, path))
}

func (dd *Destination) GetKnownPathList(id string, as uint32) []*Path {
Expand Down
19 changes: 17 additions & 2 deletions internal/pkg/table/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ type Path struct {
IsNexthopInvalid bool
IsWithdraw bool
}
type FilteredType uint8

const (
NotFiltered FilteredType = 1 << iota
PolicyFiltered
SendMaxFiltered
)

type PathLocalKey string

var localSource = &PeerInfo{}

Expand Down Expand Up @@ -566,7 +575,7 @@ func (path *Path) String() string {
s.WriteString(fmt.Sprintf("{ %s EOR | src: %s }", path.GetRouteFamily(), path.GetSource()))
return s.String()
}
s.WriteString(fmt.Sprintf("{ %s | ", path.getPrefix()))
s.WriteString(fmt.Sprintf("{ %s | ", path.GetPrefix()))
s.WriteString(fmt.Sprintf("src: %s", path.GetSource()))
s.WriteString(fmt.Sprintf(", nh: %s", path.GetNexthop()))
if path.IsNexthopInvalid {
Expand All @@ -579,7 +588,13 @@ func (path *Path) String() string {
return s.String()
}

func (path *Path) getPrefix() string {
// GetLocalKey identifies the path in the local BGP server.
func (path *Path) GetLocalKey() PathLocalKey {
// return PathLocalKey(path.GetPrefix())
return PathLocalKey(fmt.Sprintf("%s:%s:%d", path.GetRouteFamily(), path.GetNlri(), path.GetNlri().PathLocalIdentifier()))
}

func (path *Path) GetPrefix() string {
return path.GetNlri().String()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/table/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPathGetPrefix(t *testing.T) {
peerP := PathCreatePeer()
pathP := PathCreatePath(peerP)
prefix := "10.10.10.0/24"
r_prefix := pathP[0].getPrefix()
r_prefix := pathP[0].GetPrefix()
assert.Equal(t, r_prefix, prefix)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (t *Table) validatePath(path *Path) {
log.Fields{
"Topic": "Table",
"Key": t.routeFamily,
"Prefix": path.GetNlri().String(),
"Prefix": path.GetPrefix(),
"ReceivedRf": path.GetRouteFamily().String()})
}
if attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); attr != nil {
Expand Down
Loading

0 comments on commit 6c0e9eb

Please sign in to comment.