ipfstruct.h 2.7 KB

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