s4:dsdb: allocate DSDB_CONTROL_DBCHECK_FIX_DUPLICATE_LINKS oid
[Samba.git] / ctdb / protocol / protocol_tunnel.c
blobd31d9d50f01f3eecc2a0f9a3d26adc4d37dda3bc
1 /*
2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2017
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"
23 #include <talloc.h>
24 #include <tdb.h>
26 #include "protocol.h"
27 #include "protocol_api.h"
28 #include "protocol_private.h"
30 size_t ctdb_req_tunnel_len(struct ctdb_req_header *h,
31 struct ctdb_req_tunnel *c)
33 return ctdb_req_header_len(h) +
34 ctdb_uint64_len(&c->tunnel_id) +
35 ctdb_uint32_len(&c->flags) +
36 ctdb_tdb_datan_len(&c->data);
39 int ctdb_req_tunnel_push(struct ctdb_req_header *h,
40 struct ctdb_req_tunnel *c,
41 uint8_t *buf, size_t *buflen)
43 size_t length, offset = 0, np;
45 length = ctdb_req_tunnel_len(h, c);
46 if (*buflen < length) {
47 *buflen = length;
48 return EMSGSIZE;
51 h->length = *buflen;
52 ctdb_req_header_push(h, buf, &np);
53 offset += np;
55 ctdb_uint64_push(&c->tunnel_id, buf+offset, &np);
56 offset += np;
58 ctdb_uint32_push(&c->flags, buf+offset, &np);
59 offset += np;
61 ctdb_tdb_datan_push(&c->data, buf+offset, &np);
62 offset += np;
64 if (offset > *buflen) {
65 return EMSGSIZE;
68 return 0;
71 int ctdb_req_tunnel_pull(uint8_t *buf, size_t buflen,
72 struct ctdb_req_header *h,
73 TALLOC_CTX *mem_ctx,
74 struct ctdb_req_tunnel *c)
76 struct ctdb_req_header header;
77 size_t offset = 0, np;
78 int ret;
80 ret = ctdb_req_header_pull(buf, buflen, &header, &np);
81 if (ret != 0) {
82 return ret;
84 offset += np;
86 if (h != NULL) {
87 *h = header;
90 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->tunnel_id, &np);
91 if (ret != 0) {
92 return ret;
94 offset += np;
96 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
97 if (ret != 0) {
98 return ret;
100 offset += np;
102 ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, mem_ctx,
103 &c->data, &np);
104 if (ret != 0) {
105 return ret;
107 offset += np;
109 if (offset > buflen) {
110 return EMSGSIZE;
113 return 0;