From 852756f90222a8e0821f6e1994baa32eafbdc47c Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Mon, 8 Feb 2021 14:25:40 -0500 Subject: [PATCH] test: Porting FreeBSD --- docs/_docs/platform/04-freebsd.md | 131 ----------- .../_docs/platform/05-macosx-apple-silicon.md | 2 +- docs/_docs/platform/06-macosx-intel.md | 2 +- docs/_docs/platform/07-freebsd.md | 216 ++++++++++++++++++ docs/_pages/docs.md | 1 + lib/core/meson.build | 7 - lib/core/ogs-compat.h | 3 + lib/core/ogs-core.h | 1 - lib/core/ogs-macros.h | 9 +- lib/core/ogs-time.c | 5 - lib/diameter/common/ogs-diameter-common.h | 4 + lib/ipfw/glue.c | 20 +- lib/ipfw/meson.build | 2 + lib/ipfw/ogs-ipfw.c | 4 +- lib/meson.build | 1 + lib/pfcp/meson.build | 4 +- lib/sbi/conv.c | 28 ++- lib/sctp/meson.build | 8 +- lib/{core/ogs-tun.c => tun/linux-setup.c} | 46 ---- lib/{core/ogs-utun.c => tun/mac-setup.c} | 105 ++------- lib/tun/meson.build | 45 ++++ lib/{core => tun}/ogs-tun.h | 2 +- lib/tun/tunio.c | 89 ++++++++ lib/tun/windows-setup.c | 37 +++ meson.build | 2 +- src/amf/meson.build | 1 - src/ausf/meson.build | 1 - src/nrf/meson.build | 1 - src/pcf/meson.build | 1 - src/smf/gtp-path.h | 1 - src/smf/meson.build | 7 +- src/udm/meson.build | 1 - src/udr/meson.build | 1 - src/upf/meson.build | 5 +- src/upf/rule-match.c | 4 +- tests/attach/guti-test.c | 2 + tests/meson.build | 2 +- tests/registration/guti-test.c | 4 + tests/registration/paging-test.c | 3 + tests/unit/abts-main.c | 10 +- tests/unit/crash-test.c | 4 +- tests/unit/gtp-message-test.c | 3 +- tests/unit/meson.build | 6 +- tests/unit/nas-message-test.c | 8 +- tests/unit/ngap-message-test.c | 23 +- tests/unit/s1ap-message-test.c | 30 ++- tests/unit/sbi-message-test.c | 3 +- tests/unit/security-test.c | 5 +- vagrant/freebsd/Vagrantfile | 75 ++++++ 49 files changed, 629 insertions(+), 346 deletions(-) delete mode 100644 docs/_docs/platform/04-freebsd.md create mode 100644 docs/_docs/platform/07-freebsd.md rename lib/{core/ogs-tun.c => tun/linux-setup.c} (64%) rename lib/{core/ogs-utun.c => tun/mac-setup.c} (83%) create mode 100644 lib/tun/meson.build rename lib/{core => tun}/ogs-tun.h (95%) create mode 100644 lib/tun/tunio.c create mode 100644 lib/tun/windows-setup.c create mode 100644 vagrant/freebsd/Vagrantfile diff --git a/docs/_docs/platform/04-freebsd.md b/docs/_docs/platform/04-freebsd.md deleted file mode 100644 index e18e58c08..000000000 --- a/docs/_docs/platform/04-freebsd.md +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: FreeBSD -head_inline: "" ---- - -This guide is based on **FreeBSD Relase 11.1**. -{: .blue} - -### Getting MongoDB ---- - -Install MongoDB with package manager. -```bash -$ sudo pkg install mongodb -``` - -Run MongoDB server. -```bash -$ mkdir -p ./data/db -$ mongod --dbpath ./data/db -``` - -### Setting up TUN device (No persistent after rebooting) ---- - -Configure the TUN device. -```bash -$ sudo ifconfig lo0 alias 127.0.0.2 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.3 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.4 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.6 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.7 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.8 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.9 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.10 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.11 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.12 netmask 255.255.255.255 -$ sudo ifconfig lo0 alias 127.0.0.13 netmask 255.255.255.255 -``` - -Enable IP forwarding -```bash -$ sudo sysctl -w net.inet.ip.forwarding=1 -``` - -**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./support/network/restart.sh` -{: .notice--info} - -### Building Open5GS ---- - -Install the depedencies for building the source code. -```bash -$ sudo pkg install py36-pip ninja gcc bison gsed pkgconf git mongo-c-driver gnutls libgcrypt libidn libyaml libmicrohttpd curl -``` - -Install Meson using Python. -```bash -$ sudo pip install --upgrade pip -$ sudo pip install meson -``` - -Git clone. - -```bash -$ git clone https://github.com/{{ site.github_username }}/open5gs -``` - -To compile with meson: - -```bash -$ cd open5gs -$ meson build --prefix=`pwd`/install -$ ninja -C build -``` - -Check whether the compilation is correct. - -**Note:** This should require *sudo* due to access `/dev/tun0`. -{: .notice--danger} - -```bash -$ sudo ./build/tests/attach/attach ## EPC Only -$ sudo ./build/tests/registration/registration ## 5G Core Only -``` - -Run all test programs as below. - -**Note:** This should require *sudo* due to access `/dev/tun0`. -{: .notice--danger} - -```bash -$ cd build -$ sudo meson test -v -``` - -**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) -{: .notice--info} - -You need to perform the **installation process**. -```bash -$ cd build -$ ninja install -$ cd ../ -``` - -### Building WebUI of Open5GS ---- - -[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS - -```bash -$ sudo pkg install node -``` - -Install the dependencies to run WebUI - -```bash -$ cd webui -$ npm install -``` - -The WebUI runs as an [npm](https://www.npmjs.com/) script. - -```bash -$ npm run dev -``` - diff --git a/docs/_docs/platform/05-macosx-apple-silicon.md b/docs/_docs/platform/05-macosx-apple-silicon.md index 38aea6622..054e47a7d 100644 --- a/docs/_docs/platform/05-macosx-apple-silicon.md +++ b/docs/_docs/platform/05-macosx-apple-silicon.md @@ -80,7 +80,7 @@ $ sudo sh -c "echo 'nat on {en0} from cafe::1/64 to any -> {en0}' > /etc/pf.anch $ sudo pfctl -e -f /etc/pf.anchors/org.open5gs ``` -**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: `$ sudo ./misc/netconf.sh` {: .notice--info} diff --git a/docs/_docs/platform/06-macosx-intel.md b/docs/_docs/platform/06-macosx-intel.md index 6178217f0..6f4fdda34 100644 --- a/docs/_docs/platform/06-macosx-intel.md +++ b/docs/_docs/platform/06-macosx-intel.md @@ -80,7 +80,7 @@ $ sudo sh -c "echo 'nat on {en0} from cafe::1/64 to any -> {en0}' > /etc/pf.anch $ sudo pfctl -e -f /etc/pf.anchors/org.open5gs ``` -**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: `$ sudo ./misc/netconf.sh` {: .notice--info} diff --git a/docs/_docs/platform/07-freebsd.md b/docs/_docs/platform/07-freebsd.md new file mode 100644 index 000000000..74a571901 --- /dev/null +++ b/docs/_docs/platform/07-freebsd.md @@ -0,0 +1,216 @@ +--- +title: FreeBSD +head_inline: "" +--- + +This guide is based on **FreeBSD-11.4-STABLE**. +{: .blue} + +## Install **FreeBSD-11.4-STABLE** from Vagrant box (optional) +--- +Vagrant provides a simple way to create and deploy Virtual Machines from +pre-built images using VirtualBox, libvirt, or VMWare as a hypervisor engine. +This allows the user to quickly create a virtual machine without the hassle +of installing the operating system by hand. + +### Install Vagrant +--- + +The instructions to install Vagrant are provided at +[vagrantup.com](https://www.vagrantup.com/). + + +### Create a FreeBSD-11.4-STABLE Virtual Machine using Vagrant +--- + +Use the supplied `Vagrantfile` in the `vagrant` directory to create the +virtual machine. + +Note that this Vagrantfile is identical to the base FreeBSD 11 box, with +the exception that the amount of virtual memory has been increased to 1GB: + +```bash +cd vagrant/freebsd +vagrant up --provider virtualbox +``` + +### Log into the newly created FreeBSD VM +--- + +Use SSH to log into the FreeBSD 11 VM: + +```bash +vagrant ssh +``` + +Note that the Open5GS source is *not* copied into the VM. The instructions +below provide the step by step instructions for setting up Open5GS for +either a bare metal or virtual FreeBSD 11 system. + +The rest of the commands below are performed inside the FreeBSD VM as the +user 'vagrant', or on your bare metal FreeBSD 11 system as any normal user. + +### Getting MongoDB +--- + +Install MongoDB with package manager. +```bash +$ sudo pkg install mongodb44 +``` + +Run MongoDB server. +```bash +$ mkdir -p ./data/db +$ mongod --dbpath ./data/db +``` + +### Setting up network (No persistent after rebooting) +--- + +Configure the loopback interface. +```bash +$ sudo ifconfig lo0 alias 127.0.0.2 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.3 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.4 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.6 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.7 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.8 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.9 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.10 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.11 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.12 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.13 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.14 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.15 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.16 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.17 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.18 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.19 netmask 255.255.255.255 +$ sudo ifconfig lo0 alias 127.0.0.20 netmask 255.255.255.255 +``` + +Enable IP forwarding +```bash +$ sudo sysctl -w net.inet.ip.forwarding=1 +$ sudo sysctl -w net.inet6.ip6.forwarding=1 +``` + +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +`$ sudo ./misc/netconf.sh` +{: .notice--info} + +### Building Open5GS +--- + +Install the depedencies for building the source code. +```bash +$ sudo pkg install meson ninja gcc bison gsed pkgconf git mongo-c-driver gnutls libgcrypt libidn libyaml libmicrohttpd nghttp2 +``` + +Configure gcc PATH +```bash +$ setenv LIBRARY_PATH /usr/local/lib +$ setenv C_INCLUDE_PATH /usr/local/include +``` + +If you are using BASH instead of default CSH, +```bash +$ export LIBRARY_PATH=/usr/local/lib +$ export C_INCLUDE_PATH=/usr/local/include +``` + +Git clone. + +```bash +$ git clone https://github.com/{{ site.github_username }}/open5gs +``` + +To compile with meson: + +```bash +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build +``` + +**Note:** No source code changes are required for FreeBSD 11.x version. However, in FreeBSD 12.x version, we'll getting a crash with segmentation fault when calling basename(3). To avoid this, you need to change the freeDiameter source code as below. +{: .blue} + +```diff +$ cd open5gs/subprojects/freeDiameter + +$ diff --git a/include/freeDiameter/libfdproto.h b/include/freeDiameter/libfdproto.h +index 52c11ef..cd7f383 100644 +--- a/include/freeDiameter/libfdproto.h ++++ b/include/freeDiameter/libfdproto.h +@@ -293,7 +293,7 @@ extern int fd_g_debug_lvl; + + /* A version of __FILE__ without the full path. This is specific to each C file being compiled */ + static char * file_bname = NULL; +-static char * file_bname_init(char * full) { file_bname = basename(full); return file_bname; } ++static char * file_bname_init(char * full) { file_bname = __old_basename(full); return file_bname; } + #define __STRIPPED_FILE__ (file_bname ?: file_bname_init((char *)__FILE__)) + +``` + +Now, compile again: +{: .blue} + +```bash +$ cd open5gs +$ ninja -C build +``` + +Check whether the compilation is correct. + +**Note:** This should require *sudo* due to access `/dev/tun0`. +{: .notice--danger} + +```bash +$ sudo ./build/tests/attach/attach ## EPC Only +$ sudo ./build/tests/registration/registration ## 5G Core Only +``` + +Run all test programs as below. + +**Note:** This should require *sudo* due to access `/dev/tun0`. +{: .notice--danger} + +```bash +$ cd build +$ sudo meson test -v +``` + +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) +{: .notice--info} + +You need to perform the **installation process**. +```bash +$ cd build +$ ninja install +$ cd ../ +``` + +### Building WebUI of Open5GS +--- + +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS + +```bash +$ sudo pkg install node +``` + +Install the dependencies to run WebUI + +```bash +$ cd webui +$ npm install +``` + +The WebUI runs as an [npm](https://www.npmjs.com/) script. + +```bash +$ npm run dev +``` diff --git a/docs/_pages/docs.md b/docs/_pages/docs.md index 430eb6b96..889d9f698 100644 --- a/docs/_pages/docs.md +++ b/docs/_pages/docs.md @@ -32,6 +32,7 @@ head_inline: "" - [Fedora](platform/03-fedora) - [MacOSX(Apple Silicon)](platform/05-macosx-apple-silicon) - [MacOSX(Intel)](platform/06-macosx-intel) + - [FreeBSD](platform/07-freebsd) - Hardware Specific Notes - [Tested e/gNodeBs](hardware/01-genodebs) diff --git a/lib/core/meson.build b/lib/core/meson.build index 4b8ee465a..bb623c2d8 100644 --- a/lib/core/meson.build +++ b/lib/core/meson.build @@ -245,7 +245,6 @@ libcore_sources = files(''' ogs-socknode.h ogs-udp.h ogs-tcp.h - ogs-tun.h ogs-queue.h ogs-poll.h ogs-notify.h @@ -303,12 +302,6 @@ if have_func_kqueue libcore_sources += files('ogs-kqueue.c') endif -if host_system == 'darwin' - libcore_sources += files('ogs-utun.c') -else - libcore_sources += files('ogs-tun.c') -endif - libcore_inc = include_directories('.') libcore = library('ogscore', diff --git a/lib/core/ogs-compat.h b/lib/core/ogs-compat.h index aa0c816f4..0f6a5245a 100644 --- a/lib/core/ogs-compat.h +++ b/lib/core/ogs-compat.h @@ -57,6 +57,9 @@ #include #include #include +#include +#include +#include #endif diff --git a/lib/core/ogs-core.h b/lib/core/ogs-core.h index 77eba0944..b04c6cdfb 100644 --- a/lib/core/ogs-core.h +++ b/lib/core/ogs-core.h @@ -49,7 +49,6 @@ #include "core/ogs-socknode.h" #include "core/ogs-udp.h" #include "core/ogs-tcp.h" -#include "core/ogs-tun.h" #include "core/ogs-queue.h" #include "core/ogs-poll.h" #include "core/ogs-notify.h" diff --git a/lib/core/ogs-macros.h b/lib/core/ogs-macros.h index 769b5d646..734f3b9d8 100644 --- a/lib/core/ogs-macros.h +++ b/lib/core/ogs-macros.h @@ -108,14 +108,7 @@ extern "C" { #define be64toh(x) OSSwapBigToHostInt64((x)) #elif defined(__FreeBSD__) -#define le16toh(x) letoh16(x) -#define le32toh(x) letoh32(x) -#define le64toh(x) letoh64(x) - -#define be16toh(x) betoh16(x) -#define be32toh(x) betoh32(x) -#define be64toh(x) betoh64(x) - +#include #endif #ifndef WORDS_BIGENDIAN diff --git a/lib/core/ogs-time.c b/lib/core/ogs-time.c index 8eff57b22..d6e8b35e3 100644 --- a/lib/core/ogs-time.c +++ b/lib/core/ogs-time.c @@ -60,15 +60,10 @@ #include #include #include -#include #endif #include "core-config-private.h" -#if HAVE_SYS_TIME_H -#include -#endif - #include "ogs-core.h" /* diff --git a/lib/diameter/common/ogs-diameter-common.h b/lib/diameter/common/ogs-diameter-common.h index 8863c1176..04834dca0 100644 --- a/lib/diameter/common/ogs-diameter-common.h +++ b/lib/diameter/common/ogs-diameter-common.h @@ -27,6 +27,10 @@ #pragma GCC diagnostic ignored "-Wstrict-prototypes" #endif +#if defined(__FreeBSD__) +#define HAVE_NTOHLL 1 +#endif + #include "freeDiameter/libfdcore.h" #if defined(__GNUC__) diff --git a/lib/ipfw/glue.c b/lib/ipfw/glue.c index 07864531c..f6969ae9d 100644 --- a/lib/ipfw/glue.c +++ b/lib/ipfw/glue.c @@ -110,7 +110,15 @@ strlcpy(dst, src, siz) } -#endif /* __linux__ */ +/******************************************************** + * modifed by acetcom + * + * move down to remove sysctlbyname() in MacOSX and FreeBSD + */ + +/* #endif */ /* __linux__ */ + +/********************************************************/ #if defined (EMULATE_SYSCTL) @@ -359,6 +367,16 @@ skip: ; #endif /* __linux__ */ } +/******************************************************** + * modifed by acetcom + * + * move down to remove sysctlbyname in MacOSX and FreeBSD + */ + +#endif /* __linux__ */ + +/********************************************************/ + /* * The following two functions implement getsockopt/setsockopt * replacements to talk over a TCP socket. diff --git a/lib/ipfw/meson.build b/lib/ipfw/meson.build index 2aaf854e2..990972764 100644 --- a/lib/ipfw/meson.build +++ b/lib/ipfw/meson.build @@ -52,6 +52,8 @@ ipfw_cc_flags = ['-D_DEFAULT_SOURCE', '-D_BSD_SOURCE', '-DUSERSPACE', if host_system == 'linux' ipfw_cc_flags += ['-DNEED_SYSCTLBYNAME', '-DNEED_SIN_LEN'] +elif host_system == 'freebsd' + ipfw_cc_flags += ['-DNEED_SYSCTLBYNAME'] endif if cc.get_id() == 'gcc' or cc.get_id() == 'clang' diff --git a/lib/ipfw/ogs-ipfw.c b/lib/ipfw/ogs-ipfw.c index ea7ff3946..0b5855f54 100644 --- a/lib/ipfw/ogs-ipfw.c +++ b/lib/ipfw/ogs-ipfw.c @@ -24,11 +24,11 @@ #endif #endif +#include "ogs-ipfw.h" + #include "ipfw2.h" #include "objs/include_e/netinet/ip_fw.h" -#include "ogs-ipfw.h" - #define MAX_NUM_OF_TOKEN 32 #define MAX_NUM_OF_RULE_BUFFER 1024 diff --git a/lib/meson.build b/lib/meson.build index ba2920ea9..e3405bbd5 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -22,6 +22,7 @@ subdir('ipfw') subdir('crypt') subdir('app') subdir('sctp') +subdir('tun') subdir('dbi') subdir('diameter') subdir('asn1c') diff --git a/lib/pfcp/meson.build b/lib/pfcp/meson.build index 21a0aa3fb..c241773cf 100644 --- a/lib/pfcp/meson.build +++ b/lib/pfcp/meson.build @@ -44,11 +44,11 @@ libpfcp = library('ogspfcp', version : libogslib_version, c_args : '-DOGS_PFCP_COMPILATION', include_directories : [libpfcp_inc, libinc], - dependencies : [libipfw_dep, libcore_dep, libapp_dep, libgtp_dep], + dependencies : [libcore_dep, libipfw_dep, libapp_dep, libgtp_dep], install_rpath : libdir, install : true) libpfcp_dep = declare_dependency( link_with : libpfcp, include_directories : [libpfcp_inc, libinc], - dependencies : [libipfw_dep, libcore_dep, libapp_dep, libgtp_dep]) + dependencies : [libcore_dep, libipfw_dep, libapp_dep, libgtp_dep]) diff --git a/lib/sbi/conv.c b/lib/sbi/conv.c index b963013bd..da11db782 100644 --- a/lib/sbi/conv.c +++ b/lib/sbi/conv.c @@ -310,7 +310,7 @@ bool ogs_sbi_time_from_string(ogs_time_t *timestamp, char *str) { int rv, i, j, k; struct tm tm; - bool is_seconds; + bool is_subsecs, is_time, timezone_found; char seconds[MAX_TIMESTR_LEN]; char subsecs[MAX_TIMESTR_LEN]; ogs_time_t usecs; @@ -321,18 +321,25 @@ bool ogs_sbi_time_from_string(ogs_time_t *timestamp, char *str) memset(seconds, 0, sizeof seconds); memset(subsecs, 0, sizeof subsecs); - is_seconds = true; + is_subsecs = false; + is_time = false; + timezone_found = false; i = 0; j = 0, k = 0; while(str[i]) { - if (is_seconds == true && str[i] == '.') - is_seconds = false; - else if (is_seconds == false && (str[i] < '0' || str[i] > '9')) - is_seconds = true; + if (is_subsecs == false && str[i] == '.') + is_subsecs = true; + else if (is_subsecs == false && str[i] == 'T') + is_time = true; + else if (is_subsecs == true && (str[i] < '0' || str[i] > '9')) + is_subsecs = false; - if (is_seconds == true) { + if (is_time == true && (str[i] == '+' || str[i] == '-')) + timezone_found = true; + + if (is_subsecs == false) { if (str[i] == ':' && i >= 3 && (str[i-3] == '+' || str[i-3] == '-')) { - /* skip timezone ':' character */ + /* remove ':' character in timezone string range */ } else { seconds[j++] = str[i]; } @@ -344,7 +351,10 @@ bool ogs_sbi_time_from_string(ogs_time_t *timestamp, char *str) } memset(&tm, 0, sizeof(tm)); - ogs_strptime(seconds, "%Y-%m-%dT%H:%M:%S%z", &tm); + if (timezone_found == true) + ogs_strptime(seconds, "%Y-%m-%dT%H:%M:%S%z", &tm); + else + ogs_strptime(seconds, "%Y-%m-%dT%H:%M:%S", &tm); #if USE_MATH usecs = (ogs_time_t)floor(atof(subsecs) * 1000000.0 + 0.5); #else diff --git a/lib/sctp/meson.build b/lib/sctp/meson.build index 7a980bbdb..87734fa03 100644 --- a/lib/sctp/meson.build +++ b/lib/sctp/meson.build @@ -34,10 +34,7 @@ libsctp_sources = files(''' ogs-sctp.c '''.split()) -sctp_dep = cc.find_library('sctp', required : false) -if sctp_dep.found() - libsctp_sources += files('ogs-lksctp.c') -else +if host_system == 'darwin' sctp_dep = dependency('usrsctp', version: ['>=1.0.0', '<2'], fallback: ['usrsctp', 'usrsctp_dep'], @@ -48,6 +45,9 @@ else libsctp_sources += files('ogs-usrsctp.c') libsctp_conf.set('HAVE_USRSCTP', 1) +else + sctp_dep = cc.find_library('sctp', required : false) + libsctp_sources += files('ogs-lksctp.c') endif configure_file(output : 'sctp-config.h', configuration : libsctp_conf) diff --git a/lib/core/ogs-tun.c b/lib/tun/linux-setup.c similarity index 64% rename from lib/core/ogs-tun.c rename to lib/tun/linux-setup.c index 3e7c34e32..f65ba0e52 100644 --- a/lib/core/ogs-tun.c +++ b/lib/tun/linux-setup.c @@ -22,17 +22,13 @@ #undef OGS_LOG_DOMAIN #define OGS_LOG_DOMAIN __ogs_sock_domain -#if !defined(WIN32) #include #include #include #include #include -#endif -#if defined(__linux__) #include -#endif #ifndef IFNAMSIZ #define IFNAMSIZ 32 @@ -42,9 +38,6 @@ ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap) { ogs_socket_t fd = INVALID_SOCKET; -#if !defined(__linux__) - return fd; -#else const char *dev = "/dev/net/tun"; int rc; struct ifreq ifr; @@ -76,48 +69,9 @@ ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap) cleanup: close(fd); return INVALID_SOCKET; -#endif } int ogs_tun_set_ip(char *ifname, ogs_ipsubnet_t *gw, ogs_ipsubnet_t *sub) { return OGS_OK; } - -ogs_pkbuf_t *ogs_tun_read(ogs_socket_t fd, ogs_pkbuf_pool_t *packet_pool) -{ - ogs_pkbuf_t *recvbuf = NULL; - int n; - - ogs_assert(fd != INVALID_SOCKET); - ogs_assert(packet_pool); - - recvbuf = ogs_pkbuf_alloc(packet_pool, OGS_MAX_PKT_LEN); - ogs_assert(recvbuf); - ogs_pkbuf_reserve(recvbuf, OGS_TUN_MAX_HEADROOM); - ogs_pkbuf_put(recvbuf, OGS_MAX_PKT_LEN-OGS_TUN_MAX_HEADROOM); - - n = ogs_read(fd, recvbuf->data, recvbuf->len); - if (n <= 0) { - ogs_log_message(OGS_LOG_WARN, ogs_socket_errno, "ogs_read() failed"); - ogs_pkbuf_free(recvbuf); - return NULL; - } - - ogs_pkbuf_trim(recvbuf, n); - - return recvbuf; -} - -int ogs_tun_write(ogs_socket_t fd, ogs_pkbuf_t *pkbuf) -{ - ogs_assert(fd != INVALID_SOCKET); - ogs_assert(pkbuf); - - if (ogs_write(fd, pkbuf->data, pkbuf->len) <= 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "ogs_write() failed"); - return OGS_ERROR; - } - - return OGS_OK; -} diff --git a/lib/core/ogs-utun.c b/lib/tun/mac-setup.c similarity index 83% rename from lib/core/ogs-utun.c rename to lib/tun/mac-setup.c index 792d684ac..383e55737 100644 --- a/lib/core/ogs-utun.c +++ b/lib/tun/mac-setup.c @@ -18,6 +18,7 @@ */ #include "ogs-tun.h" +#include "ipfw/ipfw2.h" #undef OGS_LOG_DOMAIN #define OGS_LOG_DOMAIN __ogs_sock_domain @@ -31,13 +32,12 @@ #include #include +#if defined(__APPLE__) #include #include #include -static int unit = 0; - -static int utun_open(char *ifname, socklen_t len) +static int utun_open(int unit, char *ifname, socklen_t maxlen) { struct sockaddr_ctl addr; struct ctl_info info; @@ -45,7 +45,7 @@ static int utun_open(char *ifname, socklen_t len) int err = 0; ogs_assert(ifname); - ogs_assert(len); + ogs_assert(maxlen); fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL); if (fd < 0) return fd; @@ -65,7 +65,7 @@ static int utun_open(char *ifname, socklen_t len) err = connect(fd, (struct sockaddr *)&addr, sizeof (addr)); if (err != 0) goto on_error; - err = getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, ifname, &len); + err = getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, ifname, &maxlen); if (err != 0) goto on_error; on_error: @@ -76,18 +76,31 @@ on_error: return fd; } +#endif -ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap) +ogs_socket_t ogs_tun_open(char *ifname, int maxlen, int is_tap) { ogs_socket_t fd = INVALID_SOCKET; + int unit; ogs_assert(ifname); #define TUNTAP_ID_MAX 256 for (unit = 0; unit < TUNTAP_ID_MAX; unit++) { - if ((fd = utun_open(ifname, len)) > 0) { +#if defined(__APPLE__) + /* MacOSX "utun" device driver */ + if ((fd = utun_open(unit, ifname, maxlen)) > 0) { break; } +#else + /* FreeBSD "tun" device driver */ + char name[IFNAMSIZ]; + ogs_snprintf(name, sizeof(name), "/dev/tun%i", unit); + if ((fd = open(name, O_RDWR)) > 0) { + ogs_snprintf(ifname, maxlen, "tun%i", unit); + break; + } +#endif } if (fd < 0) { ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "open() failed"); @@ -207,19 +220,6 @@ static int tun_set_ipv4(char *ifname, return OGS_OK; } -static int contigmask(uint8_t *p, int len) -{ - int i, n; - - for (i=0; imask, IPV6_BITLEN); - ogs_snprintf(devname, sizeof devname, "utun%d", unit); ogs_snprintf(addr, sizeof addr, "%s/%d", OGS_INET6_NTOP(ipaddr->sub, buf), prefixlen); commandLine[0] = "/sbin/ifconfig"; - commandLine[1] = devname; + commandLine[1] = ifname;; commandLine[2] = "inet6"; commandLine[3] = addr; commandLine[4] = "up"; @@ -413,63 +412,3 @@ int ogs_tun_set_ip(char *ifname, ogs_ipsubnet_t *gw, ogs_ipsubnet_t *sub) return rv; } - -ogs_pkbuf_t *ogs_tun_read(ogs_socket_t fd, ogs_pkbuf_pool_t *packet_pool) -{ - ogs_pkbuf_t *recvbuf = NULL; - int n; - - ogs_assert(fd != INVALID_SOCKET); - ogs_assert(packet_pool); - - recvbuf = ogs_pkbuf_alloc(packet_pool, OGS_MAX_PKT_LEN); - ogs_assert(recvbuf); - ogs_pkbuf_reserve(recvbuf, OGS_TUN_MAX_HEADROOM); - ogs_pkbuf_put(recvbuf, OGS_MAX_PKT_LEN-OGS_TUN_MAX_HEADROOM); - - n = ogs_read(fd, recvbuf->data, recvbuf->len); - if (n <= 0) { - ogs_log_message(OGS_LOG_WARN, ogs_socket_errno, "ogs_read() failed"); - ogs_pkbuf_free(recvbuf); - return NULL; - } - - ogs_pkbuf_trim(recvbuf, n); - - /* Remove Null/Loopback Header (4bytes) */ - ogs_pkbuf_pull(recvbuf, 4); - - return recvbuf; -} - -int ogs_tun_write(ogs_socket_t fd, ogs_pkbuf_t *pkbuf) -{ - uint8_t version; - uint32_t family; - - ogs_assert(fd != INVALID_SOCKET); - ogs_assert(pkbuf); - - version = (*((unsigned char *)pkbuf->data) >> 4) & 0xf; - - if (version == 4) { - family = htobe32(AF_INET); - } else if (version == 6) { - family = htobe32(AF_INET6); - } else { - ogs_error("Invalid packet [IP version:%d, Packet Length:%d]", - version, pkbuf->len); - ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len); - return OGS_ERROR; - } - - ogs_pkbuf_push(pkbuf, sizeof(family)); - memcpy(pkbuf->data, &family, sizeof(family)); - - if (ogs_write(fd, pkbuf->data, pkbuf->len) <= 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "ogs_write() failed"); - return OGS_ERROR; - } - - return OGS_OK; -} diff --git a/lib/tun/meson.build b/lib/tun/meson.build new file mode 100644 index 000000000..c2eb5bf68 --- /dev/null +++ b/lib/tun/meson.build @@ -0,0 +1,45 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libtun_sources = files(''' + ogs-tun.h + + tunio.c +'''.split()) + +if host_system == 'linux' + libtun_sources += files('linux-setup.c') +elif host_system == 'windows' + libtun_sources += files('windows-setup.c') +else + libtun_sources += files('mac-setup.c') +endif + +libtun_inc = include_directories('.') + +libtun = library('ogstun', + sources : libtun_sources, + version : libogslib_version, + c_args : '-DOGS_TUN_COMPILATION', + include_directories : [libtun_inc, libinc], + dependencies : [libcore_dep, libipfw_dep], + install : true) + +libtun_dep = declare_dependency( + link_with : libtun, + include_directories : [libtun_inc, libinc], + dependencies : [libcore_dep, libipfw_dep]) diff --git a/lib/core/ogs-tun.h b/lib/tun/ogs-tun.h similarity index 95% rename from lib/core/ogs-tun.h rename to lib/tun/ogs-tun.h index d0917adb2..8c6fc0fd8 100644 --- a/lib/core/ogs-tun.h +++ b/lib/tun/ogs-tun.h @@ -45,7 +45,7 @@ extern "C" { */ #define OGS_TUN_MAX_HEADROOM 16 -ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap); +ogs_socket_t ogs_tun_open(char *ifname, int maxlen, int is_tap); int ogs_tun_set_ip(char *ifname, ogs_ipsubnet_t *gw, ogs_ipsubnet_t *sub); ogs_pkbuf_t *ogs_tun_read(ogs_socket_t fd, ogs_pkbuf_pool_t *packet_pool); diff --git a/lib/tun/tunio.c b/lib/tun/tunio.c new file mode 100644 index 000000000..7bc1aeb0d --- /dev/null +++ b/lib/tun/tunio.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-tun.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +ogs_pkbuf_t *ogs_tun_read(ogs_socket_t fd, ogs_pkbuf_pool_t *packet_pool) +{ + ogs_pkbuf_t *recvbuf = NULL; + int n; + + ogs_assert(fd != INVALID_SOCKET); + ogs_assert(packet_pool); + + recvbuf = ogs_pkbuf_alloc(packet_pool, OGS_MAX_PKT_LEN); + ogs_assert(recvbuf); + ogs_pkbuf_reserve(recvbuf, OGS_TUN_MAX_HEADROOM); + ogs_pkbuf_put(recvbuf, OGS_MAX_PKT_LEN-OGS_TUN_MAX_HEADROOM); + + n = ogs_read(fd, recvbuf->data, recvbuf->len); + if (n <= 0) { + ogs_log_message(OGS_LOG_WARN, ogs_socket_errno, "ogs_read() failed"); + ogs_pkbuf_free(recvbuf); + return NULL; + } + + ogs_pkbuf_trim(recvbuf, n); + +#if defined(__APPLE__) + /* Remove Null/Loopback Header (4bytes) */ + ogs_pkbuf_pull(recvbuf, 4); +#endif + + return recvbuf; +} + +int ogs_tun_write(ogs_socket_t fd, ogs_pkbuf_t *pkbuf) +{ +#if defined(__APPLE__) + uint8_t version; + uint32_t family; +#endif + + ogs_assert(fd != INVALID_SOCKET); + ogs_assert(pkbuf); + +#if defined(__APPLE__) + version = (*((unsigned char *)pkbuf->data) >> 4) & 0xf; + + if (version == 4) { + family = htobe32(AF_INET); + } else if (version == 6) { + family = htobe32(AF_INET6); + } else { + ogs_error("Invalid packet [IP version:%d, Packet Length:%d]", + version, pkbuf->len); + ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len); + return OGS_ERROR; + } + + ogs_pkbuf_push(pkbuf, sizeof(family)); + memcpy(pkbuf->data, &family, sizeof(family)); +#endif + + if (ogs_write(fd, pkbuf->data, pkbuf->len) <= 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "ogs_write() failed"); + return OGS_ERROR; + } + + return OGS_OK; +} diff --git a/lib/tun/windows-setup.c b/lib/tun/windows-setup.c new file mode 100644 index 000000000..4fc58c5b7 --- /dev/null +++ b/lib/tun/windows-setup.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-tun.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap) +{ + ogs_error("Not implemented"); + ogs_assert_if_reached(); + return INVALID_SOCKET; +} + +int ogs_tun_set_ip(char *ifname, ogs_ipsubnet_t *gw, ogs_ipsubnet_t *sub) +{ + ogs_error("Not implemented"); + ogs_assert_if_reached(); + return OGS_ERROR; +} diff --git a/meson.build b/meson.build index 8447106b8..a33a7ebc4 100644 --- a/meson.build +++ b/meson.build @@ -113,7 +113,7 @@ subdir('configs') subdir('lib') subdir('src') subdir('misc') -# Don’t build the tests unless we can run them (either natively or in an exe wrapper) +# Don't build the tests unless we can run them (either natively or in an exe wrapper) build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) if build_tests subdir('tests') diff --git a/src/amf/meson.build b/src/amf/meson.build index bcb98212c..571c8fe54 100644 --- a/src/amf/meson.build +++ b/src/amf/meson.build @@ -58,7 +58,6 @@ libamf_sources = files(''' libamf = static_library('amf', sources : libamf_sources, - link_with : libipfw, dependencies : [libapp_dep, libsctp_dep, libngap_dep, diff --git a/src/ausf/meson.build b/src/ausf/meson.build index 97271e84b..eb7a6fc5e 100644 --- a/src/ausf/meson.build +++ b/src/ausf/meson.build @@ -37,7 +37,6 @@ libausf_sources = files(''' libausf = static_library('ausf', sources : libausf_sources, - link_with : libipfw, dependencies : [libapp_dep, libcrypt_dep, libsbi_dep], diff --git a/src/nrf/meson.build b/src/nrf/meson.build index 57ac0377b..72bda8239 100644 --- a/src/nrf/meson.build +++ b/src/nrf/meson.build @@ -32,7 +32,6 @@ libnrf_sources = files(''' libnrf = static_library('nrf', sources : libnrf_sources, - link_with : libipfw, dependencies : [libapp_dep, libdbi_dep, libsbi_dep], diff --git a/src/pcf/meson.build b/src/pcf/meson.build index 32da4ff3e..4a441cabe 100644 --- a/src/pcf/meson.build +++ b/src/pcf/meson.build @@ -39,7 +39,6 @@ libpcf_sources = files(''' libpcf = static_library('pcf', sources : libpcf_sources, - link_with : libipfw, dependencies : [libcrypt_dep, libapp_dep, libdbi_dep, diff --git a/src/smf/gtp-path.h b/src/smf/gtp-path.h index b45e43cc3..be7141123 100644 --- a/src/smf/gtp-path.h +++ b/src/smf/gtp-path.h @@ -20,7 +20,6 @@ #ifndef SMF_GTP_PATH_H #define SMF_GTP_PATH_H -#include "ogs-tun.h" #include "ogs-gtp.h" #ifdef __cplusplus diff --git a/src/smf/meson.build b/src/smf/meson.build index 4e7403278..ba371084c 100644 --- a/src/smf/meson.build +++ b/src/smf/meson.build @@ -96,15 +96,13 @@ libsmf_sources = files(''' libsmf = static_library('smf', sources : libsmf_sources, - link_with : libipfw, dependencies : [libapp_dep, libsbi_dep, libngap_dep, libnas_5gs_dep, libdiameter_gx_dep, libgtp_dep, - libpfcp_dep, - libipfw_dep], + libpfcp_dep], install : false) libsmf_dep = declare_dependency( @@ -115,8 +113,7 @@ libsmf_dep = declare_dependency( libnas_5gs_dep, libdiameter_gx_dep, libgtp_dep, - libpfcp_dep, - libipfw_dep]) + libpfcp_dep]) smf_sources = files(''' app.c diff --git a/src/udm/meson.build b/src/udm/meson.build index cdab3e909..e7512342e 100644 --- a/src/udm/meson.build +++ b/src/udm/meson.build @@ -37,7 +37,6 @@ libudm_sources = files(''' libudm = static_library('udm', sources : libudm_sources, - link_with : libipfw, dependencies : [libapp_dep, libcrypt_dep, libsbi_dep], diff --git a/src/udr/meson.build b/src/udr/meson.build index c1782f6ec..19c7076a9 100644 --- a/src/udr/meson.build +++ b/src/udr/meson.build @@ -33,7 +33,6 @@ libudr_sources = files(''' libudr = static_library('udr', sources : libudr_sources, - link_with : libipfw, dependencies : [libapp_dep, libdbi_dep, libsbi_dep], diff --git a/src/upf/meson.build b/src/upf/meson.build index 05cdfa846..a8ddfe1f2 100644 --- a/src/upf/meson.build +++ b/src/upf/meson.build @@ -64,16 +64,15 @@ libupf_sources = files(''' libupf = static_library('upf', sources : libupf_sources, - link_with : libipfw, dependencies : [ - libapp_dep, libdiameter_gx_dep, libgtp_dep, libpfcp_dep, libipfw_dep + libapp_dep, libdiameter_gx_dep, libgtp_dep, libpfcp_dep, libtun_dep ], install : false) libupf_dep = declare_dependency( link_with : libupf, dependencies : [ - libapp_dep, libdiameter_gx_dep, libgtp_dep, libpfcp_dep, libipfw_dep + libapp_dep, libdiameter_gx_dep, libgtp_dep, libpfcp_dep, libtun_dep ]) upf_sources = files(''' diff --git a/src/upf/rule-match.c b/src/upf/rule-match.c index 54127bdea..4dfa951e4 100644 --- a/src/upf/rule-match.c +++ b/src/upf/rule-match.c @@ -20,14 +20,14 @@ #define _DEFAULT_SOURCE 1 #define _BSD_SOURCE 1 +#include "rule-match.h" + #include #include #include #include #include -#include "rule-match.h" - static int decode_ipv6_header( struct ip6_hdr *ip6_h, uint8_t *proto, uint16_t *hlen) { diff --git a/tests/attach/guti-test.c b/tests/attach/guti-test.c index faa7eece4..b7f055fda 100644 --- a/tests/attach/guti-test.c +++ b/tests/attach/guti-test.c @@ -292,6 +292,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#if !defined(__FreeBSD__) /* Send GTP-U ICMP Packet */ rv = test_gtpu_send_ping(gtpu, bearer, TEST_PING_IPV6); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -300,6 +301,7 @@ static void test1_func(abts_case *tc, void *data) recvbuf = test_gtpu_read(gtpu); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#endif /* Send Attach Request */ memset(&sess->pdn_connectivity_param, diff --git a/tests/meson.build b/tests/meson.build index 47d96ad44..d2872d58c 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -20,9 +20,9 @@ testinc = include_directories('.') subdir('core') subdir('crypt') subdir('sctp') +subdir('unit') subdir('common') subdir('app') -subdir('unit') subdir('registration') subdir('vonr') subdir('minimal') diff --git a/tests/registration/guti-test.c b/tests/registration/guti-test.c index 9388f93b7..a5f023fb1 100644 --- a/tests/registration/guti-test.c +++ b/tests/registration/guti-test.c @@ -308,6 +308,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#if !defined(__FreeBSD__) /* Send GTP-U ICMP Packet */ rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV6); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -316,6 +317,7 @@ static void test1_func(abts_case *tc, void *data) recvbuf = test_gtpu_read(gtpu); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#endif /* Send Registration request * - Update Registration request type @@ -845,6 +847,7 @@ static void test2_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#if !defined(__FreeBSD__) /* Send GTP-U ICMP Packet */ rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV6); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -853,6 +856,7 @@ static void test2_func(abts_case *tc, void *data) recvbuf = test_gtpu_read(gtpu); ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); +#endif /* Send Registration request * - Update Registration request type diff --git a/tests/registration/paging-test.c b/tests/registration/paging-test.c index 9f0e2115f..0f28489aa 100644 --- a/tests/registration/paging-test.c +++ b/tests/registration/paging-test.c @@ -1841,6 +1841,9 @@ static void vonr_qos_flow_test1_func(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, recvbuf); ogs_pkbuf_free(recvbuf); + /* TODO: If there is no delay here, it won't work on FreeBSD */ + ogs_msleep(100); + /* Send De-registration request */ gmmbuf = testgmm_build_de_registration_request(test_ue, 1); ABTS_PTR_NOTNULL(tc, gmmbuf); diff --git a/tests/unit/abts-main.c b/tests/unit/abts-main.c index e4a92605d..f306c40f5 100644 --- a/tests/unit/abts-main.c +++ b/tests/unit/abts-main.c @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -#include "test-app.h" -#include "mme/mme-context.h" +#include "ogs-core.h" +#include "core/abts.h" abts_suite *test_s1ap_message(abts_suite *suite); abts_suite *test_nas_message(abts_suite *suite); @@ -43,8 +43,6 @@ const struct testlist { static void terminate(void) { - mme_context_final(); - ogs_pkbuf_default_destroy(); ogs_core_terminate(); @@ -85,14 +83,10 @@ int main(int argc, const char *const argv[]) } ogs_core_initialize(); - ogs_app_setup_log(); ogs_pkbuf_default_init(&config); ogs_pkbuf_default_create(&config); - ogs_app_context_init(); - mme_context_init(); - atexit(terminate); rv = ogs_log_config_domain(optarg.domain_mask, optarg.log_level); diff --git a/tests/unit/crash-test.c b/tests/unit/crash-test.c index 39dc6803e..d35dc0cec 100644 --- a/tests/unit/crash-test.c +++ b/tests/unit/crash-test.c @@ -17,7 +17,9 @@ * along with this program. If not, see . */ -#include "test-common.h" +#include "ogs-s1ap.h" +#include "ogs-crypt.h" +#include "core/abts.h" static void test1_func(abts_case *tc, void *data) { diff --git a/tests/unit/gtp-message-test.c b/tests/unit/gtp-message-test.c index 82fd1a1cb..7d1c56498 100644 --- a/tests/unit/gtp-message-test.c +++ b/tests/unit/gtp-message-test.c @@ -17,7 +17,8 @@ * along with this program. If not, see . */ -#include "test-common.h" +#include "ogs-gtp.h" +#include "core/abts.h" static void gtp_message_test1(abts_case *tc, void *data) { diff --git a/tests/unit/meson.build b/tests/unit/meson.build index b680badb6..ba0e61c87 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -29,6 +29,10 @@ testunit_unit_sources = files(''' testunit_unit_exe = executable('unit', sources : testunit_unit_sources, c_args : [testunit_core_cc_flags, sbi_cc_flags], - dependencies : [libtestapp_dep, libmme_dep, libsbi_dep]) + dependencies : [libs1ap_dep, + libgtp_dep, + libngap_dep, + libnas_eps_dep, + libsbi_dep]) test('unit', testunit_unit_exe, is_parallel : false, suite: 'unit') diff --git a/tests/unit/nas-message-test.c b/tests/unit/nas-message-test.c index 469cc8e44..872bfbf31 100644 --- a/tests/unit/nas-message-test.c +++ b/tests/unit/nas-message-test.c @@ -17,8 +17,8 @@ * along with this program. If not, see . */ +#include "ogs-nas-eps.h" #include "core/abts.h" -#include "mme/nas-security.h" static void ogs_nas_eps_message_test1(abts_case *tc, void *data) { @@ -185,6 +185,7 @@ static void ogs_nas_eps_message_test4(abts_case *tc, void *data) ogs_pkbuf_free(pkbuf); } +#if 0 static void ogs_nas_eps_message_test5(abts_case *tc, void *data) { mme_ue_t ue; @@ -198,6 +199,7 @@ static void ogs_nas_eps_message_test5(abts_case *tc, void *data) ue.ul_count.sqn = 0xef; ABTS_INT_EQUAL(tc, 0xabcdef, ue.ul_count.i32); } +#endif static void ogs_nas_eps_message_test6(abts_case *tc, void *data) { @@ -329,11 +331,15 @@ abts_suite *test_nas_message(abts_suite *suite) { suite = ADD_SUITE(suite) + ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_ERROR); + abts_run_test(suite, ogs_nas_eps_message_test1, NULL); abts_run_test(suite, ogs_nas_eps_message_test2, NULL); abts_run_test(suite, ogs_nas_eps_message_test3, NULL); abts_run_test(suite, ogs_nas_eps_message_test4, NULL); +#if 0 /* Will remove it in order not to use mme-context.h */ abts_run_test(suite, ogs_nas_eps_message_test5, NULL); +#endif abts_run_test(suite, ogs_nas_eps_message_test6, NULL); abts_run_test(suite, ogs_nas_eps_message_test7, NULL); abts_run_test(suite, ogs_nas_eps_message_test8, NULL); diff --git a/tests/unit/ngap-message-test.c b/tests/unit/ngap-message-test.c index d13521bf1..8fa5bcbd6 100644 --- a/tests/unit/ngap-message-test.c +++ b/tests/unit/ngap-message-test.c @@ -1,7 +1,24 @@ -#include "core/abts.h" +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#include "amf/ngap-build.h" -#include "test-common.h" +#include "ogs-ngap.h" +#include "core/abts.h" static void ngap_message_test1(abts_case *tc, void *data) { diff --git a/tests/unit/s1ap-message-test.c b/tests/unit/s1ap-message-test.c index 26be15626..9b81f97c0 100644 --- a/tests/unit/s1ap-message-test.c +++ b/tests/unit/s1ap-message-test.c @@ -1,6 +1,24 @@ -#include "core/abts.h" +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -#include "mme/s1ap-build.h" +#include "ogs-s1ap.h" +#include "core/abts.h" static void s1ap_message_test1(abts_case *tc, void *data) { @@ -83,6 +101,7 @@ static void s1ap_message_test3(abts_case *tc, void *data) ogs_pkbuf_free(pkbuf); } +#if 0 static void s1ap_message_test4(abts_case *tc, void *data) { ogs_s1ap_message_t message; @@ -110,7 +129,6 @@ static void s1ap_message_test4(abts_case *tc, void *data) static void s1ap_message_test5(abts_case *tc, void *data) { -#if 0 ogs_s1ap_message_t message; int rv; ogs_pkbuf_t *pkbuf; @@ -129,7 +147,6 @@ static void s1ap_message_test5(abts_case *tc, void *data) ogs_s1ap_free(&message); ogs_pkbuf_free(pkbuf); -#endif } static void s1ap_message_test6(abts_case *tc, void *data) @@ -161,6 +178,7 @@ static void s1ap_message_test6(abts_case *tc, void *data) s1apbuf->data, s1apbuf->len) == 0); ogs_pkbuf_free(s1apbuf); } +#endif static void s1ap_message_test7(abts_case *tc, void *data) { @@ -267,12 +285,16 @@ abts_suite *test_s1ap_message(abts_suite *suite) { suite = ADD_SUITE(suite) + ogs_log_install_domain(&__ogs_s1ap_domain, "s1ap", OGS_LOG_ERROR); + abts_run_test(suite, s1ap_message_test1, NULL); abts_run_test(suite, s1ap_message_test2, NULL); abts_run_test(suite, s1ap_message_test3, NULL); +#if 0 /* Will remove it in order not to use mme-context.h */ abts_run_test(suite, s1ap_message_test4, NULL); abts_run_test(suite, s1ap_message_test5, NULL); abts_run_test(suite, s1ap_message_test6, NULL); +#endif abts_run_test(suite, s1ap_message_test7, NULL); abts_run_test(suite, s1ap_message_test8, NULL); abts_run_test(suite, s1ap_message_test9, NULL); diff --git a/tests/unit/sbi-message-test.c b/tests/unit/sbi-message-test.c index 551098acb..d4e7ef51e 100644 --- a/tests/unit/sbi-message-test.c +++ b/tests/unit/sbi-message-test.c @@ -17,9 +17,8 @@ * along with this program. If not, see . */ -#include "test-common.h" - #include "ogs-sbi.h" +#include "core/abts.h" static void sbi_message_test1(abts_case *tc, void *data) { diff --git a/tests/unit/security-test.c b/tests/unit/security-test.c index 17dda60bf..454471e52 100644 --- a/tests/unit/security-test.c +++ b/tests/unit/security-test.c @@ -17,10 +17,7 @@ * along with this program. If not, see . */ -#include "ogs-crypt.h" - -#include "mme/nas-security.h" - +#include "ogs-nas-common.h" #include "core/abts.h" static void security_test1(abts_case *tc, void *data) diff --git a/vagrant/freebsd/Vagrantfile b/vagrant/freebsd/Vagrantfile new file mode 100644 index 000000000..734d77f97 --- /dev/null +++ b/vagrant/freebsd/Vagrantfile @@ -0,0 +1,75 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "freebsd/FreeBSD-11.4-STABLE" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. +config.vm.provider "virtualbox" do |vb| + # Customize the amount of memory on the VM: + vb.memory = "3072" + vb.cpus = "1" +end + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + # config.vm.provision "shell", inline: <<-SHELL + # apt-get update + # apt-get install -y apache2 + # SHELL +end