tc full packet test
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
This commit is contained in:
29
tools/ebpf/mark_packet_id.c
Normal file
29
tools/ebpf/mark_packet_id.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/pkt_cls.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
|
||||
#define PACKET_ID_MASK 0x0FFFFFFF
|
||||
#define VERDICT_MASK 0xF0000000
|
||||
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
__uint(max_entries, 1);
|
||||
__type(key, __u32);
|
||||
__type(value, __u32);
|
||||
} packet_counter SEC(".maps");
|
||||
|
||||
SEC("classifier")
|
||||
int classifier(struct __sk_buff *skb) {
|
||||
__u32 key = 0;
|
||||
__u32 *counter = bpf_map_lookup_elem(&packet_counter, &key);
|
||||
__u32 next = 1;
|
||||
|
||||
if (counter) {
|
||||
next = __sync_add_and_fetch(counter, 1);
|
||||
}
|
||||
|
||||
skb->mark = (skb->mark & VERDICT_MASK) | (next & PACKET_ID_MASK);
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
char LICENSE[] SEC("license") = "GPL";
|
||||
41
tools/ebpf/prepend_capture_header.c
Normal file
41
tools/ebpf/prepend_capture_header.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <linux/pkt_cls.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
|
||||
#define CAPTURE_MAGIC 0x4d544350
|
||||
#define CAPTURE_VERSION 1
|
||||
|
||||
struct capture_header {
|
||||
__be32 magic;
|
||||
__u8 version;
|
||||
__u8 flags;
|
||||
__be16 header_len;
|
||||
__be32 skb_mark;
|
||||
__be32 aux_value;
|
||||
} __attribute__((packed));
|
||||
|
||||
SEC("classifier")
|
||||
int classifier(struct __sk_buff *skb) {
|
||||
struct capture_header hdr = {
|
||||
.magic = bpf_htonl(CAPTURE_MAGIC),
|
||||
.version = CAPTURE_VERSION,
|
||||
.flags = 0,
|
||||
.header_len = bpf_htons(sizeof(struct capture_header)),
|
||||
.skb_mark = bpf_htonl(skb->mark),
|
||||
.aux_value = 0,
|
||||
};
|
||||
|
||||
if (!skb->mark) {
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
if (bpf_skb_adjust_room(skb, sizeof(hdr), BPF_ADJ_ROOM_MAC, 0)) {
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
if (bpf_skb_store_bytes(skb, 0, &hdr, sizeof(hdr), 0)) {
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
char LICENSE[] SEC("license") = "GPL";
|
||||
Reference in New Issue
Block a user