/[dynamips]/upstream/dynamips-0.2.5/net_io.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/dynamips-0.2.5/net_io.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Sat Oct 6 16:01:44 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 7275 byte(s)
import 0.2.5 from upstream

1 /*
2 * Cisco 7200 (Predator) simulation platform.
3 * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Network interaction.
6 */
7
8 #ifndef __NET_IO_H__
9 #define __NET_IO_H__
10
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <sys/un.h>
14 #include <pthread.h>
15 #include "utils.h"
16
17 #ifdef LINUX_ETH
18 #include "linux_eth.h"
19 #endif
20 #ifdef GEN_ETH
21 #include "gen_eth.h"
22 #endif
23
24 /* Maximum packet size */
25 #define NETIO_MAX_PKT_SIZE 8192
26
27 /* Maximum device length */
28 #define NETIO_DEV_MAXLEN 64
29
30 enum {
31 NETIO_TYPE_UNIX = 0,
32 NETIO_TYPE_VDE,
33 NETIO_TYPE_TAP,
34 NETIO_TYPE_UDP,
35 NETIO_TYPE_TCP_CLI,
36 NETIO_TYPE_TCP_SER,
37 #ifdef LINUX_ETH
38 NETIO_TYPE_LINUX_ETH,
39 #endif
40 #ifdef GEN_ETH
41 NETIO_TYPE_GEN_ETH,
42 #endif
43 NETIO_TYPE_FIFO,
44 NETIO_TYPE_NULL,
45 NETIO_TYPE_MAX,
46 };
47
48 enum {
49 NETIO_FILTER_ACTION_DROP = 0,
50 NETIO_FILTER_ACTION_PASS,
51 NETIO_FILTER_ACTION_ALTER,
52 NETIO_FILTER_ACTION_DUPLICATE,
53 };
54
55 typedef struct netio_desc netio_desc_t;
56
57 /* VDE switch definitions */
58 enum vde_request_type { VDE_REQ_NEW_CONTROL };
59
60 #define VDE_SWITCH_MAGIC 0xfeedface
61 #define VDE_SWITCH_VERSION 3
62
63 struct vde_request_v3 {
64 m_uint32_t magic;
65 m_uint32_t version;
66 enum vde_request_type type;
67 struct sockaddr_un sock;
68 };
69
70 /* netio unix descriptor */
71 typedef struct netio_unix_desc netio_unix_desc_t;
72 struct netio_unix_desc {
73 char *local_filename;
74 struct sockaddr_un remote_sock;
75 int fd;
76 };
77
78 /* netio vde descriptor */
79 typedef struct netio_vde_desc netio_vde_desc_t;
80 struct netio_vde_desc {
81 char *local_filename;
82 struct sockaddr_un remote_sock;
83 int ctrl_fd,data_fd;
84 };
85
86 /* netio tap descriptor */
87 typedef struct netio_tap_desc netio_tap_desc_t;
88 struct netio_tap_desc {
89 char filename[NETIO_DEV_MAXLEN];
90 int fd;
91 };
92
93 /* netio udp/tcp descriptor */
94 typedef struct netio_inet_desc netio_inet_desc_t;
95 struct netio_inet_desc {
96 int local_port,remote_port;
97 char *remote_host;
98 int fd;
99 };
100
101 #ifdef LINUX_ETH
102 /* netio linux raw ethernet descriptor */
103 typedef struct netio_lnxeth_desc netio_lnxeth_desc_t;
104 struct netio_lnxeth_desc {
105 char dev_name[NETIO_DEV_MAXLEN];
106 int dev_id,fd;
107 };
108 #endif
109
110 #ifdef GEN_ETH
111 /* netio generic raw ethernet descriptor */
112 typedef struct netio_geneth_desc netio_geneth_desc_t;
113 struct netio_geneth_desc {
114 char dev_name[NETIO_DEV_MAXLEN];
115 pcap_t *pcap_dev;
116 };
117 #endif
118
119 /* FIFO packet */
120 typedef struct netio_fifo_pkt netio_fifo_pkt_t;
121 struct netio_fifo_pkt {
122 netio_fifo_pkt_t *next;
123 size_t pkt_len;
124 char pkt[0];
125 };
126
127 /* Netio FIFO */
128 typedef struct netio_fifo_desc netio_fifo_desc_t;
129 struct netio_fifo_desc {
130 pthread_cond_t cond;
131 pthread_mutex_t lock,endpoint_lock;
132 netio_fifo_desc_t *endpoint;
133 netio_fifo_pkt_t *head,*last;
134 u_int pkt_count;
135 };
136
137 /* Packet filter */
138 typedef struct netio_pktfilter netio_pktfilter_t;
139 struct netio_pktfilter {
140 char *name;
141 int (*setup)(netio_desc_t *nio,void **opt,int argc,char *argv[]);
142 void (*free)(netio_desc_t *nio,void **opt);
143 int (*pkt_handler)(netio_desc_t *nio,void *pkt,size_t len,void *opt);
144 netio_pktfilter_t *next;
145 };
146
147 /* Generic netio descriptor */
148 struct netio_desc {
149 u_int type;
150 void *dptr;
151 char *name;
152 int debug;
153
154 /* Frame Relay specific information */
155 m_uint8_t fr_lmi_seq;
156 void *fr_conn_list;
157
158 /* Ethernet specific information */
159 u_int vlan_port_type;
160 m_uint16_t vlan_id;
161 void *vlan_input_vector;
162
163 union {
164 netio_unix_desc_t nud;
165 netio_vde_desc_t nvd;
166 netio_tap_desc_t ntd;
167 netio_inet_desc_t nid;
168 #ifdef LINUX_ETH
169 netio_lnxeth_desc_t nled;
170 #endif
171 #ifdef GEN_ETH
172 netio_geneth_desc_t nged;
173 #endif
174 netio_fifo_desc_t nfd;
175 } u;
176
177 /* Send and receive prototypes */
178 ssize_t (*send)(void *desc,void *pkt,size_t len);
179 ssize_t (*recv)(void *desc,void *pkt,size_t len);
180
181 /* Configuration saving */
182 void (*save_cfg)(netio_desc_t *nio,FILE *fd);
183
184 /* Packet filters */
185 netio_pktfilter_t *rx_filter,*tx_filter;
186 void *rx_filter_data,*tx_filter_data;
187
188 /* Next pointer (for RX listener) */
189 netio_desc_t *rxl_next;
190 };
191
192 /* RX listener */
193 typedef int (*netio_rx_handler_t)(netio_desc_t *nio,
194 u_char *pkt,ssize_t pkt_len,
195 void *arg1,void *arg2);
196
197 struct netio_rx_listener {
198 netio_desc_t *nio;
199 u_int ref_count;
200 volatile int running;
201 netio_rx_handler_t rx_handler;
202 void *arg1,*arg2;
203 pthread_t spec_thread;
204 struct netio_rx_listener *prev,*next;
205 };
206
207 /* Get NETIO type given a description */
208 int netio_get_type(char *type);
209
210 /* Show the NETIO types */
211 void netio_show_types(void);
212
213 /* Create a new NetIO descriptor */
214 netio_desc_t *netio_desc_create_unix(char *nio_name,char *local,char *remote);
215
216 /* Create a new NetIO descriptor with VDE method */
217 netio_desc_t *netio_desc_create_vde(char *nio_name,char *control,char *local);
218
219 /* Create a new NetIO descriptor with TAP method */
220 netio_desc_t *netio_desc_create_tap(char *nio_name,char *tap_name);
221
222 /* Create a new NetIO descriptor with TCP_CLI method */
223 netio_desc_t *netio_desc_create_tcp_cli(char *nio_name,char *addr,char *port);
224
225 /* Create a new NetIO descriptor with TCP_SER method */
226 netio_desc_t *netio_desc_create_tcp_ser(char *nio_name,char *port);
227
228 /* Create a new NetIO descriptor with UDP method */
229 netio_desc_t *netio_desc_create_udp(char *nio_name,int local_port,
230 char *remote_host,int remote_port);
231
232 #ifdef LINUX_ETH
233 /* Create a new NetIO descriptor with raw Ethernet method */
234 netio_desc_t *netio_desc_create_lnxeth(char *nio_name,char *dev_name);
235 #endif
236
237 #ifdef GEN_ETH
238 /* Create a new NetIO descriptor with generic raw Ethernet method */
239 netio_desc_t *netio_desc_create_geneth(char *nio_name,char *dev_name);
240 #endif
241
242 /* Establish a cross-connect between two FIFO NetIO */
243 int netio_fifo_crossconnect(netio_desc_t *a,netio_desc_t *b);
244
245 /* Create a new NetIO descriptor with FIFO method */
246 netio_desc_t *netio_desc_create_fifo(char *nio_name);
247
248 /* Create a new NetIO descriptor with NULL method */
249 netio_desc_t *netio_desc_create_null(char *nio_name);
250
251 /* Acquire a reference to NIO from registry (increment reference count) */
252 netio_desc_t *netio_acquire(char *name);
253
254 /* Release an NIO (decrement reference count) */
255 int netio_release(char *name);
256
257 /* Delete a NetIO descriptor */
258 int netio_delete(char *name);
259
260 /* Delete all NetIO descriptors */
261 int netio_delete_all(void);
262
263 /* Save the configuration of a NetIO descriptor */
264 void netio_save_config(netio_desc_t *nio,FILE *fd);
265
266 /* Save configurations of all NetIO descriptors */
267 void netio_save_config_all(FILE *fd);
268
269 /* Send a packet through a NetIO descriptor */
270 ssize_t netio_send(netio_desc_t *nio,void *pkt,size_t len);
271
272 /* Receive a packet through a NetIO descriptor */
273 ssize_t netio_recv(netio_desc_t *nio,void *pkt,size_t max_len);
274
275 /* Get a NetIO FD */
276 int netio_get_fd(netio_desc_t *nio);
277
278 /* Enable a RX listener */
279 int netio_rxl_enable(netio_desc_t *nio);
280
281 /* Add an RX listener in the listener list */
282 int netio_rxl_add(netio_desc_t *nio,netio_rx_handler_t rx_handler,
283 void *arg1,void *arg2);
284
285 /* Remove a NIO from the listener list */
286 int netio_rxl_remove(netio_desc_t *nio);
287
288 /* Initialize the RXL thread */
289 int netio_rxl_init(void);
290
291 #endif

  ViewVC Help
Powered by ViewVC 1.1.26