Contents

Build strongSwan on macOS

Contents
Warning
Though I succeeded to build strongSwan on macOS, establishing VPN was tough and I aborted. I guess strongSwans is not well tested on recent macOS and establishing VPN might be even impossible on recent macOS without hacking the source.
Info
For those who reached here via google: configure YACC='/usr/local/Cellar/bison/3.4.2/bin/bison -y' --disable-kernel-netlink may fix your problem.

As of 2019-11-27, the build of strongSwan on macOS is broken;

1
2
3
4
5
6
git clone https://git.strongswan.org/strongswan.git
cd strongswan/
mkdir build/
cd build/
../configure
make

make outputs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\
		sed \
		-e "s:\@PACKAGE_VERSION\@:5.8.2dr2:" \
		../Android.common.mk.in > Android.common.mk
(CDPATH="${ZSH_VERSION+.}:" && cd .. && /bin/sh /Users/wsh/qc/strongswan/missing autoheader)
rm -f stamp-h1
touch ../config.h.in
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
Making all in src
Making all in .
make[3]: Nothing to be done for `all-am'.
Making all in include
make[3]: Nothing to be done for `all'.
Making all in libstrongswan
\
		(cd ../../../src/libstrongswan/asn1/ && /usr/local/bin/perl oid.pl)
\
		sed \
		-e "s:\@GPERF_LEN_TYPE\@:unsigned:" \
		../../../src/libstrongswan/crypto/proposal/proposal_keywords_static.h.in > ../../../src/libstrongswan/crypto/proposal/proposal_keywords_static.h
\
		/usr/bin/gperf -N proposal_get_token_static -m 10 -C -G -c -t -D \
			--output-file=../../../src/libstrongswan/crypto/proposal/proposal_keywords_static.c ../../../src/libstrongswan/crypto/proposal/proposal_keywords_static.txt
/bin/sh ../../../ylwrap ../../../src/libstrongswan/settings/settings_parser.y y.tab.c settings/settings_parser.c y.tab.h `echo settings/settings_parser.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output settings/settings_parser.output -- bison -y -v -d
/Users/wsh/qc/strongswan/build/src/libstrongswan/../../../src/libstrongswan/settings/settings_parser.y:69.9-16: syntax error, unexpected identifier, expecting string
make[3]: *** [settings/settings_parser.c] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

The version of macOS’s built-in /usr/bin/bison is too old (2.3) for settings_parser.y. Using bison from Homebrew (currently version 3.4.2) resolves this:

1
2
3
4
5
6
7
8
brew install bison
# check path to bison executable
# here, say, /usr/local/Cellar/bison/3.4.2/bin/bison
brew list bison

# try building strongSwan again
../configure YACC='/usr/local/Cellar/bison/3.4.2/bin/bison -y'
make

-y flag is necessary; without this, another error raises:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/bin/sh ../../../ylwrap ../../../src/libstrongswan/settings/settings_parser.y y.tab.c settings/settings_parser.c y.tab.h `echo settings/settings_parser.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output settings/settings_parser.output -- /usr/local/Cellar/bison/3.4.2/bin/bison -v -d
/Users/wsh/qc/strongswan/build/src/libstrongswan/../../../src/libstrongswan/settings/settings_parser.y:67.1-14: warning: deprecated directive, use ‘%define parse.error verbose’ [-Wdeprecated]
   67 | %error-verbose
      | ^~~~~~~~~~~~~~
/Users/wsh/qc/strongswan/build/src/libstrongswan/../../../src/libstrongswan/settings/settings_parser.y:71.1-31: warning: deprecated directive, use ‘%define api.prefix {settings_parser_}[-Wdeprecated]
   71 | %name-prefix "settings_parser_"
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/wsh/qc/strongswan/build/src/libstrongswan/../../../src/libstrongswan/settings/settings_parser.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]
settings_parser.output is unchanged
settings_parser.tab.c is unchanged
settings_parser.tab.h is unchanged
depbase=`echo settings/settings_parser.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
	/bin/sh ../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../src/libstrongswan -I../..  -I../../../src/libstrongswan -DIPSEC_DIR=\"/Users/wsh/usr/opt/strongswan/libexec/ipsec\" -DIPSEC_LIB_DIR=\"/Users/wsh/usr/opt/strongswan/lib/ipsec\" -DPLUGINDIR=\"/Users/wsh/usr/opt/strongswan/lib/ipsec/plugins\" -DSTRONGSWAN_CONF=\"/Users/wsh/usr/opt/strongswan/etc/strongswan.conf\"        -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT settings/settings_parser.lo -MD -MP -MF $depbase.Tpo -c -o settings/settings_parser.lo settings/settings_parser.c &&\
	mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../../src/libstrongswan -I../.. -I../../../src/libstrongswan -DIPSEC_DIR=\"/Users/wsh/usr/opt/strongswan/libexec/ipsec\" -DIPSEC_LIB_DIR=\"/Users/wsh/usr/opt/strongswan/lib/ipsec\" -DPLUGINDIR=\"/Users/wsh/usr/opt/strongswan/lib/ipsec/plugins\" -DSTRONGSWAN_CONF=\"/Users/wsh/usr/opt/strongswan/etc/strongswan.conf\" -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT settings/settings_parser.lo -MD -MP -MF settings/.deps/settings_parser.Tpo -c settings/settings_parser.c  -fno-common -DPIC -o settings/.libs/settings_parser.o
clang: error: no such file or directory: 'settings/settings_parser.c'
clang: error: no input files
make[5]: *** [settings/settings_parser.lo] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Build expects that build/src/libstrongswan/settings_parser.c is generated by yacc (bison -y), but bison creates build/src/libstrongswan/settings_parser.tab.c.

Having YACC='/usr/.../bison -y', we’ll still encounter another error:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Making all in plugins/kernel_netlink
depbase=`echo kernel_netlink_plugin.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
	/bin/sh ../../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../../../src/libcharon/plugins/kernel_netlink -I../../../..  -I../../../../../src/include -I../../../../../src/libstrongswan -I../../../../../src/libcharon -DROUTING_TABLE=220 -DROUTING_TABLE_PRIO=220   -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT kernel_netlink_plugin.lo -MD -MP -MF $depbase.Tpo -c -o kernel_netlink_plugin.lo ../../../../../src/libcharon/plugins/kernel_netlink/kernel_netlink_plugin.c &&\
	mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../../../../src/libcharon/plugins/kernel_netlink -I../../../.. -I../../../../../src/include -I../../../../../src/libstrongswan -I../../../../../src/libcharon -DROUTING_TABLE=220 -DROUTING_TABLE_PRIO=220 -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT kernel_netlink_plugin.lo -MD -MP -MF .deps/kernel_netlink_plugin.Tpo -c ../../../../../src/libcharon/plugins/kernel_netlink/kernel_netlink_plugin.c  -fno-common -DPIC -o .libs/kernel_netlink_plugin.o
depbase=`echo kernel_netlink_ipsec.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
	/bin/sh ../../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../../../src/libcharon/plugins/kernel_netlink -I../../../..  -I../../../../../src/include -I../../../../../src/libstrongswan -I../../../../../src/libcharon -DROUTING_TABLE=220 -DROUTING_TABLE_PRIO=220   -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT kernel_netlink_ipsec.lo -MD -MP -MF $depbase.Tpo -c -o kernel_netlink_ipsec.lo ../../../../../src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c &&\
	mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../../../../src/libcharon/plugins/kernel_netlink -I../../../.. -I../../../../../src/include -I../../../../../src/libstrongswan -I../../../../../src/libcharon -DROUTING_TABLE=220 -DROUTING_TABLE_PRIO=220 -O0 -ggdb3 -include /Users/wsh/qc/strongswan/build/config.h -MT kernel_netlink_ipsec.lo -MD -MP -MF .deps/kernel_netlink_ipsec.Tpo -c ../../../../../src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c  -fno-common -DPIC -o .libs/kernel_netlink_ipsec.o
In file included from ../../../../../src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c:47:
In file included from ../../../../../src/include/linux/ipsec.h:6:
../../../../../src/include/linux/pfkeyv2.h:9:10: fatal error: 'linux/types.h' file not found
#include <linux/types.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[5]: *** [kernel_netlink_ipsec.lo] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

which can be fixed with --disable-kernel-netlink.

Summary

Build with:

1
2
3
brew install bison
./configure YACC='/usr/local/Cellar/bison/3.4.2/bin/bison -y' --disable-kernel-netlink
make