2014-12-02 02:06:38 +03:00
|
|
|
#include <uapi/linux/bpf.h>
|
|
|
|
#include <uapi/linux/if_ether.h>
|
2015-03-13 21:57:43 +03:00
|
|
|
#include <uapi/linux/if_packet.h>
|
2014-12-02 02:06:38 +03:00
|
|
|
#include <uapi/linux/ip.h>
|
2020-01-20 16:06:49 +03:00
|
|
|
#include <bpf/bpf_helpers.h>
|
2019-10-08 20:59:37 +03:00
|
|
|
#include "bpf_legacy.h"
|
2014-12-02 02:06:38 +03:00
|
|
|
|
2019-11-07 03:51:53 +03:00
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_ARRAY);
|
|
|
|
__type(key, u32);
|
|
|
|
__type(value, long);
|
|
|
|
__uint(max_entries, 256);
|
|
|
|
} my_map SEC(".maps");
|
2014-12-02 02:06:38 +03:00
|
|
|
|
|
|
|
SEC("socket1")
|
2015-03-13 21:57:43 +03:00
|
|
|
int bpf_prog1(struct __sk_buff *skb)
|
2014-12-02 02:06:38 +03:00
|
|
|
{
|
|
|
|
int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
|
|
|
|
long *value;
|
|
|
|
|
2015-03-13 21:57:43 +03:00
|
|
|
if (skb->pkt_type != PACKET_OUTGOING)
|
|
|
|
return 0;
|
|
|
|
|
2014-12-02 02:06:38 +03:00
|
|
|
value = bpf_map_lookup_elem(&my_map, &index);
|
|
|
|
if (value)
|
2015-03-13 21:57:43 +03:00
|
|
|
__sync_fetch_and_add(value, skb->len);
|
2014-12-02 02:06:38 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|