mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
nwfilter: fix IP address learning
In a previous commit:
commit d4bf8f4150
Author: Daniel P. Berrangé <berrange@redhat.com>
Date: Wed Feb 14 09:43:59 2018 +0000
nwfilter: handle missing switch enum cases
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.
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
we changed a switch in the nwfilter learning thread so that it had
explict cases for all enum entries. Unfortunately the parameters in the
method had been declared with incorrect type. The "howDetect" parameter
does *not* accept "enum howDetect" values, rather it accepts a bitmask
of "enum howDetect" values, so it should have been an "int" type.
The caller always passes DETECT_STATIC|DETECT_DHCP, so essentially the
IP addressing learning was completely broken by the above change, as it
never matched any switch case, hitting the default leading to EINVAL.
Stop using a typedef for the parameter name this this is a bitmask,
not a plain enum value. Also stop using switch() since that's misleading
with bitmasks too.
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
331fcaced2
commit
1e49132dde
@ -144,7 +144,7 @@ struct _virNWFilterIPAddrLearnReq {
|
|||||||
char *filtername;
|
char *filtername;
|
||||||
virHashTablePtr filterparams;
|
virHashTablePtr filterparams;
|
||||||
virNWFilterDriverStatePtr driver;
|
virNWFilterDriverStatePtr driver;
|
||||||
enum howDetect howDetect;
|
int howDetect; /* bitmask of enum howDetect */
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
volatile bool terminate;
|
volatile bool terminate;
|
||||||
@ -437,28 +437,24 @@ learnIPAddressThread(void *arg)
|
|||||||
|
|
||||||
virMacAddrFormat(&req->macaddr, macaddr);
|
virMacAddrFormat(&req->macaddr, macaddr);
|
||||||
|
|
||||||
switch (req->howDetect) {
|
if (req->howDetect == DETECT_DHCP) {
|
||||||
case DETECT_DHCP:
|
|
||||||
if (techdriver->applyDHCPOnlyRules(req->ifname,
|
if (techdriver->applyDHCPOnlyRules(req->ifname,
|
||||||
&req->macaddr,
|
&req->macaddr,
|
||||||
NULL, false) < 0) {
|
NULL, false) < 0) {
|
||||||
|
VIR_DEBUG("Unable to apply DHCP only rules");
|
||||||
req->status = EINVAL;
|
req->status = EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
virBufferAddLit(&buf, "src port 67 and dst port 68");
|
virBufferAddLit(&buf, "src port 67 and dst port 68");
|
||||||
break;
|
} else {
|
||||||
case DETECT_STATIC:
|
|
||||||
if (techdriver->applyBasicRules(req->ifname,
|
if (techdriver->applyBasicRules(req->ifname,
|
||||||
&req->macaddr) < 0) {
|
&req->macaddr) < 0) {
|
||||||
|
VIR_DEBUG("Unable to apply basic rules");
|
||||||
req->status = EINVAL;
|
req->status = EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff:ff",
|
virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff:ff",
|
||||||
macaddr);
|
macaddr);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
req->status = EINVAL;
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
@ -693,7 +689,7 @@ learnIPAddressThread(void *arg)
|
|||||||
* once its IP address has been detected
|
* once its IP address has been detected
|
||||||
* @driver : the network filter driver
|
* @driver : the network filter driver
|
||||||
* @howDetect : the method on how the thread is supposed to detect the
|
* @howDetect : the method on how the thread is supposed to detect the
|
||||||
* IP address; must choose any of the available flags
|
* IP address; bitmask of "enum howDetect" flags.
|
||||||
*
|
*
|
||||||
* Instruct to learn the IP address being used on a given interface (ifname).
|
* Instruct to learn the IP address being used on a given interface (ifname).
|
||||||
* Unless there already is a thread attempting to learn the IP address
|
* Unless there already is a thread attempting to learn the IP address
|
||||||
@ -711,7 +707,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
|
|||||||
const char *filtername,
|
const char *filtername,
|
||||||
virHashTablePtr filterparams,
|
virHashTablePtr filterparams,
|
||||||
virNWFilterDriverStatePtr driver,
|
virNWFilterDriverStatePtr driver,
|
||||||
enum howDetect howDetect)
|
int howDetect)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
virThread thread;
|
virThread thread;
|
||||||
|
@ -43,7 +43,7 @@ int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
|
|||||||
const char *filtername,
|
const char *filtername,
|
||||||
virHashTablePtr filterparams,
|
virHashTablePtr filterparams,
|
||||||
virNWFilterDriverStatePtr driver,
|
virNWFilterDriverStatePtr driver,
|
||||||
enum howDetect howDetect);
|
int howDetect);
|
||||||
|
|
||||||
bool virNWFilterHasLearnReq(int ifindex);
|
bool virNWFilterHasLearnReq(int ifindex);
|
||||||
int virNWFilterTerminateLearnReq(const char *ifname);
|
int virNWFilterTerminateLearnReq(const char *ifname);
|
||||||
|
Loading…
Reference in New Issue
Block a user