Aneesh Kumar K.V
2002-05-08 09:50:02 UTC
Hi,
Attaching below is the patch that add Cluster Infrastructure (
http://ci-linux.sourceforge.net ) as the health check mechanism for the
keepalive daemons. Please comment on the patch so that i can continue
working on it
-aneesh
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/Makefile.in keepalived-0.5.7.new/Makefile.in
--- keepalived-0.5.7/Makefile.in Fri May 3 00:33:26 2002
+++ keepalived-0.5.7.new/Makefile.in Wed May 8 21:22:03 2002
@@ -8,6 +8,7 @@
KERNEL := _KRNL_2_$(shell uname -r | cut -d'.' -f2)_
IPVS_FLAG := @IPVS_SUPPORT@
VRRP_FLAG := @VRRP_SUPPORT@
+CI_LINUX := @CI_LINUX@
prefix = @prefix@
exec_prefix = @exec_prefix@
@@ -62,8 +63,12 @@
vrrp_ipsecah.o
endif
+ifeq ($(CI_LINUX),_WITH_CI_LINUX_)
+CI_LINUX_OBJ=check_ci.c
+endif
+
INCLUDE = -I/usr/src/linux/include
-OBJS = $(CORE_OBJS) $(IPVS_OBJS) $(VRRP_OBJS)
+OBJS = $(CORE_OBJS) $(IPVS_OBJS) $(VRRP_OBJS) $(CI_LINUX_OBJS)
.c.o:
$(CC) -o $@ $(CFLAGS) $(IPVSFLAGS) $(INCLUDE) -c $*.c
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/check_ci.c keepalived-0.5.7.new/check_ci.c
--- keepalived-0.5.7/check_ci.c Thu Jan 1 05:30:00 1970
+++ keepalived-0.5.7.new/check_ci.c Wed May 8 02:19:03 2002
@@ -0,0 +1,152 @@
+#include "check_ci.h"
+#include "parser.h"
+#include "check_api.h"
+#include "smtp.h"
+#include "ipwrapper.h"
+
+
+static nodenum_ip_map_t *nodemap;
+
+void dump_ci_check(void *data)
+{
+
+ syslog(LOG_INFO, " Keepalive method = CI_LINUX");
+ syslog(LOG_INFO, " Cluster Infrastructure for Linux");
+}
+
+
+int ci_check_thread(thread *thread)
+{
+ checker *checker;
+ int status ;
+ checker = THREAD_ARG(thread);
+
+ status = nodestatus(*(checker->rs));
+
+ switch(status) {
+
+ case UP:
+ if (!ISALIVE(checker->rs)) {
+ smtp_alert(thread->master, checker->rs
+ , NULL
+ , "UP"
+ , "=> CI-Linux CHECK succeed on service <=\n\n");
+ perform_svr_state(UP, checker->vs, checker->rs);
+ }
+ break;
+ case DOWN:
+ if (ISALIVE(checker->rs)) {
+ smtp_alert(thread->master, checker->rs
+ , NULL
+ , "DOWN"
+ , "=> TCP CHECK failed on service <=\n\n");
+ perform_svr_state(DOWN, checker->vs, checker->rs);
+ }
+ break;
+ default:
+ syslog(LOG_ERR,"Unknown node status \n");
+ }
+
+
+ /* Register the next check */
+ thread_add_timer(thread->master, ci_check_thread
+ , checker
+ , checker->vs->delay_loop);
+ return 0;
+
+}
+
+void ci_get_handler(vector strvec)
+{
+ nodemap = (nodenum_ip_map_t *)malloc(sizeof(nodenum_ip_map_t)*cluster_maxnodes()+1); /* zero is not considered as a valid node */
+ if( initialize_nodemap(nodemap) < 0 );
+
+ /* How do i inform the main line code ? */
+
+ queue_checker(NULL,dump_ci_check,ci_check_thread,NULL);
+}
+
+void install_ci_check_keyword(void)
+{
+ install_keyword("CI-LINUX", &ci_get_handler);
+}
+int initialize_nodemap(nodenum_ip_map_t *nodemap)
+{
+ FILE *fp;
+ char buf[BUFFSIZE];
+ int node_number ;
+
+ if( (fp = fopen(CLUSTERTAB,"r")) == NULL )
+ return -1;
+ while(fscanf(fp,"%s",buf) != EOF ){
+ if( buf[0] == '#' ){
+ if(fscanf (fp, "%[^\n]",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",
+ CLUSTERTAB);
+ bzero(buf,BUFFSIZE);
+ continue;
+ }
+ node_number = atoi(buf);
+ if ( node_number > cluster_maxnodes()) {
+ syslog(LOG_ERR,"Node number greater than MAX node num\n");
+ return -1;
+ }
+ if(fscanf (fp, "%s",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",CLUSTERTAB);
+ nodemap[node_number].addr_ip = inet_addr(buf);
+
+ if(fscanf (fp, "%[^\n]",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",CLUSTERTAB);
+ bzero(buf,BUFFSIZE);
+
+ }
+
+
+ return 1;
+}
+
+clusternode_t address_to_nodenum(uint32_t addr_ip)
+{
+ int i ;
+ int max_nodes = cluster_maxnodes();
+ for( i = 1 ; i<= max_nodes;i++) {
+ if( nodemap[i].addr_ip == addr_ip )
+ return i;
+ }
+ return 0; /* Not a valid node */
+}
+int node_to_address(clusternode_t node, real_server *rs)
+{
+
+ if( node > cluster_maxnodes() ) {
+ syslog(LOG_ERR,"Node number greater than Max node num \n");
+ return -1;
+ }
+
+ rs->addr_ip = nodemap[node].addr_ip;
+/* do I need to fill the rest of the values here ? */
+
+ return 1;
+}
+
+int nodestatus(real_server real)
+{
+
+ int node_num;
+ clusternode_info_t ni;
+
+ if((node_num = address_to_nodenum(real.addr_ip) ) == 0 )
+ return UNKNOWN_NODE;
+ if(clusternode_info(node_num, sizeof(ni), &ni) >= 0) {
+ if (ni.node_state == CLUSTERNODE_UP )
+ return UP;
+ else
+/* I am insterested only in two state either fully up or down */
+ return DOWN;
+ }
+ else {
+ syslog(LOG_ERR,"Error in getting the cluster information \n");
+ }
+ return UNKNOWN_NODE;
+
+}
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/check_ci.h keepalived-0.5.7.new/check_ci.h
--- keepalived-0.5.7/check_ci.h Thu Jan 1 05:30:00 1970
+++ keepalived-0.5.7.new/check_ci.h Wed May 8 21:11:59 2002
@@ -0,0 +1,34 @@
+#ifndef _CI_H
+#define _CI_H
+#include <signal.h>
+#include <pthread.h>
+#include <linux/cluster.h> /* Should change this to cluster.h alone */
+
+#include <syslog.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "data.h"
+
+#define SIGCLUSTER 2
+#define CLUSTERTAB "/etc/clustertab"
+#define BUFFSIZE 100
+#define UP 1
+#define DOWN 2
+#define UNKNOWN_NODE 0
+
+
+typedef struct nodenum_ip_map{
+ uint32_t addr_ip;
+} nodenum_ip_map_t;
+
+extern int initialize_nodemap(nodenum_ip_map_t *nodemap);
+extern int node_to_address(clusternode_t node, real_server *rs);
+extern clusternode_t address_to_nodenum(uint32_t addr_ip);
+extern int nodestatus(real_server real);
+
+
+
+#endif /* _CI_H */
+
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/configure.in keepalived-0.5.7.new/configure.in
--- keepalived-0.5.7/configure.in Fri May 3 01:05:03 2002
+++ keepalived-0.5.7.new/configure.in Wed May 8 23:03:38 2002
@@ -56,6 +56,9 @@
[ --disable-vrrp do not use the VRRP framework])
AC_ARG_ENABLE(debug,
[ --enable-debug compile with debugging flags])
+AC_ARG_WITH(ci_linux,
+ [--with-ci_linux, Compile with Cluster Infrastructure support( defalut no)],
+ ci_linux=$withval,ci_linux="no")
if test "${enable_lvs}" = "no"; then
if test "${enable_vrrp}" = "no"; then
@@ -77,6 +80,10 @@
DFLAGS="-D_DEBUG_"
AC_SUBST(DFLAGS)
fi
+if test "${ci_linux}" = "yes"; then
+CI_LINUX="_WITH_CI_LINUX_"
+AC_SUBST(CI_LINUX)
+fi
AC_SUBST(IPVS_SUPPORT)
AC_SUBST(VRRP_SUPPORT)
@@ -111,6 +118,9 @@
AC_CHECK_LIB(crypto, MD5_Init,,AC_MSG_ERROR([OpenSSL libraries are required]))
AC_CHECK_LIB(ssl, SSL_CTX_new,,AC_MSG_ERROR([OpenSSL libraries are required]))
AC_CHECK_LIB(popt, poptGetContext,,AC_MSG_ERROR([Popt libraries is required]))
+if test "${ci_linux}" = "yes"; then
+AC_CHECK_LIB(cluster,cluster_maxnodes,,AC_MSG_ERROR([libcluster libraries are required]))
+fi
dnl ----[ Create object list ]----
if test "${KERNEL_CODE}" = "2"; then
@@ -127,6 +137,9 @@
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!]))
AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h syslog.h unistd.h)
+if test "${ci_linux}" = "yes"; then
+AC_CHECK_HEADERS(linux/cluster.h,,AC_MSG_ERROR([linux/cluster.h file not found]))
+fi
dnl ----[ Checks for typedefs, structures, and compiler characteristics ]----
AC_C_CONST
Attaching below is the patch that add Cluster Infrastructure (
http://ci-linux.sourceforge.net ) as the health check mechanism for the
keepalive daemons. Please comment on the patch so that i can continue
working on it
-aneesh
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/Makefile.in keepalived-0.5.7.new/Makefile.in
--- keepalived-0.5.7/Makefile.in Fri May 3 00:33:26 2002
+++ keepalived-0.5.7.new/Makefile.in Wed May 8 21:22:03 2002
@@ -8,6 +8,7 @@
KERNEL := _KRNL_2_$(shell uname -r | cut -d'.' -f2)_
IPVS_FLAG := @IPVS_SUPPORT@
VRRP_FLAG := @VRRP_SUPPORT@
+CI_LINUX := @CI_LINUX@
prefix = @prefix@
exec_prefix = @exec_prefix@
@@ -62,8 +63,12 @@
vrrp_ipsecah.o
endif
+ifeq ($(CI_LINUX),_WITH_CI_LINUX_)
+CI_LINUX_OBJ=check_ci.c
+endif
+
INCLUDE = -I/usr/src/linux/include
-OBJS = $(CORE_OBJS) $(IPVS_OBJS) $(VRRP_OBJS)
+OBJS = $(CORE_OBJS) $(IPVS_OBJS) $(VRRP_OBJS) $(CI_LINUX_OBJS)
.c.o:
$(CC) -o $@ $(CFLAGS) $(IPVSFLAGS) $(INCLUDE) -c $*.c
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/check_ci.c keepalived-0.5.7.new/check_ci.c
--- keepalived-0.5.7/check_ci.c Thu Jan 1 05:30:00 1970
+++ keepalived-0.5.7.new/check_ci.c Wed May 8 02:19:03 2002
@@ -0,0 +1,152 @@
+#include "check_ci.h"
+#include "parser.h"
+#include "check_api.h"
+#include "smtp.h"
+#include "ipwrapper.h"
+
+
+static nodenum_ip_map_t *nodemap;
+
+void dump_ci_check(void *data)
+{
+
+ syslog(LOG_INFO, " Keepalive method = CI_LINUX");
+ syslog(LOG_INFO, " Cluster Infrastructure for Linux");
+}
+
+
+int ci_check_thread(thread *thread)
+{
+ checker *checker;
+ int status ;
+ checker = THREAD_ARG(thread);
+
+ status = nodestatus(*(checker->rs));
+
+ switch(status) {
+
+ case UP:
+ if (!ISALIVE(checker->rs)) {
+ smtp_alert(thread->master, checker->rs
+ , NULL
+ , "UP"
+ , "=> CI-Linux CHECK succeed on service <=\n\n");
+ perform_svr_state(UP, checker->vs, checker->rs);
+ }
+ break;
+ case DOWN:
+ if (ISALIVE(checker->rs)) {
+ smtp_alert(thread->master, checker->rs
+ , NULL
+ , "DOWN"
+ , "=> TCP CHECK failed on service <=\n\n");
+ perform_svr_state(DOWN, checker->vs, checker->rs);
+ }
+ break;
+ default:
+ syslog(LOG_ERR,"Unknown node status \n");
+ }
+
+
+ /* Register the next check */
+ thread_add_timer(thread->master, ci_check_thread
+ , checker
+ , checker->vs->delay_loop);
+ return 0;
+
+}
+
+void ci_get_handler(vector strvec)
+{
+ nodemap = (nodenum_ip_map_t *)malloc(sizeof(nodenum_ip_map_t)*cluster_maxnodes()+1); /* zero is not considered as a valid node */
+ if( initialize_nodemap(nodemap) < 0 );
+
+ /* How do i inform the main line code ? */
+
+ queue_checker(NULL,dump_ci_check,ci_check_thread,NULL);
+}
+
+void install_ci_check_keyword(void)
+{
+ install_keyword("CI-LINUX", &ci_get_handler);
+}
+int initialize_nodemap(nodenum_ip_map_t *nodemap)
+{
+ FILE *fp;
+ char buf[BUFFSIZE];
+ int node_number ;
+
+ if( (fp = fopen(CLUSTERTAB,"r")) == NULL )
+ return -1;
+ while(fscanf(fp,"%s",buf) != EOF ){
+ if( buf[0] == '#' ){
+ if(fscanf (fp, "%[^\n]",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",
+ CLUSTERTAB);
+ bzero(buf,BUFFSIZE);
+ continue;
+ }
+ node_number = atoi(buf);
+ if ( node_number > cluster_maxnodes()) {
+ syslog(LOG_ERR,"Node number greater than MAX node num\n");
+ return -1;
+ }
+ if(fscanf (fp, "%s",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",CLUSTERTAB);
+ nodemap[node_number].addr_ip = inet_addr(buf);
+
+ if(fscanf (fp, "%[^\n]",buf) == EOF )
+ syslog(LOG_ERR," %s File Format Error \n",CLUSTERTAB);
+ bzero(buf,BUFFSIZE);
+
+ }
+
+
+ return 1;
+}
+
+clusternode_t address_to_nodenum(uint32_t addr_ip)
+{
+ int i ;
+ int max_nodes = cluster_maxnodes();
+ for( i = 1 ; i<= max_nodes;i++) {
+ if( nodemap[i].addr_ip == addr_ip )
+ return i;
+ }
+ return 0; /* Not a valid node */
+}
+int node_to_address(clusternode_t node, real_server *rs)
+{
+
+ if( node > cluster_maxnodes() ) {
+ syslog(LOG_ERR,"Node number greater than Max node num \n");
+ return -1;
+ }
+
+ rs->addr_ip = nodemap[node].addr_ip;
+/* do I need to fill the rest of the values here ? */
+
+ return 1;
+}
+
+int nodestatus(real_server real)
+{
+
+ int node_num;
+ clusternode_info_t ni;
+
+ if((node_num = address_to_nodenum(real.addr_ip) ) == 0 )
+ return UNKNOWN_NODE;
+ if(clusternode_info(node_num, sizeof(ni), &ni) >= 0) {
+ if (ni.node_state == CLUSTERNODE_UP )
+ return UP;
+ else
+/* I am insterested only in two state either fully up or down */
+ return DOWN;
+ }
+ else {
+ syslog(LOG_ERR,"Error in getting the cluster information \n");
+ }
+ return UNKNOWN_NODE;
+
+}
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/check_ci.h keepalived-0.5.7.new/check_ci.h
--- keepalived-0.5.7/check_ci.h Thu Jan 1 05:30:00 1970
+++ keepalived-0.5.7.new/check_ci.h Wed May 8 21:11:59 2002
@@ -0,0 +1,34 @@
+#ifndef _CI_H
+#define _CI_H
+#include <signal.h>
+#include <pthread.h>
+#include <linux/cluster.h> /* Should change this to cluster.h alone */
+
+#include <syslog.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "data.h"
+
+#define SIGCLUSTER 2
+#define CLUSTERTAB "/etc/clustertab"
+#define BUFFSIZE 100
+#define UP 1
+#define DOWN 2
+#define UNKNOWN_NODE 0
+
+
+typedef struct nodenum_ip_map{
+ uint32_t addr_ip;
+} nodenum_ip_map_t;
+
+extern int initialize_nodemap(nodenum_ip_map_t *nodemap);
+extern int node_to_address(clusternode_t node, real_server *rs);
+extern clusternode_t address_to_nodenum(uint32_t addr_ip);
+extern int nodestatus(real_server real);
+
+
+
+#endif /* _CI_H */
+
diff -Nru --exclude-from=/tmp/ex.file keepalived-0.5.7/configure.in keepalived-0.5.7.new/configure.in
--- keepalived-0.5.7/configure.in Fri May 3 01:05:03 2002
+++ keepalived-0.5.7.new/configure.in Wed May 8 23:03:38 2002
@@ -56,6 +56,9 @@
[ --disable-vrrp do not use the VRRP framework])
AC_ARG_ENABLE(debug,
[ --enable-debug compile with debugging flags])
+AC_ARG_WITH(ci_linux,
+ [--with-ci_linux, Compile with Cluster Infrastructure support( defalut no)],
+ ci_linux=$withval,ci_linux="no")
if test "${enable_lvs}" = "no"; then
if test "${enable_vrrp}" = "no"; then
@@ -77,6 +80,10 @@
DFLAGS="-D_DEBUG_"
AC_SUBST(DFLAGS)
fi
+if test "${ci_linux}" = "yes"; then
+CI_LINUX="_WITH_CI_LINUX_"
+AC_SUBST(CI_LINUX)
+fi
AC_SUBST(IPVS_SUPPORT)
AC_SUBST(VRRP_SUPPORT)
@@ -111,6 +118,9 @@
AC_CHECK_LIB(crypto, MD5_Init,,AC_MSG_ERROR([OpenSSL libraries are required]))
AC_CHECK_LIB(ssl, SSL_CTX_new,,AC_MSG_ERROR([OpenSSL libraries are required]))
AC_CHECK_LIB(popt, poptGetContext,,AC_MSG_ERROR([Popt libraries is required]))
+if test "${ci_linux}" = "yes"; then
+AC_CHECK_LIB(cluster,cluster_maxnodes,,AC_MSG_ERROR([libcluster libraries are required]))
+fi
dnl ----[ Create object list ]----
if test "${KERNEL_CODE}" = "2"; then
@@ -127,6 +137,9 @@
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!]))
AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h syslog.h unistd.h)
+if test "${ci_linux}" = "yes"; then
+AC_CHECK_HEADERS(linux/cluster.h,,AC_MSG_ERROR([linux/cluster.h file not found]))
+fi
dnl ----[ Checks for typedefs, structures, and compiler characteristics ]----
AC_C_CONST