8cadff2b79
* CNI: bump to 1.0.1 This commit bumps the declared version of CNI in the Kilo manifests to 1.0.1. This is possible with no changes to the configuration lists because our simple configuration is not affected by any of the deprecations, and there was effectively no change between 0.4.0 and 1.0.0, other than the declaration of a stable API. Similarly, this commit also bumps the version of the CNI library and the plugins package. Bumping to CNI 1.0.0 will help ensure that Kilo stays compatible with container runtimes in the future. Signed-off-by: Lucas Servén Marín <lserven@gmail.com> * vendor: revendor Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package netlink
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
// Addr represents an IP address from netlink. Netlink ip addresses
|
|
// include a mask, so it stores the address as a net.IPNet.
|
|
type Addr struct {
|
|
*net.IPNet
|
|
Label string
|
|
Flags int
|
|
Scope int
|
|
Peer *net.IPNet
|
|
Broadcast net.IP
|
|
PreferedLft int
|
|
ValidLft int
|
|
LinkIndex int
|
|
}
|
|
|
|
// String returns $ip/$netmask $label
|
|
func (a Addr) String() string {
|
|
return strings.TrimSpace(fmt.Sprintf("%s %s", a.IPNet, a.Label))
|
|
}
|
|
|
|
// ParseAddr parses the string representation of an address in the
|
|
// form $ip/$netmask $label. The label portion is optional
|
|
func ParseAddr(s string) (*Addr, error) {
|
|
label := ""
|
|
parts := strings.Split(s, " ")
|
|
if len(parts) > 1 {
|
|
s = parts[0]
|
|
label = parts[1]
|
|
}
|
|
m, err := ParseIPNet(s)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Addr{IPNet: m, Label: label}, nil
|
|
}
|
|
|
|
// Equal returns true if both Addrs have the same net.IPNet value.
|
|
func (a Addr) Equal(x Addr) bool {
|
|
sizea, _ := a.Mask.Size()
|
|
sizeb, _ := x.Mask.Size()
|
|
// ignore label for comparison
|
|
return a.IP.Equal(x.IP) && sizea == sizeb
|
|
}
|
|
|
|
func (a Addr) PeerEqual(x Addr) bool {
|
|
sizea, _ := a.Peer.Mask.Size()
|
|
sizeb, _ := x.Peer.Mask.Size()
|
|
// ignore label for comparison
|
|
return a.Peer.IP.Equal(x.Peer.IP) && sizea == sizeb
|
|
}
|