1cb72d382SHuw Davies /*
2cb72d382SHuw Davies  * NetLabel CALIPSO Support
3cb72d382SHuw Davies  *
4cb72d382SHuw Davies  * This file defines the CALIPSO functions for the NetLabel system.  The
5cb72d382SHuw Davies  * NetLabel system manages static and dynamic label mappings for network
6cb72d382SHuw Davies  * protocols such as CIPSO and RIPSO.
7cb72d382SHuw Davies  *
8cb72d382SHuw Davies  * Authors: Paul Moore <paul@paul-moore.com>
9cb72d382SHuw Davies  *          Huw Davies <huw@codeweavers.com>
10cb72d382SHuw Davies  *
11cb72d382SHuw Davies  */
12cb72d382SHuw Davies 
13cb72d382SHuw Davies /* (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14cb72d382SHuw Davies  * (c) Copyright Huw Davies <huw@codeweavers.com>, 2015
15cb72d382SHuw Davies  *
16cb72d382SHuw Davies  * This program is free software;  you can redistribute it and/or modify
17cb72d382SHuw Davies  * it under the terms of the GNU General Public License as published by
18cb72d382SHuw Davies  * the Free Software Foundation; either version 2 of the License, or
19cb72d382SHuw Davies  * (at your option) any later version.
20cb72d382SHuw Davies  *
21cb72d382SHuw Davies  * This program is distributed in the hope that it will be useful,
22cb72d382SHuw Davies  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
23cb72d382SHuw Davies  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
24cb72d382SHuw Davies  * the GNU General Public License for more details.
25cb72d382SHuw Davies  *
26cb72d382SHuw Davies  * You should have received a copy of the GNU General Public License
27cb72d382SHuw Davies  * along with this program;  if not, see <http://www.gnu.org/licenses/>.
28cb72d382SHuw Davies  *
29cb72d382SHuw Davies  */
30cb72d382SHuw Davies 
31cb72d382SHuw Davies #ifndef _NETLABEL_CALIPSO
32cb72d382SHuw Davies #define _NETLABEL_CALIPSO
33cb72d382SHuw Davies 
34cb72d382SHuw Davies #include <net/netlabel.h>
35cb72d382SHuw Davies #include <net/calipso.h>
36cb72d382SHuw Davies 
37cb72d382SHuw Davies /* The following NetLabel payloads are supported by the CALIPSO subsystem.
38cb72d382SHuw Davies  *
39cb72d382SHuw Davies  * o ADD:
40cb72d382SHuw Davies  *   Sent by an application to add a new DOI mapping table.
41cb72d382SHuw Davies  *
42cb72d382SHuw Davies  *   Required attributes:
43cb72d382SHuw Davies  *
44cb72d382SHuw Davies  *     NLBL_CALIPSO_A_DOI
45cb72d382SHuw Davies  *     NLBL_CALIPSO_A_MTYPE
46cb72d382SHuw Davies  *
47cb72d382SHuw Davies  *   If using CALIPSO_MAP_PASS no additional attributes are required.
48cb72d382SHuw Davies  *
49d7cce015SHuw Davies  * o REMOVE:
50d7cce015SHuw Davies  *   Sent by an application to remove a specific DOI mapping table from the
51d7cce015SHuw Davies  *   CALIPSO system.
52d7cce015SHuw Davies  *
53d7cce015SHuw Davies  *   Required attributes:
54d7cce015SHuw Davies  *
55d7cce015SHuw Davies  *     NLBL_CALIPSO_A_DOI
56d7cce015SHuw Davies  *
57a5e34490SHuw Davies  * o LIST:
58a5e34490SHuw Davies  *   Sent by an application to list the details of a DOI definition.  On
59a5e34490SHuw Davies  *   success the kernel should send a response using the following format.
60a5e34490SHuw Davies  *
61a5e34490SHuw Davies  *   Required attributes:
62a5e34490SHuw Davies  *
63a5e34490SHuw Davies  *     NLBL_CALIPSO_A_DOI
64a5e34490SHuw Davies  *
65a5e34490SHuw Davies  *   The valid response message format depends on the type of the DOI mapping,
66a5e34490SHuw Davies  *   the defined formats are shown below.
67a5e34490SHuw Davies  *
68a5e34490SHuw Davies  *   Required attributes:
69a5e34490SHuw Davies  *
70a5e34490SHuw Davies  *     NLBL_CALIPSO_A_MTYPE
71a5e34490SHuw Davies  *
72a5e34490SHuw Davies  *   If using CALIPSO_MAP_PASS no additional attributes are required.
73a5e34490SHuw Davies  *
74e1ce69dfSHuw Davies  * o LISTALL:
75e1ce69dfSHuw Davies  *   This message is sent by an application to list the valid DOIs on the
76e1ce69dfSHuw Davies  *   system.  When sent by an application there is no payload and the
77e1ce69dfSHuw Davies  *   NLM_F_DUMP flag should be set.  The kernel should respond with a series of
78e1ce69dfSHuw Davies  *   the following messages.
79e1ce69dfSHuw Davies  *
80e1ce69dfSHuw Davies  *   Required attributes:
81e1ce69dfSHuw Davies  *
82e1ce69dfSHuw Davies  *    NLBL_CALIPSO_A_DOI
83e1ce69dfSHuw Davies  *    NLBL_CALIPSO_A_MTYPE
84e1ce69dfSHuw Davies  *
85cb72d382SHuw Davies  */
86cb72d382SHuw Davies 
87cb72d382SHuw Davies /* NetLabel CALIPSO commands */
88cb72d382SHuw Davies enum {
89cb72d382SHuw Davies 	NLBL_CALIPSO_C_UNSPEC,
90cb72d382SHuw Davies 	NLBL_CALIPSO_C_ADD,
91cb72d382SHuw Davies 	NLBL_CALIPSO_C_REMOVE,
92cb72d382SHuw Davies 	NLBL_CALIPSO_C_LIST,
93cb72d382SHuw Davies 	NLBL_CALIPSO_C_LISTALL,
94cb72d382SHuw Davies 	__NLBL_CALIPSO_C_MAX,
95cb72d382SHuw Davies };
96cb72d382SHuw Davies 
97cb72d382SHuw Davies /* NetLabel CALIPSO attributes */
98cb72d382SHuw Davies enum {
99cb72d382SHuw Davies 	NLBL_CALIPSO_A_UNSPEC,
100cb72d382SHuw Davies 	NLBL_CALIPSO_A_DOI,
101cb72d382SHuw Davies 	/* (NLA_U32)
102cb72d382SHuw Davies 	 * the DOI value */
103cb72d382SHuw Davies 	NLBL_CALIPSO_A_MTYPE,
104cb72d382SHuw Davies 	/* (NLA_U32)
105cb72d382SHuw Davies 	 * the mapping table type (defined in the calipso.h header as
106cb72d382SHuw Davies 	 * CALIPSO_MAP_*) */
107cb72d382SHuw Davies 	__NLBL_CALIPSO_A_MAX,
108cb72d382SHuw Davies };
109cb72d382SHuw Davies 
110cb72d382SHuw Davies #define NLBL_CALIPSO_A_MAX (__NLBL_CALIPSO_A_MAX - 1)
111cb72d382SHuw Davies 
112cb72d382SHuw Davies /* NetLabel protocol functions */
113cb72d382SHuw Davies #if IS_ENABLED(CONFIG_IPV6)
114cb72d382SHuw Davies int netlbl_calipso_genl_init(void);
115cb72d382SHuw Davies #else
116cb72d382SHuw Davies static inline int netlbl_calipso_genl_init(void)
117cb72d382SHuw Davies {
118cb72d382SHuw Davies 	return 0;
119cb72d382SHuw Davies }
120cb72d382SHuw Davies #endif
121cb72d382SHuw Davies 
122cb72d382SHuw Davies int calipso_doi_add(struct calipso_doi *doi_def,
123cb72d382SHuw Davies 		    struct netlbl_audit *audit_info);
124cb72d382SHuw Davies void calipso_doi_free(struct calipso_doi *doi_def);
125d7cce015SHuw Davies int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info);
126a5e34490SHuw Davies struct calipso_doi *calipso_doi_getdef(u32 doi);
127a5e34490SHuw Davies void calipso_doi_putdef(struct calipso_doi *doi_def);
128e1ce69dfSHuw Davies int calipso_doi_walk(u32 *skip_cnt,
129e1ce69dfSHuw Davies 		     int (*callback)(struct calipso_doi *doi_def, void *arg),
130e1ce69dfSHuw Davies 		     void *cb_arg);
131ceba1832SHuw Davies int calipso_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr);
132ceba1832SHuw Davies int calipso_sock_setattr(struct sock *sk,
133ceba1832SHuw Davies 			 const struct calipso_doi *doi_def,
134ceba1832SHuw Davies 			 const struct netlbl_lsm_secattr *secattr);
135ceba1832SHuw Davies void calipso_sock_delattr(struct sock *sk);
136e1adea92SHuw Davies int calipso_req_setattr(struct request_sock *req,
137e1adea92SHuw Davies 			const struct calipso_doi *doi_def,
138e1adea92SHuw Davies 			const struct netlbl_lsm_secattr *secattr);
139e1adea92SHuw Davies void calipso_req_delattr(struct request_sock *req);
140cb72d382SHuw Davies 
141cb72d382SHuw Davies #endif
142