2021-01-18 13:13:51 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-01-07 18:30:53 +01:00
|
|
|
#include <linux/bpf.h>
|
|
|
|
#include <bpf/bpf_helpers.h>
|
2021-01-11 18:44:18 +01:00
|
|
|
#include <iproute2/bpf_elf.h>
|
2021-01-07 18:30:53 +01:00
|
|
|
|
|
|
|
#include "pping.h"
|
|
|
|
#include "pping_helpers.h"
|
|
|
|
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
|
2021-01-25 20:40:57 +01:00
|
|
|
#ifdef HAVE_TC_LIBBPF /* detected by configure script in config.mk */
|
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_HASH);
|
2021-02-08 20:28:46 +01:00
|
|
|
__uint(key_size, sizeof(struct packet_id));
|
|
|
|
__uint(value_size, sizeof(struct packet_timestamp));
|
2021-01-25 20:40:57 +01:00
|
|
|
__uint(max_entries, 16384);
|
|
|
|
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
|
|
|
} ts_start SEC(".maps");
|
|
|
|
|
|
|
|
#else
|
2021-01-11 18:44:18 +01:00
|
|
|
struct bpf_elf_map SEC("maps") ts_start = {
|
2021-01-18 13:13:51 +01:00
|
|
|
.type = BPF_MAP_TYPE_HASH,
|
2021-02-08 20:28:46 +01:00
|
|
|
.size_key = sizeof(struct packet_id),
|
|
|
|
.size_value = sizeof(struct packet_timestamp),
|
2021-01-18 13:13:51 +01:00
|
|
|
.max_elem = 16384,
|
|
|
|
.pinning = PIN_GLOBAL_NS,
|
2021-01-07 18:30:53 +01:00
|
|
|
};
|
2021-01-25 20:40:57 +01:00
|
|
|
#endif
|
2021-01-07 18:30:53 +01:00
|
|
|
|
2021-02-09 18:09:30 +01:00
|
|
|
// TC-BFP for parsing packet identifier from egress traffic and add to map
|
2021-01-26 18:34:23 +01:00
|
|
|
SEC(TCBPF_PROG_SEC)
|
2021-01-07 18:30:53 +01:00
|
|
|
int tc_bpf_prog_egress(struct __sk_buff *skb)
|
|
|
|
{
|
2021-02-12 18:31:30 +01:00
|
|
|
struct parsing_context pctx;
|
2021-02-08 20:28:46 +01:00
|
|
|
struct packet_id p_id = { 0 };
|
|
|
|
struct packet_timestamp p_ts = { 0 };
|
|
|
|
|
2021-02-12 18:31:30 +01:00
|
|
|
pctx.data = (void *)(long)skb->data;
|
|
|
|
pctx.data_end = (void *)(long)skb->data_end;
|
2021-02-16 12:34:19 +01:00
|
|
|
pctx.len = skb->len;
|
2021-02-12 18:31:30 +01:00
|
|
|
pctx.nh.pos = pctx.data;
|
2021-02-08 20:28:46 +01:00
|
|
|
|
2021-02-12 18:31:30 +01:00
|
|
|
if (parse_packet_identifier(&pctx, true, &p_id) < 0)
|
2021-01-27 12:16:11 +01:00
|
|
|
goto end;
|
2021-02-08 20:28:46 +01:00
|
|
|
|
|
|
|
p_ts.timestamp = bpf_ktime_get_ns(); // or bpf_ktime_get_boot_ns
|
|
|
|
bpf_map_update_elem(&ts_start, &p_id, &p_ts, BPF_NOEXIST);
|
2021-01-07 18:30:53 +01:00
|
|
|
|
2021-01-18 13:13:51 +01:00
|
|
|
end:
|
|
|
|
return BPF_OK;
|
2021-01-07 18:30:53 +01:00
|
|
|
}
|