From 01f2b2e4e6b8f551cdd10551bce626801c2d9045 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 20 Aug 2017 12:03:13 +0000 Subject: [PATCH] Add new libnetwork This is going to be a central place to all things that needed to be implemented in C here. Signed-off-by: Michael Tremer --- .gitignore | 6 ++++ Makefile.am | 54 +++++++++++++++++++++++++---- configure.ac | 6 ++++ src/inetcalc.c | 9 ++++- src/libnetwork/libnetwork-private.h | 26 ++++++++++++++ src/libnetwork/libnetwork.c | 26 ++++++++++++++ src/libnetwork/libnetwork.sym | 6 ++++ src/libnetwork/network/libnetwork.h | 26 ++++++++++++++ src/network.pc.in | 5 +++ 9 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 src/libnetwork/libnetwork-private.h create mode 100644 src/libnetwork/libnetwork.c create mode 100644 src/libnetwork/libnetwork.sym create mode 100644 src/libnetwork/network/libnetwork.h diff --git a/.gitignore b/.gitignore index ad5e18f0..47952730 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ /Makefile /build-aux +/config.* +/libtool /missing /src/functions/functions /src/inetcalc +/src/libnetwork/libnetwork.pc /src/network.pc /src/ppp/ip-updown /src/systemd/*.service @@ -12,12 +15,15 @@ /*.tar.xz *.log *.cache +*.la +*.lo *.o *.stamp *.trs *~ .deps .dirstamp +.libs Makefile.in aclocal.m4 config.status diff --git a/Makefile.am b/Makefile.am index c18c460a..40026aa6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,7 @@ AUTOMAKE_OPTIONS = color-tests bashcompletiondir= $(datadir)/bash-completion/completions libexecdir = $(prefix)/lib -pkgconfigdatadir = $(datadir)/pkgconfig +pkgconfigdir = $(libdir)/pkgconfig pppdir = $(sysconfdir)/ppp systemconfigdir = $(datadir)/network sysctldir = $(prefix)/lib/sysctl.d @@ -59,9 +59,21 @@ INSTALL_EXEC_HOOKS = UNINSTALL_EXEC_HOOKS = noinst_DATA = -AM_CFLAGS = $(OUR_CFLAGS) -AM_CPPFLAGS = $(OUR_CPPFLAGS) -AM_LDFLAGS = $(OUR_LDFLAGS) +AM_CPPFLAGS = \ + $(OUR_CPPFLAGS) \ + -include $(top_builddir)/config.h \ + -I${top_srcdir}/src/libnetwork + +AM_CFLAGS = \ + $(OUR_CFLAGS) \ + -fvisibility=hidden \ + -ffunction-sections \ + -fdata-sections + +AM_LDFLAGS = \ + $(OUR_LDFLAGS) \ + -Wl,--gc-sections \ + -Wl,--as-needed DISTCHECK_CONFIGURE_FLAGS = \ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) \ @@ -190,6 +202,9 @@ bin_PROGRAMS = \ src_inetcalc_SOURCES = \ src/inetcalc.c +src_inetcalc_LDADD = \ + src/libnetwork.la + dist_hooks_configs_SCRIPTS = \ src/hooks/configs/dhcp \ src/hooks/configs/ipv4-static \ @@ -214,6 +229,33 @@ dist_hooks_zones_SCRIPTS = \ # ------------------------------------------------------------------------------ +LIBNETWORK_CURRENT=0 +LIBNETWORK_REVISION=0 +LIBNETWORK_AGE=0 + +pkginclude_HEADERS = \ + src/libnetwork/network/libnetwork.h + +lib_LTLIBRARIES = \ + src/libnetwork.la + +src_libnetwork_la_SOURCES = \ + src/libnetwork/libnetwork-private.h \ + src/libnetwork/libnetwork.c + +src_libnetwork_la_LDFLAGS = \ + $(AM_LDFLAGS) \ + -version-info $(LIBNETWORK_CURRENT):$(LIBNETWORK_REVISION):$(LIBNETWORK_AGE) \ + -Wl,--version-script=$(top_srcdir)/src/libnetwork/libnetwork.sym + +src_libnetwork_la_DEPENDENCIES = \ + src/libnetwork/libnetwork.sym + +EXTRA_DIST += \ + src/libnetwork/libnetwork.sym + +# ------------------------------------------------------------------------------ + ppp_SCRIPTS = \ src/ppp/ip-updown @@ -309,11 +351,11 @@ endif # ------------------------------------------------------------------------------ -pkgconfigdata_DATA = \ +pkgconfig_DATA = \ src/network.pc CLEANFILES += \ - $(pkgconfigdata_DATA) + $(pkgconfig_DATA) EXTRA_DIST += \ src/network.pc.in diff --git a/configure.ac b/configure.ac index df6d6499..b2c06d0f 100644 --- a/configure.ac +++ b/configure.ac @@ -41,6 +41,11 @@ AM_INIT_AUTOMAKE([ ]) AM_SILENT_RULES([yes]) +LT_INIT([ + disable-static + pic-only +]) + AC_PROG_LN_S AC_PROG_MKDIR_P AC_PROG_SED @@ -103,6 +108,7 @@ AC_SUBST([udevdir], [$with_udevdir]) AM_CONDITIONAL(HAVE_UDEV, [test -n "$with_udevdir"]) # ------------------------------------------------------------------------------ +AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES([ Makefile ]) diff --git a/src/inetcalc.c b/src/inetcalc.c index da3444e0..1841c840 100644 --- a/src/inetcalc.c +++ b/src/inetcalc.c @@ -28,6 +28,8 @@ #include #include +#include + typedef struct ip_address { int family; struct in6_addr addr; @@ -513,7 +515,7 @@ int main(int argc, char** argv) { int family = AF_UNSPEC; while (1) { - int c = getopt_long(argc, argv, "46bcefgnpsv", long_options, &option_index); + int c = getopt_long(argc, argv, "46bcefgnpsviV", long_options, &option_index); if (c == -1) break; @@ -580,6 +582,11 @@ int main(int argc, char** argv) { verbose = 1; break; + case 'V': + printf("%s\n", network_version()); + exit(0); + break; + case '?': break; diff --git a/src/libnetwork/libnetwork-private.h b/src/libnetwork/libnetwork-private.h new file mode 100644 index 00000000..d94f3956 --- /dev/null +++ b/src/libnetwork/libnetwork-private.h @@ -0,0 +1,26 @@ +/*############################################################################# +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2017 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU 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 . # +# # +#############################################################################*/ + +#ifndef LIBNETWORK_PRIVATE_H +#define LIBNETWORK_PRIVATE_H + +#define NETWORK_EXPORT __attribute__ ((visibility("default"))) + +#endif diff --git a/src/libnetwork/libnetwork.c b/src/libnetwork/libnetwork.c new file mode 100644 index 00000000..629a6b19 --- /dev/null +++ b/src/libnetwork/libnetwork.c @@ -0,0 +1,26 @@ +/*############################################################################# +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2017 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU 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 +#include "libnetwork-private.h" + +NETWORK_EXPORT const char* network_version() { + return "network " VERSION; +} diff --git a/src/libnetwork/libnetwork.sym b/src/libnetwork/libnetwork.sym new file mode 100644 index 00000000..5a5a464a --- /dev/null +++ b/src/libnetwork/libnetwork.sym @@ -0,0 +1,6 @@ +LIBNETWORK_0 { +global: + network_version; +local: + *; +}; diff --git a/src/libnetwork/network/libnetwork.h b/src/libnetwork/network/libnetwork.h new file mode 100644 index 00000000..615a6289 --- /dev/null +++ b/src/libnetwork/network/libnetwork.h @@ -0,0 +1,26 @@ +/*############################################################################# +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2017 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU 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 . # +# # +#############################################################################*/ + +#ifndef LIBNETWORK_H +#define LIBNETWORK_H + +const char* network_version(); + +#endif diff --git a/src/network.pc.in b/src/network.pc.in index fd3af833..8df548cc 100644 --- a/src/network.pc.in +++ b/src/network.pc.in @@ -20,9 +20,14 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ +includedir=@includedir@ +libdir=@libdir@ networkdir=@networkdir@ Name: network Description: Network configuration tools for IPFire URL: @PACKAGE_URL@ Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lnetwork +Libs.private: +Cflags: -I${includedir} -- 2.39.2