4 Copyright (C) Andrew Tridgell 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "lib/events/events.h"
23 #include "lib/util/dlinklist.h"
24 #include "lib/tdb/include/tdb.h"
25 #include "system/network.h"
26 #include "system/filesys.h"
27 #include "../include/ctdb_private.h"
32 called when a complete packet has come in
34 void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
36 struct ctdb_incoming *in = talloc_get_type(args, struct ctdb_incoming);
37 struct ctdb_req_header *hdr = (struct ctdb_req_header *)data;
40 /* incoming socket has died */
44 if (cnt < sizeof(*hdr)) {
45 DEBUG(0,(__location__ " Bad packet length %u\n", (unsigned)cnt));
49 if (cnt & (CTDB_TCP_ALIGNMENT-1)) {
50 DEBUG(0,(__location__ " Length 0x%x not multiple of alignment\n",
56 if (cnt != hdr->length) {
57 DEBUG(0,(__location__ " Bad header length %u expected %u\n",
58 (unsigned)hdr->length, (unsigned)cnt));
62 if (hdr->ctdb_magic != CTDB_MAGIC) {
63 DEBUG(0,(__location__ " Non CTDB packet 0x%x rejected\n",
68 if (hdr->ctdb_version != CTDB_VERSION) {
69 DEBUG(0, (__location__ " Bad CTDB version 0x%x rejected\n",
74 /* tell the ctdb layer above that we have a packet */
75 in->ctdb->upcalls->recv_pkt(in->ctdb, data, cnt);
83 queue a packet for sending
85 int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
87 struct ctdb_tcp_node *tnode = talloc_get_type(node->private_data,
88 struct ctdb_tcp_node);
89 return ctdb_queue_send(tnode->out_queue, data, length);