ipfstruct.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #ifndef __ipfstruct_h
  42. #define __ipfstruct_h
  43. /*
  44. * Description (ipfstruct.h)
  45. *
  46. * This file defines types and structures used to represent an
  47. * IP address filter in memory. An IP address filter contains
  48. * specifications of IP host and network addresses. Each of
  49. * these specifications can be associated with whatever information
  50. * is appropriate for a particular use of an IP address filter.
  51. */
  52. /* Define a scalar IP address value */
  53. #ifndef __IPADDR_T_
  54. #define __IPADDR_T_
  55. typedef unsigned long IPAddr_t;
  56. #endif /* __IPADDR_T_ */
  57. /*
  58. * Description (IPNode_t)
  59. *
  60. * This type describes an internal node in the radix tree. An internal
  61. * node has a link up the tree to its parent, and up to three links
  62. * down the tree to its descendants. Each internal node is used to
  63. * test a particular bit in a given IP address, and traverse down the
  64. * tree in a direction which depends on whether the bit is set, clear,
  65. * or masked out. The descendants of an internal node may be internal
  66. * nodes or leaf nodes (IPLeaf_t).
  67. */
  68. /* Define indices of links in an IPNode_t */
  69. #define IPN_CLEAR 0 /* link to node with ipn_bit clear */
  70. #define IPN_SET 1 /* link to node with ipn_bit set */
  71. #define IPN_MASKED 2 /* link to node with ipn_bit masked out */
  72. #define IPN_NLINKS 3 /* number of links */
  73. typedef struct IPNode_s IPNode_t;
  74. struct IPNode_s {
  75. char ipn_type; /* node type */
  76. #define IPN_LEAF 0 /* leaf node */
  77. #define IPN_NODE 1 /* internal node */
  78. char ipn_bit; /* bit number (31-0) to test */
  79. IPNode_t * ipn_parent; /* link to parent node */
  80. IPNode_t * ipn_links[IPN_NLINKS];
  81. };
  82. /* Helper definitions */
  83. #define ipn_clear ipn_links[IPN_CLEAR]
  84. #define ipn_set ipn_links[IPN_SET]
  85. #define ipn_masked ipn_links[IPN_MASKED]
  86. /*
  87. * Description (IPLeaf_t)
  88. *
  89. * This type describes a leaf node in the radix tree. A leaf node
  90. * contains an IP host or network address, and a network mask. A
  91. * given IP address matches a leaf node if the IP address, when masked
  92. * by ipl_netmask, equals ipl_ipaddr.
  93. */
  94. typedef struct IPLeaf_s IPLeaf_t;
  95. struct IPLeaf_s {
  96. char ipl_type; /* see ipn_type in IPNode_t */
  97. IPAddr_t ipl_netmask; /* IP network mask */
  98. IPAddr_t ipl_ipaddr; /* IP address of host or network */
  99. };
  100. typedef struct IPFilter_s IPFilter_t;
  101. struct IPFilter_s {
  102. IPFilter_t * ipf_next; /* link to next filter */
  103. IPNode_t * ipf_tree; /* pointer to radix tree structure */
  104. };
  105. #endif /* __ipfstruct_h */