bhouse-nexthop commented on code in PR #14357:
URL: https://github.com/apache/cloudstack/pull/14357#discussion_r4273505178


##########
core/src/main/java/com/cloud/agent/api/routing/SetNetworkACLCommand.java:
##########
@@ -97,6 +103,45 @@ public String[][] generateFwRules() {
         return result;
     }
 
+    /**
+     * The VR applies ports only to a rule it is sent as tcp or udp, and an 
ICMP type and code only to one
+     * sent as icmp; any other protocol goes to it as a bare number, which 
matches the whole protocol. So
+     * send protocol number 1 as icmp, and 6 and 17 as tcp and udp when the 
rule has ports, whatever form
+     * or case they were stored in. Without ports 6 and 17 stay bare numbers, 
which match the whole
+     * protocol on every VR path; a tcp or udp rule without ports has matched 
port 0 only on the iptables
+     * path (see #14363).
+     */
+    protected static String normalizeProtocol(String protocol, boolean 
hasPorts) {
+        if (protocol == null) {
+            return null;
+        }
+        String p = protocol.trim().toLowerCase(Locale.ROOT);
+        if (!StringUtils.isNumeric(p)) {
+            return p;
+        }
+        int number;
+        try {
+            number = Integer.parseInt(p);
+        } catch (NumberFormatException e) {
+            return p;
+        }
+        if (number == NetUtils.ICMP_PROTO_NUMBER) {
+            return NetUtils.ICMP_PROTO;
+        }
+        if (hasPorts && number == TCP_PROTO_NUMBER) {

Review Comment:
   Yes, agreed. Your reading is right: a stored protocol `6`/`17` rule with 
ports has been matching all of TCP/UDP, and since the encoding happens on the 
management server, it will match only its ports from the first time the list is 
re-sent after the upgrade. That's any add/update/delete of a rule in the list, 
a list replace, or a router start/reboot/restart/redeploy (network or VPC 
restart, template upgrade). This applies whatever the VR template version is.
   
   I've expanded the "Upgrade note / behaviour change" section of the 
description so it can be lifted into the release notes. It covers which stored 
rules change (6/17 with ports, protocol `1` with a stored ICMP type, upper-case 
`ICMP`, and the IPv6 rendering of protocol `1`) and which don't, when the 
change takes effect, and what operators should do. It includes a SQL query to 
find the affected rows in `network_acl_item`. It also mentions the new API 
rejection of ports on other protocol numbers.
   
   The repo has no release-notes label that I can find; the nearest are 
`type:breaking-change` and `component:upgrade`. I've left those for a committer 
to decide. Could one of you add whichever you use to flag this for the release 
notes?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to