Skip to content

Commit

Permalink
Add BPF_PROG_ARRAY for BPF_MAP_TYPE_PROG_ARRAY
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lcp committed Feb 6, 2018
1 parent 40a0aee commit 8721814
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/networking/tunnel_monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; })
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_brb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
// <port_id, bpf_dest>
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_call1.c
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = """
Expand Down

0 comments on commit 8721814

Please sign in to comment.