ipfstruct.h 2.6 KB

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