qapi/net: Wean SLIRP off QAPI type String to improve documentation
String's doc comment is useless. Replace its use in NetdevUserOptions by identical types with hopefully useful documentation. While there, add a non-doc comment explaining why the port forwarding interface is problematic. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20260506105421.2461117-4-armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> [Commit message typo fixed]
Markus Armbruster committed
May 6, 2026 at 12:54 UTC
22ef826531493f2556bbbb188e5bb0f4d095869a
2 files changed
+70
-9
net/slirp.c
+21
-6
@@ -1215,14 +1215,14 @@ void hmp_info_usernet(Monitor *mon, const QDict *qdict)
1215
}
1216
1217
static void
1218
-net_init_slirp_configs(const StringList *fwd, int flags)
1218
+net_init_slirp_configs_host(const NetdevUserHostForwardList *fwd)
1219
{
1220
while (fwd) {
1221
struct slirp_config_str *config;
1222
1223
config = g_malloc0(sizeof(*config));
1224
pstrcpy(config->str, sizeof(config->str), fwd->value->str);
1225
- config->flags = flags;
1225
+ config->flags = SLIRP_CFG_HOSTFWD;
1226
config->next = slirp_configs;
1227
slirp_configs = config;
1228
@@ -1230,9 +1230,24 @@ net_init_slirp_configs(const StringList *fwd, int flags)
1230
}
1231
}
1232
1233
-static const char **slirp_dnssearch(const StringList *dnsname)
1233
+static void
1234
+net_init_slirp_configs_guest(const NetdevUserGuestForwardList *fwd)
1235
+{
1236
+ while (fwd) {
1237
+ struct slirp_config_str *config;
1238
+
1239
+ config = g_malloc0(sizeof(*config));
1240
+ pstrcpy(config->str, sizeof(config->str), fwd->value->str);
1241
+ config->next = slirp_configs;
1242
+ slirp_configs = config;
1243
+
1244
+ fwd = fwd->next;
1245
+ }
1246
+}
1247
+
1248
+static const char **slirp_dnssearch(const NetdevUserDomainSuffixList *dnsname)
1249
{
1235
- const StringList *c = dnsname;
1250
+ const NetdevUserDomainSuffixList *c = dnsname;
1251
size_t i = 0, num_opts = 0;
1252
const char **ret;
1253
@@ -1285,8 +1300,8 @@ int net_init_slirp(const Netdev *netdev, const char *name,
1300
1301
/* all optional fields are initialized to "all bits zero" */
1302
1288
- net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD);
1289
- net_init_slirp_configs(user->guestfwd, 0);
1303
+ net_init_slirp_configs_host(user->hostfwd);
1304
+ net_init_slirp_configs_guest(user->guestfwd);
1305
1306
ret = net_slirp_init(peer, "user", name, user->q_restrict,
1307
ipv4, vnet, user->host,
qapi/net.json
+49
-3
@@ -264,6 +264,52 @@
264
'*param': ['PasstParameter'] },
265
'if': 'CONFIG_PASST' }
266
267
+##
268
+# @NetdevUserDomainSuffix:
269
+#
270
+# @str: DNS domain name suffix for host name lookup, similar to
271
+# resolv.conf(5)
272
+#
273
+# Since: 1.2
274
+##
275
+{ 'struct': 'NetdevUserDomainSuffix',
276
+ 'data': {
277
+ 'str': 'str' } }
278
+
279
+##
280
+# @NetdevUserHostForward:
281
+#
282
+# @str: Host port forwarding rule
283
+#
284
+# TODO: This string gets parsed by slirp_hostfwd(). We fail to
285
+# document syntax and semantics here. We do in qemu-options.hx.
286
+# Parsing structured configuration from strings is a no-no for QMP.
287
+# This should really be a struct. Not sure it's worth the bother
288
+# now.
289
+#
290
+# Since: 1.2
291
+##
292
+{ 'struct': 'NetdevUserHostForward',
293
+ 'data': {
294
+ 'str': 'str' } }
295
+
296
+##
297
+# @NetdevUserGuestForward:
298
+#
299
+# @str: Guest port forwarding rule
300
+#
301
+# TODO: This string gets parsed by slirp_guestfwd(). We fail to
302
+# document syntax and semantics here. We do in qemu-options.hx.
303
+# Parsing structured configuration from strings is a no-no for QMP.
304
+# This should really be a struct. Not sure it's worth the bother
305
+# now.
306
+#
307
+# Since: 1.2
308
+##
309
+{ 'struct': 'NetdevUserGuestForward',
310
+ 'data': {
311
+ 'str': 'str' } }
312
+
313
##
314
# @NetdevUserOptions:
315
#
@@ -340,7 +386,7 @@
386
'*bootfile': 'str',
387
'*dhcpstart': 'str',
388
'*dns': 'str',
343
- '*dnssearch': ['String'],
389
+ '*dnssearch': ['NetdevUserDomainSuffix'],
390
'*domainname': 'str',
391
'*ipv6-prefix': 'str',
392
'*ipv6-prefixlen': 'int',
@@ -348,8 +394,8 @@
394
'*ipv6-dns': 'str',
395
'*smb': 'str',
396
'*smbserver': 'str',
351
- '*hostfwd': ['String'],
352
- '*guestfwd': ['String'],
397
+ '*hostfwd': ['NetdevUserHostForward'],
398
+ '*guestfwd': ['NetdevUserGuestForward'],
399
'*tftp-server-name': 'str' } }
400
401
##