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) {
}, 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, "(")
}
......
......@@ -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()
}
......
......@@ -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
}
......
......@@ -21,7 +21,7 @@ type BGPPath struct {
EBGP bool
BGPIdentifier uint32
Source uint32
Communities string
Communities []uint32
LargeCommunities string
}
......
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
}
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
}
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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment