OpenWrt Forum Archive

Topic: IP Virtual Server/Load Balancer ipvsadm and ipvs kernel modules

The content of this topic has been archived on 18 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

The latest release of DD-WRT now includes IP Virtual Server load balancer
This is quite a powerful package that turns the router into fully functional load balancer.

I would like to propose to include this also in OpenWRT.

Thank you.

Do you have the link for the package source?

IP Virtual Server requires kernel modules and ipvsadm tool

ipvsadm tool latest release is 1.26 and can be retrieved here:
http://www.linuxvirtualserver.org/software/ipvs.html

I modified package/kernel/linux/modules/netfilter.mk to include the kernel modules as follows and I have the kernel modules installed:

This is for "trunk":

IPVS_MODULES:= \
    ipvs/ip_vs \
    ipvs/ip_vs_wlc

define KernelPackage/ipvs
  SUBMENU:=Netfilter Extensions
  TITLE:=IP Virtual Server modules
  DEPENDS:=+kmod-lib-crc32c
  KCONFIG:= \
    CONFIG_IP_VS \
    CONFIG_IP_VS_IPV6=y \
    CONFIG_IP_VS_DEBUG=n \
    CONFIG_IP_VS_PROTO_TCP=y \
    CONFIG_IP_VS_PROTO_UDP=y \
    CONFIG_IP_VS_PROTO_AH_ESP=y \
    CONFIG_IP_VS_PROTO_ESP=y \
    CONFIG_IP_VS_PROTO_AH=y \
    CONFIG_IP_VS_PROTO_SCTP=y \
    CONFIG_IP_VS_TAB_BITS=12 \
    CONFIG_IP_VS_RR \
    CONFIG_IP_VS_WRR \
    CONFIG_IP_VS_LC \
    CONFIG_IP_VS_WLC \
    CONFIG_IP_VS_FO \
    CONFIG_IP_VS_OVF \
    CONFIG_IP_VS_LBLC \
    CONFIG_IP_VS_LBLCR \
    CONFIG_IP_VS_DH \
    CONFIG_IP_VS_SH \
    CONFIG_IP_VS_SED \
    CONFIG_IP_VS_NQ \
    CONFIG_IP_VS_SH_TAB_BITS=8 \
    CONFIG_IP_VS_NFCT=n \
    CONFIG_NETFILTER_XT_MATCH_IPVS=n

  FILES:=$(foreach mod,$(IPVS_MODULES),$(LINUX_DIR)/net/netfilter/$(mod).ko)
  AUTOLOAD:=$(call AutoLoad,70,$(notdir $(IPVS_MODULES)))
  $(call AddDepends/ipt,+kmod-ipt-conntrack)
endef
$(eval $(call KernelPackage,ipvs))

And this is for 15.05 release:

IPVS_MODULES:= \
    ipvs/ip_vs \
    ipvs/ip_vs_wlc

define KernelPackage/ipvs
  SUBMENU:=Netfilter Extensions
  TITLE:=IP Virtual Server modules
  DEPENDS:=+kmod-ipv6 +kmod-lib-crc32c
  KCONFIG:= \
    CONFIG_IP_VS \
    CONFIG_IP_VS_IPV6=y \
    CONFIG_IP_VS_DEBUG=n \
    CONFIG_IP_VS_TAB_BITS=12 \
    CONFIG_IP_VS_PROTO_TCP=y \
    CONFIG_IP_VS_PROTO_UDP=y \
    CONFIG_IP_VS_PROTO_AH_ESP=y \
    CONFIG_IP_VS_PROTO_ESP=y \
    CONFIG_IP_VS_PROTO_AH=y \
    CONFIG_IP_VS_PROTO_SCTP=y \
    CONFIG_IP_VS_RR \
    CONFIG_IP_VS_WRR \
    CONFIG_IP_VS_LC \
    CONFIG_IP_VS_WLC \
    CONFIG_IP_VS_FO \
    CONFIG_IP_VS_LBLC \
    CONFIG_IP_VS_LBLCR \
    CONFIG_IP_VS_DH \
    CONFIG_IP_VS_SH \
    CONFIG_IP_VS_SED \
    CONFIG_IP_VS_NQ \
    CONFIG_IP_VS_SH_TAB_BITS=8 \
    CONFIG_IP_VS_FTP=m \
    CONFIG_IP_VS_NFCT=n \
    CONFIG_NETFILTER_XT_MATCH_IPVS=n

  FILES:=$(foreach mod,$(IPVS_MODULES),$(LINUX_DIR)/net/netfilter/$(mod).ko)
  AUTOLOAD:=$(call AutoLoad,70,$(notdir $(IPVS_MODULES)))
  $(call AddDepends/ipt,+kmod-ipt-conntrack)
endef
$(eval $(call KernelPackage,ipvs))

In both the above cases I compiled and created the images successfully. The modules load into the kernel.

(Last edited by haydude on 22 Jan 2016, 16:32)

I have hadded also the ipvsadm package definition below, but it fails to compile because it cannot include netlink/netlink.h
I declared the libnl and libpopt as dependencies. I am a newbie, how do I tell the system where to find both netlink and popt includes and later, the objects to link? The build system appears to ignore TARGET_CFLAGS and TARGET_LDFLAGS in the Makefile below.

make[5]: Entering directory `/net2/router/openwrt/cc-15.05/build_dir/target-mips_34kc+dsp_uClibc-0.9.33.2/ipvsadm-1.26/libipvs'
mips-openwrt-linux-uclibc-gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o libipvs.o libipvs.c
cc1: note: someone does not honour COPTS correctly, passed 0 times
In file included from libipvs.h:13:0,
                 from libipvs.c:23:
ip_vs.h:15:29: fatal error: netlink/netlink.h: No such file or directory
#include <netlink/netlink.h>
                             ^
compilation terminated.
make[5]: *** [libipvs.o] Error 1

include $(TOPDIR)/rules.mk

PKG_NAME:=ipvsadm
PKG_VERSION:=1.26

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.linuxvirtualserver.org/software/kernel-2.6/
PKG_MD5SUM:=eac3ba3f62cd4dea2da353aeddd353a8

include $(INCLUDE_DIR)/package.mk

define Package/ipvsadm
  SECTION:=net
  CATEGORY:=Network
  TITLE:=IP Virtual Server Configuration Manager
  URL:=http://www.linuxvirtualserver.org
  DEPENDS:= +kmod-ipvs +libnl +libpopt
endef

TARGET_CFLAGS += \
    -I$(STAGING_DIR)/usr/include/libnl -fhonour-copts

TARGET_LDFLAGS += -lpopt

define Build/Configure
  $(call Build/Configure/Default)
endef

define Package/ipvsadm/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,ipvsadm))

(Last edited by haydude on 22 Jan 2016, 16:37)

Please use [ code ] [ /code ] block to just post the difference.

mazilo wrote:

Please use [ code ] [ /code ] block to just post the difference.

Thanks, I updated my previous messages.

I am banging my head against a failed compilation because the build cannot include netlink.h.

Please could anyone help?

Finally I completed my first working build against cc-15.05
I had to patch the original Makefile to take the CFLAGS passed by openwrt build.

Here is the Makefile that I saved in packages/network/utils/ipvsadm

include $(TOPDIR)/rules.mk

PKG_NAME:=ipvsadm
PKG_VERSION:=1.26

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.linuxvirtualserver.org/software/kernel-2.6/
PKG_MD5SUM:=eac3ba3f62cd4dea2da353aeddd353a8

include $(INCLUDE_DIR)/package.mk

define Package/ipvsadm
  SECTION:=net
  CATEGORY:=Network
  TITLE:=IP Virtual Server Configuration Manager
  URL:=http://www.linuxvirtualserver.org
  DEPENDS:= +kmod-ipvs +libnl +libpopt
endef

TARGET_CFLAGS += \
    -I$(STAGING_DIR)/usr/include/libnl -fPIC

MAKE_FLAGS += \
    CFLAGS="$(TARGET_CFLAGS)" \
    LIBS="-lpopt" 

define Build/Configure
  $(call Build/Configure/Default)
endef

define Package/ipvsadm/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-save $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-restore $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,ipvsadm))

And the patch file 001-Makefile.patch that goes into "patches":

diff -Naur ipvsadm-1.26/ipvsadm.spec ipvsadm-1.26.wrt/ipvsadm.spec
--- ipvsadm-1.26/ipvsadm.spec    2011-02-08 00:25:36.000000000 +0000
+++ ipvsadm-1.26.wrt/ipvsadm.spec    1970-01-01 01:00:00.000000000 +0100
@@ -1,100 +0,0 @@
-%define prefix   /usr
-
-Summary: Utility to administer the Linux Virtual Server
-Name: ipvsadm
-Version: 1.26
-Release: 1
-License: GPL
-URL: http://www.LinuxVirtualServer.org/
-Group: Applications/System
-Source0: http://www.LinuxVirtualServer.org/software/ipvsadm-%{version}.tar.gz
-BuildRoot: /var/tmp/%name-%{PACKAGE_VERSION}-root
-Provides: %{name}-%{version}
-Conflicts: piranha <= 0.4.14
-
-%description
-ipvsadm is a utility to administer the IP Virtual Server services
-offered by the latest Linux kernel 2.6.x.
-
-
-%prep
-%setup -n %{name}-%{version}
-
-
-%build
-CFLAGS="${RPM_OPT_FLAGS}" make
-
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p ${RPM_BUILD_ROOT}/{sbin,%{_mandir}/man8,etc/rc.d/init.d}
-make install BUILD_ROOT=${RPM_BUILD_ROOT} MANDIR=%{_mandir}
-
-
-%files
-%defattr(-,root,root)
-%doc README
-%config /etc/rc.d/init.d/ipvsadm
-/sbin/ipvsadm*
-%{_mandir}/man8/ipvsadm*
-
-%post
-/sbin/chkconfig --add ipvsadm
-
-%preun
-/sbin/chkconfig --del ipvsadm
-
-
-%clean
-rm -rf $RPM_BUILD_DIR/%{name}
-rm -rf $RPM_BUILD_ROOT
-
-
-%changelog
-* Thu Jun 23 2005 Steve Nielsen <snielsen@comscore.com>
-- Respect rpmmacros that might be set (by using rpm --eval)
-
-* Sat Dec 20 2003 Wensong Zhang <wensong@linux-vs.org>
-- tidy up the description
-
-* Sat Apr  5 2003 Wensong Zhang <wensong@linux-vs.org>
-- Removed the unnecessary Docdir setting.
-
-* Thu Dec 16 2001 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Changed to install ipvsadm man pages according to the %{_mandir}
-
-* Thu Dec 30 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- update the %file section
-
-* Thu Dec 17 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Added a if-condition to keep both new or old rpm utility building
-  the package happily.
-
-* Tue Dec 12 2000 P.Copeland <bryce@redhat.com>
-- Small modifications to make the compiler happy in RH7 and the Alpha
-- Fixed the documentation file that got missed off in building
-  the rpm
-- Made a number of -pedantic mods though popt will not compile with
-  -pedantic
-
-* Wed Aug 9 2000 Horms <horms@vergenet.net>
-- Removed Obseletes tag as ipvsadm is back in /sbin where it belongs 
-  as it is more or less analogous to both route and ipchains both of
-  which reside in /sbin.
-- Create directory to install init script into. Init scripts won't install
-  into build directory unless this is done
-
-* Thu Jul  6 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Changed to build rpms on the ipvsadm tar ball directly
-
-* Wed Jun 21 2000 P.Copeland <copeland@redhat.com>
-- fixed silly install permission settings
-
-* Mon Jun 19 2000 P.Copeland <copeland@redhat.com>
-- Added 'dist' and 'rpms' to the Makefile
-- Added Obsoletes tag since there were early versions
-  of ipvsadm-*.rpm that installed in /sbin
-- Obsolete tag was a bit vicious re: piranha
-
-* Mon Apr 10 2000 Horms <horms@vergenet.net>
-- created for version 1.9
diff -Naur ipvsadm-1.26/Makefile ipvsadm-1.26.wrt/Makefile
--- ipvsadm-1.26/Makefile    2011-02-08 00:24:23.000000000 +0000
+++ ipvsadm-1.26.wrt/Makefile    2016-01-22 16:16:46.801814154 +0000
@@ -46,9 +46,9 @@
 STATIC_LIBS    = libipvs/libipvs.a
 
 ifeq "${ARCH}" "sparc64"
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
 else
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g
 endif
 
 
@@ -84,7 +84,7 @@
 LIBS        += -lnl
 endif
 DEFINES        = -DVERSION=\"$(VERSION)\" -DSCHEDULERS=\"$(SCHEDULERS)\" \
-          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE)
+          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE) 
 DEFINES        += $(shell if [ ! -f ../ip_vs.h ]; then    \
              echo "-DHAVE_NET_IP_VS_H"; fi;)
 

Please refer to the project page for IP Virtual Server documentation: http://www.linuxvirtualserver.org/
Enjoy your new OpenWRT Load Balancer!

(Last edited by haydude on 22 Jan 2016, 18:09)

Nice job.

Just one question about your ipvsadm-1.26/Makefile patched file. Why do you need the 2nd hunk and I quoted below. It does not seem to make any changes, AFAICT.

diff -Naur ipvsadm-1.26/Makefile ipvsadm-1.26.wrt/Makefile
--- ipvsadm-1.26/Makefile    2011-02-08 00:24:23.000000000 +0000
+++ ipvsadm-1.26.wrt/Makefile    2016-01-22 16:16:46.801814154 +0000
@@ -84,7 +84,7 @@
 LIBS        += -lnl
 endif
 DEFINES        = -DVERSION=\"$(VERSION)\" -DSCHEDULERS=\"$(SCHEDULERS)\" \
-          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE)
+          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE) 
 DEFINES        += $(shell if [ ! -f ../ip_vs.h ]; then    \
              echo "-DHAVE_NET_IP_VS_H"; fi;)
 
mazilo wrote:

Nice job.

Just one question about your ipvsadm-1.26/Makefile patched file. Why do you need the 2nd hunk and I quoted below. It does not seem to make any changes, AFAICT.

diff -Naur ipvsadm-1.26/Makefile ipvsadm-1.26.wrt/Makefile
--- ipvsadm-1.26/Makefile    2011-02-08 00:24:23.000000000 +0000
+++ ipvsadm-1.26.wrt/Makefile    2016-01-22 16:16:46.801814154 +0000
@@ -84,7 +84,7 @@
 LIBS        += -lnl
 endif
 DEFINES        = -DVERSION=\"$(VERSION)\" -DSCHEDULERS=\"$(SCHEDULERS)\" \
-          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE)
+          -DPE_LIST=\"$(PE_LIST)\" $(POPT_DEFINE) 
 DEFINES        += $(shell if [ ! -f ../ip_vs.h ]; then    \
              echo "-DHAVE_NET_IP_VS_H"; fi;)
 

Good question! 

I am not sure why diff picked that up, perhaps whilst editing a tab turned into spaces or vice-versa?
The bottom line is that it isn't necessary, nevertheless it does not do any arm.

I modified your OpenWRT Makefile for the package with the following tweaks.

  1. I find the ONLY dependency is libopt, i.e. DEPENDS:=+libpopt.

  2. I included this PKG_INSTALL:=1 recipe in your OpenWRT Makefile for the package so that the OpenWRT buildroot will automatically make use of the built-in install: recipe to install the package during the compilation process. If you take this route, you may need to either change this variable to DESTDIR in the original Makefile through a patch or add to specify the BUILD_ROOT="$(DESTDIR)" variable in MAKE_FLAGS recipe. Unfortunately, I can't make it to work with the later.

  3. I replaced the Configure with Compile recipe in your OpenWRT Makefile for the package mainly because the ipvsadm source package does not. use any GNU autotools.

  4. The included /etc/rc.d/init.d/ipvsadm file, not only is installed in the wrong location (should be installed in /etc/init.d/ipvsadm), but also probably won't work with OpenWRT (I haven't tested this, yet).

  5. I noticed the ONLY needed patch is shown below. In other words, the patch for the ipvsadm.spec file has nothing to do with the compilation, but rather is an RPM spec file which OpenWRT buildroot never uses it, AFAICT. OTOH, you don't even need any patches you specified above mainly because you already included the correct CFLAGS recipe in your OpenWRT Makefile for the package. Speaking on the CFLAGS recipe you added in the MAKE_FLAGS recipe in your OpenWRT Makefile for the package, please take a look at the OpenWRT <OpenWRT root directory>/include/package-defaults.mk file where it clearly shows the MAKE_VARS recipe is reserved for including a CFLAGS recipe. So, I would presume the recipe MAKE_FLAGS on your OpenWRT Makefile for the package should be replaced with MAKE_VARS. However, if I do this, the new CFLAGS will never get passed to the original Makefile and I don't know why. I hope someone can chime in.

diff -Naur a/Makefile b/Makefile
--- a/Makefile    2011-02-08 00:24:23.000000000 +0000
+++ b/Makefile    2016-01-22 16:16:46.801814154 +0000
@@ -46,9 +46,9 @@
 STATIC_LIBS    = libipvs/libipvs.a
 
 ifeq "${ARCH}" "sparc64"
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
 else
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g
 endif

Thank you for your message. I started only less than a week ago to look into OpenWRT development, out of a necessity, but I am amazed how easy it was to hack into it.

My process was mostly trial and error copying and adapting existing Makefiles from other packages, and without fully understanding what I was doing so I will tresure your message above. The on-line documentation seems to make lots of assumptions, so it isn't so good for newbies.

Please could you post here your modified Makefile? Has the new package made it into the mainstream in git?

I agree the ipvsadm startup in /etc/init.d should not be copied. It would be up to the user at this stage to write his own configuration and startup scripts.

The only files really necessary are ipvsadm, ipvsadm-save, ipvsadm-restore.

(Last edited by haydude on 23 Jan 2016, 21:35)

haydude wrote:

Please could you post here your modified Makefile? Has the new package made it into the mainstream in git?

I have included my version of OpenWRT Makefile for the package (based on yours).

include $(TOPDIR)/rules.mk

PKG_NAME:=ipvsadm
PKG_VERSION:=1.26

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.linuxvirtualserver.org/software/kernel-2.6/
PKG_MD5SUM:=eac3ba3f62cd4dea2da353aeddd353a8

PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

ifeq ($(CONFIG_DEVEL),y)
    export QUILT=1
endif

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=net
  CATEGORY:=Network
  TITLE:=IP Virtual Server Configuration Manager
  URL:=http://www.linuxvirtualserver.org
  DEPENDS:= +libpopt
endef

MAKE_FLAGS += \
    CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
    CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CXX)" \
    CFLAGS="$(TARGET_CFLAGS)" \
    LIBS="-lpopt" 

define Build/Compile
    $(call Build/Compile/Default)
endef

define Package/$(PKG_NAME)/install
    $(INSTALL_DIR) $(1)/{etc,usr}/
    $(CP) $(PKG_INSTALL_DIR)/. $(1)/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

The above will package all installed files.

Here is the patch file.

--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@
 #                     :   the Makefile
 #      Horms          :   Updated to add config_stream.c dynamic_array.c
 #                     :   Added autodetection of libpot
-#                     :   Added BUILD_ROOT support
+#                     :   Added DESTDIR support
 #      Wensong        :   Changed the OBJS according to detection
 #      Ratz           :   Fixed to use the correct CFLAGS on sparc64
 #
@@ -37,10 +37,10 @@ RPMSPECDIR    = $(shell rpm --eval '%_specd
 
 CC        = gcc
 INCLUDE        =
-SBIN        = $(BUILD_ROOT)/sbin
+SBIN        = $(DESTDIR)/usr/sbin
 MANDIR        = usr/man
-MAN        = $(BUILD_ROOT)/$(MANDIR)/man8
-INIT        = $(BUILD_ROOT)/etc/rc.d/init.d
+MAN        = $(DESTDIR)/$(MANDIR)/man8
+INIT        = $(DESTDIR)/etc/init.d
 MKDIR        = mkdir
 INSTALL        = install
 STATIC_LIBS    = libipvs/libipvs.a

BTW, you can request to maintain this package.

(Last edited by mazilo on 23 Jan 2016, 22:06)

Please find below the updated Makefile and patches for ipvsadm. The previous version did not pick up libnl and thus the executable could not interpret correctly IPV4 and IPV6 addresses.

This version is amended to use libnl-tiny instead of libnl. It is tested and working on Chaos Chalmer v15.05

This version does not build on the current "trunk" apparently because of some differences in libnl-tiny.

Makefile:

#
# PACKAGE: ipvsadm
# DESCRIPTION: Utility to administer the Linux Virtual Server
#
include $(TOPDIR)/rules.mk

PKG_NAME:=ipvsadm
PKG_VERSION:=1.26

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.linuxvirtualserver.org/software/kernel-2.6/
PKG_MD5SUM:=eac3ba3f62cd4dea2da353aeddd353a8

PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

ifeq ($(CONFIG_DEVEL),y)
    export QUILT=1
endif

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=net
  CATEGORY:=Network
  TITLE:=IP Virtual Server Configuration Manager
  URL:=http://www.linuxvirtualserver.org
  DEPENDS:= +kmod-ipvs +libnl-tiny +libpopt
endef

#    -I$(STAGING_DIR)/usr/include/libnl/linux -fPIC -DLIBIPVS_USE_NL
TARGET_CFLAGS += \
    -I$(STAGING_DIR)/usr/include/libnl-tiny -fPIC -DLIBIPVS_USE_NL

MAKE_FLAGS += \
    CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
    CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CXX)" \
    CFLAGS="$(TARGET_CFLAGS)" \
    LIBS="-lnl-tiny -lpopt"

define Build/Compile
    $(call Build/Compile/Default)
endef

define Package/ipvsadm/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-save $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-restore $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

Patch file: patches/001-ipvsadm.patch

diff -Naur ipvsadm-1.26/ipvsadm.spec ipvsadm-1.26.owrt/ipvsadm.spec
--- ipvsadm-1.26/ipvsadm.spec    2011-02-08 00:25:36.000000000 +0000
+++ ipvsadm-1.26.owrt/ipvsadm.spec    1970-01-01 01:00:00.000000000 +0100
@@ -1,100 +0,0 @@
-%define prefix   /usr
-
-Summary: Utility to administer the Linux Virtual Server
-Name: ipvsadm
-Version: 1.26
-Release: 1
-License: GPL
-URL: http://www.LinuxVirtualServer.org/
-Group: Applications/System
-Source0: http://www.LinuxVirtualServer.org/software/ipvsadm-%{version}.tar.gz
-BuildRoot: /var/tmp/%name-%{PACKAGE_VERSION}-root
-Provides: %{name}-%{version}
-Conflicts: piranha <= 0.4.14
-
-%description
-ipvsadm is a utility to administer the IP Virtual Server services
-offered by the latest Linux kernel 2.6.x.
-
-
-%prep
-%setup -n %{name}-%{version}
-
-
-%build
-CFLAGS="${RPM_OPT_FLAGS}" make
-
-
-%install
-rm -rf $RPM_BUILD_ROOT
-mkdir -p ${RPM_BUILD_ROOT}/{sbin,%{_mandir}/man8,etc/rc.d/init.d}
-make install BUILD_ROOT=${RPM_BUILD_ROOT} MANDIR=%{_mandir}
-
-
-%files
-%defattr(-,root,root)
-%doc README
-%config /etc/rc.d/init.d/ipvsadm
-/sbin/ipvsadm*
-%{_mandir}/man8/ipvsadm*
-
-%post
-/sbin/chkconfig --add ipvsadm
-
-%preun
-/sbin/chkconfig --del ipvsadm
-
-
-%clean
-rm -rf $RPM_BUILD_DIR/%{name}
-rm -rf $RPM_BUILD_ROOT
-
-
-%changelog
-* Thu Jun 23 2005 Steve Nielsen <snielsen@comscore.com>
-- Respect rpmmacros that might be set (by using rpm --eval)
-
-* Sat Dec 20 2003 Wensong Zhang <wensong@linux-vs.org>
-- tidy up the description
-
-* Sat Apr  5 2003 Wensong Zhang <wensong@linux-vs.org>
-- Removed the unnecessary Docdir setting.
-
-* Thu Dec 16 2001 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Changed to install ipvsadm man pages according to the %{_mandir}
-
-* Thu Dec 30 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- update the %file section
-
-* Thu Dec 17 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Added a if-condition to keep both new or old rpm utility building
-  the package happily.
-
-* Tue Dec 12 2000 P.Copeland <bryce@redhat.com>
-- Small modifications to make the compiler happy in RH7 and the Alpha
-- Fixed the documentation file that got missed off in building
-  the rpm
-- Made a number of -pedantic mods though popt will not compile with
-  -pedantic
-
-* Wed Aug 9 2000 Horms <horms@vergenet.net>
-- Removed Obseletes tag as ipvsadm is back in /sbin where it belongs 
-  as it is more or less analogous to both route and ipchains both of
-  which reside in /sbin.
-- Create directory to install init script into. Init scripts won't install
-  into build directory unless this is done
-
-* Thu Jul  6 2000 Wensong Zhang <wensong@linuxvirtualserver.org>
-- Changed to build rpms on the ipvsadm tar ball directly
-
-* Wed Jun 21 2000 P.Copeland <copeland@redhat.com>
-- fixed silly install permission settings
-
-* Mon Jun 19 2000 P.Copeland <copeland@redhat.com>
-- Added 'dist' and 'rpms' to the Makefile
-- Added Obsoletes tag since there were early versions
-  of ipvsadm-*.rpm that installed in /sbin
-- Obsolete tag was a bit vicious re: piranha
-
-* Mon Apr 10 2000 Horms <horms@vergenet.net>
-- created for version 1.9
diff -Naur ipvsadm-1.26/libipvs/ip_vs.h ipvsadm-1.26.owrt/libipvs/ip_vs.h
--- ipvsadm-1.26/libipvs/ip_vs.h    2011-02-07 02:38:57.000000000 +0000
+++ ipvsadm-1.26.owrt/libipvs/ip_vs.h    2016-01-24 19:59:27.304631247 +0000
@@ -10,6 +10,7 @@
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <linux/types.h>    /* For __beXX types in userland */
+#include <sys/types.h>
 
 #ifdef LIBIPVS_USE_NL
 #include <netlink/netlink.h>
diff -Naur ipvsadm-1.26/libipvs/libipvs.c ipvsadm-1.26.owrt/libipvs/libipvs.c
--- ipvsadm-1.26/libipvs/libipvs.c    2011-02-07 02:38:57.000000000 +0000
+++ ipvsadm-1.26.owrt/libipvs/libipvs.c    2016-01-24 20:02:49.840430677 +0000
@@ -32,7 +32,7 @@
 struct ip_vs_getinfo ipvs_info;
 
 #ifdef LIBIPVS_USE_NL
-static struct nl_handle *sock = NULL;
+static struct nl_sock *sock = NULL;
 static int family, try_nl = 1;
 #endif
 
@@ -73,7 +73,7 @@
 {
     int err = EINVAL;
 
-    sock = nl_handle_alloc();
+    sock = nl_socket_alloc();
     if (!sock) {
         nlmsg_free(msg);
         return -1;
@@ -88,7 +88,7 @@
 
     /* To test connections and set the family */
     if (msg == NULL) {
-        nl_handle_destroy(sock);
+        nl_socket_free(sock);
         sock = NULL;
         return 0;
     }
@@ -104,12 +104,12 @@
 
     nlmsg_free(msg);
 
-    nl_handle_destroy(sock);
+    nl_socket_free(sock);
 
     return 0;
 
 fail_genl:
-    nl_handle_destroy(sock);
+    nl_socket_free(sock);
     sock = NULL;
     nlmsg_free(msg);
     errno = err;
diff -Naur ipvsadm-1.26/Makefile ipvsadm-1.26.owrt/Makefile
--- ipvsadm-1.26/Makefile    2011-02-08 00:24:23.000000000 +0000
+++ ipvsadm-1.26.owrt/Makefile    2016-01-24 12:40:39.427307725 +0000
@@ -37,18 +37,17 @@
 
 CC        = gcc
 INCLUDE        =
-SBIN        = $(BUILD_ROOT)/sbin
+SBIN        = $(DESTDIR)/usr/sbin
 MANDIR        = usr/man
-MAN        = $(BUILD_ROOT)/$(MANDIR)/man8
-INIT        = $(BUILD_ROOT)/etc/rc.d/init.d
+INIT        = $(DESTDIR)/etc/rc.d/init.d
 MKDIR        = mkdir
 INSTALL        = install
 STATIC_LIBS    = libipvs/libipvs.a
 
 ifeq "${ARCH}" "sparc64"
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g -m64 -pipe -mcpu=ultrasparc -mcmodel=medlow
 else
-    CFLAGS = -Wall -Wunused -Wstrict-prototypes -g
+    CFLAGS += -Wall -Wunused -Wstrict-prototypes -g
 endif
 
 
@@ -104,12 +103,6 @@
         $(INSTALL) -m 0755 ipvsadm $(SBIN)
         $(INSTALL) -m 0755 ipvsadm-save $(SBIN)
         $(INSTALL) -m 0755 ipvsadm-restore $(SBIN)
-        [ -d $(MAN) ] || $(MKDIR) -p $(MAN)
-        $(INSTALL) -m 0644 ipvsadm.8 $(MAN)
-        $(INSTALL) -m 0644 ipvsadm-save.8 $(MAN)
-        $(INSTALL) -m 0644 ipvsadm-restore.8 $(MAN)
-        [ -d $(INIT) ] || $(MKDIR) -p $(INIT)
-        $(INSTALL) -m 0755 ipvsadm.sh $(INIT)/ipvsadm
 
 clean:
         rm -f ipvsadm $(NAME).spec $(NAME)-$(VERSION).tar.gz

The above is saved into:

package/network/utils/ipvsadm

(Last edited by haydude on 25 Jan 2016, 01:23)

Here is the new Makefile for the ipvsadm package working both in CC 15.05 and trunk
Does anybody want to maintain this new component for IP Virtual Server?


It goes into package/network/utils/ipvsadm:

#
include $(TOPDIR)/rules.mk

PKG_NAME:=ipvsadm
PKG_VERSION:=1.26

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.linuxvirtualserver.org/software/kernel-2.6/
PKG_MD5SUM:=eac3ba3f62cd4dea2da353aeddd353a8

PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

ifeq ($(CONFIG_DEVEL),y)
    export QUILT=1
endif

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
  SECTION:=net
  CATEGORY:=Network
  TITLE:=IP Virtual Server Configuration Manager
  URL:=http://www.linuxvirtualserver.org
  DEPENDS:= +kmod-ipvs +libnl-tiny +libpopt
endef

#    -I$(STAGING_DIR)/usr/include/libnl/linux -fPIC -DLIBIPVS_USE_NL
TARGET_CFLAGS += \
    -I$(STAGING_DIR)/usr/include/libnl-tiny -fPIC -DLIBIPVS_USE_NL -D_GNU_SOURCE

MAKE_FLAGS += \
    CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)" \
    CXX="$(TOOLCHAIN_DIR)/bin/$(TARGET_CXX)" \
    CFLAGS="$(TARGET_CFLAGS)" \
    LIBS="-lnl-tiny -lpopt"

define Build/Compile
    $(call Build/Compile/Default)
endef

define Package/ipvsadm/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-save $(1)/usr/sbin/
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-restore $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

The discussion might have continued from here.