Skip to content

Commit

Permalink
pkg/netutil: use native byte ordering for route information
Browse files Browse the repository at this point in the history
Fixes #7199
  • Loading branch information
Anthony Romano committed Jan 20, 2017
1 parent e446c2c commit 1ada4f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/netutil/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !linux !386,!amd64
// +build !linux

package netutil

Expand Down
11 changes: 5 additions & 6 deletions pkg/netutil/routes_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// limitations under the License.

// +build linux
// +build 386 amd64

// TODO support native endian but without using "unsafe"

package netutil

Expand All @@ -25,6 +22,8 @@ import (
"fmt"
"net"
"syscall"

"github.com/coreos/etcd/pkg/cpuutil"
)

var errNoDefaultRoute = fmt.Errorf("could not find default route")
Expand Down Expand Up @@ -80,7 +79,7 @@ func getDefaultRoute() (*syscall.NetlinkMessage, error) {
continue
}
buf := bytes.NewBuffer(m.Data[:syscall.SizeofRtMsg])
if rerr := binary.Read(buf, binary.LittleEndian, &rtmsg); rerr != nil {
if rerr := binary.Read(buf, cpuutil.ByteOrder(), &rtmsg); rerr != nil {
continue
}
if rtmsg.Dst_len == 0 {
Expand Down Expand Up @@ -109,7 +108,7 @@ func getIface(idx uint32) (*syscall.NetlinkMessage, error) {
continue
}
buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfAddrmsg])
if rerr := binary.Read(buf, binary.LittleEndian, &ifaddrmsg); rerr != nil {
if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifaddrmsg); rerr != nil {
continue
}
if ifaddrmsg.Index == idx {
Expand Down Expand Up @@ -164,7 +163,7 @@ func parsePREFSRC(m *syscall.NetlinkMessage) (host string, oif uint32, err error
host = net.IP(attr.Value).String()
}
if attr.Attr.Type == syscall.RTA_OIF {
oif = binary.LittleEndian.Uint32(attr.Value)
oif = cpuutil.ByteOrder().Uint32(attr.Value)
}
if host != "" && oif != uint32(0) {
break
Expand Down

0 comments on commit 1ada4f9

Please sign in to comment.