Commit 7a3e5bc3 authored by Teng Qin's avatar Teng Qin

Use new helper Macro across files

parent f829177b
......@@ -24,7 +24,7 @@ struct key_t {
u32 curr_pid;
};
// map_type, key_type, leaf_type, table_name, num_entry
BPF_TABLE("hash", struct key_t, u64, stats, 1024);
BPF_HASH(stats, struct key_t, u64, 1024);
int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
struct key_t key = {};
u64 zero = 0, *val;
......
......@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0 (the "License")
#include <bcc/proto.h>
BPF_TABLE("hash", u32, int, vni2if, 1024);
BPF_HASH(vni2if, u32, int, 1024);
struct vni_key {
u64 mac;
......@@ -15,12 +15,12 @@ struct host {
u64 rx_pkts;
u64 tx_pkts;
};
BPF_TABLE("hash", struct vni_key, struct host, mac2host, 10240);
BPF_HASH(mac2host, struct vni_key, struct host);
struct config {
int tunnel_ifindex;
};
BPF_TABLE("hash", int, struct config, conf, 1);
BPF_HASH(conf, int, struct config, 1);
// Handle packets from the encap device, demux into the dest tenant
int handle_ingress(struct __sk_buff *skb) {
......
......@@ -5,15 +5,15 @@
struct config {
int tunnel_ifindex;
};
BPF_TABLE("hash", int, struct config, conf, 1);
BPF_HASH(conf, int, struct config, 1);
struct tunnel_key {
u32 tunnel_id;
u32 remote_ipv4;
};
BPF_TABLE("hash", struct tunnel_key, int, tunkey2if, 1024);
BPF_HASH(tunkey2if, struct tunnel_key, int, 1024);
BPF_TABLE("hash", int, struct tunnel_key, if2tunkey, 1024);
BPF_HASH(if2tunkey, int, struct tunnel_key, 1024);
// Handle packets from the encap device, demux into the dest tenant
int handle_ingress(struct __sk_buff *skb) {
......
......@@ -51,7 +51,7 @@ struct Leaf {
unsigned char p[4];
};
BPF_TABLE("hash", struct Key, struct Leaf, cache, 128);
BPF_HASH(cache, struct Key, struct Leaf, 128);
int dns_matching(struct __sk_buff *skb)
{
......
......@@ -19,7 +19,7 @@ struct Leaf {
//BPF_TABLE(map_type, key_type, leaf_type, table_name, num_entry)
//map <Key, Leaf>
//tracing sessions having same Key(dst_ip, src_ip, dst_port,src_port)
BPF_TABLE("hash", struct Key, struct Leaf, sessions, 1024);
BPF_HASH(sessions, struct Key, struct Leaf, 1024);
/*eBPF program.
Filter IP and TCP packets, having payload not empty
......
......@@ -7,7 +7,7 @@ struct ipkey {
u32 client_ip;
};
BPF_TABLE("hash", struct ipkey, int, learned_ips, 1024);
BPF_HASH(learned_ips, struct ipkey, int, 1024);
// trivial action
int pass(struct __sk_buff *skb) {
......
......@@ -16,7 +16,7 @@ struct counters {
u64 rx_bytes;
};
BPF_TABLE("hash", struct ipkey, struct counters, stats, 1024);
BPF_HASH(stats, struct ipkey, struct counters, 1024);
BPF_TABLE("prog", int, int, parser, 10);
enum cb_index {
......
......@@ -12,10 +12,10 @@ struct ifindex_leaf_t {
};
// redirect based on mac -> out_ifindex (auto-learning)
BPF_TABLE("hash", int, struct ifindex_leaf_t, egress, 4096);
BPF_HASH(egress, int, struct ifindex_leaf_t, 4096);
// redirect based on mac -> out_ifindex (config-driven)
BPF_TABLE("hash", u64, struct ifindex_leaf_t, ingress, 4096);
BPF_HASH(ingress, struct ifindex_leaf_t, 4096);
int handle_phys2virt(struct __sk_buff *skb) {
// only handle vlan packets
......
......@@ -14,7 +14,7 @@ struct key_t {
u32 curr_pid;
};
// map_type, key_type, leaf_type, table_name, num_entry
BPF_TABLE("hash", struct key_t, u64, stats, 1024);
BPF_HASH(stats, struct key_t, u64, 1024);
int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
struct key_t key = {};
u64 zero = 0, *val;
......
......@@ -24,7 +24,7 @@ def cb(cpu, data, size):
prog = """
BPF_PERF_OUTPUT(events);
BPF_TABLE("array", int, u64, counters, 10);
BPF_ARRAY(counters, u64, 10);
int kprobe__sys_clone(void *ctx) {
struct {
u64 ts;
......
......@@ -51,7 +51,7 @@ end
function TestClang:test_sscanf()
local text = [[
BPF_TABLE("hash", int, struct { u64 a; u64 b; u32 c:18; u32 d:14; struct { u32 a; u32 b; } s; }, stats, 10);
BPF_HASH(stats, int, struct { u64 a; u64 b; u32 c:18; u32 d:14; struct { u32 a; u32 b; } s; }, 10);
int foo(void *ctx) {
return 0;
......@@ -76,7 +76,7 @@ int foo(void *ctx) {
end
function TestClang:test_sscanf_array()
local text = [[ BPF_TABLE("hash", int, struct { u32 a[3]; u32 b; }, stats, 10); ]]
local text = [[ BPF_HASH(stats, int, struct { u32 a[3]; u32 b; }, 10); ]]
local b = BPF:new{text=text, debug=0}
local t = b:get_table("stats")
......@@ -103,7 +103,7 @@ struct key_t {
struct request *req;
};
BPF_TABLE("hash", struct key_t, u64, start, 1024);
BPF_HASH(start, struct key_t, u64, 1024);
int do_request(struct pt_regs *ctx, struct request *req) {
struct key_t key = {};
......@@ -236,7 +236,7 @@ struct key_t {
u32 prev_pid;
u32 curr_pid;
};
BPF_TABLE("hash", struct key_t, u64, stats, 1024);
BPF_HASH(stats, struct key_t, u64, 1024);
int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
struct key_t key = {};
u64 zero = 0, *val;
......@@ -296,9 +296,9 @@ union emptyu {
struct empty em3;
struct empty em4;
};
BPF_TABLE("array", int, struct list, t1, 1);
BPF_TABLE("array", int, struct list *, t2, 1);
BPF_TABLE("array", int, union emptyu, t3, 1);
BPF_ARRAY(t1, struct list, 1);
BPF_ARRAY(t2, struct list *, 1);
BPF_ARRAY(t3, union emptyu, 1);
]]
local b = BPF:new{text=text}
local ffi = require("ffi")
......
......@@ -10,7 +10,7 @@ ffi.cdef[[
function TestUprobes:test_simple_library()
local text = [[
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
BPF_ARRAY(stats, u64, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
......@@ -41,7 +41,7 @@ end
function TestUprobes:test_simple_binary()
local text = [[
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
BPF_ARRAY(stats, u64, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
......
......@@ -12,7 +12,7 @@ from unittest import main, TestCase
class TestArray(TestCase):
def test_simple(self):
b = BPF(text="""BPF_TABLE("array", int, u64, table1, 128);""")
b = BPF(text="""BPF_ARRAY(table1, u64, 128);""")
t1 = b["table1"]
t1[ct.c_int(0)] = ct.c_ulonglong(100)
t1[ct.c_int(127)] = ct.c_ulonglong(1000)
......@@ -24,7 +24,7 @@ class TestArray(TestCase):
self.assertEqual(len(t1), 128)
def test_native_type(self):
b = BPF(text="""BPF_TABLE("array", int, u64, table1, 128);""")
b = BPF(text="""BPF_ARRAY(table1, u64, 128);""")
t1 = b["table1"]
t1[0] = ct.c_ulonglong(100)
t1[-2] = ct.c_ulonglong(37)
......
......@@ -15,7 +15,7 @@ error_msg = "R0 invalid mem access 'map_value_or_null'\n"
text = """
#include <uapi/linux/ptrace.h>
#include <bcc/proto.h>
BPF_TABLE("hash", int, int, t1, 10);
BPF_HASH(t1, int, int, 10);
int sim_port(struct __sk_buff *skb) {
int x = 0, *y;
"""
......
......@@ -26,33 +26,33 @@ BPF_TABLE("prog", u32, u32, jump, 16);
// physical endpoint manager (pem) tables which connects to boeht bridge 1 and bridge 2
// <port_id, bpf_dest>
BPF_TABLE("array", u32, bpf_dest_t, pem_dest, 256);
BPF_ARRAY(pem_dest, bpf_dest_t, 256);
// <port_id, ifindex>
BPF_TABLE("array", u32, u32, pem_port, 256);
BPF_ARRAY(pem_port, u32, 256);
// <ifindex, port_id>
BPF_TABLE("hash", u32, u32, pem_ifindex, 256);
BPF_HASH(pem_ifindex, u32, u32, 256);
// <0, tx2vm_pkts>
BPF_TABLE("array", u32, u32, pem_stats, 1);
BPF_ARRAY(pem_stats, u32, 1);
// bridge 1 (br1) tables
// <port_id, bpf_dest>
BPF_TABLE("array", u32, bpf_dest_t, br1_dest, 256);
BPF_ARRAY(br1_dest, bpf_dest_t, 256);
// <eth_addr, port_id>
BPF_TABLE("hash", eth_addr_t, u32, br1_mac, 256);
BPF_HASH(br1_mac, eth_addr_t, u32, 256);
// <0, rtr_ifindex>
BPF_TABLE("array", u32, u32, br1_rtr, 1);
BPF_ARRAY(br1_rtr, u32, 1);
// <mac, ifindex>
BPF_TABLE("hash", eth_addr_t, u32, br1_mac_ifindex, 1);
BPF_HASH(br1_mac_ifindex, eth_addr_t, u32, 1);
// bridge 2 (br2) tables
// <port_id, bpf_dest>
BPF_TABLE("array", u32, bpf_dest_t, br2_dest, 256);
BPF_ARRAY(br2_dest, bpf_dest_t, 256);
// <eth_addr, port_id>
BPF_TABLE("hash", eth_addr_t, u32, br2_mac, 256);
BPF_HASH(br2_mac, eth_addr_t, u32, 256);
// <0, rtr_ifindex>
BPF_TABLE("array", u32, u32, br2_rtr, 1);
BPF_ARRAY(br2_rtr, u32, 1);
// <mac, ifindex>
BPF_TABLE("hash", eth_addr_t, u32, br2_mac_ifindex, 1);
BPF_HASH(br2_mac_ifindex, eth_addr_t, u32, 1);
int pem(struct __sk_buff *skb) {
bpf_metadata_t meta = {};
......
......@@ -4,9 +4,9 @@
// physical endpoint manager (pem) tables which connects VMs and bridges
// <ifindex_in, ifindex_out>
BPF_TABLE("hash", u32, u32, pem_dest, 256);
BPF_HASH(pem_dest, u32, u32, 256);
// <0, tx_pkts>
BPF_TABLE("array", u32, u32, pem_stats, 1);
BPF_ARRAY(pem_stats, u32, 1);
int pem(struct __sk_buff *skb) {
u32 ifindex_in, *ifindex_p;
......
......@@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0 (the "License")
BPF_TABLE("prog", int, int, jump, 64);
BPF_TABLE("array", int, u64, stats, 64);
BPF_ARRAY(stats, u64, 64);
enum states {
S_EOP = 1,
......
......@@ -86,7 +86,7 @@ int do_completion(struct pt_regs *ctx, struct request *req) {
def test_sscanf(self):
text = """
BPF_TABLE("hash", int, struct { u64 a; u64 b; u64 c:36; u64 d:28; struct { u32 a; u32 b; } s; }, stats, 10);
BPF_HASH(stats, int, struct { u64 a; u64 b; u64 c:36; u64 d:28; struct { u32 a; u32 b; } s; }, 10);
int foo(void *ctx) {
return 0;
}
......@@ -107,7 +107,7 @@ int foo(void *ctx) {
def test_sscanf_array(self):
text = """
BPF_TABLE("hash", int, struct { u32 a[3]; u32 b; }, stats, 10);
BPF_HASH(stats, int, struct { u32 a[3]; u32 b; }, 10);
"""
b = BPF(text=text, debug=0)
t = b.get_table("stats")
......@@ -130,7 +130,7 @@ struct key_t {
struct request *req;
};
BPF_TABLE("hash", struct key_t, u64, start, 1024);
BPF_HASH(start, struct key_t, u64, 1024);
int do_request(struct pt_regs *ctx, struct request *req) {
struct key_t key = {};
......@@ -268,7 +268,7 @@ struct key_t {
u32 prev_pid;
u32 curr_pid;
};
BPF_TABLE("hash", struct key_t, u64, stats, 1024);
BPF_HASH(stats, struct key_t, u64, 1024);
int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
struct key_t key = {};
u64 zero = 0, *val;
......@@ -325,9 +325,9 @@ union emptyu {
struct empty em3;
struct empty em4;
};
BPF_TABLE("array", int, struct list, t1, 1);
BPF_TABLE("array", int, struct list *, t2, 1);
BPF_TABLE("array", int, union emptyu, t3, 1);
BPF_ARRAY(t1, struct list, 1);
BPF_ARRAY(t2, struct list *, 1);
BPF_ARRAY(t3, union emptyu, 1);
"""
b = BPF(text=text)
import ctypes
......@@ -351,7 +351,7 @@ BPF_TABLE("array", int, union emptyu, t3, 1);
def test_nested_union(self):
text = """
BPF_TABLE("hash", struct bpf_tunnel_key, int, t1, 1);
BPF_HASH(t1, struct bpf_tunnel_key, int, 1);
"""
b = BPF(text=text)
t1 = b["t1"]
......@@ -389,7 +389,7 @@ int process(struct xdp_md *ctx) {
def test_update_macro_arg(self):
text = """
BPF_TABLE("array", u32, u32, act, 32);
BPF_ARRAY(act, u32, 32);
#define JMP_IDX_PIPE (1U << 1)
......
......@@ -10,7 +10,7 @@ struct FwdKey {
struct FwdLeaf {
u32 fwd_idx:32;
};
BPF_TABLE("hash", struct FwdKey, struct FwdLeaf, fwd_map, 1);
BPF_HASH(fwd_map, struct FwdKey, struct FwdLeaf, 1);
// array
struct ConfigKey {
......@@ -29,7 +29,7 @@ struct MacaddrKey {
struct MacaddrLeaf {
u64 mac;
};
BPF_TABLE("hash", struct MacaddrKey, struct MacaddrLeaf, macaddr_map, 11);
BPF_HASH(macaddr_map, struct MacaddrKey, struct MacaddrLeaf, 11);
// hash
struct SlaveKey {
......@@ -38,7 +38,7 @@ struct SlaveKey {
struct SlaveLeaf {
u32 slave_ifindex;
};
BPF_TABLE("hash", struct SlaveKey, struct SlaveLeaf, slave_map, 10);
BPF_HASH(slave_map, struct SlaveKey, struct SlaveLeaf, 10);
int handle_packet(struct __sk_buff *skb) {
int ret = 0;
......
......@@ -13,7 +13,7 @@ class TestPerfCounter(unittest.TestCase):
def test_cycles(self):
text = """
BPF_PERF_ARRAY(cnt1, NUM_CPUS);
BPF_TABLE("array", u32, u64, prev, NUM_CPUS);
BPF_ARRAY(prev, u64, NUM_CPUS);
BPF_HISTOGRAM(dist);
int kprobe__sys_getuid(void *ctx) {
u32 cpu = bpf_get_smp_processor_id();
......
......@@ -12,7 +12,7 @@ struct IPLeaf {
u64 tx_pkts;
};
BPF_TABLE("hash", struct IPKey, struct IPLeaf, stats, 256);
BPF_HASH(stats, struct IPKey, struct IPLeaf, 256);
int on_packet(struct __sk_buff *skb) {
u8 *cursor = 0;
......
......@@ -3,7 +3,7 @@
#include <linux/ptrace.h>
struct Ptr { u64 ptr; };
struct Counters { u64 stat1; };
BPF_TABLE("hash", struct Ptr, struct Counters, stats, 1024);
BPF_HASH(stats, struct Ptr, struct Counters, 1024);
int count_sched(struct pt_regs *ctx) {
struct Ptr key = {.ptr = PT_REGS_PARM1(ctx)};
......
......@@ -12,7 +12,7 @@ text = """
#include <linux/ptrace.h>
struct Ptr { u64 ptr; };
struct Counters { u64 stat1; };
BPF_TABLE("hash", struct Ptr, struct Counters, stats, 1024);
BPF_HASH(stats, struct Ptr, struct Counters, 1024);
int count_sched(struct pt_regs *ctx) {
struct Ptr key = {.ptr=PT_REGS_PARM1(ctx)};
......
......@@ -4,9 +4,9 @@
#include <linux/blkdev.h>
struct Request { u64 rq; };
struct Time { u64 start; };
BPF_TABLE("hash", struct Request, struct Time, requests, 1024);
BPF_HASH(requests, struct Request, struct Time, 1024);
#define SLOTS 100
BPF_TABLE("array", u32, u64, latency, SLOTS);
BPF_ARRAY(latency, u64, SLOTS);
static u32 log2(u32 v) {
u32 r, shift;
......
......@@ -12,7 +12,7 @@ class TestKprobeRgx(TestCase):
self.b = BPF(text="""
typedef struct { int idx; } Key;
typedef struct { u64 val; } Val;
BPF_TABLE("hash", Key, Val, stats, 3);
BPF_HASH(stats, Key, Val, 3);
int hello(void *ctx) {
stats.lookup_or_init(&(Key){1}, &(Val){0})->val++;
return 0;
......
......@@ -11,7 +11,7 @@ class TestUprobes(unittest.TestCase):
def test_simple_library(self):
text = """
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
BPF_ARRAY(stats, u64, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
......@@ -40,7 +40,7 @@ int count(struct pt_regs *ctx) {
def test_simple_binary(self):
text = """
#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, stats, 1);
BPF_ARRAY(stats, u64, 1);
static void incr(int idx) {
u64 *ptr = stats.lookup(&idx);
if (ptr)
......
......@@ -11,7 +11,7 @@ struct IPLeaf {
u64 ip_xlated_pkts;
u64 arp_xlated_pkts;
};
BPF_TABLE("hash", struct IPKey, struct IPLeaf, xlate, 1024);
BPF_HASH(xlate, struct IPKey, struct IPLeaf, 1024);
int on_packet(struct __sk_buff *skb) {
u8 *cursor = 0;
......
......@@ -49,7 +49,7 @@ enum stats {
S_MAXSTAT
};
BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
BPF_ARRAY(stats, u64, S_MAXSTAT + 1);
/*
* How this is instrumented, and how to interpret the statistics, is very much
......
......@@ -30,8 +30,7 @@ struct thread_to_held_mutex_leaf_t {
};
// Map of thread ID -> array of (mutex addresses, stack id)
BPF_TABLE("hash", u32, struct thread_to_held_mutex_leaf_t,
thread_to_held_mutexes, 2097152);
BPF_HASH(thread_to_held_mutexes, u32, struct thread_to_held_mutex_leaf_t, 2097152);
// Key type for edges. Represents an edge from mutex1 => mutex2.
struct edges_key_t {
......@@ -48,7 +47,7 @@ struct edges_leaf_t {
};
// Represents all edges currently in the mutex wait graph.
BPF_TABLE("hash", struct edges_key_t, struct edges_leaf_t, edges, 2097152);
BPF_HASH(edges, struct edges_key_t, struct edges_leaf_t, 2097152);
// Info about parent thread when a child thread is created.
struct thread_created_leaf_t {
......@@ -58,7 +57,7 @@ struct thread_created_leaf_t {
};
// Map of child thread pid -> info about parent thread.
BPF_TABLE("hash", u32, struct thread_created_leaf_t, thread_to_parent, 10240);
BPF_HASH(thread_to_parent, u32, struct thread_created_leaf_t);
// Stack traces when threads are created and when mutexes are locked/unlocked.
BPF_STACK_TRACE(stack_traces, 655360);
......
......@@ -178,7 +178,7 @@ int PROBE_FUNCTION(void *ctx) {
"""
bpf_text = """#include <uapi/linux/ptrace.h>
BPF_TABLE("array", int, u64, counts, NUMLOCATIONS);
BPF_ARRAY(counts, u64, NUMLOCATIONS);
"""
# We really mean the tgid from the kernel's perspective, which is in
......
......@@ -26,7 +26,7 @@ enum stat_types {
S_MAXSTAT
};
BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
BPF_ARRAY(stats, u64, S_MAXSTAT + 1);
void stats_increment(int key) {
u64 *leaf = stats.lookup(&key);
......
......@@ -23,7 +23,7 @@ struct key_t {
u64 ip;
};
BPF_TABLE("hash", struct key_t, u64, counts, 256);
BPF_HASH(counts, struct key_t, u64, 256);
int do_count(struct pt_regs *ctx) {
struct key_t key = {};
......
......@@ -49,7 +49,7 @@ enum stat_types {
S_MAXSTAT
};
BPF_TABLE("array", int, u64, stats, S_MAXSTAT + 1);
BPF_ARRAY(stats, u64, S_MAXSTAT + 1);
void stats_increment(int key) {
u64 *leaf = stats.lookup(&key);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment