Skip to content

Commit

Permalink
vendor: update golang_org/x/net/route package
Browse files Browse the repository at this point in the history
Update the route package to git rev 6b27048a.

Introduce the following changes:
 - 6b27048 route: drop support for go1.5
 - b7fd658 route: fix typo
 - 41bba8d route: add support for the manipulation of routing informaion

Updates #19967

Change-Id: Id2bb93df97a45254a2df2b048db0143e3e52bbdf
Reviewed-on: https://go-review.googlesource.com/40830
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
Andreas Auernhammer authored and bradfitz committed Apr 16, 2017
1 parent 0e4824a commit d71863a
Show file tree
Hide file tree
Showing 27 changed files with 602 additions and 125 deletions.
152 changes: 148 additions & 4 deletions src/vendor/golang_org/x/net/route/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@ type LinkAddr struct {
// Family implements the Family method of Addr interface.
func (a *LinkAddr) Family() int { return sysAF_LINK }

func (a *LinkAddr) lenAndSpace() (int, int) {
l := 8 + len(a.Name) + len(a.Addr)
return l, roundup(l)
}

func (a *LinkAddr) marshal(b []byte) (int, error) {
l, ll := a.lenAndSpace()
if len(b) < ll {
return 0, errShortBuffer
}
nlen, alen := len(a.Name), len(a.Addr)
if nlen > 255 || alen > 255 {
return 0, errInvalidAddr
}
b[0] = byte(l)
b[1] = sysAF_LINK
if a.Index > 0 {
nativeEndian.PutUint16(b[2:4], uint16(a.Index))
}
data := b[8:]
if nlen > 0 {
b[5] = byte(nlen)
copy(data[:nlen], a.Addr)
data = data[nlen:]
}
if alen > 0 {
b[6] = byte(alen)
copy(data[:alen], a.Name)
data = data[alen:]
}
return ll, nil
}

func parseLinkAddr(b []byte) (Addr, error) {
if len(b) < 8 {
return nil, errInvalidAddr
Expand Down Expand Up @@ -90,6 +123,21 @@ type Inet4Addr struct {
// Family implements the Family method of Addr interface.
func (a *Inet4Addr) Family() int { return sysAF_INET }

func (a *Inet4Addr) lenAndSpace() (int, int) {
return sizeofSockaddrInet, roundup(sizeofSockaddrInet)
}

func (a *Inet4Addr) marshal(b []byte) (int, error) {
l, ll := a.lenAndSpace()
if len(b) < ll {
return 0, errShortBuffer
}
b[0] = byte(l)
b[1] = sysAF_INET
copy(b[4:8], a.IP[:])
return ll, nil
}

// An Inet6Addr represents an internet address for IPv6.
type Inet6Addr struct {
IP [16]byte // IP address
Expand All @@ -99,18 +147,36 @@ type Inet6Addr struct {
// Family implements the Family method of Addr interface.
func (a *Inet6Addr) Family() int { return sysAF_INET6 }

func (a *Inet6Addr) lenAndSpace() (int, int) {
return sizeofSockaddrInet6, roundup(sizeofSockaddrInet6)
}

func (a *Inet6Addr) marshal(b []byte) (int, error) {
l, ll := a.lenAndSpace()
if len(b) < ll {
return 0, errShortBuffer
}
b[0] = byte(l)
b[1] = sysAF_INET6
copy(b[8:24], a.IP[:])
if a.ZoneID > 0 {
nativeEndian.PutUint32(b[24:28], uint32(a.ZoneID))
}
return ll, nil
}

// parseInetAddr parses b as an internet address for IPv4 or IPv6.
func parseInetAddr(af int, b []byte) (Addr, error) {
switch af {
case sysAF_INET:
if len(b) < 16 {
if len(b) < sizeofSockaddrInet {
return nil, errInvalidAddr
}
a := &Inet4Addr{}
copy(a.IP[:], b[4:8])
return a, nil
case sysAF_INET6:
if len(b) < 28 {
if len(b) < sizeofSockaddrInet6 {
return nil, errInvalidAddr
}
a := &Inet6Addr{ZoneID: int(nativeEndian.Uint32(b[24:28]))}
Expand Down Expand Up @@ -174,7 +240,7 @@ func parseKernelInetAddr(af int, b []byte) (int, Addr, error) {
off6 = 8 // offset of in6_addr
)
switch {
case b[0] == 28: // size of sockaddr_in6
case b[0] == sizeofSockaddrInet6:
a := &Inet6Addr{}
copy(a.IP[:], b[off6:off6+16])
return int(b[0]), a, nil
Expand All @@ -186,7 +252,7 @@ func parseKernelInetAddr(af int, b []byte) (int, Addr, error) {
copy(a.IP[:], b[l-off6:l])
}
return int(b[0]), a, nil
case b[0] == 16: // size of sockaddr_in
case b[0] == sizeofSockaddrInet:
a := &Inet4Addr{}
copy(a.IP[:], b[off4:off4+4])
return int(b[0]), a, nil
Expand All @@ -211,6 +277,24 @@ type DefaultAddr struct {
// Family implements the Family method of Addr interface.
func (a *DefaultAddr) Family() int { return a.af }

func (a *DefaultAddr) lenAndSpace() (int, int) {
l := len(a.Raw)
return l, roundup(l)
}

func (a *DefaultAddr) marshal(b []byte) (int, error) {
l, ll := a.lenAndSpace()
if len(b) < ll {
return 0, errShortBuffer
}
if l > 255 {
return 0, errInvalidAddr
}
b[1] = byte(l)
copy(b[:l], a.Raw)
return ll, nil
}

func parseDefaultAddr(b []byte) (Addr, error) {
if len(b) < 2 || len(b) < int(b[0]) {
return nil, errInvalidAddr
Expand All @@ -219,6 +303,66 @@ func parseDefaultAddr(b []byte) (Addr, error) {
return a, nil
}

func addrsSpace(as []Addr) int {
var l int
for _, a := range as {
switch a := a.(type) {
case *LinkAddr:
_, ll := a.lenAndSpace()
l += ll
case *Inet4Addr:
_, ll := a.lenAndSpace()
l += ll
case *Inet6Addr:
_, ll := a.lenAndSpace()
l += ll
case *DefaultAddr:
_, ll := a.lenAndSpace()
l += ll
}
}
return l
}

// marshalAddrs marshals as and returns a bitmap indicating which
// address is stored in b.
func marshalAddrs(b []byte, as []Addr) (uint, error) {
var attrs uint
for i, a := range as {
switch a := a.(type) {
case *LinkAddr:
l, err := a.marshal(b)
if err != nil {
return 0, err
}
b = b[l:]
attrs |= 1 << uint(i)
case *Inet4Addr:
l, err := a.marshal(b)
if err != nil {
return 0, err
}
b = b[l:]
attrs |= 1 << uint(i)
case *Inet6Addr:
l, err := a.marshal(b)
if err != nil {
return 0, err
}
b = b[l:]
attrs |= 1 << uint(i)
case *DefaultAddr:
l, err := a.marshal(b)
if err != nil {
return 0, err
}
b = b[l:]
attrs |= 1 << uint(i)
}
}
return attrs, nil
}

func parseAddrs(attrs uint, fn func(int, []byte) (int, Addr, error), b []byte) ([]Addr, error) {
var as [sysRTAX_MAX]Addr
af := int(sysAF_UNSPEC)
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/golang_org/x/net/route/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package route
// This file contains duplicates of encoding/binary package.
//
// This package is supposed to be used by the net package of standard
// library. Therefore a package set used in the package must be the
// library. Therefore the package set used in the package must be the
// same as net package.

var (
Expand Down
8 changes: 8 additions & 0 deletions src/vendor/golang_org/x/net/route/defs_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package route
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
*/
import "C"

Expand All @@ -23,6 +25,8 @@ const (
sysAF_LINK = C.AF_LINK
sysAF_INET6 = C.AF_INET6

sysSOCK_RAW = C.SOCK_RAW

sysNET_RT_DUMP = C.NET_RT_DUMP
sysNET_RT_FLAGS = C.NET_RT_FLAGS
sysNET_RT_IFLIST = C.NET_RT_IFLIST
Expand Down Expand Up @@ -103,4 +107,8 @@ const (
sizeofRtMsghdrDarwin15 = C.sizeof_struct_rt_msghdr
sizeofRtMsghdr2Darwin15 = C.sizeof_struct_rt_msghdr2
sizeofRtMetricsDarwin15 = C.sizeof_struct_rt_metrics

sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
)
8 changes: 8 additions & 0 deletions src/vendor/golang_org/x/net/route/defs_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package route
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
*/
import "C"

Expand All @@ -23,6 +25,8 @@ const (
sysAF_LINK = C.AF_LINK
sysAF_INET6 = C.AF_INET6

sysSOCK_RAW = C.SOCK_RAW

sysNET_RT_DUMP = C.NET_RT_DUMP
sysNET_RT_FLAGS = C.NET_RT_FLAGS
sysNET_RT_IFLIST = C.NET_RT_IFLIST
Expand Down Expand Up @@ -102,4 +106,8 @@ const (

sizeofRtMsghdrDragonFlyBSD4 = C.sizeof_struct_rt_msghdr
sizeofRtMetricsDragonFlyBSD4 = C.sizeof_struct_rt_metrics

sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
)
8 changes: 8 additions & 0 deletions src/vendor/golang_org/x/net/route/defs_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package route
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
struct if_data_freebsd7 {
u_char ifi_type;
u_char ifi_physical;
Expand Down Expand Up @@ -222,6 +224,8 @@ const (
sysAF_LINK = C.AF_LINK
sysAF_INET6 = C.AF_INET6

sysSOCK_RAW = C.SOCK_RAW

sysNET_RT_DUMP = C.NET_RT_DUMP
sysNET_RT_FLAGS = C.NET_RT_FLAGS
sysNET_RT_IFLIST = C.NET_RT_IFLIST
Expand Down Expand Up @@ -326,4 +330,8 @@ const (
sizeofIfDataFreeBSD9Emu = C.sizeof_struct_if_data_freebsd9
sizeofIfDataFreeBSD10Emu = C.sizeof_struct_if_data_freebsd10
sizeofIfDataFreeBSD11Emu = C.sizeof_struct_if_data_freebsd11

sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
)
8 changes: 8 additions & 0 deletions src/vendor/golang_org/x/net/route/defs_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package route
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
*/
import "C"

Expand All @@ -23,6 +25,8 @@ const (
sysAF_LINK = C.AF_LINK
sysAF_INET6 = C.AF_INET6

sysSOCK_RAW = C.SOCK_RAW

sysNET_RT_DUMP = C.NET_RT_DUMP
sysNET_RT_FLAGS = C.NET_RT_FLAGS
sysNET_RT_IFLIST = C.NET_RT_IFLIST
Expand Down Expand Up @@ -101,4 +105,8 @@ const (

sizeofRtMsghdrNetBSD7 = C.sizeof_struct_rt_msghdr
sizeofRtMetricsNetBSD7 = C.sizeof_struct_rt_metrics

sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
)
12 changes: 12 additions & 0 deletions src/vendor/golang_org/x/net/route/defs_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package route
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <netinet/in.h>
*/
import "C"

Expand All @@ -23,6 +25,8 @@ const (
sysAF_LINK = C.AF_LINK
sysAF_INET6 = C.AF_INET6

sysSOCK_RAW = C.SOCK_RAW

sysNET_RT_DUMP = C.NET_RT_DUMP
sysNET_RT_FLAGS = C.NET_RT_FLAGS
sysNET_RT_IFLIST = C.NET_RT_IFLIST
Expand Down Expand Up @@ -91,3 +95,11 @@ const (
sysRTAX_LABEL = C.RTAX_LABEL
sysRTAX_MAX = C.RTAX_MAX
)

const (
sizeofRtMsghdr = C.sizeof_struct_rt_msghdr

sizeofSockaddrStorage = C.sizeof_struct_sockaddr_storage
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
)
8 changes: 2 additions & 6 deletions src/vendor/golang_org/x/net/route/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
package route

// A Message represents a routing message.
//
// Note: This interface will be changed to support Marshal method in
// future version.
type Message interface {
// Sys returns operating system-specific information.
Sys() []Sys
Expand Down Expand Up @@ -52,11 +49,10 @@ func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
b = b[l:]
continue
}
mtyp := int(b[3])
if fn, ok := parseFns[mtyp]; !ok {
if w, ok := wireFormats[int(b[3])]; !ok {
nskips++
} else {
m, err := fn(typ, b)
m, err := w.parse(typ, b)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit d71863a

Please sign in to comment.