You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

743 lines
22 KiB

From 72d9c7dbb01afb26faf141fbec17e2af70ea729c Mon Sep 17 00:00:00 2001
From: David Vossel <dvossel@redhat.com>
Date: Mon, 4 Nov 2013 15:03:23 -0600
Subject: [PATCH] High: IPv6addr: Split send_ua utility out of IPv6addr.c source so it can be re-used in IPaddr2 without requiring cluster-glue.
---
configure.ac | 3 +-
doc/man/Makefile.am | 2 +-
heartbeat/IPv6addr.c | 198 +++-----------------------------------------
heartbeat/IPv6addr_utils.c | 147 ++++++++++++++++++++++++++++++++
heartbeat/Makefile.am | 14 ++-
heartbeat/send_ua.c | 127 ++++++++++++++++++++++++++++
include/IPv6addr.h | 58 +++++++++++++
include/Makefile.am | 2 +-
8 files changed, 356 insertions(+), 195 deletions(-)
create mode 100644 heartbeat/IPv6addr_utils.c
create mode 100644 heartbeat/send_ua.c
create mode 100644 include/IPv6addr.h
diff --git a/configure.ac b/configure.ac
index f88a20f..ac669d8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -714,7 +714,8 @@ AM_CONDITIONAL(USE_LIBNET, test "x$libnet_version" != "xnone" )
dnl ************************************************************************
dnl * Check for netinet/icmp6.h to enable the IPv6addr resource agent
AC_CHECK_HEADERS(netinet/icmp6.h,[],[],[#include <sys/types.h>])
-AM_CONDITIONAL(USE_IPV6ADDR, test "$ac_cv_header_netinet_icmp6_h" = yes && test "$ac_cv_header_heartbeat_glue_config_h" = yes)
+AM_CONDITIONAL(USE_IPV6ADDR_AGENT, test "$ac_cv_header_netinet_icmp6_h" = yes && test "$ac_cv_header_heartbeat_glue_config_h" = yes)
+AM_CONDITIONAL(IPV6ADDR_COMPATIBLE, test "$ac_cv_header_netinet_icmp6_h" = yes)
dnl ========================================================================
dnl Compiler flags
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index 347c145..3bf569a 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -134,7 +134,7 @@ man_MANS = ocf_heartbeat_AoEtarget.7 \
ocf_heartbeat_vmware.7 \
ocf_heartbeat_zabbixserver.7
-if USE_IPV6ADDR
+if USE_IPV6ADDR_AGENT
man_MANS += ocf_heartbeat_IPv6addr.7
endif
diff --git a/heartbeat/IPv6addr.c b/heartbeat/IPv6addr.c
index fab59f5..7c1d20d 100644
--- a/heartbeat/IPv6addr.c
+++ b/heartbeat/IPv6addr.c
@@ -86,6 +86,7 @@
*/
#include <config.h>
+#include <IPv6addr.h>
#include <stdio.h>
#include <stdlib.h>
@@ -134,9 +135,7 @@
#define OCF_ERR_CONFIGURED 6
#define OCF_NOT_RUNNING 7
-const char* IF_INET6 = "/proc/net/if_inet6";
const char* APP_NAME = "IPv6addr";
-const char* APP_NAME_SUA = "send_ua";
const char* START_CMD = "start";
const char* STOP_CMD = "stop";
@@ -148,12 +147,8 @@ const char* RELOAD_CMD = "reload";
const char* META_DATA_CMD = "meta-data";
const char* VALIDATE_CMD = "validate-all";
-char BCAST_ADDR[] = "ff02::1";
-const int UA_REPEAT_COUNT = 5;
const int QUERY_COUNT = 5;
-#define HWADDR_LEN 6 /* mac address length */
-
struct in6_ifreq {
struct in6_addr ifr6_addr;
uint32_t ifr6_prefixlen;
@@ -169,7 +164,6 @@ static int meta_data_addr6(void);
static void usage(const char* self);
-static void usage_send_ua(const char* self);
int write_pid_file(const char *pid_file);
int create_pid_directory(const char *pid_file);
static void byebye(int nsig);
@@ -181,7 +175,6 @@ static char* get_if(struct in6_addr* addr_target, int* plen_target, char* prov_i
static int assign_addr6(struct in6_addr* addr6, int prefix_len, char* if_name);
static int unassign_addr6(struct in6_addr* addr6, int prefix_len, char* if_name);
int is_addr6_available(struct in6_addr* addr6);
-static int send_ua(struct in6_addr* src_ip, char* if_name);
int
main(int argc, char* argv[])
@@ -190,40 +183,11 @@ main(int argc, char* argv[])
char* ipv6addr;
char* cidr_netmask;
int ret;
- int count = UA_REPEAT_COUNT;
- int interval = 1000; /* default 1000 msec */
- int senduaflg = 0;
- int ch;
- int i;
char* cp;
char* prov_ifname = NULL;
int prefix_len = -1;
struct in6_addr addr6;
- /* Check binary name */
- if (strcmp(basename(argv[0]), APP_NAME_SUA) == 0) {
- senduaflg = 1;
- if (argc < 4) {
- usage_send_ua(argv[0]);
- return OCF_ERR_ARGS;
- }
- while ((ch = getopt(argc, argv, "h?c:i:")) != EOF) {
- switch(ch) {
- case 'c': /* count option */
- count = atoi(optarg);
- break;
- case 'i': /* interval option */
- interval = atoi(optarg);
- break;
- case 'h':
- case '?':
- default:
- usage_send_ua(argv[0]);
- return OCF_ERR_ARGS;
- }
- }
- }
-
/* Check the count of parameters first */
if (argc < 2) {
usage(argv[0]);
@@ -235,11 +199,7 @@ main(int argc, char* argv[])
signal(SIGTERM, byebye);
/* open system log */
- if (senduaflg) {
- cl_log_set_entity(APP_NAME_SUA);
- } else {
- cl_log_set_entity(APP_NAME);
- }
+ cl_log_set_entity(APP_NAME);
cl_log_set_facility(LOG_DAEMON);
/* the meta-data dont need any parameter */
@@ -248,12 +208,9 @@ main(int argc, char* argv[])
return OCF_SUCCESS;
}
- if (senduaflg) {
- ipv6addr = argv[optind];
- } else {
- /* check the OCF_RESKEY_ipv6addr parameter, should be an IPv6 address */
- ipv6addr = getenv("OCF_RESKEY_ipv6addr");
- }
+ /* check the OCF_RESKEY_ipv6addr parameter, should be an IPv6 address */
+ ipv6addr = getenv("OCF_RESKEY_ipv6addr");
+
if (ipv6addr == NULL) {
cl_log(LOG_ERR, "Please set OCF_RESKEY_ipv6addr to the IPv6 address you want to manage.");
usage(argv[0]);
@@ -271,12 +228,9 @@ main(int argc, char* argv[])
*cp=0;
}
- if (senduaflg) {
- cidr_netmask = argv[optind+1];
- } else {
- /* get provided netmask (optional) */
- cidr_netmask = getenv("OCF_RESKEY_cidr_netmask");
- }
+ /* get provided netmask (optional) */
+ cidr_netmask = getenv("OCF_RESKEY_cidr_netmask");
+
if (cidr_netmask != NULL) {
if ((atol(cidr_netmask) < 0) || (atol(cidr_netmask) > 128)) {
cl_log(LOG_ERR, "Invalid prefix_len [%s], "
@@ -294,12 +248,9 @@ main(int argc, char* argv[])
prefix_len = 0;
}
- if (senduaflg) {
- prov_ifname = argv[optind+2];
- } else {
- /* get provided interface name (optional) */
- prov_ifname = getenv("OCF_RESKEY_nic");
- }
+ /* get provided interface name (optional) */
+ prov_ifname = getenv("OCF_RESKEY_nic");
+
if (inet_pton(AF_INET6, ipv6addr, &addr6) <= 0) {
cl_log(LOG_ERR, "Invalid IPv6 address [%s]", ipv6addr);
usage(argv[0]);
@@ -312,15 +263,6 @@ main(int argc, char* argv[])
return OCF_ERR_GENERIC;
}
- if (senduaflg) {
- /* Send unsolicited advertisement packet to neighbor */
- for (i = 0; i < count; i++) {
- send_ua(&addr6, prov_ifname);
- usleep(interval * 1000);
- }
- return OCF_SUCCESS;
- }
-
/* create the pid file so we can make sure that only one IPv6addr
* for this address is running
*/
@@ -467,118 +409,6 @@ monitor_addr6(struct in6_addr* addr6, int prefix_len)
return OCF_NOT_RUNNING;
}
-/* Send an unsolicited advertisement packet
- * Please refer to rfc4861 / rfc3542
- */
-int
-send_ua(struct in6_addr* src_ip, char* if_name)
-{
- int status = -1;
- int fd;
-
- int ifindex;
- int hop;
- struct ifreq ifr;
- u_int8_t *payload = NULL;
- int payload_size;
- struct nd_neighbor_advert *na;
- struct nd_opt_hdr *opt;
- struct sockaddr_in6 src_sin6;
- struct sockaddr_in6 dst_sin6;
-
- if ((fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1) {
- cl_log(LOG_ERR, "socket(IPPROTO_ICMPV6) failed: %s",
- strerror(errno));
- return status;
- }
- /* set the outgoing interface */
- ifindex = if_nametoindex(if_name);
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
- &ifindex, sizeof(ifindex)) < 0) {
- cl_log(LOG_ERR, "setsockopt(IPV6_MULTICAST_IF) failed: %s",
- strerror(errno));
- goto err;
- }
- /* set the hop limit */
- hop = 255; /* 255 is required. see rfc4861 7.1.2 */
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
- &hop, sizeof(hop)) < 0) {
- cl_log(LOG_ERR, "setsockopt(IPV6_MULTICAST_HOPS) failed: %s",
- strerror(errno));
- goto err;
- }
-
- /* set the source address */
- memset(&src_sin6, 0, sizeof(src_sin6));
- src_sin6.sin6_family = AF_INET6;
- src_sin6.sin6_addr = *src_ip;
- src_sin6.sin6_port = 0;
- if (IN6_IS_ADDR_LINKLOCAL(&src_sin6.sin6_addr) ||
- IN6_IS_ADDR_MC_LINKLOCAL(&src_sin6.sin6_addr)) {
- src_sin6.sin6_scope_id = ifindex;
- }
-
- if (bind(fd, (struct sockaddr *)&src_sin6, sizeof(src_sin6)) < 0) {
- cl_log(LOG_ERR, "bind() failed: %s", strerror(errno));
- goto err;
- }
-
-
- /* get the hardware address */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1);
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
- cl_log(LOG_ERR, "ioctl(SIOCGIFHWADDR) failed: %s", strerror(errno));
- goto err;
- }
-
- /* build a neighbor advertisement message */
- payload_size = sizeof(struct nd_neighbor_advert)
- + sizeof(struct nd_opt_hdr) + HWADDR_LEN;
- payload = memalign(sysconf(_SC_PAGESIZE), payload_size);
- if (!payload) {
- cl_log(LOG_ERR, "malloc for payload failed");
- goto err;
- }
- memset(payload, 0, payload_size);
-
- /* Ugly typecast from ia64 hell! */
- na = (struct nd_neighbor_advert *)((void *)payload);
- na->nd_na_type = ND_NEIGHBOR_ADVERT;
- na->nd_na_code = 0;
- na->nd_na_cksum = 0; /* calculated by kernel */
- na->nd_na_flags_reserved = ND_NA_FLAG_OVERRIDE;
- na->nd_na_target = *src_ip;
-
- /* options field; set the target link-layer address */
- opt = (struct nd_opt_hdr *)(payload + sizeof(struct nd_neighbor_advert));
- opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
- opt->nd_opt_len = 1; /* The length of the option in units of 8 octets */
- memcpy(payload + sizeof(struct nd_neighbor_advert)
- + sizeof(struct nd_opt_hdr),
- &ifr.ifr_hwaddr.sa_data, HWADDR_LEN);
-
- /* sending an unsolicited neighbor advertisement to all */
- memset(&dst_sin6, 0, sizeof(dst_sin6));
- dst_sin6.sin6_family = AF_INET6;
- inet_pton(AF_INET6, BCAST_ADDR, &dst_sin6.sin6_addr); /* should not fail */
-
- if (sendto(fd, payload, payload_size, 0,
- (struct sockaddr *)&dst_sin6, sizeof(dst_sin6))
- != payload_size) {
- cl_log(LOG_ERR, "sendto(%s) failed: %s",
- if_name, strerror(errno));
- goto err;
- }
-
- status = 0;
-
-err:
- close(fd);
- free(payload);
- return status;
-}
-
/* find the network interface associated with an address */
char*
scan_if(struct in6_addr* addr_target, int* plen_target, int use_mask, char* prov_ifname)
@@ -822,12 +652,6 @@ static void usage(const char* self)
return;
}
-static void usage_send_ua(const char* self)
-{
- printf("usage: %s [-i[=Interval]] [-c[=Count]] [-h] IPv6-Address Prefix Interface\n",self);
- return;
-}
-
/* Following code is copied from send_arp.c, linux-HA project. */
void
byebye(int nsig)
diff --git a/heartbeat/IPv6addr_utils.c b/heartbeat/IPv6addr_utils.c
new file mode 100644
index 0000000..7672b70
--- /dev/null
+++ b/heartbeat/IPv6addr_utils.c
@@ -0,0 +1,147 @@
+
+/*
+ * This program manages IPv6 address with OCF Resource Agent standard.
+ *
+ * Author: Huang Zhen <zhenh@cn.ibm.com>
+ * Copyright (c) 2004 International Business Machines
+ *
+ * This library is free software; you can redistribute it and/or
+ * 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.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <IPv6addr.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <arpa/inet.h> /* for inet_pton */
+#include <net/if.h> /* for if_nametoindex */
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+
+/* Send an unsolicited advertisement packet
+ * Please refer to rfc4861 / rfc3542
+ */
+int
+send_ua(struct in6_addr* src_ip, char* if_name)
+{
+ int status = -1;
+ int fd;
+
+ int ifindex;
+ int hop;
+ struct ifreq ifr;
+ u_int8_t *payload = NULL;
+ int payload_size;
+ struct nd_neighbor_advert *na;
+ struct nd_opt_hdr *opt;
+ struct sockaddr_in6 src_sin6;
+ struct sockaddr_in6 dst_sin6;
+
+ if ((fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1) {
+ printf("ERROR: socket(IPPROTO_ICMPV6) failed: %s",
+ strerror(errno));
+ return status;
+ }
+ /* set the outgoing interface */
+ ifindex = if_nametoindex(if_name);
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+ &ifindex, sizeof(ifindex)) < 0) {
+ printf("ERROR: setsockopt(IPV6_MULTICAST_IF) failed: %s",
+ strerror(errno));
+ goto err;
+ }
+ /* set the hop limit */
+ hop = 255; /* 255 is required. see rfc4861 7.1.2 */
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+ &hop, sizeof(hop)) < 0) {
+ printf("ERROR: setsockopt(IPV6_MULTICAST_HOPS) failed: %s",
+ strerror(errno));
+ goto err;
+ }
+
+ /* set the source address */
+ memset(&src_sin6, 0, sizeof(src_sin6));
+ src_sin6.sin6_family = AF_INET6;
+ src_sin6.sin6_addr = *src_ip;
+ src_sin6.sin6_port = 0;
+ if (IN6_IS_ADDR_LINKLOCAL(&src_sin6.sin6_addr) ||
+ IN6_IS_ADDR_MC_LINKLOCAL(&src_sin6.sin6_addr)) {
+ src_sin6.sin6_scope_id = ifindex;
+ }
+
+ if (bind(fd, (struct sockaddr *)&src_sin6, sizeof(src_sin6)) < 0) {
+ printf("ERROR: bind() failed: %s", strerror(errno));
+ goto err;
+ }
+
+
+ /* get the hardware address */
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1);
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
+ printf("ERROR: ioctl(SIOCGIFHWADDR) failed: %s", strerror(errno));
+ goto err;
+ }
+
+ /* build a neighbor advertisement message */
+ payload_size = sizeof(struct nd_neighbor_advert)
+ + sizeof(struct nd_opt_hdr) + HWADDR_LEN;
+ payload = memalign(sysconf(_SC_PAGESIZE), payload_size);
+ if (!payload) {
+ printf("ERROR: malloc for payload failed");
+ goto err;
+ }
+ memset(payload, 0, payload_size);
+
+ /* Ugly typecast from ia64 hell! */
+ na = (struct nd_neighbor_advert *)((void *)payload);
+ na->nd_na_type = ND_NEIGHBOR_ADVERT;
+ na->nd_na_code = 0;
+ na->nd_na_cksum = 0; /* calculated by kernel */
+ na->nd_na_flags_reserved = ND_NA_FLAG_OVERRIDE;
+ na->nd_na_target = *src_ip;
+
+ /* options field; set the target link-layer address */
+ opt = (struct nd_opt_hdr *)(payload + sizeof(struct nd_neighbor_advert));
+ opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
+ opt->nd_opt_len = 1; /* The length of the option in units of 8 octets */
+ memcpy(payload + sizeof(struct nd_neighbor_advert)
+ + sizeof(struct nd_opt_hdr),
+ &ifr.ifr_hwaddr.sa_data, HWADDR_LEN);
+
+ /* sending an unsolicited neighbor advertisement to all */
+ memset(&dst_sin6, 0, sizeof(dst_sin6));
+ dst_sin6.sin6_family = AF_INET6;
+ inet_pton(AF_INET6, BCAST_ADDR, &dst_sin6.sin6_addr); /* should not fail */
+
+ if (sendto(fd, payload, payload_size, 0,
+ (struct sockaddr *)&dst_sin6, sizeof(dst_sin6))
+ != payload_size) {
+ printf("ERROR: sendto(%s) failed: %s",
+ if_name, strerror(errno));
+ goto err;
+ }
+
+ status = 0;
+
+err:
+ close(fd);
+ free(payload);
+ return status;
+}
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
index 0ce1c13..3393640 100644
--- a/heartbeat/Makefile.am
+++ b/heartbeat/Makefile.am
@@ -32,19 +32,23 @@ ocfdir = $(OCF_RA_DIR_PREFIX)/heartbeat
dtddir = $(datadir)/$(PACKAGE_NAME)
dtd_DATA = ra-api-1.dtd
-if USE_IPV6ADDR
+if USE_IPV6ADDR_AGENT
ocf_PROGRAMS = IPv6addr
-halib_PROGRAMS = send_ua
else
ocf_PROGRAMS =
+endif
+
+if IPV6ADDR_COMPATIBLE
+halib_PROGRAMS = send_ua
+else
halib_PROGRAMS =
endif
-IPv6addr_SOURCES = IPv6addr.c
-send_ua_SOURCES = IPv6addr.c
+IPv6addr_SOURCES = IPv6addr.c IPv6addr_utils.c
+send_ua_SOURCES = send_ua.c IPv6addr_utils.c
IPv6addr_LDADD = -lplumb $(LIBNETLIBS)
-send_ua_LDADD = -lplumb $(LIBNETLIBS)
+send_ua_LDADD = $(LIBNETLIBS)
ocf_SCRIPTS = ClusterMon \
CTDB \
diff --git a/heartbeat/send_ua.c b/heartbeat/send_ua.c
new file mode 100644
index 0000000..ef5357b
--- /dev/null
+++ b/heartbeat/send_ua.c
@@ -0,0 +1,127 @@
+
+/*
+ * This program manages IPv6 address with OCF Resource Agent standard.
+ *
+ * Author: Huang Zhen <zhenh@cn.ibm.com>
+ * Copyright (c) 2004 International Business Machines
+ *
+ * This library is free software; you can redistribute it and/or
+ * 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.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <IPv6addr.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <arpa/inet.h> /* for inet_pton */
+#include <net/if.h> /* for if_nametoindex */
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+
+static void usage_send_ua(const char* self);
+static void byebye(int nsig);
+
+int
+main(int argc, char* argv[])
+{
+ char* ipv6addr;
+ int count = UA_REPEAT_COUNT;
+ int interval = 1000; /* default 1000 msec */
+ int ch;
+ int i;
+ char* cp;
+ char* prov_ifname = NULL;
+ struct in6_addr addr6;
+
+ /* Check binary name */
+ if (argc < 4) {
+ usage_send_ua(argv[0]);
+ return OCF_ERR_ARGS;
+ }
+ while ((ch = getopt(argc, argv, "h?c:i:")) != EOF) {
+ switch(ch) {
+ case 'c': /* count option */
+ count = atoi(optarg);
+ break;
+ case 'i': /* interval option */
+ interval = atoi(optarg);
+ break;
+ case 'h':
+ case '?':
+ default:
+ usage_send_ua(argv[0]);
+ return OCF_ERR_ARGS;
+ }
+ }
+
+ /* set termination signal */
+ siginterrupt(SIGTERM, 1);
+ signal(SIGTERM, byebye);
+
+ ipv6addr = argv[optind];
+
+ if (ipv6addr == NULL) {
+ printf("ERROR: Please set OCF_RESKEY_ipv6addr to the IPv6 address you want to manage.");
+ usage_send_ua(argv[0]);
+ return OCF_ERR_ARGS;
+ }
+
+ /* legacy option */
+ if ((cp = strchr(ipv6addr, '/'))) {
+ *cp=0;
+ }
+
+ prov_ifname = argv[optind+2];
+
+ if (inet_pton(AF_INET6, ipv6addr, &addr6) <= 0) {
+ printf("ERROR: Invalid IPv6 address [%s]", ipv6addr);
+ usage_send_ua(argv[0]);
+ return OCF_ERR_ARGS;
+ }
+
+ /* Check whether this system supports IPv6 */
+ if (access(IF_INET6, R_OK)) {
+ printf("ERROR: No support for INET6 on this system.");
+ return OCF_ERR_GENERIC;
+ }
+
+ /* Send unsolicited advertisement packet to neighbor */
+ for (i = 0; i < count; i++) {
+ send_ua(&addr6, prov_ifname);
+ usleep(interval * 1000);
+ }
+
+ return OCF_SUCCESS;
+}
+
+static void usage_send_ua(const char* self)
+{
+ printf("usage: %s [-i[=Interval]] [-c[=Count]] [-h] IPv6-Address Prefix Interface\n",self);
+ return;
+}
+
+/* Following code is copied from send_arp.c, linux-HA project. */
+void
+byebye(int nsig)
+{
+ (void)nsig;
+ /* Avoid an "error exit" log message if we're killed */
+ exit(0);
+}
+
diff --git a/include/IPv6addr.h b/include/IPv6addr.h
new file mode 100644
index 0000000..720edf9
--- /dev/null
+++ b/include/IPv6addr.h
@@ -0,0 +1,58 @@
+/*
+ * This program manages IPv6 address with OCF Resource Agent standard.
+ *
+ * Author: Huang Zhen <zhenh@cn.ibm.com>
+ * Copyright (c) 2004 International Business Machines
+ *
+ * This library is free software; you can redistribute it and/or
+ * 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.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef OCF_IPV6_HELPER_H
+#define OCF_IPV6_HELPER_H
+#include <netinet/icmp6.h>
+#include <config.h>
+/*
+0 No error, action succeeded completely
+1 generic or unspecified error (current practice)
+ The "monitor" operation shall return this for a crashed, hung or
+ otherwise non-functional resource.
+2 invalid or excess argument(s)
+ Likely error code for validate-all, if the instance parameters
+ do not validate. Any other action is free to also return this
+ exit status code for this case.
+3 unimplemented feature (for example, "reload")
+4 user had insufficient privilege
+5 program is not installed
+6 program is not configured
+7 program is not running
+8 resource is running in "master" mode and fully operational
+9 resource is in "master" mode but in a failed state
+*/
+#define OCF_SUCCESS 0
+#define OCF_ERR_GENERIC 1
+#define OCF_ERR_ARGS 2
+#define OCF_ERR_UNIMPLEMENTED 3
+#define OCF_ERR_PERM 4
+#define OCF_ERR_INSTALLED 5
+#define OCF_ERR_CONFIGURED 6
+#define OCF_NOT_RUNNING 7
+
+#define HWADDR_LEN 6 /* mac address length */
+#define UA_REPEAT_COUNT 5
+#define BCAST_ADDR "ff02::1"
+#define IF_INET6 "/proc/net/if_inet6"
+
+int send_ua(struct in6_addr* src_ip, char* if_name);
+#endif
diff --git a/include/Makefile.am b/include/Makefile.am
index 5381ce0..6f46ec3 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -21,4 +21,4 @@ MAINTAINERCLEANFILES = Makefile.in config.h.in config.h.in~
idir=$(includedir)/heartbeat
i_HEADERS = agent_config.h
-noinst_HEADERS = config.h
+noinst_HEADERS = config.h IPv6addr.h
--
1.7.1