#include <pwd.h>
#include <sys/wait.h>
#endif
-#include "net.h"
-#include "net/hub.h"
-#include "monitor.h"
-#include "qemu_socket.h"
+#include "net/net.h"
+#include "clients.h"
+#include "hub.h"
+#include "monitor/monitor.h"
+#include "qemu/sockets.h"
#include "slirp/libslirp.h"
+#include "sysemu/char.h"
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
{
static inline void slirp_smb_cleanup(SlirpState *s) { }
#endif
-int slirp_can_output(void *opaque)
-{
- SlirpState *s = opaque;
-
- return qemu_can_send_packet(&s->nc);
-}
-
void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
{
SlirpState *s = opaque;
const char *vhostname, const char *tftp_export,
const char *bootfile, const char *vdhcp_start,
const char *vnameserver, const char *smb_export,
- const char *vsmbserver)
+ const char *vsmbserver, const char **dnssearch)
{
/* default settings according to historic slirp */
struct in_addr net = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
s = DO_UPCAST(SlirpState, nc, nc);
s->slirp = slirp_init(restricted, net, mask, host, vhostname,
- tftp_export, bootfile, dhcp, dns, s);
+ tftp_export, bootfile, dhcp, dns, dnssearch, s);
QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
for (config = slirp_configs; config; config = config->next) {
return 0;
error:
- qemu_del_vlan_client(nc);
+ qemu_del_net_client(nc);
return -1;
}
fwd->port = port;
fwd->slirp = s->slirp;
+ qemu_chr_fe_claim_no_fail(fwd->hd);
qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
NULL, fwd);
}
return -1;
}
-void do_info_usernet(Monitor *mon)
+void do_info_usernet(Monitor *mon, const QDict *qdict)
{
SlirpState *s;
}
}
+static const char **slirp_dnssearch(const StringList *dnsname)
+{
+ const StringList *c = dnsname;
+ size_t i = 0, num_opts = 0;
+ const char **ret;
+
+ while (c) {
+ num_opts++;
+ c = c->next;
+ }
+
+ if (num_opts == 0) {
+ return NULL;
+ }
+
+ ret = g_malloc((num_opts + 1) * sizeof(*ret));
+ c = dnsname;
+ while (c) {
+ ret[i++] = c->value->str;
+ c = c->next;
+ }
+ ret[i] = NULL;
+ return ret;
+}
+
int net_init_slirp(const NetClientOptions *opts, const char *name,
NetClientState *peer)
{
char *vnet;
int ret;
const NetdevUserOptions *user;
+ const char **dnssearch;
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_USER);
user = opts->user;
user->has_ip ? g_strdup_printf("%s/24", user->ip) :
NULL;
+ dnssearch = slirp_dnssearch(user->dnssearch);
+
/* all optional fields are initialized to "all bits zero" */
net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD);
net_init_slirp_configs(user->guestfwd, 0);
- ret = net_slirp_init(peer, "user", name, user->restrict, vnet, user->host,
- user->hostname, user->tftp, user->bootfile,
- user->dhcpstart, user->dns, user->smb,
- user->smbserver);
+ ret = net_slirp_init(peer, "user", name, user->q_restrict, vnet,
+ user->host, user->hostname, user->tftp,
+ user->bootfile, user->dhcpstart, user->dns, user->smb,
+ user->smbserver, dnssearch);
while (slirp_configs) {
config = slirp_configs;
}
g_free(vnet);
+ g_free(dnssearch);
return ret;
}