From nobody Wed May 14 18:17:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1519146631510548.6086585505477; Tue, 20 Feb 2018 09:10:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D77AD5D675; Tue, 20 Feb 2018 17:10:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A85E06049A; Tue, 20 Feb 2018 17:10:29 +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 6AFA7180B61F; Tue, 20 Feb 2018 17:10:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1KH8XlK009699 for ; Tue, 20 Feb 2018 12:08:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 777C9AE7B9; Tue, 20 Feb 2018 17:08:33 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06A8CAE7B6; Tue, 20 Feb 2018 17:08:32 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 20 Feb 2018 17:08:16 +0000 Message-Id: <20180220170822.16462-9-berrange@redhat.com> In-Reply-To: <20180220170822.16462-1-berrange@redhat.com> References: <20180220170822.16462-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/14] nwfilter: handle missing switch enum cases 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 20 Feb 2018 17:10:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Ensure all enum cases are listed in switch statements, or cast away enum type in places where we don't wish to cover all cases. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: John Ferlan --- src/conf/nwfilter_conf.h | 4 ++-- src/nwfilter/nwfilter_ebiptables_driver.c | 17 +++++++++++------ src/nwfilter/nwfilter_learnipaddr.c | 6 +++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index eeec10e67b..f960bf3d56 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -86,7 +86,7 @@ typedef enum { (((data)->flags) & NWFILTER_ENTRY_ITEM_FLAG_IS_NEG) =20 /* datatypes appearing in rule attributes */ -enum attrDatatype { +typedef enum attrDatatype { DATATYPE_UINT16 =3D (1 << 0), DATATYPE_UINT8 =3D (1 << 1), DATATYPE_UINT16_HEX =3D (1 << 2), @@ -106,7 +106,7 @@ enum attrDatatype { DATATYPE_IPSETFLAGS =3D (1 << 16), =20 DATATYPE_LAST =3D (1 << 17), -}; +} virNWFilterAttrDataType; =20 # define NWFILTER_MAC_BGA "01:80:c2:00:00:00" =20 diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index b8682a1130..b19b07c845 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -320,11 +320,16 @@ _printDataType(virNWFilterVarCombIterPtr vars, VIR_FREE(flags); break; =20 - default: + case DATATYPE_STRING: + case DATATYPE_STRINGCOPY: + case DATATYPE_BOOLEAN: virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unhandled datatype %x"), item->datatype); + _("Cannot print data type %x"), item->datatype); + return -1; + case DATATYPE_LAST: + default: + virReportEnumRangeError(virNWFilterAttrDataType, item->datatype); return -1; - break; } =20 return 0; @@ -1183,7 +1188,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw, =20 PRINT_IPT_ROOT_CHAIN(chain, chainPrefix, ifname); =20 - switch (rule->prtclType) { + switch ((int)rule->prtclType) { case VIR_NWFILTER_RULE_PROTOCOL_TCP: case VIR_NWFILTER_RULE_PROTOCOL_TCPoIPV6: fwrule =3D virFirewallAddRule(fw, layer, @@ -1873,7 +1878,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, #define INST_ITEM_MASK(S, I, MASK, C) \ INST_ITEM_2PARMS(S, I, MASK, C, "/") =20 - switch (rule->prtclType) { + switch ((int)rule->prtclType) { case VIR_NWFILTER_RULE_PROTOCOL_MAC: fwrule =3D virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET, "-t", "nat", @@ -2677,7 +2682,7 @@ ebtablesCreateTmpSubChainFW(virFirewallPtr fw, fwrule =3D virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET, "-t", "nat", "-A", rootchain, NULL); =20 - switch (protoidx) { + switch ((int)protoidx) { case L2_PROTO_MAC_IDX: break; case L2_PROTO_STP_IDX: diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 5b95f0e613..9ca0639576 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -430,7 +430,7 @@ learnIPAddressThread(void *arg) } virBufferAddLit(&buf, "src port 67 and dst port 68"); break; - default: + case DETECT_STATIC: if (techdriver->applyBasicRules(req->ifname, &req->macaddr) < 0) { req->status =3D EINVAL; @@ -438,6 +438,10 @@ learnIPAddressThread(void *arg) } virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff= :ff", macaddr); + break; + default: + req->status =3D EINVAL; + goto done; } =20 if (virBufferError(&buf)) { --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list