slirp: Add domainname option to slirp's DHCP server
This patch will allow the user to include the domainname option in replies from the built-in DHCP server. Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
parent
c181ddaa17
commit
f18d137542
12
net/slirp.c
12
net/slirp.c
@ -157,7 +157,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
|||||||
const char *bootfile, const char *vdhcp_start,
|
const char *bootfile, const char *vdhcp_start,
|
||||||
const char *vnameserver, const char *vnameserver6,
|
const char *vnameserver, const char *vnameserver6,
|
||||||
const char *smb_export, const char *vsmbserver,
|
const char *smb_export, const char *vsmbserver,
|
||||||
const char **dnssearch, Error **errp)
|
const char **dnssearch, const char *vdomainname,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
/* default settings according to historic slirp */
|
/* default settings according to historic slirp */
|
||||||
struct in_addr net = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
|
struct in_addr net = { .s_addr = htonl(0x0a000200) }; /* 10.0.2.0 */
|
||||||
@ -359,6 +360,11 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
|||||||
ip6_dns.s6_addr[15] |= 3;
|
ip6_dns.s6_addr[15] |= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vdomainname && !*vdomainname) {
|
||||||
|
error_setg(errp, "'domainname' parameter cannot be empty");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nc = qemu_new_net_client(&net_slirp_info, peer, model, name);
|
nc = qemu_new_net_client(&net_slirp_info, peer, model, name);
|
||||||
|
|
||||||
@ -371,7 +377,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
|||||||
s->slirp = slirp_init(restricted, ipv4, net, mask, host,
|
s->slirp = slirp_init(restricted, ipv4, net, mask, host,
|
||||||
ipv6, ip6_prefix, vprefix6_len, ip6_host,
|
ipv6, ip6_prefix, vprefix6_len, ip6_host,
|
||||||
vhostname, tftp_export, bootfile, dhcp,
|
vhostname, tftp_export, bootfile, dhcp,
|
||||||
dns, ip6_dns, dnssearch, s);
|
dns, ip6_dns, dnssearch, vdomainname, s);
|
||||||
QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
|
QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
|
||||||
|
|
||||||
for (config = slirp_configs; config; config = config->next) {
|
for (config = slirp_configs; config; config = config->next) {
|
||||||
@ -958,7 +964,7 @@ int net_init_slirp(const Netdev *netdev, const char *name,
|
|||||||
user->ipv6_host, user->hostname, user->tftp,
|
user->ipv6_host, user->hostname, user->tftp,
|
||||||
user->bootfile, user->dhcpstart,
|
user->bootfile, user->dhcpstart,
|
||||||
user->dns, user->ipv6_dns, user->smb,
|
user->dns, user->ipv6_dns, user->smb,
|
||||||
user->smbserver, dnssearch, errp);
|
user->smbserver, dnssearch, user->domainname, errp);
|
||||||
|
|
||||||
while (slirp_configs) {
|
while (slirp_configs) {
|
||||||
config = slirp_configs;
|
config = slirp_configs;
|
||||||
|
@ -160,6 +160,9 @@
|
|||||||
# @dnssearch: list of DNS suffixes to search, passed as DHCP option
|
# @dnssearch: list of DNS suffixes to search, passed as DHCP option
|
||||||
# to the guest
|
# to the guest
|
||||||
#
|
#
|
||||||
|
# @domainname: guest-visible domain name of the virtual nameserver
|
||||||
|
# (since 2.12)
|
||||||
|
#
|
||||||
# @ipv6-prefix: IPv6 network prefix (default is fec0::) (since
|
# @ipv6-prefix: IPv6 network prefix (default is fec0::) (since
|
||||||
# 2.6). The network prefix is given in the usual
|
# 2.6). The network prefix is given in the usual
|
||||||
# hexadecimal IPv6 address notation.
|
# hexadecimal IPv6 address notation.
|
||||||
@ -197,6 +200,7 @@
|
|||||||
'*dhcpstart': 'str',
|
'*dhcpstart': 'str',
|
||||||
'*dns': 'str',
|
'*dns': 'str',
|
||||||
'*dnssearch': ['String'],
|
'*dnssearch': ['String'],
|
||||||
|
'*domainname': 'str',
|
||||||
'*ipv6-prefix': 'str',
|
'*ipv6-prefix': 'str',
|
||||||
'*ipv6-prefixlen': 'int',
|
'*ipv6-prefixlen': 'int',
|
||||||
'*ipv6-host': 'str',
|
'*ipv6-host': 'str',
|
||||||
|
@ -1906,8 +1906,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
|
|||||||
"-netdev user,id=str[,ipv4[=on|off]][,net=addr[/mask]][,host=addr]\n"
|
"-netdev user,id=str[,ipv4[=on|off]][,net=addr[/mask]][,host=addr]\n"
|
||||||
" [,ipv6[=on|off]][,ipv6-net=addr[/int]][,ipv6-host=addr]\n"
|
" [,ipv6[=on|off]][,ipv6-net=addr[/int]][,ipv6-host=addr]\n"
|
||||||
" [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n"
|
" [,restrict=on|off][,hostname=host][,dhcpstart=addr]\n"
|
||||||
" [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,tftp=dir]\n"
|
" [,dns=addr][,ipv6-dns=addr][,dnssearch=domain][,domainname=domain]\n"
|
||||||
" [,bootfile=f][,hostfwd=rule][,guestfwd=rule]"
|
" [,tftp=dir][,bootfile=f][,hostfwd=rule][,guestfwd=rule]"
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
"[,smb=dir[,smbserver=addr]]\n"
|
"[,smb=dir[,smbserver=addr]]\n"
|
||||||
#endif
|
#endif
|
||||||
@ -2135,6 +2135,9 @@ Example:
|
|||||||
qemu-system-i386 -nic user,dnssearch=mgmt.example.org,dnssearch=example.org
|
qemu-system-i386 -nic user,dnssearch=mgmt.example.org,dnssearch=example.org
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
@item domainname=@var{domain}
|
||||||
|
Specifies the client domain name reported by the built-in DHCP server.
|
||||||
|
|
||||||
@item tftp=@var{dir}
|
@item tftp=@var{dir}
|
||||||
When using the user mode network stack, activate a built-in TFTP
|
When using the user mode network stack, activate a built-in TFTP
|
||||||
server. The files in @var{dir} will be exposed as the root of a TFTP server.
|
server. The files in @var{dir} will be exposed as the root of a TFTP server.
|
||||||
|
@ -298,6 +298,14 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
|
|||||||
q += val;
|
q += val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (slirp->vdomainname) {
|
||||||
|
val = strlen(slirp->vdomainname);
|
||||||
|
*q++ = RFC1533_DOMAINNAME;
|
||||||
|
*q++ = val;
|
||||||
|
memcpy(q, slirp->vdomainname, val);
|
||||||
|
q += val;
|
||||||
|
}
|
||||||
|
|
||||||
if (slirp->vdnssearch) {
|
if (slirp->vdnssearch) {
|
||||||
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
|
size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
|
||||||
val = slirp->vdnssearch_len;
|
val = slirp->vdnssearch_len;
|
||||||
|
@ -16,7 +16,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
|
|||||||
const char *tftp_path, const char *bootfile,
|
const char *tftp_path, const char *bootfile,
|
||||||
struct in_addr vdhcp_start, struct in_addr vnameserver,
|
struct in_addr vdhcp_start, struct in_addr vnameserver,
|
||||||
struct in6_addr vnameserver6, const char **vdnssearch,
|
struct in6_addr vnameserver6, const char **vdnssearch,
|
||||||
void *opaque);
|
const char *vdomainname, void *opaque);
|
||||||
void slirp_cleanup(Slirp *slirp);
|
void slirp_cleanup(Slirp *slirp);
|
||||||
|
|
||||||
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
|
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
|
||||||
|
@ -286,7 +286,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
|
|||||||
const char *tftp_path, const char *bootfile,
|
const char *tftp_path, const char *bootfile,
|
||||||
struct in_addr vdhcp_start, struct in_addr vnameserver,
|
struct in_addr vdhcp_start, struct in_addr vnameserver,
|
||||||
struct in6_addr vnameserver6, const char **vdnssearch,
|
struct in6_addr vnameserver6, const char **vdnssearch,
|
||||||
void *opaque)
|
const char *vdomainname, void *opaque)
|
||||||
{
|
{
|
||||||
Slirp *slirp = g_malloc0(sizeof(Slirp));
|
Slirp *slirp = g_malloc0(sizeof(Slirp));
|
||||||
|
|
||||||
@ -317,6 +317,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
|
|||||||
}
|
}
|
||||||
slirp->tftp_prefix = g_strdup(tftp_path);
|
slirp->tftp_prefix = g_strdup(tftp_path);
|
||||||
slirp->bootp_filename = g_strdup(bootfile);
|
slirp->bootp_filename = g_strdup(bootfile);
|
||||||
|
slirp->vdomainname = g_strdup(vdomainname);
|
||||||
slirp->vdhcp_startaddr = vdhcp_start;
|
slirp->vdhcp_startaddr = vdhcp_start;
|
||||||
slirp->vnameserver_addr = vnameserver;
|
slirp->vnameserver_addr = vnameserver;
|
||||||
slirp->vnameserver_addr6 = vnameserver6;
|
slirp->vnameserver_addr6 = vnameserver6;
|
||||||
@ -349,6 +350,7 @@ void slirp_cleanup(Slirp *slirp)
|
|||||||
g_free(slirp->vdnssearch);
|
g_free(slirp->vdnssearch);
|
||||||
g_free(slirp->tftp_prefix);
|
g_free(slirp->tftp_prefix);
|
||||||
g_free(slirp->bootp_filename);
|
g_free(slirp->bootp_filename);
|
||||||
|
g_free(slirp->vdomainname);
|
||||||
g_free(slirp);
|
g_free(slirp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +193,7 @@ struct Slirp {
|
|||||||
char *bootp_filename;
|
char *bootp_filename;
|
||||||
size_t vdnssearch_len;
|
size_t vdnssearch_len;
|
||||||
uint8_t *vdnssearch;
|
uint8_t *vdnssearch;
|
||||||
|
char *vdomainname;
|
||||||
|
|
||||||
/* tcp states */
|
/* tcp states */
|
||||||
struct socket tcb;
|
struct socket tcb;
|
||||||
|
Loading…
Reference in New Issue
Block a user