aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
Diffstat (limited to 'include/net')
-rw-r--r--include/net/cipso_ipv4.h250
-rw-r--r--include/net/inet_sock.h2
-rw-r--r--include/net/netlabel.h291
3 files changed, 542 insertions, 1 deletions
diff --git a/include/net/cipso_ipv4.h b/include/net/cipso_ipv4.h
new file mode 100644
index 000000000000..c7175e725804
--- /dev/null
+++ b/include/net/cipso_ipv4.h
@@ -0,0 +1,250 @@
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/*
16 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
26 * the GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 *
32 */
33
34#ifndef _CIPSO_IPV4_H
35#define _CIPSO_IPV4_H
36
37#include <linux/types.h>
38#include <linux/rcupdate.h>
39#include <linux/list.h>
40#include <net/netlabel.h>
41
42/* known doi values */
43#define CIPSO_V4_DOI_UNKNOWN 0x00000000
44
45/* tag types */
46#define CIPSO_V4_TAG_INVALID 0
47#define CIPSO_V4_TAG_RBITMAP 1
48#define CIPSO_V4_TAG_ENUM 2
49#define CIPSO_V4_TAG_RANGE 5
50#define CIPSO_V4_TAG_PBITMAP 6
51#define CIPSO_V4_TAG_FREEFORM 7
52
53/* doi mapping types */
54#define CIPSO_V4_MAP_UNKNOWN 0
55#define CIPSO_V4_MAP_STD 1
56#define CIPSO_V4_MAP_PASS 2
57
58/* limits */
59#define CIPSO_V4_MAX_REM_LVLS 256
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 65536
63#define CIPSO_V4_INV_CAT 0x80000000
64#define CIPSO_V4_MAX_LOC_CATS (CIPSO_V4_INV_CAT - 1)
65
66/*
67 * CIPSO DOI definitions
68 */
69
70/* DOI definition struct */
71#define CIPSO_V4_TAG_MAXCNT 5
72struct cipso_v4_doi {
73 u32 doi;
74 u32 type;
75 union {
76 struct cipso_v4_std_map_tbl *std;
77 } map;
78 u8 tags[CIPSO_V4_TAG_MAXCNT];
79
80 u32 valid;
81 struct list_head list;
82 struct rcu_head rcu;
83 struct list_head dom_list;
84};
85
86/* Standard CIPSO mapping table */
87/* NOTE: the highest order bit (i.e. 0x80000000) is an 'invalid' flag, if the
88 * bit is set then consider that value as unspecified, meaning the
89 * mapping for that particular level/category is invalid */
90struct cipso_v4_std_map_tbl {
91 struct {
92 u32 *cipso;
93 u32 *local;
94 u32 cipso_size;
95 u32 local_size;
96 } lvl;
97 struct {
98 u32 *cipso;
99 u32 *local;
100 u32 cipso_size;
101 u32 local_size;
102 } cat;
103};
104
105/*
106 * Sysctl Variables
107 */
108
109#ifdef CONFIG_NETLABEL
110extern int cipso_v4_cache_enabled;
111extern int cipso_v4_cache_bucketsize;
112extern int cipso_v4_rbm_optfmt;
113extern int cipso_v4_rbm_strictvalid;
114#endif
115
116/*
117 * Helper Functions
118 */
119
120#define CIPSO_V4_OPTEXIST(x) (IPCB(x)->opt.cipso != 0)
121#define CIPSO_V4_OPTPTR(x) ((x)->nh.raw + IPCB(x)->opt.cipso)
122
123/*
124 * DOI List Functions
125 */
126
127#ifdef CONFIG_NETLABEL
128int cipso_v4_doi_add(struct cipso_v4_doi *doi_def);
129int cipso_v4_doi_remove(u32 doi, void (*callback) (struct rcu_head * head));
130struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi);
131struct sk_buff *cipso_v4_doi_dump_all(size_t headroom);
132struct sk_buff *cipso_v4_doi_dump(u32 doi, size_t headroom);
133int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def, const char *domain);
134int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
135 const char *domain);
136#else
137static inline int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
138{
139 return -ENOSYS;
140}
141
142static inline int cipso_v4_doi_remove(u32 doi,
143 void (*callback) (struct rcu_head * head))
144{
145 return 0;
146}
147
148static inline struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
149{
150 return NULL;
151}
152
153static inline struct sk_buff *cipso_v4_doi_dump_all(size_t headroom)
154{
155 return NULL;
156}
157
158static inline struct sk_buff *cipso_v4_doi_dump(u32 doi, size_t headroom)
159{
160 return NULL;
161}
162
163static inline int cipso_v4_doi_domhsh_add(struct cipso_v4_doi *doi_def,
164 const char *domain)
165{
166 return -ENOSYS;
167}
168
169static inline int cipso_v4_doi_domhsh_remove(struct cipso_v4_doi *doi_def,
170 const char *domain)
171{
172 return 0;
173}
174#endif /* CONFIG_NETLABEL */
175
176/*
177 * Label Mapping Cache Functions
178 */
179
180#ifdef CONFIG_NETLABEL
181void cipso_v4_cache_invalidate(void);
182int cipso_v4_cache_add(const struct sk_buff *skb,
183 const struct netlbl_lsm_secattr *secattr);
184#else
185static inline void cipso_v4_cache_invalidate(void)
186{
187 return;
188}
189
190static inline int cipso_v4_cache_add(const struct sk_buff *skb,
191 const struct netlbl_lsm_secattr *secattr)
192{
193 return 0;
194}
195#endif /* CONFIG_NETLABEL */
196
197/*
198 * Protocol Handling Functions
199 */
200
201#ifdef CONFIG_NETLABEL
202void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway);
203int cipso_v4_socket_setopt(struct socket *sock,
204 unsigned char *opt,
205 u32 opt_len);
206int cipso_v4_socket_setattr(const struct socket *sock,
207 const struct cipso_v4_doi *doi_def,
208 const struct netlbl_lsm_secattr *secattr);
209int cipso_v4_socket_getopt(const struct socket *sock,
210 unsigned char **opt,
211 u32 *opt_len);
212int cipso_v4_socket_getattr(const struct socket *sock,
213 struct netlbl_lsm_secattr *secattr);
214int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
215 struct netlbl_lsm_secattr *secattr);
216int cipso_v4_validate(unsigned char **option);
217#else
218static inline void cipso_v4_error(struct sk_buff *skb,
219 int error,
220 u32 gateway)
221{
222 return;
223}
224
225static inline int cipso_v4_socket_setattr(const struct socket *sock,
226 const struct cipso_v4_doi *doi_def,
227 const struct netlbl_lsm_secattr *secattr)
228{
229 return -ENOSYS;
230}
231
232static inline int cipso_v4_socket_getattr(const struct socket *sock,
233 struct netlbl_lsm_secattr *secattr)
234{
235 return -ENOSYS;
236}
237
238static inline int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
239 struct netlbl_lsm_secattr *secattr)
240{
241 return -ENOSYS;
242}
243
244static inline int cipso_v4_validate(unsigned char **option)
245{
246 return -ENOSYS;
247}
248#endif /* CONFIG_NETLABEL */
249
250#endif /* _CIPSO_IPV4_H */
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 1f4a9a60d4cc..f4caad56cd03 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -51,7 +51,7 @@ struct ip_options {
51 ts_needtime:1, 51 ts_needtime:1,
52 ts_needaddr:1; 52 ts_needaddr:1;
53 unsigned char router_alert; 53 unsigned char router_alert;
54 unsigned char __pad1; 54 unsigned char cipso;
55 unsigned char __pad2; 55 unsigned char __pad2;
56 unsigned char __data[0]; 56 unsigned char __data[0];
57}; 57};
diff --git a/include/net/netlabel.h b/include/net/netlabel.h
new file mode 100644
index 000000000000..7cae730832c7
--- /dev/null
+++ b/include/net/netlabel.h
@@ -0,0 +1,291 @@
1/*
2 * NetLabel System
3 *
4 * The NetLabel system manages static and dynamic label mappings for network
5 * protocols such as CIPSO and RIPSO.
6 *
7 * Author: Paul Moore <paul.moore@hp.com>
8 *
9 */
10
11/*
12 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
22 * the GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30#ifndef _NETLABEL_H
31#define _NETLABEL_H
32
33#include <linux/types.h>
34#include <linux/skbuff.h>
35#include <net/netlink.h>
36
37/*
38 * NetLabel - A management interface for maintaining network packet label
39 * mapping tables for explicit packet labling protocols.
40 *
41 * Network protocols such as CIPSO and RIPSO require a label translation layer
42 * to convert the label on the packet into something meaningful on the host
43 * machine. In the current Linux implementation these mapping tables live
44 * inside the kernel; NetLabel provides a mechanism for user space applications
45 * to manage these mapping tables.
46 *
47 * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to
48 * send messages between kernel and user space. The general format of a
49 * NetLabel message is shown below:
50 *
51 * +-----------------+-------------------+--------- --- -- -
52 * | struct nlmsghdr | struct genlmsghdr | payload
53 * +-----------------+-------------------+--------- --- -- -
54 *
55 * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal.
56 * The payload is dependent on the subsystem specified in the
57 * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions
58 * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c
59 * file. All of the fields in the NetLabel payload are NETLINK attributes, the
60 * length of each field is the length of the NETLINK attribute payload, see
61 * include/net/netlink.h for more information on NETLINK attributes.
62 *
63 */
64
65/*
66 * NetLabel NETLINK protocol
67 */
68
69#define NETLBL_PROTO_VERSION 1
70
71/* NetLabel NETLINK types/families */
72#define NETLBL_NLTYPE_NONE 0
73#define NETLBL_NLTYPE_MGMT 1
74#define NETLBL_NLTYPE_MGMT_NAME "NLBL_MGMT"
75#define NETLBL_NLTYPE_RIPSO 2
76#define NETLBL_NLTYPE_RIPSO_NAME "NLBL_RIPSO"
77#define NETLBL_NLTYPE_CIPSOV4 3
78#define NETLBL_NLTYPE_CIPSOV4_NAME "NLBL_CIPSOv4"
79#define NETLBL_NLTYPE_CIPSOV6 4
80#define NETLBL_NLTYPE_CIPSOV6_NAME "NLBL_CIPSOv6"
81#define NETLBL_NLTYPE_UNLABELED 5
82#define NETLBL_NLTYPE_UNLABELED_NAME "NLBL_UNLBL"
83
84/* NetLabel return codes */
85#define NETLBL_E_OK 0
86
87/*
88 * Helper functions
89 */
90
91#define NETLBL_LEN_U8 nla_total_size(sizeof(u8))
92#define NETLBL_LEN_U16 nla_total_size(sizeof(u16))
93#define NETLBL_LEN_U32 nla_total_size(sizeof(u32))
94
95/**
96 * netlbl_netlink_alloc_skb - Allocate a NETLINK message buffer
97 * @head: the amount of headroom in bytes
98 * @body: the desired size (minus headroom) in bytes
99 * @gfp_flags: the alloc flags to pass to alloc_skb()
100 *
101 * Description:
102 * Allocate a NETLINK message buffer based on the sizes given in @head and
103 * @body. If @head is greater than zero skb_reserve() is called to reserve
104 * @head bytes at the start of the buffer. Returns a valid sk_buff pointer on
105 * success, NULL on failure.
106 *
107 */
108static inline struct sk_buff *netlbl_netlink_alloc_skb(size_t head,
109 size_t body,
110 int gfp_flags)
111{
112 struct sk_buff *skb;
113
114 skb = alloc_skb(NLMSG_ALIGN(head + body), gfp_flags);
115 if (skb == NULL)
116 return NULL;
117 if (head > 0) {
118 skb_reserve(skb, head);
119 if (skb_tailroom(skb) < body) {
120 kfree_skb(skb);
121 return NULL;
122 }
123 }
124
125 return skb;
126}
127
128/*
129 * NetLabel - Kernel API for accessing the network packet label mappings.
130 *
131 * The following functions are provided for use by other kernel modules,
132 * specifically kernel LSM modules, to provide a consistent, transparent API
133 * for dealing with explicit packet labeling protocols such as CIPSO and
134 * RIPSO. The functions defined here are implemented in the
135 * net/netlabel/netlabel_kapi.c file.
136 *
137 */
138
139/* Domain mapping definition struct */
140struct netlbl_dom_map;
141
142/* Domain mapping operations */
143int netlbl_domhsh_remove(const char *domain);
144
145/* LSM security attributes */
146struct netlbl_lsm_cache {
147 void (*free) (const void *data);
148 void *data;
149};
150struct netlbl_lsm_secattr {
151 char *domain;
152
153 u32 mls_lvl;
154 u32 mls_lvl_vld;
155 unsigned char *mls_cat;
156 size_t mls_cat_len;
157
158 struct netlbl_lsm_cache cache;
159};
160
161/*
162 * LSM security attribute operations
163 */
164
165
166/**
167 * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct
168 * @secattr: the struct to initialize
169 *
170 * Description:
171 * Initialize an already allocated netlbl_lsm_secattr struct. Returns zero on
172 * success, negative values on error.
173 *
174 */
175static inline int netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
176{
177 memset(secattr, 0, sizeof(*secattr));
178 return 0;
179}
180
181/**
182 * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct
183 * @secattr: the struct to clear
184 * @clear_cache: cache clear flag
185 *
186 * Description:
187 * Destroys the @secattr struct, including freeing all of the internal buffers.
188 * If @clear_cache is true then free the cache fields, otherwise leave them
189 * intact. The struct must be reset with a call to netlbl_secattr_init()
190 * before reuse.
191 *
192 */
193static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr,
194 u32 clear_cache)
195{
196 if (clear_cache && secattr->cache.data != NULL && secattr->cache.free)
197 secattr->cache.free(secattr->cache.data);
198 kfree(secattr->domain);
199 kfree(secattr->mls_cat);
200}
201
202/**
203 * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct
204 * @flags: the memory allocation flags
205 *
206 * Description:
207 * Allocate and initialize a netlbl_lsm_secattr struct. Returns a valid
208 * pointer on success, or NULL on failure.
209 *
210 */
211static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(int flags)
212{
213 return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
214}
215
216/**
217 * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct
218 * @secattr: the struct to free
219 * @clear_cache: cache clear flag
220 *
221 * Description:
222 * Frees @secattr including all of the internal buffers. If @clear_cache is
223 * true then free the cache fields, otherwise leave them intact.
224 *
225 */
226static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr,
227 u32 clear_cache)
228{
229 netlbl_secattr_destroy(secattr, clear_cache);
230 kfree(secattr);
231}
232
233/*
234 * LSM protocol operations
235 */
236
237#ifdef CONFIG_NETLABEL
238int netlbl_socket_setattr(const struct socket *sock,
239 const struct netlbl_lsm_secattr *secattr);
240int netlbl_socket_getattr(const struct socket *sock,
241 struct netlbl_lsm_secattr *secattr);
242int netlbl_skbuff_getattr(const struct sk_buff *skb,
243 struct netlbl_lsm_secattr *secattr);
244void netlbl_skbuff_err(struct sk_buff *skb, int error);
245#else
246static inline int netlbl_socket_setattr(const struct socket *sock,
247 const struct netlbl_lsm_secattr *secattr)
248{
249 return -ENOSYS;
250}
251
252static inline int netlbl_socket_getattr(const struct socket *sock,
253 struct netlbl_lsm_secattr *secattr)
254{
255 return -ENOSYS;
256}
257
258static inline int netlbl_skbuff_getattr(const struct sk_buff *skb,
259 struct netlbl_lsm_secattr *secattr)
260{
261 return -ENOSYS;
262}
263
264static inline void netlbl_skbuff_err(struct sk_buff *skb, int error)
265{
266 return;
267}
268#endif /* CONFIG_NETLABEL */
269
270/*
271 * LSM label mapping cache operations
272 */
273
274#ifdef CONFIG_NETLABEL
275void netlbl_cache_invalidate(void);
276int netlbl_cache_add(const struct sk_buff *skb,
277 const struct netlbl_lsm_secattr *secattr);
278#else
279static inline void netlbl_cache_invalidate(void)
280{
281 return;
282}
283
284static inline int netlbl_cache_add(const struct sk_buff *skb,
285 const struct netlbl_lsm_secattr *secattr)
286{
287 return 0;
288}
289#endif /* CONFIG_NETLABEL */
290
291#endif /* _NETLABEL_H */