cipso_ipv4.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 256
  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 65536
  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, void (*callback) (struct rcu_head * head));
  115. struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi);
  116. int cipso_v4_doi_walk(u32 *skip_cnt,
  117. int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
  118. void *cb_arg);
  119. int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def, const char *domain);
  120. int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  121. const char *domain);
  122. #else
  123. static inline int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
  124. {
  125. return -ENOSYS;
  126. }
  127. static inline int cipso_v4_doi_remove(u32 doi,
  128. void (*callback) (struct rcu_head * head))
  129. {
  130. return 0;
  131. }
  132. static inline struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
  133. {
  134. return NULL;
  135. }
  136. static inline int cipso_v4_doi_walk(u32 *skip_cnt,
  137. int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
  138. void *cb_arg)
  139. {
  140. return 0;
  141. }
  142. static inline int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def,
  143. const char *domain)
  144. {
  145. return -ENOSYS;
  146. }
  147. static inline int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
  148. const char *domain)
  149. {
  150. return 0;
  151. }
  152. #endif /* CONFIG_NETLABEL */
  153. /*
  154. * Label Mapping Cache Functions
  155. */
  156. #ifdef CONFIG_NETLABEL
  157. void cipso_v4_cache_invalidate(void);
  158. int cipso_v4_cache_add(const struct sk_buff *skb,
  159. const struct netlbl_lsm_secattr *secattr);
  160. #else
  161. static inline void cipso_v4_cache_invalidate(void)
  162. {
  163. return;
  164. }
  165. static inline int cipso_v4_cache_add(const struct sk_buff *skb,
  166. const struct netlbl_lsm_secattr *secattr)
  167. {
  168. return 0;
  169. }
  170. #endif /* CONFIG_NETLABEL */
  171. /*
  172. * Protocol Handling Functions
  173. */
  174. #ifdef CONFIG_NETLABEL
  175. void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway);
  176. int cipso_v4_socket_setattr(const struct socket *sock,
  177. const struct cipso_v4_doi *doi_def,
  178. const struct netlbl_lsm_secattr *secattr);
  179. int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr);
  180. int cipso_v4_socket_getattr(const struct socket *sock,
  181. struct netlbl_lsm_secattr *secattr);
  182. int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  183. struct netlbl_lsm_secattr *secattr);
  184. int cipso_v4_validate(unsigned char **option);
  185. #else
  186. static inline void cipso_v4_error(struct sk_buff *skb,
  187. int error,
  188. u32 gateway)
  189. {
  190. return;
  191. }
  192. static inline int cipso_v4_socket_setattr(const struct socket *sock,
  193. const struct cipso_v4_doi *doi_def,
  194. const struct netlbl_lsm_secattr *secattr)
  195. {
  196. return -ENOSYS;
  197. }
  198. static inline int cipso_v4_sock_getattr(struct sock *sk,
  199. struct netlbl_lsm_secattr *secattr)
  200. {
  201. return -ENOSYS;
  202. }
  203. static inline int cipso_v4_socket_getattr(const struct socket *sock,
  204. struct netlbl_lsm_secattr *secattr)
  205. {
  206. return -ENOSYS;
  207. }
  208. static inline int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
  209. struct netlbl_lsm_secattr *secattr)
  210. {
  211. return -ENOSYS;
  212. }
  213. static inline int cipso_v4_validate(unsigned char **option)
  214. {
  215. return -ENOSYS;
  216. }
  217. #endif /* CONFIG_NETLABEL */
  218. #endif /* _CIPSO_IPV4_H */