This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
/
vnetwork.h
325 lines (283 loc) · 14.8 KB
/
vnetwork.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
// -*- mode: C; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
// vim: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
/*************************************************************************
* Copyright 2009-2012 Eucalyptus Systems, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta
* CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need
* additional information or have any questions.
*
* This file may incorporate work covered under the following copyright
* and permission notice:
*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, Regents of the University of California
* All rights reserved.
*
* 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. USERS OF THIS SOFTWARE ACKNOWLEDGE
* THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL,
* COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS SOFTWARE,
* AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
* IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA,
* SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY,
* WHICH IN THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION,
* REPLACEMENT OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO
* IDENTIFIED, OR WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT
* NEEDED TO COMPLY WITH ANY SUCH LICENSES OR RIGHTS.
************************************************************************/
#ifndef INCLUDE_VNETWORK_H
#define INCLUDE_VNETWORK_H
//!
//! @file
//! Defines the Virtual Network library.
//!
/*----------------------------------------------------------------------------*\
| |
| INCLUDES |
| |
\*----------------------------------------------------------------------------*/
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <eucalyptus.h>
#include <linux/limits.h>
/*----------------------------------------------------------------------------*\
| |
| DEFINES |
| |
\*----------------------------------------------------------------------------*/
#ifndef MAX_PATH
#define MAX_PATH 4096
#endif /* ! MAX_PATH */
#define NUMBER_OF_VLANS 4096
#define NUMBER_OF_HOSTS_PER_VLAN 2048
#define NUMBER_OF_PUBLIC_IPS 2048
#define NUMBER_OF_CCS 8
#define MAX_ETH_DEV_PATH 16
/*----------------------------------------------------------------------------*\
| |
| TYPEDEFS |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| ENUMERATIONS |
| |
\*----------------------------------------------------------------------------*/
enum {
NC,
CC,
CLC
};
/*----------------------------------------------------------------------------*\
| |
| STRUCTURES |
| |
\*----------------------------------------------------------------------------*/
typedef struct netEntry_t {
unsigned char mac[6];
char active;
uint32_t ip;
} netEntry;
typedef struct userEntry_t {
char netName[64];
char userName[48];
char uuid[48];
} userEntry;
typedef struct networkEntry_t {
int numhosts;
char active;
uint32_t nw;
uint32_t nm;
uint32_t bc;
uint32_t dns;
uint32_t router;
netEntry addrs[NUMBER_OF_HOSTS_PER_VLAN];
time_t createTime;
} networkEntry;
typedef struct publicip_t {
uint32_t ip;
uint32_t dstip;
int allocated;
char uuid[48];
} publicip;
typedef struct tunnelData_t {
int localIpId;
int localIpIdLast;
uint32_t ccs[NUMBER_OF_CCS];
time_t ccsTunnelStart[NUMBER_OF_CCS];
time_t tunpassMtime;
int tunneling;
} tunnelData;
typedef struct vnetConfig_t {
char eucahome[MAX_PATH];
char path[MAX_PATH];
char dhcpdaemon[MAX_PATH];
char dhcpuser[32];
char pubInterface[32];
char privInterface[32];
char bridgedev[32];
char mode[32];
char macPrefix[6];
uint32_t localIps[32];
uint32_t nw;
uint32_t nm;
uint32_t euca_ns;
uint32_t cloudIp;
char euca_domainname[256];
int role;
int enabled;
int initialized;
int numaddrs;
int addrIndexMin;
int addrIndexMax;
int max_vlan;
tunnelData tunnels;
char etherdevs[NUMBER_OF_VLANS][MAX_ETH_DEV_PATH];
userEntry users[NUMBER_OF_VLANS];
networkEntry networks[NUMBER_OF_VLANS];
publicip publicips[NUMBER_OF_PUBLIC_IPS];
char iptables[4194304];
} vnetConfig;
/*----------------------------------------------------------------------------*\
| |
| EXPORTED VARIABLES |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| EXPORTED PROTOTYPES |
| |
\*----------------------------------------------------------------------------*/
int vnetInit(vnetConfig * vnetconfig, char *mode, char *eucahome, char *path, int role, char *pubInterface, char *privInterface, char *numberofaddrs,
char *network, char *netmask, char *broadcast, char *nameserver, char *domainname, char *router, char *daemon, char *dhcpuser,
char *bridgedev, char *localIp, char *macPrefix);
int vnetSetMetadataRedirect(vnetConfig * vnetconfig);
int vnetUnsetMetadataRedirect(vnetConfig * vnetconfig);
int vnetInitTunnels(vnetConfig * vnetconfig);
int vnetAddHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan, int idx);
int vnetDelHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan);
int vnetRefreshHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan, int idx);
int vnetEnableHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan);
int vnetDisableHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan);
int vnetDeleteChain(vnetConfig * vnetconfig, char *userName, char *netName);
int vnetCreateChain(vnetConfig * vnetconfig, char *userName, char *netName);
int vnetSaveTablesToMemory(vnetConfig * vnetconfig);
int vnetRestoreTablesFromMemory(vnetConfig * vnetconfig);
int vnetFlushTable(vnetConfig * vnetconfig, char *userName, char *netName);
int vnetApplySingleEBTableRule(vnetConfig * vnetconfig, char *table, char *rule);
int vnetApplySingleTableRule(vnetConfig * vnetconfig, char *table, char *rule);
int vnetTableRule(vnetConfig * vnetconfig, char *type, char *destUserName, char *destName, char *sourceUserName, char *sourceNet, char *sourceNetName,
char *protocol, int minPort, int maxPort);
int vnetSetVlan(vnetConfig * vnetconfig, int vlan, char *uuid, char *user, char *network);
int vnetGetVlan(vnetConfig * vnetconfig, char *user, char *network);
int vnetGetAllVlans(vnetConfig * vnetconfig, char ***outusers, char ***outnets, int *len);
int vnetGenerateNetworkParams(vnetConfig * vnetconfig, char *instId, int vlan, int nidx, char *outmac, char *outpubip, char *outprivip);
int vnetGetNextHost(vnetConfig * vnetconfig, char *mac, char *ip, int vlan, int idx);
int vnetCountLocalIP(vnetConfig * vnetconfig);
int vnetCheckLocalIP(vnetConfig * vnetconfig, uint32_t ip);
int vnetAddLocalIP(vnetConfig * vnetconfig, uint32_t ip);
int vnetAddDev(vnetConfig * vnetconfig, char *dev);
int vnetDelDev(vnetConfig * vnetconfig, char *dev);
int vnetGenerateDHCP(vnetConfig * vnetconfig, int *numHosts);
int vnetKickDHCP(vnetConfig * vnetconfig);
int vnetAddCCS(vnetConfig * vnetconfig, uint32_t cc);
int vnetDelCCS(vnetConfig * vnetconfig, uint32_t cc);
int vnetSetCCS(vnetConfig * vnetconfig, char **ccs, int ccsLen);
int vnetStartInstanceNetwork(vnetConfig * vnetconfig, int vlan, char *publicIp, char *privateIp, char *macaddr);
int vnetStopInstanceNetwork(vnetConfig * vnetconfig, int vlan, char *publicIp, char *privateIp, char *macaddr);
int vnetStartNetworkManaged(vnetConfig * vnetconfig, int vlan, char *uuid, char *userName, char *netName, char **outbrname);
int vnetAttachTunnels(vnetConfig * vnetconfig, int vlan, char *newbrname);
int vnetDetachTunnels(vnetConfig * vnetconfig, int vlan, char *newbrname);
int vnetTeardownTunnels(vnetConfig * vnetconfig);
int vnetTeardownTunnelsVTUN(vnetConfig * vnetconfig);
int vnetSetupTunnels(vnetConfig * vnetconfig);
int vnetSetupTunnelsVTUN(vnetConfig * vnetconfig);
int vnetAddGatewayIP(vnetConfig * vnetconfig, int vlan, char *devname, int localIpId);
int vnetApplyArpTableRules(vnetConfig * vnetconfig);
int vnetDelGatewayIP(vnetConfig * vnetconfig, int vlan, char *devname, int localIpId);
int vnetStopNetworkManaged(vnetConfig * vnetconfig, int vlan, char *userName, char *netName);
int vnetStartNetwork(vnetConfig * vnetconfig, int vlan, char *uuid, char *userName, char *netName, char **outbrname);
int vnetGetPublicIP(vnetConfig * vnetconfig, char *ip, char **dstip, int *allocated, int *addrdevno);
int vnetCheckPublicIP(vnetConfig * vnetconfig, char *ip);
int vnetAddPublicIP(vnetConfig * vnetconfig, char *inip);
int vnetAssignAddress(vnetConfig * vnetconfig, char *src, char *dst);
int vnetAllocatePublicIP(vnetConfig * vnetconfig, char *uuid, char *ip, char *dstip);
int vnetDeallocatePublicIP(vnetConfig * vnetconfig, char *uuid, char *ip, char *dstip);
int vnetSetPublicIP(vnetConfig * vnetconfig, char *uuid, char *ip, char *dstip, int setval);
int vnetReassignAddress(vnetConfig * vnetconfig, char *uuid, char *src, char *dst);
int vnetUnassignAddress(vnetConfig * vnetconfig, char *src, char *dst);
int vnetStopNetwork(vnetConfig * vnetconfig, int vlan, char *userName, char *netName);
int instId2mac(vnetConfig * vnetconfig, char *instId, char *outmac);
int ip2mac(vnetConfig * vnetconfig, char *ip, char **mac);
int mac2ip(vnetConfig * vnetconfig, char *mac, char **ip);
uint32_t dot2hex(char *in);
int getdevinfo(char *dev, uint32_t ** outips, uint32_t ** outnms, int *len);
void hex2mac(unsigned char in[6], char **out);
void mac2hex(char *in, unsigned char out[6]);
int maczero(unsigned char in[6]);
int machexcmp(char *ina, unsigned char inb[6]);
char *hex2dot(uint32_t in);
char *ipdot2macdot(char *ip, char *macprefix);
int vnetLoadIPTables(vnetConfig * vnetconfig);
int check_chain(vnetConfig * vnetconfig, char *userName, char *netName);
int check_deviceup(char *dev);
int check_device(char *dev);
int check_bridgestp(char *br);
int check_bridgedev(char *br, char *dev);
int check_bridge(char *brname);
int check_tablerule(vnetConfig * vnetconfig, char *table, char *rule);
int check_isip(char *ip);
char *host2ip(char *host);
/*----------------------------------------------------------------------------*\
| |
| STATIC INLINE PROTOTYPES |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| MACROS |
| |
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
| |
| STATIC INLINE IMPLEMENTATION |
| |
\*----------------------------------------------------------------------------*/
#endif /* ! INCLUDE_VNETWORK_H */