forked from nadoo/ipset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipset_linux.go
46 lines (35 loc) · 1.23 KB
/
ipset_linux.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
package ipset
import "github.com/nadoo/ipset/internal/netlink"
var nl *netlink.NetLink
// Option is used to set parameters of ipset operations.
type Option = netlink.Option
// OptIPv6 sets `family inet6` parameter to operations.
func OptIPv6() Option { return func(opts *netlink.Options) { opts.IPv6 = true } }
// OptTimeout sets `timeout xx` parameter to operations.
func OptTimeout(timeout uint32) Option { return func(opts *netlink.Options) { opts.Timeout = timeout } }
// Init prepares a netlink socket of ipset.
func Init() (err error) {
nl, err = netlink.New()
return err
}
// Create creates a new set.
func Create(setName string, opts ...Option) (err error) {
return nl.CreateSet(setName, opts...)
}
// Destroy destroys a named set.
func Destroy(setName string) (err error) {
return nl.DestroySet(setName)
}
// Flush flushes a named set.
func Flush(setName string) (err error) {
return nl.FlushSet(setName)
}
// Add adds an entry to the named set.
// entry could be: "1.1.1.1" or "192.168.1.0/24".
func Add(setName, entry string, opts ...Option) (err error) {
return nl.AddToSet(setName, entry, opts...)
}
// Del deletes an entry from the named set.
func Del(setName, entry string) (err error) {
return nl.DelFromSet(setName, entry)
}