netlabel_domainhash.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * NetLabel Domain Hash Table
  3. *
  4. * This file manages the domain hash table that NetLabel uses to determine
  5. * which network labeling protocol to use for a given domain. The NetLabel
  6. * system manages static and dynamic label mappings for network protocols such
  7. * as CIPSO and RIPSO.
  8. *
  9. * Author: Paul Moore <paul@paul-moore.com>
  10. *
  11. */
  12. /*
  13. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  23. * the GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. #ifndef _NETLABEL_DOMAINHASH_H
  30. #define _NETLABEL_DOMAINHASH_H
  31. #include <linux/types.h>
  32. #include <linux/rcupdate.h>
  33. #include <linux/list.h>
  34. #include "netlabel_addrlist.h"
  35. /* Domain hash table size */
  36. /* XXX - currently this number is an uneducated guess */
  37. #define NETLBL_DOMHSH_BITSIZE 7
  38. /* Domain mapping definition structures */
  39. struct netlbl_domaddr_map {
  40. struct list_head list4;
  41. struct list_head list6;
  42. };
  43. struct netlbl_dommap_def {
  44. u32 type;
  45. union {
  46. struct netlbl_domaddr_map *addrsel;
  47. struct cipso_v4_doi *cipso;
  48. struct calipso_doi *calipso;
  49. };
  50. };
  51. #define netlbl_domhsh_addr4_entry(iter) \
  52. container_of(iter, struct netlbl_domaddr4_map, list)
  53. struct netlbl_domaddr4_map {
  54. struct netlbl_dommap_def def;
  55. struct netlbl_af4list list;
  56. };
  57. #define netlbl_domhsh_addr6_entry(iter) \
  58. container_of(iter, struct netlbl_domaddr6_map, list)
  59. struct netlbl_domaddr6_map {
  60. struct netlbl_dommap_def def;
  61. struct netlbl_af6list list;
  62. };
  63. struct netlbl_dom_map {
  64. char *domain;
  65. u16 family;
  66. struct netlbl_dommap_def def;
  67. u32 valid;
  68. struct list_head list;
  69. struct rcu_head rcu;
  70. };
  71. /* init function */
  72. int netlbl_domhsh_init(u32 size);
  73. /* Manipulate the domain hash table */
  74. int netlbl_domhsh_add(struct netlbl_dom_map *entry,
  75. struct netlbl_audit *audit_info);
  76. int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
  77. struct netlbl_audit *audit_info);
  78. int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
  79. struct netlbl_audit *audit_info);
  80. int netlbl_domhsh_remove_af4(const char *domain,
  81. const struct in_addr *addr,
  82. const struct in_addr *mask,
  83. struct netlbl_audit *audit_info);
  84. int netlbl_domhsh_remove_af6(const char *domain,
  85. const struct in6_addr *addr,
  86. const struct in6_addr *mask,
  87. struct netlbl_audit *audit_info);
  88. int netlbl_domhsh_remove(const char *domain, u16 family,
  89. struct netlbl_audit *audit_info);
  90. int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info);
  91. struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family);
  92. struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
  93. __be32 addr);
  94. #if IS_ENABLED(CONFIG_IPV6)
  95. struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
  96. const struct in6_addr *addr);
  97. int netlbl_domhsh_remove_af6(const char *domain,
  98. const struct in6_addr *addr,
  99. const struct in6_addr *mask,
  100. struct netlbl_audit *audit_info);
  101. #endif /* IPv6 */
  102. int netlbl_domhsh_walk(u32 *skip_bkt,
  103. u32 *skip_chain,
  104. int (*callback) (struct netlbl_dom_map *entry, void *arg),
  105. void *cb_arg);
  106. #endif