Postfix3.3.1
cidr_match.h
[詳解]
1 #ifndef _CIDR_MATCH_H_INCLUDED_
2 #define _CIDR_MATCH_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* dict_cidr 3h
7 /* SUMMARY
8 /* CIDR-style pattern matching
9 /* SYNOPSIS
10 /* #include <cidr_match.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * System library.
16  */
17 #include <limits.h> /* CHAR_BIT */
18 
19  /*
20  * Utility library.
21  */
22 #include <myaddrinfo.h> /* MAI_V6ADDR_BYTES etc. */
23 #include <vstring.h>
24 
25  /*
26  * External interface.
27  *
28  * Address length is protocol dependent. Find out how large our address byte
29  * strings should be.
30  */
31 #ifdef HAS_IPV6
32 # define CIDR_MATCH_ABYTES MAI_V6ADDR_BYTES
33 #else
34 # define CIDR_MATCH_ABYTES MAI_V4ADDR_BYTES
35 #endif
36 
37  /*
38  * Each parsed CIDR pattern can be member of a linked list.
39  */
40 typedef struct CIDR_MATCH {
41  int op; /* operation, match or control flow */
42  int match; /* positive or negative match */
43  unsigned char net_bytes[CIDR_MATCH_ABYTES]; /* network portion */
44  unsigned char mask_bytes[CIDR_MATCH_ABYTES]; /* network mask */
45  unsigned char addr_family; /* AF_XXX */
46  unsigned char addr_byte_count; /* typically, 4 or 16 */
47  unsigned char addr_bit_count; /* optimization */
48  unsigned char mask_shift; /* optimization */
49  struct CIDR_MATCH *next; /* next entry */
50  struct CIDR_MATCH *block_end; /* block terminator */
51 } CIDR_MATCH;
52 
53 #define CIDR_MATCH_OP_MATCH 1 /* Match this pattern */
54 #define CIDR_MATCH_OP_IF 2 /* Increase if/endif nesting on match */
55 #define CIDR_MATCH_OP_ENDIF 3 /* Decrease if/endif nesting on match */
56 
57 #define CIDR_MATCH_TRUE 1 /* Request positive match */
58 #define CIDR_MATCH_FALSE 0 /* Request negative match */
59 
60 extern VSTRING *cidr_match_parse(CIDR_MATCH *, char *, int, VSTRING *);
61 extern VSTRING *cidr_match_parse_if(CIDR_MATCH *, char *, int, VSTRING *);
62 extern void cidr_match_endif(CIDR_MATCH *);
63 
64 extern CIDR_MATCH *cidr_match_execute(CIDR_MATCH *, const char *);
65 
66 /* LICENSE
67 /* .ad
68 /* .fi
69 /* The Secure Mailer license must be distributed with this software.
70 /* AUTHOR(S)
71 /* Wietse Venema
72 /* IBM T.J. Watson Research
73 /* P.O. Box 704
74 /* Yorktown Heights, NY 10598, USA
75 /*
76 /* Wietse Venema
77 /* Google, Inc.
78 /* 111 8th Avenue
79 /* New York, NY 10011, USA
80 /*--*/
81 
82 #endif
unsigned char mask_shift
Definition: cidr_match.h:48
unsigned char addr_bit_count
Definition: cidr_match.h:47
struct CIDR_MATCH * block_end
Definition: cidr_match.h:50
unsigned char net_bytes[CIDR_MATCH_ABYTES]
Definition: cidr_match.h:43
unsigned char addr_byte_count
Definition: cidr_match.h:46
struct CIDR_MATCH CIDR_MATCH
#define CIDR_MATCH_ABYTES
Definition: cidr_match.h:34
VSTRING * cidr_match_parse(CIDR_MATCH *, char *, int, VSTRING *)
Definition: cidr_match.c:186
unsigned char mask_bytes[CIDR_MATCH_ABYTES]
Definition: cidr_match.h:44
struct CIDR_MATCH * next
Definition: cidr_match.h:49
CIDR_MATCH * cidr_match_execute(CIDR_MATCH *, const char *)
Definition: cidr_match.c:148
unsigned char addr_family
Definition: cidr_match.h:45
void cidr_match_endif(CIDR_MATCH *)
Definition: cidr_match.c:301
VSTRING * cidr_match_parse_if(CIDR_MATCH *, char *, int, VSTRING *)
Definition: cidr_match.c:289