Re: [libvirt] [PATCH v2 08/42] nwfilter: handle missing switch enum cases

2018-02-19 Thread John Ferlan


On 02/15/2018 11:43 AM, Daniel P. Berrangé wrote:
> 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é 
> ---
>  src/nwfilter/nwfilter_ebiptables_driver.c | 16 +++-
>  src/nwfilter/nwfilter_learnipaddr.c   |  6 +-
>  2 files changed, 16 insertions(+), 6 deletions(-)
> 

[...]

> diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
> b/src/nwfilter/nwfilter_learnipaddr.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(, "src port 67 and dst port 68");
>  break;
> -default:
> +case DETECT_STATIC:
>  if (techdriver->applyBasicRules(req->ifname,
>  >macaddr) < 0) {
>  req->status = EINVAL;
> @@ -438,6 +438,10 @@ learnIPAddressThread(void *arg)
>  }
>  virBufferAsprintf(, "ether host %s or ether dst 
> ff:ff:ff:ff:ff:ff",
>macaddr);
> +break;
> +default:
> +req->status = EINVAL;
> +goto done;

Could add a VIR_DEBUG() in this just to "track" the reason it was EINVAL
since there's so many ways it could be EINVAL, not that important...

>  }
>  
>  if (virBufferError()) {
> 

Reviewed-by: John Ferlan 

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 08/42] nwfilter: handle missing switch enum cases

2018-02-15 Thread Daniel P . Berrangé
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é 
---
 src/nwfilter/nwfilter_ebiptables_driver.c | 16 +++-
 src/nwfilter/nwfilter_learnipaddr.c   |  6 +-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
b/src/nwfilter/nwfilter_ebiptables_driver.c
index b8682a1130..c624337f4d 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -320,11 +320,17 @@ _printDataType(virNWFilterVarCombIterPtr vars,
 VIR_FREE(flags);
 break;
 
+case DATATYPE_STRING:
+case DATATYPE_STRINGCOPY:
+case DATATYPE_BOOLEAN:
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Cannot print data type %x"), item->datatype);
+return -1;
+case DATATYPE_LAST:
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Unhandled datatype %x"), item->datatype);
+   _("Unexpected datatype %x"), item->datatype);
 return -1;
-break;
 }
 
 return 0;
@@ -1183,7 +1189,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
 
 PRINT_IPT_ROOT_CHAIN(chain, chainPrefix, ifname);
 
-switch (rule->prtclType) {
+switch ((int)rule->prtclType) {
 case VIR_NWFILTER_RULE_PROTOCOL_TCP:
 case VIR_NWFILTER_RULE_PROTOCOL_TCPoIPV6:
 fwrule = virFirewallAddRule(fw, layer,
@@ -1873,7 +1879,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 #define INST_ITEM_MASK(S, I, MASK, C) \
 INST_ITEM_2PARMS(S, I, MASK, C, "/")
 
-switch (rule->prtclType) {
+switch ((int)rule->prtclType) {
 case VIR_NWFILTER_RULE_PROTOCOL_MAC:
 fwrule = virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET,
 "-t", "nat",
@@ -2677,7 +2683,7 @@ ebtablesCreateTmpSubChainFW(virFirewallPtr fw,
 fwrule = virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET,
 "-t", "nat", "-A", rootchain, NULL);
 
-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_learnipaddr.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(, "src port 67 and dst port 68");
 break;
-default:
+case DETECT_STATIC:
 if (techdriver->applyBasicRules(req->ifname,
 >macaddr) < 0) {
 req->status = EINVAL;
@@ -438,6 +438,10 @@ learnIPAddressThread(void *arg)
 }
 virBufferAsprintf(, "ether host %s or ether dst ff:ff:ff:ff:ff:ff",
   macaddr);
+break;
+default:
+req->status = EINVAL;
+goto done;
 }
 
 if (virBufferError()) {
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list