cipso_ipv4.h 6.9 KB

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