can heartbeat bind to an interface?
Alan Robertson
alanr@unix.sh
Thu, 14 Mar 2002 14:39:37 -0700
Jeremy Hansen wrote:
> On Thu, 14 Mar 2002, Lars Marowsky-Bree wrote:
>
>
>>On 2002-03-14T15:18:53,
>> Jeremy Hansen <jeremy@xxedgexx.com> said:
>>
>>
>>>I see heartbeat is binding to all interfaces. Can I force heartbeat to
>>>bind to a specific interface only?.
>>>
>>heartbeat should only bind to the interfaces specified in ha.cf ?
>>
>
> ha.cf
> # What interfaces to heartbeat over?
> #
> udp eth1
> -----------------
>
> netstat:
> udp 0 0 0.0.0.0:32770 0.0.0.0:*
> 3405/heartbeat
>
> udp 0 0 0.0.0.0:694 0.0.0.0:*
> 3405/heartbeat
Here's the code that binds to the interfaces for writing...
#if defined(SO_BINDTODEVICE)
{
/*
* We want to send out this particular interface
*
* This is so we can have redundant NICs, and heartbeat on both
*/
struct ifreq i;
strcpy(i.ifr_name, mp->name);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE
, &i, sizeof(i)) == -1) {
LOG(PIL_CRIT
, "Error setting socket option SO_BINDTODEVICE"
": %s"
, strerror(errno));
close(sockfd);
return(-1);
}
if (DEBUGPKT) {
ha_log (LOG_DEBUG
, "bcast_make_send_sock: Modified %d"
" Added option SO_BINDTODEVICE."
, sockfd);
}
}
#endif
Here's the code for the "reading" side.
#if defined(SO_BINDTODEVICE)
{
/*
* We want to receive packets only from this interface...
*/
struct ifreq i;
strcpy(i.ifr_name, ei->interface);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE
, &i, sizeof(i)) == -1) {
LOG(PIL_CRIT
, "Error setting socket option"
" SO_BINDTODEVICE(r) on %s: %s"
, i.ifr_name, strerror(errno));
close(sockfd);
return(-1);
}
if (ANYDEBUG) {
LOG(PIL_DEBUG
, "SO_BINDTODEVICE(r) set for device %s"
, i.ifr_name);
}
}
#endif
And, if this code is disabled, I can't start more than one read process
because it knows the port is already bound to. So, I think the code is
likely working.
I couldn't tell... Do you think it's working or not?
-- Alan Robertson
alanr@unix.sh