Skip to content

Commit

Permalink
Use new helper Macro across files
Browse files Browse the repository at this point in the history
  • Loading branch information
palmtenor committed Mar 29, 2017
1 parent f829177 commit 7a3e5bc
Show file tree
Hide file tree
Showing 33 changed files with 72 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/lua/task_switch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions examples/networking/distributed_bridge/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions examples/networking/distributed_bridge/tunnel_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/dns_matching/dns_matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/http_filter/http-parse-complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/neighbor_sharing/tc_neighbor_sharing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/networking/tunnel_monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions examples/networking/vlan_learning/vlan_learning.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing/task_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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;
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing/trace_perf_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions tests/lua/test_clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/lua/test_uprobes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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)
Expand All @@ -24,7 +24,7 @@ def test_simple(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_bpf_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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;
"""
Expand Down
24 changes: 12 additions & 12 deletions tests/python/test_brb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_brb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_call1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_probe_read_keys(self):

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;
}
Expand All @@ -107,7 +107,7 @@ def test_sscanf(self):

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")
Expand All @@ -130,7 +130,7 @@ def test_iosnoop(self):
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 = {};
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_task_switch(self):
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;
Expand Down Expand Up @@ -325,9 +325,9 @@ def test_complex_leaf_types(self):
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
Expand All @@ -351,7 +351,7 @@ def test_syntax_error(self):

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"]
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_call_macro_arg(self):

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)
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_clang_complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_perf_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_stat1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7a3e5bc

Please sign in to comment.