netlabel_domainhash.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * NetLabel Domain Hash Table
  4. *
  5. * This file manages the domain hash table that NetLabel uses to determine
  6. * which network labeling protocol to use for a given domain. The NetLabel
  7. * system manages static and dynamic label mappings for network protocols such
  8. * as CIPSO and RIPSO.
  9. *
  10. * Author: Paul Moore <paul@paul-moore.com>
  11. */
  12. /*
  13. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
  14. */
  15. #ifndef _NETLABEL_DOMAINHASH_H
  16. #define _NETLABEL_DOMAINHASH_H
  17. #include <linux/types.h>
  18. #include <linux/rcupdate.h>
  19. #include <linux/list.h>
  20. #include "netlabel_addrlist.h"
  21. /* Domain hash table size */
  22. /* XXX - currently this number is an uneducated guess */
  23. #define NETLBL_DOMHSH_BITSIZE 7
  24. /* Domain mapping definition structures */
  25. struct netlbl_domaddr_map {
  26. struct list_head list4;
  27. struct list_head list6;
  28. };
  29. struct netlbl_dommap_def {
  30. u32 type;
  31. union {
  32. struct netlbl_domaddr_map *addrsel;
  33. struct cipso_v4_doi *cipso;
  34. struct calipso_doi *calipso;
  35. };
  36. };
  37. #define netlbl_domhsh_addr4_entry(iter) \
  38. container_of(iter, struct netlbl_domaddr4_map, list)
  39. struct netlbl_domaddr4_map {
  40. struct netlbl_dommap_def def;
  41. struct netlbl_af4list list;
  42. };
  43. #define netlbl_domhsh_addr6_entry(iter) \
  44. container_of(iter, struct netlbl_domaddr6_map, list)
  45. struct netlbl_domaddr6_map {
  46. struct netlbl_dommap_def def;
  47. struct netlbl_af6list list;
  48. };
  49. struct netlbl_dom_map {
  50. char *domain;
  51. u16 family;
  52. struct netlbl_dommap_def def;
  53. u32 valid;
  54. struct list_head list;
  55. struct rcu_head rcu;
  56. };
  57. /* init function */
  58. int netlbl_domhsh_init(u32 size);
  59. /* Manipulate the domain hash table */
  60. int netlbl_domhsh_add(struct netlbl_dom_map *entry,
  61. struct netlbl_audit *audit_info);
  62. int netlbl_domhsh_add_default(struct netlbl_dom_map *entry,
  63. struct netlbl_audit *audit_info);
  64. int netlbl_domhsh_remove_entry(struct netlbl_dom_map *entry,
  65. struct netlbl_audit *audit_info);
  66. int netlbl_domhsh_remove_af4(const char *domain,
  67. const struct in_addr *addr,
  68. const struct in_addr *mask,
  69. struct netlbl_audit *audit_info);
  70. int netlbl_domhsh_remove_af6(const char *domain,
  71. const struct in6_addr *addr,
  72. const struct in6_addr *mask,
  73. struct netlbl_audit *audit_info);
  74. int netlbl_domhsh_remove(const char *domain, u16 family,
  75. struct netlbl_audit *audit_info);
  76. int netlbl_domhsh_remove_default(u16 family, struct netlbl_audit *audit_info);
  77. struct netlbl_dom_map *netlbl_domhsh_getentry(const char *domain, u16 family);
  78. struct netlbl_dommap_def *netlbl_domhsh_getentry_af4(const char *domain,
  79. __be32 addr);
  80. #if IS_ENABLED(CONFIG_IPV6)
  81. struct netlbl_dommap_def *netlbl_domhsh_getentry_af6(const char *domain,
  82. const struct in6_addr *addr);
  83. int netlbl_domhsh_remove_af6(const char *domain,
  84. const struct in6_addr *addr,
  85. const struct in6_addr *mask,
  86. struct netlbl_audit *audit_info);
  87. #endif /* IPv6 */
  88. int netlbl_domhsh_walk(u32 *skip_bkt,
  89. u32 *skip_chain,
  90. int (*callback) (struct netlbl_dom_map *entry, void *arg),
  91. void *cb_arg);
  92. #endif