Merge branch 'master' of 10.1.1.27:/shared/ctdb/ctdb-master
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 20 Feb 2012 10:30:13 +0000 (21:30 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 20 Feb 2012 10:30:13 +0000 (21:30 +1100)
(This used to be ctdb commit 0fd3bf919b1b8e5aaa98444c306c6770a6a3209f)

14 files changed:
ctdb/Makefile.in
ctdb/common/ctdb_util.c
ctdb/common/system_freebsd.c [new file with mode: 0644]
ctdb/configure.ac
ctdb/libctdb/control.c
ctdb/libctdb/ctdb.c
ctdb/libctdb/io_elem.c
ctdb/libctdb/local_tdb.c
ctdb/libctdb/logging.c
ctdb/libctdb/messages.c
ctdb/libctdb/sync.c
ctdb/server/ctdb_daemon.c
ctdb/server/ctdb_takeover.c
ctdb/tools/ctdb.c

index 80008016b5c5848461c59cede4133a8bcfd9a0aa..52b2ef10984cd7f00231acbb5087dc1a8877fae9 100755 (executable)
@@ -35,7 +35,7 @@ PMDA_LIBS = -lpcp -lpcp_pmda
 PMDA_INSTALL = @CTDB_PMDA_INSTALL@
 PMDA_DEST_DIR = /var/lib/pcp/pmdas
 
-CFLAGS=-g -I$(srcdir)/include -Iinclude -Ilib -Ilib/util -I$(srcdir) \
+CFLAGS=@CPPFLAGS@ -g -I$(srcdir)/include -Iinclude -Ilib -Ilib/util -I$(srcdir) \
        -I@tallocdir@ -I@tdbdir@/include -I@libreplacedir@ \
        -DVARDIR=\"$(localstatedir)\" -DETCDIR=\"$(etcdir)\" \
        -DLOGDIR=\"$(logdir)\" \
index 1ff4c1f9aa2052cb97b46c54af6c579ab9ed430f..bb32b6a34591ae670300d7da84147430f69480a3 100644 (file)
@@ -522,7 +522,7 @@ void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip)
 #endif
                cip->ip.sin_family = AF_INET;
                cip->ip.sin_port   = ip->ip6.sin6_port;
-               memcpy(&cip->ip.sin_addr, &ip->ip6.sin6_addr.s6_addr32[3], 4);
+               memcpy(&cip->ip.sin_addr, &ip->ip6.sin6_addr.s6_addr[12], 4);
        }
 }
 
diff --git a/ctdb/common/system_freebsd.c b/ctdb/common/system_freebsd.c
new file mode 100644 (file)
index 0000000..c72b6f8
--- /dev/null
@@ -0,0 +1,371 @@
+/* 
+   ctdb system specific code to manage raw sockets on freebsd
+
+   Copyright (C) Ronnie Sahlberg  2007
+   Copyright (C) Andrew Tridgell  2007
+   Copyright (C) Marc Dequènes (Duck) 2009
+   Copyright (C) Volker Lendecke 2012
+
+   This program 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 3 of the License, or
+   (at your option) any later version.
+   
+   This program 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, see <http://www.gnu.org/licenses/>.
+
+
+  This file is a copy of 'common/system_linux.c' adapted for Hurd^W kFreeBSD
+  needs, and inspired by 'common/system_aix.c' for the pcap usage.
+*/
+
+#include "includes.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "system/wait.h"
+#include "../include/ctdb_private.h"
+#include "lib/tevent/tevent.h"
+#include <net/ethernet.h>
+#include <netinet/ip6.h>
+#include <net/if_arp.h>
+#include <pcap.h>
+
+
+#ifndef ETHERTYPE_IP6
+#define ETHERTYPE_IP6 0x86dd
+#endif
+
+/*
+  calculate the tcp checksum for tcp over ipv6
+*/
+static uint16_t tcp_checksum6(uint16_t *data, size_t n, struct ip6_hdr *ip6)
+{
+       uint32_t phdr[2];
+       uint32_t sum = 0;
+       uint16_t sum2;
+
+       sum += uint16_checksum((uint16_t *)(void *)&ip6->ip6_src, 16);
+       sum += uint16_checksum((uint16_t *)(void *)&ip6->ip6_dst, 16);
+
+       phdr[0] = htonl(n);
+       phdr[1] = htonl(ip6->ip6_nxt);
+       sum += uint16_checksum((uint16_t *)phdr, 8);
+
+       sum += uint16_checksum(data, n);
+
+       sum = (sum & 0xFFFF) + (sum >> 16);
+       sum = (sum & 0xFFFF) + (sum >> 16);
+       sum2 = htons(sum);
+       sum2 = ~sum2;
+       if (sum2 == 0) {
+               return 0xFFFF;
+       }
+       return sum2;
+}
+
+/*
+  send gratuitous arp reply after we have taken over an ip address
+
+  saddr is the address we are trying to claim
+  iface is the interface name we will be using to claim the address
+ */
+int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
+{
+       /* FIXME We dont do gratuitous arp on Hurd yet */
+       return 0;
+}
+
+
+/*
+  simple TCP checksum - assumes data is multiple of 2 bytes long
+ */
+static uint16_t tcp_checksum(uint16_t *data, size_t n, struct ip *ip)
+{
+       uint32_t sum = uint16_checksum(data, n);
+       uint16_t sum2;
+       sum += uint16_checksum((uint16_t *)(void *)&ip->ip_src,
+                              sizeof(ip->ip_src));
+       sum += uint16_checksum((uint16_t *)(void *)&ip->ip_dst,
+                              sizeof(ip->ip_dst));
+       sum += ip->ip_p + n;
+       sum = (sum & 0xFFFF) + (sum >> 16);
+       sum = (sum & 0xFFFF) + (sum >> 16);
+       sum2 = htons(sum);
+       sum2 = ~sum2;
+       if (sum2 == 0) {
+               return 0xFFFF;
+       }
+       return sum2;
+}
+
+/*
+  Send tcp segment from the specified IP/port to the specified
+  destination IP/port. 
+
+  This is used to trigger the receiving host into sending its own ACK,
+  which should trigger early detection of TCP reset by the client
+  after IP takeover
+
+  This can also be used to send RST segments (if rst is true) and also
+  if correct seq and ack numbers are provided.
+ */
+int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
+                     const ctdb_sock_addr *src,
+                     uint32_t seq, uint32_t ack, int rst)
+{
+       int s;
+       int ret;
+       uint32_t one = 1;
+       uint16_t tmpport;
+       ctdb_sock_addr *tmpdest;
+       struct {
+               struct ip ip;
+               struct tcphdr tcp;
+       } ip4pkt;
+       struct {
+               struct ip6_hdr ip6;
+               struct tcphdr tcp;
+       } ip6pkt;
+
+       switch (src->ip.sin_family) {
+       case AF_INET:
+               ZERO_STRUCT(ip4pkt);
+               ip4pkt.ip.ip_v  = 4;
+               ip4pkt.ip.ip_hl    = sizeof(ip4pkt.ip)/4;
+               ip4pkt.ip.ip_len   = htons(sizeof(ip4pkt));
+               ip4pkt.ip.ip_ttl   = 255;
+               ip4pkt.ip.ip_p     = IPPROTO_TCP;
+               ip4pkt.ip.ip_src.s_addr = src->ip.sin_addr.s_addr;
+               ip4pkt.ip.ip_dst.s_addr = dest->ip.sin_addr.s_addr;
+               ip4pkt.ip.ip_sum   = 0;
+
+               ip4pkt.tcp.th_sport = src->ip.sin_port;
+               ip4pkt.tcp.th_dport = dest->ip.sin_port;
+               ip4pkt.tcp.th_seq   = seq;
+               ip4pkt.tcp.th_ack   = ack;
+               ip4pkt.tcp.th_flags = 0;
+               ip4pkt.tcp.th_flags |= TH_ACK;
+               if (rst) {
+                       ip4pkt.tcp.th_flags |= TH_RST;
+               }
+               ip4pkt.tcp.th_off   = sizeof(ip4pkt.tcp)/4;
+               /* this makes it easier to spot in a sniffer */
+               ip4pkt.tcp.th_win   = htons(1234);
+               ip4pkt.tcp.th_sum   = tcp_checksum((uint16_t *)&ip4pkt.tcp, sizeof(ip4pkt.tcp), &ip4pkt.ip);
+
+               /* open a raw socket to send this segment from */
+               s = socket(AF_INET, SOCK_RAW, htons(IPPROTO_RAW));
+               if (s == -1) {
+                       DEBUG(DEBUG_CRIT,(__location__ " failed to open raw socket (%s)\n",
+                                strerror(errno)));
+                       return -1;
+               }
+
+               ret = setsockopt(s, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one));
+               if (ret != 0) {
+                       DEBUG(DEBUG_CRIT,(__location__ " failed to setup IP headers (%s)\n",
+                                strerror(errno)));
+                       close(s);
+                       return -1;
+               }
+
+               set_nonblocking(s);
+               set_close_on_exec(s);
+
+               ret = sendto(s, &ip4pkt, sizeof(ip4pkt), 0,
+                            (const struct sockaddr *)&dest->ip,
+                            sizeof(dest->ip));
+               close(s);
+               if (ret != sizeof(ip4pkt)) {
+                       DEBUG(DEBUG_CRIT,(__location__ " failed sendto (%s)\n", strerror(errno)));
+                       return -1;
+               }
+               break;
+       case AF_INET6:
+               ZERO_STRUCT(ip6pkt);
+               ip6pkt.ip6.ip6_vfc  = 0x60;
+               ip6pkt.ip6.ip6_plen = htons(20);
+               ip6pkt.ip6.ip6_nxt  = IPPROTO_TCP;
+               ip6pkt.ip6.ip6_hlim = 64;
+               ip6pkt.ip6.ip6_src  = src->ip6.sin6_addr;
+               ip6pkt.ip6.ip6_dst  = dest->ip6.sin6_addr;
+
+               ip6pkt.tcp.th_sport = src->ip6.sin6_port;
+               ip6pkt.tcp.th_dport = dest->ip6.sin6_port;
+               ip6pkt.tcp.th_seq   = seq;
+               ip6pkt.tcp.th_ack   = ack;
+               ip6pkt.tcp.th_flags = 0;
+               ip6pkt.tcp.th_flags |= TH_ACK;
+               if (rst) {
+                       ip6pkt.tcp.th_flags |= TH_RST;
+               }
+               ip6pkt.tcp.th_off   = sizeof(ip6pkt.tcp)/4;
+               /* this makes it easier to spot in a sniffer */
+               ip6pkt.tcp.th_win   = htons(1234);
+               ip6pkt.tcp.th_sum   = tcp_checksum6((uint16_t *)&ip6pkt.tcp, sizeof(ip6pkt.tcp), &ip6pkt.ip6);
+
+               s = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW);
+               if (s == -1) {
+                       DEBUG(DEBUG_CRIT, (__location__ " Failed to open sending socket\n"));
+                       return -1;
+
+               }
+               /* sendto() dont like if the port is set and the socket is
+                  in raw mode.
+               */
+               tmpdest = discard_const(dest);
+               tmpport = tmpdest->ip6.sin6_port;
+
+               tmpdest->ip6.sin6_port = 0;
+               ret = sendto(s, &ip6pkt, sizeof(ip6pkt), 0,
+                            (const struct sockaddr *)&dest->ip6,
+                            sizeof(dest->ip6));
+               tmpdest->ip6.sin6_port = tmpport;
+               close(s);
+
+               if (ret != sizeof(ip6pkt)) {
+                       DEBUG(DEBUG_CRIT,(__location__ " failed sendto (%s)\n", strerror(errno)));
+                       return -1;
+               }
+               break;
+
+       default:
+               DEBUG(DEBUG_CRIT,(__location__ " not an ipv4/v6 address\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
+/* 
+   This function is used to open a raw socket to capture from
+ */
+int ctdb_sys_open_capture_socket(const char *iface, void **private_data)
+{
+       pcap_t *pt;
+
+       pt=pcap_open_live(iface, 100, 0, 0, NULL);
+       if (pt == NULL) {
+               DEBUG(DEBUG_CRIT,("Failed to open capture device %s\n", iface));
+               return -1;
+       }
+       *((pcap_t **)private_data) = pt;
+
+       return pcap_fileno(pt);
+}
+
+/* This function is used to close the capture socket
+ */
+int ctdb_sys_close_capture_socket(void *private_data)
+{
+       pcap_t *pt = (pcap_t *)private_data;
+       pcap_close(pt);
+       return 0;
+}
+
+
+/*
+  called when the raw socket becomes readable
+ */
+int ctdb_sys_read_tcp_packet(int s, void *private_data, 
+                       ctdb_sock_addr *src, ctdb_sock_addr *dst,
+                       uint32_t *ack_seq, uint32_t *seq)
+{
+       int ret;
+#define RCVPKTSIZE 100
+       char pkt[RCVPKTSIZE];
+       struct ether_header *eth;
+       struct ip *ip;
+       struct ip6_hdr *ip6;
+       struct tcphdr *tcp;
+
+       ret = recv(s, pkt, RCVPKTSIZE, MSG_TRUNC);
+       if (ret < sizeof(*eth)+sizeof(*ip)) {
+               return -1;
+       }
+
+       /* Ethernet */
+       eth = (struct ether_header *)pkt;
+
+       /* we want either IPv4 or IPv6 */
+       if (ntohs(eth->ether_type) == ETHERTYPE_IP) {
+               /* IP */
+               ip = (struct ip *)(eth+1);
+
+               /* We only want IPv4 packets */
+               if (ip->ip_v != 4) {
+                       return -1;
+               }
+               /* Dont look at fragments */
+               if ((ntohs(ip->ip_off)&0x1fff) != 0) {
+                       return -1;
+               }
+               /* we only want TCP */
+               if (ip->ip_p != IPPROTO_TCP) {
+                       return -1;
+               }
+
+               /* make sure its not a short packet */
+               if (offsetof(struct tcphdr, th_ack) + 4 + 
+                   (ip->ip_hl*4) + sizeof(*eth) > ret) {
+                       return -1;
+               }
+               /* TCP */
+               tcp = (struct tcphdr *)((ip->ip_hl*4) + (char *)ip);
+
+               /* tell the caller which one we've found */
+               src->ip.sin_family      = AF_INET;
+               src->ip.sin_addr.s_addr = ip->ip_src.s_addr;
+               src->ip.sin_port        = tcp->th_sport;
+               dst->ip.sin_family      = AF_INET;
+               dst->ip.sin_addr.s_addr = ip->ip_dst.s_addr;
+               dst->ip.sin_port        = tcp->th_dport;
+               *ack_seq                = tcp->th_ack;
+               *seq                    = tcp->th_seq;
+
+               return 0;
+       } else if (ntohs(eth->ether_type) == ETHERTYPE_IP6) {
+               /* IP6 */
+               ip6 = (struct ip6_hdr *)(eth+1);
+
+               /* we only want TCP */
+               if (ip6->ip6_nxt != IPPROTO_TCP) {
+                       return -1;
+               }
+
+               /* TCP */
+               tcp = (struct tcphdr *)(ip6+1);
+
+               /* tell the caller which one we've found */
+               src->ip6.sin6_family = AF_INET6;
+               src->ip6.sin6_port   = tcp->th_sport;
+               src->ip6.sin6_addr   = ip6->ip6_src;
+
+               dst->ip6.sin6_family = AF_INET6;
+               dst->ip6.sin6_port   = tcp->th_dport;
+               dst->ip6.sin6_addr   = ip6->ip6_dst;
+
+               *ack_seq             = tcp->th_ack;
+               *seq                 = tcp->th_seq;
+
+               return 0;
+       }
+
+       return -1;
+}
+
+bool ctdb_sys_check_iface_exists(const char *iface)
+{
+       return true;
+}
+
+int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
+{
+       /* FIXME not implemented */
+       return 1;
+}
index 8a3bd7efb33b521272fe0d40b1d5457ee278813f..50d20a04a16d17f607eaefc99c77349acdb2043d 100644 (file)
@@ -33,6 +33,15 @@ case `uname` in
     CTDB_SCSI_IO=
     CTDB_PCAP_LDFLAGS=-lpcap
     ;;
+  FreeBSD)
+    CTDB_SYSTEM_OBJ=common/system_freebsd.o
+    CTDB_SCSI_IO=
+    CTDB_PCAP_LDFLAGS=-lpcap
+    LDFLAGS="$LDFLAGS -L/usr/local/lib -lexecinfo"
+    AC_SUBST(LDFLAGS)
+    CPPFLAGS="$CPPFLAGS -I/usr/local/include -D_FREEBSD_=1"
+    AC_SUBST(CPPFLAGS)
+    ;;
   GNU)
     CTDB_SYSTEM_OBJ=common/system_gnu.o
     CTDB_SCSI_IO=
index 8741ad9c0b2b1e1f50521bff1b6796fa03d4e9a3..b4c54cd660389e3458b0f315a4c21fe75b3f3348 100644 (file)
@@ -16,6 +16,7 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#include <sys/socket.h>
 #include <string.h>
 #include <ctdb.h>
 #include <ctdb_protocol.h>
index 13ccf9e4de4fc5f96991384b14081c85d4a95d02..191b097af172c2c4174271e989a0e3c0115d345d 100644 (file)
@@ -17,6 +17,8 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#include <sys/socket.h>
+#include <string.h>
 #include <ctdb.h>
 #include <poll.h>
 #include <errno.h>
index 81d44e4369a528409bc9f630e022f35211cbf178..572237b1c27494c6c001842d9a158e17f0faddfa 100644 (file)
@@ -17,6 +17,7 @@
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <string.h>
 #include <stdint.h>
 #include <stdbool.h>
index 705be2b548fb9a636cde77133414ec9e4689a02b..506e9740f59f73c9b411a570d1266f84c88ccaa9 100644 (file)
@@ -18,6 +18,7 @@
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <sys/socket.h>
 #include <ctdb.h>
 #include <tdb.h>
 #include <stdlib.h>
index 83f47742d75a108c96c26c6b1ee5ebae95a3880a..d897b6f61c09ebb8699c0c142e5b05945de9bead 100644 (file)
@@ -16,6 +16,7 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#include <sys/socket.h>
 #include <stdio.h>
 #include <errno.h>
 #include <ctdb.h>
index 66b41b52553305674bb21f8bb45ca870482211ad..254df028eb6dfd6f90cae2511a125af95c953cff 100644 (file)
@@ -17,6 +17,7 @@
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <sys/socket.h>
 #include "libctdb_private.h"
 #include "messages.h"
 #include "io_elem.h"
index 4b68cd1e32cc1278110679b0c557b5f58ffad26e..0e175f7f1296f911a401c680db352fd7a2d71dc0 100644 (file)
@@ -16,6 +16,7 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#include <sys/socket.h>
 #include <ctdb.h>
 #include <stdbool.h>
 #include <poll.h>
index 24369978648ebfb629f67676e1275a9701b84f8f..65ad055b1b95e98cd383ec6cb93178aaa6885c80 100644 (file)
@@ -288,6 +288,10 @@ static void daemon_request_message_from_client(struct ctdb_client *client,
        TDB_DATA data;
        int res;
 
+       if (c->hdr.destnode == CTDB_CURRENT_NODE) {
+               c->hdr.destnode = ctdb_get_pnn(client->ctdb);
+       }
+
        /* maybe the message is for another client on this node */
        if (ctdb_get_pnn(client->ctdb)==c->hdr.destnode) {
                ctdb_request_message(client->ctdb, (struct ctdb_req_header *)c);
index 87e1b0001d6da31f137e3a45ccea4bd4bb5c4b67..830b751b03625efd20ab5f0ca9f78515c440c62e 100644 (file)
@@ -1222,12 +1222,14 @@ static uint32_t *ip_key(ctdb_sock_addr *ip)
        case AF_INET:
                key[3]  = htonl(ip->ip.sin_addr.s_addr);
                break;
-       case AF_INET6:
-               key[0]  = htonl(ip->ip6.sin6_addr.s6_addr32[0]);
-               key[1]  = htonl(ip->ip6.sin6_addr.s6_addr32[1]);
-               key[2]  = htonl(ip->ip6.sin6_addr.s6_addr32[2]);
-               key[3]  = htonl(ip->ip6.sin6_addr.s6_addr32[3]);
+       case AF_INET6: {
+               uint32_t *s6_a32 = (uint32_t *)&(ip->ip6.sin6_addr.s6_addr);
+               key[0]  = htonl(s6_a32[0]);
+               key[1]  = htonl(s6_a32[1]);
+               key[2]  = htonl(s6_a32[2]);
+               key[3]  = htonl(s6_a32[3]);
                break;
+       }
        default:
                DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family passed :%u\n", ip->sa.sa_family));
                return key;
@@ -2800,18 +2802,23 @@ static uint32_t *killtcp_key(ctdb_sock_addr *src, ctdb_sock_addr *dst)
                key[2]  = dst->ip.sin_port;
                key[3]  = src->ip.sin_port;
                break;
-       case AF_INET6:
-               key[0]  = dst->ip6.sin6_addr.s6_addr32[3];
-               key[1]  = src->ip6.sin6_addr.s6_addr32[3];
-               key[2]  = dst->ip6.sin6_addr.s6_addr32[2];
-               key[3]  = src->ip6.sin6_addr.s6_addr32[2];
-               key[4]  = dst->ip6.sin6_addr.s6_addr32[1];
-               key[5]  = src->ip6.sin6_addr.s6_addr32[1];
-               key[6]  = dst->ip6.sin6_addr.s6_addr32[0];
-               key[7]  = src->ip6.sin6_addr.s6_addr32[0];
+       case AF_INET6: {
+               uint32_t *dst6_addr32 =
+                       (uint32_t *)&(dst->ip6.sin6_addr.s6_addr);
+               uint32_t *src6_addr32 =
+                       (uint32_t *)&(src->ip6.sin6_addr.s6_addr);
+               key[0]  = dst6_addr32[3];
+               key[1]  = src6_addr32[3];
+               key[2]  = dst6_addr32[2];
+               key[3]  = src6_addr32[2];
+               key[4]  = dst6_addr32[1];
+               key[5]  = src6_addr32[1];
+               key[6]  = dst6_addr32[0];
+               key[7]  = src6_addr32[0];
                key[8]  = dst->ip6.sin6_port;
                key[9]  = src->ip6.sin6_port;
                break;
+       }
        default:
                DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family passed :%u\n", src->sa.sa_family));
                return key;
index aeb14c951ba8ff5fc8ae2c28b848c01c1e17a794..a9fbddcf78852f45151fe2d1a279762acbe893ee 100644 (file)
@@ -1601,12 +1601,14 @@ static uint32_t *ip_key(ctdb_sock_addr *ip)
        case AF_INET:
                key[0]  = ip->ip.sin_addr.s_addr;
                break;
-       case AF_INET6:
-               key[0]  = ip->ip6.sin6_addr.s6_addr32[3];
-               key[1]  = ip->ip6.sin6_addr.s6_addr32[2];
-               key[2]  = ip->ip6.sin6_addr.s6_addr32[1];
-               key[3]  = ip->ip6.sin6_addr.s6_addr32[0];
+       case AF_INET6: {
+               uint32_t *s6_a32 = (uint32_t *)&(ip->ip6.sin6_addr.s6_addr);
+               key[0]  = s6_a32[3];
+               key[1]  = s6_a32[2];
+               key[2]  = s6_a32[1];
+               key[3]  = s6_a32[0];
                break;
+       }
        default:
                DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family passed :%u\n", ip->sa.sa_family));
                return key;