2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2015
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 int ctdb_req_header_verify(struct ctdb_req_header
*h
, uint32_t operation
)
32 if (h
->length
< sizeof(struct ctdb_req_header
)) {
36 if (h
->ctdb_magic
!= CTDB_MAGIC
) {
40 if (h
->ctdb_version
!= CTDB_PROTOCOL
) {
44 if (operation
!= 0 && h
->operation
!= operation
) {
51 void ctdb_req_header_fill(struct ctdb_req_header
*h
, uint32_t generation
,
52 uint32_t operation
, uint32_t destnode
,
53 uint32_t srcnode
, uint32_t reqid
)
55 h
->length
= sizeof(struct ctdb_req_header
);
56 h
->ctdb_magic
= CTDB_MAGIC
;
57 h
->ctdb_version
= CTDB_PROTOCOL
;
58 h
->generation
= generation
;
59 h
->operation
= operation
;
60 h
->destnode
= destnode
;
65 size_t ctdb_req_header_len(struct ctdb_req_header
*in
)
67 return ctdb_uint32_len(&in
->length
) +
68 ctdb_uint32_len(&in
->ctdb_magic
) +
69 ctdb_uint32_len(&in
->ctdb_version
) +
70 ctdb_uint32_len(&in
->generation
) +
71 ctdb_uint32_len(&in
->operation
) +
72 ctdb_uint32_len(&in
->destnode
) +
73 ctdb_uint32_len(&in
->srcnode
) +
74 ctdb_uint32_len(&in
->reqid
);
77 void ctdb_req_header_push(struct ctdb_req_header
*in
, uint8_t *buf
,
80 size_t offset
= 0, np
;
82 ctdb_uint32_push(&in
->length
, buf
+offset
, &np
);
85 ctdb_uint32_push(&in
->ctdb_magic
, buf
+offset
, &np
);
88 ctdb_uint32_push(&in
->ctdb_version
, buf
+offset
, &np
);
91 ctdb_uint32_push(&in
->generation
, buf
+offset
, &np
);
94 ctdb_uint32_push(&in
->operation
, buf
+offset
, &np
);
97 ctdb_uint32_push(&in
->destnode
, buf
+offset
, &np
);
100 ctdb_uint32_push(&in
->srcnode
, buf
+offset
, &np
);
103 ctdb_uint32_push(&in
->reqid
, buf
+offset
, &np
);
109 int ctdb_req_header_pull(uint8_t *buf
, size_t buflen
,
110 struct ctdb_req_header
*out
, size_t *npull
)
112 size_t offset
= 0, np
;
115 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->length
, &np
);
121 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->ctdb_magic
,
128 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->ctdb_version
,
135 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->generation
,
142 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->operation
,
149 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->destnode
, &np
);
155 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->srcnode
, &np
);
161 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->reqid
, &np
);