From 872181455189b5bf76818fa95c3cf738cb911108 Mon Sep 17 00:00:00 2001 From: Gary Lin Date: Mon, 5 Feb 2018 17:03:44 +0800 Subject: [PATCH] Add BPF_PROG_ARRAY for BPF_MAP_TYPE_PROG_ARRAY Define a new macro to make it easier to declare a program array. Also replace BPF_TABLE("prog") in examples and tests with BPF_PROG_ARRAY. Signed-off-by: Gary Lin --- examples/networking/tunnel_monitor/monitor.c | 2 +- src/cc/export/helpers.h | 3 +++ tests/python/test_brb.c | 2 +- tests/python/test_call1.c | 2 +- tests/python/test_clang.py | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/networking/tunnel_monitor/monitor.c b/examples/networking/tunnel_monitor/monitor.c index 93146d52b7fa..630e4a682153 100644 --- a/examples/networking/tunnel_monitor/monitor.c +++ b/examples/networking/tunnel_monitor/monitor.c @@ -17,7 +17,7 @@ struct counters { }; BPF_HASH(stats, struct ipkey, struct counters, 1024); -BPF_TABLE("prog", int, int, parser, 10); +BPF_PROG_ARRAY(parser, 10); enum cb_index { CB_FLAGS = 0, diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h index ad5747840bd0..9a4d7a100787 100644 --- a/src/cc/export/helpers.h +++ b/src/cc/export/helpers.h @@ -186,6 +186,9 @@ struct bpf_stacktrace { #define BPF_STACK_TRACE(_name, _max_entries) \ BPF_TABLE("stacktrace", int, struct bpf_stacktrace, _name, _max_entries) +#define BPF_PROG_ARRAY(_name, _max_entries) \ + BPF_TABLE("prog", u32, u32, _name, _max_entries) + // packet parsing state machine helpers #define cursor_advance(_cursor, _len) \ ({ void *_tmp = _cursor; _cursor += _len; _tmp; }) diff --git a/tests/python/test_brb.c b/tests/python/test_brb.c index 2141735c0f12..c2bf5fbef286 100644 --- a/tests/python/test_brb.c +++ b/tests/python/test_brb.c @@ -22,7 +22,7 @@ typedef struct eth_addr { } eth_addr_t; // Program table definitions for tail calls -BPF_TABLE("prog", u32, u32, jump, 16); +BPF_PROG_ARRAY(jump, 16); // physical endpoint manager (pem) tables which connects to boeht bridge 1 and bridge 2 // diff --git a/tests/python/test_call1.c b/tests/python/test_call1.c index e07bbe8e7e0f..787de21cbc40 100644 --- a/tests/python/test_call1.c +++ b/tests/python/test_call1.c @@ -1,7 +1,7 @@ // Copyright (c) PLUMgrid, Inc. // Licensed under the Apache License, Version 2.0 (the "License") -BPF_TABLE("prog", int, int, jump, 64); +BPF_PROG_ARRAY(jump, 64); BPF_ARRAY(stats, u64, 64); enum states { diff --git a/tests/python/test_clang.py b/tests/python/test_clang.py index 58c808ebeb8a..1bb2098c3218 100755 --- a/tests/python/test_clang.py +++ b/tests/python/test_clang.py @@ -426,7 +426,7 @@ def test_too_many_args(self): def test_call_macro_arg(self): text = """ -BPF_TABLE("prog", u32, u32, jmp, 32); +BPF_PROG_ARRAY(jmp, 32); #define JMP_IDX_PIPE (1U << 1) @@ -607,7 +607,7 @@ def test_map_insert(self): def test_prog_array_delete(self): text = """ -BPF_TABLE("prog", int, int, dummy, 256); +BPF_PROG_ARRAY(dummy, 256); """ b1 = BPF(text=text) text = """