aboutsummaryrefslogtreecommitdiffstats
path: root/src/dumm/iface.h
blob: ae886acc321e146b1bab4dfd386d3da967495803 (plain)
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
/*
 * Copyright (C) 2007 Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * 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; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * 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.
 */

#ifndef IFACE_H
#define IFACE_H

#include <library.h>
#include <collections/enumerator.h>
#include <networking/host.h>

#define TAP_DEVICE "/dev/net/tun"

typedef struct iface_t iface_t;

#include "mconsole.h"
#include "bridge.h"
#include "guest.h"

/**
 * Interface in a guest, connected to a tap device on the host.
 */
struct iface_t {

	/**
	 * Get the interface name in the guest (e.g. eth0).
	 *
	 * @return			guest interface name
	 */
	char* (*get_guestif)(iface_t *this);

	/**
	 * Get the interface name at the host (e.g. tap0).
	 *
	 * @return			host interface (tap device) name
	 */
	char* (*get_hostif)(iface_t *this);

	/**
	 * Add an address to the interface.
	 *
	 * @param addr		address to add to the interface
	 * @param bits		network prefix length in bits
	 * @return			TRUE if address added
	 */
	bool (*add_address)(iface_t *this, host_t *addr, int bits);

	/**
	 * Create an enumerator over all installed addresses.
	 *
	 * @return			enumerator over host_t*
	 */
	enumerator_t* (*create_address_enumerator)(iface_t *this);

	/**
	 * Remove an address from an interface.
	 *
	 * @note The network prefix length has to be the same as used in add_address
	 *
	 * @param addr		address to remove
	 * @param bits		network prefix length in bits
	 * @return			TRUE if address removed
	 */
	bool (*delete_address)(iface_t *this, host_t *addr, int bits);

	/**
	 * Set the bridge this interface is attached to.
	 *
	 * @param bridge	assigned bridge, or NULL for none
	 */
	void (*set_bridge)(iface_t *this, bridge_t *bridge);

	/**
	 * Get the bridge this iface is connected, or NULL.
	 *
	 * @return			connected bridge, or NULL
	 */
	bridge_t* (*get_bridge)(iface_t *this);

	/**
	 * Get the guest this iface belongs to.
	 *
	 * @return			guest of this iface
	 */
	guest_t* (*get_guest)(iface_t *this);

	/**
	 * Destroy an interface
	 */
	void (*destroy) (iface_t *this);
};

/**
 * Create a new interface for a guest
 *
 * @param name		name of the interface in the guest
 * @param guest		guest this iface is connecting
 * @param mconsole	mconsole of guest
 * @return			interface descriptor, or NULL if failed
 */
iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole);

#endif /* IFACE_H */