Skip to contentSkip to conversation

bpf: simplify definition of BPF_FIB_LOOKUP related flags

PATCH Applied Martynas Pumputis 3 participants 5 messages Jun 12, 2019 – Jun 13, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 bpf: simplify definition of BPF_FIB_LOOKUP related flags

Previously, the BPF_FIB_LOOKUP_{DIRECT,OUTPUT} flags were defined with the help of BIT macro. This had the following issues:

- In order to user any of the flags, a user was required to depend on <linux/bits.h>.
- No other flag in bpf.h uses the macro, so it seems that an unwritten convention is to use (1 << (nr)) to define BPF-related flags.

---
 include/uapi/linux/bpf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/bpf.h +2 -2
index 63e0cf66f01a..a8f17bc86732 100644
@@ -3376,8 +3376,8 @@ struct bpf_raw_tracepoint_args {
 /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
  * OUTPUT:  Do lookup from egress perspective; default is ingress
  */
-#define BPF_FIB_LOOKUP_DIRECT  BIT(0)
-#define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
+#define BPF_FIB_LOOKUP_DIRECT  (1U << 0)
+#define BPF_FIB_LOOKUP_OUTPUT  (1U << 1)
 
 enum {
 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 2/2 bpf: sync BPF_FIB_LOOKUP flag changes with BPF uapi

Sync the changes to the flags made in "bpf: simplify definition of BPF_FIB_LOOKUP related flags" with the BPF uapi headers.

Doing in a separate commit to ease syncing of github/libbpf.

---
 tools/include/uapi/linux/bpf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/include/uapi/linux/bpf.h +2 -2
index 63e0cf66f01a..a8f17bc86732 100644
@@ -3376,8 +3376,8 @@ struct bpf_raw_tracepoint_args {
 /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
  * OUTPUT:  Do lookup from egress perspective; default is ingress
  */
-#define BPF_FIB_LOOKUP_DIRECT  BIT(0)
-#define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
+#define BPF_FIB_LOOKUP_DIRECT  (1U << 0)
+#define BPF_FIB_LOOKUP_OUTPUT  (1U << 1)
 
 enum {
 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
Signature · 1 line
2.21.0
Acked-by on v2 2/2
#2 lore raw

Re: [PATCH bpf v2 2/2] bpf: sync BPF_FIB_LOOKUP flag changes with BPF uapi

Quoted 7 lines · Martynas Pumputis

Sync the changes to the flags made in "bpf: simplify definition of BPF_FIB_LOOKUP related flags" with the BPF uapi headers.

Doing in a separate commit to ease syncing of github/libbpf.

Quoted 22 lines
---
 tools/include/uapi/linux/bpf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/include/uapi/linux/bpf.h +2 -3
index 63e0cf66f01a..a8f17bc86732 100644
@@ -3376,8 +3376,8 @@ struct bpf_raw_tracepoint_args {
 /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
  * OUTPUT:  Do lookup from egress perspective; default is ingress
  */
-#define BPF_FIB_LOOKUP_DIRECT  BIT(0)
-#define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
+#define BPF_FIB_LOOKUP_DIRECT  (1U << 0)
+#define BPF_FIB_LOOKUP_OUTPUT  (1U << 1)
 
 enum {
        BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
--

2.21.0

Acked-by on v2 1/2
#3 lore raw
In reply to Martynas Pumputis
Quoted 9 lines · Martynas Pumputis

Previously, the BPF_FIB_LOOKUP_{DIRECT,OUTPUT} flags were defined with the help of BIT macro. This had the following issues:

- In order to user any of the flags, a user was required to depend on <linux/bits.h>.
- No other flag in bpf.h uses the macro, so it seems that an unwritten convention is to use (1 << (nr)) to define BPF-related flags.

Makes sense!

Quoted 23 lines
---
 include/uapi/linux/bpf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/bpf.h +2 -3
index 63e0cf66f01a..a8f17bc86732 100644
@@ -3376,8 +3376,8 @@ struct bpf_raw_tracepoint_args {
 /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
  * OUTPUT:  Do lookup from egress perspective; default is ingress
  */
-#define BPF_FIB_LOOKUP_DIRECT  BIT(0)
-#define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
+#define BPF_FIB_LOOKUP_DIRECT  (1U << 0)
+#define BPF_FIB_LOOKUP_OUTPUT  (1U << 1)
 
 enum {
        BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
--

2.21.0

maintainer Applied
#4 lore raw
In reply to Martynas Pumputis
Quoted 9 lines · Martynas Pumputis

Previously, the BPF_FIB_LOOKUP_{DIRECT,OUTPUT} flags were defined with the help of BIT macro. This had the following issues:

- In order to user any of the flags, a user was required to depend on <linux/bits.h>.
- No other flag in bpf.h uses the macro, so it seems that an unwritten convention is to use (1 << (nr)) to define BPF-related flags.

Applied, thanks!