cipso_ipv4.h 7.4 KB

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