summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-04-06 04:43:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:51 -0500
commita9044f92c9f6eb74c5f7cb56f43a6f8ea25ccb2a (patch)
tree66051e9710511ad3a8bac9722696f9931539e947
parent4685a42eaf28e0d4644bfa4cf18ef08abee329d3 (diff)
downloadsamba-a9044f92c9f6eb74c5f7cb56f43a6f8ea25ccb2a.tar.gz
samba-a9044f92c9f6eb74c5f7cb56f43a6f8ea25ccb2a.tar.bz2
samba-a9044f92c9f6eb74c5f7cb56f43a6f8ea25ccb2a.zip
r22098: merged from bzr tree
(This used to be commit a57af1ff8234ab590ebf28b3316953bec880005c)
-rw-r--r--source4/cluster/ctdb/common/ctdb.c10
-rw-r--r--source4/cluster/ctdb/common/ctdb_call.c12
-rw-r--r--source4/cluster/ctdb/common/ctdb_message.c2
-rw-r--r--source4/cluster/ctdb/include/ctdb_private.h5
-rw-r--r--source4/cluster/ctdb/tcp/tcp_connect.c17
5 files changed, 45 insertions, 1 deletions
diff --git a/source4/cluster/ctdb/common/ctdb.c b/source4/cluster/ctdb/common/ctdb.c
index e4f7289550..da07192c21 100644
--- a/source4/cluster/ctdb/common/ctdb.c
+++ b/source4/cluster/ctdb/common/ctdb.c
@@ -205,6 +205,16 @@ static void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t len
return;
}
+ if (hdr->ctdb_magic != CTDB_MAGIC) {
+ ctdb_set_error(ctdb, "Non CTDB packet rejected\n");
+ return;
+ }
+
+ if (hdr->ctdb_version != CTDB_VERSION) {
+ ctdb_set_error(ctdb, "Bad CTDB version 0x%x rejected\n", hdr->ctdb_version);
+ return;
+ }
+
switch (hdr->operation) {
case CTDB_REQ_CALL:
ctdb_request_call(ctdb, hdr);
diff --git a/source4/cluster/ctdb/common/ctdb_call.c b/source4/cluster/ctdb/common/ctdb_call.c
index 0b4195140c..decdbe127f 100644
--- a/source4/cluster/ctdb/common/ctdb_call.c
+++ b/source4/cluster/ctdb/common/ctdb_call.c
@@ -125,6 +125,8 @@ static void ctdb_send_error(struct ctdb_context *ctdb,
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = len + msglen;
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REPLY_ERROR;
r->hdr.destnode = hdr->srcnode;
r->hdr.srcnode = ctdb->vnn;
@@ -153,6 +155,8 @@ static void ctdb_call_send_redirect(struct ctdb_context *ctdb,
r = ctdb->methods->allocate_pkt(ctdb, sizeof(*r));
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = sizeof(*r);
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REPLY_REDIRECT;
r->hdr.destnode = c->hdr.srcnode;
r->hdr.srcnode = ctdb->vnn;
@@ -184,6 +188,8 @@ static void ctdb_call_send_dmaster(struct ctdb_db_context *ctdb_db,
r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = len;
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REQ_DMASTER;
r->hdr.destnode = ctdb_lmaster(ctdb, key);
r->hdr.srcnode = ctdb->vnn;
@@ -264,6 +270,8 @@ void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr
r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = len;
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REPLY_DMASTER;
r->hdr.destnode = c->dmaster;
r->hdr.srcnode = ctdb->vnn;
@@ -346,6 +354,8 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
r = ctdb->methods->allocate_pkt(ctdb, len);
CTDB_NO_MEMORY_FATAL(ctdb, r);
r->hdr.length = len;
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REPLY_CALL;
r->hdr.destnode = hdr->srcnode;
r->hdr.srcnode = hdr->destnode;
@@ -576,6 +586,8 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c
CTDB_NO_MEMORY_NULL(ctdb, state->c);
state->c->hdr.length = len;
+ state->c->hdr.ctdb_magic = CTDB_MAGIC;
+ state->c->hdr.ctdb_version = CTDB_VERSION;
state->c->hdr.operation = CTDB_REQ_CALL;
state->c->hdr.destnode = header.dmaster;
state->c->hdr.srcnode = ctdb->vnn;
diff --git a/source4/cluster/ctdb/common/ctdb_message.c b/source4/cluster/ctdb/common/ctdb_message.c
index ca909f8994..562a23ee3a 100644
--- a/source4/cluster/ctdb/common/ctdb_message.c
+++ b/source4/cluster/ctdb/common/ctdb_message.c
@@ -64,6 +64,8 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
CTDB_NO_MEMORY(ctdb, r);
r->hdr.length = len;
+ r->hdr.ctdb_magic = CTDB_MAGIC;
+ r->hdr.ctdb_version = CTDB_VERSION;
r->hdr.operation = CTDB_REQ_MESSAGE;
r->hdr.destnode = vnn;
r->hdr.srcnode = ctdb->vnn;
diff --git a/source4/cluster/ctdb/include/ctdb_private.h b/source4/cluster/ctdb/include/ctdb_private.h
index 66a9a6e244..9c93466e19 100644
--- a/source4/cluster/ctdb/include/ctdb_private.h
+++ b/source4/cluster/ctdb/include/ctdb_private.h
@@ -155,11 +155,16 @@ enum ctdb_operation {
CTDB_REQ_MESSAGE = 6
};
+#define CTDB_MAGIC 0x43544442 /* CTDB */
+#define CTDB_VERSION 1
+
/*
packet structures
*/
struct ctdb_req_header {
uint32_t length;
+ uint32_t ctdb_magic;
+ uint32_t ctdb_version;
uint32_t operation;
uint32_t destnode;
uint32_t srcnode;
diff --git a/source4/cluster/ctdb/tcp/tcp_connect.c b/source4/cluster/ctdb/tcp/tcp_connect.c
index fe0fc210ba..85fffc2f70 100644
--- a/source4/cluster/ctdb/tcp/tcp_connect.c
+++ b/source4/cluster/ctdb/tcp/tcp_connect.c
@@ -98,6 +98,7 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
struct ctdb_tcp_node *tnode = talloc_get_type(node->private,
struct ctdb_tcp_node);
struct ctdb_context *ctdb = node->ctdb;
+ struct sockaddr_in sock_in;
struct sockaddr_in sock_out;
tnode->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -109,7 +110,21 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
}
sock_out.sin_port = htons(node->address.port);
sock_out.sin_family = PF_INET;
-
+
+
+ /* Bind our side of the socketpair to the same address we use to listen
+ * on incoming CTDB traffic.
+ * We must specify this address to make sure that the address we expose to
+ * the remote side is actually routable in case CTDB traffic will run on
+ * a dedicated non-routeable network.
+ */
+ if (ctdb_tcp_get_address(ctdb, ctdb->address.address, &sock_in.sin_addr) != 0) {
+ return;
+ }
+ sock_in.sin_port = htons(0); /* INPORT_ANY is not always available */
+ sock_in.sin_family = PF_INET;
+ bind(tnode->fd, (struct sockaddr *)&sock_in, sizeof(sock_in));
+
if (connect(tnode->fd, (struct sockaddr *)&sock_out, sizeof(sock_out)) != 0 &&
errno != EINPROGRESS) {
/* try again once a second */