From nobody Sun May 5 06:34:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594848499; cv=none; d=zohomail.com; s=zohoarc; b=d/5XKOWkc9DWumjgoEJyck47JT/dSlnaN6njvLGLG1uEBDblHm34w2VxZQ+Kf1gKh4LDwXG6JZtt+GGZyZ59nqlghHatuUSdJrzHHBq2onWIVqxzSwf6QNtIIZuL5XEBVAf81CwG8nNCkFej3bmrJAo2uBATsUuQa0LJHA8OAQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594848499; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=x6HmpUeRElxyskyHzoeE1n/Kl+bVeSNkk6oKLEHng8M=; b=Lem5n60nueVHTaWRyuarBh7BAinSNA7TIY34Z0nmgIkHHuSiVjyLvmxWAsoVp+/RTvXNM3l6Ns9J/QXgw3txQQB4UIKXjRGIK8es+5cs57urRXgkvRPCWjR5vVadM9mmn+crY/R6gEMv/70F0Evmh7tUD+xV46+abYKTMYDZjZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 159484849952157.88907031213978; Wed, 15 Jul 2020 14:28:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-RiDe2EqUMh6W7tLDBrWu-g-1; Wed, 15 Jul 2020 17:28:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90DEF10A1; Wed, 15 Jul 2020 21:28:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1A2C79D0E; Wed, 15 Jul 2020 21:28:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E934196221; Wed, 15 Jul 2020 21:27:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06FLRvh6028202 for ; Wed, 15 Jul 2020 17:27:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27B4779D13; Wed, 15 Jul 2020 21:27:57 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65CB479D0E for ; Wed, 15 Jul 2020 21:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594848498; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=x6HmpUeRElxyskyHzoeE1n/Kl+bVeSNkk6oKLEHng8M=; b=WSv5RJWr1W5auLazulF2H4hrkUHlpwkDKufNWIfFDYbiisdoOr193SiD+tjA1FJ3dn0wnS u6UxrzA6aYPkENH2Mn76x4c0KMmNnfJX3K4Ajlcoc405BI4E4xmnC4Mr4twsvqF5xYC9eo /nqZd7kr2Eh/jAn7Rs4K7AVwi7PLkdI= X-MC-Unique: RiDe2EqUMh6W7tLDBrWu-g-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH] network: split out networkSetIPv6Sysctl Date: Wed, 15 Jul 2020 23:27:49 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Refactor networkSetIPv6Sysctls to remove repetition and reuse of the 'field' variable. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Andrea Bolognani --- src/network/bridge_driver.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 713763130b..d817b5cbd6 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2249,37 +2249,51 @@ networkEnableIPForwarding(bool enableIPv4, } =20 =20 +static int +networkSetIPv6Sysctl(const char *bridge, + const char *sysctl_field, + const char *sysctl_setting, + bool ignoreMissing) +{ + g_autofree char *field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf= /%s/%s", + bridge, sysctl_field); + + if (ignoreMissing && access(field, W_OK) < 0 && errno =3D=3D ENOENT) + return -2; + + if (virFileWriteStr(field, sysctl_setting, 0) < 0) { + virReportSystemError(errno, + _("cannot write to '%s' on bridge '%s'"), + field, bridge); + return -1; + } + + return 0; +} + + static int networkSetIPv6Sysctls(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - char *field =3D NULL; - int ret =3D -1; bool enableIPv6 =3D !!virNetworkDefGetIPByIndex(def, AF_INET6, 0); + int rc; =20 /* set disable_ipv6 if there are no ipv6 addresses defined for the * network. But also unset it if there *are* ipv6 addresses, as we * can't be sure of its default value. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/disable_ipv6", - def->bridge); - - if (access(field, W_OK) < 0 && errno =3D=3D ENOENT) { + rc =3D networkSetIPv6Sysctl(def->bridge, "disable_ipv6", + enableIPv6 ? "0" : "1", true); + if (rc =3D=3D -2) { if (!enableIPv6) VIR_DEBUG("ipv6 appears to already be disabled on %s", def->bridge); - ret =3D 0; - goto cleanup; + return 0; + } else if (rc < 0) { + return -1; } =20 - if (virFileWriteStr(field, enableIPv6 ? "0" : "1", 0) < 0) { - virReportSystemError(errno, - _("cannot write to %s to enable/disable IPv6 " - "on bridge %s"), field, def->bridge); - goto cleanup; - } - VIR_FREE(field); - /* The rest of the ipv6 sysctl tunables should always be set the * same, whether or not we're using ipv6 on this bridge. */ @@ -2287,31 +2301,16 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) /* Prevent guests from hijacking the host network by sending out * their own router advertisements. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra", - def->bridge); - - if (virFileWriteStr(field, "0", 0) < 0) { - virReportSystemError(errno, - _("cannot disable %s"), field); - goto cleanup; - } - VIR_FREE(field); + if (networkSetIPv6Sysctl(def->bridge, "accept_ra", "0", false) < 0) + return -1; =20 /* All interfaces used as a gateway (which is what this is, by * definition), must always have autoconf=3D0. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", de= f->bridge); + if (networkSetIPv6Sysctl(def->bridge, "autoconf", "0", false) < 0) + return -1; =20 - if (virFileWriteStr(field, "0", 0) < 0) { - virReportSystemError(errno, - _("cannot disable %s"), field); - goto cleanup; - } - - ret =3D 0; - cleanup: - VIR_FREE(field); - return ret; + return 0; } =20 =20 --=20 2.25.4