cipso_ipv4.h 7.0 KB

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