diff options
author | Rafael Gieschke <rafael@gieschke.de> | 2021-11-18 22:43:12 +0100 |
---|---|---|
committer | Rafael Gieschke <rafael@gieschke.de> | 2021-11-18 22:44:04 +0100 |
commit | fce12b625370236862574db0574de570de4f6c18 (patch) | |
tree | 7d74e454c8ad610466f5fa961c4906acd343aec3 | |
parent | 67b4b90a55815b8717af71c154fc7d0ad7377c16 (diff) | |
download | slirp-fce12b625370236862574db0574de570de4f6c18.zip slirp-fce12b625370236862574db0574de570de4f6c18.tar.gz slirp-fce12b625370236862574db0574de570de4f6c18.tar.bz2 |
Allow to disable internal DHCP server
Setting `cfg->disable_dhcp` to `true` will disable the internal DHCP server.
Signed-off-by: Rafael Gieschke <rafael@gieschke.de>
-rw-r--r-- | src/bootp.c | 2 | ||||
-rw-r--r-- | src/libslirp.h | 6 | ||||
-rw-r--r-- | src/slirp.c | 6 | ||||
-rw-r--r-- | src/slirp.h | 1 |
4 files changed, 13 insertions, 2 deletions
diff --git a/src/bootp.c b/src/bootp.c index d78d61b..1a3517e 100644 --- a/src/bootp.c +++ b/src/bootp.c @@ -369,7 +369,7 @@ void bootp_input(struct mbuf *m) { struct bootp_t *bp = mtod_check(m, sizeof(struct bootp_t)); - if (bp && bp->bp_op == BOOTP_REQUEST) { + if (!m->slirp->disable_dhcp && bp && bp->bp_op == BOOTP_REQUEST) { bootp_reply(m->slirp, bp, m_end(m)); } } diff --git a/src/libslirp.h b/src/libslirp.h index 8e4ea33..1e75501 100644 --- a/src/libslirp.h +++ b/src/libslirp.h @@ -74,7 +74,7 @@ typedef struct SlirpCb { } SlirpCb; #define SLIRP_CONFIG_VERSION_MIN 1 -#define SLIRP_CONFIG_VERSION_MAX 3 +#define SLIRP_CONFIG_VERSION_MAX 4 typedef struct SlirpConfig { /* Version must be provided */ @@ -120,6 +120,10 @@ typedef struct SlirpConfig { * Fields introduced in SlirpConfig version 3 begin */ bool disable_dns; /* slirp will not redirect/serve any DNS packet */ + /* + * Fields introduced in SlirpConfig version 4 begin + */ + bool disable_dhcp; /* slirp will not reply to any DHCP requests */ } SlirpConfig; /* Create a new instance of a slirp stack */ diff --git a/src/slirp.c b/src/slirp.c index 378a70b..568064f 100644 --- a/src/slirp.c +++ b/src/slirp.c @@ -457,6 +457,12 @@ Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, void *opaque) slirp->disable_dns = false; } + if (cfg->version >= 4) { + slirp->disable_dhcp = cfg->disable_dhcp; + } else { + slirp->disable_dhcp = false; + } + return slirp; } diff --git a/src/slirp.h b/src/slirp.h index 89d79f3..64ab0dd 100644 --- a/src/slirp.h +++ b/src/slirp.h @@ -139,6 +139,7 @@ struct Slirp { struct in6_addr vprefix_addr6; uint8_t vprefix_len; struct in6_addr vhost_addr6; + bool disable_dhcp; /* slirp will not reply to any DHCP requests */ struct in_addr vdhcp_startaddr; struct in_addr vnameserver_addr; struct in6_addr vnameserver_addr6; |