1 | /* |
---|
2 | * Copyright (c) 2006-2007, XenSource Inc. |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU Lesser General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2.1 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * Lesser General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Lesser General Public |
---|
15 | * License along with this library; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <stddef.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "xen_internal.h" |
---|
24 | #include <xen/api/xen_common.h> |
---|
25 | #include <xen/api/xen_host.h> |
---|
26 | #include <xen/api/xen_network.h> |
---|
27 | #include <xen/api/xen_pif.h> |
---|
28 | #include <xen/api/xen_pif_metrics.h> |
---|
29 | |
---|
30 | |
---|
31 | XEN_FREE(xen_pif) |
---|
32 | XEN_SET_ALLOC_FREE(xen_pif) |
---|
33 | XEN_ALLOC(xen_pif_record) |
---|
34 | XEN_SET_ALLOC_FREE(xen_pif_record) |
---|
35 | XEN_ALLOC(xen_pif_record_opt) |
---|
36 | XEN_RECORD_OPT_FREE(xen_pif) |
---|
37 | XEN_SET_ALLOC_FREE(xen_pif_record_opt) |
---|
38 | |
---|
39 | |
---|
40 | static const struct_member xen_pif_record_struct_members[] = |
---|
41 | { |
---|
42 | { .key = "uuid", |
---|
43 | .type = &abstract_type_string, |
---|
44 | .offset = offsetof(xen_pif_record, uuid) }, |
---|
45 | { .key = "device", |
---|
46 | .type = &abstract_type_string, |
---|
47 | .offset = offsetof(xen_pif_record, device) }, |
---|
48 | { .key = "network", |
---|
49 | .type = &abstract_type_ref, |
---|
50 | .offset = offsetof(xen_pif_record, network) }, |
---|
51 | { .key = "host", |
---|
52 | .type = &abstract_type_ref, |
---|
53 | .offset = offsetof(xen_pif_record, host) }, |
---|
54 | { .key = "MAC", |
---|
55 | .type = &abstract_type_string, |
---|
56 | .offset = offsetof(xen_pif_record, mac) }, |
---|
57 | { .key = "MTU", |
---|
58 | .type = &abstract_type_int, |
---|
59 | .offset = offsetof(xen_pif_record, mtu) }, |
---|
60 | { .key = "VLAN", |
---|
61 | .type = &abstract_type_int, |
---|
62 | .offset = offsetof(xen_pif_record, vlan) }, |
---|
63 | { .key = "metrics", |
---|
64 | .type = &abstract_type_ref, |
---|
65 | .offset = offsetof(xen_pif_record, metrics) } |
---|
66 | }; |
---|
67 | |
---|
68 | const abstract_type xen_pif_record_abstract_type_ = |
---|
69 | { |
---|
70 | .typename = STRUCT, |
---|
71 | .struct_size = sizeof(xen_pif_record), |
---|
72 | .member_count = |
---|
73 | sizeof(xen_pif_record_struct_members) / sizeof(struct_member), |
---|
74 | .members = xen_pif_record_struct_members |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | void |
---|
79 | xen_pif_record_free(xen_pif_record *record) |
---|
80 | { |
---|
81 | if (record == NULL) |
---|
82 | { |
---|
83 | return; |
---|
84 | } |
---|
85 | free(record->handle); |
---|
86 | free(record->uuid); |
---|
87 | free(record->device); |
---|
88 | xen_network_record_opt_free(record->network); |
---|
89 | xen_host_record_opt_free(record->host); |
---|
90 | free(record->mac); |
---|
91 | xen_pif_metrics_record_opt_free(record->metrics); |
---|
92 | free(record); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | bool |
---|
97 | xen_pif_get_record(xen_session *session, xen_pif_record **result, xen_pif pif) |
---|
98 | { |
---|
99 | abstract_value param_values[] = |
---|
100 | { |
---|
101 | { .type = &abstract_type_string, |
---|
102 | .u.string_val = pif } |
---|
103 | }; |
---|
104 | |
---|
105 | abstract_type result_type = xen_pif_record_abstract_type_; |
---|
106 | |
---|
107 | *result = NULL; |
---|
108 | XEN_CALL_("PIF.get_record"); |
---|
109 | |
---|
110 | if (session->ok) |
---|
111 | { |
---|
112 | (*result)->handle = xen_strdup_((*result)->uuid); |
---|
113 | } |
---|
114 | |
---|
115 | return session->ok; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | bool |
---|
120 | xen_pif_get_by_uuid(xen_session *session, xen_pif *result, char *uuid) |
---|
121 | { |
---|
122 | abstract_value param_values[] = |
---|
123 | { |
---|
124 | { .type = &abstract_type_string, |
---|
125 | .u.string_val = uuid } |
---|
126 | }; |
---|
127 | |
---|
128 | abstract_type result_type = abstract_type_string; |
---|
129 | |
---|
130 | *result = NULL; |
---|
131 | XEN_CALL_("PIF.get_by_uuid"); |
---|
132 | return session->ok; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | bool |
---|
137 | xen_pif_get_device(xen_session *session, char **result, xen_pif pif) |
---|
138 | { |
---|
139 | abstract_value param_values[] = |
---|
140 | { |
---|
141 | { .type = &abstract_type_string, |
---|
142 | .u.string_val = pif } |
---|
143 | }; |
---|
144 | |
---|
145 | abstract_type result_type = abstract_type_string; |
---|
146 | |
---|
147 | *result = NULL; |
---|
148 | XEN_CALL_("PIF.get_device"); |
---|
149 | return session->ok; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | bool |
---|
154 | xen_pif_get_network(xen_session *session, xen_network *result, xen_pif pif) |
---|
155 | { |
---|
156 | abstract_value param_values[] = |
---|
157 | { |
---|
158 | { .type = &abstract_type_string, |
---|
159 | .u.string_val = pif } |
---|
160 | }; |
---|
161 | |
---|
162 | abstract_type result_type = abstract_type_string; |
---|
163 | |
---|
164 | *result = NULL; |
---|
165 | XEN_CALL_("PIF.get_network"); |
---|
166 | return session->ok; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | bool |
---|
171 | xen_pif_get_host(xen_session *session, xen_host *result, xen_pif pif) |
---|
172 | { |
---|
173 | abstract_value param_values[] = |
---|
174 | { |
---|
175 | { .type = &abstract_type_string, |
---|
176 | .u.string_val = pif } |
---|
177 | }; |
---|
178 | |
---|
179 | abstract_type result_type = abstract_type_string; |
---|
180 | |
---|
181 | *result = NULL; |
---|
182 | XEN_CALL_("PIF.get_host"); |
---|
183 | return session->ok; |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | bool |
---|
188 | xen_pif_get_mac(xen_session *session, char **result, xen_pif pif) |
---|
189 | { |
---|
190 | abstract_value param_values[] = |
---|
191 | { |
---|
192 | { .type = &abstract_type_string, |
---|
193 | .u.string_val = pif } |
---|
194 | }; |
---|
195 | |
---|
196 | abstract_type result_type = abstract_type_string; |
---|
197 | |
---|
198 | *result = NULL; |
---|
199 | XEN_CALL_("PIF.get_MAC"); |
---|
200 | return session->ok; |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | bool |
---|
205 | xen_pif_get_mtu(xen_session *session, int64_t *result, xen_pif pif) |
---|
206 | { |
---|
207 | abstract_value param_values[] = |
---|
208 | { |
---|
209 | { .type = &abstract_type_string, |
---|
210 | .u.string_val = pif } |
---|
211 | }; |
---|
212 | |
---|
213 | abstract_type result_type = abstract_type_int; |
---|
214 | |
---|
215 | XEN_CALL_("PIF.get_MTU"); |
---|
216 | return session->ok; |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | bool |
---|
221 | xen_pif_get_vlan(xen_session *session, int64_t *result, xen_pif pif) |
---|
222 | { |
---|
223 | abstract_value param_values[] = |
---|
224 | { |
---|
225 | { .type = &abstract_type_string, |
---|
226 | .u.string_val = pif } |
---|
227 | }; |
---|
228 | |
---|
229 | abstract_type result_type = abstract_type_int; |
---|
230 | |
---|
231 | XEN_CALL_("PIF.get_VLAN"); |
---|
232 | return session->ok; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | bool |
---|
237 | xen_pif_get_metrics(xen_session *session, xen_pif_metrics *result, xen_pif pif) |
---|
238 | { |
---|
239 | abstract_value param_values[] = |
---|
240 | { |
---|
241 | { .type = &abstract_type_string, |
---|
242 | .u.string_val = pif } |
---|
243 | }; |
---|
244 | |
---|
245 | abstract_type result_type = abstract_type_string; |
---|
246 | |
---|
247 | *result = NULL; |
---|
248 | XEN_CALL_("PIF.get_metrics"); |
---|
249 | return session->ok; |
---|
250 | } |
---|
251 | |
---|
252 | |
---|
253 | bool |
---|
254 | xen_pif_set_device(xen_session *session, xen_pif pif, char *device) |
---|
255 | { |
---|
256 | abstract_value param_values[] = |
---|
257 | { |
---|
258 | { .type = &abstract_type_string, |
---|
259 | .u.string_val = pif }, |
---|
260 | { .type = &abstract_type_string, |
---|
261 | .u.string_val = device } |
---|
262 | }; |
---|
263 | |
---|
264 | xen_call_(session, "PIF.set_device", param_values, 2, NULL, NULL); |
---|
265 | return session->ok; |
---|
266 | } |
---|
267 | |
---|
268 | |
---|
269 | bool |
---|
270 | xen_pif_set_mac(xen_session *session, xen_pif pif, char *mac) |
---|
271 | { |
---|
272 | abstract_value param_values[] = |
---|
273 | { |
---|
274 | { .type = &abstract_type_string, |
---|
275 | .u.string_val = pif }, |
---|
276 | { .type = &abstract_type_string, |
---|
277 | .u.string_val = mac } |
---|
278 | }; |
---|
279 | |
---|
280 | xen_call_(session, "PIF.set_MAC", param_values, 2, NULL, NULL); |
---|
281 | return session->ok; |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | bool |
---|
286 | xen_pif_set_mtu(xen_session *session, xen_pif pif, int64_t mtu) |
---|
287 | { |
---|
288 | abstract_value param_values[] = |
---|
289 | { |
---|
290 | { .type = &abstract_type_string, |
---|
291 | .u.string_val = pif }, |
---|
292 | { .type = &abstract_type_int, |
---|
293 | .u.int_val = mtu } |
---|
294 | }; |
---|
295 | |
---|
296 | xen_call_(session, "PIF.set_MTU", param_values, 2, NULL, NULL); |
---|
297 | return session->ok; |
---|
298 | } |
---|
299 | |
---|
300 | |
---|
301 | bool |
---|
302 | xen_pif_set_vlan(xen_session *session, xen_pif pif, int64_t vlan) |
---|
303 | { |
---|
304 | abstract_value param_values[] = |
---|
305 | { |
---|
306 | { .type = &abstract_type_string, |
---|
307 | .u.string_val = pif }, |
---|
308 | { .type = &abstract_type_int, |
---|
309 | .u.int_val = vlan } |
---|
310 | }; |
---|
311 | |
---|
312 | xen_call_(session, "PIF.set_VLAN", param_values, 2, NULL, NULL); |
---|
313 | return session->ok; |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | bool |
---|
318 | xen_pif_create_vlan(xen_session *session, xen_pif *result, char *device, xen_network network, xen_host host, int64_t vlan) |
---|
319 | { |
---|
320 | abstract_value param_values[] = |
---|
321 | { |
---|
322 | { .type = &abstract_type_string, |
---|
323 | .u.string_val = device }, |
---|
324 | { .type = &abstract_type_string, |
---|
325 | .u.string_val = network }, |
---|
326 | { .type = &abstract_type_string, |
---|
327 | .u.string_val = host }, |
---|
328 | { .type = &abstract_type_int, |
---|
329 | .u.int_val = vlan } |
---|
330 | }; |
---|
331 | |
---|
332 | abstract_type result_type = abstract_type_string; |
---|
333 | |
---|
334 | *result = NULL; |
---|
335 | XEN_CALL_("PIF.create_VLAN"); |
---|
336 | return session->ok; |
---|
337 | } |
---|
338 | |
---|
339 | |
---|
340 | bool |
---|
341 | xen_pif_destroy(xen_session *session, xen_pif self) |
---|
342 | { |
---|
343 | abstract_value param_values[] = |
---|
344 | { |
---|
345 | { .type = &abstract_type_string, |
---|
346 | .u.string_val = self } |
---|
347 | }; |
---|
348 | |
---|
349 | xen_call_(session, "PIF.destroy", param_values, 1, NULL, NULL); |
---|
350 | return session->ok; |
---|
351 | } |
---|
352 | |
---|
353 | |
---|
354 | bool |
---|
355 | xen_pif_get_all(xen_session *session, struct xen_pif_set **result) |
---|
356 | { |
---|
357 | |
---|
358 | abstract_type result_type = abstract_type_string_set; |
---|
359 | |
---|
360 | *result = NULL; |
---|
361 | xen_call_(session, "PIF.get_all", NULL, 0, &result_type, result); |
---|
362 | return session->ok; |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | bool |
---|
367 | xen_pif_get_uuid(xen_session *session, char **result, xen_pif pif) |
---|
368 | { |
---|
369 | abstract_value param_values[] = |
---|
370 | { |
---|
371 | { .type = &abstract_type_string, |
---|
372 | .u.string_val = pif } |
---|
373 | }; |
---|
374 | |
---|
375 | abstract_type result_type = abstract_type_string; |
---|
376 | |
---|
377 | *result = NULL; |
---|
378 | XEN_CALL_("PIF.get_uuid"); |
---|
379 | return session->ok; |
---|
380 | } |
---|