[OpenWrt-Devel] [PATCH v2 1/2] ipvsadm

Mauro Mozzarelli mauro at ezplanet.net
Fri Mar 4 15:48:01 EST 2016


--------8<------------
This package contains:
- ipvsadm utility to configure IP VS tables, virtual and real servers

Dependencies:
- ipvs kernel modules configuration (patch previously posted)

Signed-off-by: Mauro Mozzarelli <mauro at ezplanet.net>
--------8<------------
diff --git a/package/network/utils/ipvsadm/Makefile b/package/network/utils/ipvsadm/Makefile
new file mode 100644
index 0000000..9856a75
--- /dev/null
+++ b/package/network/utils/ipvsadm/Makefile
@@ -0,0 +1,54 @@
+#
+# Copyright (C) 2016 OpenWrt, Mauro Mozzarelli
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# AUTHOR: Mauro Mozzarelli <mauro at ezplanet.net>
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ipvsadm
+PKG_VERSION:=1.26
+PKG_MAINTAINER:=Mauro Mozzarelli <mauro at ezplanet.net>
+PKG_LICENSE:=GPL-1.0
+PKG_RELEASE:=1
+
+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
+
+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
+
+define Package/$(PKG_NAME)/description
+  IPVS (IP Virtual Server) implements transport-layer load balancing inside the Linux kernel, so called Layer-4 switching.
+  ipvsadm is used to set up, maintain or inspect the virtual server table in the Linux kernel.
+  The Linux Virtual Server can be used to build scalable network services based on a cluster of two or more nodes.
+endef
+
+TARGET_CFLAGS += \
+	-I$(STAGING_DIR)/usr/include/libnl-tiny -fPIC -DLIBIPVS_USE_NL_3 -D_GNU_SOURCE
+
+MAKE_FLAGS += \
+	CFLAGS="$(TARGET_CFLAGS)" \
+	LIBS="-lnl-tiny -lpopt"
+
+define Package/$(PKG_NAME)/install
+	$(INSTALL_DIR) $(1)/sbin
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm $(1)/sbin/
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-save $(1)/sbin/
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/ipvsadm-restore $(1)/sbin/
+endef
+
+$(eval $(call BuildPackage,$(PKG_NAME)))
diff --git a/package/network/utils/ipvsadm/patches/001-ipvsadm-libnl3.patch
b/package/network/utils/ipvsadm/patches/001-ipvsadm-libnl3.patch
new file mode 100644
index 0000000..6c1c792
--- /dev/null
+++ b/package/network/utils/ipvsadm/patches/001-ipvsadm-libnl3.patch
@@ -0,0 +1,191 @@
+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-03-04 17:13:13.133483236 +0000
+@@ -6,10 +6,15 @@
+ #ifndef _IP_VS_H
+ #define _IP_VS_H
+
++#ifdef LIBIPVS_USE_NL_3
++#define LIBIPVS_USE_NL
++#endif
++
+ #include <netinet/in.h>
+ #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-03-04 17:13:23.336361387 +0000
+@@ -9,8 +9,19 @@
+  *              modify it under the terms of the GNU General Public License
+  *              as published by the Free Software Foundation; either version
+  *              2 of the License, or (at your option) any later version.
++ *
++ * Changelog:
++ *
++ * Mauro Mozzarelli <mauro at ezplanet.net>:
++ *              Added LIBIPVS_USE_NL_3 to add libnl3 style API support.
++ *              This allows also build and deployment in embedded systems
++ *              using libnl-tiny like OpenWrt
+  */
+
++#ifdef LIBIPVS_USE_NL_3
++#define LIBIPVS_USE_NL
++#endif
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+@@ -32,7 +43,11 @@
+ struct ip_vs_getinfo ipvs_info;
+
+ #ifdef LIBIPVS_USE_NL
++#ifdef LIBIPVS_USE_NL_3
++static struct nl_sock *sock = NULL;
++#else
+ static struct nl_handle *sock = NULL;
++#endif
+ static int family, try_nl = 1;
+ #endif
+
+@@ -73,7 +88,11 @@
+ {
+ 	int err = EINVAL;
+
++#ifdef LIBIPVS_USE_NL_3
++	sock = nl_socket_alloc();
++#else
+ 	sock = nl_handle_alloc();
++#endif
+ 	if (!sock) {
+ 		nlmsg_free(msg);
+ 		return -1;
+@@ -88,7 +107,11 @@
+
+ 	/* To test connections and set the family */
+ 	if (msg == NULL) {
++#ifdef LIBIPVS_USE_NL_3
++		nl_socket_free(sock);
++#else
+ 		nl_handle_destroy(sock);
++#endif
+ 		sock = NULL;
+ 		return 0;
+ 	}
+@@ -104,12 +127,20 @@
+
+ 	nlmsg_free(msg);
+
++#ifdef LIBIPVS_USE_NL_3
++	nl_socket_free(sock);
++#else
+ 	nl_handle_destroy(sock);
++#endif
+
+ 	return 0;
+
+ fail_genl:
++#ifdef LIBIPVS_USE_NL_3
++	nl_socket_free(sock);
++#else
+ 	nl_handle_destroy(sock);
++#endif
+ 	sock = NULL;
+ 	nlmsg_free(msg);
+ 	errno = err;
+diff -Naur ipvsadm-1.26/libipvs/Makefile ipvsadm-1.26.owrt/libipvs/Makefile
+--- ipvsadm-1.26/libipvs/Makefile	2008-09-21 11:02:03.000000000 +0100
++++ ipvsadm-1.26.owrt/libipvs/Makefile	2016-03-04 17:13:27.981305915 +0000
+@@ -1,9 +1,23 @@
+ # Makefile for libipvs
++#
++# Changelog:
++#
++# Mauro Mozzarelli <mauro at ezplanet.net>:
++#               Added support for libnl-3 and libnl-tiny
++#
+
+-CC		= gcc
+-CFLAGS		= -Wall -Wunused -Wstrict-prototypes -g -fPIC
++CC			= gcc
++CFLAGS		+= -Wall -Wunused -Wstrict-prototypes -g -fPIC
+ ifneq (0,$(HAVE_NL))
++ifneq (0,$(HAVE_NL_1))
+ CFLAGS		+= -DLIBIPVS_USE_NL
++ifeq (1,$(HAVE_NL_TINY))
++HAVE_NL_3	= 1
++endif
++ifeq (1,$(HAVE_NL_3))
++CFLAGS		+= -DLIBIPVS_USE_NL_3
++endif
++endif
+ endif
+
+ INCLUDE		+= $(shell if [ -f ../../ip_vs.h ]; then	\
+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-03-04 17:11:51.920453471 +0000
+@@ -11,6 +11,11 @@
+ #
+ #      ChangeLog
+ #
++#      M. Mozzarelli  :   Amended to support build and deployment in OpenWrt
++#                     :   CFLAGS now accepting passed parameters; -fPIC added
++#                     :   Now supports libnl3 API by defining HAVE_NL_3 or
++#                     :   HAVE_NL_TINY (OpenWrt); some tidy up
++#                     :   Added support for DESTDIR installation for OpenWRT and DD-WRT
+ #      Wensong        :   Modified the Makefile and the spec files so
+ #                     :   that rpms can be created with ipvsadm alone
+ #      P.Copeland     :   Modified the Makefile and the spec files so
+@@ -35,20 +40,23 @@
+ RPMSOURCEDIR	= $(shell rpm --eval '%_sourcedir')
+ RPMSPECDIR	= $(shell rpm --eval '%_specdir')
+
+-CC		= gcc
++CC			= gcc
+ INCLUDE		=
++ifneq (0,$(DESTDIR))
++BUILD_ROOT	= $(DESTDIR)
++endif
+ SBIN		= $(BUILD_ROOT)/sbin
+ MANDIR		= usr/man
+-MAN		= $(BUILD_ROOT)/$(MANDIR)/man8
++MAN			= $(BUILD_ROOT)/$(MANDIR)/man8
+ INIT		= $(BUILD_ROOT)/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 -fPIC
+ endif
+
+
+@@ -93,8 +101,9 @@
+
+ all:            libs ipvsadm
+
++$(STATIC_LIBS): libs
+ libs:
+-		make -C libipvs
++		$(MAKE) -C libipvs
+
+ ipvsadm:	$(OBJS) $(STATIC_LIBS)
+ 		$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+@@ -116,7 +125,7 @@
+ 		rm -rf debian/tmp
+ 		find . -name '*.[ao]' -o -name "*~" -o -name "*.orig" \
+ 		  -o -name "*.rej" -o -name core | xargs rm -f
+-		make -C libipvs clean
++		$(MAKE) -C libipvs clean
+
+ distclean:	clean
+
diff --git a/package/network/utils/ipvsadm/patches/002-ipvsadm-scripts.patch
b/package/network/utils/ipvsadm/patches/002-ipvsadm-scripts.patch
new file mode 100644
index 0000000..f569073
--- /dev/null
+++ b/package/network/utils/ipvsadm/patches/002-ipvsadm-scripts.patch
@@ -0,0 +1,41 @@
+diff -Naur ipvsadm-1.26/ipvsadm-restore ipvsadm-1.26.owrt/ipvsadm-restore
+--- ipvsadm-1.26/ipvsadm-restore	2008-09-18 16:57:37.000000000 +0100
++++ ipvsadm-1.26.owrt/ipvsadm-restore	2016-03-04 17:23:11.291379392 +0000
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #      ipvsadm-restore - Restore IPVS rules
+ #
+ #      A very simple wrapper to restore IPVS rules
+@@ -11,9 +11,10 @@
+ #      This file:
+ #
+ #      ChangeLog
+-#      Horms               :        Clear IPVS rules before adding from STDIN
+-#      Horms               :        Filter out "^#"
+ #
++#      M. Mozzarelli       :  Modified to use /bin/sh for compatibility
++#      Horms               :  Clear IPVS rules before adding from STDIN
++#      Horms               :  Filter out "^#"
+ #
+
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
+diff -Naur ipvsadm-1.26/ipvsadm-save ipvsadm-1.26.owrt/ipvsadm-save
+--- ipvsadm-1.26/ipvsadm-save	2008-09-18 16:57:37.000000000 +0100
++++ ipvsadm-1.26.owrt/ipvsadm-save	2016-03-04 17:23:07.257426535 +0000
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!/bin/sh
+ #      ipvsadm-save - Save IPVS rules
+ #
+ #      A very simple wrapper to save IPVS rules
+@@ -12,7 +12,8 @@
+ #
+ #      ChangeLog
+ #
+-#	 Wensong Zhang          :  Added the "-n" option and the help()
++#      M. Mozzarelli       :  Modified to use /bin/sh for compatibility
++#      Wensong Zhang       :  Added the "-n" option and the help()
+ #
+
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list