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