mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
unix: migrate some illumos definitions to solaris
Fixes golang/go#56000 Change-Id: Ica6549385ddb466c4697cc45851e2b59fd6e0f24 Reviewed-on: https://go-review.googlesource.com/c/sys/+/437357 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
84dc82d7e8
commit
68d869b943
@@ -12,6 +12,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
@@ -331,3 +332,55 @@ func TestPortEventSlices(t *testing.T) {
|
||||
t.Errorf("port.Close() failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifreqSetName(t *testing.T) {
|
||||
var l unix.Lifreq
|
||||
err := l.SetName("12345678901234356789012345678901234567890")
|
||||
if err == nil {
|
||||
t.Fatal(`Lifreq.SetName should reject names that are too long`)
|
||||
}
|
||||
err = l.SetName("tun0")
|
||||
if err != nil {
|
||||
t.Errorf(`Lifreq.SetName("tun0") failed: %v`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifreqGetMTU(t *testing.T) {
|
||||
// Find links and their MTU using CLI tooling
|
||||
// $ dladm show-link -p -o link,mtu
|
||||
// net0:1500
|
||||
out, err := exec.Command("dladm", "show-link", "-p", "-o", "link,mtu").Output()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to use dladm to find data links: %v", err)
|
||||
}
|
||||
lines := strings.Split(string(out), "\n")
|
||||
tc := make(map[string]string)
|
||||
for _, line := range lines {
|
||||
v := strings.Split(line, ":")
|
||||
if len(v) == 2 {
|
||||
tc[v[0]] = v[1]
|
||||
}
|
||||
}
|
||||
ip_fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("could not open udp socket: %v", err)
|
||||
}
|
||||
// SIOCGLIFMTU is negative which confuses the compiler if used inline:
|
||||
// Using "unix.IoctlLifreq(ip_fd, unix.SIOCGLIFMTU, &l)" results in
|
||||
// "constant -1065850502 overflows uint"
|
||||
reqnum := int(unix.SIOCGLIFMTU)
|
||||
var l unix.Lifreq
|
||||
for link, mtu := range tc {
|
||||
err = l.SetName(link)
|
||||
if err != nil {
|
||||
t.Fatalf("Lifreq.SetName(%q) failed: %v", link, err)
|
||||
}
|
||||
if err = unix.IoctlLifreq(ip_fd, uint(reqnum), &l); err != nil {
|
||||
t.Fatalf("unable to SIOCGLIFMTU: %v", err)
|
||||
}
|
||||
m := l.GetLifruUint()
|
||||
if fmt.Sprintf("%d", m) != mtu {
|
||||
t.Errorf("unable to read MTU correctly: expected %s, got %d", mtu, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user