<net/if.h> and <linux/if.h> are incompatible

Bug #673073 reported by Colin Watson
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
eglibc (Ubuntu)
Invalid
High
Unassigned
linux (Ubuntu)
Fix Released
High
Andy Whitcroft

Bug Description

The following minimal test program:

  #include <net/if.h>
  #include <linux/rtnetlink.h>
  int main (int argc, char **argv) { return 0; }

compiled successfully in Ubuntu 10.10, but fails in the in-development Natty series (libc6-dev 2.12.1-0ubuntu8, linux-libc-dev 2.6.37-2.10) as follows:

  $ gcc -Wall t.c -o t
  In file included from /usr/include/linux/netdevice.h:28:0,
                   from /usr/include/linux/rtnetlink.h:9,
                   from t.c:2:
  /usr/include/linux/if.h:135:8: error: redefinition of ‘struct ifmap’
  /usr/include/net/if.h:112:8: note: originally defined here
  /usr/include/linux/if.h:169:8: error: redefinition of ‘struct ifreq’
  /usr/include/net/if.h:127:8: note: originally defined here
  /usr/include/linux/if.h:218:8: error: redefinition of ‘struct ifconf’
  /usr/include/net/if.h:177:8: note: originally defined here

So far, this problem has bitten busybox, wireless-tools, and NetworkManager.

This was triggered by a change in Linux 2.6.37-rc1 which added '#include <linux/netdevice.h>' to include/linux/rtnetlink.h, so I'm filing this bug on both libc and the kernel. It might be possible to work around this in the kernel in a way that's less intrusive to userspace applications, but really, I think the problem is that you can't include both <net/if.h> and <linux/if.h> (even transitively) at the same time. Until that's fixed, it's difficult to use the generic net headers together with Linux-specific features - note that there's no way to get at the functionality from <linux/rtnetlink.h> without including a <linux/*> header directly.

It's possible to work around this by shuffling includes to avoid using <net/if.h> and only use <linux/if.h> (you typically have to include <sys/socket.h> too), but it's messy and it would be better to steer in the direction of fewer <linux/*> inclusions in userspace applications, not more.

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

wpasupplicant is touched by this as well, both in its current version and the 0.7.3 packaging in Debian SVN.

Revision history for this message
Loïc Minier (lool) wrote :

I checked the upstream glibc list and git repos and didn't see anything related going in

Revision history for this message
Loïc Minier (lool) wrote :

This also affects glibc itself: sysdeps/unix/sysv/linux/if_index.c #includes net/if.h and glibc's netlinkaccess.h which includes linux/rtnetlink.h.

Revision history for this message
Loïc Minier (lool) wrote :

I checked Fedora's glibc packaging git and while it patches sysdeps/unix/sysv/linux/netlinkaccess.h, it doesn't help this particular issue.

Revision history for this message
Colin Watson (cjwatson) wrote :

netcfg was also affected. Workaround:

+#ifdef __linux__
+#include <linux/if.h>
+#else
 #include <net/if.h>
+#endif

Revision history for this message
Matthias Klose (doko) wrote :

this blocks the initial eglibc upload for natty, independently where the change has to be made

Changed in linux (Ubuntu):
importance: Undecided → High
milestone: none → natty-alpha-1
status: New → Confirmed
Changed in eglibc (Ubuntu):
importance: Undecided → High
milestone: none → natty-alpha-1
status: New → Confirmed
Andy Whitcroft (apw)
Changed in linux (Ubuntu):
assignee: nobody → Andy Whitcroft (apw)
Revision history for this message
Andy Whitcroft (apw) wrote :

This looks to be triggered by a new header added to rtnetlink.h. By the looks of things this is not required for userspace use, and all uses of it within the header are limited to the kernel. Moving the include down to the kernel section seems to sort out the issue. Will push a patch to this effect upstream.

Andy Whitcroft (apw)
Changed in linux (Ubuntu):
status: Confirmed → In Progress
Revision history for this message
Colin Watson (cjwatson) wrote : Re: [Bug 673073] Re: <net/if.h> and <linux/if.h> are incompatible

Sounds plausible. Thanks!

Revision history for this message
Matthias Klose (doko) wrote :

linux-libc-dev test package provided by apw does work

Changed in eglibc (Ubuntu):
status: Confirmed → Invalid
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package linux - 2.6.37-4.12

---------------
linux (2.6.37-4.12) natty; urgency=low

  [ Andy Whitcroft ]

  * Revert "[Upstream] HID: magicmouse: add param for scroll speed"
  * Revert "[Upstream] HID: magicmouse: properly account for scroll
    movement in state"
  * Revert "[Upstream] HID: magicmouse: disable and add module param for
    scroll acceleration"
  * Revert "[Upstream] HID: magicmouse: scroll on entire surface, not just
    middle of mouse"

  [ Henrik Rydberg ]

  * SAUCE: hid: ntrig: remove sysfs nodes
  * SAUCE: hid: ntrig: Setup input filtering manually
  * SAUCE: hid: ntrig: New ghost-filtering event logic

  [ Manoj Iyer ]

  * SAUCE: Added quirk to recognize GE0301 3G modem as an interface.
    - LP: #348861

  [ Upstream Kernel Changes ]

  * Revert "mmc: fix all hangs related to mmc/sd card insert/removal during
    suspend/resume"
  * Revert "[ARM] implement arch_randomize_brk()"
  * Revert "ARM: stack protector: change the canary value per task"
  * Revert "ARM: initial stack protector (-fstack-protector) support"
  * Revert "ALSA: hda - Handle pin NID 0x1a on ALC259/269"
  * Revert "ALSA: hda - Handle missing NID 0x1b on ALC259 codec"
  * Revert "perf probe: Add kernel source path option"
  * hid: ntrig: Support single-touch devices
  * hid: ntrig: Mask pen switch events
  * net: rtnetlink.h -- only include linux/netdevice.h when used by the
    kernel
    - LP: #673073
  * Fix userspace build of linux/fs.h
 -- Andy Whitcroft <email address hidden> Mon, 15 Nov 2010 19:31:44 +0000

Changed in linux (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.