From nobody Sat Nov 23 17:38:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723051180809151.0289403174412; Wed, 7 Aug 2024 10:19:40 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B2DD3D82; Wed, 7 Aug 2024 13:19:39 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 99CEB12B7; Wed, 7 Aug 2024 13:16:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7C909C2F; Wed, 7 Aug 2024 13:16:09 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B7217C92 for ; Wed, 7 Aug 2024 13:16:08 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-iuB4Q-XdMo2A0nAGJVVl6w-1; Wed, 07 Aug 2024 13:16:07 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DA361955F4B for ; Wed, 7 Aug 2024 17:16:06 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.32.31]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E609519560A3 for ; Wed, 7 Aug 2024 17:16:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723050968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O53itCshRN1BZjRSK9zK0goqi6F/lNI0Ct/2ajpU/P0=; b=OJPReaKYdh2PF8kxWaUubZhX4G8i08eZqCTZZ9BCr4wYVCyJv/YlUMduuGn6Xd6sZI1PZw kAY3K/P2xgBak6tqXy8HDrSdVVjRBLNs4VUO7QR5g8ZgcKaCYEzdnIgmz25Be5jeLjUWhB T49a0x1fI85taLYrvkPhV0FT0T41cuo= X-MC-Unique: iuB4Q-XdMo2A0nAGJVVl6w-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH 2/7] network: add configurable network autoaddr items to driver config Date: Wed, 7 Aug 2024 13:15:58 -0400 Message-ID: <20240807171603.218784-3-laine@redhat.com> In-Reply-To: <20240807171603.218784-1-laine@redhat.com> References: <20240807171603.218784-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 42EVR5F4AGQBYIH3KUWWRSIZ7ZLG6LE7 X-Message-ID-Hash: 42EVR5F4AGQBYIH3KUWWRSIZ7ZLG6LE7 X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723051181197116600 Content-Type: text/plain; charset="utf-8"; x-default="true" These options are added to network.conf and virNetworkDriverConfig object: autoaddr_start - start of the range of subnets to search (def: "192.168.122= .0") autoaddr_end - end of the range of subnets (def: "192.168.255.0") autoaddr_prefix - prefix of these subnets (def: 24) They will be used by the network driver when looking for unused subnets to assign to networks that have "autoaddr=3D'yes'" in one of their elements. Signed-off-by: Laine Stump --- meson.build | 14 +++++- meson_options.txt | 4 ++ src/network/bridge_driver_conf.c | 61 ++++++++++++++++++++++++ src/network/bridge_driver_conf.h | 4 ++ src/network/libvirtd_network.aug | 8 +++- src/network/meson.build | 6 +++ src/network/network.conf.in | 11 +++++ src/network/test_libvirtd_network.aug.in | 3 ++ 8 files changed, 109 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 06d88ad1f3..71da7db741 100644 --- a/meson.build +++ b/meson.build @@ -1646,6 +1646,15 @@ endif if not get_option('driver_network').disabled() and conf.has('WITH_LIBVIRTD= ') conf.set('WITH_NETWORK', 1) =20 + autoaddr_start =3D get_option('autoaddr_start') + conf.set_quoted('AUTOADDR_START', autoaddr_start) + + autoaddr_end =3D get_option('autoaddr_end') + conf.set_quoted('AUTOADDR_END', autoaddr_end) + + autoaddr_prefix =3D get_option('autoaddr_prefix') + conf.set('AUTOADDR_PREFIX', autoaddr_prefix) + firewall_backend_priority =3D get_option('firewall_backend_priority') if firewall_backend_priority.length() =3D=3D 0 if host_machine.system() =3D=3D 'linux' @@ -2406,7 +2415,10 @@ misc_summary =3D { } if conf.has('WITH_NETWORK') misc_summary +=3D { - 'firewall backends': firewall_backend_priority, + 'autoaddr_start': autoaddr_start, + 'autoaddr_end': autoaddr_end, + 'autoaddr_prefix': autoaddr_prefix, + 'firewall backends': firewall_backend_priority, } endif summary(misc_summary, section: 'Miscellaneous', bool_yn: true, list_sep: '= ') diff --git a/meson_options.txt b/meson_options.txt index 2d440c63d8..7a1a86211e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -118,6 +118,10 @@ option('firewalld', type: 'feature', value: 'auto', de= scription: 'firewalld supp # dep:firewalld option('firewalld_zone', type: 'feature', value: 'auto', description: 'whe= ther to install firewalld libvirt zone') option('firewall_backend_priority', type: 'array', choices: ['nftables', '= iptables'], value: [], description: 'order in which to try firewall backend= s') +option('autoaddr_start', type: 'string', value: '192.168.122.0', descripti= on: 'Start of range of IPv4 subnets to choose an unused subnet from') +option('autoaddr_end', type: 'string', value: '192.168.255.0', description= : 'End of range of IPv4 subnets to choose an unused subnet from') +option('autoaddr_prefix', type: 'integer', value: 24, description: 'prefix= of IPv4 subnets to choose an unused subnet from') + option('host_validate', type: 'feature', value: 'auto', description: 'buil= d virt-host-validate') option('init_script', type: 'combo', choices: ['systemd', 'openrc', 'check= ', 'none'], value: 'check', description: 'Style of init script to install') option('loader_nvram', type: 'string', value: '', description: 'Pass list = of pairs of : paths. Both pairs and list items are separated= by a colon.') diff --git a/src/network/bridge_driver_conf.c b/src/network/bridge_driver_c= onf.c index 9da5e790b7..cb2915550f 100644 --- a/src/network/bridge_driver_conf.c +++ b/src/network/bridge_driver_conf.c @@ -65,6 +65,13 @@ virNetworkLoadDriverConfig(virNetworkDriverConfig *cfg G= _GNUC_UNUSED, const char *filename) { g_autoptr(virConf) conf =3D NULL; + + const char *autoaddrStart =3D "192.168.122.0"; + const char *autoaddrEnd =3D "192.168.255.0"; + unsigned int autoaddrPrefix =3D 24; + g_autofree char *autoaddrStartFromConf =3D NULL; + g_autofree char *autoaddrEndFromConf =3D NULL; + g_autofree char *fwBackendStr =3D NULL; bool fwBackendSelected =3D false; size_t i; @@ -88,6 +95,36 @@ virNetworkLoadDriverConfig(virNetworkDriverConfig *cfg G= _GNUC_UNUSED, =20 /* use virConfGetValue*(conf, ...) functions to read any settings = into cfg */ =20 + if (virConfGetValueString(conf, "autoaddr_start", &autoaddrStartFr= omConf) < 0) + return -1; + if (autoaddrStartFromConf) { + VIR_DEBUG("autoaddr_start setting requested from config file %= s: '%s'", + filename, autoaddrStartFromConf); + autoaddrStart =3D autoaddrStartFromConf; + } + + if (virConfGetValueString(conf, "autoaddr_end", &autoaddrEndFromCo= nf) < 0) + return -1; + if (autoaddrEndFromConf) { + VIR_DEBUG("autoaddr_end setting requested from config file %s:= '%s'", + filename, autoaddrEndFromConf); + autoaddrEnd =3D autoaddrEndFromConf; + } + + switch (virConfGetValueUInt(conf, "autoaddr_prefix", &autoaddrPref= ix)) { + case 1: + VIR_DEBUG("autoaddr_prefix setting requested from config file = %s: '%u'", + filename, autoaddrPrefix); + break; + + case 0: + break; + + case -1: + default: + return -1; + } + if (virConfGetValueString(conf, "firewall_backend", &fwBackendStr)= < 0) return -1; =20 @@ -106,6 +143,30 @@ virNetworkLoadDriverConfig(virNetworkDriverConfig *cfg= G_GNUC_UNUSED, } } =20 + if (virSocketAddrParse(&cfg->autoaddrStart, autoaddrStart, AF_INET) < = 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid autoaddr_start '%1$s' in network driver = config file %2$s, must be numeric IPv4 network address"), + autoaddrStart, filename); + return -1; + } + + if (virSocketAddrParse(&cfg->autoaddrEnd, autoaddrEnd, AF_INET) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid autoaddr_end '%1$s' in network driver co= nfig file %2$s, must be numeric IPv4 network address"), + autoaddrStart, filename); + return -1; + } + + if ((cfg->autoaddrPrefix =3D autoaddrPrefix) > 32) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid IPv4 prefix '%1$u' in network driver con= fig file %2$s"), + autoaddrPrefix, filename); + return -1; + } + + VIR_INFO("autoaddr_start=3D'%s' autoaddr_end=3D'%s' autoaddr_prefix=3D= '%u'", + autoaddrStart, autoaddrEnd, autoaddrPrefix); + for (i =3D 0; i < nFwBackends && !fwBackendSelected; i++) { =20 switch ((virFirewallBackend)fwBackends[i]) { diff --git a/src/network/bridge_driver_conf.h b/src/network/bridge_driver_c= onf.h index 8f221f391e..7ebf77037d 100644 --- a/src/network/bridge_driver_conf.h +++ b/src/network/bridge_driver_conf.h @@ -39,6 +39,10 @@ struct _virNetworkDriverConfig { char *pidDir; char *dnsmasqStateDir; =20 + virSocketAddr autoaddrStart; + virSocketAddr autoaddrEnd; + unsigned int autoaddrPrefix; + virFirewallBackend firewallBackend; }; =20 diff --git a/src/network/libvirtd_network.aug b/src/network/libvirtd_networ= k.aug index 5d6d72dd92..5212505e1f 100644 --- a/src/network/libvirtd_network.aug +++ b/src/network/libvirtd_network.aug @@ -22,10 +22,16 @@ module Libvirtd_network =3D let int_entry (kw:string) =3D [ key kw . value_sep . int_val ] let str_array_entry (kw:string) =3D [ key kw . value_sep . str_array_va= l ] =20 + let autoaddr_entry =3D str_entry "autoaddr_start" + | str_entry "autoaddr_end" + | int_entry "autoaddr_prefix" + let firewall_backend_entry =3D str_entry "firewall_backend" =20 (* Each entry in the config is one of the following *) - let entry =3D firewall_backend_entry + let entry =3D autoaddr_entry + | firewall_backend_entry + let comment =3D [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \= t\n][^\n]*)?/ . del /\n/ "\n" ] let empty =3D [ label "#empty" . eol ] =20 diff --git a/src/network/meson.build b/src/network/meson.build index 07cd5cda55..8faff6eb1c 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -51,6 +51,9 @@ if conf.has('WITH_NETWORK') } =20 network_options_conf =3D configuration_data({ + 'AUTOADDR_START': autoaddr_start, + 'AUTOADDR_END': autoaddr_end, + 'AUTOADDR_PREFIX': autoaddr_prefix, 'FIREWALL_BACKEND_PRIORITY': ', '.join(firewall_backend_priority), 'FIREWALL_BACKEND': firewall_backend_priority[0], }) @@ -62,6 +65,9 @@ if conf.has('WITH_NETWORK') ) =20 network_options_hack_conf =3D configuration_data({ + 'AUTOADDR_START': autoaddr_start, + 'AUTOADDR_END': autoaddr_end, + 'AUTOADDR_PREFIX': autoaddr_prefix, 'FIREWALL_BACKEND_PRIORITY': ', '.join(firewall_backend_priority), 'FIREWALL_BACKEND': firewall_backend_priority[0], # This hack is necessary because the output file is going to be diff --git a/src/network/network.conf.in b/src/network/network.conf.in index 5ed64a04a5..83a27df04c 100644 --- a/src/network/network.conf.in +++ b/src/network/network.conf.in @@ -27,3 +27,14 @@ # reloaded using the new backend.) # #firewall_backend =3D "@FIREWALL_BACKEND@" +# +# autoaddr_start +# autoaddr_end +# autoaddr_prefix +# +# These three setting specify the range of subnets that should be used +# for networks that have "autoaddr=3D'yes'" +# +#autoaddr_start =3D "@AUTOADDR_START@" +#autoaddr_end =3D "@AUTOADDR_END@" +#autoaddr_prefix =3D @AUTOADDR_PREFIX@ diff --git a/src/network/test_libvirtd_network.aug.in b/src/network/test_li= bvirtd_network.aug.in index 9e29a9192f..6edcbaed62 100644 --- a/src/network/test_libvirtd_network.aug.in +++ b/src/network/test_libvirtd_network.aug.in @@ -3,3 +3,6 @@ module Test_libvirtd_network =3D =20 test Libvirtd_network.lns get conf =3D { "firewall_backend" =3D "@FIREWALL_BACKEND@" } +{ "autoaddr_start" =3D "@AUTOADDR_START@" } +{ "autoaddr_end" =3D "@AUTOADDR_END@" } +{ "autoaddr_prefix" =3D "@AUTOADDR_PREFIX@" } --=20 2.45.2