-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add conserve mode for VPC offerings #12487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ca62353
5ade2b3
3fd969b
9e3eeb7
45eba18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ | |
| import javax.inject.Inject; | ||
| import javax.naming.ConfigurationException; | ||
|
|
||
| import com.cloud.network.vpc.VpcOfferingVO; | ||
| import com.cloud.network.vpc.dao.VpcOfferingDao; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
|
|
@@ -159,6 +161,8 @@ public class FirewallManagerImpl extends ManagerBase implements FirewallService, | |
| IpAddressManager _ipAddrMgr; | ||
| @Inject | ||
| RoutedIpv4Manager routedIpv4Manager; | ||
| @Inject | ||
| VpcOfferingDao vpcOfferingDao; | ||
|
|
||
| private boolean _elbEnabled = false; | ||
| static Boolean rulesContinueOnErrFlag = true; | ||
|
|
@@ -395,6 +399,17 @@ public void detectRulesConflict(FirewallRule newRule) throws NetworkRuleConflict | |
| assert (rules.size() >= 1); | ||
| } | ||
|
|
||
| NetworkVO newRuleNetwork = _networkDao.findById(newRule.getNetworkId()); | ||
| if (newRuleNetwork == null) { | ||
| throw new InvalidParameterValueException("Unable to create firewall rule as cannot find network by id=" + newRule.getNetworkId()); | ||
| } | ||
| boolean isNewRuleOnVpcNetwork = newRuleNetwork.getVpcId() != null; | ||
| boolean isVpcConserveModeEnabled = false; | ||
| if (isNewRuleOnVpcNetwork) { | ||
| VpcOfferingVO vpcOffering = vpcOfferingDao.findById(newRuleNetwork.getVpcId()); | ||
| isVpcConserveModeEnabled = vpcOffering != null && vpcOffering.isConserveMode(); | ||
| } | ||
|
Comment on lines
+402
to
+411
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new method(s)? |
||
|
|
||
| for (FirewallRuleVO rule : rules) { | ||
| if (rule.getId() == newRule.getId()) { | ||
| continue; // Skips my own rule. | ||
|
|
@@ -443,8 +458,14 @@ public void detectRulesConflict(FirewallRule newRule) throws NetworkRuleConflict | |
| } | ||
|
|
||
| // Checking if the rule applied is to the same network that is passed in the rule. | ||
| if (rule.getNetworkId() != newRule.getNetworkId() && rule.getState() != State.Revoke) { | ||
| throw new NetworkRuleConflictException("New rule is for a different network than what's specified in rule " + rule.getXid()); | ||
| // (except for VPCs with conserve mode = true) | ||
| if ((!isNewRuleOnVpcNetwork || !isVpcConserveModeEnabled) | ||
| && rule.getNetworkId() != newRule.getNetworkId() && rule.getState() != State.Revoke) { | ||
| String errMsg = String.format("New rule is for a different network than what's specified in rule %s", rule.getXid()); | ||
| if (isNewRuleOnVpcNetwork) { | ||
| errMsg += String.format(" - VPC id=%s is not using conserve mode", newRuleNetwork.getVpcId()); | ||
| } | ||
| throw new NetworkRuleConflictException(errMsg); | ||
|
Comment on lines
402
to
468
|
||
| } | ||
|
Comment on lines
+461
to
469
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new method |
||
|
|
||
| //Check for the ICMP protocol. This has to be done separately from other protocols as we need to check the ICMP codes and ICMP type also. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In detectRulesConflict, the code uses newRuleNetwork.getVpcId() (a VPC id) to look up a VpcOffering via vpcOfferingDao.findById(...). This will query the vpc_offerings table by offering id and can return the wrong offering (or null), causing conserve mode detection to be incorrect. Fetch the VPC (e.g., via VpcDao using the VPC id from the network) and then look up the offering by vpc.getVpcOfferingId(), or otherwise resolve the offering id explicitly before calling vpcOfferingDao.