sipp icon indicating copy to clipboard operation
sipp copied to clipboard

[FreeBSD] make fails if -DUSE_PCAP was set on cmake

Open kadabusha opened this issue 3 years ago • 11 comments

Case on cmake parameter -DUSE_PCAP=1 was set, make fails on 40th. Same behavior is observed on 11.4-RELEASE-p9 and 11.3-RELEASE-p12 - if DUSE_PCAP is not specified, make finishes at no issues. Checked on Debian10 - make finishes at no issues in same scenario.

[1@freebsd ~/sipp]$ pkg info|grep 'libpcap\|libnet\|curses\|cmake'
cmake-3.20.4                   Cross-platform Makefile generator
libnet-1.1.6_5,1               C library for creating IP packets
libpcap-1.10.0                 Ubiquitous network traffic capture library
ncurses-6.2.20210626           Library for terminal-independent, full-screen output
[1@freebsd ~/sipp]$ uname -r
11.4-RELEASE-p9
[1@freebsd ~]$ git clone https://github.com/SIPp/sipp.git
Cloning into 'sipp'...
remote: Enumerating objects: 7268, done.
remote: Counting objects: 100% (434/434), done.
remote: Compressing objects: 100% (270/270), done.
remote: Total 7268 (delta 283), reused 269 (delta 163), pack-reused 6834
Receiving objects: 100% (7268/7268), 5.71 MiB | 13.26 MiB/s, done.
Resolving deltas: 100% (5190/5190), done.
[1@freebsd ~]$ cd sipp
[1@freebsd ~/sipp]$ cmake . -DUSE_PCAP=1
-- The C compiler identification is Clang 10.0.0
-- The CXX compiler identification is Clang 10.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for endian.h
-- Looking for endian.h - not found
-- Looking for sys/endian.h
-- Looking for sys/endian.h - not found
-- Looking for sys/epoll.h
-- Looking for sys/epoll.h - not found
-- Performing Test HAVE_UDP_UH_PREFIX
-- Performing Test HAVE_UDP_UH_PREFIX - Failed
-- Looking for le16toh
-- Looking for le16toh - not found
-- Looking for le16toh
-- Looking for le16toh - not found
-- Found Git: /usr/local/bin/git (found version "2.32.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/1/sipp
[1@freebsd ~/sipp]$ make
[  0%] Built target version
[  2%] Building CXX object CMakeFiles/sipp.dir/src/actions.cpp.o
[  5%] Building CXX object CMakeFiles/sipp.dir/src/auth.cpp.o
[  8%] Building CXX object CMakeFiles/sipp.dir/src/call.cpp.o
[ 11%] Building CXX object CMakeFiles/sipp.dir/src/call_generation_task.cpp.o
[ 14%] Building C object CMakeFiles/sipp.dir/src/comp.c.o
[ 17%] Building CXX object CMakeFiles/sipp.dir/src/deadcall.cpp.o
[ 20%] Building CXX object CMakeFiles/sipp.dir/src/infile.cpp.o
[ 22%] Building CXX object CMakeFiles/sipp.dir/src/jlsrtp.cpp.o
[ 25%] Building CXX object CMakeFiles/sipp.dir/src/listener.cpp.o
[ 28%] Building CXX object CMakeFiles/sipp.dir/src/logger.cpp.o
[ 31%] Building C object CMakeFiles/sipp.dir/src/md5.c.o
[ 34%] Building CXX object CMakeFiles/sipp.dir/src/message.cpp.o
[ 37%] Building C object CMakeFiles/sipp.dir/src/milenage.c.o
[ 40%] Building C object CMakeFiles/sipp.dir/src/prepare_pcap.c.o
/home/1/sipp/src/prepare_pcap.c:251:32: error: no member named 'len' in 'struct udphdr'
        pktlen = ntohs(udphdr->uh_ulen);
                       ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:74:37: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                           ^
/home/1/sipp/src/prepare_pcap.c:251:32: error: no member named 'len' in 'struct udphdr'
        pktlen = ntohs(udphdr->uh_ulen);
                       ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:40: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                              ^
/home/1/sipp/src/prepare_pcap.c:251:32: error: no member named 'len' in 'struct udphdr'
        pktlen = ntohs(udphdr->uh_ulen);
                       ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:51: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                                         ^
/home/1/sipp/src/prepare_pcap.c:251:32: error: no member named 'len' in 'struct udphdr'
        pktlen = ntohs(udphdr->uh_ulen);
                       ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:53: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                                           ^
/home/1/sipp/src/prepare_pcap.c:270:17: error: no member named 'check' in 'struct udphdr'
        udphdr->uh_sum = 0;
        ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:34:16: note: expanded from macro 'uh_sum'
#define uh_sum check
               ^
/home/1/sipp/src/prepare_pcap.c:275:62: error: no member named 'len' in 'struct udphdr'
        pkt_index->partial_check = check((uint16_t*)&udphdr->uh_ulen, pktlen - 4) + ntohs(IPPROTO_UDP + pktlen);
                                                     ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/home/1/sipp/src/prepare_pcap.c:278:34: error: no member named 'dest' in 'struct udphdr'
        if (base > ntohs(udphdr->uh_dport))
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:74:37: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                           ^
/home/1/sipp/src/prepare_pcap.c:278:34: error: no member named 'dest' in 'struct udphdr'
        if (base > ntohs(udphdr->uh_dport))
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:40: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                              ^
/home/1/sipp/src/prepare_pcap.c:278:34: error: no member named 'dest' in 'struct udphdr'
        if (base > ntohs(udphdr->uh_dport))
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:51: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                                         ^
/home/1/sipp/src/prepare_pcap.c:278:34: error: no member named 'dest' in 'struct udphdr'
        if (base > ntohs(udphdr->uh_dport))
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:53: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                                           ^
/home/1/sipp/src/prepare_pcap.c:279:34: error: no member named 'dest' in 'struct udphdr'
            base = ntohs(udphdr->uh_dport);
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:74:37: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                           ^
/home/1/sipp/src/prepare_pcap.c:279:34: error: no member named 'dest' in 'struct udphdr'
            base = ntohs(udphdr->uh_dport);
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:40: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                              ^
/home/1/sipp/src/prepare_pcap.c:279:34: error: no member named 'dest' in 'struct udphdr'
            base = ntohs(udphdr->uh_dport);
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:51: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                                         ^
/home/1/sipp/src/prepare_pcap.c:279:34: error: no member named 'dest' in 'struct udphdr'
            base = ntohs(udphdr->uh_dport);
                         ~~~~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/usr/include/netinet/in.h:120:26: note: expanded from macro 'ntohs'
#define ntohs(x)        __ntohs(x)
                                ^
/usr/include/x86/endian.h:129:30: note: expanded from macro '__ntohs'
#define __ntohs(x)      __bswap16(x)
                                  ^
/usr/include/x86/endian.h:75:53: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                                           ^
/home/1/sipp/src/prepare_pcap.c:368:10: error: no member named 'len' in 'struct udphdr'
    udp->uh_ulen = htons(pktlen);
    ~~~  ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
/home/1/sipp/src/prepare_pcap.c:369:10: error: no member named 'check' in 'struct udphdr'
    udp->uh_sum = 0;
    ~~~  ^
/home/1/sipp/src/prepare_pcap.c:34:16: note: expanded from macro 'uh_sum'
#define uh_sum check
               ^
/home/1/sipp/src/prepare_pcap.c:370:10: error: no member named 'source' in 'struct udphdr'
    udp->uh_sport = 0;
    ~~~  ^
/home/1/sipp/src/prepare_pcap.c:35:18: note: expanded from macro 'uh_sport'
#define uh_sport source
                 ^
/home/1/sipp/src/prepare_pcap.c:371:10: error: no member named 'dest' in 'struct udphdr'
    udp->uh_dport = 0;
    ~~~  ^
/home/1/sipp/src/prepare_pcap.c:36:18: note: expanded from macro 'uh_dport'
#define uh_dport dest
                 ^
/home/1/sipp/src/prepare_pcap.c:448:59: error: no member named 'len' in 'struct udphdr'
        pkt_index->partial_check = check(&dtmfpacket->udp.uh_ulen, pktlen - 4) + ntohs(IPPROTO_UDP + pktlen);
                                          ~~~~~~~~~~~~~~~ ^
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
*** Error code 1

Stop.
make[2]: stopped in /usr/home/1/sipp
*** Error code 1

Stop.
make[1]: stopped in /usr/home/1/sipp
*** Error code 1

Stop.
make: stopped in /usr/home/1/sipp

kadabusha avatar Nov 15 '21 13:11 kadabusha

Looks like SIPp wrongly thinks the members should be changed:

/home/1/sipp/src/prepare_pcap.c:448:59: error: no member named 'len' in 'struct udphdr'
...
/home/1/sipp/src/prepare_pcap.c:33:17: note: expanded from macro 'uh_ulen'
#define uh_ulen len

That should probably be fixed with a cmake check to find out what the structure of the udphdr is:

$ wgrep . HAVE_UDP_UH_PREFIX
./CMakeCache.txt://Test HAVE_UDP_UH_PREFIX
./CMakeCache.txt:HAVE_UDP_UH_PREFIX:INTERNAL=1
./src/prepare_pcap.c:#ifndef HAVE_UDP_UH_PREFIX
./src/send_packets.c:#ifndef HAVE_UDP_UH_PREFIX
./CMakeLists.txt:CHECK_STRUCT_HAS_MEMBER("struct udphdr" uh_sport "sys/types.h;netinet/udp.h"  HAVE_UDP_UH_PREFIX)
./config.h:#define HAVE_UDP_UH_PREFIX 1

Apparently that exists. But the check does not work for you on your FreeBSD...

Maybe you can figure out why?

-- Performing Test HAVE_UDP_UH_PREFIX
-- Performing Test HAVE_UDP_UH_PREFIX - Failed

Until this says Success, while your struct udphdr does have these prefixes, you'll keep getting compile errors.

On Ubuntu/Focal, this looks like:

/* UDP header as specified by RFC 768, August 1980. */

struct udphdr
{
  __extension__ union
  {
    struct
    {
      uint16_t uh_sport;        /* source port */
      uint16_t uh_dport;        /* destination port */
      uint16_t uh_ulen;         /* udp length */
      uint16_t uh_sum;          /* udp checksum */
    };
    struct
    {
      uint16_t source;
      uint16_t dest;
      uint16_t len;
      uint16_t check;
    };
  };
};

in /usr/include/netinet/udp.h.

wdoekes avatar Nov 16 '21 11:11 wdoekes

Hi, @wdoekes Thanks for prompt reply here. In udp.h on both systems that struct is same, I also checked a few systems on FreeBSD 11.2, 11.1 and 10.3 - same there too. On Debian box mentioned above the struct looks the same as in your message.

/*
 * UDP protocol header.
 * Per RFC 768, September, 1981.
 */
struct udphdr {
        u_short uh_sport;               /* source port */
        u_short uh_dport;               /* destination port */
        u_short uh_ulen;                /* udp length */
        u_short uh_sum;                 /* udp checksum */
};

kadabusha avatar Nov 16 '21 12:11 kadabusha

Maybe cmake fails to compile the test program then. Perhaps because of missing headers that define u_short :shrug:

#include <netinet/udp.h>

int main() {
    struct udphdr u;
    u.uh_sport = 1;
    return 0;
}

Does that compile? What do you need to make that compile?

wdoekes avatar Nov 16 '21 12:11 wdoekes

Not sure I got it right - where shall I put that code? config.h does not work for me, as well as /usr/include/netinet/udp.h (obviously). Do I need to apply the patch by running cmake with some flag or so (e.g. cmake patch etc)?

kadabusha avatar Nov 16 '21 13:11 kadabusha

$ cat > whatever.c << EOF
#include <netinet/udp.h>

int main() {
    struct udphdr u;
    u.uh_sport = 1;
    return 0;
}
EOF

$ gcc -Wall whatever.c -o whatever
(check output, and see whether it complains)

wdoekes avatar Nov 16 '21 15:11 wdoekes

[1@freebsd ~/sipp]$ gcc -Wall whatever.c -o whatever
In file included from whatever.c:1:
/usr/include/netinet/udp.h:42:2: error: unknown type name 'u_short'
   42 |  u_short uh_sport;  /* source port */
      |  ^~~~~~~
/usr/include/netinet/udp.h:43:2: error: unknown type name 'u_short'
   43 |  u_short uh_dport;  /* destination port */
      |  ^~~~~~~
/usr/include/netinet/udp.h:44:2: error: unknown type name 'u_short'
   44 |  u_short uh_ulen;  /* udp length */
      |  ^~~~~~~
/usr/include/netinet/udp.h:45:2: error: unknown type name 'u_short'
   45 |  u_short uh_sum;   /* udp checksum */
      |  ^~~~~~~
whatever.c: In function 'main':
whatever.c:4:19: warning: variable 'u' set but not used [-Wunused-but-set-variable]
    4 |     struct udphdr u;
      |                   ^

kadabusha avatar Nov 16 '21 15:11 kadabusha

Perhaps because of missing headers that define u_short

So yeah.

And inserting this before line 1 does not help?

#include <sys/types.h>

Again. This is something you need to figure out. My google-fu for (free)bsd systems is not real good.

wdoekes avatar Nov 16 '21 15:11 wdoekes

Likely something related to this though: https://lists.freebsd.org/pipermail/freebsd-standards/2016-January/003133.html

wdoekes avatar Nov 16 '21 15:11 wdoekes

Add sys/types.h has removed all errors but "not used" one:

$ gcc -Wall whatever.c -o whatever
whatever.c: In function 'main':
whatever.c:5:19: warning: variable 'u' set but not used [-Wunused-but-set-variable]
    5 |     struct udphdr u;
      |                   ^

Ok, thanks for your efforts - I'll try to get some help from FreeBSD people then.

kadabusha avatar Nov 16 '21 15:11 kadabusha

all errors but "not used" one

Yes. Ignore the warnings. Only the errors were relevant here.

Ok, thanks for your efforts - I'll try to get some help from FreeBSD people then.

:+1:

wdoekes avatar Nov 16 '21 15:11 wdoekes

Hi, @wdoekes Please see below the reply from FreeBSD guru, fix was checked on FreeBSD 11.3 and on Debian 10(buster) PR for the change: #562

the cmake . prints:

-- Performing Test HAVE_UDP_UH_PREFIX - Failed

because of this: CMakeFiles/CMakeError.log: Performing C SOURCE FILE Test HAVE_UDP_UH_PREFIX failed with the following output:

error: invalid argument '-std=c++11' not allowed with 'C'

which indicates an error in the CMakeLists.txt as it is configured to use C++ specific flag std=c++11 even with C compiler. And here is the culprit in the CMakeLists.txt:

set(CMAKE_REQUIRED_FLAGS "-std=c++11")

if it is replaced with the proper way to add that flag:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

then the sipp configures and builds with no problem

kadabusha avatar Nov 22 '21 07:11 kadabusha