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_private.h"
28 #include "protocol_api.h"
31 enum ctdb_runstate runstate
;
34 { CTDB_RUNSTATE_UNKNOWN
, "UNKNOWN" },
35 { CTDB_RUNSTATE_INIT
, "INIT" },
36 { CTDB_RUNSTATE_SETUP
, "SETUP" },
37 { CTDB_RUNSTATE_FIRST_RECOVERY
, "FIRST_RECOVERY" },
38 { CTDB_RUNSTATE_STARTUP
, "STARTUP" },
39 { CTDB_RUNSTATE_RUNNING
, "RUNNING" },
40 { CTDB_RUNSTATE_SHUTDOWN
, "SHUTDOWN" },
44 const char *ctdb_runstate_to_string(enum ctdb_runstate runstate
)
48 for (i
=0; runstate_map
[i
].label
!= NULL
; i
++) {
49 if (runstate_map
[i
].runstate
== runstate
) {
50 return runstate_map
[i
].label
;
54 return runstate_map
[0].label
;
57 enum ctdb_runstate
ctdb_runstate_from_string(const char *runstate_str
)
61 for (i
=0; runstate_map
[i
].label
!= NULL
; i
++) {
62 if (strcasecmp(runstate_map
[i
].label
,
64 return runstate_map
[i
].runstate
;
68 return CTDB_RUNSTATE_UNKNOWN
;
72 enum ctdb_event event
;
75 { CTDB_EVENT_INIT
, "init" },
76 { CTDB_EVENT_SETUP
, "setup" },
77 { CTDB_EVENT_STARTUP
, "startup" },
78 { CTDB_EVENT_START_RECOVERY
, "startrecovery" },
79 { CTDB_EVENT_RECOVERED
, "recovered" },
80 { CTDB_EVENT_TAKE_IP
, "takeip" },
81 { CTDB_EVENT_RELEASE_IP
, "releaseip" },
82 { CTDB_EVENT_MONITOR
, "monitor" },
83 { CTDB_EVENT_SHUTDOWN
, "shutdown" },
84 { CTDB_EVENT_UPDATE_IP
, "updateip" },
85 { CTDB_EVENT_IPREALLOCATED
, "ipreallocated" },
86 { CTDB_EVENT_MAX
, "all" },
90 const char *ctdb_event_to_string(enum ctdb_event event
)
94 for (i
=0; event_map
[i
].label
!= NULL
; i
++) {
95 if (event_map
[i
].event
== event
) {
96 return event_map
[i
].label
;
103 enum ctdb_event
ctdb_event_from_string(const char *event_str
)
107 for (i
=0; event_map
[i
].label
!= NULL
; i
++) {
108 if (strcmp(event_map
[i
].label
, event_str
) == 0) {
109 return event_map
[i
].event
;
113 return CTDB_EVENT_MAX
;
116 const char *ctdb_sock_addr_to_string(TALLOC_CTX
*mem_ctx
, ctdb_sock_addr
*addr
)
120 cip
= talloc_size(mem_ctx
, 128);
122 return "Memory Error";
125 switch (addr
->sa
.sa_family
) {
127 inet_ntop(addr
->ip
.sin_family
, &addr
->ip
.sin_addr
,
132 inet_ntop(addr
->ip6
.sin6_family
, &addr
->ip6
.sin6_addr
,
137 sprintf(cip
, "Unknown family %u", addr
->sa
.sa_family
);
144 bool ctdb_sock_addr_same_ip(ctdb_sock_addr
*addr1
, ctdb_sock_addr
*addr2
)
146 if (addr1
->sa
.sa_family
!= addr2
->sa
.sa_family
) {
150 switch (addr1
->sa
.sa_family
) {
152 if (addr1
->ip
.sin_addr
.s_addr
!= addr2
->ip
.sin_addr
.s_addr
) {
158 if (memcmp(addr1
->ip6
.sin6_addr
.s6_addr
,
159 addr2
->ip6
.sin6_addr
.s6_addr
, 16) != 0) {
171 bool ctdb_sock_addr_same(ctdb_sock_addr
*addr1
, ctdb_sock_addr
*addr2
)
173 if (! ctdb_sock_addr_same_ip(addr1
, addr2
)) {
177 switch (addr1
->sa
.sa_family
) {
179 if (addr1
->ip
.sin_port
!= addr2
->ip
.sin_port
) {
185 if (addr1
->ip6
.sin6_port
!= addr2
->ip6
.sin6_port
) {