build: update github.com/vishvananda/netlink to 1.3.0
This includes a breaking change:
acdc658b86
route.Dst is now a zero IPNet instead of nil
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
This commit is contained in:
115
vendor/github.com/vishvananda/netlink/ipset_linux.go
generated
vendored
115
vendor/github.com/vishvananda/netlink/ipset_linux.go
generated
vendored
@ -67,11 +67,13 @@ type IpsetCreateOptions struct {
|
||||
Comments bool
|
||||
Skbinfo bool
|
||||
|
||||
Revision uint8
|
||||
IPFrom net.IP
|
||||
IPTo net.IP
|
||||
PortFrom uint16
|
||||
PortTo uint16
|
||||
Family uint8
|
||||
Revision uint8
|
||||
IPFrom net.IP
|
||||
IPTo net.IP
|
||||
PortFrom uint16
|
||||
PortTo uint16
|
||||
MaxElements uint32
|
||||
}
|
||||
|
||||
// IpsetProtocol returns the ipset protocol version from the kernel
|
||||
@ -94,6 +96,11 @@ func IpsetFlush(setname string) error {
|
||||
return pkgHandle.IpsetFlush(setname)
|
||||
}
|
||||
|
||||
// IpsetSwap swaps two ipsets.
|
||||
func IpsetSwap(setname, othersetname string) error {
|
||||
return pkgHandle.IpsetSwap(setname, othersetname)
|
||||
}
|
||||
|
||||
// IpsetList dumps an specific ipset.
|
||||
func IpsetList(setname string) (*IPSetResult, error) {
|
||||
return pkgHandle.IpsetList(setname)
|
||||
@ -114,6 +121,11 @@ func IpsetDel(setname string, entry *IPSetEntry) error {
|
||||
return pkgHandle.IpsetDel(setname, entry)
|
||||
}
|
||||
|
||||
// IpsetTest tests whether an entry is in a set or not.
|
||||
func IpsetTest(setname string, entry *IPSetEntry) (bool, error) {
|
||||
return pkgHandle.IpsetTest(setname, entry)
|
||||
}
|
||||
|
||||
func (h *Handle) IpsetProtocol() (protocol uint8, minVersion uint8, err error) {
|
||||
req := h.newIpsetRequest(nl.IPSET_CMD_PROTOCOL)
|
||||
msgs, err := req.Execute(unix.NETLINK_NETFILTER, 0)
|
||||
@ -153,11 +165,18 @@ func (h *Handle) IpsetCreate(setname, typename string, options IpsetCreateOption
|
||||
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_PORT_FROM|int(nl.NLA_F_NET_BYTEORDER), buf[:2]))
|
||||
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_PORT_TO|int(nl.NLA_F_NET_BYTEORDER), buf[2:]))
|
||||
default:
|
||||
family = unix.AF_INET
|
||||
family = options.Family
|
||||
if family == 0 {
|
||||
family = unix.AF_INET
|
||||
}
|
||||
}
|
||||
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_FAMILY, nl.Uint8Attr(family)))
|
||||
|
||||
if options.MaxElements != 0 {
|
||||
data.AddChild(&nl.Uint32Attribute{Type: nl.IPSET_ATTR_MAXELEM | nl.NLA_F_NET_BYTEORDER, Value: options.MaxElements})
|
||||
}
|
||||
|
||||
if timeout := options.Timeout; timeout != nil {
|
||||
data.AddChild(&nl.Uint32Attribute{Type: nl.IPSET_ATTR_TIMEOUT | nl.NLA_F_NET_BYTEORDER, Value: *timeout})
|
||||
}
|
||||
@ -197,6 +216,14 @@ func (h *Handle) IpsetFlush(setname string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (h *Handle) IpsetSwap(setname, othersetname string) error {
|
||||
req := h.newIpsetRequest(nl.IPSET_CMD_SWAP)
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(setname)))
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_TYPENAME, nl.ZeroTerminated(othersetname)))
|
||||
_, err := ipsetExecute(req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (h *Handle) IpsetList(name string) (*IPSetResult, error) {
|
||||
req := h.newIpsetRequest(nl.IPSET_CMD_LIST)
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(name)))
|
||||
@ -236,18 +263,23 @@ func (h *Handle) IpsetDel(setname string, entry *IPSetEntry) error {
|
||||
return h.ipsetAddDel(nl.IPSET_CMD_DEL, setname, entry)
|
||||
}
|
||||
|
||||
func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error {
|
||||
req := h.newIpsetRequest(nlCmd)
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(setname)))
|
||||
|
||||
if entry.Comment != "" {
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_COMMENT, nl.ZeroTerminated(entry.Comment)))
|
||||
func encodeIP(ip net.IP) (*nl.RtAttr, error) {
|
||||
typ := int(nl.NLA_F_NET_BYTEORDER)
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
typ |= nl.IPSET_ATTR_IPADDR_IPV4
|
||||
ip = ip4
|
||||
} else {
|
||||
typ |= nl.IPSET_ATTR_IPADDR_IPV6
|
||||
}
|
||||
|
||||
return nl.NewRtAttr(typ, ip), nil
|
||||
}
|
||||
|
||||
func buildEntryData(entry *IPSetEntry) (*nl.RtAttr, error) {
|
||||
data := nl.NewRtAttr(nl.IPSET_ATTR_DATA|int(nl.NLA_F_NESTED), nil)
|
||||
|
||||
if !entry.Replace {
|
||||
req.Flags |= unix.NLM_F_EXCL
|
||||
if entry.Comment != "" {
|
||||
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_COMMENT, nl.ZeroTerminated(entry.Comment)))
|
||||
}
|
||||
|
||||
if entry.Timeout != nil {
|
||||
@ -255,7 +287,10 @@ func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error
|
||||
}
|
||||
|
||||
if entry.IP != nil {
|
||||
nestedData := nl.NewRtAttr(nl.IPSET_ATTR_IP|int(nl.NLA_F_NET_BYTEORDER), entry.IP)
|
||||
nestedData, err := encodeIP(entry.IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_IP|int(nl.NLA_F_NESTED), nestedData.Serialize()))
|
||||
}
|
||||
|
||||
@ -268,7 +303,10 @@ func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error
|
||||
}
|
||||
|
||||
if entry.IP2 != nil {
|
||||
nestedData := nl.NewRtAttr(nl.IPSET_ATTR_IP|int(nl.NLA_F_NET_BYTEORDER), entry.IP2)
|
||||
nestedData, err := encodeIP(entry.IP2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_IP2|int(nl.NLA_F_NESTED), nestedData.Serialize()))
|
||||
}
|
||||
|
||||
@ -295,14 +333,53 @@ func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error
|
||||
if entry.Mark != nil {
|
||||
data.AddChild(&nl.Uint32Attribute{Type: nl.IPSET_ATTR_MARK | nl.NLA_F_NET_BYTEORDER, Value: *entry.Mark})
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error {
|
||||
req := h.newIpsetRequest(nlCmd)
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(setname)))
|
||||
|
||||
if !entry.Replace {
|
||||
req.Flags |= unix.NLM_F_EXCL
|
||||
}
|
||||
|
||||
data, err := buildEntryData(entry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data.AddChild(&nl.Uint32Attribute{Type: nl.IPSET_ATTR_LINENO | nl.NLA_F_NET_BYTEORDER, Value: 0})
|
||||
req.AddData(data)
|
||||
|
||||
_, err := ipsetExecute(req)
|
||||
_, err = ipsetExecute(req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (h *Handle) IpsetTest(setname string, entry *IPSetEntry) (bool, error) {
|
||||
req := h.newIpsetRequest(nl.IPSET_CMD_TEST)
|
||||
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(setname)))
|
||||
|
||||
if !entry.Replace {
|
||||
req.Flags |= unix.NLM_F_EXCL
|
||||
}
|
||||
|
||||
data, err := buildEntryData(entry)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
req.AddData(data)
|
||||
|
||||
_, err = ipsetExecute(req)
|
||||
if err != nil {
|
||||
if err == nl.IPSetError(nl.IPSET_ERR_EXIST) {
|
||||
// not exist
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (h *Handle) newIpsetRequest(cmd int) *nl.NetlinkRequest {
|
||||
req := h.newNetlinkRequest(cmd|(unix.NFNL_SUBSYS_IPSET<<8), nl.GetIpsetFlags(cmd))
|
||||
|
||||
@ -466,7 +543,7 @@ func parseIPSetEntry(data []byte) (entry IPSetEntry) {
|
||||
case nl.IPSET_ATTR_IP | nl.NLA_F_NESTED:
|
||||
for attr := range nl.ParseAttributes(attr.Value) {
|
||||
switch attr.Type {
|
||||
case nl.IPSET_ATTR_IP:
|
||||
case nl.IPSET_ATTR_IPADDR_IPV4, nl.IPSET_ATTR_IPADDR_IPV6:
|
||||
entry.IP = net.IP(attr.Value)
|
||||
default:
|
||||
log.Printf("unknown nested ADT attribute from kernel: %+v", attr)
|
||||
@ -475,7 +552,7 @@ func parseIPSetEntry(data []byte) (entry IPSetEntry) {
|
||||
case nl.IPSET_ATTR_IP2 | nl.NLA_F_NESTED:
|
||||
for attr := range nl.ParseAttributes(attr.Value) {
|
||||
switch attr.Type {
|
||||
case nl.IPSET_ATTR_IP:
|
||||
case nl.IPSET_ATTR_IPADDR_IPV4, nl.IPSET_ATTR_IPADDR_IPV6:
|
||||
entry.IP2 = net.IP(attr.Value)
|
||||
default:
|
||||
log.Printf("unknown nested ADT attribute from kernel: %+v", attr)
|
||||
|
Reference in New Issue
Block a user