Skip to content

Commit

Permalink
Builtin slirp: Removed QTAILQ* stuff and some other cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
vruppert committed Apr 28, 2024
1 parent 2059854 commit 58f4490
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 387 deletions.
4 changes: 2 additions & 2 deletions bochs/iodev/network/eth_slirp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,15 @@ void bx_slirp_pktmover_c::rx_timer(void)
#if BX_HAVE_LIBSLIRP
slirp_pollfds_fill(slirp, &timeout, add_poll_cb, this);
#else
slirp_select_fill(&nfds, &rfds, &wfds, &xfds, &timeout);
slirp_select_fill(slirp, &nfds, &rfds, &wfds, &xfds, &timeout);
#endif
tv.tv_sec = 0;
tv.tv_usec = 0;
ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
#if BX_HAVE_LIBSLIRP
slirp_pollfds_poll(slirp, (ret < 0), get_revents_cb, this);
#else
slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
slirp_select_poll(slirp, &rfds, &wfds, &xfds, (ret < 0));
#endif
}

Expand Down
16 changes: 7 additions & 9 deletions bochs/iodev/network/slirp/dnssearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/

#include "slirp.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#if BX_NETWORKING && BX_NETMOD_SLIRP

Expand All @@ -45,23 +42,24 @@ typedef struct compact_domain {
size_t common_octets;
} CompactDomain;

static size_t
domain_suffix_diffoff(const CompactDomain *a, const CompactDomain *b)
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--;
da--;
db--;
if (*da != *db) {
break;
}
}
return i;
}

static int CDECL domain_suffix_ord(const void *cva, const void *cvb)
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;
Expand Down Expand Up @@ -161,8 +159,8 @@ static void domain_mklabels(Slirp *s, CompactDomain *cd, const char *input)
cd->len = 0;
}

static void
domain_mkxrefs(CompactDomain *doms, CompactDomain *last, size_t depth)
static void domain_mkxrefs(CompactDomain *doms, CompactDomain *last,
size_t depth)
{
CompactDomain *i = doms, *target = doms;

Expand Down
55 changes: 16 additions & 39 deletions bochs/iodev/network/slirp/if.cc
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 1995 Danny Gasparovski.
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/

#define BX_PLUGGABLE

#include "slirp.h"

#if BX_NETWORKING && BX_NETMOD_SLIRP

static void
ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
{
ifm->ifs_next = ifmhead->ifs_next;
ifmhead->ifs_next = ifm;
ifm->ifs_prev = ifmhead;
ifm->ifs_next->ifs_prev = ifm;
ifm->ifs_next = ifmhead->ifs_next;
ifmhead->ifs_next = ifm;
ifm->ifs_prev = ifmhead;
ifm->ifs_next->ifs_prev = ifm;
}

static void
ifs_remque(struct mbuf *ifm)
static void ifs_remque(struct mbuf *ifm)
{
ifm->ifs_prev->ifs_next = ifm->ifs_next;
ifm->ifs_next->ifs_prev = ifm->ifs_prev;
ifm->ifs_prev->ifs_next = ifm->ifs_next;
ifm->ifs_next->ifs_prev = ifm->ifs_prev;
}

void
if_init(Slirp *slirp)
void if_init(Slirp *slirp)
{
slirp->if_fastq.ifq_next = slirp->if_fastq.ifq_prev = &slirp->if_fastq;
slirp->if_batchq.ifq_next = slirp->if_batchq.ifq_prev = &slirp->if_batchq;
Expand All @@ -49,16 +41,15 @@ if_init(Slirp *slirp)
* to the fastq (eg. if the user does an ls -alR in a telnet session,
* it'll temporarily get downgraded to the batchq)
*/
void
if_output(struct socket *so, struct mbuf *ifm)
void if_output(struct socket *so, struct mbuf *ifm)
{
Slirp *slirp = ifm->slirp;
struct mbuf *ifq;
int on_fastq = 1;
Slirp *slirp = ifm->slirp;
struct mbuf *ifq;
int on_fastq = 1;

DEBUG_CALL("if_output");
DEBUG_ARG("so = %lx", (long)so);
DEBUG_ARG("ifm = %lx", (long)ifm);
DEBUG_CALL("if_output");
DEBUG_ARG("so = %lx", (long)so);
DEBUG_ARG("ifm = %lx", (long)ifm);

/*
* First remove the mbuf from m_usedlist,
Expand Down Expand Up @@ -136,26 +127,12 @@ if_output(struct socket *so, struct mbuf *ifm)
}
}

#ifndef FULL_BOLT
/*
* This prevents us from malloc()ing too many mbufs
*/
if_start(ifm->slirp);
#endif
}

/*
* Send a packet
* We choose a packet based on its position in the output queues;
* If there are packets on the fastq, they are sent FIFO, before
* everything else. Otherwise we choose the first packet from the
* batchq and send it. the next packet chosen will be from the session
* after this one, then the session after that one, and so on.. So,
* for example, if there are 3 ftp session's fighting for bandwidth,
* one packet will be sent from the first session, then one packet
* from the second session, then one packet from the third, then back
* to the first, etc. etc.
*/
void if_start(Slirp *slirp)
{
uint64_t now = slirp->cb->clock_get_ns(slirp->opaque);
Expand Down
23 changes: 10 additions & 13 deletions bochs/iodev/network/slirp/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ typedef uint32_t n_long; /* long as received from the net */
*/
#define IPVERSION 4

#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif

/*
* Structure of an internet header, naked of options.
*/
SLIRP_PACKED_BEGIN
struct ip {
#ifndef BX_LITTLE_ENDIAN
uint8_t ip_v:4, /* version */
Expand All @@ -92,7 +89,7 @@ struct ip {
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
} GCC_ATTRIBUTE((packed));
} SLIRP_PACKED_END;

#define IP_MAXPACKET 65535 /* maximum packet size */

Expand Down Expand Up @@ -136,6 +133,7 @@ struct ip {
/*
* Time stamp option structure.
*/
SLIRP_PACKED_BEGIN
struct ip_timestamp {
uint8_t ipt_code; /* IPOPT_TS */
uint8_t ipt_len; /* size of structure (variable) */
Expand All @@ -154,7 +152,7 @@ struct ip_timestamp {
n_long ipt_time;
} ipt_ta[1];
} ipt_timestamp;
} GCC_ATTRIBUTE((packed));
} SLIRP_PACKED_END;

/* flag bits for ipt_flg */
#define IPOPT_TS_TSONLY 0 /* timestamps only */
Expand All @@ -181,14 +179,16 @@ struct ip_timestamp {
#define IP_MSS 576 /* default maximum segment size */

#if SIZEOF_CHAR_P == 4
SLIRP_PACKED_BEGIN
struct mbuf_ptr {
struct mbuf *mptr;
uint32_t dummy;
} GCC_ATTRIBUTE((packed));
} SLIRP_PACKED_END;
#else
SLIRP_PACKED_BEGIN
struct mbuf_ptr {
struct mbuf *mptr;
} GCC_ATTRIBUTE((packed));
} SLIRP_PACKED_END;
#endif
struct qlink {
void *next, *prev;
Expand All @@ -197,14 +197,15 @@ struct qlink {
/*
* Overlay for ip header used by other protocols (tcp, udp).
*/
SLIRP_PACKED_BEGIN
struct ipovly {
struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
uint8_t ih_x1; /* (unused) */
uint8_t ih_pr; /* protocol */
uint16_t ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
} GCC_ATTRIBUTE((packed));
} SLIRP_PACKED_END;

/*
* Ip reassembly queue structure. Each fragment
Expand Down Expand Up @@ -251,8 +252,4 @@ struct ipoption {
int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
} GCC_ATTRIBUTE((packed));

#if defined(_MSC_VER)
#pragma pack(pop)
#endif

#endif
6 changes: 3 additions & 3 deletions bochs/iodev/network/slirp/libslirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
/* Shut down an instance of a slirp stack */
void slirp_cleanup(Slirp *slirp);

void slirp_select_fill(int *pnfds, fd_set *readfds, fd_set *writefds,
void slirp_select_fill(Slirp *slirp, int *pnfds, fd_set *readfds, fd_set *writefds,
fd_set *xfds, uint32_t *timeout);

void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
int select_error);
void slirp_select_poll(Slirp *slirp, fd_set *readfds, fd_set *writefds,
fd_set *xfds, int select_error);

void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);

Expand Down
39 changes: 9 additions & 30 deletions bochs/iodev/network/slirp/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,20 @@
#include <sys/select.h>
#endif

#define TOWRITEMAX 512
#include "libslirp.h"

extern int slirp_socket;
extern int slirp_socket_unit;
extern int slirp_socket_port;
extern uint32_t slirp_socket_addr;
extern char *slirp_socket_passwd;
extern int ctty_closed;

/*
* Get the difference in 2 times from updtim()
* Allow for wraparound times, "just in case"
* x is the greater of the 2 (current time) and y is
* what it's being compared against.
*/
#define TIME_DIFF(x,y) (x)-(y) < 0 ? ~0-(y)+(x) : (x)-(y)

extern char *slirp_tty;
extern char *exec_shell;
extern u_int curtime;
extern fd_set *global_readfds, *global_writefds, *global_xfds;
/* The current guest virtual time */
extern unsigned curtime;
/* Always equal to INADDR_LOOPBACK, in network order */
extern struct in_addr loopback_addr;
/* Always equal to IN_CLASSA_NET, in network order */
extern unsigned long loopback_mask;
extern char *username;
extern char *socket_path;
extern int towrite_max;
extern int ppp_exit;
extern int tcp_keepintvl;

#define PROTO_SLIP 0x1
#ifdef USE_PPP
#define PROTO_PPP 0x2
#endif
extern fd_set *global_readfds, *global_writefds, *global_xfds;

/* Send a packet to the guest */
int if_encap(Slirp *slirp, struct mbuf *ifm);
ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags);
/* Send a frame to the guest. Flags are passed to the send() call */
slirp_ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags);

#endif
Loading

0 comments on commit 58f4490

Please sign in to comment.