From: Clément Chigot Date: Fri, 28 Sep 2018 13:50:01 +0000 (+0200) Subject: net: add AIX operating system X-Git-Tag: go1.12beta1~827 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9ff11b026089791c4d2bc14c17647f3cb4f4aa22;p=gostls13.git net: add AIX operating system This commit adds AIX operating system to net package for ppc64 architecture. Updates: #25893 Change-Id: I46bbc7b03931019beb969443cb3f9a756956c66c Reviewed-on: https://go-review.googlesource.com/c/138724 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/net/addrselect.go b/src/net/addrselect.go index 1ab9fc5326..7c0dfe261c 100644 --- a/src/net/addrselect.go +++ b/src/net/addrselect.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris // Minimal RFC 6724 address selection. diff --git a/src/net/conf.go b/src/net/conf.go index 127aba30cb..971b1a399a 100644 --- a/src/net/conf.go +++ b/src/net/conf.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris package net diff --git a/src/net/dial_unix_test.go b/src/net/dial_unix_test.go index 0adc10d0bd..3cfc9d81b8 100644 --- a/src/net/dial_unix_test.go +++ b/src/net/dial_unix_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris package net diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 9a0b1d69a8..3b0293025d 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris // DNS client: see RFC 1035. // Has to be linked into package net for Dial. diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 9482fc466f..7dccb6b8ec 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris package net diff --git a/src/net/dnsconfig_unix.go b/src/net/dnsconfig_unix.go index 64c66f96b8..842d408e56 100644 --- a/src/net/dnsconfig_unix.go +++ b/src/net/dnsconfig_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris // Read system DNS config from /etc/resolv.conf diff --git a/src/net/dnsconfig_unix_test.go b/src/net/dnsconfig_unix_test.go index 37bdeb04c8..0797559d1a 100644 --- a/src/net/dnsconfig_unix_test.go +++ b/src/net/dnsconfig_unix_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris package net diff --git a/src/net/error_posix.go b/src/net/error_posix.go index 0000700809..70efa4c66f 100644 --- a/src/net/error_posix.go +++ b/src/net/error_posix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows +// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows package net diff --git a/src/net/error_unix.go b/src/net/error_unix.go index b5a5829eaa..e615330388 100644 --- a/src/net/error_unix.go +++ b/src/net/error_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd js linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd js linux netbsd openbsd solaris package net diff --git a/src/net/fd_unix.go b/src/net/fd_unix.go index 055ecf0336..e7ab9a45fd 100644 --- a/src/net/fd_unix.go +++ b/src/net/fd_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris package net diff --git a/src/net/file_unix.go b/src/net/file_unix.go index 676798d693..452a079bfc 100644 --- a/src/net/file_unix.go +++ b/src/net/file_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris package net diff --git a/src/net/hook_unix.go b/src/net/hook_unix.go index d672bd01b0..a1568319f3 100644 --- a/src/net/hook_unix.go +++ b/src/net/hook_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris +// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris package net diff --git a/src/net/interface_aix.go b/src/net/interface_aix.go new file mode 100644 index 0000000000..8b70206206 --- /dev/null +++ b/src/net/interface_aix.go @@ -0,0 +1,165 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +import ( + //"os" + "syscall" + "unsafe" +) + +type RawSockaddrDatalink struct { + Len uint8 + Family uint8 + Index uint16 + Type uint8 + Nlen uint8 + Alen uint8 + Slen uint8 + Data [120]byte +} + +const _KINFO_RT_IFLIST = (0x1 << 8) | 3 | (1 << 30) + +const _RTAX_NETMASK = 2 +const _RTAX_IFA = 5 +const _RTAX_MAX = 8 + +func getIfList() ([]byte, error) { + needed, err := syscall.Getkerninfo(_KINFO_RT_IFLIST, 0, 0, 0) + if err != nil { + return nil, nil // XXX + } + tab := make([]byte, needed) + _, err = syscall.Getkerninfo(_KINFO_RT_IFLIST, uintptr(unsafe.Pointer(&tab[0])), uintptr(unsafe.Pointer(&needed)), 0) + if err != nil { + return nil, nil // XXX + } + return tab[:needed], nil +} + +// If the ifindex is zero, interfaceTable returns mappings of all +// network interfaces. Otherwise it returns a mapping of a specific +// interface. +func interfaceTable(ifindex int) ([]Interface, error) { + tab, err := getIfList() + if err != nil { + return nil, err + } + + var ift []Interface + for len(tab) > 0 { + ifm := (*syscall.IfMsgHdr)(unsafe.Pointer(&tab[0])) + if ifm.Msglen == 0 { + break + } + if ifm.Type == syscall.RTM_IFINFO { + if ifindex == 0 || ifindex == int(ifm.Index) { + sdl := (*RawSockaddrDatalink)(unsafe.Pointer(&tab[syscall.SizeofIfMsghdr])) + + ifi := &Interface{Index: int(ifm.Index), Flags: linkFlags(ifm.Flags)} + ifi.Name = string(sdl.Data[:sdl.Nlen]) + ifi.HardwareAddr = sdl.Data[sdl.Nlen : sdl.Nlen+sdl.Alen] + /* XXX MTU? */ + ift = append(ift, *ifi) + if ifindex == int(ifm.Index) { + break + } + } + } + tab = tab[ifm.Msglen:] + } + + return ift, nil +} + +func linkFlags(rawFlags int32) Flags { + var f Flags + if rawFlags&syscall.IFF_UP != 0 { + f |= FlagUp + } + if rawFlags&syscall.IFF_BROADCAST != 0 { + f |= FlagBroadcast + } + if rawFlags&syscall.IFF_LOOPBACK != 0 { + f |= FlagLoopback + } + if rawFlags&syscall.IFF_POINTOPOINT != 0 { + f |= FlagPointToPoint + } + if rawFlags&syscall.IFF_MULTICAST != 0 { + f |= FlagMulticast + } + return f +} + +// If the ifi is nil, interfaceAddrTable returns addresses for all +// network interfaces. Otherwise it returns addresses for a specific +// interface. +func interfaceAddrTable(ifi *Interface) ([]Addr, error) { + tab, err := getIfList() + if err != nil { + return nil, err + } + + var ifat []Addr + for len(tab) > 0 { + ifm := (*syscall.IfMsgHdr)(unsafe.Pointer(&tab[0])) + if ifm.Msglen == 0 { + break + } + if ifm.Type == syscall.RTM_NEWADDR { + if ifi == nil || ifi.Index == int(ifm.Index) { + mask := ifm.Addrs + off := uint(syscall.SizeofIfMsghdr) + + var iprsa, nmrsa *syscall.RawSockaddr + for i := uint(0); i < _RTAX_MAX; i++ { + if mask&(1<