Skip to content
Snippets Groups Projects
Commit 4df9a4b4 authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

bgp communities -> []uint32

parent 826e7afd
No related branches found
No related tags found
No related merge requests found
...@@ -690,24 +690,6 @@ func LargeCommunityAttributeForString(s string) (*PathAttribute, error) { ...@@ -690,24 +690,6 @@ func LargeCommunityAttributeForString(s string) (*PathAttribute, error) {
}, nil }, 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 { func isBeginOfASSet(asPathPart string) bool {
return strings.Contains(asPathPart, "(") return strings.Contains(asPathPart, "(")
} }
......
...@@ -233,7 +233,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) { ...@@ -233,7 +233,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) {
path.BGPPath.ASPath = pa.ASPathString() path.BGPPath.ASPath = pa.ASPathString()
path.BGPPath.ASPathLen = pa.ASPathLen() path.BGPPath.ASPathLen = pa.ASPathLen()
case packet.CommunitiesAttr: case packet.CommunitiesAttr:
path.BGPPath.Communities = pa.CommunityString() path.BGPPath.Communities = pa.Value.([]uint32)
case packet.LargeCommunitiesAttr: case packet.LargeCommunitiesAttr:
path.BGPPath.LargeCommunities = pa.LargeCommunityString() path.BGPPath.LargeCommunities = pa.LargeCommunityString()
} }
......
...@@ -49,11 +49,10 @@ func addOptionalPathAttribues(p *route.Path, parent *packet.PathAttribute) error ...@@ -49,11 +49,10 @@ func addOptionalPathAttribues(p *route.Path, parent *packet.PathAttribute) error
current := parent current := parent
if len(p.BGPPath.Communities) > 0 { if len(p.BGPPath.Communities) > 0 {
communities, err := packet.CommunityAttributeForString(p.BGPPath.Communities) communities := &packet.PathAttribute{
if err != nil { TypeCode: packet.CommunitiesAttr,
return fmt.Errorf("Could not create communities attribute: %v", err) Value: p.BGPPath.Communities,
} }
current.Next = communities current.Next = communities
current = communities current = communities
} }
......
...@@ -21,7 +21,7 @@ type BGPPath struct { ...@@ -21,7 +21,7 @@ type BGPPath struct {
EBGP bool EBGP bool
BGPIdentifier uint32 BGPIdentifier uint32
Source uint32 Source uint32
Communities string Communities []uint32
LargeCommunities string LargeCommunities string
} }
......
package actions package actions
import ( import (
"strings"
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
) )
...@@ -26,9 +23,8 @@ func (a *AddCommunityAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Pa ...@@ -26,9 +23,8 @@ func (a *AddCommunityAction) Do(p net.Prefix, pa *route.Path) (modPath *route.Pa
modified := pa.Copy() modified := pa.Copy()
for _, com := range a.communities { 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 return modified, false
} }
package filter package filter
import (
"strings"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
)
type CommunityFilter struct { type CommunityFilter struct {
community uint32 community uint32
} }
func (f *CommunityFilter) Matches(communityString string) bool { func (f *CommunityFilter) Matches(coms []uint32) bool {
return strings.Contains(communityString, packet.CommunityStringForUint32(f.community)) for _, com := range coms {
if com == f.community {
return true
}
}
return false
} }
package routingtable package routingtable
import ( import (
"strings"
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route" "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 // 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 { ...@@ -32,17 +29,7 @@ func isDisallowedByCommunity(p *route.Path, n *Neighbor) bool {
return false return false
} }
strs := strings.Split(p.BGPPath.Communities, " ") for _, com := range 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
}
if (com == packet.WellKnownCommunityNoExport && !n.IBGP) || com == packet.WellKnownCommunityNoAdvertise { if (com == packet.WellKnownCommunityNoExport && !n.IBGP) || com == packet.WellKnownCommunityNoAdvertise {
return true return true
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment