[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Linux-cluster] [PATCH][RESEND] Add network interface select option for fence_xvmd



Hello,


I updated my patch for fence_xvmd to add network interface select option
posted before.

This patch fixes the following issues ATST:

 1. fence_xvmd selects wrong network interface to listen on if host has
    multiple interfaces and target interface is not for default route.
    As a result, fence_xvmd does not repond to fence_xvm's request.
 2. fence_xvmd cannot start if default route is not set.

The following patch is for cluster-3 HEAD.

The same problem exists in cluster-2 (rhel5's cluster) and I opened
bugzilla bug for that version: rhbz#459720.


Signed-Off-By: Satoru SATOH <satoru satoh gmail com>

 fence/agents/xvm/fence_xvmd.c |    6 +++---
 fence/agents/xvm/mcast.c      |    9 +++++----
 fence/agents/xvm/mcast.h      |    4 ++--
 fence/agents/xvm/options.c    |   13 +++++++++++++
 fence/agents/xvm/options.h    |    1 +
 fence/man/fence_xvmd.8        |    3 +++
 6 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/fence/agents/xvm/fence_xvmd.c b/fence/agents/xvm/fence_xvmd.c
index 888f24b..2746c23 100644
--- a/fence/agents/xvm/fence_xvmd.c
+++ b/fence/agents/xvm/fence_xvmd.c
@@ -921,7 +921,7 @@ main(int argc, char **argv)
 	unsigned int logmode = 0;
 	char key[MAX_KEY_LEN];
 	int key_len = 0, x;
-	char *my_options = "dfi:a:p:C:U:c:k:u?hLXV";
+	char *my_options = "dfi:a:p:I:C:U:c:k:u?hLXV";
 	cman_handle_t ch = NULL;
 	void *h = NULL;
 
@@ -1031,9 +1031,9 @@ main(int argc, char **argv)
 	}
 
 	if (args.family == PF_INET)
-		mc_sock = ipv4_recv_sk(args.addr, args.port);
+		mc_sock = ipv4_recv_sk(args.addr, args.port, args.ifindex);
 	else
-		mc_sock = ipv6_recv_sk(args.addr, args.port);
+		mc_sock = ipv6_recv_sk(args.addr, args.port, args.ifindex);
 	if (mc_sock < 0) {
 		log_printf(LOG_ERR,
 			   "Could not set up multicast listen socket\n");
diff --git a/fence/agents/xvm/mcast.c b/fence/agents/xvm/mcast.c
index db46328..9f20c89 100644
--- a/fence/agents/xvm/mcast.c
+++ b/fence/agents/xvm/mcast.c
@@ -31,10 +31,10 @@ LOGSYS_DECLARE_SUBSYS ("XVM", SYSLOGLEVEL);
   Sets up a multicast receive socket
  */
 int
-ipv4_recv_sk(char *addr, int port)
+ipv4_recv_sk(char *addr, int port, unsigned int ifindex)
 {
 	int sock;
-	struct ip_mreq mreq;
+	struct ip_mreqn mreq;
 	struct sockaddr_in sin;
 
 	/* Store multicast address */
@@ -74,7 +74,7 @@ ipv4_recv_sk(char *addr, int port)
 	 * Join multicast group
 	 */
 	/* mreq.imr_multiaddr.s_addr is set above */
-	mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+	mreq.imr_ifindex = ifindex;
 	dbg_printf(4, "Joining multicast group\n");
 	if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
 		       &mreq, sizeof(mreq)) == -1) {
@@ -184,7 +184,7 @@ ipv4_send_sk(char *send_addr, char *addr, int port, struct sockaddr *tgt,
   Sets up a multicast receive (ipv6) socket
  */
 int
-ipv6_recv_sk(char *addr, int port)
+ipv6_recv_sk(char *addr, int port, unsigned int ifindex)
 {
 	int sock, val;
 	struct ipv6_mreq mreq;
@@ -203,6 +203,7 @@ ipv6_recv_sk(char *addr, int port)
 	memcpy(&mreq.ipv6mr_multiaddr, &sin.sin6_addr,
 	       sizeof(struct in6_addr));
 
+	mreq.ipv6mr_interface = ifindex;
 
 	/********************************
 	 * SET UP MULTICAST RECV SOCKET *
diff --git a/fence/agents/xvm/mcast.h b/fence/agents/xvm/mcast.h
index 5113f04..08fd6de 100644
--- a/fence/agents/xvm/mcast.h
+++ b/fence/agents/xvm/mcast.h
@@ -4,11 +4,11 @@
 #define IPV4_MCAST_DEFAULT "225.0.0.12"
 #define IPV6_MCAST_DEFAULT "ff05::3:1"
 
-int ipv4_recv_sk(char *addr, int port);
+int ipv4_recv_sk(char *addr, int port, unsigned int ifindex);
 int ipv4_send_sk(char *src_addr, char *addr, int port,
 		 struct sockaddr *src, socklen_t slen,
 		 int ttl);
-int ipv6_recv_sk(char *addr, int port);
+int ipv6_recv_sk(char *addr, int port, unsigned int ifindex);
 int ipv6_send_sk(char *src_addr, char *addr, int port,
 		 struct sockaddr *src, socklen_t slen,
 		 int ttl);
diff --git a/fence/agents/xvm/options.c b/fence/agents/xvm/options.c
index 969ca8d..58b2aec 100644
--- a/fence/agents/xvm/options.c
+++ b/fence/agents/xvm/options.c
@@ -104,6 +104,13 @@ assign_port(fence_xvm_args_t *args, struct arg_info *arg, char *value)
 
 
 static inline void
+assign_interface(fence_xvm_args_t *args, struct arg_info *arg, char *value)
+{
+	args->ifindex = if_nametoindex(value);
+}
+
+
+static inline void
 assign_retrans(fence_xvm_args_t *args, struct arg_info *arg, char *value)
 {
 	args->retr_time = atoi(value);
@@ -307,6 +314,10 @@ static struct arg_info _arg_info[] = {
 	  "IP port (default=1229)",
 	  assign_port },
 
+	{ 'I', "-I <interface>", "multicast_address",
+	  "Network interface name to listen on",
+	  assign_interface },
+
 	{ 'r', "-r <retrans>", "retrans", 
 	  "Multicast retransmit time (in 1/10sec; default=20)",
 	  assign_retrans },
@@ -416,6 +427,7 @@ args_init(fence_xvm_args_t *args)
 	args->hash = DEFAULT_HASH;
 	args->auth = DEFAULT_AUTH;
 	args->port = 1229;
+	args->ifindex = 0;
 	args->family = PF_INET;
 	args->timeout = 30;
 	args->retr_time = 20;
@@ -445,6 +457,7 @@ args_print(fence_xvm_args_t *args)
 	_pr_int(args->hash);
 	_pr_int(args->auth);
 	_pr_int(args->port);
+	_pr_int(args->ifindex);
 	_pr_int(args->family);
 	_pr_int(args->timeout);
 	_pr_int(args->retr_time);
diff --git a/fence/agents/xvm/options.h b/fence/agents/xvm/options.h
index 7a2dcca..07f99da 100644
--- a/fence/agents/xvm/options.h
+++ b/fence/agents/xvm/options.h
@@ -23,6 +23,7 @@ typedef struct {
 	fence_hash_t hash;
 	fence_auth_type_t auth;
 	int port;
+	unsigned int ifindex;
 	int family;
 	int timeout;
 	int retr_time;
diff --git a/fence/man/fence_xvmd.8 b/fence/man/fence_xvmd.8
index 5a47211..12af607 100644
--- a/fence/man/fence_xvmd.8
+++ b/fence/man/fence_xvmd.8
@@ -39,6 +39,9 @@ for ipv6)
 \fB-p\fP \fIport\fP
 Port to use (default=1229)
 .TP
+\fB-I\fP \fIinterface\fP
+Network interface to listen on, e.g. eth0.
+.TP
 \fB-C\fP \fIauth\fP
 Authentication type (none, sha1, sha256, sha512; default=sha256).  This
 controls the authentication mechanism used to authenticate clients.  The
-- 
1.5.6.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]