/*++ /* NAME /* ip_match 3 /* SUMMARY /* IP address pattern matching /* SYNOPSIS /* #include <ip_match.h> /* /* char *ip_match_parse(byte_codes, pattern) /* VSTRING *byte_codes; /* char *pattern; /* /* char *ip_match_save(byte_codes) /* const VSTRING *byte_codes; /* /* int ip_match_execute(byte_codes, addr_bytes) /* cost char *byte_codes; /* const char *addr_bytes; /* /* char *ip_match_dump(printable, byte_codes) /* VSTRING *printable; /* const char *byte_codes; /* DESCRIPTION /* This module supports IP address pattern matching. See below /* for a description of the supported address pattern syntax. /* /* This implementation aims to minimize the cost of encoding /* the pattern in internal form, while still providing good /* matching performance in the typical case. The first byte /* of an encoded pattern specifies the expected address family /* (for example, AF_INET); other details of the encoding are /* private and are subject to change. /* /* ip_match_parse() converts the user-specified pattern to /* internal form. The result value is a null pointer in case /* of success, or a pointer into the byte_codes buffer with a /* detailed problem description. /* /* ip_match_save() saves the result from ip_match_parse() for /* longer-term usage. The result should be passed to myfree(). /* /* ip_match_execute() matches a binary network in addr_bytes /* against a byte-code array in byte_codes. It is an error to /* use different address families for the byte_codes and addr_bytes /* arguments (the first byte-code value contains the expected /* address family). The result is non-zero in case of success. /* /* ip_match_dump() produces an ASCII dump of a byte-code array. /* The dump is supposed to be identical to the input pattern /* modulo upper/lower case or leading nulls with IPv6). This /* function is primarily a debugging aid. /* /* Arguments /* .IP addr_bytes /* Binary network address in network-byte order. /* .IP byte_codes /* Byte-code array produced by ip_match_parse(). /* .IP pattern /* Human-readable address pattern. /* .IP printable /* storage for ASCII dump of a byte-code array. /* IPV4 PATTERN SYNTAX /* .ad /* .fi /* An IPv4 address pattern has four fields separated by ".". /* Each field is either a decimal number, or a sequence inside /* "[]" that contains one or more ";"-separated decimal /* numbers or number..number ranges. /* /* Examples of patterns are 1.2.3.4 (matches itself, as one /* would expect) and 1.2.3.[2,4,6..8] (matches 1.2.3.2, 1.2.3.4, /* 1.2.3.6, 1.2.3.7, 1.2.3.8). /* /* Thus, any pattern field can be a sequence inside "[]", but /* a "[]" sequence cannot span multiple address fields, and /* a pattern field cannot contain both a number and a "[]" /* sequence at the same time. /* /* This means that the pattern 1.2.[3.4] is not valid (the /* sequence [3.4] cannot span two address fields) and the /* pattern 1.2.3.3[6..9] is also not valid (the last field /* cannot be both number 3 and sequence [6..9] at the same /* time). /* /* The syntax for IPv4 patterns is as follows: /* /* .in +5 /* v4pattern = v4field "." v4field "." v4field "." v4field /* .br /* v4field = v4octet | "[" v4sequence "]" /* .br /* v4octet = any decimal number in the range 0 through 255 /* .br /* v4sequence = v4seq_member | v4sequence ";" v4seq_member /* .br /* v4seq_member = v4octet | v4octet ".." v4octet /* .in /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this /* software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA
/*--*/
/* ip_match_next_token - carve out the next token from input pattern */
staticint ip_match_next_token(char **pstart, char **psaved_start, int *poval)
{ unsignedchar *cp; int oval; /* octet value */ int type; /* token value */
/* *Returnaliteral,error,orEOFtoken.Updatethereadpointertothe *startofthenexttokenorleaveitatthestringterminator.
*/ #define IP_MATCH_RETURN_TOK(next, type) \ do { *pstart = (char *) (next); return (type); } while (0)
/* *ReturnatokenthatcontainsanIPv4addressoctetvalue.
*/ #define IP_MATCH_RETURN_TOK_VAL(next, type, oval) do { \
*poval = (oval); IP_MATCH_RETURN_TOK((next), type); \
} while (0)
/* ip_match_parse - parse an entire wild-card address pattern */
char *ip_match_parse(VSTRING *byte_codes, char *pattern)
{ int octet_count; char *saved_cp; char *cp; int token_type; int look_ahead; int oval; int saved_oval;
/* *Simplifythisifwechangeto{}forwildcardnotation.
*/ #define FIND_TERMINATOR(start, cp) do { \ int _level = 0; \ for (cp = (start) ; *cp; cp++) { \ if (*cp == '[') _level++; \ if (*cp != ']') continue; \ if (--_level == 0) break; \
} \
} while (0)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.