forked from eucalyptus/eucalyptus
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy patheucanetd.h
375 lines (319 loc) · 17.5 KB
/
eucanetd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// -*- mode: C; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
// vim: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
/*************************************************************************
* Copyright 2017 Ent. Services Development Corporation LP
*
* Redistribution and use of this software in source and binary forms,
* with or without modification, are permitted provided that the
* following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
************************************************************************/
#ifndef _INCLUDE_EUCANETD_H_
#define _INCLUDE_EUCANETD_H_
//!
//! @file net/eucanetd.h
//! Definition of the service management layer
//!
/*----------------------------------------------------------------------------*\
| |
| INCLUDES |
| |
\*----------------------------------------------------------------------------*/
#include <data.h>
#include <atomic_file.h>
#include <config.h>
#include <data.h>
#include <ipt_handler.h>
#include <ips_handler.h>
#include <ebt_handler.h>
#include <atomic_file.h>
#include <euca_gni.h>
/*----------------------------------------------------------------------------*\
| |
| DEFINES |
| |
\*----------------------------------------------------------------------------*/
//! @{
//! @name The bitmask indicating which of the API needs to be executed after a successful system scrub
#define EUCANETD_RUN_NO_API 0x00000000 //!< Bassically says don't do anything
#define EUCANETD_RUN_NETWORK_API 0x00000001 //!< If set, this will trigger the core to run the implement_network() driver API
#define EUCANETD_RUN_SECURITY_GROUP_API 0x00000002 //!< If set, this will trigger the core to run the implement_sg() driver API
#define EUCANETD_RUN_ADDRESSING_API 0x00000004 //!< If set, this will trigger the core to run the implement_addressing() driver API
#define EUCANETD_RUN_ALL_API (EUCANETD_RUN_NETWORK_API | EUCANETD_RUN_SECURITY_GROUP_API | EUCANETD_RUN_ADDRESSING_API)
#define EUCANETD_RUN_ERROR_API 0x80000000 //!< This is to indicate an error case
#define EUCANETD_VPCMIDO_IFERROR 0x40000000 //!< Error implementing interface(s) in VPCMIDO
#define EUCANETD_VPCMIDO_GWERROR 0x20000000 //!< Error implementing gateway(s) in VPCMIDO
//! @}
// eucanetd error codes
#define EUCANETD_ERR_VPCMIDO_API 20
#define EUCANETD_ERR_VPCMIDO_CORE 30
#define EUCANETD_ERR_VPCMIDO_CORE_GW 40
#define EUCANETD_ERR_VPCMIDO_MD 50
#define EUCANETD_ERR_VPCMIDO_TZ 60
#define EUCANETD_ERR_VPCMIDO_POPULATE 70
#define EUCANETD_ERR_VPCMIDO_PASS1 80
#define EUCANETD_ERR_VPCMIDO_PASS2 90
#define EUCANETD_ERR_VPCMIDO_VPCS 100
#define EUCANETD_ERR_VPCMIDO_SGS 110
#define EUCANETD_ERR_VPCMIDO_ENIS 120
#define EUCANETD_ERR_VPCMIDO_NACLS 130
#define EUCANETD_ERR_VPCMIDO_OTHER 255
//! @{
//! @name Various known network IP and usual bitmask
#define INADDR_METADATA 0xA9FEA9FE //!< Metadata IP address
#define IN_HOST_NET 0xFFFFFFFF //!< 32 bit host network (not defined in in.h)
//! @}
#define NUM_EUCANETD_CONFIG 1
/* Defines the bitmask for the flush mode */
#define EUCANETD_FLUSH_AND_RUN_MASK 0x01 //!< Will only flush and continue running
#define EUCANETD_FLUSH_ONLY_MASK 0x02 //!< Will flush and stop running the daemon
#define EUCANETD_FLUSH_MASK 0xFF //!< Mask to see if we need to flush
#define EUCANETD_DUMMY_UDP_PORT 63822
#define EUCANETD_DHCPD_UNIT "eucanetd-dhcpd@%s.service"
#define EUCANETD_NGINX_UNIT "eucanetd-nginx.service"
#define SYSCTL_BRIDGE_PATH "/proc/sys/net/bridge"
#define SYSCTL_BRIDGE_CALLIPTABLES "/proc/sys/net/bridge/bridge-nf-call-iptables"
#define SYSCTL_IP_FORWARD "/proc/sys/net/ipv4/ip_forward"
/*----------------------------------------------------------------------------*\
| |
| TYPEDEFS |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| ENUMERATIONS |
| |
\*----------------------------------------------------------------------------*/
// Enumeration of configuration constants found in eucalyptus.conf
enum {
EUCANETD_CVAL_PUBINTERFACE,
EUCANETD_CVAL_PRIVINTERFACE,
EUCANETD_CVAL_BRIDGE,
EUCANETD_CVAL_EUCAHOME,
EUCANETD_CVAL_MODE,
EUCANETD_CVAL_DHCPDAEMON,
EUCANETD_CVAL_DHCPUSER,
EUCANETD_CVAL_SYSTEMCTL,
EUCANETD_CVAL_POLLING_FREQUENCY,
EUCANETD_CVAL_DISABLE_L2_ISOLATION,
EUCANETD_CVAL_NC_PROXY,
EUCANETD_CVAL_NC_ROUTER,
EUCANETD_CVAL_NC_ROUTER_IP,
EUCANETD_CVAL_METADATA_USE_VM_PRIVATE,
EUCANETD_CVAL_METADATA_IP,
EUCANETD_CVAL_ADDRSPERNET,
EUCANETD_CVAL_EUCA_USER,
EUCANETD_CVAL_LOGLEVEL,
EUCANETD_CVAL_LOGROLLNUMBER,
EUCANETD_CVAL_LOGMAXSIZE,
EUCANETD_CVAL_MIDO_INTRTCIDR,
EUCANETD_CVAL_MIDO_INTMDCIDR,
EUCANETD_CVAL_MIDO_EXTMDCIDR,
EUCANETD_CVAL_MIDO_MDCIDR,
EUCANETD_CVAL_MIDO_MAX_RTID,
EUCANETD_CVAL_MIDO_MAX_ENIID,
EUCANETD_CVAL_MIDO_ENABLE_ARPTABLE,
EUCANETD_CVAL_MIDO_ENABLE_MIDOMD,
EUCANETD_CVAL_MIDO_API_URIBASE,
EUCANETD_CVAL_MIDO_MD_VETH_USE_NETNS,
EUCANETD_CVAL_MIDO_MD_254_EGRESS,
EUCANETD_CVAL_MIDO_MD_253_EGRESS,
EUCANETD_CVAL_MIDO_VALIDATE_MIDOCONFIG,
EUCANETD_CVAL_LOCALIP,
EUCANETD_CVAL_LAST,
};
enum {
FLUSH_NONE,
FLUSH_ALL,
FLUSH_DYNAMIC,
FLUSH_MIDO_ALL,
FLUSH_MIDO_DYNAMIC,
FLUSH_MIDO_CHECKDUPS,
FLUSH_MIDO_DUPS,
FLUSH_MIDO_CHECKVPC,
FLUSH_MIDO_CHECKUNCONNECTED,
FLUSH_MIDO_UNCONNECTED,
FLUSH_MIDO_VPC,
FLUSH_MIDO_TZONE,
FLUSH_MIDO_LISTVPC,
FLUSH_MIDO_LISTGATEWAYS,
FLUSH_MIDO_TEST,
};
//! Enumeration of the peer component type running alongside this eucanetd service
typedef enum eucanetd_peer_t {
PEER_INVALID = 0, //!< This is an invalid peer, this is used to detect initialization failures (forget to initialize)
PEER_CLC = 1, //!< This indicates we are currently working with a CLC component
PEER_CC = 2, //!< This indicates we are currently working with a CC component
PEER_NC = 3, //!< This indicates we are currently working with an NC component
PEER_NONE = 4, //!< This indicates we are currently running on a non-euca host
PEER_MAX = 5, //!< This is an invalid role use to detect initialization errors (couldn't set the role)
} eucanetd_peer;
enum eucanetd_debug_level_t {
EUCANETD_DEBUG_NONE = 0,
EUCANETD_DEBUG_TRACE = 1,
EUCANETD_DEBUG_DEBUG = 2,
EUCANETD_DEBUG_INFO = 3,
EUCANETD_DEBUG_WARN = 4,
EUCANETD_DEBUG_ERROR = 5,
EUCANETD_DEBUG_FATAL = 6,
};
/*----------------------------------------------------------------------------*\
| |
| STRUCTURES |
| |
\*----------------------------------------------------------------------------*/
//! Structure defining the core EUCANETD configuration
typedef struct eucanetdConfig_t {
ipt_handler *ipt; //!< Pointer to the IP Tables Handler
ips_handler *ips; //!< Pointer to the IP Sets Handler
ebt_handler *ebt; //!< Pointer to the EB Tables Handler
char netMode[NETMODE_LEN]; //!< Network mode name string
euca_netmode nmCode; //!< Network mode integer code
char *eucahome; //!< Pointer to the string containing the eucalyptus area home path
char *eucauser; //!< Pointer to the string containing the eucalyptus system user name
char cmdprefix[EUCA_MAX_PATH];
char configFiles[NUM_EUCANETD_CONFIG][EUCA_MAX_PATH];
u32 vmGatewayIP;
u32 clcMetadataIP;
char ncRouterIP[INET_ADDR_LEN];
char metadataIP[INET_ADDR_LEN];
char pubInterface[IF_NAME_LEN]; //!< The configured public interface device to use for networking (VNET_PUBINTERFACE)
char privInterface[IF_NAME_LEN]; //!< The configured private interface device to use for networking (VNET_PRIVINTERFACE)
char bridgeDev[IF_NAME_LEN]; //!< The configured bridge device to use for networking (VNET_BRIDGE)
char dhcpDaemon[EUCA_MAX_PATH]; //!< The path to the ISC DHCP server executable to use. (VNET_DHCPDAEMON)
char systemctl[EUCA_MAX_PATH]; //!< systemctl executable to use. (VNET_SYSTEMCTL)
char mido_intrtcidr[NETWORK_ADDR_LEN];
char mido_intmdcidr[NETWORK_ADDR_LEN];
char mido_extmdcidr[NETWORK_ADDR_LEN];
char mido_mdcidr[NETWORK_ADDR_LEN];
char mido_md_254_egress[256];
char mido_md_253_egress[256];
char mido_api_uribase[URI_LEN];
int mido_max_rtid;
int mido_max_eniid;
atomic_file global_network_info_file;
char lastAppliedVersion[32];
// these are flags that can be set by values in eucalyptus.conf
int polling_frequency;
int disable_l2_isolation;
int nc_router_ip;
int nc_router;
int metadata_use_vm_private;
int metadata_ip;
in_addr_t localIp; //!< Local address to use for this system
u32 *my_ips;
int max_my_ips;
int eucanetd_err;
boolean eucanetd_first_update;
boolean nc_proxy; //!< Set to TRUE to indicate we're using the NC proxy feature
boolean enable_mido_arptable;
boolean mido_arptable_config_changed;
boolean enable_mido_md;
boolean mido_md_veth_use_netns;
boolean mido_md_config_changed;
boolean mido_md_egress_rules_changed;
boolean populate_mido_md;
boolean validate_mido_config;
int debug;
boolean systemd; //!< Set to TRUE to indicate systemd mode (do not switch user or daemonize)
int flushmode;
char *flushmodearg;
boolean multieucanetd_safe;
int udpsock;
boolean init;
u32 euca_version;
char *euca_version_str;
} eucanetdConfig;
//! Network Driver API
typedef struct driver_handler_t {
char name[CHAR_BUFFER_SIZE]; //!< The name of the given network driver (e.g. EDGE, VPCMIDO, etc.)
int (*init) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< The driver initialization interface
int (*upgrade) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< This is optional when upgrade tasks are required.
int (*cleanup) (eucanetdConfig *pConfig, globalNetworkInfo *pGni, boolean doFlush); //!< The driver cleanup interface
int (*system_flush) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< Responsible for the flushing of all euca networking artifacts
int (*system_maint) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< Maintenance actions when eucanetd is idle (e.g., no GNI changes)
u32 (*system_scrub) (eucanetdConfig *pConfig, globalNetworkInfo *pGni,
globalNetworkInfo *pGniApplied); //!< Works on detecting what is changing
int (*implement_network) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< Takes care of network devices, tunnels, etc.
int (*implement_sg) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< Takes care of security group implementations and membership
int (*implement_addressing) (eucanetdConfig *pConfig, globalNetworkInfo *pGni); //!< Takes care of IP addressing, Elastic IPs, etc.
int (*handle_signal) (eucanetdConfig *pConfig, globalNetworkInfo *pGni, int signal); //!< Forward signals (USR1 and USR2) to driver
} driver_handler;
/*----------------------------------------------------------------------------*\
| |
| EXPORTED VARIABLES |
| |
\*----------------------------------------------------------------------------*/
//! @{
//! @name Configuration Keys from eucalyptus.conf
extern configEntry configKeysRestartEUCANETD[];
extern configEntry configKeysNoRestartEUCANETD[];
//! @}
//! @{
//! @name Network Driver Interfaces (NDIs)
extern struct driver_handler_t edgeDriverHandler; //!< EDGE network driver callback instance
extern struct driver_handler_t midoVpcDriverHandler; //!< MIDONET VPC network driver callback instance
//! @}
//! Global Network Information structure pointer.
//extern globalNetworkInfo *globalnetworkinfo;
//! Role of the component running alongside this eucanetd service
extern eucanetd_peer eucanetdPeer;
//! Array of peer type strings
extern const char *asPeerRoleName[];
extern int sig_rcvd;
/*----------------------------------------------------------------------------*\
| |
| EXPORTED PROTOTYPES |
| |
\*----------------------------------------------------------------------------*/
int eucanetd_dummy_udpsock(void);
int eucanetd_dummy_udpsock_close(void);
void eucanetd_emulate_sigusr2(void);
/*----------------------------------------------------------------------------*\
| |
| STATIC INLINE PROTOTYPES |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| MACROS |
| |
\*----------------------------------------------------------------------------*/
//! Macro to check whether or not a given peer value is valid
#define PEER_IS_VALID(_peer) (((_peer) > PEER_INVALID) && ((_peer) < PEER_MAX))
//! Macro to determine if we are on a CLC
#define PEER_IS_CLC(_peer) ((_peer) == PEER_CLC)
//! Macro to determine if we are on a CC
#define PEER_IS_CC(_peer) ((_peer) == PEER_CC)
//! Macro to determine if we are on a NC
#define PEER_IS_NC(_peer) ((_peer) == PEER_NC)
//! Macro to determine if we are not either NC, CC, and CLC
#define PEER_IS_NONE(_peer) ((_peer) == PEER_NONE)
//! Macro to convert a peer enumeration to a string representation
#define PEER2STR(_peer) ((((unsigned)(_peer)) > PEER_MAX) ? asPeerRoleName[PEER_MAX] : asPeerRoleName[(_peer)])
/*----------------------------------------------------------------------------*\
| |
| STATIC INLINE IMPLEMENTATION |
| |
\*----------------------------------------------------------------------------*/
#endif /* ! _INCLUDE_EUCANETD_H_ */