[v4] lib/bpf: Rename bpf function names to avoid potential conflict with libpcap

Message ID 20230312062021.7349-1-mars14850@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v4] lib/bpf: Rename bpf function names to avoid potential conflict with libpcap |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing warning Testing issues
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

J.J. Martzki March 12, 2023, 6:20 a.m. UTC
  The library libpcap has their function 'bpf_validate' either so there would
be a multiple definition issue when linking with librte_bpf.a and libpcap.a
statically (Same as http://dpdk.org/patch/52631). So just rename the
function names to avoid such issue.

Signed-off-by: J.J. Martzki <mars14850@gmail.com>

---
v4:
* Update my name.
v3:
* Rewrite the commit message.
v2:
* Rename all functions in bpf_impl.h.
* Adjust the commit message.
---
 lib/bpf/bpf.c           |  6 +++---
 lib/bpf/bpf_convert.c   |  3 ---
 lib/bpf/bpf_impl.h      | 10 ++++------
 lib/bpf/bpf_jit_arm64.c |  2 +-
 lib/bpf/bpf_jit_x86.c   |  2 +-
 lib/bpf/bpf_load.c      |  4 ++--
 lib/bpf/bpf_validate.c  |  2 +-
 7 files changed, 12 insertions(+), 17 deletions(-)
  

Comments

Konstantin Ananyev March 12, 2023, 2:02 p.m. UTC | #1
12/03/2023 06:20, J.J. Martzki пишет:
> The library libpcap has their function 'bpf_validate' either so there would
> be a multiple definition issue when linking with librte_bpf.a and libpcap.a
> statically (Same as http://dpdk.org/patch/52631). So just rename the
> function names to avoid such issue.
> 
> Signed-off-by: J.J. Martzki <mars14850@gmail.com>
> 
> ---
> v4:
> * Update my name.
> v3:
> * Rewrite the commit message.
> v2:
> * Rename all functions in bpf_impl.h.
> * Adjust the commit message.
> ---
>   lib/bpf/bpf.c           |  6 +++---
>   lib/bpf/bpf_convert.c   |  3 ---
>   lib/bpf/bpf_impl.h      | 10 ++++------
>   lib/bpf/bpf_jit_arm64.c |  2 +-
>   lib/bpf/bpf_jit_x86.c   |  2 +-
>   lib/bpf/bpf_load.c      |  4 ++--
>   lib/bpf/bpf_validate.c  |  2 +-
>   7 files changed, 12 insertions(+), 17 deletions(-)
> 
> diff --git a/lib/bpf/bpf.c b/lib/bpf/bpf.c
> index 1e1dd42a58..f218a8f2b0 100644
> --- a/lib/bpf/bpf.c
> +++ b/lib/bpf/bpf.c
> @@ -31,14 +31,14 @@ rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
>   }
>   
>   int
> -bpf_jit(struct rte_bpf *bpf)
> +rte_bpf_jit(struct rte_bpf *bpf)
>   {
>   	int32_t rc;
>   
>   #if defined(RTE_ARCH_X86_64)
> -	rc = bpf_jit_x86(bpf);
> +	rc = rte_bpf_jit_x86(bpf);
>   #elif defined(RTE_ARCH_ARM64)
> -	rc = bpf_jit_arm64(bpf);
> +	rc = rte_bpf_jit_arm64(bpf);
>   #else
>   	rc = -ENOTSUP;
>   #endif
> diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
> index 9563274c9c..d441be6663 100644
> --- a/lib/bpf/bpf_convert.c
> +++ b/lib/bpf/bpf_convert.c
> @@ -23,11 +23,8 @@
>   #include <rte_malloc.h>
>   #include <rte_errno.h>
>   
> -/* Workaround name conflicts with libpcap */
> -#define bpf_validate(f, len) bpf_validate_libpcap(f, len)
>   #include <pcap/pcap.h>
>   #include <pcap/bpf.h>
> -#undef bpf_validate
>   
>   #include "bpf_impl.h"
>   #include "bpf_def.h"
> diff --git a/lib/bpf/bpf_impl.h b/lib/bpf/bpf_impl.h
> index b4d8e87c6d..e955b74181 100644
> --- a/lib/bpf/bpf_impl.h
> +++ b/lib/bpf/bpf_impl.h
> @@ -17,12 +17,10 @@ struct rte_bpf {
>   	uint32_t stack_sz;
>   };
>   
> -extern int bpf_validate(struct rte_bpf *bpf);
> -
> -extern int bpf_jit(struct rte_bpf *bpf);
> -
> -extern int bpf_jit_x86(struct rte_bpf *);
> -extern int bpf_jit_arm64(struct rte_bpf *);
> +extern int rte_bpf_validate(struct rte_bpf *bpf);
> +extern int rte_bpf_jit(struct rte_bpf *bpf);
> +extern int rte_bpf_jit_x86(struct rte_bpf *bpf);
> +extern int rte_bpf_jit_arm64(struct rte_bpf *bpf);

I am still not quite ok to us 'rte_' prefix for internal library 
functions...
Might be at least '_rte_', or '_bpf_'?
Another ask - can you put comment here with advise for future
add-ons to avoid pure 'bpf_' prefix and why.
Konstantin


>   extern int rte_bpf_logtype;
>   
> diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
> index db79ff7385..d1ab5f8fbf 100644
> --- a/lib/bpf/bpf_jit_arm64.c
> +++ b/lib/bpf/bpf_jit_arm64.c
> @@ -1393,7 +1393,7 @@ emit(struct a64_jit_ctx *ctx, struct rte_bpf *bpf)
>    * Produce a native ISA version of the given BPF code.
>    */
>   int
> -bpf_jit_arm64(struct rte_bpf *bpf)
> +rte_bpf_jit_arm64(struct rte_bpf *bpf)
>   {
>   	struct a64_jit_ctx ctx;
>   	size_t size;
> diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
> index c1a30e0386..182004ac7d 100644
> --- a/lib/bpf/bpf_jit_x86.c
> +++ b/lib/bpf/bpf_jit_x86.c
> @@ -1490,7 +1490,7 @@ emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)
>    * produce a native ISA version of the given BPF code.
>    */
>   int
> -bpf_jit_x86(struct rte_bpf *bpf)
> +rte_bpf_jit_x86(struct rte_bpf *bpf)
>   {
>   	int32_t rc;
>   	uint32_t i;
> diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
> index 1e17df6ce0..2c4bca3586 100644
> --- a/lib/bpf/bpf_load.c
> +++ b/lib/bpf/bpf_load.c
> @@ -108,9 +108,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm)
>   		return NULL;
>   	}
>   
> -	rc = bpf_validate(bpf);
> +	rc = rte_bpf_validate(bpf);
>   	if (rc == 0) {
> -		bpf_jit(bpf);
> +		rte_bpf_jit(bpf);
>   		if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
>   			rc = -ENOMEM;
>   	}
> diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
> index 61cbb42216..2d3d899966 100644
> --- a/lib/bpf/bpf_validate.c
> +++ b/lib/bpf/bpf_validate.c
> @@ -2302,7 +2302,7 @@ evaluate(struct bpf_verifier *bvf)
>   }
>   
>   int
> -bpf_validate(struct rte_bpf *bpf)
> +rte_bpf_validate(struct rte_bpf *bpf)
>   {
>   	int32_t rc;
>   	struct bpf_verifier bvf;
  
J.J. Martzki March 13, 2023, 1:50 a.m. UTC | #2
Actually I'm still hesitating about the 'rte_' prefix either. So I'll
try a new prefix in the next version, comments will be added together
:)

Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> 于2023年3月12日周日 22:02写道:
>
> 12/03/2023 06:20, J.J. Martzki пишет:
> > The library libpcap has their function 'bpf_validate' either so there would
> > be a multiple definition issue when linking with librte_bpf.a and libpcap.a
> > statically (Same as http://dpdk.org/patch/52631). So just rename the
> > function names to avoid such issue.
> >
> > Signed-off-by: J.J. Martzki <mars14850@gmail.com>
> >
> > ---
> > v4:
> > * Update my name.
> > v3:
> > * Rewrite the commit message.
> > v2:
> > * Rename all functions in bpf_impl.h.
> > * Adjust the commit message.
> > ---
> >   lib/bpf/bpf.c           |  6 +++---
> >   lib/bpf/bpf_convert.c   |  3 ---
> >   lib/bpf/bpf_impl.h      | 10 ++++------
> >   lib/bpf/bpf_jit_arm64.c |  2 +-
> >   lib/bpf/bpf_jit_x86.c   |  2 +-
> >   lib/bpf/bpf_load.c      |  4 ++--
> >   lib/bpf/bpf_validate.c  |  2 +-
> >   7 files changed, 12 insertions(+), 17 deletions(-)
> >
> > diff --git a/lib/bpf/bpf.c b/lib/bpf/bpf.c
> > index 1e1dd42a58..f218a8f2b0 100644
> > --- a/lib/bpf/bpf.c
> > +++ b/lib/bpf/bpf.c
> > @@ -31,14 +31,14 @@ rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
> >   }
> >
> >   int
> > -bpf_jit(struct rte_bpf *bpf)
> > +rte_bpf_jit(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >
> >   #if defined(RTE_ARCH_X86_64)
> > -     rc = bpf_jit_x86(bpf);
> > +     rc = rte_bpf_jit_x86(bpf);
> >   #elif defined(RTE_ARCH_ARM64)
> > -     rc = bpf_jit_arm64(bpf);
> > +     rc = rte_bpf_jit_arm64(bpf);
> >   #else
> >       rc = -ENOTSUP;
> >   #endif
> > diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
> > index 9563274c9c..d441be6663 100644
> > --- a/lib/bpf/bpf_convert.c
> > +++ b/lib/bpf/bpf_convert.c
> > @@ -23,11 +23,8 @@
> >   #include <rte_malloc.h>
> >   #include <rte_errno.h>
> >
> > -/* Workaround name conflicts with libpcap */
> > -#define bpf_validate(f, len) bpf_validate_libpcap(f, len)
> >   #include <pcap/pcap.h>
> >   #include <pcap/bpf.h>
> > -#undef bpf_validate
> >
> >   #include "bpf_impl.h"
> >   #include "bpf_def.h"
> > diff --git a/lib/bpf/bpf_impl.h b/lib/bpf/bpf_impl.h
> > index b4d8e87c6d..e955b74181 100644
> > --- a/lib/bpf/bpf_impl.h
> > +++ b/lib/bpf/bpf_impl.h
> > @@ -17,12 +17,10 @@ struct rte_bpf {
> >       uint32_t stack_sz;
> >   };
> >
> > -extern int bpf_validate(struct rte_bpf *bpf);
> > -
> > -extern int bpf_jit(struct rte_bpf *bpf);
> > -
> > -extern int bpf_jit_x86(struct rte_bpf *);
> > -extern int bpf_jit_arm64(struct rte_bpf *);
> > +extern int rte_bpf_validate(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit_x86(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit_arm64(struct rte_bpf *bpf);
>
> I am still not quite ok to us 'rte_' prefix for internal library
> functions...
> Might be at least '_rte_', or '_bpf_'?
> Another ask - can you put comment here with advise for future
> add-ons to avoid pure 'bpf_' prefix and why.
> Konstantin
>
>
> >   extern int rte_bpf_logtype;
> >
> > diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
> > index db79ff7385..d1ab5f8fbf 100644
> > --- a/lib/bpf/bpf_jit_arm64.c
> > +++ b/lib/bpf/bpf_jit_arm64.c
> > @@ -1393,7 +1393,7 @@ emit(struct a64_jit_ctx *ctx, struct rte_bpf *bpf)
> >    * Produce a native ISA version of the given BPF code.
> >    */
> >   int
> > -bpf_jit_arm64(struct rte_bpf *bpf)
> > +rte_bpf_jit_arm64(struct rte_bpf *bpf)
> >   {
> >       struct a64_jit_ctx ctx;
> >       size_t size;
> > diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
> > index c1a30e0386..182004ac7d 100644
> > --- a/lib/bpf/bpf_jit_x86.c
> > +++ b/lib/bpf/bpf_jit_x86.c
> > @@ -1490,7 +1490,7 @@ emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)
> >    * produce a native ISA version of the given BPF code.
> >    */
> >   int
> > -bpf_jit_x86(struct rte_bpf *bpf)
> > +rte_bpf_jit_x86(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >       uint32_t i;
> > diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
> > index 1e17df6ce0..2c4bca3586 100644
> > --- a/lib/bpf/bpf_load.c
> > +++ b/lib/bpf/bpf_load.c
> > @@ -108,9 +108,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm)
> >               return NULL;
> >       }
> >
> > -     rc = bpf_validate(bpf);
> > +     rc = rte_bpf_validate(bpf);
> >       if (rc == 0) {
> > -             bpf_jit(bpf);
> > +             rte_bpf_jit(bpf);
> >               if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
> >                       rc = -ENOMEM;
> >       }
> > diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
> > index 61cbb42216..2d3d899966 100644
> > --- a/lib/bpf/bpf_validate.c
> > +++ b/lib/bpf/bpf_validate.c
> > @@ -2302,7 +2302,7 @@ evaluate(struct bpf_verifier *bvf)
> >   }
> >
> >   int
> > -bpf_validate(struct rte_bpf *bpf)
> > +rte_bpf_validate(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >       struct bpf_verifier bvf;
>
  
J.J. Martzki March 13, 2023, 2:55 p.m. UTC | #3
I've read the libbpf code again and I found some other functions with
pure 'bpf_' prefix. Should we rename all the functions whose names
start with pure 'bpf_'?

Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> 于2023年3月12日周日 22:02写道:
>
> 12/03/2023 06:20, J.J. Martzki пишет:
> > The library libpcap has their function 'bpf_validate' either so there would
> > be a multiple definition issue when linking with librte_bpf.a and libpcap.a
> > statically (Same as http://dpdk.org/patch/52631). So just rename the
> > function names to avoid such issue.
> >
> > Signed-off-by: J.J. Martzki <mars14850@gmail.com>
> >
> > ---
> > v4:
> > * Update my name.
> > v3:
> > * Rewrite the commit message.
> > v2:
> > * Rename all functions in bpf_impl.h.
> > * Adjust the commit message.
> > ---
> >   lib/bpf/bpf.c           |  6 +++---
> >   lib/bpf/bpf_convert.c   |  3 ---
> >   lib/bpf/bpf_impl.h      | 10 ++++------
> >   lib/bpf/bpf_jit_arm64.c |  2 +-
> >   lib/bpf/bpf_jit_x86.c   |  2 +-
> >   lib/bpf/bpf_load.c      |  4 ++--
> >   lib/bpf/bpf_validate.c  |  2 +-
> >   7 files changed, 12 insertions(+), 17 deletions(-)
> >
> > diff --git a/lib/bpf/bpf.c b/lib/bpf/bpf.c
> > index 1e1dd42a58..f218a8f2b0 100644
> > --- a/lib/bpf/bpf.c
> > +++ b/lib/bpf/bpf.c
> > @@ -31,14 +31,14 @@ rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
> >   }
> >
> >   int
> > -bpf_jit(struct rte_bpf *bpf)
> > +rte_bpf_jit(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >
> >   #if defined(RTE_ARCH_X86_64)
> > -     rc = bpf_jit_x86(bpf);
> > +     rc = rte_bpf_jit_x86(bpf);
> >   #elif defined(RTE_ARCH_ARM64)
> > -     rc = bpf_jit_arm64(bpf);
> > +     rc = rte_bpf_jit_arm64(bpf);
> >   #else
> >       rc = -ENOTSUP;
> >   #endif
> > diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
> > index 9563274c9c..d441be6663 100644
> > --- a/lib/bpf/bpf_convert.c
> > +++ b/lib/bpf/bpf_convert.c
> > @@ -23,11 +23,8 @@
> >   #include <rte_malloc.h>
> >   #include <rte_errno.h>
> >
> > -/* Workaround name conflicts with libpcap */
> > -#define bpf_validate(f, len) bpf_validate_libpcap(f, len)
> >   #include <pcap/pcap.h>
> >   #include <pcap/bpf.h>
> > -#undef bpf_validate
> >
> >   #include "bpf_impl.h"
> >   #include "bpf_def.h"
> > diff --git a/lib/bpf/bpf_impl.h b/lib/bpf/bpf_impl.h
> > index b4d8e87c6d..e955b74181 100644
> > --- a/lib/bpf/bpf_impl.h
> > +++ b/lib/bpf/bpf_impl.h
> > @@ -17,12 +17,10 @@ struct rte_bpf {
> >       uint32_t stack_sz;
> >   };
> >
> > -extern int bpf_validate(struct rte_bpf *bpf);
> > -
> > -extern int bpf_jit(struct rte_bpf *bpf);
> > -
> > -extern int bpf_jit_x86(struct rte_bpf *);
> > -extern int bpf_jit_arm64(struct rte_bpf *);
> > +extern int rte_bpf_validate(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit_x86(struct rte_bpf *bpf);
> > +extern int rte_bpf_jit_arm64(struct rte_bpf *bpf);
>
> I am still not quite ok to us 'rte_' prefix for internal library
> functions...
> Might be at least '_rte_', or '_bpf_'?
> Another ask - can you put comment here with advise for future
> add-ons to avoid pure 'bpf_' prefix and why.
> Konstantin
>
>
> >   extern int rte_bpf_logtype;
> >
> > diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
> > index db79ff7385..d1ab5f8fbf 100644
> > --- a/lib/bpf/bpf_jit_arm64.c
> > +++ b/lib/bpf/bpf_jit_arm64.c
> > @@ -1393,7 +1393,7 @@ emit(struct a64_jit_ctx *ctx, struct rte_bpf *bpf)
> >    * Produce a native ISA version of the given BPF code.
> >    */
> >   int
> > -bpf_jit_arm64(struct rte_bpf *bpf)
> > +rte_bpf_jit_arm64(struct rte_bpf *bpf)
> >   {
> >       struct a64_jit_ctx ctx;
> >       size_t size;
> > diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
> > index c1a30e0386..182004ac7d 100644
> > --- a/lib/bpf/bpf_jit_x86.c
> > +++ b/lib/bpf/bpf_jit_x86.c
> > @@ -1490,7 +1490,7 @@ emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)
> >    * produce a native ISA version of the given BPF code.
> >    */
> >   int
> > -bpf_jit_x86(struct rte_bpf *bpf)
> > +rte_bpf_jit_x86(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >       uint32_t i;
> > diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
> > index 1e17df6ce0..2c4bca3586 100644
> > --- a/lib/bpf/bpf_load.c
> > +++ b/lib/bpf/bpf_load.c
> > @@ -108,9 +108,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm)
> >               return NULL;
> >       }
> >
> > -     rc = bpf_validate(bpf);
> > +     rc = rte_bpf_validate(bpf);
> >       if (rc == 0) {
> > -             bpf_jit(bpf);
> > +             rte_bpf_jit(bpf);
> >               if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
> >                       rc = -ENOMEM;
> >       }
> > diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
> > index 61cbb42216..2d3d899966 100644
> > --- a/lib/bpf/bpf_validate.c
> > +++ b/lib/bpf/bpf_validate.c
> > @@ -2302,7 +2302,7 @@ evaluate(struct bpf_verifier *bvf)
> >   }
> >
> >   int
> > -bpf_validate(struct rte_bpf *bpf)
> > +rte_bpf_validate(struct rte_bpf *bpf)
> >   {
> >       int32_t rc;
> >       struct bpf_verifier bvf;
>
  
Stephen Hemminger March 13, 2023, 3:54 p.m. UTC | #4
On Mon, 13 Mar 2023 22:55:34 +0800
"J.J. Martzki" <mars14850@gmail.com> wrote:

> I've read the libbpf code again and I found some other functions with
> pure 'bpf_' prefix. Should we rename all the functions whose names
> start with pure 'bpf_'?

Yes, all visible (ie non-static) functions should use a DPDK style
prefix.
  
Konstantin Ananyev March 13, 2023, 5:07 p.m. UTC | #5
> I've read the libbpf code again and I found some other functions with
> pure 'bpf_' prefix. Should we rename all the functions whose names
> start with pure 'bpf_'?

I thought you already prefixed all non-static functions in the lib...
Or do I miss something? 
 
> Konstantin Ananyev <konstantin.v.ananyev@yandex.ru> 于2023年3月12日周日 22:02写道:
> >
> > 12/03/2023 06:20, J.J. Martzki пишет:
> > > The library libpcap has their function 'bpf_validate' either so there would
> > > be a multiple definition issue when linking with librte_bpf.a and libpcap.a
> > > statically (Same as http://dpdk.org/patch/52631). So just rename the
> > > function names to avoid such issue.
> > >
> > > Signed-off-by: J.J. Martzki <mars14850@gmail.com>
> > >
> > > ---
> > > v4:
> > > * Update my name.
> > > v3:
> > > * Rewrite the commit message.
> > > v2:
> > > * Rename all functions in bpf_impl.h.
> > > * Adjust the commit message.
> > > ---
> > >   lib/bpf/bpf.c           |  6 +++---
> > >   lib/bpf/bpf_convert.c   |  3 ---
> > >   lib/bpf/bpf_impl.h      | 10 ++++------
> > >   lib/bpf/bpf_jit_arm64.c |  2 +-
> > >   lib/bpf/bpf_jit_x86.c   |  2 +-
> > >   lib/bpf/bpf_load.c      |  4 ++--
> > >   lib/bpf/bpf_validate.c  |  2 +-
> > >   7 files changed, 12 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/lib/bpf/bpf.c b/lib/bpf/bpf.c
> > > index 1e1dd42a58..f218a8f2b0 100644
> > > --- a/lib/bpf/bpf.c
> > > +++ b/lib/bpf/bpf.c
> > > @@ -31,14 +31,14 @@ rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
> > >   }
> > >
> > >   int
> > > -bpf_jit(struct rte_bpf *bpf)
> > > +rte_bpf_jit(struct rte_bpf *bpf)
> > >   {
> > >       int32_t rc;
> > >
> > >   #if defined(RTE_ARCH_X86_64)
> > > -     rc = bpf_jit_x86(bpf);
> > > +     rc = rte_bpf_jit_x86(bpf);
> > >   #elif defined(RTE_ARCH_ARM64)
> > > -     rc = bpf_jit_arm64(bpf);
> > > +     rc = rte_bpf_jit_arm64(bpf);
> > >   #else
> > >       rc = -ENOTSUP;
> > >   #endif
> > > diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
> > > index 9563274c9c..d441be6663 100644
> > > --- a/lib/bpf/bpf_convert.c
> > > +++ b/lib/bpf/bpf_convert.c
> > > @@ -23,11 +23,8 @@
> > >   #include <rte_malloc.h>
> > >   #include <rte_errno.h>
> > >
> > > -/* Workaround name conflicts with libpcap */
> > > -#define bpf_validate(f, len) bpf_validate_libpcap(f, len)
> > >   #include <pcap/pcap.h>
> > >   #include <pcap/bpf.h>
> > > -#undef bpf_validate
> > >
> > >   #include "bpf_impl.h"
> > >   #include "bpf_def.h"
> > > diff --git a/lib/bpf/bpf_impl.h b/lib/bpf/bpf_impl.h
> > > index b4d8e87c6d..e955b74181 100644
> > > --- a/lib/bpf/bpf_impl.h
> > > +++ b/lib/bpf/bpf_impl.h
> > > @@ -17,12 +17,10 @@ struct rte_bpf {
> > >       uint32_t stack_sz;
> > >   };
> > >
> > > -extern int bpf_validate(struct rte_bpf *bpf);
> > > -
> > > -extern int bpf_jit(struct rte_bpf *bpf);
> > > -
> > > -extern int bpf_jit_x86(struct rte_bpf *);
> > > -extern int bpf_jit_arm64(struct rte_bpf *);
> > > +extern int rte_bpf_validate(struct rte_bpf *bpf);
> > > +extern int rte_bpf_jit(struct rte_bpf *bpf);
> > > +extern int rte_bpf_jit_x86(struct rte_bpf *bpf);
> > > +extern int rte_bpf_jit_arm64(struct rte_bpf *bpf);
> >
> > I am still not quite ok to us 'rte_' prefix for internal library
> > functions...
> > Might be at least '_rte_', or '_bpf_'?
> > Another ask - can you put comment here with advise for future
> > add-ons to avoid pure 'bpf_' prefix and why.
> > Konstantin
> >
> >
> > >   extern int rte_bpf_logtype;
> > >
> > > diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
> > > index db79ff7385..d1ab5f8fbf 100644
> > > --- a/lib/bpf/bpf_jit_arm64.c
> > > +++ b/lib/bpf/bpf_jit_arm64.c
> > > @@ -1393,7 +1393,7 @@ emit(struct a64_jit_ctx *ctx, struct rte_bpf *bpf)
> > >    * Produce a native ISA version of the given BPF code.
> > >    */
> > >   int
> > > -bpf_jit_arm64(struct rte_bpf *bpf)
> > > +rte_bpf_jit_arm64(struct rte_bpf *bpf)
> > >   {
> > >       struct a64_jit_ctx ctx;
> > >       size_t size;
> > > diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
> > > index c1a30e0386..182004ac7d 100644
> > > --- a/lib/bpf/bpf_jit_x86.c
> > > +++ b/lib/bpf/bpf_jit_x86.c
> > > @@ -1490,7 +1490,7 @@ emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)
> > >    * produce a native ISA version of the given BPF code.
> > >    */
> > >   int
> > > -bpf_jit_x86(struct rte_bpf *bpf)
> > > +rte_bpf_jit_x86(struct rte_bpf *bpf)
> > >   {
> > >       int32_t rc;
> > >       uint32_t i;
> > > diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
> > > index 1e17df6ce0..2c4bca3586 100644
> > > --- a/lib/bpf/bpf_load.c
> > > +++ b/lib/bpf/bpf_load.c
> > > @@ -108,9 +108,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm)
> > >               return NULL;
> > >       }
> > >
> > > -     rc = bpf_validate(bpf);
> > > +     rc = rte_bpf_validate(bpf);
> > >       if (rc == 0) {
> > > -             bpf_jit(bpf);
> > > +             rte_bpf_jit(bpf);
> > >               if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
> > >                       rc = -ENOMEM;
> > >       }
> > > diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
> > > index 61cbb42216..2d3d899966 100644
> > > --- a/lib/bpf/bpf_validate.c
> > > +++ b/lib/bpf/bpf_validate.c
> > > @@ -2302,7 +2302,7 @@ evaluate(struct bpf_verifier *bvf)
> > >   }
> > >
> > >   int
> > > -bpf_validate(struct rte_bpf *bpf)
> > > +rte_bpf_validate(struct rte_bpf *bpf)
> > >   {
> > >       int32_t rc;
> > >       struct bpf_verifier bvf;
> >
  
Stephen Hemminger March 13, 2023, 5:22 p.m. UTC | #6
On Mon, 13 Mar 2023 17:07:29 +0000
Konstantin Ananyev <konstantin.ananyev@huawei.com> wrote:

> > I've read the libbpf code again and I found some other functions with
> > pure 'bpf_' prefix. Should we rename all the functions whose names
> > start with pure 'bpf_'?  
> 
> I thought you already prefixed all non-static functions in the lib...
> Or do I miss something? 

Right, it was bpf_validate, bpf_jit_XXX that were not prefixed.

.../build/lib/librte_bpf.a.p $ nm * | grep ' T ' | grep -v 'rte_bpf'
0000000000000070 T bpf_jit
0000000000003210 T bpf_jit_x86
00000000000021f0 T bpf_validate
  
J.J. Martzki March 14, 2023, 2:21 a.m. UTC | #7
Ok, that was my mistake. I’ll send the new patch later :)

Sent from my iPhone

> On Mar 14, 2023, at 01:22, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Mon, 13 Mar 2023 17:07:29 +0000
> Konstantin Ananyev <konstantin.ananyev@huawei.com> wrote:
> 
>>> I've read the libbpf code again and I found some other functions with
>>> pure 'bpf_' prefix. Should we rename all the functions whose names
>>> start with pure 'bpf_'?  
>> 
>> I thought you already prefixed all non-static functions in the lib...
>> Or do I miss something? 
> 
> Right, it was bpf_validate, bpf_jit_XXX that were not prefixed.
> 
> .../build/lib/librte_bpf.a.p $ nm * | grep ' T ' | grep -v 'rte_bpf'
> 0000000000000070 T bpf_jit
> 0000000000003210 T bpf_jit_x86
> 00000000000021f0 T bpf_validate
  

Patch

diff --git a/lib/bpf/bpf.c b/lib/bpf/bpf.c
index 1e1dd42a58..f218a8f2b0 100644
--- a/lib/bpf/bpf.c
+++ b/lib/bpf/bpf.c
@@ -31,14 +31,14 @@  rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
 }
 
 int
-bpf_jit(struct rte_bpf *bpf)
+rte_bpf_jit(struct rte_bpf *bpf)
 {
 	int32_t rc;
 
 #if defined(RTE_ARCH_X86_64)
-	rc = bpf_jit_x86(bpf);
+	rc = rte_bpf_jit_x86(bpf);
 #elif defined(RTE_ARCH_ARM64)
-	rc = bpf_jit_arm64(bpf);
+	rc = rte_bpf_jit_arm64(bpf);
 #else
 	rc = -ENOTSUP;
 #endif
diff --git a/lib/bpf/bpf_convert.c b/lib/bpf/bpf_convert.c
index 9563274c9c..d441be6663 100644
--- a/lib/bpf/bpf_convert.c
+++ b/lib/bpf/bpf_convert.c
@@ -23,11 +23,8 @@ 
 #include <rte_malloc.h>
 #include <rte_errno.h>
 
-/* Workaround name conflicts with libpcap */
-#define bpf_validate(f, len) bpf_validate_libpcap(f, len)
 #include <pcap/pcap.h>
 #include <pcap/bpf.h>
-#undef bpf_validate
 
 #include "bpf_impl.h"
 #include "bpf_def.h"
diff --git a/lib/bpf/bpf_impl.h b/lib/bpf/bpf_impl.h
index b4d8e87c6d..e955b74181 100644
--- a/lib/bpf/bpf_impl.h
+++ b/lib/bpf/bpf_impl.h
@@ -17,12 +17,10 @@  struct rte_bpf {
 	uint32_t stack_sz;
 };
 
-extern int bpf_validate(struct rte_bpf *bpf);
-
-extern int bpf_jit(struct rte_bpf *bpf);
-
-extern int bpf_jit_x86(struct rte_bpf *);
-extern int bpf_jit_arm64(struct rte_bpf *);
+extern int rte_bpf_validate(struct rte_bpf *bpf);
+extern int rte_bpf_jit(struct rte_bpf *bpf);
+extern int rte_bpf_jit_x86(struct rte_bpf *bpf);
+extern int rte_bpf_jit_arm64(struct rte_bpf *bpf);
 
 extern int rte_bpf_logtype;
 
diff --git a/lib/bpf/bpf_jit_arm64.c b/lib/bpf/bpf_jit_arm64.c
index db79ff7385..d1ab5f8fbf 100644
--- a/lib/bpf/bpf_jit_arm64.c
+++ b/lib/bpf/bpf_jit_arm64.c
@@ -1393,7 +1393,7 @@  emit(struct a64_jit_ctx *ctx, struct rte_bpf *bpf)
  * Produce a native ISA version of the given BPF code.
  */
 int
-bpf_jit_arm64(struct rte_bpf *bpf)
+rte_bpf_jit_arm64(struct rte_bpf *bpf)
 {
 	struct a64_jit_ctx ctx;
 	size_t size;
diff --git a/lib/bpf/bpf_jit_x86.c b/lib/bpf/bpf_jit_x86.c
index c1a30e0386..182004ac7d 100644
--- a/lib/bpf/bpf_jit_x86.c
+++ b/lib/bpf/bpf_jit_x86.c
@@ -1490,7 +1490,7 @@  emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)
  * produce a native ISA version of the given BPF code.
  */
 int
-bpf_jit_x86(struct rte_bpf *bpf)
+rte_bpf_jit_x86(struct rte_bpf *bpf)
 {
 	int32_t rc;
 	uint32_t i;
diff --git a/lib/bpf/bpf_load.c b/lib/bpf/bpf_load.c
index 1e17df6ce0..2c4bca3586 100644
--- a/lib/bpf/bpf_load.c
+++ b/lib/bpf/bpf_load.c
@@ -108,9 +108,9 @@  rte_bpf_load(const struct rte_bpf_prm *prm)
 		return NULL;
 	}
 
-	rc = bpf_validate(bpf);
+	rc = rte_bpf_validate(bpf);
 	if (rc == 0) {
-		bpf_jit(bpf);
+		rte_bpf_jit(bpf);
 		if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
 			rc = -ENOMEM;
 	}
diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
index 61cbb42216..2d3d899966 100644
--- a/lib/bpf/bpf_validate.c
+++ b/lib/bpf/bpf_validate.c
@@ -2302,7 +2302,7 @@  evaluate(struct bpf_verifier *bvf)
 }
 
 int
-bpf_validate(struct rte_bpf *bpf)
+rte_bpf_validate(struct rte_bpf *bpf)
 {
 	int32_t rc;
 	struct bpf_verifier bvf;