aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/netlink/rtnl_test.go
blob: 0d6290e8d215a732aca150496d227db7384def87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package netlink

import (
	"syscall"
	"testing"
)

func TestPayloadRTNETLINK(t *testing.T) {
	t.Parallel()

	checkPayload(t, []payloadTestCase{
		{"RTM_NEWADDR lo", func(c *Conn) {
			(&RouteConn{c}).writeNewaddrLo(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,
		}},

		{"RTM_NEWLINK", func(c *Conn) {
			c.seq++
			(&RouteConn{c}).writeIfInfomsg(
				syscall.RTM_NEWLINK, 0,
				&syscall.IfInfomsg{
					Family: syscall.AF_UNSPEC,
					Index:  1,
					Flags:  syscall.IFF_UP,
					Change: syscall.IFF_UP,
				},
			)
		}, []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,
		}},
	})
}