netlabel_calipso.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * NetLabel CALIPSO Support
  3. *
  4. * This file defines the CALIPSO functions for the NetLabel system. The
  5. * NetLabel system manages static and dynamic label mappings for network
  6. * protocols such as CIPSO and RIPSO.
  7. *
  8. * Authors: Paul Moore <paul@paul-moore.com>
  9. * Huw Davies <huw@codeweavers.com>
  10. *
  11. */
  12. /* (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  13. * (c) Copyright Huw Davies <huw@codeweavers.com>, 2015
  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_CALIPSO
  30. #define _NETLABEL_CALIPSO
  31. #include <net/netlabel.h>
  32. #include <net/calipso.h>
  33. /* The following NetLabel payloads are supported by the CALIPSO subsystem.
  34. *
  35. * o ADD:
  36. * Sent by an application to add a new DOI mapping table.
  37. *
  38. * Required attributes:
  39. *
  40. * NLBL_CALIPSO_A_DOI
  41. * NLBL_CALIPSO_A_MTYPE
  42. *
  43. * If using CALIPSO_MAP_PASS no additional attributes are required.
  44. *
  45. * o REMOVE:
  46. * Sent by an application to remove a specific DOI mapping table from the
  47. * CALIPSO system.
  48. *
  49. * Required attributes:
  50. *
  51. * NLBL_CALIPSO_A_DOI
  52. *
  53. * o LIST:
  54. * Sent by an application to list the details of a DOI definition. On
  55. * success the kernel should send a response using the following format.
  56. *
  57. * Required attributes:
  58. *
  59. * NLBL_CALIPSO_A_DOI
  60. *
  61. * The valid response message format depends on the type of the DOI mapping,
  62. * the defined formats are shown below.
  63. *
  64. * Required attributes:
  65. *
  66. * NLBL_CALIPSO_A_MTYPE
  67. *
  68. * If using CALIPSO_MAP_PASS no additional attributes are required.
  69. *
  70. * o LISTALL:
  71. * This message is sent by an application to list the valid DOIs on the
  72. * system. When sent by an application there is no payload and the
  73. * NLM_F_DUMP flag should be set. The kernel should respond with a series of
  74. * the following messages.
  75. *
  76. * Required attributes:
  77. *
  78. * NLBL_CALIPSO_A_DOI
  79. * NLBL_CALIPSO_A_MTYPE
  80. *
  81. */
  82. /* NetLabel CALIPSO commands */
  83. enum {
  84. NLBL_CALIPSO_C_UNSPEC,
  85. NLBL_CALIPSO_C_ADD,
  86. NLBL_CALIPSO_C_REMOVE,
  87. NLBL_CALIPSO_C_LIST,
  88. NLBL_CALIPSO_C_LISTALL,
  89. __NLBL_CALIPSO_C_MAX,
  90. };
  91. /* NetLabel CALIPSO attributes */
  92. enum {
  93. NLBL_CALIPSO_A_UNSPEC,
  94. NLBL_CALIPSO_A_DOI,
  95. /* (NLA_U32)
  96. * the DOI value */
  97. NLBL_CALIPSO_A_MTYPE,
  98. /* (NLA_U32)
  99. * the mapping table type (defined in the calipso.h header as
  100. * CALIPSO_MAP_*) */
  101. __NLBL_CALIPSO_A_MAX,
  102. };
  103. #define NLBL_CALIPSO_A_MAX (__NLBL_CALIPSO_A_MAX - 1)
  104. /* NetLabel protocol functions */
  105. #if IS_ENABLED(CONFIG_IPV6)
  106. int netlbl_calipso_genl_init(void);
  107. #else
  108. static inline int netlbl_calipso_genl_init(void)
  109. {
  110. return 0;
  111. }
  112. #endif
  113. int calipso_doi_add(struct calipso_doi *doi_def,
  114. struct netlbl_audit *audit_info);
  115. void calipso_doi_free(struct calipso_doi *doi_def);
  116. int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info);
  117. struct calipso_doi *calipso_doi_getdef(u32 doi);
  118. void calipso_doi_putdef(struct calipso_doi *doi_def);
  119. int calipso_doi_walk(u32 *skip_cnt,
  120. int (*callback)(struct calipso_doi *doi_def, void *arg),
  121. void *cb_arg);
  122. int calipso_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr);
  123. int calipso_sock_setattr(struct sock *sk,
  124. const struct calipso_doi *doi_def,
  125. const struct netlbl_lsm_secattr *secattr);
  126. void calipso_sock_delattr(struct sock *sk);
  127. int calipso_req_setattr(struct request_sock *req,
  128. const struct calipso_doi *doi_def,
  129. const struct netlbl_lsm_secattr *secattr);
  130. void calipso_req_delattr(struct request_sock *req);
  131. unsigned char *calipso_optptr(const struct sk_buff *skb);
  132. int calipso_getattr(const unsigned char *calipso,
  133. struct netlbl_lsm_secattr *secattr);
  134. int calipso_skbuff_setattr(struct sk_buff *skb,
  135. const struct calipso_doi *doi_def,
  136. const struct netlbl_lsm_secattr *secattr);
  137. int calipso_skbuff_delattr(struct sk_buff *skb);
  138. void calipso_cache_invalidate(void);
  139. int calipso_cache_add(const unsigned char *calipso_ptr,
  140. const struct netlbl_lsm_secattr *secattr);
  141. #endif