cipso_ipv4.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 <linux/net.h>
  38. #include <linux/skbuff.h>
  39. #include <net/netlabel.h>
  40. /* known doi values */
  41. #define CIPSO_V4_DOI_UNKNOWN 0x00000000
  42. /* tag types */
  43. #define CIPSO_V4_TAG_INVALID 0
  44. #define CIPSO_V4_TAG_RBITMAP 1
  45. #define CIPSO_V4_TAG_ENUM 2
  46. #define CIPSO_V4_TAG_RANGE 5
  47. #define CIPSO_V4_TAG_PBITMAP 6
  48. #define CIPSO_V4_TAG_FREEFORM 7
  49. /* doi mapping types */
  50. #define CIPSO_V4_MAP_UNKNOWN 0
  51. #define CIPSO_V4_MAP_STD 1
  52. #define CIPSO_V4_MAP_PASS 2
  53. /* limits */
  54. #define CIPSO_V4_MAX_REM_LVLS 255
  55. #define CIPSO_V4_INV_LVL 0x80000000
  56. #define CIPSO_V4_MAX_LOC_LVLS (CIPSO_V4_INV_LVL - 1)
  57. #define CIPSO_V4_MAX_REM_CATS 65534
  58. #define CIPSO_V4_INV_CAT 0x80000000
  59. #define CIPSO_V4_MAX_LOC_CATS (CIPSO_V4_INV_CAT - 1)
  60. /*
  61. * CIPSO DOI definitions
  62. */
  63. /* DOI definition struct */
  64. #define CIPSO_V4_TAG_MAXCNT 5
  65. struct cipso_v4_doi {
  66. u32 doi;
  67. u32 type;
  68. union {
  69. struct cipso_v4_std_map_tbl *std;
  70. } map;
  71. u8 tags[CIPSO_V4_TAG_MAXCNT];
  72. u32 valid;
  73. struct list_head list;
  74. struct rcu_head rcu;
  75. struct list_head dom_list;
  76. };
  77. /* Standard CIPSO mapping table */
  78. /* NOTE: the highest order bit (i.e. 0x80000000) is an 'invalid' flag, if the
  79. * bit is set then consider that value as unspecified, meaning the
  80. * mapping for that particular level/category is invalid */
  81. struct cipso_v4_std_map_tbl {
  82. struct {
  83. u32 *cipso;
  84. u32 *local;
  85. u32 cipso_size;
  86. u32 local_size;
  87. } lvl;
  88. struct {
  89. u32 *cipso;
  90. u32 *local;
  91. u32 cipso_size;
  92. u32 local_size;
  93. } cat;
  94. };
  95. /*
  96. * Sysctl Variables
  97. */
  98. #ifdef CONFIG_NETLABEL
  99. extern int cipso_v4_cache_enabled;
  100. extern int cipso_v4_cache_bucketsize;
  101. extern int cipso_v4_rbm_optfmt;
  102. extern int cipso_v4_rbm_strictvalid;
  103. #endif
  104. /*
  105. * Helper Functions
  106. */
  107. #define CIPSO_V4_OPTEXIST(x) (IPCB(x)->opt.cipso != 0)
  108. #define CIPSO_V4_OPTPTR(x) ((x)->nh.raw + IPCB(x)->opt.cipso)
  109. /*
  110. * DOI List Functions
  111. */
  112. #ifdef CONFIG_NETLABEL
  113. int cipso_v4_doi_add(struct cipso_v4_doi *doi_def);
  114. int cipso_v4_doi_remove(u32 doi,
  115. struct netlbl_audit *audit_info,
  116. void (*callback) (struct rcu_head * head));
  117. struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi);
  118. int cipso_v4_doi_walk(u32 *skip_cnt,
  119. int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
  120. void *cb_arg);
  121. int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def, const char *domain);
  122. int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  123. const char *domain);
  124. #else
  125. static inline int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
  126. {
  127. return -ENOSYS;
  128. }
  129. static inline int cipso_v4_doi_remove(u32 doi,
  130. struct netlbl_audit *audit_info,
  131. void (*callback) (struct rcu_head * head))
  132. {
  133. return 0;
  134. }
  135. static inline struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
  136. {
  137. return NULL;
  138. }
  139. static inline int cipso_v4_doi_walk(u32 *skip_cnt,
  140. int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
  141. void *cb_arg)
  142. {
  143. return 0;
  144. }
  145. static inline int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def,
  146. const char *domain)
  147. {
  148. return -ENOSYS;
  149. }
  150. static inline int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  151. const char *domain)
  152. {
  153. return 0;
  154. }
  155. #endif /* CONFIG_NETLABEL */
  156. /*
  157. * Label Mapping Cache Functions
  158. */
  159. #ifdef CONFIG_NETLABEL
  160. void cipso_v4_cache_invalidate(void);
  161. int cipso_v4_cache_add(const struct sk_buff *skb,
  162. const struct netlbl_lsm_secattr *secattr);
  163. #else
  164. static inline void cipso_v4_cache_invalidate(void)
  165. {
  166. return;
  167. }
  168. static inline int cipso_v4_cache_add(const struct sk_buff *skb,
  169. const struct netlbl_lsm_secattr *secattr)
  170. {
  171. return 0;
  172. }
  173. #endif /* CONFIG_NETLABEL */
  174. /*
  175. * Protocol Handling Functions
  176. */
  177. #ifdef CONFIG_NETLABEL
  178. void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway);
  179. int cipso_v4_socket_setattr(const struct socket *sock,
  180. const struct cipso_v4_doi *doi_def,
  181. const struct netlbl_lsm_secattr *secattr);
  182. int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr);
  183. int cipso_v4_socket_getattr(const struct socket *sock,
  184. struct netlbl_lsm_secattr *secattr);
  185. int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  186. struct netlbl_lsm_secattr *secattr);
  187. int cipso_v4_validate(unsigned char **option);
  188. #else
  189. static inline void cipso_v4_error(struct sk_buff *skb,
  190. int error,
  191. u32 gateway)
  192. {
  193. return;
  194. }
  195. static inline int cipso_v4_socket_setattr(const struct socket *sock,
  196. const struct cipso_v4_doi *doi_def,
  197. const struct netlbl_lsm_secattr *secattr)
  198. {
  199. return -ENOSYS;
  200. }
  201. static inline int cipso_v4_sock_getattr(struct sock *sk,
  202. struct netlbl_lsm_secattr *secattr)
  203. {
  204. return -ENOSYS;
  205. }
  206. static inline int cipso_v4_socket_getattr(const struct socket *sock,
  207. struct netlbl_lsm_secattr *secattr)
  208. {
  209. return -ENOSYS;
  210. }
  211. static inline int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  212. struct netlbl_lsm_secattr *secattr)
  213. {
  214. return -ENOSYS;
  215. }
  216. static inline int cipso_v4_validate(unsigned char **option)
  217. {
  218. return -ENOSYS;
  219. }
  220. #endif /* CONFIG_NETLABEL */
  221. #endif /* _CIPSO_IPV4_H */