diff --git a/protocols/bgp/packet/path_attributes.go b/protocols/bgp/packet/path_attributes.go index acd5c78ab813c5b3cc6442f61067c85471366545..b62aacda0e58706f461bedfa513b1269919160b8 100644 --- a/protocols/bgp/packet/path_attributes.go +++ b/protocols/bgp/packet/path_attributes.go @@ -690,24 +690,6 @@ func LargeCommunityAttributeForString(s string) (*PathAttribute, error) { }, nil } -func CommunityAttributeForString(s string) (*PathAttribute, error) { - strs := strings.Split(s, " ") - coms := make([]uint32, len(strs)) - - var err error - for i, str := range strs { - coms[i], err = ParseCommunityString(str) - if err != nil { - return nil, err - } - } - - return &PathAttribute{ - TypeCode: CommunitiesAttr, - Value: coms, - }, nil -} - func isBeginOfASSet(asPathPart string) bool { return strings.Contains(asPathPart, "(") } diff --git a/protocols/bgp/server/fsm_established.go b/protocols/bgp/server/fsm_established.go index 66480407dc7e39e174b4f391017bfdc8c9f2e05f..c1507eb5241e780dedef1c1fcec3aceb63b0802a 100644 --- a/protocols/bgp/server/fsm_established.go +++ b/protocols/bgp/server/fsm_established.go @@ -233,7 +233,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) { path.BGPPath.ASPath = pa.ASPathString() path.BGPPath.ASPathLen = pa.ASPathLen() case packet.CommunitiesAttr: - path.BGPPath.Communities = pa.CommunityString() + path.BGPPath.Communities = pa.Value.([]uint32) case packet.LargeCommunitiesAttr: path.BGPPath.LargeCommunities = pa.LargeCommunityString() } diff --git a/protocols/bgp/server/update_helper.go b/protocols/bgp/server/update_helper.go index c45181803ee3c5c54f777cfbb66e7d3ad6831d53..393df4e969a97c44b66501c1911867059b988a06 100644 --- a/protocols/bgp/server/update_helper.go +++ b/protocols/bgp/server/update_helper.go @@ -49,11 +49,10 @@ func addOptionalPathAttribues(p *route.Path, parent *packet.PathAttribute) error current := parent if len(p.BGPPath.Communities) > 0 { - communities, err := packet.CommunityAttributeForString(p.BGPPath.Communities) - if err != nil { - return fmt.Errorf("Could not create communities attribute: %v", err) + communities := &packet.PathAttribute{ + TypeCode: packet.CommunitiesAttr, + Value: p.BGPPath.Communities, } - current.Next = communities current = communities } diff --git a/route/bgp.go b/route/bgp.go index 80aebdfe2dbb01b6b54a90a2fec6cd77b4e2ced4..3beb6b569e36dee60de849da8d623c0b360c8025 100644 --- a/route/bgp.go +++ b/route/bgp.go @@ -21,7 +21,7 @@ type BGPPath struct { EBGP bool BGPIdentifier uint32 Source uint32 - Communities string + Communities []uint32 LargeCommunities string } diff --git a/routingtable/filter/actions/add_community_action.go b/routingtable/filter/actions/add_community_action.go index 01ad05f62936574bb576d55fe1c7bcf23697a38f..c24107e8b94be6657174fbd3dffb06ae978ff767 100644 --- a/routingtable/filter/actions/add_community_action.go +++ b/routingtable/filter/actions/add_community_action.go @@ -1,10 +1,7 @@ package actions import ( - "strings" - "github.com/bio-routing/bio-rd/net" - "github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/route" ) @@ -26,9 +23,8 @@ func (a *AddCommunityAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Pa modified := pa.Copy() for _, com := range a.communities { - modified.BGPPath.Communities = modified.BGPPath.Communities + " " + packet.CommunityStringForUint32(com) + modified.BGPPath.Communities = append(modified.BGPPath.Communities, com) } - modified.BGPPath.Communities = strings.TrimLeft(modified.BGPPath.Communities, " ") return modified, false } diff --git a/routingtable/filter/community_filter.go b/routingtable/filter/community_filter.go index 9d384e54ad0a58ee622e3d2b0bb1b857c867b0c3..b07d4b332349de507ca5591010475ebd920fed94 100644 --- a/routingtable/filter/community_filter.go +++ b/routingtable/filter/community_filter.go @@ -1,15 +1,15 @@ package filter -import ( - "strings" - - "github.com/bio-routing/bio-rd/protocols/bgp/packet" -) - type CommunityFilter struct { community uint32 } -func (f *CommunityFilter) Matches(communityString string) bool { - return strings.Contains(communityString, packet.CommunityStringForUint32(f.community)) +func (f *CommunityFilter) Matches(coms []uint32) bool { + for _, com := range coms { + if com == f.community { + return true + } + } + + return false } diff --git a/routingtable/update_helper.go b/routingtable/update_helper.go index c18936f3a21055678401a9ec4697ab00363fc4f0..6709bd43ab7e2d39914c6ebd1c59abb6518e8189 100644 --- a/routingtable/update_helper.go +++ b/routingtable/update_helper.go @@ -1,12 +1,9 @@ package routingtable import ( - "strings" - "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/route" - log "github.com/sirupsen/logrus" ) // ShouldPropagateUpdate performs some default checks and returns if an route update should be propagated to a neighbor @@ -32,17 +29,7 @@ func isDisallowedByCommunity(p *route.Path, n *Neighbor) bool { return false } - strs := strings.Split(p.BGPPath.Communities, " ") - for _, str := range strs { - com, err := packet.ParseCommunityString(str) - if err != nil { - log.WithField("Sender", "routingtable.ShouldAnnounce()"). - WithField("community", str). - WithError(err). - Error("Could not parse community") - continue - } - + for _, com := range p.BGPPath.Communities { if (com == packet.WellKnownCommunityNoExport && !n.IBGP) || com == packet.WellKnownCommunityNoAdvertise { return true }