|
20 | 20 |
|
21 | 21 | import org.apache.cloudstack.framework.config.ConfigKey; |
22 | 22 |
|
| 23 | +import com.googlecode.ipv6.IPv6Network; |
| 24 | + |
23 | 25 | import com.cloud.exception.AgentUnavailableException; |
24 | 26 | import com.cloud.exception.ConcurrentOperationException; |
25 | 27 | import com.cloud.exception.ResourceUnavailableException; |
|
29 | 31 | import com.cloud.user.Account; |
30 | 32 | import com.cloud.user.User; |
31 | 33 | import com.cloud.utils.component.Manager; |
| 34 | +import com.cloud.utils.net.NetUtils; |
32 | 35 | import com.cloud.vm.DomainRouterVO; |
33 | 36 |
|
34 | 37 | /** |
@@ -82,10 +85,31 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA |
82 | 85 | ConfigKey<Boolean> ExposeDnsAndBootpServer = new ConfigKey<>(Boolean.class, "expose.dns.externally", "Advanced", "false", |
83 | 86 | "open dns, dhcp and bootp on the public interface", true, ConfigKey.Scope.Zone, null); |
84 | 87 | ConfigKey<String> NetworkUsageExemptCidrs = new ConfigKey<>(String.class, "network.usage.exempt.cidrs", "Usage", "", |
85 | | - "Comma-separated IPv4 addresses or CIDRs. Traffic between guest networks and these addresses doesn't count " + |
86 | | - "towards virtual router network usage. Routers pick up a change the next time they start or restart.", |
| 88 | + "Comma-separated IPv4 or IPv6 addresses or CIDRs. Traffic between guest networks and these addresses doesn't count " + |
| 89 | + "towards virtual router network usage. Virtual routers only count IPv4 traffic, so they ignore IPv6 entries. " + |
| 90 | + "Routers pick up a change the next time they start or restart.", |
87 | 91 | true, ConfigKey.Scope.Zone, null, null, null, null, null, ConfigKey.Kind.CSV, null); |
88 | 92 |
|
| 93 | + /** |
| 94 | + * Tidies one entry of {@link #NetworkUsageExemptCidrs} into a CIDR, or returns null if it isn't a valid address or CIDR. |
| 95 | + * For example, 192.0.2.5 becomes 192.0.2.5/32, 198.51.100.70/24 becomes 198.51.100.0/24 and 2001:db8::5 becomes |
| 96 | + * 2001:db8::5/128. Callers refuse a /0 result, as it would exempt all traffic. |
| 97 | + */ |
| 98 | + static String normaliseUsageExemptCidr(String entry) { |
| 99 | + if (NetUtils.isValidIp4(entry)) { |
| 100 | + entry = entry + "/32"; |
| 101 | + } else if (NetUtils.isValidIp6(entry)) { |
| 102 | + entry = entry + "/128"; |
| 103 | + } |
| 104 | + if (NetUtils.isValidIp4Cidr(entry)) { |
| 105 | + return NetUtils.getCidrSubNet(entry) + "/" + NetUtils.getCidr(entry).second(); |
| 106 | + } |
| 107 | + if (entry.contains(":") && NetUtils.isValidIp6Cidr(entry)) { |
| 108 | + return IPv6Network.fromString(entry).toString(); |
| 109 | + } |
| 110 | + return null; |
| 111 | + } |
| 112 | + |
89 | 113 | ConfigKey<String> VirtualRouterServiceOffering = new ConfigKey<>(String.class, VirtualRouterServiceOfferingCK, "Advanced", "", |
90 | 114 | "Uuid of the service offering used by virtual routers; if NULL - system offering will be used", true, ConfigKey.Scope.Account, null); |
91 | 115 |
|
|
0 commit comments