From: Ophir Munk <ophirmu@mellanox.com>
To: dev@dpdk.org, Pascal Mazon <pascal.mazon@6wind.com>,
Keith Wiles <keith.wiles@intel.com>
Cc: Thomas Monjalon <thomas@monjalon.net>,
Olga Shern <olgas@mellanox.com>,
Ophir Munk <ophirmu@mellanox.com>
Subject: [dpdk-dev] [PATCH v1] net/tap: explain how to compile eBPF C file
Date: Mon, 11 Jun 2018 16:06:12 +0000 [thread overview]
Message-ID: <1528733172-24747-1-git-send-email-ophirmu@mellanox.com> (raw)
This commit explains how to manually compile the C source file
tap_bpf_program.c into an ELF file using the clang compiler.
The code in tap_bpf_program.c requires definitions found in iproute2
source code. This commit suggests cloning the iproute2 git tree and
include its path in the clang command. It also adds inclusion of file
bpf_api.h (required for eBPF definitions) which is located in iproute2
source tree. For more details refer to TAP documentation.
This commit is related to commits [1] and [2].
[1] commit cdc07e83bb24 ("net/tap: add eBPF program file")
[2] commit aabe70df73a3 ("net/tap: add eBPF bytes code")
Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
---
doc/guides/nics/tap.rst | 21 +++++++++++++++++----
drivers/net/tap/tap_bpf_program.c | 5 +++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst
index 2714868..af6c534 100644
--- a/doc/guides/nics/tap.rst
+++ b/doc/guides/nics/tap.rst
@@ -234,13 +234,26 @@ C functions under different ELF sections.
2. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above
-3. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file::
+3. The code in ``tap_bpf_program.c`` requires definitions found in iproute2
+source code.
- clang -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \
- -filetype=obj -o <tap_bpf_program.o>
+Clone the iproute2 git tree and make it accessible to the build environment, say
+under directory ``<iproute2_root_tree>`` ::
+
+ git clone https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/ \
+ <iproute2_root_tree>
+
+The code in ``tap_bpf_program.c`` must include file ``bpf_api.h`` which is
+located under ``<iproute2_root_tree>`` directory. This file contains eBPF
+related definitions.
+4. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file::
+
+ clang -I <iproute2_root_tree>/iproute2/include \
+ -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \
+ -filetype=obj -o <tap_bpf_program.o>
-4. Use a tool that receives two parameters: an eBPF object file and a section
+5. Use a tool that receives two parameters: an eBPF object file and a section
name, and prints out the section as a C array of eBPF instructions.
Embed the C array in your TAP PMD tree.
diff --git a/drivers/net/tap/tap_bpf_program.c b/drivers/net/tap/tap_bpf_program.c
index 1cb7382..60b069b 100644
--- a/drivers/net/tap/tap_bpf_program.c
+++ b/drivers/net/tap/tap_bpf_program.c
@@ -17,6 +17,11 @@
#include <linux/bpf.h>
#include "tap_rss.h"
+/*
+ * bpf_api.h file is located under iproute2
+ * tree, see TAP documentation.
+ */
+#include "bpf_api.h"
/** Create IPv4 address */
#define IPv4(a, b, c, d) ((__u32)(((a) & 0xff) << 24) | \
--
1.8.3.1
next reply other threads:[~2018-06-11 16:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 16:06 Ophir Munk [this message]
[not found] ` <A1755B7A-CDB5-4A55-9B44-9C9DEFDA9C88@intel.com>
2018-06-12 12:26 ` Thomas Monjalon
2018-06-12 12:36 ` Wiles, Keith
2018-06-12 12:58 ` Thomas Monjalon
2018-06-12 13:33 ` Wiles, Keith
2018-06-12 13:44 ` Thomas Monjalon
2018-06-12 13:52 ` Wiles, Keith
2018-06-12 14:02 ` Ophir Munk
2018-07-04 19:47 ` Ferruh Yigit
2018-07-04 20:11 ` Thomas Monjalon
2018-07-05 12:34 ` Wiles, Keith
2018-08-23 12:09 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1528733172-24747-1-git-send-email-ophirmu@mellanox.com \
--to=ophirmu@mellanox.com \
--cc=dev@dpdk.org \
--cc=keith.wiles@intel.com \
--cc=olgas@mellanox.com \
--cc=pascal.mazon@6wind.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).