|
48 | 48 | import org.apache.commons.collections.CollectionUtils; |
49 | 49 | import org.apache.commons.lang.SystemUtils; |
50 | 50 | import org.apache.commons.lang3.StringUtils; |
| 51 | +import org.apache.commons.lang3.math.NumberUtils; |
51 | 52 | import org.apache.commons.net.util.SubnetUtils; |
52 | 53 | import org.apache.commons.validator.routines.InetAddressValidator; |
53 | 54 | import org.apache.commons.validator.routines.RegexValidator; |
@@ -82,6 +83,8 @@ public class NetUtils { |
82 | 83 | public final static String ICMP_PROTO = "icmp"; |
83 | 84 | public static final String ICMP6_PROTO = "icmp6"; |
84 | 85 | public final static int ICMP_PROTO_NUMBER = 1; |
| 86 | + public final static int TCP_PROTO_NUMBER = 6; |
| 87 | + public final static int UDP_PROTO_NUMBER = 17; |
85 | 88 | public final static String ALL_PROTO = "all"; |
86 | 89 | public final static String HTTP_PROTO = "http"; |
87 | 90 | public final static String HTTPS_PROTO = "https"; |
@@ -1013,6 +1016,21 @@ public static boolean isValidSecurityGroupProto(final String p) { |
1013 | 1016 | return proto.equals(TCP_PROTO) || proto.equals(UDP_PROTO) || proto.equals(ICMP_PROTO) || proto.equals(ALL_PROTO); |
1014 | 1017 | } |
1015 | 1018 |
|
| 1019 | + /** |
| 1020 | + * Gives a rule's protocol trimmed, with protocol number 1 as icmp, so that the rule keeps its ICMP |
| 1021 | + * type and code. |
| 1022 | + */ |
| 1023 | + public static String icmpProtocolNumberAsName(final String protocol) { |
| 1024 | + if (protocol == null) { |
| 1025 | + return null; |
| 1026 | + } |
| 1027 | + final String p = protocol.trim(); |
| 1028 | + if (StringUtils.isNumeric(p) && NumberUtils.toInt(p, -1) == ICMP_PROTO_NUMBER) { |
| 1029 | + return ICMP_PROTO; |
| 1030 | + } |
| 1031 | + return p; |
| 1032 | + } |
| 1033 | + |
1016 | 1034 | public static boolean isValidAlgorithm(final String p) { |
1017 | 1035 | final String algo = p.toLowerCase(); |
1018 | 1036 | return algo.equals("roundrobin") || algo.equals("leastconn") || algo.equals("source"); |
|
0 commit comments