aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/netlink_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-11 03:32:21 +0900
committerOphestra <cat@gensokyo.uk>2026-01-11 03:36:20 +0900
commit2494ede1067d5071d3cc7d355cdc2ae3fac66dc5 (patch)
tree77cd8ef4785a83918f78389ce05011b0fc14bd97 /container/netlink_test.go
parentda3848b92f22259d97b1d3851e17d1a8c6ffeb3d (diff)
container/init: configure interface lo
This enables loopback networking when owning the net namespace. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/netlink_test.go')
-rw-r--r--container/netlink_test.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/container/netlink_test.go b/container/netlink_test.go
new file mode 100644
index 00000000..8ecc8ea0
--- /dev/null
+++ b/container/netlink_test.go
@@ -0,0 +1,72 @@
+package container
+
+import (
+ "testing"
+ "unsafe"
+)
+
+func TestSizeof(t *testing.T) {
+ if got := unsafe.Sizeof(newaddrLo{}); got != sizeofNewaddrLo {
+ t.Fatalf("newaddrLo: sizeof = %#x, want %#x", got, sizeofNewaddrLo)
+ }
+
+ if got := unsafe.Sizeof(newlinkLo{}); got != sizeofNewlinkLo {
+ t.Fatalf("newlinkLo: sizeof = %#x, want %#x", got, sizeofNewlinkLo)
+ }
+}
+
+func TestRtnetlinkMessage(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ msg interface{ toWireFormat() []byte }
+ want []byte
+ }{
+ {"newaddrLo", (&rtnetlink{pid: 1, seq: 0}).newaddrLo(1), []byte{
+ /* Len */ 0x28, 0, 0, 0,
+ /* Type */ 0x14, 0,
+ /* Flags */ 5, 6,
+ /* Seq */ 0, 0, 0, 0,
+ /* Pid */ 1, 0, 0, 0,
+
+ /* Family */ 2,
+ /* Prefixlen */ 8,
+ /* Flags */ 0x80,
+ /* Scope */ 0xfe,
+ /* Index */ 1, 0, 0, 0,
+
+ /* Len */ 8, 0,
+ /* Type */ 2, 0,
+ /* in_addr */ 127, 0, 0, 1,
+
+ /* Len */ 8, 0,
+ /* Type */ 1, 0,
+ /* in_addr */ 127, 0, 0, 1,
+ }},
+
+ {"newlinkLo", (&rtnetlink{pid: 1, seq: 1}).newlinkLo(1), []byte{
+ /* Len */ 0x20, 0, 0, 0,
+ /* Type */ 0x10, 0,
+ /* Flags */ 5, 0,
+ /* Seq */ 1, 0, 0, 0,
+ /* Pid */ 1, 0, 0, 0,
+
+ /* Family */ 0,
+ /* pad */ 0,
+ /* Type */ 0, 0,
+ /* Index */ 1, 0, 0, 0,
+ /* Flags */ 1, 0, 0, 0,
+ /* Change */ 1, 0, 0, 0,
+ }},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ if got := tc.msg.toWireFormat(); string(got) != string(tc.want) {
+ t.Fatalf("toWireFormat: %#v, want %#v", got, tc.want)
+ }
+ })
+ }
+}