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

support for multiple prefix lists

parent d5767c9e
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......@@ -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
}
......
......@@ -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)),
},
},
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment