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

Annotation of /upstream/dynamips-0.2.7-RC1/hv_nio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Sat Oct 6 16:05:34 2007 UTC (12 years, 2 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC2/hv_nio.c
File MIME type: text/plain
File size: 9167 byte(s)
dynamips-0.2.6-RC2

1 dpavlin 1 /*
2     * Cisco 7200 (Predator) simulation platform.
3     * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4     *
5     * Hypervisor NIO routines.
6     */
7    
8     #include <stdio.h>
9     #include <stdlib.h>
10     #include <unistd.h>
11     #include <string.h>
12     #include <sys/types.h>
13     #include <sys/stat.h>
14     #include <sys/mman.h>
15     #include <signal.h>
16     #include <fcntl.h>
17     #include <errno.h>
18     #include <assert.h>
19     #include <stdarg.h>
20     #include <sys/ioctl.h>
21     #include <sys/types.h>
22     #include <sys/socket.h>
23     #include <arpa/inet.h>
24     #include <pthread.h>
25    
26     #include "mips64.h"
27     #include "dynamips.h"
28     #include "utils.h"
29     #include "net.h"
30     #include "atm.h"
31     #include "frame_relay.h"
32     #include "crc.h"
33     #include "net_io.h"
34     #include "net_io_bridge.h"
35     #include "net_io_filter.h"
36     #ifdef GEN_ETH
37     #include "gen_eth.h"
38     #endif
39     #include "registry.h"
40     #include "hypervisor.h"
41    
42     /*
43     * Create a UDP NIO
44     *
45     * Parameters: <nio_name> <local_port> <remote_host> <remote_port>
46     */
47     static int cmd_create_udp(hypervisor_conn_t *conn,int argc,char *argv[])
48     {
49     netio_desc_t *nio;
50    
51     nio = netio_desc_create_udp(argv[0],atoi(argv[1]),argv[2],atoi(argv[3]));
52    
53     if (!nio) {
54     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
55     "unable to create UDP NIO");
56     return(-1);
57     }
58    
59     netio_release(argv[0]);
60     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
61     return(0);
62     }
63    
64     /*
65     * Create a UNIX NIO
66     *
67     * Parameters: <nio_name> <local_file> <remote_file>
68     */
69     static int cmd_create_unix(hypervisor_conn_t *conn,int argc,char *argv[])
70     {
71     netio_desc_t *nio;
72    
73     nio = netio_desc_create_unix(argv[0],argv[1],argv[2]);
74    
75     if (!nio) {
76     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,"unable to create UNIX NIO");
77     return(-1);
78     }
79    
80     netio_release(argv[0]);
81     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
82     return(0);
83     }
84    
85     /*
86     * Create a VDE NIO
87     *
88     * Parameters: <nio_name> <control_file> <local_file>
89     */
90     static int cmd_create_vde(hypervisor_conn_t *conn,int argc,char *argv[])
91     {
92     netio_desc_t *nio;
93    
94     nio = netio_desc_create_vde(argv[0],argv[1],argv[2]);
95    
96     if (!nio) {
97     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,"unable to create VDE NIO");
98     return(-1);
99     }
100    
101     netio_release(argv[0]);
102     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
103     return(0);
104     }
105    
106     /*
107     * Create a TAP NIO
108     *
109     * Parameters: <nio_name> <tap_device>
110     */
111     static int cmd_create_tap(hypervisor_conn_t *conn,int argc,char *argv[])
112     {
113     netio_desc_t *nio;
114    
115     nio = netio_desc_create_tap(argv[0],argv[1]);
116    
117     if (!nio) {
118     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,"unable to create TAP NIO");
119     return(-1);
120     }
121    
122     netio_release(argv[0]);
123     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
124     return(0);
125     }
126    
127     /*
128     * Create a generic ethernet PCAP NIO
129     *
130     * Parameters: <nio_name> <eth_device>
131     */
132     #ifdef GEN_ETH
133     static int cmd_create_gen_eth(hypervisor_conn_t *conn,int argc,char *argv[])
134     {
135     netio_desc_t *nio;
136    
137     nio = netio_desc_create_geneth(argv[0],argv[1]);
138    
139     if (!nio) {
140     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
141     "unable to create generic ethernet NIO");
142     return(-1);
143     }
144    
145     netio_release(argv[0]);
146     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
147     return(0);
148     }
149     #endif
150    
151     /*
152     * Create a linux raw ethernet NIO
153     *
154     * Parameters: <nio_name> <eth_device>
155     */
156     #ifdef LINUX_ETH
157     static int cmd_create_linux_eth(hypervisor_conn_t *conn,int argc,char *argv[])
158     {
159     netio_desc_t *nio;
160    
161     nio = netio_desc_create_lnxeth(argv[0],argv[1]);
162    
163     if (!nio) {
164     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
165     "unable to create Linux raw ethernet NIO");
166     return(-1);
167     }
168    
169     netio_release(argv[0]);
170     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
171     return(0);
172     }
173     #endif
174    
175     /*
176     * Create a Null NIO
177     *
178     * Parameters: <nio_name>
179     */
180     static int cmd_create_null(hypervisor_conn_t *conn,int argc,char *argv[])
181     {
182     netio_desc_t *nio;
183    
184     nio = netio_desc_create_null(argv[0]);
185    
186     if (!nio) {
187     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
188     "unable to create Null NIO");
189     return(-1);
190     }
191    
192     netio_release(argv[0]);
193     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
194     return(0);
195     }
196    
197     /*
198     * Create a FIFO NIO
199     *
200     * Parameters: <nio_name>
201     */
202     static int cmd_create_fifo(hypervisor_conn_t *conn,int argc,char *argv[])
203     {
204     netio_desc_t *nio;
205    
206     nio = netio_desc_create_fifo(argv[0]);
207    
208     if (!nio) {
209     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
210     "unable to create FIFO NIO");
211     return(-1);
212     }
213    
214     netio_release(argv[0]);
215     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' created",argv[0]);
216     return(0);
217     }
218    
219     /*
220     * Establish a cross-connect between 2 FIFO NIO
221     *
222     * Parameters: <nio_A_name> <nio_B_name>
223     */
224     static int cmd_crossconnect_fifo(hypervisor_conn_t *conn,int argc,char *argv[])
225     {
226     netio_desc_t *a,*b;
227    
228     if (!(a = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO)))
229     return(-1);
230    
231     if (!(b = hypervisor_find_object(conn,argv[1],OBJ_TYPE_NIO))) {
232     netio_release(argv[0]);
233     return(-1);
234     }
235    
236     netio_fifo_crossconnect(a,b);
237    
238     netio_release(argv[0]);
239     netio_release(argv[1]);
240    
241     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
242     return(0);
243     }
244    
245     /* Delete a NIO */
246     static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
247     {
248     int res;
249    
250     res = netio_delete(argv[0]);
251    
252     if (res == 1) {
253     hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' deleted",argv[0]);
254     } else {
255     hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
256     "unable to delete NIO '%s'",argv[0]);
257     }
258    
259     return(res);
260     }
261    
262     /*
263     * Enable/Disable debugging for an NIO
264     *
265     * Parameters: <nio_name> <debug_level>
266     */
267     static int cmd_set_debug(hypervisor_conn_t *conn,int argc,char *argv[])
268     {
269     netio_desc_t *nio;
270    
271     if (!(nio = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO)))
272     return(-1);
273    
274     nio->debug = atoi(argv[1]);
275    
276     netio_release(argv[0]);
277     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
278     return(0);
279     }
280    
281     /* Bind a packet filter */
282     static int cmd_bind_filter(hypervisor_conn_t *conn,int argc,char *argv[])
283     {
284     netio_desc_t *nio;
285     int res;
286    
287     if (!(nio = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO)))
288     return(-1);
289    
290     res = netio_filter_bind(nio,atoi(argv[1]),argv[2]);
291     netio_release(argv[0]);
292    
293     if (!res) {
294     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
295     } else {
296     hypervisor_send_reply(conn,HSC_ERR_UNK_OBJ,1,
297     "Unknown filter %s",argv[2]);
298     }
299     return(0);
300     }
301    
302     /* Unbind a packet filter */
303     static int cmd_unbind_filter(hypervisor_conn_t *conn,int argc,char *argv[])
304     {
305     netio_desc_t *nio;
306     int res;
307    
308     if (!(nio = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO)))
309     return(-1);
310    
311     res = netio_filter_unbind(nio,atoi(argv[1]));
312     netio_release(argv[0]);
313    
314     if (!res) {
315     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
316     } else {
317     hypervisor_send_reply(conn,HSC_ERR_UNK_OBJ,1,
318     "No filter previously defined");
319     }
320     return(0);
321     }
322    
323    
324     /* Setup a packet filter for a given NIO */
325     static int cmd_setup_filter(hypervisor_conn_t *conn,int argc,char *argv[])
326     {
327     netio_desc_t *nio;
328    
329     if (!(nio = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO)))
330     return(-1);
331    
332     netio_filter_setup(nio,atoi(argv[1]),argc-2,&argv[2]);
333     netio_release(argv[0]);
334    
335     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
336     return(0);
337     }
338    
339     /* Show info about a NIO object */
340     static void cmd_show_nio_list(registry_entry_t *entry,void *opt,int *err)
341     {
342     hypervisor_conn_t *conn = opt;
343     hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
344     }
345    
346     /* NIO List */
347     static int cmd_nio_list(hypervisor_conn_t *conn,int argc,char *argv[])
348     {
349     int err = 0;
350     registry_foreach_type(OBJ_TYPE_NIO,cmd_show_nio_list,conn,&err);
351     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
352     return(0);
353     }
354    
355     /* NIO commands */
356     static hypervisor_cmd_t nio_cmd_array[] = {
357     { "create_udp", 4, 4, cmd_create_udp, NULL },
358     { "create_unix", 3, 3, cmd_create_unix, NULL },
359     { "create_vde", 3, 3, cmd_create_vde, NULL },
360     { "create_tap", 2, 2, cmd_create_tap, NULL },
361     #ifdef GEN_ETH
362     { "create_gen_eth", 2, 2, cmd_create_gen_eth, NULL },
363     #endif
364     #ifdef LINUX_ETH
365     { "create_linux_eth", 2, 2, cmd_create_linux_eth, NULL },
366     #endif
367     { "create_null", 1, 1, cmd_create_null, NULL },
368     { "create_fifo", 1, 1, cmd_create_fifo, NULL },
369     { "crossconnect_fifo", 2, 2, cmd_crossconnect_fifo, NULL },
370     { "delete", 1, 1, cmd_delete, NULL },
371     { "set_debug", 2, 2, cmd_set_debug, NULL },
372     { "bind_filter", 3, 3, cmd_bind_filter, NULL },
373     { "unbind_filter", 2, 2, cmd_unbind_filter, NULL },
374     { "setup_filter", 2, 10, cmd_setup_filter, NULL },
375     { "list", 0, 0, cmd_nio_list, NULL },
376     { NULL, -1, -1, NULL, NULL },
377     };
378    
379     /* Hypervisor NIO initialization */
380     int hypervisor_nio_init(void)
381     {
382     hypervisor_module_t *module;
383    
384     module = hypervisor_register_module("nio");
385     assert(module != NULL);
386    
387     hypervisor_register_cmd_array(module,nio_cmd_array);
388     return(0);
389     }

  ViewVC Help
Powered by ViewVC 1.1.26