From 002e3c7ae951544e6f88083a54ee3370d79baff8 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Fri, 30 Apr 2021 22:13:04 +0900 Subject: [PATCH] [Alpine] Add Dockerfile and Document --- docker/alpine/latest/base/Dockerfile | 26 ++++++ docker/alpine/latest/dev/Dockerfile | 20 +++++ docker/alpine/latest/dev/setup.sh | 10 +++ docs/_docs/platform/08-alpine.md | 115 ++++++++++++++++++++++++ docs/_pages/docs.md | 1 + lib/core/ogs-macros.h | 4 +- lib/ipfw/glue.h | 9 +- lib/ipfw/objs/include_e/netinet/ip_fw.h | 15 ++-- lib/sbi/client.c | 2 +- 9 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 docker/alpine/latest/base/Dockerfile create mode 100644 docker/alpine/latest/dev/Dockerfile create mode 100755 docker/alpine/latest/dev/setup.sh create mode 100644 docs/_docs/platform/08-alpine.md diff --git a/docker/alpine/latest/base/Dockerfile b/docker/alpine/latest/base/Dockerfile new file mode 100644 index 000000000..61d8abb38 --- /dev/null +++ b/docker/alpine/latest/base/Dockerfile @@ -0,0 +1,26 @@ +ARG dist=alpine +ARG tag=latest +FROM ${dist}:${tag} + +MAINTAINER Sukchan Lee + +RUN apk update && \ + apk add --no-cache \ + alpine-sdk \ + bison \ + flex \ + git \ + meson \ + bash \ + linux-headers \ + bsd-compat-headers \ + yaml-dev \ + lksctp-tools-dev \ + gnutls-dev \ + libgcrypt-dev \ + libidn-dev \ + mongo-c-driver-dev \ + libmicrohttpd-dev \ + curl-dev \ + nghttp2-dev \ + iproute2 diff --git a/docker/alpine/latest/dev/Dockerfile b/docker/alpine/latest/dev/Dockerfile new file mode 100644 index 000000000..9c97df339 --- /dev/null +++ b/docker/alpine/latest/dev/Dockerfile @@ -0,0 +1,20 @@ +ARG dist=alpine +ARG tag=latest +ARG username=acetcom +FROM ${username}/${dist}-${tag}-open5gs-base + +MAINTAINER Sukchan Lee + +COPY setup.sh /root + +RUN apk update && \ + apk add --no-cache \ + vim \ + sudo + +ARG username=acetcom +RUN adduser -u 1000 acetcom -D && \ + echo "${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username} && \ + chmod 0440 /etc/sudoers.d/${username} + +WORKDIR /home/${username} diff --git a/docker/alpine/latest/dev/setup.sh b/docker/alpine/latest/dev/setup.sh new file mode 100755 index 000000000..e3210034b --- /dev/null +++ b/docker/alpine/latest/dev/setup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun +fi +ip addr del 10.45.0.1/16 dev ogstun 2> /dev/null +ip addr add 10.45.0.1/16 dev ogstun +ip addr del 2001:230:cafe::1/48 dev ogstun 2> /dev/null +ip addr add 2001:230:cafe::1/48 dev ogstun +ip link set ogstun up diff --git a/docs/_docs/platform/08-alpine.md b/docs/_docs/platform/08-alpine.md new file mode 100644 index 000000000..ce0043586 --- /dev/null +++ b/docs/_docs/platform/08-alpine.md @@ -0,0 +1,115 @@ +--- +title: Alpine +head_inline: "" +--- + +This guide is based on **Alpine 3.13** Distribution. +{: .blue} + +### Getting MongoDB +--- + +Install MongoDB with package manager. +```bash +$ sudo apk update +$ sudo apk add mongodb +``` + +Run MongoDB server. +```bash +$ mkdir -p ./data/db +$ mongod --dbpath ./data/db +``` + +### Setting up TUN device (No persistent after rebooting) +--- + +Create the TUN device. Interface name will be `ogstun`. +```bash +$ sudo apk add iproute2 +$ sudo ip tuntap add name ogstun mode tun +$ ip link show +``` + +You are now ready to set the IP address on TUN device. + +```bash +$ sudo ip addr add 10.45.0.1/16 dev ogstun +$ sudo ip addr add 2001:230:cafe::1/48 dev ogstun +``` + +Make sure it is set up properly. +```bash +$ sudo ip link set ogstun up +$ ip link show +``` + +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/main/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 apk add alpine-sdk bison flex git meson bash sudo linux-headers bsd-compat-headers yaml-dev lksctp-tools-dev gnutls-dev libgcrypt-dev libidn-dev mongo-c-driver-dev libmicrohttpd-dev curl-dev nghttp2-dev +``` + +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. +```bash +$ ./build/tests/attach/attach ## EPC Only +$ ./build/tests/registration/registration ## 5G Core Only +``` + +Run all test programs as below. +```bash +$ cd build +$ 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 apk add nodejs +``` + +Install the dependencies to run WebUI + +```bash +$ cd webui +$ npm ci --no-optional +``` + +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 953fbf97d..2407d75cf 100644 --- a/docs/_pages/docs.md +++ b/docs/_pages/docs.md @@ -25,6 +25,7 @@ head_inline: "" - [MacOSX(Apple Silicon)](platform/05-macosx-apple-silicon) - [MacOSX(Intel)](platform/06-macosx-intel) - [FreeBSD](platform/07-freebsd) + - [Alpine](platform/08-alpine) - Hardware Specific Notes - [eNodeBs/gNodeBs tested on Open5GS](hardware/01-genodebs) diff --git a/lib/core/ogs-macros.h b/lib/core/ogs-macros.h index 5d675862d..c00406263 100644 --- a/lib/core/ogs-macros.h +++ b/lib/core/ogs-macros.h @@ -109,8 +109,10 @@ extern "C" { #elif defined(__FreeBSD__) #include -#elif ! defined(__GLIBC__) + +#elif defined(__linux__) #include + #endif #ifndef WORDS_BIGENDIAN diff --git a/lib/ipfw/glue.h b/lib/ipfw/glue.h index a478ba6a3..be65f7822 100644 --- a/lib/ipfw/glue.h +++ b/lib/ipfw/glue.h @@ -71,8 +71,13 @@ static __inline time_t _long_to_time(long tlong) { - if (sizeof(long) == sizeof(u_int32_t)) - return((time_t)(u_int32_t)(tlong)); +#if 0 /* modified by acetcom */ + if (sizeof(long) == sizeof(__int32_t)) + return((time_t)(__int32_t)(tlong)); +#else + if (sizeof(long) == sizeof(int32_t)) + return((time_t)(int32_t)(tlong)); +#endif return((time_t)tlong); } diff --git a/lib/ipfw/objs/include_e/netinet/ip_fw.h b/lib/ipfw/objs/include_e/netinet/ip_fw.h index 1e9361a53..f5d3aa0ea 100644 --- a/lib/ipfw/objs/include_e/netinet/ip_fw.h +++ b/lib/ipfw/objs/include_e/netinet/ip_fw.h @@ -517,19 +517,20 @@ typedef struct _ipfw_insn_nat { struct cfg_nat *nat; } ipfw_insn_nat; -#if !defined(__GLIBC__) /* Adding support for musl libc netint */ /* Apply ipv6 mask on ipv6 addr */ -#define APPLY_MASK(addr,mask) \ - (addr)->__u6_addr.__s6_addr32[0] &= (mask)->__u6_addr.__s6_addr32[0]; \ - (addr)->__u6_addr.__s6_addr32[1] &= (mask)->__u6_addr.__s6_addr32[1]; \ - (addr)->__u6_addr.__s6_addr32[2] &= (mask)->__u6_addr.__s6_addr32[2]; \ - (addr)->__u6_addr.__s6_addr32[3] &= (mask)->__u6_addr.__s6_addr32[3]; -#else +#if 0 /* modified by acetcom */ #define APPLY_MASK(addr,mask) \ (addr)->__u6_addr.__u6_addr32[0] &= (mask)->__u6_addr.__u6_addr32[0]; \ (addr)->__u6_addr.__u6_addr32[1] &= (mask)->__u6_addr.__u6_addr32[1]; \ (addr)->__u6_addr.__u6_addr32[2] &= (mask)->__u6_addr.__u6_addr32[2]; \ (addr)->__u6_addr.__u6_addr32[3] &= (mask)->__u6_addr.__u6_addr32[3]; +#else +#define APPLY_MASK(addr,mask) \ + do { \ + int i; \ + for (i = 0; i < 16; i++) \ + (addr)->s6_addr[i] &= (mask)->s6_addr[i]; \ + } while(0); #endif /* Structure for ipv6 */ diff --git a/lib/sbi/client.c b/lib/sbi/client.c index 75ee6ad8b..cd0eab832 100644 --- a/lib/sbi/client.c +++ b/lib/sbi/client.c @@ -165,7 +165,7 @@ ogs_sbi_client_t *ogs_sbi_client_find(ogs_sockaddr_t *addr) } #define mycase(code) \ - case code: s = (code) + case code: s = OGS_STRINGIFY(code) static void mcode_or_die(const char *where, CURLMcode code) {