forked from florianl/go-nflog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
142 lines (122 loc) · 2.74 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package nflog
import (
"errors"
"log"
)
// Various constants
const (
// Available copy modes for Config.Copymode.
NfUlnlCopyNone byte = 0x00
NfUlnlCopyMeta byte = 0x01
// Provides a complete copy of the packet in the Msg map.
// But can be limited by setting Config.Bufsize.
NfUlnlCopyPacket byte = 0x02
// Flags that can be set on a connection
NfUlnlCfgFSeq uint16 = 0x0001
NfUlnlCfgFSeqGlobal uint16 = 0x0002
// Requires Kernel configuration of CONFIG_NETFILTER_NETLINK_GLUE_CT
NfUlnlCfgFConntrack uint16 = 0x0004
)
// Various errors
var (
ErrCopyMode = errors.New("Unsupported copy mode")
ErrUnknownFlag = errors.New("Unsupported flag")
)
// nfLogSubSysUlog the netlink subsystem we will query
const nfnlSubSysUlog = 0x04
// Message types
const (
// Kernel to userspace
nfUlnlMsgPacket = iota
// Userspace to kernel
nfUlnlMsgConfig
)
const (
_ = iota
nfUlACfgCmd
nfUlACfgMode
nfUlACfgNlBufSize
nfUlACfgTimeOut /* in 1/100 s */
nfUlACfgQThresh
nfUlACfgFlags
)
const (
_ = iota
nfUlnlCfgCmdBind
nfUlnlCfgCmdUnbind
nfUlnlCfgCmdPfBind
nfUlnlCfgCmdPfUnbind
)
const nlafNested = (1 << 15)
const (
_ = iota
nfUlaAttrPacketHdr
nfUlaAttrMark
nfUlaAttrTimestamp
nfUlaAttrIfindexIndev
nfUlaAttrIfindexOutdev
nfUlaAttrIfindexPhysIndev
nfUlaAttrIfindexPhysOutdev
nfUlaAttrHwaddr
nfUlaAttrPayload
nfUlaAttrPrefix
nfUlaAttrUID
nfUlaAttrSeq
nfUlaAttrSeqGlobal
nfUlaAttrGID
nfUlaAttrHwType
nfUlaAttrHwHeader
nfUlaAttrHwLen
nfUlaAttrCt
nfUlaAttrCtInfo
)
// Various identifier,that can be the key of Msg map
// A Msg map don't need to contain all of these keys.
const (
AttrHwProtocol = iota
AttrHook
AttrMark
AttrTimestamp
AttrIfindexIndev
AttrIfindexOutdev
AttrIfindexPhysIndev
AttrIfindexPhysOutdev
AttrHwAddr
AttrPayload
AttrPrefix
AttrUID
AttrSeq
AttrSeqGlobal
AttrGID
AttrHwType
AttrHwHeader
AttrHwLen
AttrCt
AttrCtInfo
)
// Config contains options for a Conn.
type Config struct {
// Network namespace the Nflog needs to operate in. If set to 0 (default),
// no network namespace will be entered.
NetNS int
// Optional flags
Flags uint16
// Specifies the number of packets in the group,
// until they will be pushed to userspace.
QThresh uint32
// Maximum time in 1/100s that a packet in the nflog group will be queued,
// until it is pushed to userspace.
Timeout uint32
// Nflog group this socket will be assigned to.
Group uint16
// Specifies how the kernel handles a packet in the nflog group.
Copymode uint8
// If NfUlnlCopyPacket is set as CopyMode,
// this parameter specifies the maximum number of bytes,
// that will be copied to userspace.
Bufsize uint32
// Interface to log internals.
Logger *log.Logger
}
// Msg contains all the information of a connection
type Msg map[int]interface{}