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/>.
21 #include "system/network.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
) {
52 ctdb_req_header_push(h
, buf
, &np
);
55 ctdb_uint64_push(&c
->tunnel_id
, buf
+offset
, &np
);
58 ctdb_uint32_push(&c
->flags
, buf
+offset
, &np
);
61 ctdb_tdb_datan_push(&c
->data
, buf
+offset
, &np
);
64 if (offset
> *buflen
) {
71 int ctdb_req_tunnel_pull(uint8_t *buf
, size_t buflen
,
72 struct ctdb_req_header
*h
,
74 struct ctdb_req_tunnel
*c
)
76 struct ctdb_req_header header
;
77 size_t offset
= 0, np
;
80 ret
= ctdb_req_header_pull(buf
, buflen
, &header
, &np
);
90 ret
= ctdb_uint64_pull(buf
+offset
, buflen
-offset
, &c
->tunnel_id
, &np
);
96 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &c
->flags
, &np
);
102 ret
= ctdb_tdb_datan_pull(buf
+offset
, buflen
-offset
, mem_ctx
,
109 if (offset
> buflen
) {