Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141997322
D54133.id169269.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D54133.id169269.diff
View Options
diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8
--- a/usr.sbin/bhyve/bhyve.8
+++ b/usr.sbin/bhyve/bhyve.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 26, 2025
+.Dd January 5, 2026
.Dt BHYVE 8
.Os
.Sh NAME
@@ -542,6 +542,8 @@
.Cm slirp
.Op Cm \&,open
.Op Cm \&,hostfwd= Ar proto : Ar hostaddr : Ar hostport - Ar guestaddr : Ar guestport
+.Op Cm \&,mac= Ar xx:xx:xx:xx:xx:xx
+.Op Cm \&,mtu= Ar N
.Xc
.El
.Sm on
diff --git a/usr.sbin/bhyve/net_backend_slirp.c b/usr.sbin/bhyve/net_backend_slirp.c
--- a/usr.sbin/bhyve/net_backend_slirp.c
+++ b/usr.sbin/bhyve/net_backend_slirp.c
@@ -62,15 +62,18 @@
#include "config.h"
#include "debug.h"
#include "mevent.h"
+#include "net_utils.h"
#include "net_backends.h"
#include "net_backends_priv.h"
-#define SLIRP_MTU 2048
+#define DEFAULT_MTU 2048
struct slirp_priv {
int s;
pid_t helper;
struct mevent *mevp;
+ size_t mtu;
+ uint8_t *buf;
};
extern char **environ;
@@ -86,6 +89,8 @@
const char **argv;
char sockname[32];
int error, s[2];
+ const char *mtu_value;
+ size_t mtu;
if (socketpair(PF_LOCAL, SOCK_SEQPACKET | SOCK_NONBLOCK, 0, s) != 0) {
EPRINTLN("socketpair");
@@ -124,6 +129,25 @@
EPRINTLN("nvlist_clone");
goto err;
}
+
+ mtu_value = get_config_value_node(config, "mtu");
+ if (mtu_value != NULL) {
+ if (net_parsemtu(mtu_value, &mtu)) {
+ EPRINTLN("Could not parse MTU");
+ goto err;
+ }
+ } else {
+ mtu = DEFAULT_MTU;
+ }
+ nvlist_add_number(config, "mtui", mtu);
+
+ priv->mtu = mtu;
+ priv->buf = malloc(mtu);
+ if (priv->buf == NULL) {
+ EPRINTLN("Could not allocate buffer");
+ goto err;
+ }
+
nvlist_add_string(config, "vmname", get_config_value("name"));
error = nvlist_send(s[0], config);
nvlist_destroy(config);
@@ -146,6 +170,7 @@
return (0);
err:
+ free(priv->buf);
(void)close(s[0]);
(void)close(s[1]);
return (-1);
@@ -168,6 +193,8 @@
{
struct slirp_priv *priv = NET_BE_PRIV(be);
+ free(priv->buf);
+
if (priv->helper > 0) {
int status;
@@ -184,17 +211,15 @@
slirp_peek_recvlen(struct net_backend *be)
{
struct slirp_priv *priv = NET_BE_PRIV(be);
- uint8_t buf[SLIRP_MTU];
ssize_t n;
/*
* Copying into the buffer is totally unnecessary, but we don't
* implement MSG_TRUNC for SEQPACKET sockets.
*/
- n = recv(priv->s, buf, sizeof(buf), MSG_PEEK | MSG_DONTWAIT);
+ n = recv(priv->s, priv->buf, priv->mtu, MSG_PEEK | MSG_DONTWAIT);
if (n < 0)
return (errno == EWOULDBLOCK ? 0 : -1);
- assert((size_t)n <= SLIRP_MTU);
return (n);
}
@@ -218,7 +243,7 @@
return (0);
return (-1);
}
- assert(n <= SLIRP_MTU);
+ assert((size_t)n <= priv->mtu);
return (n);
}
diff --git a/usr.sbin/bhyve/slirp/slirp-helper.c b/usr.sbin/bhyve/slirp/slirp-helper.c
--- a/usr.sbin/bhyve/slirp/slirp-helper.c
+++ b/usr.sbin/bhyve/slirp/slirp-helper.c
@@ -38,8 +38,6 @@
#include "config.h"
#include "libslirp.h"
-#define SLIRP_MTU 2048
-
struct slirp_priv {
Slirp *slirp; /* libslirp handle */
int sock; /* data and control socket */
@@ -47,6 +45,8 @@
struct pollfd *pollfds;
size_t npollfds;
size_t lastpollfd;
+ size_t mtu;
+ uint8_t *buf;
};
typedef int (*slirp_add_hostxfwd_p_t)(Slirp *,
@@ -104,7 +104,7 @@
priv = param;
- assert(len <= SLIRP_MTU);
+ assert(len <= priv->mtu);
n = send(priv->sock, buf, len, MSG_EOR);
if (n < 0) {
warn("slirp_cb_send_packet: send");
@@ -289,16 +289,14 @@
ssize_t n;
do {
- uint8_t buf[SLIRP_MTU];
-
- n = recv(priv->sock, buf, sizeof(buf),
+ n = recv(priv->sock, priv->buf, priv->mtu,
MSG_DONTWAIT);
if (n < 0) {
if (errno == EWOULDBLOCK)
break;
err(1, "recv");
}
- slirp_input_p(priv->slirp, buf, (int)n);
+ slirp_input_p(priv->slirp, priv->buf, (int)n);
} while (n >= 0);
}
}
@@ -464,6 +462,7 @@
const char *hostfwd, *vmname;
int ch, fd, sd;
bool restricted;
+ size_t mtu;
sd = -1;
while ((ch = getopt(argc, argv, "S:")) != -1) {
@@ -514,6 +513,13 @@
config = nvlist_recv(sd, 0);
if (config == NULL)
err(1, "nvlist_recv");
+
+ mtu = nvlist_get_number(config, "mtui");
+ priv.mtu = mtu;
+ priv.buf = malloc(mtu);
+ if (priv.buf == NULL)
+ err(1, "malloc");
+
vmname = get_config_value_node(config, "vmname");
if (vmname != NULL)
setproctitle("%s", vmname);
@@ -521,7 +527,7 @@
slirpconfig = (SlirpConfig){
.version = 4,
- .if_mtu = SLIRP_MTU,
+ .if_mtu = mtu,
.restricted = restricted,
.in_enabled = true,
.vnetwork.s_addr = htonl(0x0a000200), /* 10.0.2.0/24 */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 4:37 PM (8 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27653276
Default Alt Text
D54133.id169269.diff (4 KB)
Attached To
Mode
D54133: bhyve: support MTU configuration for SLIRP net backend
Attached
Detach File
Event Timeline
Log In to Comment