Skip to content

Commit 4ee845a

Browse files
committed
[BPF] add counters for dropped fragments
1 parent d636dfd commit 4ee845a

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

felix/bpf-gpl/counters.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "bpf.h"
99

10-
#define MAX_COUNTERS_SIZE 17
10+
#define MAX_COUNTERS_SIZE 19
1111

1212
typedef __u64 counters_t[MAX_COUNTERS_SIZE];
1313

@@ -25,6 +25,10 @@ CALI_MAP(cali_counters, 3,
2525
struct counters_key, counters_t, 20000,
2626
0)
2727

28+
CALI_MAP(cali_counters_scratch, 2,
29+
BPF_MAP_TYPE_PERCPU_ARRAY,
30+
__u32, counters_t, 1, 0)
31+
2832
static CALI_BPF_INLINE counters_t *counters_get(int ifindex)
2933
{
3034
struct counters_key key = {
@@ -49,7 +53,12 @@ static CALI_BPF_INLINE counters_t *counters_get(int ifindex)
4953
/* If there was no entry created yet, create it. It is a hash
5054
* map so any entry must be created first!
5155
*/
52-
counters_t ctrs = {};
56+
int scratch_zero = 0;
57+
counters_t *ctrs = cali_counters_scratch_lookup_elem(&scratch_zero);
58+
if (!ctrs) {
59+
return NULL;
60+
}
61+
5362
if (cali_counters_update_elem(&key, ctrs, BPF_ANY)) {
5463
return NULL;
5564
}

felix/bpf-gpl/reasons.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ enum calico_reason {
2626
CALI_REASON_SOURCE_COLLISION,
2727
CALI_REASON_SOURCE_COLLISION_FAILED,
2828
CALI_REASON_CT_CREATE_FAILED,
29-
CALI_REASON_ACCEPTED_BY_XDP, // Not used by counters map
29+
CALI_REASON_FRAG_WAIT,
30+
CALI_REASON_FRAG_REORDER,
31+
// Not used by counters map
32+
CALI_REASON_ACCEPTED_BY_XDP,
3033
CALI_REASON_WEP_NOT_READY,
3134
CALI_REASON_NATIFACE,
3235
};

felix/bpf-gpl/tc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ int calico_tc_main(struct __sk_buff *skb)
205205
#ifndef IPVER6
206206
if (CALI_F_TO_HOST && ip_is_frag(ip_hdr(ctx))) {
207207
if (!frags4_handle(ctx)) {
208+
deny_reason(ctx, CALI_REASON_FRAG_WAIT);
208209
goto deny;
209210
}
210211
/* force it through stack to trigger any further necessary fragmentation */
@@ -280,6 +281,9 @@ static CALI_BPF_INLINE int pre_policy_processing(struct cali_tc_ctx *ctx)
280281
}
281282
goto allow;
282283
}
284+
285+
deny_reason(ctx, CALI_REASON_FRAG_REORDER);
286+
goto deny;
283287
}
284288
#endif
285289

felix/bpf/counters/counters.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
const (
30-
MaxCounterNumber int = 17
30+
MaxCounterNumber int = 19
3131
counterMapKeySize int = 8
3232
counterMapValueSize int = 8
3333
)
@@ -76,6 +76,8 @@ const (
7676
SourceCollisionHit
7777
SourceCollisionResolutionFailed
7878
ConntrackCreateFailed
79+
DroppedFragWait
80+
DroppedFragReorder
7981
)
8082

8183
type Description struct {
@@ -170,6 +172,14 @@ var descriptions DescList = DescList{
170172
Counter: SourceCollisionResolutionFailed,
171173
Category: "Dropped", Caption: "NAT source collision resolution failed",
172174
},
175+
{
176+
Counter: DroppedFragWait,
177+
Category: "Dropped", Caption: "fragment of yet incomplete packet",
178+
},
179+
{
180+
Counter: DroppedFragReorder,
181+
Category: "Dropped", Caption: "fragment out of order within host",
182+
},
173183
}
174184

175185
func Descriptions() DescList {

0 commit comments

Comments
 (0)