Some work on the new slirp module

- added dnssearch sources from latest Qemu slirp (currently unused feature)
- minor other updates from Qemu slirp
- add #if blocks around already up-to-date slirp sources for conditional compilation
- TODO: finish updating from Qemu and start fixing compiler warnings
This commit is contained in:
Volker Ruppert 2014-02-27 19:11:18 +00:00
parent 695d245116
commit 5ea6e8c941
20 changed files with 487 additions and 54 deletions

View File

@ -56,6 +56,7 @@ SLIRP_OBJS = \
slirp/bootp.o \
slirp/cksum.o \
slirp/compat.o \
slirp/dnssearch.o \
slirp/if.o \
slirp/ip_icmp.o \
slirp/ip_input.o \
@ -231,11 +232,16 @@ slirp/arp_table.o: slirp/arp_table.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.o: slirp/bootp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.o: slirp/bootp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/cksum.o: slirp/cksum.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
@ -246,16 +252,26 @@ slirp/compat.o: slirp/compat.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/if.o: slirp/if.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h ../iodev.h \
../../bochs.h ../../config.h ../../osdep.h ../../bx_debug/debug.h \
../../osdep.h ../../gui/siminterface.h ../../cpudb.h \
../../gui/paramtree.h ../../memory/memory.h ../../pc_system.h \
../../gui/gui.h ../../instrument/stubs/instrument.h ../../plugin.h \
../../extplugin.h ../../param_names.h
slirp/dnssearch.o: slirp/dnssearch.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/if.o: slirp/if.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/ip_icmp.o: slirp/ip_icmp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
@ -286,16 +302,16 @@ slirp/sbuf.o: slirp/sbuf.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_c
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/slirp.o: slirp/slirp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h ../iodev.h \
../../bochs.h ../../config.h ../../osdep.h ../../bx_debug/debug.h \
../../osdep.h ../../gui/siminterface.h ../../cpudb.h \
../../gui/paramtree.h ../../memory/memory.h ../../pc_system.h \
../../gui/gui.h ../../instrument/stubs/instrument.h ../../plugin.h \
../../extplugin.h ../../param_names.h
slirp/slirp.o: slirp/slirp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/socket.o: slirp/socket.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
@ -424,11 +440,16 @@ slirp/arp_table.lo: slirp/arp_table.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.lo: slirp/bootp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/bootp.lo: slirp/bootp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/cksum.lo: slirp/cksum.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
@ -439,16 +460,26 @@ slirp/compat.lo: slirp/compat.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h \
slirp/if.h slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/if.lo: slirp/if.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h ../iodev.h \
../../bochs.h ../../config.h ../../osdep.h ../../bx_debug/debug.h \
../../osdep.h ../../gui/siminterface.h ../../cpudb.h \
../../gui/paramtree.h ../../memory/memory.h ../../pc_system.h \
../../gui/gui.h ../../instrument/stubs/instrument.h ../../plugin.h \
../../extplugin.h ../../param_names.h
slirp/dnssearch.lo: slirp/dnssearch.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/if.lo: slirp/if.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h ../../osdep.h \
../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/ip_icmp.lo: slirp/ip_icmp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \
@ -479,16 +510,16 @@ slirp/sbuf.lo: slirp/sbuf.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h
slirp/slirp.lo: slirp/slirp.@CPP_SUFFIX@ slirp/slirp.h ../../config.h slirp/slirp_config.h \
slirp/debug.h slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h \
slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h \
slirp/ip_icmp.h slirp/mbuf.h slirp/sbuf.h slirp/socket.h slirp/if.h \
slirp/main.h slirp/misc.h slirp/bootp.h slirp/tftp.h ../iodev.h \
../../bochs.h ../../config.h ../../osdep.h ../../bx_debug/debug.h \
../../osdep.h ../../gui/siminterface.h ../../cpudb.h \
../../gui/paramtree.h ../../memory/memory.h ../../pc_system.h \
../../gui/gui.h ../../instrument/stubs/instrument.h ../../plugin.h \
../../extplugin.h ../../param_names.h
slirp/slirp.lo: slirp/slirp.@CPP_SUFFIX@ ../iodev.h ../../bochs.h ../../config.h \
../../osdep.h ../../bx_debug/debug.h ../../config.h ../../osdep.h \
../../gui/siminterface.h ../../cpudb.h ../../gui/paramtree.h \
../../memory/memory.h ../../pc_system.h ../../gui/gui.h \
../../instrument/stubs/instrument.h ../../plugin.h ../../extplugin.h \
../../param_names.h slirp/slirp.h slirp/slirp_config.h slirp/debug.h \
slirp/libslirp.h slirp/compat.h slirp/ip.h slirp/tcp.h slirp/tcp_var.h \
slirp/tcpip.h slirp/tcp_timer.h slirp/udp.h slirp/ip_icmp.h slirp/mbuf.h \
slirp/sbuf.h slirp/socket.h slirp/if.h slirp/main.h slirp/misc.h \
slirp/bootp.h slirp/tftp.h
slirp/socket.lo: slirp/socket.@CPP_SUFFIX@ slirp/slirp.h ../../config.h \
slirp/slirp_config.h slirp/debug.h slirp/libslirp.h slirp/compat.h \
slirp/ip.h slirp/tcp.h slirp/tcp_var.h slirp/tcpip.h slirp/tcp_timer.h \

View File

@ -117,7 +117,7 @@ bx_slirp_new_pktmover_c::bx_slirp_new_pktmover_c(const char *netif,
host.s_addr = htonl(0x0a000202); /* 10.0.2.2 */
dhcp.s_addr = htonl(0x0a00020f); /* 10.0.2.15 */
dns.s_addr = htonl(0x0a000203); /* 10.0.2.3 */
slirp = slirp_init(0, net, mask, host, NULL, netif, NULL, dhcp, dns, this);
slirp = slirp_init(0, net, mask, host, NULL, netif, NULL, dhcp, dns, NULL, this);
bx_slirp_instances++;
}

View File

@ -24,6 +24,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
{
const uint32_t broadcast_addr =
@ -95,3 +97,5 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
return 0;
}
#endif

View File

@ -21,8 +21,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "iodev.h"
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define LOG_THIS genlog->
/* XXX: only DHCP is supported */
#define LEASE_TIME (24 * 3600)
@ -287,6 +293,17 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
memcpy(q, slirp->client_hostname, val);
q += val;
}
if (slirp->vdnssearch) {
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
val = slirp->vdnssearch_len;
if (val + 1 > (int)spaceleft) {
BX_ERROR(("DHCP packet size exceeded, omitting domain-search option."));
} else {
memcpy(q, slirp->vdnssearch, val);
q += val;
}
}
} else {
static const char nak_msg[] = "requested address not available";
@ -318,3 +335,5 @@ void bootp_input(struct mbuf *m)
bootp_reply(m->slirp, bp);
}
}
#endif

View File

@ -32,6 +32,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
/*
* Checksum routine for Internet Protocol family headers (Portable Version).
*
@ -137,3 +139,5 @@ cont:
REDUCE;
return (~sum & 0xffff);
}
#endif

View File

@ -24,6 +24,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
void pstrcpy(char *buf, int buf_size, const char *str)
{
int c;
@ -94,3 +96,5 @@ int qemu_socket(int domain, int type, int protocol)
return ret;
}
#endif

View File

@ -0,0 +1,320 @@
/*
* Domain search option for DHCP (RFC 3397)
*
* Copyright (c) 2012 Klaus Stengel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "iodev.h"
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define LOG_THIS genlog->
static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119;
static const uint8_t MAX_OPT_LEN = 255;
static const uint8_t OPT_HEADER_LEN = 2;
static const uint8_t REFERENCE_LEN = 2;
struct compact_domain;
typedef struct compact_domain {
struct compact_domain *self;
struct compact_domain *refdom;
uint8_t *labels;
size_t len;
size_t common_octets;
} CompactDomain;
static size_t
domain_suffix_diffoff(const CompactDomain *a, const CompactDomain *b)
{
size_t la = a->len, lb = b->len;
uint8_t *da = a->labels + la, *db = b->labels + lb;
size_t i, lm = (la < lb) ? la : lb;
for (i = 0; i < lm; i++) {
da--; db--;
if (*da != *db) {
break;
}
}
return i;
}
static int domain_suffix_ord(const void *cva, const void *cvb)
{
const CompactDomain *a = (const CompactDomain*)cva, *b = (const CompactDomain*)cvb;
size_t la = a->len, lb = b->len;
size_t doff = domain_suffix_diffoff(a, b);
uint8_t ca = a->labels[la - doff];
uint8_t cb = b->labels[lb - doff];
if (ca < cb) {
return -1;
}
if (ca > cb) {
return 1;
}
if (la < lb) {
return -1;
}
if (la > lb) {
return 1;
}
return 0;
}
static size_t domain_common_label(CompactDomain *a, CompactDomain *b)
{
size_t res, doff = domain_suffix_diffoff(a, b);
uint8_t *first_eq_pos = a->labels + (a->len - doff);
uint8_t *label = a->labels;
while (*label && label < first_eq_pos) {
label += *label + 1;
}
res = a->len - (label - a->labels);
/* only report if it can help to reduce the packet size */
return (res > REFERENCE_LEN) ? res : 0;
}
static void domain_fixup_order(CompactDomain *cd, size_t n)
{
size_t i;
for (i = 0; i < n; i++) {
CompactDomain *cur = cd + i, *next = cd[i].self;
while (!cur->common_octets) {
CompactDomain *tmp = next->self; /* backup target value */
next->self = cur;
cur->common_octets++;
cur = next;
next = tmp;
}
}
}
static void domain_mklabels(CompactDomain *cd, const char *input)
{
uint8_t *len_marker = cd->labels;
uint8_t *output = len_marker; /* pre-incremented */
const char *in = input;
char cur_chr;
size_t len = 0;
if (cd->len == 0) {
goto fail;
}
cd->len++;
do {
cur_chr = *in++;
if (cur_chr == '.' || cur_chr == '\0') {
len = output - len_marker;
if ((len == 0 && cur_chr == '.') || len >= 64) {
goto fail;
}
*len_marker = len;
output++;
len_marker = output;
} else {
output++;
*output = cur_chr;
}
} while (cur_chr != '\0');
/* ensure proper zero-termination */
if (len != 0) {
*len_marker = 0;
cd->len++;
}
return;
fail:
BX_ERROR(("failed to parse domain name '%s'\n", input));
cd->len = 0;
}
static void
domain_mkxrefs(CompactDomain *doms, CompactDomain *last, size_t depth)
{
CompactDomain *i = doms, *target = doms;
do {
if (i->labels < target->labels) {
target = i;
}
} while (i++ != last);
for (i = doms; i != last; i++) {
CompactDomain *group_last;
size_t next_depth;
if (i->common_octets == depth) {
continue;
}
next_depth = -1;
for (group_last = i; group_last != last; group_last++) {
size_t co = group_last->common_octets;
if (co <= depth) {
break;
}
if (co < next_depth) {
next_depth = co;
}
}
domain_mkxrefs(i, group_last, next_depth);
i = group_last;
if (i == last) {
break;
}
}
if (depth == 0) {
return;
}
i = doms;
do {
if (i != target && i->refdom == NULL) {
i->refdom = target;
i->common_octets = depth;
}
} while (i++ != last);
}
static size_t domain_compactify(CompactDomain *domains, size_t n)
{
uint8_t *start = domains->self->labels, *outptr = start;
size_t i;
for (i = 0; i < n; i++) {
CompactDomain *cd = domains[i].self;
CompactDomain *rd = cd->refdom;
if (rd != NULL) {
size_t moff = (rd->labels - start)
+ (rd->len - cd->common_octets);
if (moff < 0x3FFFu) {
cd->len -= cd->common_octets - 2;
cd->labels[cd->len - 1] = moff & 0xFFu;
cd->labels[cd->len - 2] = 0xC0u | (moff >> 8);
}
}
if (cd->labels != outptr) {
memmove(outptr, cd->labels, cd->len);
cd->labels = outptr;
}
outptr += cd->len;
}
return outptr - start;
}
int translate_dnssearch(Slirp *s, const char **names)
{
size_t blocks, bsrc_start, bsrc_end, bdst_start;
size_t i, num_domains, memreq = 0;
uint8_t *result = NULL, *outptr;
CompactDomain *domains = NULL;
const char **nameptr = names;
while (*nameptr != NULL) {
nameptr++;
}
num_domains = nameptr - names;
if (num_domains == 0) {
return -2;
}
domains = (CompactDomain*)malloc(num_domains * sizeof(*domains));
for (i = 0; i < num_domains; i++) {
size_t nlen = strlen(names[i]);
memreq += nlen + 2; /* 1 zero octet + 1 label length octet */
domains[i].self = domains + i;
domains[i].len = nlen;
domains[i].common_octets = 0;
domains[i].refdom = NULL;
}
/* reserve extra 2 header bytes for each 255 bytes of output */
memreq += ((memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN) * OPT_HEADER_LEN;
result = (uint8_t*)malloc(memreq * sizeof(*result));
outptr = result;
for (i = 0; i < num_domains; i++) {
domains[i].labels = outptr;
domain_mklabels(domains + i, names[i]);
outptr += domains[i].len;
}
if (outptr == result) {
free(domains);
free(result);
return -1;
}
qsort(domains, num_domains, sizeof(*domains), domain_suffix_ord);
domain_fixup_order(domains, num_domains);
for (i = 1; i < num_domains; i++) {
size_t cl = domain_common_label(domains + i - 1, domains + i);
domains[i - 1].common_octets = cl;
}
domain_mkxrefs(domains, domains + num_domains - 1, 0);
memreq = domain_compactify(domains, num_domains);
blocks = (memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN;
bsrc_end = memreq;
bsrc_start = (blocks - 1) * MAX_OPT_LEN;
bdst_start = bsrc_start + blocks * OPT_HEADER_LEN;
memreq += blocks * OPT_HEADER_LEN;
while (blocks--) {
size_t len = bsrc_end - bsrc_start;
memmove(result + bdst_start, result + bsrc_start, len);
result[bdst_start - 2] = RFC3397_OPT_DOMAIN_SEARCH;
result[bdst_start - 1] = len;
bsrc_end = bsrc_start;
bsrc_start -= MAX_OPT_LEN;
bdst_start -= MAX_OPT_LEN + OPT_HEADER_LEN;
}
free(domains);
s->vdnssearch = result;
s->vdnssearch_len = memreq;
return 0;
}
#endif

View File

@ -8,6 +8,8 @@
#include "iodev.h"
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static void
ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
{
@ -240,3 +242,5 @@ void if_start(Slirp *slirp)
slirp->if_start_busy = false;
}
#endif

View File

@ -33,6 +33,8 @@
#include "slirp.h"
#include "ip_icmp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
/* The message sent when emulating PING */
/* Be nice and tell them it's just a pseudo-ping packet */
static const char icmp_ping_msg[] = "This is a pseudo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
@ -448,3 +450,5 @@ void icmp_receive(struct socket *so)
}
icmp_detach(so);
}
#endif

View File

@ -41,6 +41,8 @@
#include "slirp.h"
#include "ip_icmp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp);
static void ip_freef(Slirp *slirp, struct ipq *fp);
static void ip_enq(register struct ipasfrag *p,
@ -210,7 +212,6 @@ void ip_input(struct mbuf *m)
return;
bad:
m_free(m);
return;
}
#define iptofrag(P) ((struct ipasfrag *)(((char*)(P)) - sizeof(struct qlink)))
@ -664,3 +665,5 @@ ip_stripoptions(register struct mbuf *m, struct mbuf *mopt)
ip->ip_hl = sizeof(struct ip) >> 2;
}
#endif

View File

@ -40,6 +40,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
/* Number of packets queued before we start sending
* (to prevent allocing too many mbufs) */
#define IF_THRESH 10
@ -170,3 +172,5 @@ bad:
m_free(m0);
goto done;
}
#endif

View File

@ -12,7 +12,8 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost,
const char *vhostname, const char *tftp_path,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, void *opaque);
struct in_addr vnameserver, const char **vdnssearch,
void *opaque);
void slirp_cleanup(Slirp *slirp);
void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds,

View File

@ -17,6 +17,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define MBUF_THRESH 30
/*
@ -239,3 +241,5 @@ dtom(Slirp *slirp, void *dat)
return (struct mbuf *)0;
}
#endif

View File

@ -7,6 +7,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static void sbappendsb(struct sbuf *sb, struct mbuf *m);
void
@ -184,3 +186,5 @@ sbcopy(struct sbuf *sb, int off, int len, char *to)
memcpy(to+off,sb->sb_data,len);
}
}
#endif

View File

@ -206,7 +206,8 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost,
const char *vhostname, const char *tftp_path,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, void *opaque)
struct in_addr vnameserver, const char **vdnssearch,
void *opaque)
{
Slirp *slirp = (Slirp*)malloc(sizeof(Slirp));
memset(slirp, 0, sizeof(Slirp));
@ -237,6 +238,10 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
slirp->vdhcp_startaddr = vdhcp_start;
slirp->vnameserver_addr = vnameserver;
if (vdnssearch) {
translate_dnssearch(slirp, vdnssearch);
}
slirp->opaque = opaque;
QTAILQ_INSERT_TAIL(&slirp_instances, slirp, entry);
@ -427,6 +432,7 @@ void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds,
slirp->do_slowtimo = true; /* Let socket expire */
}
}
if (so->so_state & SS_ISFCONNECTED) {
FD_SET(so->s, readfds);
UPD_NFDS(so->s);

View File

@ -251,6 +251,8 @@ struct Slirp {
/* bootp/dhcp states */
BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
char *bootp_filename;
size_t vdnssearch_len;
uint8_t *vdnssearch;
/* tcp states */
struct socket tcb;
@ -308,6 +310,9 @@ void if_start(struct ttys *);
#define SO_OPTIONS DO_KEEPALIVE
#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL)
/* dnssearch.c */
int translate_dnssearch(Slirp *s, const char ** names);
/* cksum.c */
int cksum(struct mbuf *m, int len);

View File

@ -41,6 +41,8 @@
#include "slirp.h"
#include "ip_icmp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
#define TCPREXMTTHRESH 3
#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ)
@ -1488,3 +1490,5 @@ tcp_mss(struct tcpcb *tp, u_int offer)
return mss;
}
#endif

View File

@ -40,6 +40,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static const u_char tcp_outflags[TCP_NSTATES] = {
TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK,
@ -491,3 +493,5 @@ tcp_setpersist(struct tcpcb *tp)
if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
tp->t_rxtshift++;
}
#endif

View File

@ -32,6 +32,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer);
/*
@ -290,3 +292,5 @@ tcp_timers(register struct tcpcb *tp, int timer)
return (tp);
}
#endif

View File

@ -24,6 +24,8 @@
#include "slirp.h"
#if BX_NETWORKING && BX_NETMOD_SLIRP_NEW
static inline int tftp_session_in_use(struct tftp_session *spt)
{
return (spt->slirp != NULL);
@ -439,3 +441,5 @@ void tftp_input(struct mbuf *m)
break;
}
}
#endif