...
1 package libcontainer
2
3 import (
4 "fmt"
5 "math"
6
7 "github.com/vishvananda/netlink/nl"
8 "golang.org/x/sys/unix"
9 )
10
11
12
13 const (
14 InitMsg uint16 = 62000
15 CloneFlagsAttr uint16 = 27281
16 NsPathsAttr uint16 = 27282
17 UidmapAttr uint16 = 27283
18 GidmapAttr uint16 = 27284
19 SetgroupAttr uint16 = 27285
20 OomScoreAdjAttr uint16 = 27286
21 RootlessEUIDAttr uint16 = 27287
22 UidmapPathAttr uint16 = 27288
23 GidmapPathAttr uint16 = 27289
24 MountSourcesAttr uint16 = 27290
25 )
26
27 type Int32msg struct {
28 Type uint16
29 Value uint32
30 }
31
32
33
34
35
36 func (msg *Int32msg) Serialize() []byte {
37 buf := make([]byte, msg.Len())
38 native := nl.NativeEndian()
39 native.PutUint16(buf[0:2], uint16(msg.Len()))
40 native.PutUint16(buf[2:4], msg.Type)
41 native.PutUint32(buf[4:8], msg.Value)
42 return buf
43 }
44
45 func (msg *Int32msg) Len() int {
46 return unix.NLA_HDRLEN + 4
47 }
48
49
50
51
52 type Bytemsg struct {
53 Type uint16
54 Value []byte
55 }
56
57 func (msg *Bytemsg) Serialize() []byte {
58 l := msg.Len()
59 if l > math.MaxUint16 {
60
61
62
63 panic(netlinkError{fmt.Errorf("netlink: cannot serialize bytemsg of length %d (larger than UINT16_MAX)", l)})
64 }
65 buf := make([]byte, (l+unix.NLA_ALIGNTO-1) & ^(unix.NLA_ALIGNTO-1))
66 native := nl.NativeEndian()
67 native.PutUint16(buf[0:2], uint16(l))
68 native.PutUint16(buf[2:4], msg.Type)
69 copy(buf[4:], msg.Value)
70 return buf
71 }
72
73 func (msg *Bytemsg) Len() int {
74 return unix.NLA_HDRLEN + len(msg.Value) + 1
75 }
76
77 type Boolmsg struct {
78 Type uint16
79 Value bool
80 }
81
82 func (msg *Boolmsg) Serialize() []byte {
83 buf := make([]byte, msg.Len())
84 native := nl.NativeEndian()
85 native.PutUint16(buf[0:2], uint16(msg.Len()))
86 native.PutUint16(buf[2:4], msg.Type)
87 if msg.Value {
88 native.PutUint32(buf[4:8], uint32(1))
89 } else {
90 native.PutUint32(buf[4:8], uint32(0))
91 }
92 return buf
93 }
94
95 func (msg *Boolmsg) Len() int {
96 return unix.NLA_HDRLEN + 4
97 }
98
View as plain text