Skip to content

Commit

Permalink
Added Samba libreplace implementation for freeifaddrs and getifaddrs
Browse files Browse the repository at this point in the history
In case if system doesn't provide above functions, don't fail and use
Samba project libreplace implementation.
This allows to run app on embedded systems.
  • Loading branch information
mobrembski authored and Michał Obrembski committed Feb 25, 2021
1 parent 42e9e8d commit f62c839
Show file tree
Hide file tree
Showing 8 changed files with 969 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/openfortivpn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ jobs:
run: sudo apt-get install -y astyle

- name: Artistic Style
run: ./tests/lint/astyle.sh $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation)
run: ./tests/lint/astyle.sh $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation | grep -v ifaddrs)

- name: Linux Kernel Coding Style
run: ./tests/lint/checkpatch.sh $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation)
run: ./tests/lint/checkpatch.sh $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation | grep -v ifaddrs)

- name: EOL at EOF
run: ./tests/lint/eol-at-eof.sh $(git ls-files | grep -v openssl_hostname_validation)
run: ./tests/lint/eol-at-eof.sh $(git ls-files | grep -v openssl_hostname_validation | grep -v ifaddrs)

- name: Line Length
run: ./tests/lint/line_length.py $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation)
run: ./tests/lint/line_length.py $(git ls-files '*.[ch]' | grep -v openssl_hostname_validation | grep -v ifaddrs)

build:
name: Build
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \
src/xml.h src/userinput.c src/userinput.h \
src/openssl_hostname_validation.c \
src/openssl_hostname_validation.h
if LIBREPLACE_REQUIRED
openfortivpn_SOURCES += src/ifaddrs.c
endif
openfortivpn_CFLAGS = -Wall -pedantic
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
-DPPP_PATH=\"@PPP_PATH@\" \
-DNETSTAT_PATH=\"@NETSTAT_PATH@\" \
Expand Down
42 changes: 38 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ AC_TYPE_UINT8_T
AC_CHECK_TYPES([struct termios], [], [], [#include <termios.h>])

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([ \
access \
atoi \
Expand All @@ -125,15 +123,13 @@ fputs \
fread \
free \
freeaddrinfo \
freeifaddrs \
freopen \
fwrite \
gai_strerror \
getaddrinfo \
getchar \
getenv \
geteuid \
getifaddrs \
getopt_long \
htons \
index \
Expand Down Expand Up @@ -502,6 +498,44 @@ AC_ARG_WITH([resolvconf-config-file],
AC_DEFINE_UNQUOTED([RESOLV_CONF_FILE_PATH],["$withval"])
)

AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <netdb.h>
int main(int argc, char **argv){
struct ifaddrs *ifp = NULL;
int ret = getifaddrs (&ifp);
freeifaddrs(ifp);
}
])], [
libreplace_required=no
AC_MSG_NOTICE([HAVE_IFADDRS... 1])
],[
libreplace_required=yes
AC_MSG_NOTICE([HAVE_IFADDRS... 0])
])

AC_ARG_ENABLE([libreplace],
[AS_HELP_STRING([--enable-libreplace], [Force to use libreplace ifaddrs implementation])],
[enable_libreplace=yes],
[enable_libreplace=no])
AS_CASE(["$enable_libreplace"],
[yes], [
AC_MSG_NOTICE([Force using libreplace...])
],
[no], [
],
[AC_MSG_ERROR([unknown option '$enable_libreplace' for --enable-libreplace])])
AS_IF([test "x$enable_libreplace" != "xno" -o "x$libreplace_required" != "xno"], [AC_DEFINE([HAVE_IFADDRS],[0])], [AC_DEFINE([HAVE_IFADDRS],[1])])
AM_CONDITIONAL([LIBREPLACE_REQUIRED], [test "x$enable_libreplace" = "xyes" -o "x$libreplace_required" = "xyes"])

# prepare to get rid of obsolete code (FortiOS 4)
AC_ARG_ENABLE([obsolete],
[AS_HELP_STRING([--disable-obsolete], [disable support for FortiOS 4])],,
Expand Down
Loading

0 comments on commit f62c839

Please sign in to comment.