Small vendor update for go-sockaddr: now able to filter by CIDR.

This commit is contained in:
Sean Chittenden 2016-12-03 01:21:34 +11:00
parent f0ab957711
commit cf02ce2033
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
2 changed files with 36 additions and 7 deletions

View File

@ -486,7 +486,10 @@ func IfByType(inputTypes string, ifAddrs IfAddrs) (matched, remainder IfAddrs, e
ifTypes := strings.Split(strings.ToLower(inputTypes), "|")
for _, ifType := range ifTypes {
if ifType != "ip" && ifType != "ipv4" && ifType != "ipv6" && ifType != "unix" {
switch ifType {
case "ip", "ipv4", "ipv6", "unix":
// Valid types
default:
return nil, nil, fmt.Errorf("unsupported type %q %q", ifType, inputTypes)
}
}
@ -622,6 +625,28 @@ func IfByFlag(inputFlags string, ifAddrs IfAddrs) (matched, remainder IfAddrs, e
return matchedAddrs, excludedAddrs, nil
}
// IfByNetwork returns an IfAddrs that are equal to or included within the
// network passed in by selector.
func IfByNetwork(selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, IfAddrs, error) {
var includedIfs, excludedIfs IfAddrs
for _, netStr := range strings.Split(selectorParam, "|") {
netAddr, err := NewIPAddr(netStr)
if err != nil {
return nil, nil, fmt.Errorf("unable to create an IP address from %+q: %v", netStr, err)
}
for _, ifAddr := range inputIfAddrs {
if netAddr.Contains(ifAddr.SockAddr) {
includedIfs = append(includedIfs, ifAddr)
} else {
excludedIfs = append(excludedIfs, ifAddr)
}
}
}
return includedIfs, excludedIfs, nil
}
// IncludeIfs returns an IfAddrs based on the passed in selector.
func IncludeIfs(selectorName, selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, error) {
var includedIfs IfAddrs
@ -634,6 +659,8 @@ func IncludeIfs(selectorName, selectorParam string, inputIfAddrs IfAddrs) (IfAdd
includedIfs, _, err = IfByFlag(selectorParam, inputIfAddrs)
case "name":
includedIfs, _, err = IfByName(selectorParam, inputIfAddrs)
case "network":
includedIfs, _, err = IfByNetwork(selectorParam, inputIfAddrs)
case "port":
includedIfs, _, err = IfByPort(selectorParam, inputIfAddrs)
case "rfc", "rfcs":
@ -665,6 +692,8 @@ func ExcludeIfs(selectorName, selectorParam string, inputIfAddrs IfAddrs) (IfAdd
_, excludedIfs, err = IfByFlag(selectorParam, inputIfAddrs)
case "name":
_, excludedIfs, err = IfByName(selectorParam, inputIfAddrs)
case "network":
_, excludedIfs, err = IfByNetwork(selectorParam, inputIfAddrs)
case "port":
_, excludedIfs, err = IfByPort(selectorParam, inputIfAddrs)
case "rfc", "rfcs":

12
vendor/vendor.json vendored
View File

@ -420,16 +420,16 @@
"revisionTime": "2016-09-30T03:51:02Z"
},
{
"checksumSHA1": "LmCRW89WaBzau5RaVIhx8QHwLYo=",
"checksumSHA1": "gnhc8egaCa7Ue516rnQkfutdBO8=",
"path": "github.com/hashicorp/go-sockaddr",
"revision": "33afa667d8f9a6ca9d435a8f8c6e87af423c9356",
"revisionTime": "2016-12-02T07:02:37Z"
"revision": "af174a6fe6c9f9a049a638e1dae7bc4442c4d426",
"revisionTime": "2016-12-02T14:18:37Z"
},
{
"checksumSHA1": "Y+c+ahUug8/vK+cWRLatV5aB4ps=",
"checksumSHA1": "lPzwetgfMBtpHqdTPolgejMctVQ=",
"path": "github.com/hashicorp/go-sockaddr/template",
"revision": "a99c57b5a5f48c51607e63089075fe7434fe219a",
"revisionTime": "2016-12-02T03:16:41Z"
"revision": "af174a6fe6c9f9a049a638e1dae7bc4442c4d426",
"revisionTime": "2016-12-02T14:18:37Z"
},
{
"checksumSHA1": "xZ7Ban1x//6uUIU1xtrTbCYNHBc=",