More Slirp cleanups.

This commit is contained in:
waltje
2017-05-11 03:30:55 -04:00
parent deb30e41a0
commit ced75af0c2
4 changed files with 47 additions and 57 deletions

View File

@@ -119,7 +119,7 @@ getouraddr()
our_addr.s_addr = loopback_addr.s_addr; our_addr.s_addr = loopback_addr.s_addr;
#endif #endif
#undef ANCIENT #undef ANCIENT
pclog("My IP address: %s (%s)\n", inet_ntoa(our_addr), buff); pclog(" Our IP address: %s (%s)\n", inet_ntoa(our_addr), buff);
} }
//#if SIZEOF_CHAR_P == 8 //#if SIZEOF_CHAR_P == 8

View File

@@ -1,23 +1,20 @@
#include "slirp.h" #include "slirp.h"
/* host address */
struct in_addr our_addr;
/* host dns address */
struct in_addr dns_addr;
/* host loopback address */
struct in_addr loopback_addr;
/* address for slirp virtual addresses */ /* Our actual addresses. */
struct in_addr special_addr; char slirp_hostname[33];
/* virtual address alias for host */ struct in_addr our_addr; /* host IP address */
struct in_addr alias_addr; struct in_addr dns_addr; /* host DNS server */
struct in_addr loopback_addr; /* host loopback address */
/* FIXME: this is probably not working with new MAC address stuff.. --FvK */ /* Our SLiRP virtual addresses. */
struct in_addr special_addr; /* virtual IP address */
struct in_addr alias_addr; /* virtual address alias for host */
const uint8_t special_ethaddr[6] = { const uint8_t special_ethaddr[6] = {
0x52, 0x54, 0x00, 0x12, 0x35, 0x00 0x52, 0x54, 0x00, 0x12, 0x35, 0x00 /* virtual MAC address. */
}; };
uint8_t client_ethaddr[6]; uint8_t client_ethaddr[6]; /* guest's MAC address */
int do_slowtimo; int do_slowtimo;
int link_up; int link_up;
@@ -28,8 +25,6 @@ struct ex_list *exec_list;
/* XXX: suppress those select globals */ /* XXX: suppress those select globals */
fd_set *global_readfds, *global_writefds, *global_xfds; fd_set *global_readfds, *global_writefds, *global_xfds;
char slirp_hostname[33];
extern void pclog(const char *, ...); extern void pclog(const char *, ...);
extern int config_get_int(char *, char *, int); extern int config_get_int(char *, char *, int);
@@ -67,16 +62,11 @@ static int get_dns_addr(struct in_addr *pdns_addr)
pIPAddr = &(FixedInfo->DnsServerList); pIPAddr = &(FixedInfo->DnsServerList);
inet_aton(pIPAddr->IpAddress.String, &tmp_addr); inet_aton(pIPAddr->IpAddress.String, &tmp_addr);
*pdns_addr = tmp_addr; *pdns_addr = tmp_addr;
#if 1 printf( " DNS Servers:\n" );
printf( "DNS Servers:\n" );
printf( "DNS Addr:%s\n", pIPAddr->IpAddress.String );
pIPAddr = FixedInfo -> DnsServerList.Next;
while ( pIPAddr ) { while ( pIPAddr ) {
printf( "DNS Addr:%s\n", pIPAddr ->IpAddress.String ); printf( " Address: %s\n", pIPAddr ->IpAddress.String );
pIPAddr = pIPAddr ->Next; pIPAddr = pIPAddr ->Next;
} }
#endif
if (FixedInfo) { if (FixedInfo) {
GlobalFree(FixedInfo); GlobalFree(FixedInfo);
FixedInfo = NULL; FixedInfo = NULL;
@@ -132,13 +122,17 @@ void slirp_cleanup(void)
} }
#endif #endif
int slirp_init(void)
int
slirp_init(void)
{ {
struct in_addr myaddr; char* category = "SLiRP Port Forwarding";
int rc; char key[32];
char* category = "SLiRP Port Forwarding"; struct in_addr myaddr;
char key[32]; int i = 0, udp, from, to;
int i = 0, udp, from, to; int rc;
pclog("%s initializing..\n", category);
#ifdef SLIRP_DEBUG #ifdef SLIRP_DEBUG
// debug_init("/tmp/slirp.log", DEBUG_DEFAULT); // debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
@@ -170,29 +164,28 @@ debug_init("slirplog.txt",DEBUG_DEFAULT);
return -1; return -1;
inet_aton(CTL_SPECIAL, &special_addr); inet_aton(CTL_SPECIAL, &special_addr);
alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS);
getouraddr(); getouraddr();
inet_aton(CTL_LOCAL, &myaddr);
inet_aton("10.0.2.15",&myaddr); while (1) {
sprintf(key, "%d_udp", i);
udp = config_get_int(category, key, 0);
sprintf(key, "%d_from", i);
from = config_get_int(category, key, 0);
if (from < 1)
break;
sprintf(key, "%d_to", i);
to = config_get_int(category, key, from);
while (1) { rc = slirp_redir(udp, from, myaddr, to);
sprintf(key, "%d_udp", i); if (rc == 0)
udp = config_get_int(category, key, 0); pclog("slirp redir %d -> %d successful\n", from, to);
sprintf(key, "%d_from", i); else
from = config_get_int(category, key, 0); pclog("slirp redir %d -> %d failed (%d)\n", from, to, rc);
if (from < 1)
break;
sprintf(key, "%d_to", i);
to = config_get_int(category, key, from);
rc = slirp_redir(udp, from, myaddr, to); i++;
if (rc == 0) }
pclog("slirp redir %d -> %d successful\n", from, to);
else
pclog("slirp redir %d -> %d failed (%d)\n", from, to, rc);
i++;
}
return 0; return 0;
} }
@@ -648,7 +641,6 @@ void slirp_input(const uint8_t *pkt, int pkt_len)
struct SLIRPmbuf *m; struct SLIRPmbuf *m;
int proto; int proto;
pclog("SLIRP_input(%08lx, %d)\n", pkt, pkt_len);
if (pkt_len < ETH_HLEN) if (pkt_len < ETH_HLEN)
return; return;

View File

@@ -1,8 +1,6 @@
#ifndef __COMMON_H__ #ifndef __COMMON_H__
#define __COMMON_H__ #define __COMMON_H__
#define SLIRP_DEBUG 1
#define SLIRP_VERSION "Cockatrice special" #define SLIRP_VERSION "Cockatrice special"
#define CONFIG_QEMU #define CONFIG_QEMU

View File

@@ -39,11 +39,11 @@ extern int timer_start;
timer_update_outstanding(); \ timer_update_outstanding(); \
} while (0) } while (0)
void timer_process(); extern void timer_process(void);
void timer_update_outstanding(); extern void timer_update_outstanding(void);
void timer_reset(); extern void timer_reset(void);
int timer_add(void (*callback)(void *priv), int *count, int *enable, void *priv); extern int timer_add(void (*callback)(void *priv), int *count, int *enable, void *priv);
void timer_set_callback(int timer, void (*callback)(void *priv)); extern void timer_set_callback(int timer, void (*callback)(void *priv));
#define TIMER_ALWAYS_ENABLED &timer_one #define TIMER_ALWAYS_ENABLED &timer_one