move common code of system_linux.c and system_aix.c into new system_common.c
authorMichael Adam <obnox@samba.org>
Sat, 28 Feb 2009 02:08:31 +0000 (03:08 +0100)
committerMichael Adam <obnox@samba.org>
Sat, 28 Feb 2009 02:08:31 +0000 (03:08 +0100)
Michael

Makefile.in
common/system_aix.c
common/system_common.c [new file with mode: 0644]
common/system_linux.c
include/ctdb_private.h

index 03023b393addc3653b6231ce356b44764a38867b..861aa8883a41e5212ebc41c9a3133d3a855b1dd9 100755 (executable)
@@ -41,7 +41,7 @@ UTIL_OBJ = lib/util/idtree.o lib/util/db_wrap.o lib/util/strlist.o lib/util/util
 
 CTDB_COMMON_OBJ =  common/ctdb_io.o common/ctdb_util.o \
        common/ctdb_ltdb.o common/ctdb_message.o common/cmdline.o  \
-       lib/util/debug.o common/rb_tree.o @CTDB_SYSTEM_OBJ@
+       lib/util/debug.o common/rb_tree.o @CTDB_SYSTEM_OBJ@ common/system_common.o
 
 CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
 
index d5ca4778646a8e4c8619ad5af525bd018ba9e38b..5fe54130d423595d34523c71a120a4a20d850093 100644 (file)
@@ -66,23 +66,6 @@ int ctdb_sys_open_sending_socket(void)
 }
 #endif
 
-/*
-  uint16 checksum for n bytes
- */
-static uint32_t uint16_checksum(uint16_t *data, size_t n)
-{
-       uint32_t sum=0;
-       while (n>=2) {
-               sum += (uint32_t)ntohs(*data);
-               data++;
-               n -= 2;
-       }
-       if (n == 1) {
-               sum += (uint32_t)ntohs(*(uint8_t *)data);
-       }
-       return sum;
-}
-
 /*
   simple TCP checksum - assumes data is multiple of 2 bytes long
  */
@@ -187,41 +170,6 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
        return 0;
 }
 
-
-/*
-  see if we currently have an interface with the given IP
-
-  we try to bind to it, and if that fails then we don't have that IP
-  on an interface
- */
-bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
-{
-       int s;
-       int ret;
-       ctdb_sock_addr __addr = *_addr;
-       ctdb_sock_addr *addr = &__addr;
-       
-       switch (addr->sa.sa_family) {
-       case AF_INET:
-               addr->ip.sin_port = 0;
-               break;
-       case AF_INET6:
-               addr->ip6.sin6_port = 0;
-               break;
-       }
-
-       s = socket(addr->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
-       if (s == -1) {
-               return false;
-       }
-       ret = bind(s, (struct sockaddr *)addr, sizeof(ctdb_sock_addr));
-       close(s);
-       return ret == 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)
diff --git a/common/system_common.c b/common/system_common.c
new file mode 100644 (file)
index 0000000..9aa4620
--- /dev/null
@@ -0,0 +1,72 @@
+/* 
+   ctdb system specific code to manage raw sockets on linux
+
+   Copyright (C) Ronnie Sahlberg  2007
+   Copyright (C) Andrew Tridgell  2007
+
+   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/>.
+*/
+
+#include "includes.h"
+#include "system/network.h"
+
+/*
+  uint16 checksum for n bytes
+ */
+uint32_t uint16_checksum(uint16_t *data, size_t n)
+{
+       uint32_t sum=0;
+       while (n>=2) {
+               sum += (uint32_t)ntohs(*data);
+               data++;
+               n -= 2;
+       }
+       if (n == 1) {
+               sum += (uint32_t)ntohs(*(uint8_t *)data);
+       }
+       return sum;
+}
+
+/*
+  see if we currently have an interface with the given IP
+
+  we try to bind to it, and if that fails then we don't have that IP
+  on an interface
+ */
+bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
+{
+       int s;
+       int ret;
+       ctdb_sock_addr __addr = *_addr;
+       ctdb_sock_addr *addr = &__addr;
+
+       switch (addr->sa.sa_family) {
+       case AF_INET:
+               addr->ip.sin_port = 0;
+               break;
+       case AF_INET6:
+               addr->ip6.sin6_port = 0;
+               break;
+       }
+
+       s = socket(addr->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
+       if (s == -1) {
+               return false;
+       }
+
+       ret = bind(s, (struct sockaddr *)addr, sizeof(ctdb_sock_addr));
+
+       close(s);
+       return ret == 0;
+}
index 0d5ea631b9d1118e3ae6346dee04952205886b96..a771e3ba04f377697bac8b4db93d79b8a9378b49 100644 (file)
 #define ETHERTYPE_IP6 0x86dd
 #endif
 
-/*
-  uint16 checksum for n bytes
- */
-static uint32_t uint16_checksum(uint16_t *data, size_t n)
-{
-       uint32_t sum=0;
-       while (n>=2) {
-               sum += (uint32_t)ntohs(*data);
-               data++;
-               n -= 2;
-       }
-       if (n == 1) {
-               sum += (uint32_t)ntohs(*(uint8_t *)data);
-       }
-       return sum;
-}
-
 /*
   calculate the tcp checksum for tcp over ipv6
 */
@@ -404,40 +387,6 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
        return 0;
 }
 
-
-/*
-  see if we currently have an interface with the given IP
-
-  we try to bind to it, and if that fails then we don't have that IP
-  on an interface
-
-  ifname, if non-NULL, will return the name of the interface this ip is tied to
- */
-bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
-{
-       int s;
-       int ret;
-       ctdb_sock_addr __addr = *_addr;
-       ctdb_sock_addr *addr = &__addr;
-
-       switch (addr->sa.sa_family) {
-       case AF_INET:
-               addr->ip.sin_port = 0;
-               break;
-       case AF_INET6:
-               addr->ip6.sin6_port = 0;
-               break;
-       }
-       s = socket(addr->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
-       if (s == -1) {
-               return false;
-       }
-       ret = bind(s, (struct sockaddr *)addr, sizeof(ctdb_sock_addr));
-
-       close(s);
-       return ret == 0;
-}
-
 /* 
    This function is used to open a raw socket to capture from
  */
index ceac3842bd72c10ac7352a81d79dd7c11849fcde..e62987484defdb21ae019c2de1263beec401045b 100644 (file)
@@ -1224,6 +1224,7 @@ int ctdb_ctrl_get_public_ipsv4(struct ctdb_context *ctdb,
 
 
 /* from takeover/system.c */
+uint32_t uint16_checksum(uint16_t *data, size_t n);
 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,