- if (protocol != null && !protocol.isEmpty()) {
- return (this.getProtoNum() != 0 || protocol.equalsIgnoreCase("any"));
+ IPProtocols p = IPProtocols.fromString(protocol);
+ return p != null;
+ }
+
+ /**
+ *
+ * @param tpPort
+ * String representing the transport protocol port number
+ * @return true if tpPort contains a decimal value between 0 and 65535
+ */
+ private boolean hasValidPort(String tpPort) {
+ try {
+ int port = Integer.decode(tpPort);
+ return ((port >= 0) && (port <= 0xffff));
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Validate the transport protocol source and destination ports as
+ * entered by users.
+ *
+ * @return true if ports are defined and are in valid range
+ */
+ private boolean hasValidPorts() {
+ if (tpSrc !=null && !tpSrc.isEmpty()) {
+ if (!hasValidPort(tpSrc)) {
+ return false;
+ }
+ }
+
+ if (tpDst !=null && !tpDst.isEmpty()) {
+ return hasValidPort(tpDst);