All of lore.kernel.org
 help / color / mirror / Atom feed
* using libbpf in external projects
@ 2020-03-22 18:50 Jason A. Donenfeld
  2020-03-23  5:37   ` Yonghong Song
  0 siblings, 1 reply; 6+ messages in thread
From: Jason A. Donenfeld @ 2020-03-22 18:50 UTC (permalink / raw)
  To: bpf; +Cc: nicolas, linux-kbuild

Hi,

Nicolas (CC'd) and I are working on a small utility that does some bpf
things. What it actually does isn't important. But I did just clean up
its use of libbpf by way of a Makefile:

> KERNEL_VERSION := 5.5.11
> PKG_CONFIG ?= pkg-config
>
> all: linux-$(KERNEL_VERSION)/.prepared
>     @$(MAKE) --no-print-directory netifexec
>
> linux-$(KERNEL_VERSION)/.prepared:
>     curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(KERNEL_VERSION).tar.xz | tar xJf -
>     touch $@
>
> CFLAGS ?= -O3
> CFLAGS += -Ilinux-$(KERNEL_VERSION)/tools/lib/bpf -Ilinux-$(KERNEL_VERSION)/tools/include -Ilinux-$(KERNEL_VERSION)/tools/include/uapi
> CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
> CFLAGS += -MMD -MP
> CFLAGS += -std=gnu99 -D_GNU_SOURCE
> CFLAGS += -Wall
> CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf zlib)
> LDLIBS += $(shell $(PKG_CONFIG) --libs libelf zlib)
>
> netifexec: $(sort $(patsubst %.c,%.o,$(wildcard *.c linux-$(KERNEL_VERSION)/tools/lib/bpf/*.c)))
>
> clean:
>     $(RM) netifexec *.o *.d linux-$(KERNEL_VERSION)/tools/lib/bpf/*.o linux-$(KERNEL_VERSION)/tools/lib/bpf/*.d
>
> mrproper: clean
>     $(RM) -r linux-$(KERNEL_VERSION)
>
> .PHONY: all clean mrproper

Ignoring that piping curl to tar with no hash checking is unsafe, is
this kind of embedding something you intended people would do to use
this code externally? Or is there another distribution of this library
from elsewhere that you'd recommend?

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using libbpf in external projects
  2020-03-22 18:50 using libbpf in external projects Jason A. Donenfeld
@ 2020-03-23  5:37   ` Yonghong Song
  0 siblings, 0 replies; 6+ messages in thread
From: Yonghong Song @ 2020-03-23  5:37 UTC (permalink / raw)
  To: Jason A. Donenfeld, bpf; +Cc: nicolas, linux-kbuild



On 3/22/20 11:50 AM, Jason A. Donenfeld wrote:
> Hi,
> 
> Nicolas (CC'd) and I are working on a small utility that does some bpf
> things. What it actually does isn't important. But I did just clean up
> its use of libbpf by way of a Makefile:
> 
>> KERNEL_VERSION := 5.5.11
>> PKG_CONFIG ?= pkg-config
>>
>> all: linux-$(KERNEL_VERSION)/.prepared
>>      @$(MAKE) --no-print-directory netifexec
>>
>> linux-$(KERNEL_VERSION)/.prepared:
>>      curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(KERNEL_VERSION).tar.xz | tar xJf -
>>      touch $@
>>
>> CFLAGS ?= -O3
>> CFLAGS += -Ilinux-$(KERNEL_VERSION)/tools/lib/bpf -Ilinux-$(KERNEL_VERSION)/tools/include -Ilinux-$(KERNEL_VERSION)/tools/include/uapi
>> CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
>> CFLAGS += -MMD -MP
>> CFLAGS += -std=gnu99 -D_GNU_SOURCE
>> CFLAGS += -Wall
>> CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf zlib)
>> LDLIBS += $(shell $(PKG_CONFIG) --libs libelf zlib)
>>
>> netifexec: $(sort $(patsubst %.c,%.o,$(wildcard *.c linux-$(KERNEL_VERSION)/tools/lib/bpf/*.c)))
>>
>> clean:
>>      $(RM) netifexec *.o *.d linux-$(KERNEL_VERSION)/tools/lib/bpf/*.o linux-$(KERNEL_VERSION)/tools/lib/bpf/*.d
>>
>> mrproper: clean
>>      $(RM) -r linux-$(KERNEL_VERSION)
>>
>> .PHONY: all clean mrproper
> 
> Ignoring that piping curl to tar with no hash checking is unsafe, is
> this kind of embedding something you intended people would do to use
> this code externally? Or is there another distribution of this library
> from elsewhere that you'd recommend?

Jason, we have libbpf github mirror
    https://github.com/libbpf/libbpf
for the libbpf codes here.
Please take a look. The Makefile in the kernel tree contains some kernel
specific definitions/paths etc. The Makefile in the github is more 
suitable to be included/adapted for user space application.
You are welcome to contribute there (w.r.t. easy-to-use Makefile).

> 
> Jason
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using libbpf in external projects
@ 2020-03-23  5:37   ` Yonghong Song
  0 siblings, 0 replies; 6+ messages in thread
From: Yonghong Song @ 2020-03-23  5:37 UTC (permalink / raw)
  To: Jason A. Donenfeld, bpf; +Cc: nicolas, linux-kbuild



On 3/22/20 11:50 AM, Jason A. Donenfeld wrote:
> Hi,
> 
> Nicolas (CC'd) and I are working on a small utility that does some bpf
> things. What it actually does isn't important. But I did just clean up
> its use of libbpf by way of a Makefile:
> 
>> KERNEL_VERSION := 5.5.11
>> PKG_CONFIG ?= pkg-config
>>
>> all: linux-$(KERNEL_VERSION)/.prepared
>>      @$(MAKE) --no-print-directory netifexec
>>
>> linux-$(KERNEL_VERSION)/.prepared:
>>      curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(KERNEL_VERSION).tar.xz | tar xJf -
>>      touch $@
>>
>> CFLAGS ?= -O3
>> CFLAGS += -Ilinux-$(KERNEL_VERSION)/tools/lib/bpf -Ilinux-$(KERNEL_VERSION)/tools/include -Ilinux-$(KERNEL_VERSION)/tools/include/uapi
>> CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
>> CFLAGS += -MMD -MP
>> CFLAGS += -std=gnu99 -D_GNU_SOURCE
>> CFLAGS += -Wall
>> CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf zlib)
>> LDLIBS += $(shell $(PKG_CONFIG) --libs libelf zlib)
>>
>> netifexec: $(sort $(patsubst %.c,%.o,$(wildcard *.c linux-$(KERNEL_VERSION)/tools/lib/bpf/*.c)))
>>
>> clean:
>>      $(RM) netifexec *.o *.d linux-$(KERNEL_VERSION)/tools/lib/bpf/*.o linux-$(KERNEL_VERSION)/tools/lib/bpf/*.d
>>
>> mrproper: clean
>>      $(RM) -r linux-$(KERNEL_VERSION)
>>
>> .PHONY: all clean mrproper
> 
> Ignoring that piping curl to tar with no hash checking is unsafe, is
> this kind of embedding something you intended people would do to use
> this code externally? Or is there another distribution of this library
> from elsewhere that you'd recommend?

Jason, we have libbpf github mirror
    https://github.com/libbpf/libbpf
for the libbpf codes here.
Please take a look. The Makefile in the kernel tree contains some kernel
specific definitions/paths etc. The Makefile in the github is more 
suitable to be included/adapted for user space application.
You are welcome to contribute there (w.r.t. easy-to-use Makefile).

> 
> Jason
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using libbpf in external projects
  2020-03-23  5:37   ` Yonghong Song
  (?)
@ 2020-03-23  5:59   ` Jason A. Donenfeld
  2020-03-23 17:50     ` Andrii Nakryiko
  -1 siblings, 1 reply; 6+ messages in thread
From: Jason A. Donenfeld @ 2020-03-23  5:59 UTC (permalink / raw)
  To: Yonghong Song; +Cc: bpf, nicolas, linux-kbuild

Thanks! That's much nicer to use:

https://git.zx2c4.com/netifexec/commit/?id=8a39f70c981264500d27e90bbd5e3baf8f2d10d3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using libbpf in external projects
  2020-03-23  5:59   ` Jason A. Donenfeld
@ 2020-03-23 17:50     ` Andrii Nakryiko
  2020-03-23 18:17       ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2020-03-23 17:50 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: Yonghong Song, bpf, nicolas, Linux Kbuild mailing list

On Sun, Mar 22, 2020 at 11:00 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> Thanks! That's much nicer to use:
>
> https://git.zx2c4.com/netifexec/commit/?id=8a39f70c981264500d27e90bbd5e3baf8f2d10d3


You probably don't want to compile libbpf with your custom rules. See
BCC libbpf-tools [0] on how to do this when you use libbpf as a
submodule. The idea is to do a sub-make call and let libbpf's Makefile
deal with everything.

Having said that, though, libbpf is packaged properly for Fedora (and
I think maybe for OpenSUSE and Debian, but not sure), so if you can
rely on libbpf package, that would probably be easiest and best. If
Linux distribution(s) you are targeting doesn't have libbpf package
yet, we'd really appreciate you reaching out to packager and asking
them to follow Fedora and do it :) Would make everyone's job easier in
long term. Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: using libbpf in external projects
  2020-03-23 17:50     ` Andrii Nakryiko
@ 2020-03-23 18:17       ` Andrii Nakryiko
  0 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2020-03-23 18:17 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: Yonghong Song, bpf, nicolas, Linux Kbuild mailing list

On Mon, Mar 23, 2020 at 10:50 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sun, Mar 22, 2020 at 11:00 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> >
> > Thanks! That's much nicer to use:
> >
> > https://git.zx2c4.com/netifexec/commit/?id=8a39f70c981264500d27e90bbd5e3baf8f2d10d3
>
>
> You probably don't want to compile libbpf with your custom rules. See
> BCC libbpf-tools [0] on how to do this when you use libbpf as a
> submodule. The idea is to do a sub-make call and let libbpf's Makefile
> deal with everything.
>
> Having said that, though, libbpf is packaged properly for Fedora (and
> I think maybe for OpenSUSE and Debian, but not sure), so if you can
> rely on libbpf package, that would probably be easiest and best. If
> Linux distribution(s) you are targeting doesn't have libbpf package
> yet, we'd really appreciate you reaching out to packager and asking
> them to follow Fedora and do it :) Would make everyone's job easier in
> long term. Thanks!

Just realized I didn't paste the link:

  [0] https://github.com/iovisor/bcc/tree/master/libbpf-tools

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-23 18:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-22 18:50 using libbpf in external projects Jason A. Donenfeld
2020-03-23  5:37 ` Yonghong Song
2020-03-23  5:37   ` Yonghong Song
2020-03-23  5:59   ` Jason A. Donenfeld
2020-03-23 17:50     ` Andrii Nakryiko
2020-03-23 18:17       ` Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.