[SCM] CTDB repository - branch master updated - a06abf6bff6c4d379453e5063d8de1a6542c982a

Andrew Tridgell tridge at samba.org
Wed Sep 17 11:01:14 GMT 2008


The branch, master has been updated
       via  a06abf6bff6c4d379453e5063d8de1a6542c982a (commit)
       via  475cfada33b4c13aaaca773d5485bbe26bffbf46 (commit)
       via  196968c552e6ebcb57389d769a4b25f42fa8bc5d (commit)
       via  5e641ef9d6cca286061138a9680dcf2495736e8b (commit)
       via  95bf36559d62f29e6f538f3a173b504ef3258341 (commit)
       via  0aca4daf908b76d6013ff3dfad41beb9114fc1a3 (commit)
       via  a120c734c5425ebb2e09c2009374aa0bc5a432e8 (commit)
       via  2583d0c8f9932e023b7377582f62c840e264be80 (commit)
       via  1d5d13345086201fe55517aea5f8674ff3db1090 (commit)
       via  2b70953cd51e879dc1fa113d68c6614051da5260 (commit)
       via  3ff0711fd3b288c153218ad33e8462a94b8d3275 (commit)
       via  d1aa7953450de6ae215589404fb19e05edd3906f (commit)
       via  666c3835376cd6b66aeaa110c76ecf052cd71a0a (commit)
       via  616b71fef54a3d1ea2638602099722a19ef6f41d (commit)
       via  a72f5b7d1560e427e18b1c55a2932a7fb037f4c7 (commit)
       via  a89977f8cb2463a87147dcc0ad936cb5d4131670 (commit)
       via  cd69d292292eaab3aac0e9d9fc57cb621597c63c (commit)
       via  e26ce5140ed005725f8b7ac8ba23a180fd7d5337 (commit)
       via  8060e591b0eb2d184b5a7444487477225d2e1dbf (commit)
       via  c4bc4317df4106e81b238dbfaf861ca6104304c1 (commit)
       via  4d1c0418cfe6170bc081684dbe45908a5d285f0b (commit)
       via  f84d0a9a8c7e9589e8833f21e1f977a0adab356b (commit)
       via  2a8bf5e7dc7364a8280d96db0f9579d2582a8524 (commit)
       via  0709093af11e0735ed1e13b06ac073990631e692 (commit)
       via  7da0c65c8526d66d4f2a788bd646d39237befa54 (commit)
       via  12bc85c90a640a72ff538c003eb81da9dd1f2e3f (commit)
       via  4dfbfb4618433d9ed79ca1bdb1e2e51d96d4ee62 (commit)
       via  293d12a40501320a21efaf592b8f20e8590a5197 (commit)
       via  2f8b33948e395228cbac3450c0c684e49069abf0 (commit)
       via  1157d61a0bc557d8ffc453c518dfc48473492bfd (commit)
       via  b0fe4c45fc5ba1ecf62ebb921092c8a34e28a2bd (commit)
       via  6da7b36b7ccc4ee9b809867ea32036f09a801bb3 (commit)
       via  83735951352a243da185031e4853e7e40c43a0fb (commit)
       via  0a38ea11af9237501f2951fee698a59b46f8750d (commit)
       via  bf6effef0cc9e5f2eeeb38fce855a90624a76239 (commit)
       via  1f131f21386f428bbbbb29098d56c2f64596583b (commit)
       via  48fad9c06185a1f2580473cac02b3722e35c2023 (commit)
       via  ff413beb4bb31e277e843235a1ce5e5ad7b92c71 (commit)
       via  0674b33a7492cc1a194833f5ca87d8b30457faee (commit)
       via  77762170ad1dbc4620565bb898af5d493fac117d (commit)
       via  b567e215f5c58d646a392408b9cc1df8ef029b33 (commit)
       via  d6061214b4ef7e628ba7d27d81f23174c5364f67 (commit)
       via  a09864519d04f1e6a7ba498a795b6390183902a8 (commit)
       via  082dd600ef25431efbf087ebf1957fbfd61cf104 (commit)
      from  c4ad24e7c2b27b168d43ebfa95c459da27697d1e (commit)

http://gitweb.samba.org/?p=tridge/ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a06abf6bff6c4d379453e5063d8de1a6542c982a
Author: Andrew Tridgell <tridge at samba.org>
Date:   Wed Sep 17 21:00:04 2008 +1000

    expanded ctdb_diagnostics based on recent experience

commit 475cfada33b4c13aaaca773d5485bbe26bffbf46
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Sep 17 14:24:12 2008 +1000

    use the correct tunable   failcount not timeout

commit 196968c552e6ebcb57389d769a4b25f42fa8bc5d
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Sep 17 14:17:41 2008 +1000

    The ctdb daemon keeps track of whether the recovery process is running
    correctly by measuring how long it was since the last successful
    communication with the recovery daemon was recorded.
    
    After a certain timeout the ctdb daemon would deem the recovery daemon
    as inoperable and shut down.
    
    If the system clock is suddenly changed forward by many (60 or more)
    seconds this could cause the timeout to trigger prematurely/immediately
    where ctdb would incorrectly think that more than 60 seconds had passed
    since last successful communications and thus abort.
    
    Instead of cehcking for one timeout occuring, only deem the recovery
    daemon to be "down" and trigger a shutdown if communications have
    timedout for three intervals in a row.

commit 5e641ef9d6cca286061138a9680dcf2495736e8b
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 16 09:00:48 2008 +1000

    fix a slow memory leak in the recovery daemon in the error paths for the
    memdump function

commit 95bf36559d62f29e6f538f3a173b504ef3258341
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 16 07:55:57 2008 +1000

    fix some slow memory leaks in the vacuuming handler in the recovery
    daemon

commit 0aca4daf908b76d6013ff3dfad41beb9114fc1a3
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 16 06:50:28 2008 +1000

    From Volker L
    Fix a slow memory leak in the recovery daemon if there is a recoery
    triggered during the public ip reassignment process

commit a120c734c5425ebb2e09c2009374aa0bc5a432e8
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Sep 15 07:04:26 2008 +1000

    updates to the precompiled documentation

commit 2583d0c8f9932e023b7377582f62c840e264be80
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 18:20:52 2008 +1000

    Document the new descriptive node specifications.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 1d5d13345086201fe55517aea5f8674ff3db1090
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 16:55:18 2008 +1000

    onnode changes.  "ok" is an alias for "healthy", "con" is an alias for
    "connected".  Allow "rm" or "recmaster" to be a nodespec for the
    recovery master. Better error handling for interaction with ctdb
    client.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 2b70953cd51e879dc1fa113d68c6614051da5260
Merge: d1aa7953450de6ae215589404fb19e05edd3906f 3ff0711fd3b288c153218ad33e8462a94b8d3275
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 18:21:51 2008 +1000

    Merge commit 'origin/master' into for-ronnie

commit 3ff0711fd3b288c153218ad33e8462a94b8d3275
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Sep 12 12:06:53 2008 +1000

    i add a new ctdb command "ctdb recmaster"
    this shows the node id of hte current recmaster

commit d1aa7953450de6ae215589404fb19e05edd3906f
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 11:22:50 2008 +1000

    Changes to onnode.  Add "healthy" and "connected" as possible
    nodespecs.  Since we're now explicitly using bash, use local variables
    when sensible.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 666c3835376cd6b66aeaa110c76ecf052cd71a0a
Merge: 616b71fef54a3d1ea2638602099722a19ef6f41d a72f5b7d1560e427e18b1c55a2932a7fb037f4c7
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 11:26:25 2008 +1000

    Merge commit 'origin/master' into for-ronnie

commit 616b71fef54a3d1ea2638602099722a19ef6f41d
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Sep 12 10:36:15 2008 +1000

    Minor documentation fixes.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit a72f5b7d1560e427e18b1c55a2932a7fb037f4c7
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 9 13:59:48 2008 +1000

    lower the debuglevel when logging unknown idr in responses

commit a89977f8cb2463a87147dcc0ad936cb5d4131670
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 9 13:55:31 2008 +1000

    lower the debug level for when printing that the nodeflags have changed

commit cd69d292292eaab3aac0e9d9fc57cb621597c63c
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Sep 9 13:44:46 2008 +1000

    additional monitoring between the two daemons.
    
    we currently only monitor that the dameons are running by kill(0, pid)
    and verifying the the domain socket between them is ok.
    
    this is not sufficient since we can have a situation where the recovery
    daemon is hung.
    
    this new code monitors that the recovery daemon is operating.
    if the recovery hangs, we log this and shut down the main daemon

commit e26ce5140ed005725f8b7ac8ba23a180fd7d5337
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Sep 8 08:57:42 2008 +1000

    From C Cowan.
    Patch to make AIX compile with the new ipv6 additions.

commit 8060e591b0eb2d184b5a7444487477225d2e1dbf
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Aug 29 12:26:02 2008 +1000

    zero out the address structure to keep valgrind happy

commit c4bc4317df4106e81b238dbfaf861ca6104304c1
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 27 10:26:34 2008 +1000

    new version 1.0.58

commit 4d1c0418cfe6170bc081684dbe45908a5d285f0b
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 27 10:24:35 2008 +1000

    rename ctdb_tcp_client back to the original name ctdb_control_tcp

commit f84d0a9a8c7e9589e8833f21e1f977a0adab356b
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Aug 25 10:13:18 2008 +1000

    From Abhijith Das <adas at redhat.com>:
    
    Fixup the initscript sdo it passes rpm-lint

commit 2a8bf5e7dc7364a8280d96db0f9579d2582a8524
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Aug 25 10:03:16 2008 +1000

    Add a "reload" option to the initscript.

commit 0709093af11e0735ed1e13b06ac073990631e692
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Aug 25 09:41:08 2008 +1000

    add a link to my webpage

commit 7da0c65c8526d66d4f2a788bd646d39237befa54
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Aug 25 08:52:29 2008 +1000

    version 1.0.57   : initial ipv6 support

commit 12bc85c90a640a72ff538c003eb81da9dd1f2e3f
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Aug 22 09:25:47 2008 +1000

    Do not fail the takeip event if the "ip addr add ..." command failed.
    Let the event complete successfully.   the local recovery daemon will check that we have the address and reissue takip othervise.
    
    There are several reasons why "ip addr add "  can fail, one is a misconfiguration
    anothe ris that for ipv6 the stack is a lot more picky than for ipv4.     for examplke this WILL fail in ipv6 if there is a duplicate ip address on the network.
    
    thus  this check could cause rolling-recoveries  which is why it has to go

commit 4dfbfb4618433d9ed79ca1bdb1e2e51d96d4ee62
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Aug 22 09:09:08 2008 +1000

    when we collect all ip addresses and sort them for the "ctdb ip -n all" output we must look at more than just the first 4 bytes of the sockaddr address or ipv6 wont work

commit 293d12a40501320a21efaf592b8f20e8590a5197
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 12:50:50 2008 +1000

    When we harvest all tcp connections to kill off after a takeip/releaseip event we must also harvest the ipv4 connections which may be presented in ::ff:xxxx:xxxx form by netstat

commit 2f8b33948e395228cbac3450c0c684e49069abf0
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 12:02:54 2008 +1000

    we must canonicalize the sockaddr structures in killtcp so that we do the necessary downgrade if required

commit 1157d61a0bc557d8ffc453c518dfc48473492bfd
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 11:58:27 2008 +1000

    make the function to canonicalize a sockaddr structure public

commit b0fe4c45fc5ba1ecf62ebb921092c8a34e28a2bd
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 11:52:36 2008 +1000

    when we compare ip addresses in ctdb_same_ip we must first canonicalize the addresses  so that we realize that 127.0.0.1:22 is really the same thing as ::ffff:127.0.0.1:22
    
    Downgrade all AF_INET6 ::ffff:xxxx:xxxx sockaddresses into AF_INET ones

commit 6da7b36b7ccc4ee9b809867ea32036f09a801bb3
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 09:47:00 2008 +1000

    update the socketkiller in the eventscripts to be able to handle ipv6

commit 83735951352a243da185031e4853e7e40c43a0fb
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 20 09:23:31 2008 +1000

    fix a bug in the tcp socketkiller for ipv6

commit 0a38ea11af9237501f2951fee698a59b46f8750d
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Aug 19 18:24:08 2008 +1000

    fix the ipv6 checksum calculation for pseudoheader so that it actually works
    
    add support to send ipv6 "gratious arp" aka neighbor solicitation packets from ctdb
    
    Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>

commit bf6effef0cc9e5f2eeeb38fce855a90624a76239
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Aug 19 14:58:57 2008 +1000

    remove a file we dont need
    
    Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>

commit 1f131f21386f428bbbbb29098d56c2f64596583b
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue Aug 19 14:58:29 2008 +1000

    initial ipv6 patch
    
    Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>

commit 48fad9c06185a1f2580473cac02b3722e35c2023
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Aug 14 10:57:08 2008 +1000

    use a local tdb_traverse instead of a ctdb_pulldb to lessen the impact of the system while performing a database backup

commit ff413beb4bb31e277e843235a1ce5e5ad7b92c71
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Aug 14 09:52:23 2008 +1000

    only freeze the local node when doing a backup and not the entire cluster

commit 0674b33a7492cc1a194833f5ca87d8b30457faee
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Aug 14 08:36:39 2008 +1000

    store the database name, not the backup filename in the database header

commit 77762170ad1dbc4620565bb898af5d493fac117d
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Aug 14 08:35:19 2008 +1000

    Encode a file version number in the database backup header
    Encode the database name in the header so we dont need to provide the database
    name when doing a restore
    Encode a timestamp in the header telling us when the backup was created

commit b567e215f5c58d646a392408b9cc1df8ef029b33
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 13 22:03:29 2008 +1000

    Add two new ctdb commands :
    
    ctdb backupdb : which will copy a database out from ctdb and write it to a file
    ctdb restoredb : which will read a database backup from a file and write it into ctdb

commit d6061214b4ef7e628ba7d27d81f23174c5364f67
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jul 11 15:05:41 2008 +1000

    Signed-off-by: Martin Schwenke <martin at meltin.net>
    
    Minor updates to doc/onnode.1.xml.

commit a09864519d04f1e6a7ba498a795b6390183902a8
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jul 11 14:57:24 2008 +1000

    Signed-off-by: Martin Schwenke <martin at meltin.net>
    
    Minor fix to tools/onnode usage message.

commit 082dd600ef25431efbf087ebf1957fbfd61cf104
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Jul 11 12:52:01 2008 +1000

    Signed-off-by: Martin Schwenke <martin at meltin.net>
    
    In tools/onnode, remove reference to -t option in usage message.

-----------------------------------------------------------------------

Summary of changes:
 client/ctdb_client.c         |   24 ++-
 common/ctdb_util.c           |  143 ++++++++-----
 common/system_aix.c          |  108 ++++++----
 common/system_linux.c        |  260 +++++++++++++++-------
 config/ctdb.init             |   24 +-
 config/events.d/10.interface |    1 -
 config/functions             |   14 +-
 doc/ctdb.1                   |  296 +++++++++++++-------------
 doc/ctdb.1.html              |   98 +++++-----
 doc/ctdb.1.xml               |    2 +-
 doc/ctdbd.1                  |  319 ++++++++++++++--------------
 doc/ctdbd.1.html             |   72 +++---
 doc/ctdbd.1.xml              |   22 +-
 doc/onnode.1                 |    8 +-
 doc/onnode.1.html            |   16 +-
 doc/onnode.1.xml             |   65 +++++-
 include/ctdb.h               |    1 +
 include/ctdb_private.h       |   58 +++---
 packaging/RPM/ctdb.spec      |    8 +-
 server/ctdb_control.c        |    6 +-
 server/ctdb_daemon.c         |    5 +-
 server/ctdb_recover.c        |   54 +++++-
 server/ctdb_recoverd.c       |   26 ++-
 server/ctdb_takeover.c       |  380 ++++++++++++++++++---------------
 server/ctdb_tunables.c       |    2 +
 server/ctdbd.c               |    6 +-
 tcp/tcp_connect.c            |  131 +++++++----
 tests/nodes.txt              |    3 -
 tests/start_daemons.sh       |    9 +-
 tools/ctdb.c                 |  485 +++++++++++++++++++++++++++++++++++++-----
 tools/ctdb_diagnostics       |   11 +-
 tools/onnode                 |  103 ++++++++--
 utils/ipmux/ipmux.c          |    8 +-
 web/index.html               |    2 +-
 34 files changed, 1801 insertions(+), 969 deletions(-)


Changeset truncated at 500 lines:

diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 0d85374..6d80efc 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -2422,15 +2422,15 @@ int ctdb_ctrl_gratious_arp(struct ctdb_context *ctdb,
 int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, 
 			      struct timeval timeout, uint32_t destnode, 
 			      TALLOC_CTX *mem_ctx, 
-			      struct sockaddr_in *ip,
+			      ctdb_sock_addr *addr,
 			      struct ctdb_control_tcp_tickle_list **list)
 {
 	int ret;
 	TDB_DATA data, outdata;
 	int32_t status;
 
-	data.dptr = (uint8_t*)ip;
-	data.dsize = sizeof(struct sockaddr_in);
+	data.dptr = (uint8_t*)addr;
+	data.dsize = sizeof(ctdb_sock_addr);
 
 	ret = ctdb_control(ctdb, destnode, 0, 
 			   CTDB_CONTROL_GET_TCP_TICKLE_LIST, 0, data, 
@@ -3280,3 +3280,21 @@ again:
 	talloc_free(h);
 	return 0;
 }
+
+/*
+  recovery daemon ping to main daemon
+ */
+int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb)
+{
+	int ret;
+	int32_t res;
+
+	ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_RECD_PING, 0, tdb_null, 
+			   ctdb, NULL, &res, NULL, NULL);
+	if (ret != 0 || res != 0) {
+		DEBUG(DEBUG_ERR,("Failed to send recd ping\n"));
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/common/ctdb_util.c b/common/ctdb_util.c
index b096a52..cc68291 100644
--- a/common/ctdb_util.c
+++ b/common/ctdb_util.c
@@ -147,7 +147,7 @@ void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *ty
 
 	p = _idr_find_type(ctdb->idr, (reqid>>16)&0xFFFF, type, location);
 	if (p == NULL) {
-		DEBUG(DEBUG_ERR, ("Could not find idr:%u\n",reqid));
+		DEBUG(DEBUG_WARNING, ("Could not find idr:%u\n",reqid));
 	}
 
 	return p;
@@ -362,40 +362,6 @@ void set_close_on_exec(int fd)
 }
 
 
-/*
-  parse a ip:num pair with the given separator
- */
-static bool parse_ip_num(const char *s, struct in_addr *addr, unsigned *num, const char sep)
-{
-	const char *p;
-	char *endp = NULL;
-	char buf[16];
-
-	p = strchr(s, sep);
-	if (p == NULL) {
-		return false;
-	}
-
-	if (p - s > 15) {
-		return false;
-	}
-
-	*num = strtoul(p+1, &endp, 10);
-	if (endp == NULL || *endp != 0) {
-		/* trailing garbage */
-		return false;
-	}
-
-	strlcpy(buf, s, 1+p-s);
-
-	if (inet_aton(buf, addr) == 0) {
-		return false;
-	}
-
-	return true;
-}
-
-
 static bool parse_ipv4(const char *s, unsigned port, ctdb_sock_addr *saddr)
 {
 	saddr->ip.sin_family = AF_INET;
@@ -492,45 +458,91 @@ bool parse_ip(const char *addr, ctdb_sock_addr *saddr)
 /*
   parse a ip/mask pair
  */
-bool parse_ip_mask(const char *s, struct sockaddr_in *ip, unsigned *mask)
+bool parse_ip_mask(const char *str, ctdb_sock_addr *addr, unsigned *mask)
 {
-	ZERO_STRUCT(*ip);
+	TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+	char *s, *p;
+	char *endp = NULL;
+	bool ret;
 
-	if (!parse_ip_num(s, &ip->sin_addr, mask, '/')) {
+	ZERO_STRUCT(*addr);
+	s = talloc_strdup(tmp_ctx, str);
+	if (s == NULL) {
+		DEBUG(DEBUG_ERR, (__location__ " Failed strdup()\n"));
+		talloc_free(tmp_ctx);
 		return false;
 	}
-	if (*mask > 32) {
+
+	p = rindex(s, '/');
+	if (p == NULL) {
+		DEBUG(DEBUG_ERR, (__location__ " This addr: %s does not contain a mask\n", s));
+		talloc_free(tmp_ctx);
 		return false;
 	}
-	ip->sin_family = AF_INET;
-	ip->sin_port   = 0;
-	return true;
+
+	*mask = strtoul(p+1, &endp, 10);
+	if (endp == NULL || *endp != 0) {
+		/* trailing garbage */
+		DEBUG(DEBUG_ERR, (__location__ " Trailing garbage after the mask in %s\n", s));
+		talloc_free(tmp_ctx);
+		return false;
+	}
+	*p = 0;
+
+
+	/* now is this a ipv4 or ipv6 address ?*/
+	p = index(s, ':');
+	if (p == NULL) {
+		ret = parse_ipv4(s, 0, addr);
+	} else {
+		ret = parse_ipv6(s, 0, addr);
+	}
+
+	talloc_free(tmp_ctx);
+	return ret;
 }
 
 /*
-  compare two sockaddr_in structures - matching only on IP
- */
-bool ctdb_same_ipv4(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2)
+   This is used to canonicalize a ctdb_sock_addr structure.
+*/
+void ctdb_canonicalize_ip(const ctdb_sock_addr *ip, ctdb_sock_addr *cip)
 {
-	return ip1->sin_family == ip2->sin_family &&
-		ip1->sin_addr.s_addr == ip2->sin_addr.s_addr;
+	char prefix[12] = { 0,0,0,0,0,0,0,0,0,0,0xff,0xff };
+
+	memcpy(cip, ip, sizeof (*cip));
+
+	if ( (ip->sa.sa_family == AF_INET6)
+	&& !memcmp(&ip->ip6.sin6_addr, prefix, 12)) {
+		memset(cip, 0, sizeof(*cip));
+#ifdef HAVE_SOCK_SIN_LEN
+		cip->ip.sin_len = sizeof(*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);
+	}
 }
 
-bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2)
+bool ctdb_same_ip(const ctdb_sock_addr *tip1, const ctdb_sock_addr *tip2)
 {
-	if (ip1->sa.sa_family != ip2->sa.sa_family) {
+	ctdb_sock_addr ip1, ip2;
+
+	ctdb_canonicalize_ip(tip1, &ip1);
+	ctdb_canonicalize_ip(tip2, &ip2);
+	
+	if (ip1.sa.sa_family != ip2.sa.sa_family) {
 		return false;
 	}
 
-	switch (ip1->sa.sa_family) {
+	switch (ip1.sa.sa_family) {
 	case AF_INET:
-		return ip1->ip.sin_addr.s_addr == ip2->ip.sin_addr.s_addr;
+		return ip1.ip.sin_addr.s_addr == ip2.ip.sin_addr.s_addr;
 	case AF_INET6:
-		return !memcmp(&ip1->ip6.sin6_addr.s6_addr[0],
-				&ip2->ip6.sin6_addr.s6_addr[0],
+		return !memcmp(&ip1.ip6.sin6_addr.s6_addr[0],
+				&ip2.ip6.sin6_addr.s6_addr[0],
 				16);
 	default:
-		DEBUG(DEBUG_ERR, (__location__ " CRITICAL Can not compare sockaddr structures of type %u\n", ip1->sa.sa_family));
+		DEBUG(DEBUG_ERR, (__location__ " CRITICAL Can not compare sockaddr structures of type %u\n", ip1.sa.sa_family));
 		return false;
 	}
 
@@ -538,13 +550,30 @@ bool ctdb_same_ip(ctdb_sock_addr *ip1, ctdb_sock_addr *ip2)
 }
 
 /*
-  compare two sockaddr_in structures
+  compare two ctdb_sock_addr structures
  */
-bool ctdb_same_sockaddr(const struct sockaddr_in *ip1, const struct sockaddr_in *ip2)
+bool ctdb_same_sockaddr(const ctdb_sock_addr *ip1, const ctdb_sock_addr *ip2)
 {
-	return ctdb_same_ipv4(ip1, ip2) && ip1->sin_port == ip2->sin_port;
+	return ctdb_same_ip(ip1, ip2) && ip1->ip.sin_port == ip2->ip.sin_port;
 }
 
+char *ctdb_addr_to_str(ctdb_sock_addr *addr)
+{
+	static char cip[128] = "";
+
+	switch (addr->sa.sa_family) {
+	case AF_INET:
+		inet_ntop(addr->ip.sin_family, &addr->ip.sin_addr, cip, sizeof(cip));
+		break;
+	case AF_INET6:
+		inet_ntop(addr->ip6.sin6_family, &addr->ip6.sin6_addr, cip, sizeof(cip));
+		break;
+	default:
+		DEBUG(DEBUG_ERR, (__location__ " ERROR, unknown family %u\n", addr->sa.sa_family));
+	}
+
+	return cip;
+}
 
 
 void ctdb_block_signal(int signum)
diff --git a/common/system_aix.c b/common/system_aix.c
index b08692d..8fe630d 100644
--- a/common/system_aix.c
+++ b/common/system_aix.c
@@ -194,17 +194,17 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest,
   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(struct sockaddr_in ip)
+bool ctdb_sys_have_ip(ctdb_sock_addr *addr)
 {
 	int s;
 	int ret;
 	
-	ip.sin_port = 0;
-	s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+	addr->ip.sin_port = 0;
+	s = socket(addr->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
 	if (s == -1) {
 		return false;
 	}
-	ret = bind(s, (struct sockaddr *)&ip, sizeof(ip));
+	ret = bind(s, (struct sockaddr *)addr, sizeof(ctdb_sock_addr));
 	close(s);
 	return ret == 0;
 }
@@ -306,12 +306,13 @@ static int aix_get_mac_addr(const char *device_name, uint8_t mac[6])
 }
 
 int ctdb_sys_read_tcp_packet(int s, void *private_data, 
-			struct sockaddr_in *src, struct sockaddr_in *dst,
+			ctdb_sock_addr *src, ctdb_sock_addr *dst,
 			uint32_t *ack_seq, uint32_t *seq)
 {
 	int ret;
 	struct ether_header *eth;
 	struct ip *ip;
+	struct ip6_hdr *ip6;
 	struct tcphdr *tcp;
 	struct ctdb_killtcp_connection *conn;
 	struct pcap_pkthdr pkthdr;
@@ -326,44 +327,75 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 	/* Ethernet */
 	eth = (struct ether_header *)buffer;
 
-	/* We are only interested in IP packets */
-	if (eth->ether_type != htons(ETHERTYPE_IP)) {
-		return -1;
-	}
+	/* we want either IPv4 or IPv6 */
+	if (eth->ether_type == htons(ETHERTYPE_IP)) {
+		/* IP */
+		ip = (struct ip *)(eth+1);
 
-	/* 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;
+		}
 
-	/* 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) > 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;
 
-	/* make sure its not a short packet */
-	if (offsetof(struct tcphdr, th_ack) + 4 + 
-	    (ip->ip_hl*4) > ret) {
-		return -1;
+
+		return 0;
+#ifndef ETHERTYPE_IP6
+#define ETHERTYPE_IP6 0x86dd
+#endif
+	} else if (eth->ether_type == htons(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;
 	}
-	/* TCP */
-	tcp = (struct tcphdr *)((ip->ip_hl*4) + (char *)ip);
-	
-	/* tell the caller which one we've found */
-	src->sin_addr.s_addr = ip->ip_src.s_addr;
-	src->sin_port        = tcp->th_sport;
-	dst->sin_addr.s_addr = ip->ip_dst.s_addr;
-	dst->sin_port        = tcp->th_dport;
-	*ack_seq             = tcp->th_ack;
-	*seq                 = tcp->th_seq;
 
-	return 0;
+	return -1;
 }
 
 
diff --git a/common/system_linux.c b/common/system_linux.c
index 32db545..1bf4903 100644
--- a/common/system_linux.c
+++ b/common/system_linux.c
@@ -26,9 +26,58 @@
 #include "lib/events/events.h"
 #include <netinet/if_ether.h>
 #include <netinet/ip6.h>
+#include <netinet/icmp6.h>
 #include <net/if_arp.h>
 
 
+#ifndef ETHERTYPE_IP6
+#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
+*/
+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
@@ -42,8 +91,10 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
 	struct sockaddr sa;
 	struct ether_header *eh;
 	struct arphdr *ah;
+	struct ip6_hdr *ip6;
+	struct icmp6_hdr *icmp6;
 	struct ifreq if_hwaddr;
-	unsigned char buffer[64]; /*minimum eth frame size */
+	unsigned char buffer[78]; /* ipv6 neigh solicitation size */
 	char *ptr;
 
 	ZERO_STRUCT(sa);
@@ -131,8 +182,66 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
 
 		close(s);
 		break;
+	case AF_INET6:
+		s = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP6));
+		if (s == -1){
+			DEBUG(DEBUG_CRIT,(__location__ " failed to open raw socket\n"));
+			return -1;
+		}
+
+		/* get the mac address */
+		strcpy(if_hwaddr.ifr_name, iface);
+		ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
+		if ( ret < 0 ) {
+			close(s);
+			DEBUG(DEBUG_CRIT,(__location__ " ioctl failed\n"));
+			return -1;
+		}
+		if (ARPHRD_LOOPBACK == if_hwaddr.ifr_hwaddr.sa_family) {
+			DEBUG(DEBUG_DEBUG,("Ignoring loopback arp request\n"));
+			close(s);
+			return 0;
+		}
+		if (if_hwaddr.ifr_hwaddr.sa_family != AF_LOCAL) {
+			close(s);
+			errno = EINVAL;
+			DEBUG(DEBUG_CRIT,(__location__ " not an ethernet address family (0x%x)\n",
+				 if_hwaddr.ifr_hwaddr.sa_family));
+			return -1;
+		}


-- 
CTDB repository


More information about the samba-cvs mailing list