[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-ha-dev
Subject: [Linux-ha-dev] Re: Issues with heartbeat and iproute + bcast.c mod
From: Kevin Dwyer <kevin () pheared ! net>
Date: 2002-07-31 19:47:14
[Download RAW message or body]
In order to temporarily fix my problem here, I modified bcast.c to be able
to take an argument of the style: bcast eth0/10.1.1.255
(interfacename/broadcastaddress)
I rolled it around a bit and couldn't really come up with what I had
hoped. Adding a parse function to the bcast plugin seemed like the likely
choice at first, but that doesn't seem to behave the way I'd like without
lots more work. So instead, I added a short piece that will split the
interface and broadcast values when you call bcast_new. The drawback is
that it's not pretty to do it like that; I'd prefer that it actually used
a parser, but reading mcast.c (which has one) didn't leave me with the
impression that it could be done easily that way.
This is really a request for comments.
Does this look like a good way to do it?
(patch is attached, against current CVS)
I started rooting through the ip route source, and it looks like getting
the broadcast address in that fashion is doable but is a much bigger
task. Anybody feel like giving it a shot? ;)
Should I just go back on vacation? ;)
Oh BTW, I was reading stuff on the linux-ha site and saw mention of
#Linux-HA -- Does anybody actually frequent it? Looked empty to me. :)
-[ kevin@pheared.net devel.pheared.net ]-
-[ Rather be forgotten, than remembered for giving in. ]-
-[ ZZ = g ^ (xb * xa) mod p g = h^{(p-1)/q} mod p ]-
["patch-bcast.c" (TEXT/PLAIN)]
Index: lib/plugins/HBcomm/bcast.c
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/lib/plugins/HBcomm/bcast.c,v
retrieving revision 1.20
diff -u -r1.20 bcast.c
--- lib/plugins/HBcomm/bcast.c 16 Jul 2002 17:10:32 -0000 1.20
+++ lib/plugins/HBcomm/bcast.c 31 Jul 2002 19:39:21 -0000
@@ -74,7 +74,7 @@
static int bcast_make_receive_sock(struct hb_media* ei);
static int bcast_make_send_sock(struct hb_media * mp);
static struct ip_private *
- new_ip_interface(const char * ifn, int port);
+ new_ip_interface(const char * ifn, int port, struct in_addr *brd);
static int bcast_descr(char** buffer);
static int bcast_mtype(char** buffer);
static int bcast_isping(void);
@@ -230,25 +230,61 @@
{
struct ip_private* ipi;
struct hb_media * ret;
+ char *intf_new;
+ char tmp_broadaddr[16]; /* Enough for 15 chars of inet addr */
+ struct in_addr *broadaddr = NULL;
bcast_init();
- ipi = new_ip_interface(intf, localudpport);
+
+ if (strchr(intf, '/')) {
+ /* Hack to allow explicit broadcast address specification */
+ /* Split the interface and the broadcast address */
+ /* Expected input: eth0/10.1.1.255 */
+
+ char *slash = strchr(intf, '/');
+ int intf_len = slash-intf; /* strlen("eth0") */
+ char *tmp_intf = MALLOC(intf_len);
+
+ strncpy(tmp_intf, intf, intf_len);
+ tmp_intf[intf_len] = 0;
+ intf_new = MALLOC(intf_len);
+ strcpy(intf_new, tmp_intf);
+
+ strcpy(tmp_broadaddr, slash+1);
+
+ broadaddr = MALLOC(sizeof(struct in_addr));
+ inet_aton(tmp_broadaddr, broadaddr);
+
+ FREE(tmp_intf);
+
+ ha_log(LOG_DEBUG, "bcast_new: Intf: %s Bcast: %s\n",
+ intf_new, inet_ntoa(*broadaddr));
+
+ } else {
+ intf_new = MALLOC(strlen(intf) + 1);
+ strcpy(intf_new, intf);
+ }
+
+ ipi = new_ip_interface(intf_new, localudpport, broadaddr);
+ if (broadaddr) FREE(broadaddr);
+
if (DEBUGPKT) {
- ha_log(LOG_DEBUG, "bcast_new: attempting to open %s:%d", intf
+ ha_log(LOG_DEBUG, "bcast_new: attempting to open %s:%d", intf_new
, localudpport);
}
if (ipi == NULL) {
LOG(PIL_CRIT, "IP interface [%s] does not exist"
- , intf);
+ , intf_new);
+ FREE(intf_new);
return(NULL);
}
ret = (struct hb_media*) MALLOC(sizeof(struct hb_media));
if (ret != NULL) {
char * name;
ret->pd = (void*)ipi;
- name = MALLOC(strlen(intf)+1);
- strcpy(name, intf);
+ name = MALLOC(strlen(intf_new)+1);
+ strcpy(name, intf_new);
ret->name = name;
ret->wpipe[0] = 0;
ret->wpipe[1] = 0;
@@ -262,6 +298,9 @@
ha_log(LOG_DEBUG, "bcast_new: ret was NULL");
}
}
+
+ FREE(intf_new);
+
return(ret);
}
@@ -472,7 +511,7 @@
* This is so we can have redundant NICs, and heartbeat on both
*/
struct ifreq i;
- strcpy(i.ifr_name, mp->name);
+ strcpy(i.ifr_name, ei->interface);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE
, &i, sizeof(i)) == -1) {
@@ -618,17 +657,20 @@
static struct ip_private *
-new_ip_interface(const char * ifn, int port)
+new_ip_interface(const char * ifn, int port, struct in_addr *brd)
{
struct ip_private * ep;
struct in_addr broadaddr;
-
- /* Fetch the broadcast address for this interface */
- if (if_get_broadaddr(ifn, &broadaddr) < 0) {
- /* this function whines about problems... */
- return (NULL);
- }
+ if (brd) memcpy(&broadaddr, brd, sizeof(struct in_addr));
+ else {
+ /* Fetch the broadcast address for this interface */
+ if (if_get_broadaddr(ifn, &broadaddr) < 0) {
+ /* this function whines about problems... */
+ return (NULL);
+ }
+ }
+
/*
* We now have all the information we need. Populate our
* structure with the information we've gotten.
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.community.tummy.com
http://lists.community.tummy.com/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic