Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build fails on AIX 7.3: system headers fail to include properly #1216

Open
infrastation opened this issue Aug 23, 2023 · 6 comments
Open

build fails on AIX 7.3: system headers fail to include properly #1216

infrastation opened this issue Aug 23, 2023 · 6 comments

Comments

@infrastation
Copy link
Member

It looks like some constants need to be either #ifdef-wrapped properly or made mandatory in Autoconf/CMake. AFAIR, on AIX 7.1 at least 4 build matrix setups managed to pass, on AIX 7.2 the source compiled, but failed to link. On AIX 7.3 it fails to compile (as can be reproduced on CFarm host gcc119):


bash-5.1$ PATH="/opt/freeware/bin:$PATH" MAKEFLAGS='-j4' MATRIX_CC='gcc' MATRIX_REMOTE=no TEST_RELEASETAR=no ./build_matrix.sh
[...]

./pcap-bpf.c: In function 'bpf_bind':
./pcap-bpf.c:756:21: error: 'BIOCSETIF' undeclared (first use in this function); did you mean 'TIOCSETC'?
  756 |  status = ioctl(fd, BIOCSETIF, (caddr_t)&ifr);
      |                     ^~~~~~~~~
      |                     TIOCSETC
./pcap-bpf.c:756:21: note: each undeclared identifier is reported only once for each function it appears in
./pcap-bpf.c: In function 'pcap_stats_bpf':
./pcap-bpf.c:1146:18: error: storage size of 's' isn't known
 1146 |  struct bpf_stat s;
      |                  ^
./pcap-bpf.c:1161:19: error: 'BIOCGSTATS' undeclared (first use in this function)
 1161 |  if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) {
      |                   ^~~~~~~~~~
./pcap-bpf.c:1146:18: error: unused variable 's' [-Werror=unused-variable]
 1146 |  struct bpf_stat s;
      |                  ^
./pcap-bpf.c: In function 'pcap_read_bpf':
./pcap-bpf.c:1354:15: error: invalid use of undefined type 'struct bpf_hdr'
 1354 |   caplen = bhp->bh_caplen;
      |               ^~
./pcap-bpf.c:1355:15: error: invalid use of undefined type 'struct bpf_hdr'
 1355 |   hdrlen = bhp->bh_hdrlen;
      |               ^~
./pcap-bpf.c:1371:48: error: invalid use of undefined type 'struct bpf_hdr'
 1371 |       pcap_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
      |                                                ^~
./pcap-bpf.c:1392:26: error: invalid use of undefined type 'struct bpf_hdr'
 1392 |    pkthdr.ts.tv_sec = bhp->bh_tstamp.tv_sec;
      |                          ^~
./pcap-bpf.c:1398:27: error: invalid use of undefined type 'struct bpf_hdr'
 1398 |    pkthdr.ts.tv_usec = bhp->bh_tstamp.tv_usec/1000;
      |                           ^~
./pcap-bpf.c:1415:20: error: invalid use of undefined type 'struct bpf_hdr'
 1415 |    pkthdr.len = bhp->bh_datalen;
      |                    ^~
./pcap-bpf.c: In function 'bpf_load':
./pcap-bpf.c:1555:20: error: storage size of 'cfg_bpf' isn't known
 1555 |  struct bpf_config cfg_bpf;
      |                    ^~~~~~~
./pcap-bpf.c:1555:20: error: unused variable 'cfg_bpf' [-Werror=unused-variable]
./pcap-bpf.c: In function 'pcap_activate_bpf':
./pcap-bpf.c:1880:21: error: storage size of 'bv' isn't known
 1880 |  struct bpf_version bv;
      |                     ^~
./pcap-bpf.c:1913:16: error: 'BIOCVERSION' undeclared (first use in this function)
 1913 |  if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) {
      |                ^~~~~~~~~~~
./pcap-bpf.c:1919:21: error: 'BPF_MAJOR_VERSION' undeclared (first use in this function)
 1919 |  if (bv.bv_major != BPF_MAJOR_VERSION ||
      |                     ^~~~~~~~~~~~~~~~~
./pcap-bpf.c:1920:20: error: 'BPF_MINOR_VERSION' undeclared (first use in this function)
 1920 |      bv.bv_minor < BPF_MINOR_VERSION) {
      |                    ^~~~~~~~~~~~~~~~~
./pcap-bpf.c:2206:18: error: 'BIOCSBLEN' undeclared (first use in this function)
 2206 |    if (ioctl(fd, BIOCSBLEN,
      |                  ^~~~~~~~~
./pcap-bpf.c:2247:19: error: 'BIOCGBLEN' undeclared (first use in this function)
 2247 |    if ((ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) ||
      |                   ^~~~~~~~~
./pcap-bpf.c:2293:16: error: 'BIOCGDLT' undeclared (first use in this function)
 2293 |  if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) {
      |                ^~~~~~~~
./pcap-bpf.c:2591:21: error: 'BIOCSRTIMEOUT' undeclared (first use in this function)
 2591 |    if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) {
      |                     ^~~~~~~~~~~~~
./pcap-bpf.c:2648:20: error: 'BIOCPROMISC' undeclared (first use in this function)
 2648 |   if (ioctl(p->fd, BIOCPROMISC, NULL) < 0) {
      |                    ^~~~~~~~~~~
./pcap-bpf.c:2707:19: error: 'BIOCSETF' undeclared (first use in this function); did you mean 'TIOCSETC'?
 2707 |  if (ioctl(p->fd, BIOCSETF, (caddr_t)&total_prog) < 0) {
      |                   ^~~~~~~~
      |                   TIOCSETC
./pcap-bpf.c:1880:21: error: unused variable 'bv' [-Werror=unused-variable]
 1880 |  struct bpf_version bv;
      |                     ^~
./pcap-bpf.c: In function 'pcap_setfilter_bpf':
./pcap-bpf.c:3441:19: error: 'BIOCSETF' undeclared (first use in this function); did you mean 'TIOCSETC'?
 3441 |  if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) == 0) {
      |                   ^~~~~~~~
      |                   TIOCSETC
cc1: all warnings being treated as errors
make: *** [Makefile:86: pcap-bpf.o] Error 1

bash-5.1$ gcc --version
gcc (GCC) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

bash-5.1$ uname -a
AIX gcc119 3 7 00F9C1964C00 powerpc AIX
@guyharris
Copy link
Member

No, those should all be defined by some header on AIX, given that they still support BPF and the key BPF ioctls, but it'll take some poking around to see what headers they are.

@guyharris
Copy link
Member

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARGH.

Older versions of AIX "helpfully" defined their own values for DLT_ entries, using RFC 1573 ifType values from SNMP rather than the "they started out as ARP hardware values, and then we moved on" values used in LBL's BPF. (They even more "helpfully" used them when writing to pcap files, in addition to writing packets with nanosecond-precision time stamps, without bothering to use a new magic value. They used a version number of 2.2; Wireshark has some hackery to detect that, and it doesn't involve looking at packet records, as some other hackery in there does, so maybe I could add it to libpcap.)

With our libpcap, the intent is to behave the same on AIX as on other platforms, so most of libpcap uses the DLT_ values from libpcap's header files, not the system header files, so it doesn't use the weird AIX values. However, pcap-bpf.c needs some stuff from the system net/bpf.h, so it includes it, but undefines _AIX before doing so and redefines it after including it. It also maps IFT_ values, which are what BIOCGDLT returns on those versions of AIX, to DLT_ values.

The libpcap that comes with newer versions of AIX, however, appears to have decided to behave like regular libpcap.

However, the net/bpf.h in AIX 7.3, at least, *doesn't define the BIOC ioctls unless _AIX is defined, so the workaround for the old AIX problem results in a problem on newer AIXes.

The configure script/CMake files could, on AIX, test whether DLT_NULL is defined as 0 or not and, if not, treat the platform as "old AIX" and do all the workaround stuff, otherwise don't use it.

Or, if IBM fixed it long enough ago, we could just drop support for AIX versions where BPF returns ifType values.

I'd prefer the latter, at this point; getting rid of support for older systems could get rid of some cruft.

(Too bad somebody complained abou problems with recent libpcap on Mac OS X 10.4(!), showing that there's apparently at least some demand for that. Maybe we can drop that in 1.11.)

@mcr
Copy link
Member

mcr commented Nov 15, 2023 via email

@guyharris
Copy link
Member

Or, if IBM fixed it long enough ago, we could just drop support for AIX versions where BPF returns ifType values.

I hope that, in the newer versions of AIX, BPF returns normal DLT_ values, rather than ifType values, rather than BPF continuing to return ifType values and AIX's libpcap mapping those to DLT_ values.

Unfortunately, opening BPF devices requires root access, and I don't have root access on any AIX machines, so I can't test whether AIX 7.x, for example, has a BPF that returns DLT_ values. So my inclination is to 1) drop support for older AIXes, as you suggest and 2) put in a sanity check to, on AIX, make sure that devices don't return the device's ifType value for BIOCGDLT and, if they do, map them to the appropriate DLT_ value.

@infrastation
Copy link
Member Author

In case this is useful, the pcap_datalink man page in AIX 7.3 gives an example of IFT_ETHER as a return value, not a DLT_.

@infrastation
Copy link
Member Author

If the solution requires version-specific means to include AIX headers, would this be sufficient?

AIX 7.1

_AIX71 is defined
_AIX is defined

AIX 7.3

_AIX71 is defined
_AIX72 is defined
_AIX73 is defined
_AIX is defined

@infrastation infrastation changed the title build fails on AIX 7.3 build fails on AIX 7.3: system headers fail to include properly Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants