bridging using libbridge
[strongswan.git] / src / dumm / guest.h
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #ifndef GUEST_H
17 #define GUEST_H
18
19 #include <library.h>
20 #include <utils/iterator.h>
21
22 #include "iface.h"
23
24 #define MASTER_DIR "master"
25 #define DIFF_DIR "diff"
26 #define UNION_DIR "union"
27 #define MEMORY_FILE "mem"
28 #define KERNEL_FILE "linux"
29 #define LOG_FILE "boot.log"
30 #define NOTIFY_FILE "notify"
31
32 typedef enum guest_state_t guest_state_t;
33
34 /**
35 * @brief State of a guest (started, stopped, ...)
36 */
37 enum guest_state_t {
38 /** guest kernel not running at all */
39 GUEST_STOPPED,
40 /** kernel started, but not yet available */
41 GUEST_STARTING,
42 /** guest is up and running */
43 GUEST_RUNNING,
44 /** guest has been paused */
45 GUEST_PAUSED,
46 /** guest is stopping (shutting down) */
47 GUEST_STOPPING,
48 };
49
50 /**
51 * string mappings for guest_state_t
52 */
53 extern enum_name_t *guest_state_names;
54
55 typedef struct guest_t guest_t;
56
57 /**
58 * @brief A guest is a UML instance running on the host.
59 **/
60 struct guest_t {
61
62 /**
63 * @brief Get the name of this guest.
64 *
65 * @return name of the guest
66 */
67 char* (*get_name) (guest_t *this);
68
69 /**
70 * @brief Get the process ID of the guest child process.
71 *
72 * @return name of the guest
73 */
74 pid_t (*get_pid) (guest_t *this);
75 /**
76 * @brief Get the state of the guest (stopped, started, etc.).
77 *
78 * @return guests state
79 */
80 guest_state_t (*get_state)(guest_t *this);
81
82 /**
83 * @brief Start the guest.
84 *
85 * @param kernel kernel to boot for this guest
86 * @return TRUE if guest successfully started
87 */
88 bool (*start) (guest_t *this, char *kernel);
89
90 /**
91 * @brief Kill the guest.
92 *
93 * @return TRUE if guest was running and killed
94 */
95 bool (*stop) (guest_t *this);
96
97 /**
98 * @brief Create a new interface for that host.
99 *
100 * @param name name of the interface in the guest
101 * @return created interface, or NULL if failed
102 */
103 iface_t* (*create_iface)(guest_t *this, char *name);
104
105 /**
106 * @brief Create an iterator over all guest interfaces.
107 *
108 * @return iterator over iface_t's
109 */
110 iterator_t* (*create_iface_iterator)(guest_t *this);
111
112 /**
113 * @brief Called whenever a SIGCHILD is received.
114 */
115 void (*sigchild)(guest_t *this);
116
117 /**
118 * @brief Close and destroy a guest with all interfaces
119 */
120 void (*destroy) (guest_t *this);
121 };
122
123 /**
124 * @brief Create a new, unstarted guest.
125 *
126 * @param parent parent directory to create the guest in
127 * @param name name of the guest to create
128 * @param kernel kernel this guest uses
129 * @param master read-only master filesystem for guest
130 * @param mem amount of memory to give the guest
131 */
132 guest_t *guest_create(char *parent, char *name, char *kernel,
133 char *master, int mem);
134
135 /**
136 * @brief Load a guest created with guest_create().
137 *
138 * @param parent parent directory to look for a guest
139 * @param name name of the guest directory
140 */
141 guest_t *guest_load(char *parent, char *name);
142
143 #endif /* GUEST_H */
144