forked from cilium/cilium
/
drop.go
101 lines (91 loc) · 2.75 KB
/
drop.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
// Copyright 2016-2017 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bpfdebug
import (
"fmt"
)
const (
// DropNotifyLen is the amount of packet data provided in a drop notification
DropNotifyLen = 32
)
// DropNotify is the message format of a drop notification in the BPF ring buffer
type DropNotify struct {
Type uint8
SubType uint8
Source uint16
Hash uint32
OrigLen uint32
CapLen uint32
SrcLabel uint32
DstLabel uint32
DstID uint32
Ifindex uint32
// data
}
var errors = map[uint8]string{
0: "Success",
2: "Invalid packet",
130: "Invalid source mac",
131: "Invalid destination mac",
132: "Invalid source ip",
133: "Policy denied",
134: "Invalid packet",
135: "CT: Truncated or invalid header",
136: "CT: Missing TCP ACK flag",
137: "CT: Unknown L4 protocol",
138: "CT: Can't create entry from packet",
139: "Unsupported L3 protocol",
140: "Missed tail call",
141: "Error writing to packet",
142: "Unknown L4 protocol",
143: "Unknown ICMPv4 code",
144: "Unknown ICMPv4 type",
145: "Unknown ICMPv6 code",
146: "Unknown ICMPv6 type",
147: "Error retrieving tunnel key",
148: "Error retrieving tunnel options",
149: "Invalid Geneve option",
150: "Unknown L3 target address",
151: "Not a local target address",
152: "No matching local container found",
153: "Error while correcting L3 checksum",
154: "Error while correcting L4 checksum",
155: "CT: Map insertion failed",
156: "Invalid IPv6 extension header",
157: "IPv6 fragmentation not supported",
158: "Service backend not found",
159: "Policy denied (L4)",
}
func dropReason(reason uint8) string {
if err, ok := errors[reason]; ok {
return err
}
return fmt.Sprintf("%d", reason)
}
// Dump prints the drop notification in human readable form
func (n *DropNotify) Dump(dissect bool, data []byte, prefix string) {
fmt.Printf("%s MARK %#x FROM %d Packet dropped %d (%s) %d bytes ifindex=%d",
prefix, n.Hash, n.Source, n.SubType, dropReason(n.SubType), n.OrigLen, n.Ifindex)
if n.SrcLabel != 0 || n.DstLabel != 0 {
fmt.Printf(" %d->%d", n.SrcLabel, n.DstLabel)
}
if n.DstID != 0 {
fmt.Printf(" to lxc %d\n", n.DstID)
} else {
fmt.Printf("\n")
}
if n.CapLen > 0 && len(data) > DropNotifyLen {
Dissect(dissect, data[DropNotifyLen:])
}
}