-
Notifications
You must be signed in to change notification settings - Fork 48
/
chain.go
48 lines (42 loc) · 1000 Bytes
/
chain.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
package tc
import (
"github.com/florianl/go-tc/internal/unix"
"github.com/mdlayher/netlink"
)
// Chain represents a collection of filter
type Chain struct {
Tc
}
// Chain allows to read and alter chains
func (tc *Tc) Chain() *Chain {
return &Chain{*tc}
}
// Add creates a new chain
func (c *Chain) Add(info *Object) error {
if info == nil {
return ErrNoArg
}
options, err := validateFilterObject(unix.RTM_NEWCHAIN, info)
if err != nil {
return err
}
return c.action(unix.RTM_NEWCHAIN, netlink.Create|netlink.Excl, &info.Msg, options)
}
// Delete removes a chain
func (c *Chain) Delete(info *Object) error {
if info == nil {
return ErrNoArg
}
options, err := validateFilterObject(unix.RTM_DELCHAIN, info)
if err != nil {
return err
}
return c.action(unix.RTM_DELCHAIN, netlink.HeaderFlags(0), &info.Msg, options)
}
// Get fetches chains
func (c *Chain) Get(i *Msg) ([]Object, error) {
if i == nil {
return []Object{}, ErrNoArg
}
return c.get(unix.RTM_GETCHAIN, i)
}