| 1 |
/** BEGIN COPYRIGHT BLOCK |
| 2 |
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. |
| 3 |
* Copyright (C) 2005 Red Hat, Inc. |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* License: GPL (version 3 or any later version). |
| 7 |
* See LICENSE for details. |
| 8 |
* END COPYRIGHT BLOCK **/ |
| 9 |
|
| 10 |
#ifdef HAVE_CONFIG_H |
| 11 |
#include <config.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
#ifndef __ipfstruct_h |
| 15 |
#define __ipfstruct_h |
| 16 |
|
| 17 |
/* |
| 18 |
* Description (ipfstruct.h) |
| 19 |
* |
| 20 |
* This file defines types and structures used to represent an |
| 21 |
* IP address filter in memory. An IP address filter contains |
| 22 |
* specifications of IP host and network addresses. Each of |
| 23 |
* these specifications can be associated with whatever information |
| 24 |
* is appropriate for a particular use of an IP address filter. |
| 25 |
*/ |
| 26 |
|
| 27 |
/* Define a scalar IP address value */ |
| 28 |
#ifndef __IPADDR_T_ |
| 29 |
#define __IPADDR_T_ |
| 30 |
typedef unsigned long IPAddr_t; |
| 31 |
#endif /* __IPADDR_T_ */ |
| 32 |
|
| 33 |
/* |
| 34 |
* Description (IPNode_t) |
| 35 |
* |
| 36 |
* This type describes an internal node in the radix tree. An internal |
| 37 |
* node has a link up the tree to its parent, and up to three links |
| 38 |
* down the tree to its descendants. Each internal node is used to |
| 39 |
* test a particular bit in a given IP address, and traverse down the |
| 40 |
* tree in a direction which depends on whether the bit is set, clear, |
| 41 |
* or masked out. The descendants of an internal node may be internal |
| 42 |
* nodes or leaf nodes (IPLeaf_t). |
| 43 |
*/ |
| 44 |
|
| 45 |
/* Define indices of links in an IPNode_t */ |
| 46 |
#define IPN_CLEAR 0 /* link to node with ipn_bit clear */ |
| 47 |
#define IPN_SET 1 /* link to node with ipn_bit set */ |
| 48 |
#define IPN_MASKED 2 /* link to node with ipn_bit masked out */ |
| 49 |
#define IPN_NLINKS 3 /* number of links */ |
| 50 |
|
| 51 |
typedef struct IPNode_s IPNode_t; |
| 52 |
struct IPNode_s |
| 53 |
{ |
| 54 |
char ipn_type; /* node type */ |
| 55 |
#define IPN_LEAF 0 /* leaf node */ |
| 56 |
#define IPN_NODE 1 /* internal node */ |
| 57 |
|
| 58 |
char ipn_bit; /* bit number (31-0) to test */ |
| 59 |
IPNode_t *ipn_parent; /* link to parent node */ |
| 60 |
IPNode_t *ipn_links[IPN_NLINKS]; |
| 61 |
}; |
| 62 |
|
| 63 |
/* Helper definitions */ |
| 64 |
#define ipn_clear ipn_links[IPN_CLEAR] |
| 65 |
#define ipn_set ipn_links[IPN_SET] |
| 66 |
#define ipn_masked ipn_links[IPN_MASKED] |
| 67 |
|
| 68 |
/* |
| 69 |
* Description (IPLeaf_t) |
| 70 |
* |
| 71 |
* This type describes a leaf node in the radix tree. A leaf node |
| 72 |
* contains an IP host or network address, and a network mask. A |
| 73 |
* given IP address matches a leaf node if the IP address, when masked |
| 74 |
* by ipl_netmask, equals ipl_ipaddr. |
| 75 |
*/ |
| 76 |
|
| 77 |
typedef struct IPLeaf_s IPLeaf_t; |
| 78 |
struct IPLeaf_s |
| 79 |
{ |
| 80 |
char ipl_type; /* see ipn_type in IPNode_t */ |
| 81 |
IPAddr_t ipl_netmask; /* IP network mask */ |
| 82 |
IPAddr_t ipl_ipaddr; /* IP address of host or network */ |
| 83 |
}; |
| 84 |
|
| 85 |
typedef struct IPFilter_s IPFilter_t; |
| 86 |
struct IPFilter_s |
| 87 |
{ |
| 88 |
IPFilter_t *ipf_next; /* link to next filter */ |
| 89 |
IPNode_t *ipf_tree; /* pointer to radix tree structure */ |
| 90 |
}; |
| 91 |
|
| 92 |
#endif /* __ipfstruct_h */ |