1 | /*
|
---|
2 | ctdb over TCP
|
---|
3 |
|
---|
4 | Copyright (C) Andrew Tridgell 2006
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "replace.h"
|
---|
21 | #include "system/network.h"
|
---|
22 | #include "system/filesys.h"
|
---|
23 |
|
---|
24 | #include "lib/util/dlinklist.h"
|
---|
25 | #include "lib/util/debug.h"
|
---|
26 |
|
---|
27 | #include "ctdb_private.h"
|
---|
28 |
|
---|
29 | #include "common/common.h"
|
---|
30 | #include "common/logging.h"
|
---|
31 |
|
---|
32 | #include "ctdb_tcp.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | /*
|
---|
36 | called when a complete packet has come in
|
---|
37 | */
|
---|
38 | void ctdb_tcp_read_cb(uint8_t *data, size_t cnt, void *args)
|
---|
39 | {
|
---|
40 | struct ctdb_incoming *in = talloc_get_type(args, struct ctdb_incoming);
|
---|
41 | struct ctdb_req_header *hdr = (struct ctdb_req_header *)data;
|
---|
42 |
|
---|
43 | if (data == NULL) {
|
---|
44 | /* incoming socket has died */
|
---|
45 | goto failed;
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (cnt < sizeof(*hdr)) {
|
---|
49 | DEBUG(DEBUG_ALERT,(__location__ " Bad packet length %u\n", (unsigned)cnt));
|
---|
50 | goto failed;
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (cnt & (CTDB_TCP_ALIGNMENT-1)) {
|
---|
54 | DEBUG(DEBUG_ALERT,(__location__ " Length 0x%x not multiple of alignment\n",
|
---|
55 | (unsigned)cnt));
|
---|
56 | goto failed;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | if (cnt != hdr->length) {
|
---|
61 | DEBUG(DEBUG_ALERT,(__location__ " Bad header length %u expected %u\n",
|
---|
62 | (unsigned)hdr->length, (unsigned)cnt));
|
---|
63 | goto failed;
|
---|
64 | }
|
---|
65 |
|
---|
66 | if (hdr->ctdb_magic != CTDB_MAGIC) {
|
---|
67 | DEBUG(DEBUG_ALERT,(__location__ " Non CTDB packet 0x%x rejected\n",
|
---|
68 | hdr->ctdb_magic));
|
---|
69 | goto failed;
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (hdr->ctdb_version != CTDB_PROTOCOL) {
|
---|
73 | DEBUG(DEBUG_ALERT, (__location__ " Bad CTDB version 0x%x rejected\n",
|
---|
74 | hdr->ctdb_version));
|
---|
75 | goto failed;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* tell the ctdb layer above that we have a packet */
|
---|
79 | in->ctdb->upcalls->recv_pkt(in->ctdb, data, cnt);
|
---|
80 | return;
|
---|
81 |
|
---|
82 | failed:
|
---|
83 | talloc_free(in);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /*
|
---|
87 | queue a packet for sending
|
---|
88 | */
|
---|
89 | int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
|
---|
90 | {
|
---|
91 | struct ctdb_tcp_node *tnode = talloc_get_type(node->private_data,
|
---|
92 | struct ctdb_tcp_node);
|
---|
93 | return ctdb_queue_send(tnode->out_queue, data, length);
|
---|
94 | }
|
---|