forked from Alkorin/nflog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
128 lines (114 loc) · 2.09 KB
/
types.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package nflog
import (
"syscall"
)
type nlmsghdr struct {
Len uint32
Type uint16
Flags uint16
Seq uint32
Pid uint32
}
type nfgenmsg struct {
Family uint8
Version uint8
ResId uint16 // BigEndian
}
type nfattr struct {
Len uint16
Type uint16
}
type nfulnl_msg_config_cmd struct {
Command uint8
}
type nfulnl_msg_config_mode struct {
CopyRange uint32 // BigEndian
CopyMode uint8
_pad uint8
}
type nfConfigCmd struct {
Header nlmsghdr
Message nfgenmsg
Attr nfattr
Cmd nfulnl_msg_config_cmd
}
type nfConfigMode struct {
Header nlmsghdr
Message nfgenmsg
Attr nfattr
Mode nfulnl_msg_config_mode
}
type nflogHeader struct {
Family uint8
Version uint8
ResId uint16 // BigEndian
}
type nflogTlv struct {
Len uint16
Type uint16
}
type HwAddr struct {
Len uint16
Pad uint16
Addr [8]uint8
}
func newNFConfigCmd(cmd uint8, family uint8, resId uint16) nfConfigCmd {
return nfConfigCmd{
Header: nlmsghdr{
Len: 25,
Type: (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG,
Flags: syscall.NLM_F_REQUEST | syscall.NLM_F_ACK,
Seq: 0,
Pid: 0,
},
Message: nfgenmsg{
Family: family,
Version: NFNETLINK_V0,
ResId: htons(resId),
},
Attr: nfattr{
Len: 5,
Type: NFULA_CFG_CMD,
},
Cmd: nfulnl_msg_config_cmd{
Command: cmd,
},
}
}
func newNFConfigMode(resId uint16, copyLen uint16) nfConfigMode {
return nfConfigMode{
Header: nlmsghdr{
Len: 30,
Type: (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG,
Flags: syscall.NLM_F_REQUEST | syscall.NLM_F_ACK,
Seq: 0,
Pid: 0,
},
Message: nfgenmsg{
Family: syscall.AF_UNSPEC,
Version: NFNETLINK_V0,
ResId: htons(resId),
},
Attr: nfattr{
Len: 10,
Type: NFULA_CFG_MODE,
},
Mode: nfulnl_msg_config_mode{
CopyMode: NFULNL_COPY_PACKET,
CopyRange: htonl(uint32(copyLen)),
},
}
}
type Msg struct {
Group uint16
Family uint8
Prefix string
UID *uint32
GID *uint32
InDev *uint32
OutDev *uint32
HwAddr *HwAddr
MacLayerType *uint16
MacLayer []byte
Payload []byte
}