2023-10-11 17:31:41 +03:00
|
|
|
// Package ipset provides ipset functionality.
|
|
|
|
package ipset
|
2021-06-18 17:55:01 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2023-10-11 17:31:41 +03:00
|
|
|
// Manager is the ipset manager interface.
|
2021-06-18 17:55:01 +03:00
|
|
|
//
|
|
|
|
// TODO(a.garipov): Perhaps generalize this into some kind of a NetFilter type,
|
|
|
|
// since ipset is exclusive to Linux?
|
2023-10-11 17:31:41 +03:00
|
|
|
type Manager interface {
|
2021-06-18 17:55:01 +03:00
|
|
|
Add(host string, ip4s, ip6s []net.IP) (n int, err error)
|
|
|
|
Close() (err error)
|
|
|
|
}
|
|
|
|
|
2023-10-11 17:31:41 +03:00
|
|
|
// NewManager returns a new ipset manager. IPv4 addresses are added to an
|
|
|
|
// ipset with an ipv4 family; IPv6 addresses, to an ipv6 ipset. ipset must
|
|
|
|
// exist.
|
2021-06-18 17:55:01 +03:00
|
|
|
//
|
|
|
|
// The syntax of the ipsetConf is:
|
|
|
|
//
|
2022-09-07 18:03:18 +03:00
|
|
|
// DOMAIN[,DOMAIN].../IPSET_NAME[,IPSET_NAME]...
|
2021-06-18 17:55:01 +03:00
|
|
|
//
|
2024-07-03 15:38:37 +03:00
|
|
|
// If ipsetConf is empty, msg and err are nil. The error's chain contains
|
|
|
|
// [errors.ErrUnsupported] if current OS is not supported.
|
2023-10-11 17:31:41 +03:00
|
|
|
func NewManager(ipsetConf []string) (mgr Manager, err error) {
|
2021-12-27 20:54:00 +03:00
|
|
|
if len(ipsetConf) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-10-11 17:31:41 +03:00
|
|
|
return newManager(ipsetConf)
|
2021-06-18 17:55:01 +03:00
|
|
|
}
|