1 /////////////////////////////////////////////////////////////////////////
2 // $Id: eth.cc,v 1.27 2008/12/11 18:01:56 vruppert Exp $
3 /////////////////////////////////////////////////////////////////////////
5 // Copyright (C) 2001 MandrakeSoft S.A.
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 // eth.cc - helper code to find and create pktmover classes
29 // Peter Grehan (grehan@iprg.nokia.com) coded all of this
30 // NE2000/ether stuff.
32 // Define BX_PLUGGABLE in files that can be compiled into plugins. For
33 // platforms that require a special tag on exported symbols, BX_PLUGGABLE
34 // is used to know when we are exporting symbols and when we are importing.
37 #define NO_DEVICE_INCLUDES
44 #define LOG_THIS /* not needed */
46 eth_locator_c
*eth_locator_c::all
;
49 // Each pktmover module has a static locator class that registers
52 eth_locator_c::eth_locator_c(const char *type
)
60 extern class bx_null_locator_c bx_null_match
;
63 extern class bx_fbsd_locator_c bx_fbsd_match
;
66 extern class bx_linux_locator_c bx_linux_match
;
69 extern class bx_win32_locator_c bx_win32_match
;
72 extern class bx_tap_locator_c bx_tap_match
;
75 extern class bx_tuntap_locator_c bx_tuntap_match
;
78 extern class bx_vde_locator_c bx_vde_match
;
81 extern class bx_arpback_locator_c bx_arpback_match
;
83 extern class bx_vnet_locator_c bx_vnet_match
;
86 // Called by ethernet chip emulations to locate and create a pktmover
90 eth_locator_c::create(const char *type
, const char *netif
,
92 eth_rx_handler_t rxh
, void *rxarg
, const char *script
)
94 #ifdef eth_static_constructors
95 for (eth_locator_c
*p
= all
; p
!= NULL
; p
= p
->next
) {
96 if (strcmp(type
, p
->type
) == 0)
97 return (p
->allocate(netif
, macaddr
, rxh
, rxarg
, script
));
100 eth_locator_c
*ptr
= 0;
104 if (!strcmp(type
, "arpback"))
105 ptr
= (eth_locator_c
*) &bx_arpback_match
;
110 if (!strcmp(type
, "null"))
111 ptr
= (eth_locator_c
*) &bx_null_match
;
116 if (!strcmp(type
, "fbsd"))
117 ptr
= (eth_locator_c
*) &bx_fbsd_match
;
122 if (!strcmp(type
, "linux"))
123 ptr
= (eth_locator_c
*) &bx_linux_match
;
128 if (!strcmp(type
, "tuntap"))
129 ptr
= (eth_locator_c
*) &bx_tuntap_match
;
134 if (!strcmp(type
, "vde"))
135 ptr
= (eth_locator_c
*) &bx_vde_match
;
140 if (!strcmp(type
, "tap"))
141 ptr
= (eth_locator_c
*) &bx_tap_match
;
146 if(!strcmp(type
, "win32"))
147 ptr
= (eth_locator_c
*) &bx_win32_match
;
151 if (!strcmp(type
, "vnet"))
152 ptr
= (eth_locator_c
*) &bx_vnet_match
;
155 return (ptr
->allocate(netif
, macaddr
, rxh
, rxarg
, script
));
161 #if (HAVE_ETHERTAP==1) || (HAVE_TUNTAP==1) || (HAVE_VDE==1)
164 #include <sys/wait.h>
168 #define LOG_THIS bx_devices.pluginNE2kDevice->
170 // This is a utility script used for tuntap or ethertap
171 int execute_script(const char* scriptname
, char* arg1
)
176 char filename
[BX_PATHNAME_LEN
];
177 if (scriptname
[0]=='/') {
178 strcpy(filename
, scriptname
);
181 getcwd(filename
, BX_PATHNAME_LEN
);
182 strcat(filename
, "/");
183 strcat(filename
, scriptname
);
186 // execute the script
187 BX_INFO(("Executing script '%s %s'",filename
,arg1
));
188 execle(filename
, scriptname
, arg1
, NULL
, NULL
);
190 // if we get here there has been a problem
195 if (!WIFEXITED(status
)) {
198 return WEXITSTATUS(status
);
201 #endif // (HAVE_ETHERTAP==1) || (HAVE_TUNTAP==1)
203 #endif /* if BX_NETWORKING */