Skip to content

Commit f62c839

Browse files
mobrembskiMichał Obrembski
authored andcommitted
Added Samba libreplace implementation for freeifaddrs and getifaddrs
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.
1 parent 42e9e8d commit f62c839

8 files changed

Lines changed: 969 additions & 15 deletions

File tree

.github/workflows/openfortivpn.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ jobs:
2121
run: sudo apt-get install -y astyle
2222

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

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

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

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

3535
build:
3636
name: Build

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \
88
src/xml.h src/userinput.c src/userinput.h \
99
src/openssl_hostname_validation.c \
1010
src/openssl_hostname_validation.h
11+
if LIBREPLACE_REQUIRED
12+
openfortivpn_SOURCES += src/ifaddrs.c
13+
endif
14+
openfortivpn_CFLAGS = -Wall -pedantic
1115
openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
1216
-DPPP_PATH=\"@PPP_PATH@\" \
1317
-DNETSTAT_PATH=\"@NETSTAT_PATH@\" \

configure.ac

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ AC_TYPE_UINT8_T
103103
AC_CHECK_TYPES([struct termios], [], [], [#include <termios.h>])
104104

105105
# Checks for library functions.
106-
AC_FUNC_MALLOC
107-
AC_FUNC_REALLOC
108106
AC_CHECK_FUNCS([ \
109107
access \
110108
atoi \
@@ -125,15 +123,13 @@ fputs \
125123
fread \
126124
free \
127125
freeaddrinfo \
128-
freeifaddrs \
129126
freopen \
130127
fwrite \
131128
gai_strerror \
132129
getaddrinfo \
133130
getchar \
134131
getenv \
135132
geteuid \
136-
getifaddrs \
137133
getopt_long \
138134
htons \
139135
index \
@@ -502,6 +498,44 @@ AC_ARG_WITH([resolvconf-config-file],
502498
AC_DEFINE_UNQUOTED([RESOLV_CONF_FILE_PATH],["$withval"])
503499
)
504500

501+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
502+
#include <sys/types.h>
503+
#if STDC_HEADERS
504+
#include <stdlib.h>
505+
#include <stddef.h>
506+
#endif
507+
#include <sys/socket.h>
508+
#include <netinet/in.h>
509+
#include <arpa/inet.h>
510+
#include <ifaddrs.h>
511+
#include <netdb.h>
512+
int main(int argc, char **argv){
513+
struct ifaddrs *ifp = NULL;
514+
int ret = getifaddrs (&ifp);
515+
freeifaddrs(ifp);
516+
}
517+
])], [
518+
libreplace_required=no
519+
AC_MSG_NOTICE([HAVE_IFADDRS... 1])
520+
],[
521+
libreplace_required=yes
522+
AC_MSG_NOTICE([HAVE_IFADDRS... 0])
523+
])
524+
525+
AC_ARG_ENABLE([libreplace],
526+
[AS_HELP_STRING([--enable-libreplace], [Force to use libreplace ifaddrs implementation])],
527+
[enable_libreplace=yes],
528+
[enable_libreplace=no])
529+
AS_CASE(["$enable_libreplace"],
530+
[yes], [
531+
AC_MSG_NOTICE([Force using libreplace...])
532+
],
533+
[no], [
534+
],
535+
[AC_MSG_ERROR([unknown option '$enable_libreplace' for --enable-libreplace])])
536+
AS_IF([test "x$enable_libreplace" != "xno" -o "x$libreplace_required" != "xno"], [AC_DEFINE([HAVE_IFADDRS],[0])], [AC_DEFINE([HAVE_IFADDRS],[1])])
537+
AM_CONDITIONAL([LIBREPLACE_REQUIRED], [test "x$enable_libreplace" = "xyes" -o "x$libreplace_required" = "xyes"])
538+
505539
# prepare to get rid of obsolete code (FortiOS 4)
506540
AC_ARG_ENABLE([obsolete],
507541
[AS_HELP_STRING([--disable-obsolete], [disable support for FortiOS 4])],,

0 commit comments

Comments
 (0)