Moved host_t and host_resolver_t to a new networking subfolder
[strongswan.git] / src / dumm / iface.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 IFACE_H
17 #define IFACE_H
18
19 #include <library.h>
20 #include <utils/enumerator.h>
21 #include <networking/host.h>
22
23 #define TAP_DEVICE "/dev/net/tun"
24
25 typedef struct iface_t iface_t;
26
27 #include "mconsole.h"
28 #include "bridge.h"
29 #include "guest.h"
30
31 /**
32 * Interface in a guest, connected to a tap device on the host.
33 */
34 struct iface_t {
35
36 /**
37 * Get the interface name in the guest (e.g. eth0).
38 *
39 * @return guest interface name
40 */
41 char* (*get_guestif)(iface_t *this);
42
43 /**
44 * Get the interface name at the host (e.g. tap0).
45 *
46 * @return host interface (tap device) name
47 */
48 char* (*get_hostif)(iface_t *this);
49
50 /**
51 * Add an address to the interface.
52 *
53 * @param addr address to add to the interface
54 * @param bits network prefix length in bits
55 * @return TRUE if address added
56 */
57 bool (*add_address)(iface_t *this, host_t *addr, int bits);
58
59 /**
60 * Create an enumerator over all installed addresses.
61 *
62 * @return enumerator over host_t*
63 */
64 enumerator_t* (*create_address_enumerator)(iface_t *this);
65
66 /**
67 * Remove an address from an interface.
68 *
69 * @note The network prefix length has to be the same as used in add_address
70 *
71 * @param addr address to remove
72 * @param bits network prefix length in bits
73 * @return TRUE if address removed
74 */
75 bool (*delete_address)(iface_t *this, host_t *addr, int bits);
76
77 /**
78 * Set the bridge this interface is attached to.
79 *
80 * @param bridge assigned bridge, or NULL for none
81 */
82 void (*set_bridge)(iface_t *this, bridge_t *bridge);
83
84 /**
85 * Get the bridge this iface is connected, or NULL.
86 *
87 * @return connected bridge, or NULL
88 */
89 bridge_t* (*get_bridge)(iface_t *this);
90
91 /**
92 * Get the guest this iface belongs to.
93 *
94 * @return guest of this iface
95 */
96 guest_t* (*get_guest)(iface_t *this);
97
98 /**
99 * Destroy an interface
100 */
101 void (*destroy) (iface_t *this);
102 };
103
104 /**
105 * Create a new interface for a guest
106 *
107 * @param name name of the interface in the guest
108 * @param guest guest this iface is connecting
109 * @param mconsole mconsole of guest
110 * @return interface descriptor, or NULL if failed
111 */
112 iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole);
113
114 #endif /* IFACE_H */
115