autobuild: Implement a split python2 and python2 build pattern
[samba.git] / ctdb / cluster / cluster_conf.c
1 /*
2    CTDB cluster config handling
3
4    Copyright (C) Martin Schwenke  2018
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
23 #include "lib/util/debug.h"
24
25 #include "common/conf.h"
26
27 #include "cluster_conf.h"
28
29 #define CLUSTER_TRANSPORT_DEFAULT "tcp"
30
31 /*
32  * Ideally this wants to be a void function but it also used directly
33  * as a validation function
34  */
35 static bool check_static_string_change(const char *key,
36                                        const char *old_value,
37                                        const char *new_value,
38                                        enum conf_update_mode mode)
39 {
40         if (mode == CONF_MODE_RELOAD) {
41                 if (strcmp(old_value, new_value) != 0) {
42                         D_WARNING("Ignoring update of [%s] -> %s\n",
43                                   CLUSTER_CONF_SECTION,
44                                   key);
45                 }
46         }
47
48         return true;
49 }
50
51 static bool validate_transport(const char *key,
52                                const char *old_transport,
53                                const char *new_transport,
54                                enum conf_update_mode mode)
55 {
56         /* Don't allow "ib" for now.  It is broken! */
57         if (strcmp(new_transport, CLUSTER_TRANSPORT_DEFAULT) != 0) {
58                 D_ERR("Invalid value for [cluster] -> transport = %s\n",
59                       new_transport);
60                 return false;
61         }
62
63         /* This sometimes warns but always returns true */
64         return check_static_string_change(key,
65                                           old_transport,
66                                           new_transport,
67                                           mode);
68 }
69
70 static bool validate_node_address(const char *key,
71                                   const char *old_node_address,
72                                   const char *new_node_address,
73                                   enum conf_update_mode mode)
74 {
75         struct in_addr addr4;
76         struct in6_addr addr6;
77         int ret;
78
79         if (new_node_address == NULL) {
80                 goto good;
81         }
82
83         ret = inet_pton(AF_INET, new_node_address, &addr4);
84         if (ret == 1) {
85                 goto good;
86         }
87
88         ret = inet_pton(AF_INET6, new_node_address, &addr6);
89         if (ret == 1) {
90                 goto good;
91         }
92
93         D_ERR("Invalid value for [cluster] -> node address = %s\n",
94               new_node_address);
95         return false;
96
97 good:
98         /* This sometimes warns but always returns true */
99         return check_static_string_change(key,
100                                           old_node_address,
101                                           new_node_address,
102                                           mode);
103 }
104
105 void cluster_conf_init(struct conf_context *conf)
106 {
107         conf_define_section(conf, CLUSTER_CONF_SECTION, NULL);
108
109         conf_define_string(conf,
110                            CLUSTER_CONF_SECTION,
111                            CLUSTER_CONF_TRANSPORT,
112                            CLUSTER_TRANSPORT_DEFAULT,
113                            validate_transport);
114         conf_define_string(conf,
115                            CLUSTER_CONF_SECTION,
116                            CLUSTER_CONF_NODE_ADDRESS,
117                            NULL,
118                            validate_node_address);
119         conf_define_string(conf,
120                            CLUSTER_CONF_SECTION,
121                            CLUSTER_CONF_RECOVERY_LOCK,
122                            NULL,
123                            check_static_string_change);
124 }