cipso_ipv4.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * CIPSO - Commercial IP Security Option
  3. *
  4. * This is an implementation of the CIPSO 2.2 protocol as specified in
  5. * draft-ietf-cipso-ipsecurity-01.txt with additional tag types as found in
  6. * FIPS-188, copies of both documents can be found in the Documentation
  7. * directory. While CIPSO never became a full IETF RFC standard many vendors
  8. * have chosen to adopt the protocol and over the years it has become a
  9. * de-facto standard for labeled networking.
  10. *
  11. * Author: Paul Moore <paul.moore@hp.com>
  12. *
  13. */
  14. /*
  15. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  25. * the GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. */
  32. #ifndef _CIPSO_IPV4_H
  33. #define _CIPSO_IPV4_H
  34. #include <linux/types.h>
  35. #include <linux/rcupdate.h>
  36. #include <linux/list.h>
  37. #include <net/netlabel.h>
  38. /* known doi values */
  39. #define CIPSO_V4_DOI_UNKNOWN 0x00000000
  40. /* tag types */
  41. #define CIPSO_V4_TAG_INVALID 0
  42. #define CIPSO_V4_TAG_RBITMAP 1
  43. #define CIPSO_V4_TAG_ENUM 2
  44. #define CIPSO_V4_TAG_RANGE 5
  45. #define CIPSO_V4_TAG_PBITMAP 6
  46. #define CIPSO_V4_TAG_FREEFORM 7
  47. /* doi mapping types */
  48. #define CIPSO_V4_MAP_UNKNOWN 0
  49. #define CIPSO_V4_MAP_STD 1
  50. #define CIPSO_V4_MAP_PASS 2
  51. /* limits */
  52. #define CIPSO_V4_MAX_REM_LVLS 256
  53. #define CIPSO_V4_INV_LVL 0x80000000
  54. #define CIPSO_V4_MAX_LOC_LVLS (CIPSO_V4_INV_LVL - 1)
  55. #define CIPSO_V4_MAX_REM_CATS 65536
  56. #define CIPSO_V4_INV_CAT 0x80000000
  57. #define CIPSO_V4_MAX_LOC_CATS (CIPSO_V4_INV_CAT - 1)
  58. /*
  59. * CIPSO DOI definitions
  60. */
  61. /* DOI definition struct */
  62. #define CIPSO_V4_TAG_MAXCNT 5
  63. struct cipso_v4_doi {
  64. u32 doi;
  65. u32 type;
  66. union {
  67. struct cipso_v4_std_map_tbl *std;
  68. } map;
  69. u8 tags[CIPSO_V4_TAG_MAXCNT];
  70. u32 valid;
  71. struct list_head list;
  72. struct rcu_head rcu;
  73. struct list_head dom_list;
  74. };
  75. /* Standard CIPSO mapping table */
  76. /* NOTE: the highest order bit (i.e. 0x80000000) is an 'invalid' flag, if the
  77. * bit is set then consider that value as unspecified, meaning the
  78. * mapping for that particular level/category is invalid */
  79. struct cipso_v4_std_map_tbl {
  80. struct {
  81. u32 *cipso;
  82. u32 *local;
  83. u32 cipso_size;
  84. u32 local_size;
  85. } lvl;
  86. struct {
  87. u32 *cipso;
  88. u32 *local;
  89. u32 cipso_size;
  90. u32 local_size;
  91. } cat;
  92. };
  93. /*
  94. * Sysctl Variables
  95. */
  96. #ifdef CONFIG_NETLABEL
  97. extern int cipso_v4_cache_enabled;
  98. extern int cipso_v4_cache_bucketsize;
  99. extern int cipso_v4_rbm_optfmt;
  100. extern int cipso_v4_rbm_strictvalid;
  101. #endif
  102. /*
  103. * Helper Functions
  104. */
  105. #define CIPSO_V4_OPTEXIST(x) (IPCB(x)->opt.cipso != 0)
  106. #define CIPSO_V4_OPTPTR(x) ((x)->nh.raw + IPCB(x)->opt.cipso)
  107. /*
  108. * DOI List Functions
  109. */
  110. #ifdef CONFIG_NETLABEL
  111. int cipso_v4_doi_add(struct cipso_v4_doi *doi_def);
  112. int cipso_v4_doi_remove(u32 doi, void (*callback) (struct rcu_head * head));
  113. struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi);
  114. struct sk_buff *cipso_v4_doi_dump_all(size_t headroom);
  115. struct sk_buff *cipso_v4_doi_dump(u32 doi, size_t headroom);
  116. int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def, const char *domain);
  117. int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  118. const char *domain);
  119. #else
  120. static inline int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
  121. {
  122. return -ENOSYS;
  123. }
  124. static inline int cipso_v4_doi_remove(u32 doi,
  125. void (*callback) (struct rcu_head * head))
  126. {
  127. return 0;
  128. }
  129. static inline struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
  130. {
  131. return NULL;
  132. }
  133. static inline struct sk_buff *cipso_v4_doi_dump_all(size_t headroom)
  134. {
  135. return NULL;
  136. }
  137. static inline struct sk_buff *cipso_v4_doi_dump(u32 doi, size_t headroom)
  138. {
  139. return NULL;
  140. }
  141. static inline int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def,
  142. const char *domain)
  143. {
  144. return -ENOSYS;
  145. }
  146. static inline int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  147. const char *domain)
  148. {
  149. return 0;
  150. }
  151. #endif /* CONFIG_NETLABEL */
  152. /*
  153. * Label Mapping Cache Functions
  154. */
  155. #ifdef CONFIG_NETLABEL
  156. void cipso_v4_cache_invalidate(void);
  157. int cipso_v4_cache_add(const struct sk_buff *skb,
  158. const struct netlbl_lsm_secattr *secattr);
  159. #else
  160. static inline void cipso_v4_cache_invalidate(void)
  161. {
  162. return;
  163. }
  164. static inline int cipso_v4_cache_add(const struct sk_buff *skb,
  165. const struct netlbl_lsm_secattr *secattr)
  166. {
  167. return 0;
  168. }
  169. #endif /* CONFIG_NETLABEL */
  170. /*
  171. * Protocol Handling Functions
  172. */
  173. #ifdef CONFIG_NETLABEL
  174. void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway);
  175. int cipso_v4_socket_setopt(struct socket *sock,
  176. unsigned char *opt,
  177. u32 opt_len);
  178. int cipso_v4_socket_setattr(const struct socket *sock,
  179. const struct cipso_v4_doi *doi_def,
  180. const struct netlbl_lsm_secattr *secattr);
  181. int cipso_v4_socket_getopt(const struct socket *sock,
  182. unsigned char **opt,
  183. u32 *opt_len);
  184. int cipso_v4_socket_getattr(const struct socket *sock,
  185. struct netlbl_lsm_secattr *secattr);
  186. int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  187. struct netlbl_lsm_secattr *secattr);
  188. int cipso_v4_validate(unsigned char **option);
  189. #else
  190. static inline void cipso_v4_error(struct sk_buff *skb,
  191. int error,
  192. u32 gateway)
  193. {
  194. return;
  195. }
  196. static inline int cipso_v4_socket_setattr(const struct socket *sock,
  197. const struct cipso_v4_doi *doi_def,
  198. const struct netlbl_lsm_secattr *secattr)
  199. {
  200. return -ENOSYS;
  201. }
  202. static inline int cipso_v4_socket_getattr(const struct socket *sock,
  203. struct netlbl_lsm_secattr *secattr)
  204. {
  205. return -ENOSYS;
  206. }
  207. static inline int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  208. struct netlbl_lsm_secattr *secattr)
  209. {
  210. return -ENOSYS;
  211. }
  212. static inline int cipso_v4_validate(unsigned char **option)
  213. {
  214. return -ENOSYS;
  215. }
  216. #endif /* CONFIG_NETLABEL */
  217. #endif /* _CIPSO_IPV4_H */