Skip to contentSkip to conversation

include: uapi: netfilter_bridge.h: Cover for musl libc

PATCH New Sasha Levin 1 participant 1 message Feb 23

Subsystems (2)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/1 include: uapi: netfilter_bridge.h: Cover for musl libc

From: Phil Sutter <[email protected]>

[ Upstream commit 4edd4ba71ce0df015303dba75ea9d20d1a217546 ]

Musl defines its own struct ethhdr and thus defines __UAPI_DEF_ETHHDR to zero. To avoid struct redefinition errors, user space is therefore supposed to include netinet/if_ether.h before (or instead of) linux/if_ether.h. To relieve them from this burden, include the libc header here if not building for kernel space.

---

LLM Generated explanations, may be completely bogus:

I have enough information to make a thorough analysis.

## Analysis

### 1. Commit Message Analysis

The commit fixes a **userspace build failure** when compiling programs against musl libc that include <linux/netfilter_bridge.h>. Musl defines its own struct ethhdr and sets __UAPI_DEF_ETHHDR to zero to tell kernel UAPI headers not to redefine it. However, this mechanism only works if musl's <netinet/if_ether.h> is included *before* the kernel's <linux/if_ether.h>. Without this fix, including <linux/netfilter_bridge.h> (which transitively includes <linux/if_ether.h>) results in struct redefinition errors.

The commit has a Reported-by: tag from Alyssa Ross, indicating a real user hit this issue.

### 2. Code Change Analysis

The change is minimal - 3 lines added:

```c
#ifndef __KERNEL__
#include <netinet/if_ether.h>   /* for __UAPI_DEF_ETHHDR if defined */
#endif
```

This is inserted before the existing #include <linux/if_ether.h>, so that musl's <netinet/if_ether.h> sets __UAPI_DEF_ETHHDR=0 before the kernel header checks it. The #ifndef __KERNEL__ guard ensures this only affects userspace compilation - the kernel build is completely unaffected.

### 3. Classification

This is a **build fix** for UAPI headers. The stable kernel rules explicitly allow build fixes ("Fixes for compilation errors or warnings... These are critical for users who need to build the kernel").

### 4. Scope and Risk Assessment

- **Lines changed**: 3 lines added (plus context from moved lines in the diff)
- **Files touched**: 1 UAPI header file
- **Risk**: Essentially zero. The added code is guarded by #ifndef __KERNEL__, so it cannot affect kernel compilation or runtime in any way. It only affects userspace programs including this header.
- **Kernel runtime impact**: None whatsoever

### 5. Precedent

This follows an established pattern used in multiple other UAPI headers:
- include/uapi/linux/mptcp.h - includes <netinet/in.h> and <sys/socket.h> for the same reason (commit 06e445f740c1a, which had a Fixes: tag)
- include/uapi/linux/if.h - includes <sys/socket.h>
- include/uapi/linux/vm_sockets.h - includes <sys/socket.h>

The original __UAPI_DEF_ETHHDR mechanism was added in commit 6926e041a8920 specifically for musl compatibility.

### 6. User Impact

Users compiling netfilter/ebtables userspace tools (like iptables, nftables, ebtables) against musl libc are affected. This is particularly relevant for:
- Alpine Linux and other musl-based distributions
- Embedded systems using musl
- Container environments using musl-based images (e.g., Alpine Docker images)

Without this fix, these users must manually ensure <netinet/if_ether.h> is included before any kernel netfilter headers, which is fragile and error-prone.

### 7. Dependencies

None. The patch is completely self-contained. The __UAPI_DEF_ETHHDR mechanism in include/uapi/linux/if_ether.h has been present since 2018 (commit 6926e041a8920), so it exists in all active stable trees.

### Verification

- Verified the current file contents via Read of include/uapi/linux/netfilter_bridge.h - confirmed it includes <linux/if_ether.h> which defines struct ethhdr
- Verified include/uapi/linux/if_ether.h lines 171-182 show the __UAPI_DEF_ETHHDR guard mechanism exists and works by checking the macro before defining struct ethhdr
- Verified via git log that the __UAPI_DEF_ETHHDR mechanism was introduced in commit 6926e041a8920 (2018) - present in all stable trees
- Verified the established pattern via Explore agent: similar musl- compat fixes exist in mptcp.h, if.h, vm_sockets.h, ethtool.h
- Verified the mptcp precedent (06e445f740c1a) was a similar fix with a Fixes: tag, confirming this class of fix is considered bug-worthy
- Verified via lore.kernel.org that the patch went through proper review via the netfilter-devel list and was included in Florian Westphal's netfilter patch series
- Could NOT verify if the mptcp fix was specifically backported to stable trees (unverified), but it had a Fixes: tag which would trigger auto-selection

### Conclusion

This is a textbook build fix for a UAPI header. It:
1. Fixes a real compilation error reported by a real user
2. Is obviously correct - follows an established pattern used in other headers
3. Is tiny (3 lines) with zero risk to kernel runtime
4. Has no dependencies on other commits
5. Falls squarely within the "build fixes" exception for stable

**YES**

 include/uapi/linux/netfilter_bridge.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/linux/netfilter_bridge.h +4 -0
index 1610fdbab98df..ad520d3e9df8f 100644
@@ -5,6 +5,10 @@
 /* bridge-specific defines for netfilter. 
  */
 
+#ifndef __KERNEL__
+#include <netinet/if_ether.h>	/* for __UAPI_DEF_ETHHDR if defined */
+#endif
+
 #include <linux/in.h>
 #include <linux/netfilter.h>
 #include <linux/if_ether.h>
Signature · 1 line
2.51.0