-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Matchall filter #311
Merged
Merged
Add Matchall filter #311
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,13 +168,13 @@ func TestAdvancedFilterAddDel(t *testing.T) { | |
} | ||
|
||
u32SelKeys := []TcU32Key{ | ||
TcU32Key{ | ||
{ | ||
Mask: 0xff, | ||
Val: 80, | ||
Off: 20, | ||
OffMask: 0, | ||
}, | ||
TcU32Key{ | ||
{ | ||
Mask: 0xffff, | ||
Val: 0x146ca, | ||
Off: 32, | ||
|
@@ -546,13 +546,11 @@ func TestFilterU32BpfAddDel(t *testing.T) { | |
} | ||
} | ||
|
||
func TestFilterClsActBpfAddDel(t *testing.T) { | ||
tearDown := setUpNetlinkTest(t) | ||
defer tearDown() | ||
if err := LinkAdd(&Ifb{LinkAttrs{Name: "foo"}}); err != nil { | ||
func setupLinkForTestWithQdisc(t *testing.T, linkName string) (Qdisc, Link) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if err := LinkAdd(&Ifb{LinkAttrs{Name: linkName}}); err != nil { | ||
t.Fatal(err) | ||
} | ||
link, err := LinkByName("foo") | ||
link, err := LinkByName(linkName) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -568,8 +566,6 @@ func TestFilterClsActBpfAddDel(t *testing.T) { | |
QdiscAttrs: attrs, | ||
QdiscType: "clsact", | ||
} | ||
// This feature was added in kernel 4.5 | ||
minKernelRequired(t, 4, 5) | ||
|
||
if err := QdiscAdd(qdisc); err != nil { | ||
t.Fatal(err) | ||
|
@@ -584,7 +580,17 @@ func TestFilterClsActBpfAddDel(t *testing.T) { | |
if q, ok := qdiscs[0].(*GenericQdisc); !ok || q.Type() != "clsact" { | ||
t.Fatal("qdisc is the wrong type") | ||
} | ||
return qdiscs[0], link | ||
} | ||
|
||
func TestFilterClsActBpfAddDel(t *testing.T) { | ||
// This feature was added in kernel 4.5 | ||
minKernelRequired(t, 4, 5) | ||
|
||
tearDown := setUpNetlinkTest(t) | ||
defer tearDown() | ||
|
||
qdisc, link := setupLinkForTestWithQdisc(t, "foo") | ||
filterattrs := FilterAttrs{ | ||
LinkIndex: link.Attrs().Index, | ||
Parent: HANDLE_MIN_EGRESS, | ||
|
@@ -643,11 +649,82 @@ func TestFilterClsActBpfAddDel(t *testing.T) { | |
if err := QdiscDel(qdisc); err != nil { | ||
t.Fatal(err) | ||
} | ||
qdiscs, err = SafeQdiscList(link) | ||
qdiscs, err := SafeQdiscList(link) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(qdiscs) != 0 { | ||
t.Fatal("Failed to remove qdisc") | ||
} | ||
} | ||
|
||
func TestFilterMatchAllAddDel(t *testing.T) { | ||
// This classifier was added in kernel 4.7 | ||
minKernelRequired(t, 4, 7) | ||
|
||
tearDown := setUpNetlinkTest(t) | ||
defer tearDown() | ||
_, link := setupLinkForTestWithQdisc(t, "foo") | ||
_, link2 := setupLinkForTestWithQdisc(t, "bar") | ||
filter := &MatchAll{ | ||
FilterAttrs: FilterAttrs{ | ||
LinkIndex: link.Attrs().Index, | ||
Parent: HANDLE_MIN_EGRESS, | ||
Priority: 32000, | ||
Protocol: unix.ETH_P_ALL, | ||
}, | ||
Actions: []Action{ | ||
&MirredAction{ | ||
ActionAttrs: ActionAttrs{ | ||
Action: TC_ACT_STOLEN, | ||
}, | ||
MirredAction: TCA_EGRESS_REDIR, | ||
Ifindex: link2.Attrs().Index, | ||
}, | ||
}, | ||
} | ||
if err := FilterAdd(filter); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
filters, err := FilterList(link, HANDLE_MIN_EGRESS) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(filters) != 1 { | ||
t.Fatal("Failed to add filter") | ||
} | ||
matchall, ok := filters[0].(*MatchAll) | ||
if !ok { | ||
t.Fatal("Filter is the wrong type") | ||
} | ||
|
||
if matchall.Priority != 32000 { | ||
t.Fatal("Filter priority does not match") | ||
} | ||
|
||
if len(matchall.Actions) != 1 { | ||
t.Fatal("Filter has no actions") | ||
} | ||
|
||
mirredAction, ok := matchall.Actions[0].(*MirredAction) | ||
if !ok { | ||
t.Fatal("Action does not match") | ||
} | ||
|
||
if mirredAction.Ifindex != link2.Attrs().Index { | ||
t.Fatal("Action ifindex does not match") | ||
} | ||
|
||
if err := FilterDel(filter); err != nil { | ||
t.Fatal(err) | ||
} | ||
filters, err = FilterList(link, HANDLE_MIN_EGRESS) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(filters) != 0 { | ||
t.Fatal("Failed to remove filter") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes were made by gofmt, I can split it out into another PR, or a different commit