diff options
Diffstat (limited to 'src/pkg/syscall/netlink_linux.go')
| -rw-r--r-- | src/pkg/syscall/netlink_linux.go | 43 | 
1 files changed, 20 insertions, 23 deletions
| diff --git a/src/pkg/syscall/netlink_linux.go b/src/pkg/syscall/netlink_linux.go index 62d9e15e2..dc0f68470 100644 --- a/src/pkg/syscall/netlink_linux.go +++ b/src/pkg/syscall/netlink_linux.go @@ -63,31 +63,28 @@ func newNetlinkRouteRequest(proto, seq, family int) []byte {  // NetlinkRIB returns routing information base, as known as RIB,  // which consists of network facility information, states and  // parameters. -func NetlinkRIB(proto, family int) ([]byte, int) { +func NetlinkRIB(proto, family int) ([]byte, error) {  	var ( -		s     int -		e     int  		lsanl SockaddrNetlink -		seq   int  		tab   []byte  	) -	s, e = Socket(AF_NETLINK, SOCK_RAW, 0) -	if e != 0 { +	s, e := Socket(AF_NETLINK, SOCK_RAW, 0) +	if e != nil {  		return nil, e  	}  	defer Close(s)  	lsanl.Family = AF_NETLINK  	e = Bind(s, &lsanl) -	if e != 0 { +	if e != nil {  		return nil, e  	} -	seq++ +	seq := 1  	wb := newNetlinkRouteRequest(proto, seq, family)  	e = Sendto(s, wb, 0, &lsanl) -	if e != 0 { +	if e != nil {  		return nil, e  	} @@ -100,7 +97,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {  		rb = make([]byte, Getpagesize())  		nr, _, e = Recvfrom(s, rb, 0) -		if e != 0 { +		if e != nil {  			return nil, e  		}  		if nr < NLMSG_HDRLEN { @@ -111,7 +108,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {  		msgs, _ := ParseNetlinkMessage(rb)  		for _, m := range msgs { -			if lsa, e = Getsockname(s); e != 0 { +			if lsa, e = Getsockname(s); e != nil {  				return nil, e  			}  			switch v := lsa.(type) { @@ -132,7 +129,7 @@ func NetlinkRIB(proto, family int) ([]byte, int) {  	}  done: -	return tab, 0 +	return tab, nil  }  // NetlinkMessage represents the netlink message. @@ -143,18 +140,18 @@ type NetlinkMessage struct {  // ParseNetlinkMessage parses buf as netlink messages and returns  // the slice containing the NetlinkMessage structs. -func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) { +func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, error) {  	var (  		h    *NlMsghdr  		dbuf []byte  		dlen int -		e    int +		e    error  		msgs []NetlinkMessage  	)  	for len(buf) >= NLMSG_HDRLEN {  		h, dbuf, dlen, e = netlinkMessageHeaderAndData(buf) -		if e != 0 { +		if e != nil {  			break  		}  		m := NetlinkMessage{} @@ -167,12 +164,12 @@ func ParseNetlinkMessage(buf []byte) ([]NetlinkMessage, int) {  	return msgs, e  } -func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, int) { +func netlinkMessageHeaderAndData(buf []byte) (*NlMsghdr, []byte, int, error) {  	h := (*NlMsghdr)(unsafe.Pointer(&buf[0]))  	if h.Len < NLMSG_HDRLEN || int(h.Len) > len(buf) {  		return nil, nil, 0, EINVAL  	} -	return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), 0 +	return h, buf[NLMSG_HDRLEN:], nlmAlignOf(int(h.Len)), nil  }  // NetlinkRouteAttr represents the netlink route attribute. @@ -184,13 +181,13 @@ type NetlinkRouteAttr struct {  // ParseNetlinkRouteAttr parses msg's payload as netlink route  // attributes and returns the slice containing the NetlinkRouteAttr  // structs. -func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) { +func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, error) {  	var (  		buf   []byte  		a     *RtAttr  		alen  int  		vbuf  []byte -		e     int +		e     error  		attrs []NetlinkRouteAttr  	) @@ -207,7 +204,7 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) {  	for len(buf) >= SizeofRtAttr {  		a, vbuf, alen, e = netlinkRouteAttrAndValue(buf) -		if e != 0 { +		if e != nil {  			break  		}  		ra := NetlinkRouteAttr{} @@ -217,13 +214,13 @@ func ParseNetlinkRouteAttr(msg *NetlinkMessage) ([]NetlinkRouteAttr, int) {  		buf = buf[alen:]  	} -	return attrs, 0 +	return attrs, nil  } -func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, int) { +func netlinkRouteAttrAndValue(buf []byte) (*RtAttr, []byte, int, error) {  	h := (*RtAttr)(unsafe.Pointer(&buf[0]))  	if h.Len < SizeofRtAttr || int(h.Len) > len(buf) {  		return nil, nil, 0, EINVAL  	} -	return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), 0 +	return h, buf[SizeofRtAttr:], rtaAlignOf(int(h.Len)), nil  } | 
