/** * Process the provided IPv4 address string parsed from the IP bind rule address expression. It * returns a byte array corresponding to the address string. The specified bit set represents * wild-card characters '*' found in the string. * * @param addrStr A string representing an IPv4 address. * @param wildCardBitSet A bit set used to save wild-card information. * @param expr The original expression from the IP bind rule. * @return A address byte array that can be used along with the prefix bit mask to evaluate an * IPv4 address. * @throws AciException If the address string is not a valid IPv4 address string. */ private static byte[] procIPv4Addr(String addrStr, BitSet wildCardBitSet, String expr) throws AciException { byte[] addrBytes = new byte[IN4ADDRSZ]; String[] s = addrStr.split("\\.", -1); try { if (s.length != IN4ADDRSZ) { Message message = WARN_ACI_SYNTAX_INVALID_IPV4_FORMAT.get(expr); throw new AciException(message); } for (int i = 0; i < IN4ADDRSZ; i++) { String quad = s[i].trim(); if (quad.equals("*")) wildCardBitSet.set(i); else { long val = Integer.parseInt(quad); // must be between 0-255 if ((val < 0) || (val > 0xff)) { Message message = WARN_ACI_SYNTAX_INVALID_IPV4_VALUE.get(expr); throw new AciException(message); } addrBytes[i] = (byte) (val & 0xff); } } } catch (NumberFormatException nfex) { Message message = WARN_ACI_SYNTAX_IPV4_NOT_NUMERIC.get(expr); throw new AciException(message); } return addrBytes; }
/** * Process the specified netmask string. Only pertains to IPv4 address expressions. * * @param netmaskStr String represntation of the netmask parsed from the address expression. * @param numParts The number of parts in the IP address expression. 1 if there isn't a netmask, * and 2 if there is. Anything else is an error (i.e., 254.244.123.234++255.255.255.0). * @param expr The original expression from the bind rule. * @return A byte array representing the netmask bit mask used to match IP addresses. * @throws AciException If the netmask string is invalid. */ private static byte[] getNetmaskBytes(String netmaskStr, int numParts, String expr) throws AciException { byte[] netmaskBytes = new byte[IN4ADDRSZ]; // Look up the string in the valid netmask hash table. If it isn't // there it is an error. if (!validNetMasks.containsKey(netmaskStr)) { Message message = WARN_ACI_SYNTAX_INVALID_NETMASK.get(expr); throw new AciException(message); } // Can only have one netmask value and one address string. if ((numParts < 1) || (numParts > 2)) { Message message = WARN_ACI_SYNTAX_INVALID_NETMASK_FORMAT.get(expr); throw new AciException(message); } String[] s = netmaskStr.split("\\.", -1); try { for (int i = 0; i < IN4ADDRSZ; i++) { String quad = s[i].trim(); long val = Integer.parseInt(quad); netmaskBytes[i] = (byte) (val & 0xff); } } catch (NumberFormatException nfex) { Message message = WARN_ACI_SYNTAX_IPV4_NOT_NUMERIC.get(expr); throw new AciException(message); } return netmaskBytes; }