-
Notifications
You must be signed in to change notification settings - Fork 48
/
example_actions_test.go
50 lines (44 loc) · 903 Bytes
/
example_actions_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build linux
// +build linux
package tc_test
import (
"fmt"
"os"
"github.com/florianl/go-tc"
)
func ExampleActions() {
tcnl, err := tc.Open(&tc.Config{})
if err != nil {
fmt.Fprintf(os.Stderr, "could not open rtnetlink socket: %v\n", err)
return
}
defer func() {
if err := tcnl.Close(); err != nil {
fmt.Fprintf(os.Stderr, "could not close rtnetlink socket: %v\n", err)
}
}()
// Create a gact Actions.
if err := tcnl.Actions().Add([]*tc.Action{
{
Kind: "gact",
Gact: &tc.Gact{
Parms: &tc.GactParms{
Action: 2, // drop
},
},
},
}); err != nil {
fmt.Fprintf(os.Stderr, "failed to add actions: %v\n", err)
return
}
// Delete the gact Actions on Index 1.
if err := tcnl.Actions().Delete([]*tc.Action{
{
Kind: "gact",
Index: 1,
},
}); err != nil {
fmt.Fprintf(os.Stderr, "failed to delete gact actions: %v\n", err)
return
}
}