Merge pull request #90555 from andrewsykim/update-moby-ipvs

update github.com/moby/ipvs to v1.0.1 to fix IPVS compatiblity issue with older kernels
This commit is contained in:
Kubernetes Prow Robot 2020-05-01 00:40:51 -07:00 committed by GitHub
commit b6514880d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 6 deletions

4
go.mod
View File

@ -71,7 +71,7 @@ require (
github.com/lpabon/godbc v0.1.1 // indirect github.com/lpabon/godbc v0.1.1 // indirect
github.com/magiconair/properties v1.8.1 // indirect github.com/magiconair/properties v1.8.1 // indirect
github.com/miekg/dns v1.1.4 github.com/miekg/dns v1.1.4
github.com/moby/ipvs v1.0.0 github.com/moby/ipvs v1.0.1
github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb // indirect github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb // indirect
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
@ -329,7 +329,7 @@ replace (
github.com/mitchellh/go-homedir => github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir => github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-wordwrap => github.com/mitchellh/go-wordwrap v1.0.0 github.com/mitchellh/go-wordwrap => github.com/mitchellh/go-wordwrap v1.0.0
github.com/mitchellh/mapstructure => github.com/mitchellh/mapstructure v1.1.2 github.com/mitchellh/mapstructure => github.com/mitchellh/mapstructure v1.1.2
github.com/moby/ipvs => github.com/moby/ipvs v1.0.0 github.com/moby/ipvs => github.com/moby/ipvs v1.0.1
github.com/moby/term => github.com/moby/term v0.0.0-20200312100748-672ec06f55cd github.com/moby/term => github.com/moby/term v0.0.0-20200312100748-672ec06f55cd
github.com/modern-go/concurrent => github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd github.com/modern-go/concurrent => github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/reflect2 => github.com/modern-go/reflect2 v1.0.1 github.com/modern-go/reflect2 => github.com/modern-go/reflect2 v1.0.1

4
go.sum
View File

@ -315,8 +315,8 @@ github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/moby/ipvs v1.0.0 h1:89i8bPaL2DC0cjyRDv0QQOYUOU4fujziJmhF4ca/mtY= github.com/moby/ipvs v1.0.1 h1:aoZ7fhLTXgDbzVrAnvV+XbKOU8kOET7B3+xULDF/1o0=
github.com/moby/ipvs v1.0.0/go.mod h1:2pngiyseZbIKXNv7hsKj3O9UEz30c53MT9005gt2hxQ= github.com/moby/ipvs v1.0.1/go.mod h1:2pngiyseZbIKXNv7hsKj3O9UEz30c53MT9005gt2hxQ=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd h1:aY7OQNf2XqY/JQ6qREWamhI/81os/agb2BAGpcx5yWI= github.com/moby/term v0.0.0-20200312100748-672ec06f55cd h1:aY7OQNf2XqY/JQ6qREWamhI/81os/agb2BAGpcx5yWI=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo= github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=

View File

@ -5,6 +5,7 @@ package ipvs
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"net" "net"
"os/exec" "os/exec"
@ -449,7 +450,7 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
d.ActiveConnections = int(native.Uint16(attr.Value)) d.ActiveConnections = int(native.Uint16(attr.Value))
case ipvsDestAttrInactiveConnections: case ipvsDestAttrInactiveConnections:
d.InactiveConnections = int(native.Uint16(attr.Value)) d.InactiveConnections = int(native.Uint16(attr.Value))
case ipvsSvcAttrStats: case ipvsDestAttrStats:
stats, err := assembleStats(attr.Value) stats, err := assembleStats(attr.Value)
if err != nil { if err != nil {
return nil, err return nil, err
@ -458,6 +459,19 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
} }
} }
// in older kernels (< 3.18), the destination address family attribute doesn't exist so we must
// assume it based on the destination address provided.
if d.AddressFamily == 0 {
// we can't check the address family using net stdlib because netlink returns
// IPv4 addresses as the first 4 bytes in a []byte of length 16 where as
// stdlib expects it as the last 4 bytes.
addressFamily, err := getIPFamily(addressBytes)
if err != nil {
return nil, err
}
d.AddressFamily = addressFamily
}
// parse Address after parse AddressFamily incase of parseIP error // parse Address after parse AddressFamily incase of parseIP error
if addressBytes != nil { if addressBytes != nil {
ip, err := parseIP(addressBytes, d.AddressFamily) ip, err := parseIP(addressBytes, d.AddressFamily)
@ -470,6 +484,37 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
return &d, nil return &d, nil
} }
// getIPFamily parses the IP family based on raw data from netlink.
// For AF_INET, netlink will set the first 4 bytes with trailing zeros
// 10.0.0.1 -> [10 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]
// For AF_INET6, the full 16 byte array is used:
// 2001:db8:3c4d:15::1a00 -> [32 1 13 184 60 77 0 21 0 0 0 0 0 0 26 0]
func getIPFamily(address []byte) (uint16, error) {
if len(address) == 4 {
return syscall.AF_INET, nil
}
if isZeros(address) {
return 0, errors.New("could not parse IP family from address data")
}
// assume IPv4 if first 4 bytes are non-zero but rest of the data is trailing zeros
if !isZeros(address[:4]) && isZeros(address[4:]) {
return syscall.AF_INET, nil
}
return syscall.AF_INET6, nil
}
func isZeros(b []byte) bool {
for i := 0; i < len(b); i++ {
if b[i] != 0 {
return false
}
}
return true
}
// parseDestination given a ipvs netlink response this function will respond with a valid destination entry, an error otherwise // parseDestination given a ipvs netlink response this function will respond with a valid destination entry, an error otherwise
func (i *Handle) parseDestination(msg []byte) (*Destination, error) { func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
var dst *Destination var dst *Destination

2
vendor/modules.txt vendored
View File

@ -485,7 +485,7 @@ github.com/mistifyio/go-zfs
github.com/mitchellh/go-wordwrap github.com/mitchellh/go-wordwrap
# github.com/mitchellh/mapstructure v1.1.2 => github.com/mitchellh/mapstructure v1.1.2 # github.com/mitchellh/mapstructure v1.1.2 => github.com/mitchellh/mapstructure v1.1.2
github.com/mitchellh/mapstructure github.com/mitchellh/mapstructure
# github.com/moby/ipvs v1.0.0 => github.com/moby/ipvs v1.0.0 # github.com/moby/ipvs v1.0.1 => github.com/moby/ipvs v1.0.1
github.com/moby/ipvs github.com/moby/ipvs
# github.com/moby/term v0.0.0-20200312100748-672ec06f55cd => github.com/moby/term v0.0.0-20200312100748-672ec06f55cd # github.com/moby/term v0.0.0-20200312100748-672ec06f55cd => github.com/moby/term v0.0.0-20200312100748-672ec06f55cd
github.com/moby/term github.com/moby/term