smbstatus: add json items to traverse_struct
[Samba.git] / ctdb / tcp / tcp_io.c
blobbcb18fbf300affdd92cc41067be7e4b4b88ad08a
1 /*
2 ctdb over TCP
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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
21 #include "system/network.h"
22 #include "system/filesys.h"
24 #include "lib/util/dlinklist.h"
25 #include "lib/util/debug.h"
27 #include "ctdb_private.h"
29 #include "common/common.h"
30 #include "common/logging.h"
32 #include "ctdb_tcp.h"
36 called when a complete packet has come in
38 void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
40 struct ctdb_node *node = talloc_get_type_abort(args, struct ctdb_node);
41 struct ctdb_tcp_node *tnode = talloc_get_type_abort(
42 node->transport_data, struct ctdb_tcp_node);
43 struct ctdb_req_header *hdr = (struct ctdb_req_header *)data;
45 if (data == NULL) {
46 /* incoming socket has died */
47 goto failed;
50 if (cnt < sizeof(*hdr)) {
51 DEBUG(DEBUG_ALERT,(__location__ " Bad packet length %u\n", (unsigned)cnt));
52 goto failed;
55 if (cnt & (CTDB_TCP_ALIGNMENT-1)) {
56 DEBUG(DEBUG_ALERT,(__location__ " Length 0x%x not multiple of alignment\n",
57 (unsigned)cnt));
58 goto failed;
61 if (hdr->ctdb_magic != CTDB_MAGIC) {
62 DEBUG(DEBUG_ALERT,(__location__ " Non CTDB packet 0x%x rejected\n",
63 hdr->ctdb_magic));
64 goto failed;
67 if (hdr->ctdb_version != CTDB_PROTOCOL) {
68 DEBUG(DEBUG_ALERT, (__location__ " Bad CTDB version 0x%x rejected\n",
69 hdr->ctdb_version));
70 goto failed;
73 /* tell the ctdb layer above that we have a packet */
74 tnode->ctdb->upcalls->recv_pkt(tnode->ctdb, data, cnt);
75 return;
77 failed:
78 node->ctdb->upcalls->node_dead(node);
80 TALLOC_FREE(data);
84 queue a packet for sending
86 int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
88 struct ctdb_tcp_node *tnode = talloc_get_type(node->transport_data,
89 struct ctdb_tcp_node);
90 if (tnode->out_queue == NULL) {
91 DBG_DEBUG("No outgoing connection, dropping packet\n");
92 return 0;
95 return ctdb_queue_send(tnode->out_queue, data, length);