diff --git a/routingtable/filter/from.go b/routingtable/filter/from.go index 2237fe4ea9fcc61e65f2ec8c59a400e619fc092f..108253973493f499fc33dc5a3fe3d7b32d6e1d06 100644 --- a/routingtable/filter/from.go +++ b/routingtable/filter/from.go @@ -6,9 +6,19 @@ import ( ) type From struct { - prefixList *PrefixList + prefixLists []*PrefixList } func (f *From) Matches(p net.Prefix, pa *route.Path) bool { - return f.prefixList.Matches(p) + return f.matchesAnyPrefixList(p) +} + +func (t *From) matchesAnyPrefixList(p net.Prefix) bool { + for _, l := range t.prefixLists { + if l.Matches(p) { + return true + } + } + + return false } diff --git a/routingtable/filter/prefix_list.go b/routingtable/filter/prefix_list.go index b783a07a540b67acc7fd3384b582490f0bb5aea2..8ccf36e8ab9820ad428604a08a5ded2cbcf03f91 100644 --- a/routingtable/filter/prefix_list.go +++ b/routingtable/filter/prefix_list.go @@ -6,8 +6,15 @@ type PrefixList struct { allowed []net.Prefix } -func (f *PrefixList) Matches(p net.Prefix) bool { - for _, a := range f.allowed { +func NewPrefixList(pfxs ...net.Prefix) *PrefixList { + l := &PrefixList{ + allowed: pfxs, + } + return l +} + +func (l *PrefixList) Matches(p net.Prefix) bool { + for _, a := range l.allowed { if !a.Contains(p) { return false } diff --git a/routingtable/filter/term_test.go b/routingtable/filter/term_test.go index bd0a00bebbe0636a78c8b9b7ca5e90cd83aaadd5..bf045323e5221a43f8ed8643fab0b6ad8acf91f3 100644 --- a/routingtable/filter/term_test.go +++ b/routingtable/filter/term_test.go @@ -46,10 +46,8 @@ func TestProcess(t *testing.T) { path: &route.Path{}, from: []*From{ { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 0), - }, + []*PrefixList{ + NewPrefixList(net.NewPfx(0, 0)), }, }, }, @@ -65,10 +63,8 @@ func TestProcess(t *testing.T) { path: &route.Path{}, from: []*From{ { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 32), - }, + []*PrefixList{ + NewPrefixList(net.NewPfx(0, 32)), }, }, }, @@ -84,10 +80,8 @@ func TestProcess(t *testing.T) { path: &route.Path{}, from: []*From{ { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 0), - }, + []*PrefixList{ + NewPrefixList(net.NewPfx(0, 0)), }, }, }, @@ -103,10 +97,8 @@ func TestProcess(t *testing.T) { path: &route.Path{}, from: []*From{ { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 0), - }, + []*PrefixList{ + NewPrefixList(net.NewPfx(0, 0)), }, }, }, @@ -123,17 +115,9 @@ func TestProcess(t *testing.T) { path: &route.Path{}, from: []*From{ { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 32), - }, - }, - }, - { - &PrefixList{ - allowed: []net.Prefix{ - net.NewPfx(0, 0), - }, + []*PrefixList{ + NewPrefixList(net.NewPfx(0, 32)), + NewPrefixList(net.NewPfx(0, 0)), }, }, },