Skip to contentSkip to conversation

build: fix libpcap detection with unusable header

PATCH In review Maayan Kashani 3 participants 6 messages Jul 7 – Jul 8 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: fix libpcap detection with unusable header

The libpcap detection only checked that the library was present, that <pcap.h> could be included, and that a trivial program links. None of these fail when a distribution ships a libpcap-devel package whose <pcap.h> is empty (present but declaring nothing) while libpcap.so is
installed: has_header() passes on an empty file and the link test does not reference any pcap symbol. RTE_HAS_LIBPCAP was then set and the pcap-dependent code (bpf_convert.c, port source/sink, dumpcap) failed to build with errors such as:

bpf_convert.c: error: invalid use of undefined type
'const struct bpf_insn'

Require an actual pcap declaration (pcap_create) to be visible in the header before enabling libpcap support, so a broken or empty header disables the optional pcap features instead of breaking the build.

Fixes d6024c0a6757 ("build: cleanup libpcap dependent components")
---
 config/meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
config/meson.build +4 -1
index d7f5e55c18f..4bfb8535781 100644
@@ -290,7 +290,10 @@ if not pcap_dep.found()
     # pcap got a pkg-config file only in 1.9.0
     pcap_dep = cc.find_library(pcap_lib, required: false)
 endif
-if (pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+# has_header() passes even when pcap.h is empty; require a real declaration.
+if (pcap_dep.found()
+        and cc.has_header_symbol('pcap.h', 'pcap_create', dependencies: pcap_dep,
+                args: '-D_GNU_SOURCE')
         and cc.links(min_c_code, dependencies: pcap_dep))
     dpdk_conf.set('RTE_HAS_LIBPCAP', 1)
     dpdk_extra_ldflags += '-l@0@'.format(pcap_lib)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 9 lines · Maayan Kashani

The libpcap detection only checked that the library was present, that <pcap.h> could be included, and that a trivial program links. None of these fail when a distribution ships a libpcap-devel package whose <pcap.h> is empty (present but declaring nothing) while libpcap.so is
installed: has_header() passes on an empty file and the link test does not reference any pcap symbol. RTE_HAS_LIBPCAP was then set and the pcap-dependent code (bpf_convert.c, port source/sink, dumpcap) failed to build with errors such as:

Why would a distribution ship a devel package with an empty header file for pcap.h? Is that expected behaviour in some scenario that I'm unaware of, because it seems strange to me?

/Bruce

Quoted 34 lines

bpf_convert.c: error: invalid use of undefined type
'const struct bpf_insn'

Require an actual pcap declaration (pcap_create) to be visible in the header before enabling libpcap support, so a broken or empty header disables the optional pcap features instead of breaking the build.

Fixes d6024c0a6757 ("build: cleanup libpcap dependent components")
---
 config/meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
config/meson.build +4 -1
index d7f5e55c18f..4bfb8535781 100644
@@ -290,7 +290,10 @@ if not pcap_dep.found()
     # pcap got a pkg-config file only in 1.9.0
     pcap_dep = cc.find_library(pcap_lib, required: false)
 endif
-if (pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+# has_header() passes even when pcap.h is empty; require a real declaration.
+if (pcap_dep.found()
+        and cc.has_header_symbol('pcap.h', 'pcap_create', dependencies: pcap_dep,
+                args: '-D_GNU_SOURCE')
         and cc.links(min_c_code, dependencies: pcap_dep))
     dpdk_conf.set('RTE_HAS_LIBPCAP', 1)
     dpdk_extra_ldflags += '-l@0@'.format(pcap_lib)
Signature · 1 line
2.21.0
#2 lore raw

Hi, Bruce,
we encountered DPDK build issue on Tencent 4.6.
It is not expected; the package/image appears corrupted.
RPM verification confirms the headers differ from the packaged contents. The DPDK change is still valid because optional dependency detection should test for usable declarations, not just file existence and library presence.”

Regards,
Maayan Kashani

Quoted 64 lines

-----Original Message-----
From: Bruce Richardson <[email protected]>
Sent: Tuesday, 7 July 2026 17:16
To: Maayan Kashani <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]; David Marchand <[email protected]>; Stephen Hemminger <[email protected]>
Subject: Re: [PATCH] build: fix libpcap detection with unusable header

External email: Use caution opening links or attachments

Quoted 9 lines · Maayan Kashani

The libpcap detection only checked that the library was present, that <pcap.h> could be included, and that a trivial program links. None of these fail when a distribution ships a libpcap-devel package whose <pcap.h> is empty (present but declaring nothing) while libpcap.so is
installed: has_header() passes on an empty file and the link test does not reference any pcap symbol. RTE_HAS_LIBPCAP was then set and the pcap-dependent code (bpf_convert.c, port source/sink, dumpcap) failed to build with errors such as:

Why would a distribution ship a devel package with an empty header file for pcap.h? Is that expected behaviour in some scenario that I'm unaware of, because it seems strange to me?

/Bruce

Quoted 20 lines

bpf_convert.c: error: invalid use of undefined type
'const struct bpf_insn'

Require an actual pcap declaration (pcap_create) to be visible in the header before enabling libpcap support, so a broken or empty header disables the optional pcap features instead of breaking the build.

Fixes d6024c0a6757 ("build: cleanup libpcap dependent components")
---
 config/meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
config/meson.build index renamed from config/meson.build +0 -0

d7f5e55c18f..4bfb8535781 100644

config/meson.build if not pcap_dep.found() · line 293

Quoted 4 lines
config/meson.build +1 -0
@@ -290,7 +290,10 @@ if not pcap_dep.found()
     # pcap got a pkg-config file only in 1.9.0
     pcap_dep = cc.find_library(pcap_lib, required: false)  endif -if
 (pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+# has_header() passes even when pcap.h is empty; require a real

declaration.

config/meson.build if not pcap_dep.found() · line 295

Quoted 2 lines
config/meson.build +2 -0
+if (pcap_dep.found()
+        and cc.has_header_symbol('pcap.h', 'pcap_create', dependencies:

pcap_dep,

Quoted 7 lines
config/meson.build +1 -1
+                args: '-D_GNU_SOURCE')
         and cc.links(min_c_code, dependencies: pcap_dep))
     dpdk_conf.set('RTE_HAS_LIBPCAP', 1)
     dpdk_extra_ldflags += '-l@0@'.format(pcap_lib)
--

2.21.0

#3 lore raw

Not sure. Working around busted packages in DPDK is a bad idea.

Quoted 79 lines · On Wed, Jul 8, 2026, 08:38 Maayan Kashani <[email protected]> wrote:

Hi, Bruce,
we encountered DPDK build issue on Tencent 4.6.
It is not expected; the package/image appears corrupted.
RPM verification confirms the headers differ from the packaged contents. The DPDK change is still valid because optional dependency detection should
test for usable declarations, not just file existence and library presence.”

Regards,
Maayan Kashani

Quoted 23 lines

-----Original Message-----
From: Bruce Richardson <[email protected]>
Sent: Tuesday, 7 July 2026 17:16
To: Maayan Kashani <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]; David Marchand <[email protected]>; Stephen Hemminger <[email protected]>
Subject: Re: [PATCH] build: fix libpcap detection with unusable header

External email: Use caution opening links or attachments

Quoted 9 lines · Maayan Kashani

The libpcap detection only checked that the library was present, that <pcap.h> could be included, and that a trivial program links. None of these fail when a distribution ships a libpcap-devel package whose <pcap.h> is empty (present but declaring nothing) while libpcap.so is
installed: has_header() passes on an empty file and the link test does not reference any pcap symbol. RTE_HAS_LIBPCAP was then set and the pcap-dependent code (bpf_convert.c, port source/sink, dumpcap) failed to build with errors such as:

Quoted 1 line

Why would a distribution ship a devel package with an empty header file

for

Quoted 20 lines

pcap.h? Is that expected behaviour in some scenario that I'm unaware of, because it seems strange to me?

/Bruce

Quoted 15 lines

bpf_convert.c: error: invalid use of undefined type
'const struct bpf_insn'

Require an actual pcap declaration (pcap_create) to be visible in the header before enabling libpcap support, so a broken or empty header disables the optional pcap features instead of breaking the build.

Fixes d6024c0a6757 ("build: cleanup libpcap dependent components")
---
 config/meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 12 lines

config/meson.build if not pcap_dep.found() · line 293

Quoted 9 lines
config/meson.build index renamed from config/meson.build +0 -0

d7f5e55c18f..4bfb8535781 100644

config/meson.build +1 -0
@@ -290,7 +290,10 @@ if not pcap_dep.found()
     # pcap got a pkg-config file only in 1.9.0
     pcap_dep = cc.find_library(pcap_lib, required: false)  endif -if
 (pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+# has_header() passes even when pcap.h is empty; require a real

declaration.

Quoted 2 lines
config/meson.build +2 -0
+if (pcap_dep.found()
+        and cc.has_header_symbol('pcap.h', 'pcap_create',

dependencies:

Quoted 8 lines

pcap_dep,

Quoted 7 lines
config/meson.build +1 -1
+                args: '-D_GNU_SOURCE')
         and cc.links(min_c_code, dependencies: pcap_dep))
     dpdk_conf.set('RTE_HAS_LIBPCAP', 1)
     dpdk_extra_ldflags += '-l@0@'.format(pcap_lib)
--

2.21.0

#4 lore raw

Understood. Thanks.

Regards,
Maayan Kashani

From: Stephen Hemminger <[email protected]>
Sent: Wednesday, 8 July 2026 10:11
To: Maayan Kashani <[email protected]>
Cc: Bruce Richardson <[email protected]>; dev <[email protected]>; Raslan Darawsheh <[email protected]>; stable <[email protected]>; David Marchand <[email protected]>
Subject: Re: [PATCH] build: fix libpcap detection with unusable header

External email: Use caution opening links or attachments

Not sure. Working around busted packages in DPDK is a bad idea.

On Wed, Jul 8, 2026, 08:38 Maayan Kashani <[email protected]<mailto:[email protected]>> wrote:
Hi, Bruce,
we encountered DPDK build issue on Tencent 4.6.
It is not expected; the package/image appears corrupted.
RPM verification confirms the headers differ from the packaged contents.
The DPDK change is still valid because optional dependency detection should
test for usable declarations, not just file existence and library presence.”

Regards,
Maayan Kashani

Quoted 64 lines

-----Original Message-----
From: Bruce Richardson <[email protected]<mailto:[email protected]>>
Sent: Tuesday, 7 July 2026 17:16
To: Maayan Kashani <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; Raslan Darawsheh <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>; David Marchand <[email protected]<mailto:[email protected]>>; Stephen Hemminger <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH] build: fix libpcap detection with unusable header

External email: Use caution opening links or attachments

Quoted 9 lines · Maayan Kashani

The libpcap detection only checked that the library was present, that <pcap.h> could be included, and that a trivial program links. None of these fail when a distribution ships a libpcap-devel package whose <pcap.h> is empty (present but declaring nothing) while libpcap.so is
installed: has_header() passes on an empty file and the link test does not reference any pcap symbol. RTE_HAS_LIBPCAP was then set and the pcap-dependent code (bpf_convert.c, port source/sink, dumpcap) failed to build with errors such as:

Why would a distribution ship a devel package with an empty header file for pcap.h? Is that expected behaviour in some scenario that I'm unaware of, because it seems strange to me?

/Bruce

Quoted 20 lines

bpf_convert.c: error: invalid use of undefined type
'const struct bpf_insn'

Require an actual pcap declaration (pcap_create) to be visible in the header before enabling libpcap support, so a broken or empty header disables the optional pcap features instead of breaking the build.

Fixes d6024c0a6757 ("build: cleanup libpcap dependent components")
---
 config/meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
config/meson.build index renamed from config/meson.build +0 -0

d7f5e55c18f..4bfb8535781 100644

config/meson.build if not pcap_dep.found() · line 293

Quoted 4 lines
config/meson.build +1 -0
@@ -290,7 +290,10 @@ if not pcap_dep.found()
     # pcap got a pkg-config file only in 1.9.0
     pcap_dep = cc.find_library(pcap_lib, required: false)  endif -if
 (pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+# has_header() passes even when pcap.h is empty; require a real

declaration.

config/meson.build if not pcap_dep.found() · line 295

Quoted 2 lines
config/meson.build +2 -0
+if (pcap_dep.found()
+        and cc.has_header_symbol('pcap.h', 'pcap_create', dependencies:

pcap_dep,

Quoted 7 lines
config/meson.build +1 -1
+                args: '-D_GNU_SOURCE')
         and cc.links(min_c_code, dependencies: pcap_dep))
     dpdk_conf.set('RTE_HAS_LIBPCAP', 1)
     dpdk_extra_ldflags += '-l@0@'.format(pcap_lib)
--

2.21.0

#5 lore raw
In reply to Maayan Kashani
Quoted 6 lines · Maayan Kashani

Hi, Bruce, we encountered DPDK build issue on Tencent 4.6. It is not expected; the package/image appears corrupted. RPM verification confirms the headers differ from the packaged contents. The DPDK change is still valid because optional dependency detection should test for usable declarations, not just file existence and library presence.”

I would disagree. Following that logic of checking for broken packages, you're only handling a very small subset of that. If we start checking this, we really should check for each and every definition in the file that we need - otherwise we can still have issues with a broken package, for example, it's broken in missing one definition that we need.

IMHO, in all these cases its better to let things fail, rather than working around them, in order to prompt correction of the broken package.

/Bruce