forked from florianl/go-conntrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattribute_expected.go
82 lines (73 loc) · 1.69 KB
/
attribute_expected.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
//+build linux
package conntrack
import (
"fmt"
"github.com/mdlayher/netlink"
)
const (
ctaExpUnspec = iota
ctaExpMaster = iota
ctaExpTuple = iota
ctaExpMask = iota
ctaExpTimeout = iota
ctaExpID = iota
ctaExpHelpName = iota
ctaExpZone = iota
ctaExpFlags = iota
ctaExpClass = iota
ctaExpNAT = iota
ctaExpFN = iota
)
const (
ctaExpectNATUnspec = iota
ctaExpectNATDir = iota
ctaExpectNATTuple = iota
)
func extractExpectTuple(expect Conn, offset int, data []byte) error {
attributes, err := netlink.UnmarshalAttributes(data)
if err != nil {
return err
}
for _, attr := range attributes {
switch attr.Type {
case ctaTupleIP + nlafNested:
case ctaTupleProto + nlafNested:
case ctaTupleZone + nlafNested:
default:
return fmt.Errorf("Tuple %d is not yet implemented", attr.Type)
}
}
return nil
}
func extractExpectAttribute(expect Conn, data []byte) error {
attributes, err := netlink.UnmarshalAttributes(data)
if err != nil {
return err
}
for _, attr := range attributes {
switch attr.Type & 0xFF {
case ctaExpMask:
if err := extractExpectTuple(expect, 0, attr.Data); err != nil {
return err
}
case ctaExpTimeout:
expect[AttrTimeout] = attr.Data
case ctaExpHelpName:
expect[AttrHelperName] = attr.Data
case ctaExpZone:
expect[AttrZone] = attr.Data
case ctaExpFN:
expect[AttrHelperInfo] = attr.Data
default:
fmt.Println(attr.Type&0xFF, "\t", attr.Length, "\t", attr.Data)
}
}
return nil
}
func extractExpectAttributes(msg []byte) (Conn, error) {
var expect = make(map[ConnAttrType][]byte)
if err := extractExpectAttribute(expect, msg[24:]); err != nil {
return nil, err
}
return expect, nil
}