blob: f85d0e07af2dd9c7f4f4fb2f6b05fcf99b21c8eb [file] [log] [blame]
Paul Moored15c3452006-08-03 16:48:37 -07001/*
2 * NetLabel Management Support
3 *
4 * This file defines the management functions for the NetLabel system. The
5 * NetLabel system manages static and dynamic label mappings for network
6 * protocols such as CIPSO and RIPSO.
7 *
Paul Moore82c21bf2011-08-01 11:10:33 +00008 * Author: Paul Moore <paul@paul-moore.com>
Paul Moored15c3452006-08-03 16:48:37 -07009 *
10 */
11
12/*
Paul Moore63c41682008-10-10 10:16:32 -040013 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
Paul Moored15c3452006-08-03 16:48:37 -070014 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
23 * the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
Jeff Kirsherd484ff12013-12-06 09:13:41 -080026 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Paul Moored15c3452006-08-03 16:48:37 -070027 *
28 */
29
30#include <linux/types.h>
31#include <linux/socket.h>
32#include <linux/string.h>
33#include <linux/skbuff.h>
Paul Moore63c41682008-10-10 10:16:32 -040034#include <linux/in.h>
35#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Paul Moored15c3452006-08-03 16:48:37 -070037#include <net/sock.h>
38#include <net/netlink.h>
39#include <net/genetlink.h>
Paul Moore63c41682008-10-10 10:16:32 -040040#include <net/ip.h>
41#include <net/ipv6.h>
Paul Moored15c3452006-08-03 16:48:37 -070042#include <net/netlabel.h>
43#include <net/cipso_ipv4.h>
Huw Daviesdc7de732016-06-27 15:02:49 -040044#include <net/calipso.h>
Arun Sharma600634972011-07-26 16:09:06 -070045#include <linux/atomic.h>
Paul Moored15c3452006-08-03 16:48:37 -070046
Huw Daviesdc7de732016-06-27 15:02:49 -040047#include "netlabel_calipso.h"
Paul Moored15c3452006-08-03 16:48:37 -070048#include "netlabel_domainhash.h"
49#include "netlabel_user.h"
50#include "netlabel_mgmt.h"
51
Paul Moorec783f1c2008-01-29 08:37:52 -050052/* NetLabel configured protocol counter */
53atomic_t netlabel_mgmt_protocount = ATOMIC_INIT(0);
Paul Moore23bcdc12007-07-18 12:28:45 -040054
Paul Moorefd385852006-09-25 15:56:37 -070055/* Argument struct for netlbl_domhsh_walk() */
56struct netlbl_domhsh_walk_arg {
57 struct netlink_callback *nl_cb;
58 struct sk_buff *skb;
59 u32 seq;
60};
61
Paul Moored15c3452006-08-03 16:48:37 -070062/* NetLabel Generic NETLINK CIPSOv4 family */
63static struct genl_family netlbl_mgmt_gnl_family = {
64 .id = GENL_ID_GENERATE,
65 .hdrsize = 0,
66 .name = NETLBL_NLTYPE_MGMT_NAME,
67 .version = NETLBL_PROTO_VERSION,
Paul Moorefd385852006-09-25 15:56:37 -070068 .maxattr = NLBL_MGMT_A_MAX,
Paul Moored15c3452006-08-03 16:48:37 -070069};
70
Paul Moorefd385852006-09-25 15:56:37 -070071/* NetLabel Netlink attribute policy */
Patrick McHardyef7c79e2007-06-05 12:38:30 -070072static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = {
Paul Moorefd385852006-09-25 15:56:37 -070073 [NLBL_MGMT_A_DOMAIN] = { .type = NLA_NUL_STRING },
74 [NLBL_MGMT_A_PROTOCOL] = { .type = NLA_U32 },
75 [NLBL_MGMT_A_VERSION] = { .type = NLA_U32 },
76 [NLBL_MGMT_A_CV4DOI] = { .type = NLA_U32 },
Huw Davies8f18e672016-06-27 15:02:46 -040077 [NLBL_MGMT_A_FAMILY] = { .type = NLA_U16 },
Huw Daviesdc7de732016-06-27 15:02:49 -040078 [NLBL_MGMT_A_CLPDOI] = { .type = NLA_U32 },
Paul Moorefd385852006-09-25 15:56:37 -070079};
Paul Moored15c3452006-08-03 16:48:37 -070080
81/*
Paul Moore63c41682008-10-10 10:16:32 -040082 * Helper Functions
83 */
84
85/**
86 * netlbl_mgmt_add - Handle an ADD message
87 * @info: the Generic NETLINK info block
88 * @audit_info: NetLabel audit information
89 *
90 * Description:
91 * Helper function for the ADD and ADDDEF messages to add the domain mappings
92 * from the message to the hash table. See netlabel.h for a description of the
93 * message format. Returns zero on success, negative values on failure.
94 *
95 */
96static int netlbl_mgmt_add_common(struct genl_info *info,
97 struct netlbl_audit *audit_info)
98{
99 int ret_val = -EINVAL;
Paul Moore63c41682008-10-10 10:16:32 -0400100 struct netlbl_domaddr_map *addrmap = NULL;
101 struct cipso_v4_doi *cipsov4 = NULL;
Huw Daviesdc7de732016-06-27 15:02:49 -0400102#if IS_ENABLED(CONFIG_IPV6)
103 struct calipso_doi *calipso = NULL;
104#endif
Paul Moore63c41682008-10-10 10:16:32 -0400105 u32 tmp_val;
Markus Elfring4de46d52015-02-02 11:00:24 +0100106 struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
Paul Moore63c41682008-10-10 10:16:32 -0400107
Markus Elfring4de46d52015-02-02 11:00:24 +0100108 if (!entry)
109 return -ENOMEM;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400110 entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
Paul Moore63c41682008-10-10 10:16:32 -0400111 if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
112 size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
113 entry->domain = kmalloc(tmp_size, GFP_KERNEL);
114 if (entry->domain == NULL) {
115 ret_val = -ENOMEM;
Markus Elfring4de46d52015-02-02 11:00:24 +0100116 goto add_free_entry;
Paul Moore63c41682008-10-10 10:16:32 -0400117 }
118 nla_strlcpy(entry->domain,
119 info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
120 }
121
Paul Moore6a8b7f02013-08-02 14:45:08 -0400122 /* NOTE: internally we allow/use a entry->def.type value of
Paul Moore63c41682008-10-10 10:16:32 -0400123 * NETLBL_NLTYPE_ADDRSELECT but we don't currently allow users
124 * to pass that as a protocol value because we need to know the
125 * "real" protocol */
126
Paul Moore6a8b7f02013-08-02 14:45:08 -0400127 switch (entry->def.type) {
Paul Moore63c41682008-10-10 10:16:32 -0400128 case NETLBL_NLTYPE_UNLABELED:
Huw Davies8f18e672016-06-27 15:02:46 -0400129 if (info->attrs[NLBL_MGMT_A_FAMILY])
130 entry->family =
131 nla_get_u16(info->attrs[NLBL_MGMT_A_FAMILY]);
132 else
133 entry->family = AF_UNSPEC;
Paul Moore63c41682008-10-10 10:16:32 -0400134 break;
135 case NETLBL_NLTYPE_CIPSOV4:
136 if (!info->attrs[NLBL_MGMT_A_CV4DOI])
Markus Elfring4de46d52015-02-02 11:00:24 +0100137 goto add_free_domain;
Paul Moore63c41682008-10-10 10:16:32 -0400138
139 tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
140 cipsov4 = cipso_v4_doi_getdef(tmp_val);
141 if (cipsov4 == NULL)
Markus Elfring4de46d52015-02-02 11:00:24 +0100142 goto add_free_domain;
Huw Davies8f18e672016-06-27 15:02:46 -0400143 entry->family = AF_INET;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400144 entry->def.cipso = cipsov4;
Paul Moore63c41682008-10-10 10:16:32 -0400145 break;
Huw Daviesdc7de732016-06-27 15:02:49 -0400146#if IS_ENABLED(CONFIG_IPV6)
147 case NETLBL_NLTYPE_CALIPSO:
148 if (!info->attrs[NLBL_MGMT_A_CLPDOI])
149 goto add_free_domain;
150
151 tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CLPDOI]);
152 calipso = calipso_doi_getdef(tmp_val);
153 if (calipso == NULL)
154 goto add_free_domain;
155 entry->family = AF_INET6;
156 entry->def.calipso = calipso;
157 break;
158#endif /* IPv6 */
Paul Moore63c41682008-10-10 10:16:32 -0400159 default:
Markus Elfring4de46d52015-02-02 11:00:24 +0100160 goto add_free_domain;
Paul Moore63c41682008-10-10 10:16:32 -0400161 }
162
Huw Davies8f18e672016-06-27 15:02:46 -0400163 if ((entry->family == AF_INET && info->attrs[NLBL_MGMT_A_IPV6ADDR]) ||
164 (entry->family == AF_INET6 && info->attrs[NLBL_MGMT_A_IPV4ADDR]))
165 goto add_doi_put_def;
166
Paul Moore63c41682008-10-10 10:16:32 -0400167 if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
168 struct in_addr *addr;
169 struct in_addr *mask;
170 struct netlbl_domaddr4_map *map;
171
172 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
173 if (addrmap == NULL) {
174 ret_val = -ENOMEM;
Markus Elfring4de46d52015-02-02 11:00:24 +0100175 goto add_doi_put_def;
Paul Moore63c41682008-10-10 10:16:32 -0400176 }
177 INIT_LIST_HEAD(&addrmap->list4);
178 INIT_LIST_HEAD(&addrmap->list6);
179
180 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) !=
181 sizeof(struct in_addr)) {
182 ret_val = -EINVAL;
Markus Elfring4de46d52015-02-02 11:00:24 +0100183 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400184 }
185 if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) !=
186 sizeof(struct in_addr)) {
187 ret_val = -EINVAL;
Markus Elfring4de46d52015-02-02 11:00:24 +0100188 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400189 }
190 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
191 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
192
193 map = kzalloc(sizeof(*map), GFP_KERNEL);
194 if (map == NULL) {
195 ret_val = -ENOMEM;
Markus Elfring4de46d52015-02-02 11:00:24 +0100196 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400197 }
198 map->list.addr = addr->s_addr & mask->s_addr;
199 map->list.mask = mask->s_addr;
200 map->list.valid = 1;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400201 map->def.type = entry->def.type;
Paul Moore63c41682008-10-10 10:16:32 -0400202 if (cipsov4)
Paul Moore6a8b7f02013-08-02 14:45:08 -0400203 map->def.cipso = cipsov4;
Paul Moore63c41682008-10-10 10:16:32 -0400204
205 ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
206 if (ret_val != 0) {
207 kfree(map);
Markus Elfring4de46d52015-02-02 11:00:24 +0100208 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400209 }
210
Huw Davies8f18e672016-06-27 15:02:46 -0400211 entry->family = AF_INET;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400212 entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
213 entry->def.addrsel = addrmap;
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000214#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400215 } else if (info->attrs[NLBL_MGMT_A_IPV6ADDR]) {
216 struct in6_addr *addr;
217 struct in6_addr *mask;
218 struct netlbl_domaddr6_map *map;
219
220 addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
221 if (addrmap == NULL) {
222 ret_val = -ENOMEM;
Markus Elfring4de46d52015-02-02 11:00:24 +0100223 goto add_doi_put_def;
Paul Moore63c41682008-10-10 10:16:32 -0400224 }
225 INIT_LIST_HEAD(&addrmap->list4);
226 INIT_LIST_HEAD(&addrmap->list6);
227
228 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) !=
229 sizeof(struct in6_addr)) {
230 ret_val = -EINVAL;
Markus Elfring4de46d52015-02-02 11:00:24 +0100231 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400232 }
233 if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) !=
234 sizeof(struct in6_addr)) {
235 ret_val = -EINVAL;
Markus Elfring4de46d52015-02-02 11:00:24 +0100236 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400237 }
238 addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
239 mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
240
241 map = kzalloc(sizeof(*map), GFP_KERNEL);
242 if (map == NULL) {
243 ret_val = -ENOMEM;
Markus Elfring4de46d52015-02-02 11:00:24 +0100244 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400245 }
Alexey Dobriyan4e3fd7a2011-11-21 03:39:03 +0000246 map->list.addr = *addr;
Paul Moore63c41682008-10-10 10:16:32 -0400247 map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
248 map->list.addr.s6_addr32[1] &= mask->s6_addr32[1];
249 map->list.addr.s6_addr32[2] &= mask->s6_addr32[2];
250 map->list.addr.s6_addr32[3] &= mask->s6_addr32[3];
Alexey Dobriyan4e3fd7a2011-11-21 03:39:03 +0000251 map->list.mask = *mask;
Paul Moore63c41682008-10-10 10:16:32 -0400252 map->list.valid = 1;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400253 map->def.type = entry->def.type;
Huw Daviesdc7de732016-06-27 15:02:49 -0400254 if (calipso)
255 map->def.calipso = calipso;
Paul Moore63c41682008-10-10 10:16:32 -0400256
257 ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
258 if (ret_val != 0) {
259 kfree(map);
Markus Elfring4de46d52015-02-02 11:00:24 +0100260 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400261 }
262
Huw Davies8f18e672016-06-27 15:02:46 -0400263 entry->family = AF_INET6;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400264 entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
265 entry->def.addrsel = addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400266#endif /* IPv6 */
267 }
268
269 ret_val = netlbl_domhsh_add(entry, audit_info);
270 if (ret_val != 0)
Markus Elfring4de46d52015-02-02 11:00:24 +0100271 goto add_free_addrmap;
Paul Moore63c41682008-10-10 10:16:32 -0400272
273 return 0;
274
Markus Elfring4de46d52015-02-02 11:00:24 +0100275add_free_addrmap:
Paul Moore63c41682008-10-10 10:16:32 -0400276 kfree(addrmap);
Markus Elfring4de46d52015-02-02 11:00:24 +0100277add_doi_put_def:
278 cipso_v4_doi_putdef(cipsov4);
Huw Daviesdc7de732016-06-27 15:02:49 -0400279#if IS_ENABLED(CONFIG_IPV6)
280 calipso_doi_putdef(calipso);
281#endif
Markus Elfring4de46d52015-02-02 11:00:24 +0100282add_free_domain:
283 kfree(entry->domain);
284add_free_entry:
Paul Moore63c41682008-10-10 10:16:32 -0400285 kfree(entry);
286 return ret_val;
287}
288
289/**
290 * netlbl_mgmt_listentry - List a NetLabel/LSM domain map entry
291 * @skb: the NETLINK buffer
292 * @entry: the map entry
293 *
294 * Description:
295 * This function is a helper function used by the LISTALL and LISTDEF command
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300296 * handlers. The caller is responsible for ensuring that the RCU read lock
Paul Moore63c41682008-10-10 10:16:32 -0400297 * is held. Returns zero on success, negative values on failure.
298 *
299 */
300static int netlbl_mgmt_listentry(struct sk_buff *skb,
301 struct netlbl_dom_map *entry)
302{
Paul Mooref8a02472008-10-29 16:09:12 -0400303 int ret_val = 0;
Paul Moore63c41682008-10-10 10:16:32 -0400304 struct nlattr *nla_a;
305 struct nlattr *nla_b;
306 struct netlbl_af4list *iter4;
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000307#if IS_ENABLED(CONFIG_IPV6)
Paul Moore63c41682008-10-10 10:16:32 -0400308 struct netlbl_af6list *iter6;
309#endif
310
311 if (entry->domain != NULL) {
312 ret_val = nla_put_string(skb,
313 NLBL_MGMT_A_DOMAIN, entry->domain);
314 if (ret_val != 0)
315 return ret_val;
316 }
317
Huw Davies8f18e672016-06-27 15:02:46 -0400318 ret_val = nla_put_u16(skb, NLBL_MGMT_A_FAMILY, entry->family);
319 if (ret_val != 0)
320 return ret_val;
321
Paul Moore6a8b7f02013-08-02 14:45:08 -0400322 switch (entry->def.type) {
Paul Moore63c41682008-10-10 10:16:32 -0400323 case NETLBL_NLTYPE_ADDRSELECT:
324 nla_a = nla_nest_start(skb, NLBL_MGMT_A_SELECTORLIST);
325 if (nla_a == NULL)
326 return -ENOMEM;
327
Paul Moore6a8b7f02013-08-02 14:45:08 -0400328 netlbl_af4list_foreach_rcu(iter4, &entry->def.addrsel->list4) {
Paul Moore63c41682008-10-10 10:16:32 -0400329 struct netlbl_domaddr4_map *map4;
330 struct in_addr addr_struct;
331
332 nla_b = nla_nest_start(skb, NLBL_MGMT_A_ADDRSELECTOR);
333 if (nla_b == NULL)
334 return -ENOMEM;
335
336 addr_struct.s_addr = iter4->addr;
Jiri Benc930345e2015-03-29 16:59:25 +0200337 ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4ADDR,
338 addr_struct.s_addr);
Paul Moore63c41682008-10-10 10:16:32 -0400339 if (ret_val != 0)
340 return ret_val;
341 addr_struct.s_addr = iter4->mask;
Jiri Benc930345e2015-03-29 16:59:25 +0200342 ret_val = nla_put_in_addr(skb, NLBL_MGMT_A_IPV4MASK,
343 addr_struct.s_addr);
Paul Moore63c41682008-10-10 10:16:32 -0400344 if (ret_val != 0)
345 return ret_val;
346 map4 = netlbl_domhsh_addr4_entry(iter4);
347 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400348 map4->def.type);
Paul Moore63c41682008-10-10 10:16:32 -0400349 if (ret_val != 0)
350 return ret_val;
Paul Moore6a8b7f02013-08-02 14:45:08 -0400351 switch (map4->def.type) {
Paul Moore63c41682008-10-10 10:16:32 -0400352 case NETLBL_NLTYPE_CIPSOV4:
353 ret_val = nla_put_u32(skb, NLBL_MGMT_A_CV4DOI,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400354 map4->def.cipso->doi);
Paul Moore63c41682008-10-10 10:16:32 -0400355 if (ret_val != 0)
356 return ret_val;
357 break;
358 }
359
360 nla_nest_end(skb, nla_b);
361 }
Eric Dumazetdfd56b82011-12-10 09:48:31 +0000362#if IS_ENABLED(CONFIG_IPV6)
Paul Moore6a8b7f02013-08-02 14:45:08 -0400363 netlbl_af6list_foreach_rcu(iter6, &entry->def.addrsel->list6) {
Paul Moore63c41682008-10-10 10:16:32 -0400364 struct netlbl_domaddr6_map *map6;
365
366 nla_b = nla_nest_start(skb, NLBL_MGMT_A_ADDRSELECTOR);
367 if (nla_b == NULL)
368 return -ENOMEM;
369
Jiri Benc930345e2015-03-29 16:59:25 +0200370 ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6ADDR,
371 &iter6->addr);
Paul Moore63c41682008-10-10 10:16:32 -0400372 if (ret_val != 0)
373 return ret_val;
Jiri Benc930345e2015-03-29 16:59:25 +0200374 ret_val = nla_put_in6_addr(skb, NLBL_MGMT_A_IPV6MASK,
375 &iter6->mask);
Paul Moore63c41682008-10-10 10:16:32 -0400376 if (ret_val != 0)
377 return ret_val;
378 map6 = netlbl_domhsh_addr6_entry(iter6);
379 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400380 map6->def.type);
Paul Moore63c41682008-10-10 10:16:32 -0400381 if (ret_val != 0)
382 return ret_val;
383
Huw Daviesdc7de732016-06-27 15:02:49 -0400384 switch (map6->def.type) {
385 case NETLBL_NLTYPE_CALIPSO:
386 ret_val = nla_put_u32(skb, NLBL_MGMT_A_CLPDOI,
387 map6->def.calipso->doi);
388 if (ret_val != 0)
389 return ret_val;
390 break;
391 }
392
Paul Moore63c41682008-10-10 10:16:32 -0400393 nla_nest_end(skb, nla_b);
394 }
395#endif /* IPv6 */
396
397 nla_nest_end(skb, nla_a);
398 break;
399 case NETLBL_NLTYPE_UNLABELED:
Huw Daviesdc7de732016-06-27 15:02:49 -0400400 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL,
401 entry->def.type);
Paul Moore63c41682008-10-10 10:16:32 -0400402 break;
403 case NETLBL_NLTYPE_CIPSOV4:
Huw Daviesdc7de732016-06-27 15:02:49 -0400404 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL,
405 entry->def.type);
Paul Moore63c41682008-10-10 10:16:32 -0400406 if (ret_val != 0)
407 return ret_val;
408 ret_val = nla_put_u32(skb, NLBL_MGMT_A_CV4DOI,
Paul Moore6a8b7f02013-08-02 14:45:08 -0400409 entry->def.cipso->doi);
Paul Moore63c41682008-10-10 10:16:32 -0400410 break;
Huw Daviesdc7de732016-06-27 15:02:49 -0400411 case NETLBL_NLTYPE_CALIPSO:
412 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL,
413 entry->def.type);
414 if (ret_val != 0)
415 return ret_val;
416 ret_val = nla_put_u32(skb, NLBL_MGMT_A_CLPDOI,
417 entry->def.calipso->doi);
418 break;
Paul Moore63c41682008-10-10 10:16:32 -0400419 }
420
421 return ret_val;
422}
423
424/*
Paul Moored15c3452006-08-03 16:48:37 -0700425 * NetLabel Command Handlers
426 */
427
428/**
429 * netlbl_mgmt_add - Handle an ADD message
430 * @skb: the NETLINK buffer
431 * @info: the Generic NETLINK info block
432 *
433 * Description:
434 * Process a user generated ADD message and add the domains from the message
435 * to the hash table. See netlabel.h for a description of the message format.
436 * Returns zero on success, negative values on failure.
437 *
438 */
439static int netlbl_mgmt_add(struct sk_buff *skb, struct genl_info *info)
440{
Paul Moore95d4e6b2006-09-29 17:05:05 -0700441 struct netlbl_audit audit_info;
Paul Moored15c3452006-08-03 16:48:37 -0700442
Paul Moore63c41682008-10-10 10:16:32 -0400443 if ((!info->attrs[NLBL_MGMT_A_DOMAIN]) ||
444 (!info->attrs[NLBL_MGMT_A_PROTOCOL]) ||
445 (info->attrs[NLBL_MGMT_A_IPV4ADDR] &&
446 info->attrs[NLBL_MGMT_A_IPV6ADDR]) ||
447 (info->attrs[NLBL_MGMT_A_IPV4MASK] &&
448 info->attrs[NLBL_MGMT_A_IPV6MASK]) ||
449 ((info->attrs[NLBL_MGMT_A_IPV4ADDR] != NULL) ^
450 (info->attrs[NLBL_MGMT_A_IPV4MASK] != NULL)) ||
451 ((info->attrs[NLBL_MGMT_A_IPV6ADDR] != NULL) ^
452 (info->attrs[NLBL_MGMT_A_IPV6MASK] != NULL)))
453 return -EINVAL;
Paul Moorefd385852006-09-25 15:56:37 -0700454
Paul Moore95d4e6b2006-09-29 17:05:05 -0700455 netlbl_netlink_auditinfo(skb, &audit_info);
456
Paul Moore63c41682008-10-10 10:16:32 -0400457 return netlbl_mgmt_add_common(info, &audit_info);
Paul Moored15c3452006-08-03 16:48:37 -0700458}
459
460/**
461 * netlbl_mgmt_remove - Handle a REMOVE message
462 * @skb: the NETLINK buffer
463 * @info: the Generic NETLINK info block
464 *
465 * Description:
466 * Process a user generated REMOVE message and remove the specified domain
467 * mappings. Returns zero on success, negative values on failure.
468 *
469 */
470static int netlbl_mgmt_remove(struct sk_buff *skb, struct genl_info *info)
471{
Paul Moorefd385852006-09-25 15:56:37 -0700472 char *domain;
Paul Moore95d4e6b2006-09-29 17:05:05 -0700473 struct netlbl_audit audit_info;
Paul Moored15c3452006-08-03 16:48:37 -0700474
Paul Moorefd385852006-09-25 15:56:37 -0700475 if (!info->attrs[NLBL_MGMT_A_DOMAIN])
476 return -EINVAL;
477
Paul Moore95d4e6b2006-09-29 17:05:05 -0700478 netlbl_netlink_auditinfo(skb, &audit_info);
479
Paul Moorefd385852006-09-25 15:56:37 -0700480 domain = nla_data(info->attrs[NLBL_MGMT_A_DOMAIN]);
Huw Davies8f18e672016-06-27 15:02:46 -0400481 return netlbl_domhsh_remove(domain, AF_UNSPEC, &audit_info);
Paul Moorefd385852006-09-25 15:56:37 -0700482}
483
484/**
485 * netlbl_mgmt_listall_cb - netlbl_domhsh_walk() callback for LISTALL
486 * @entry: the domain mapping hash table entry
487 * @arg: the netlbl_domhsh_walk_arg structure
488 *
489 * Description:
490 * This function is designed to be used as a callback to the
491 * netlbl_domhsh_walk() function for use in generating a response for a LISTALL
492 * message. Returns the size of the message on success, negative values on
493 * failure.
494 *
495 */
496static int netlbl_mgmt_listall_cb(struct netlbl_dom_map *entry, void *arg)
497{
498 int ret_val = -ENOMEM;
499 struct netlbl_domhsh_walk_arg *cb_arg = arg;
500 void *data;
501
Eric W. Biederman15e47302012-09-07 20:12:54 +0000502 data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid,
Thomas Graf17c157c2006-11-14 19:46:02 -0800503 cb_arg->seq, &netlbl_mgmt_gnl_family,
504 NLM_F_MULTI, NLBL_MGMT_C_LISTALL);
Paul Moorefd385852006-09-25 15:56:37 -0700505 if (data == NULL)
506 goto listall_cb_failure;
507
Paul Moore63c41682008-10-10 10:16:32 -0400508 ret_val = netlbl_mgmt_listentry(cb_arg->skb, entry);
Paul Moored15c3452006-08-03 16:48:37 -0700509 if (ret_val != 0)
Paul Moorefd385852006-09-25 15:56:37 -0700510 goto listall_cb_failure;
Paul Moored15c3452006-08-03 16:48:37 -0700511
Paul Moorefd385852006-09-25 15:56:37 -0700512 cb_arg->seq++;
Johannes Berg053c0952015-01-16 22:09:00 +0100513 genlmsg_end(cb_arg->skb, data);
514 return 0;
Paul Moored15c3452006-08-03 16:48:37 -0700515
Paul Moorefd385852006-09-25 15:56:37 -0700516listall_cb_failure:
517 genlmsg_cancel(cb_arg->skb, data);
Paul Moored15c3452006-08-03 16:48:37 -0700518 return ret_val;
519}
520
521/**
Paul Moorefd385852006-09-25 15:56:37 -0700522 * netlbl_mgmt_listall - Handle a LISTALL message
Paul Moored15c3452006-08-03 16:48:37 -0700523 * @skb: the NETLINK buffer
Paul Moorefd385852006-09-25 15:56:37 -0700524 * @cb: the NETLINK callback
Paul Moored15c3452006-08-03 16:48:37 -0700525 *
526 * Description:
Paul Moorefd385852006-09-25 15:56:37 -0700527 * Process a user generated LISTALL message and dumps the domain hash table in
528 * a form suitable for use in a kernel generated LISTALL message. Returns zero
529 * on success, negative values on failure.
Paul Moored15c3452006-08-03 16:48:37 -0700530 *
531 */
Paul Moorefd385852006-09-25 15:56:37 -0700532static int netlbl_mgmt_listall(struct sk_buff *skb,
533 struct netlink_callback *cb)
Paul Moored15c3452006-08-03 16:48:37 -0700534{
Paul Moorefd385852006-09-25 15:56:37 -0700535 struct netlbl_domhsh_walk_arg cb_arg;
536 u32 skip_bkt = cb->args[0];
537 u32 skip_chain = cb->args[1];
Paul Moored15c3452006-08-03 16:48:37 -0700538
Paul Moorefd385852006-09-25 15:56:37 -0700539 cb_arg.nl_cb = cb;
540 cb_arg.skb = skb;
541 cb_arg.seq = cb->nlh->nlmsg_seq;
Paul Moored15c3452006-08-03 16:48:37 -0700542
Paul Moorefd385852006-09-25 15:56:37 -0700543 netlbl_domhsh_walk(&skip_bkt,
544 &skip_chain,
545 netlbl_mgmt_listall_cb,
546 &cb_arg);
Paul Moored15c3452006-08-03 16:48:37 -0700547
Paul Moorefd385852006-09-25 15:56:37 -0700548 cb->args[0] = skip_bkt;
549 cb->args[1] = skip_chain;
550 return skb->len;
Paul Moored15c3452006-08-03 16:48:37 -0700551}
552
553/**
554 * netlbl_mgmt_adddef - Handle an ADDDEF message
555 * @skb: the NETLINK buffer
556 * @info: the Generic NETLINK info block
557 *
558 * Description:
559 * Process a user generated ADDDEF message and respond accordingly. Returns
560 * zero on success, negative values on failure.
561 *
562 */
563static int netlbl_mgmt_adddef(struct sk_buff *skb, struct genl_info *info)
564{
Paul Moore95d4e6b2006-09-29 17:05:05 -0700565 struct netlbl_audit audit_info;
Paul Moored15c3452006-08-03 16:48:37 -0700566
Paul Moore63c41682008-10-10 10:16:32 -0400567 if ((!info->attrs[NLBL_MGMT_A_PROTOCOL]) ||
568 (info->attrs[NLBL_MGMT_A_IPV4ADDR] &&
569 info->attrs[NLBL_MGMT_A_IPV6ADDR]) ||
570 (info->attrs[NLBL_MGMT_A_IPV4MASK] &&
571 info->attrs[NLBL_MGMT_A_IPV6MASK]) ||
572 ((info->attrs[NLBL_MGMT_A_IPV4ADDR] != NULL) ^
573 (info->attrs[NLBL_MGMT_A_IPV4MASK] != NULL)) ||
574 ((info->attrs[NLBL_MGMT_A_IPV6ADDR] != NULL) ^
575 (info->attrs[NLBL_MGMT_A_IPV6MASK] != NULL)))
576 return -EINVAL;
Paul Moored15c3452006-08-03 16:48:37 -0700577
Paul Moore95d4e6b2006-09-29 17:05:05 -0700578 netlbl_netlink_auditinfo(skb, &audit_info);
579
Paul Moore63c41682008-10-10 10:16:32 -0400580 return netlbl_mgmt_add_common(info, &audit_info);
Paul Moored15c3452006-08-03 16:48:37 -0700581}
582
583/**
584 * netlbl_mgmt_removedef - Handle a REMOVEDEF message
585 * @skb: the NETLINK buffer
586 * @info: the Generic NETLINK info block
587 *
588 * Description:
589 * Process a user generated REMOVEDEF message and remove the default domain
590 * mapping. Returns zero on success, negative values on failure.
591 *
592 */
593static int netlbl_mgmt_removedef(struct sk_buff *skb, struct genl_info *info)
594{
Paul Moore95d4e6b2006-09-29 17:05:05 -0700595 struct netlbl_audit audit_info;
596
597 netlbl_netlink_auditinfo(skb, &audit_info);
598
Huw Davies8f18e672016-06-27 15:02:46 -0400599 return netlbl_domhsh_remove_default(AF_UNSPEC, &audit_info);
Paul Moored15c3452006-08-03 16:48:37 -0700600}
601
602/**
603 * netlbl_mgmt_listdef - Handle a LISTDEF message
604 * @skb: the NETLINK buffer
605 * @info: the Generic NETLINK info block
606 *
607 * Description:
608 * Process a user generated LISTDEF message and dumps the default domain
609 * mapping in a form suitable for use in a kernel generated LISTDEF message.
610 * Returns zero on success, negative values on failure.
611 *
612 */
613static int netlbl_mgmt_listdef(struct sk_buff *skb, struct genl_info *info)
614{
615 int ret_val = -ENOMEM;
Paul Moorefd385852006-09-25 15:56:37 -0700616 struct sk_buff *ans_skb = NULL;
617 void *data;
618 struct netlbl_dom_map *entry;
Huw Davies8f18e672016-06-27 15:02:46 -0400619 u16 family;
620
621 if (info->attrs[NLBL_MGMT_A_FAMILY])
622 family = nla_get_u16(info->attrs[NLBL_MGMT_A_FAMILY]);
623 else
624 family = AF_INET;
Paul Moored15c3452006-08-03 16:48:37 -0700625
Thomas Graf339bf982006-11-10 14:10:15 -0800626 ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Paul Moored15c3452006-08-03 16:48:37 -0700627 if (ans_skb == NULL)
Paul Moorefd385852006-09-25 15:56:37 -0700628 return -ENOMEM;
Thomas Graf17c157c2006-11-14 19:46:02 -0800629 data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
630 0, NLBL_MGMT_C_LISTDEF);
Paul Moorefd385852006-09-25 15:56:37 -0700631 if (data == NULL)
Paul Moored15c3452006-08-03 16:48:37 -0700632 goto listdef_failure;
Paul Moored15c3452006-08-03 16:48:37 -0700633
Paul Moorefd385852006-09-25 15:56:37 -0700634 rcu_read_lock();
Huw Davies8f18e672016-06-27 15:02:46 -0400635 entry = netlbl_domhsh_getentry(NULL, family);
Paul Moorefd385852006-09-25 15:56:37 -0700636 if (entry == NULL) {
637 ret_val = -ENOENT;
638 goto listdef_failure_lock;
639 }
Paul Moore63c41682008-10-10 10:16:32 -0400640 ret_val = netlbl_mgmt_listentry(ans_skb, entry);
Paul Moorefd385852006-09-25 15:56:37 -0700641 rcu_read_unlock();
Paul Moore63c41682008-10-10 10:16:32 -0400642 if (ret_val != 0)
643 goto listdef_failure;
Paul Moorefd385852006-09-25 15:56:37 -0700644
645 genlmsg_end(ans_skb, data);
Denis V. Lunevfe785be2008-07-10 16:53:39 -0700646 return genlmsg_reply(ans_skb, info);
Paul Moored15c3452006-08-03 16:48:37 -0700647
Paul Moorefd385852006-09-25 15:56:37 -0700648listdef_failure_lock:
649 rcu_read_unlock();
Paul Moored15c3452006-08-03 16:48:37 -0700650listdef_failure:
Paul Moorefd385852006-09-25 15:56:37 -0700651 kfree_skb(ans_skb);
Paul Moored15c3452006-08-03 16:48:37 -0700652 return ret_val;
653}
654
655/**
Paul Moorefd385852006-09-25 15:56:37 -0700656 * netlbl_mgmt_protocols_cb - Write an individual PROTOCOL message response
657 * @skb: the skb to write to
Paul Moorefd385852006-09-25 15:56:37 -0700658 * @cb: the NETLINK callback
659 * @protocol: the NetLabel protocol to use in the message
Paul Moored15c3452006-08-03 16:48:37 -0700660 *
661 * Description:
Paul Moorefd385852006-09-25 15:56:37 -0700662 * This function is to be used in conjunction with netlbl_mgmt_protocols() to
663 * answer a application's PROTOCOLS message. Returns the size of the message
664 * on success, negative values on failure.
Paul Moored15c3452006-08-03 16:48:37 -0700665 *
666 */
Paul Moorefd385852006-09-25 15:56:37 -0700667static int netlbl_mgmt_protocols_cb(struct sk_buff *skb,
668 struct netlink_callback *cb,
669 u32 protocol)
Paul Moored15c3452006-08-03 16:48:37 -0700670{
671 int ret_val = -ENOMEM;
Paul Moorefd385852006-09-25 15:56:37 -0700672 void *data;
Paul Moored15c3452006-08-03 16:48:37 -0700673
Eric W. Biederman15e47302012-09-07 20:12:54 +0000674 data = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
Thomas Graf17c157c2006-11-14 19:46:02 -0800675 &netlbl_mgmt_gnl_family, NLM_F_MULTI,
676 NLBL_MGMT_C_PROTOCOLS);
Paul Moorefd385852006-09-25 15:56:37 -0700677 if (data == NULL)
678 goto protocols_cb_failure;
Paul Moored15c3452006-08-03 16:48:37 -0700679
Paul Moorefd385852006-09-25 15:56:37 -0700680 ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL, protocol);
Paul Moored15c3452006-08-03 16:48:37 -0700681 if (ret_val != 0)
Paul Moorefd385852006-09-25 15:56:37 -0700682 goto protocols_cb_failure;
Paul Moored15c3452006-08-03 16:48:37 -0700683
Johannes Berg053c0952015-01-16 22:09:00 +0100684 genlmsg_end(skb, data);
685 return 0;
Paul Moored15c3452006-08-03 16:48:37 -0700686
Paul Moorefd385852006-09-25 15:56:37 -0700687protocols_cb_failure:
688 genlmsg_cancel(skb, data);
Paul Moored15c3452006-08-03 16:48:37 -0700689 return ret_val;
690}
691
692/**
Paul Moorefd385852006-09-25 15:56:37 -0700693 * netlbl_mgmt_protocols - Handle a PROTOCOLS message
694 * @skb: the NETLINK buffer
695 * @cb: the NETLINK callback
696 *
697 * Description:
698 * Process a user generated PROTOCOLS message and respond accordingly.
699 *
700 */
701static int netlbl_mgmt_protocols(struct sk_buff *skb,
702 struct netlink_callback *cb)
703{
704 u32 protos_sent = cb->args[0];
705
706 if (protos_sent == 0) {
707 if (netlbl_mgmt_protocols_cb(skb,
708 cb,
709 NETLBL_NLTYPE_UNLABELED) < 0)
710 goto protocols_return;
711 protos_sent++;
712 }
713 if (protos_sent == 1) {
714 if (netlbl_mgmt_protocols_cb(skb,
715 cb,
716 NETLBL_NLTYPE_CIPSOV4) < 0)
717 goto protocols_return;
718 protos_sent++;
719 }
Huw Daviescb72d382016-06-27 15:02:46 -0400720#if IS_ENABLED(CONFIG_IPV6)
721 if (protos_sent == 2) {
722 if (netlbl_mgmt_protocols_cb(skb,
723 cb,
724 NETLBL_NLTYPE_CALIPSO) < 0)
725 goto protocols_return;
726 protos_sent++;
727 }
728#endif
Paul Moorefd385852006-09-25 15:56:37 -0700729
730protocols_return:
731 cb->args[0] = protos_sent;
732 return skb->len;
733}
734
735/**
Paul Moored15c3452006-08-03 16:48:37 -0700736 * netlbl_mgmt_version - Handle a VERSION message
737 * @skb: the NETLINK buffer
738 * @info: the Generic NETLINK info block
739 *
740 * Description:
741 * Process a user generated VERSION message and respond accordingly. Returns
742 * zero on success, negative values on failure.
743 *
744 */
745static int netlbl_mgmt_version(struct sk_buff *skb, struct genl_info *info)
746{
747 int ret_val = -ENOMEM;
748 struct sk_buff *ans_skb = NULL;
Paul Moorefd385852006-09-25 15:56:37 -0700749 void *data;
Paul Moored15c3452006-08-03 16:48:37 -0700750
Thomas Graf339bf982006-11-10 14:10:15 -0800751 ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Paul Moored15c3452006-08-03 16:48:37 -0700752 if (ans_skb == NULL)
Paul Moorefd385852006-09-25 15:56:37 -0700753 return -ENOMEM;
Thomas Graf17c157c2006-11-14 19:46:02 -0800754 data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
755 0, NLBL_MGMT_C_VERSION);
Paul Moorefd385852006-09-25 15:56:37 -0700756 if (data == NULL)
Paul Moored15c3452006-08-03 16:48:37 -0700757 goto version_failure;
758
Paul Moorefd385852006-09-25 15:56:37 -0700759 ret_val = nla_put_u32(ans_skb,
760 NLBL_MGMT_A_VERSION,
761 NETLBL_PROTO_VERSION);
Paul Moored15c3452006-08-03 16:48:37 -0700762 if (ret_val != 0)
763 goto version_failure;
764
Paul Moorefd385852006-09-25 15:56:37 -0700765 genlmsg_end(ans_skb, data);
Denis V. Lunevfe785be2008-07-10 16:53:39 -0700766 return genlmsg_reply(ans_skb, info);
Paul Moored15c3452006-08-03 16:48:37 -0700767
768version_failure:
769 kfree_skb(ans_skb);
Paul Moored15c3452006-08-03 16:48:37 -0700770 return ret_val;
771}
772
773
774/*
775 * NetLabel Generic NETLINK Command Definitions
776 */
777
Johannes Berg4534de82013-11-14 17:14:46 +0100778static const struct genl_ops netlbl_mgmt_genl_ops[] = {
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800779 {
Paul Moored15c3452006-08-03 16:48:37 -0700780 .cmd = NLBL_MGMT_C_ADD,
Paul Moorefd385852006-09-25 15:56:37 -0700781 .flags = GENL_ADMIN_PERM,
782 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700783 .doit = netlbl_mgmt_add,
784 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800785 },
786 {
Paul Moored15c3452006-08-03 16:48:37 -0700787 .cmd = NLBL_MGMT_C_REMOVE,
Paul Moorefd385852006-09-25 15:56:37 -0700788 .flags = GENL_ADMIN_PERM,
789 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700790 .doit = netlbl_mgmt_remove,
791 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800792 },
793 {
Paul Moorefd385852006-09-25 15:56:37 -0700794 .cmd = NLBL_MGMT_C_LISTALL,
Paul Moored15c3452006-08-03 16:48:37 -0700795 .flags = 0,
Paul Moorefd385852006-09-25 15:56:37 -0700796 .policy = netlbl_mgmt_genl_policy,
797 .doit = NULL,
798 .dumpit = netlbl_mgmt_listall,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800799 },
800 {
Paul Moored15c3452006-08-03 16:48:37 -0700801 .cmd = NLBL_MGMT_C_ADDDEF,
Paul Moorefd385852006-09-25 15:56:37 -0700802 .flags = GENL_ADMIN_PERM,
803 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700804 .doit = netlbl_mgmt_adddef,
805 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800806 },
807 {
Paul Moored15c3452006-08-03 16:48:37 -0700808 .cmd = NLBL_MGMT_C_REMOVEDEF,
Paul Moorefd385852006-09-25 15:56:37 -0700809 .flags = GENL_ADMIN_PERM,
810 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700811 .doit = netlbl_mgmt_removedef,
812 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800813 },
814 {
Paul Moored15c3452006-08-03 16:48:37 -0700815 .cmd = NLBL_MGMT_C_LISTDEF,
816 .flags = 0,
Paul Moorefd385852006-09-25 15:56:37 -0700817 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700818 .doit = netlbl_mgmt_listdef,
819 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800820 },
821 {
Paul Moorefd385852006-09-25 15:56:37 -0700822 .cmd = NLBL_MGMT_C_PROTOCOLS,
Paul Moored15c3452006-08-03 16:48:37 -0700823 .flags = 0,
Paul Moorefd385852006-09-25 15:56:37 -0700824 .policy = netlbl_mgmt_genl_policy,
825 .doit = NULL,
826 .dumpit = netlbl_mgmt_protocols,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800827 },
828 {
Paul Moored15c3452006-08-03 16:48:37 -0700829 .cmd = NLBL_MGMT_C_VERSION,
830 .flags = 0,
Paul Moorefd385852006-09-25 15:56:37 -0700831 .policy = netlbl_mgmt_genl_policy,
Paul Moored15c3452006-08-03 16:48:37 -0700832 .doit = netlbl_mgmt_version,
833 .dumpit = NULL,
Pavel Emelyanov227c43c2008-02-17 22:33:16 -0800834 },
Paul Moored15c3452006-08-03 16:48:37 -0700835};
836
837/*
838 * NetLabel Generic NETLINK Protocol Functions
839 */
840
841/**
842 * netlbl_mgmt_genl_init - Register the NetLabel management component
843 *
844 * Description:
845 * Register the NetLabel management component with the Generic NETLINK
846 * mechanism. Returns zero on success, negative values on failure.
847 *
848 */
Pavel Emelyanov05705e42008-02-17 22:33:57 -0800849int __init netlbl_mgmt_genl_init(void)
Paul Moored15c3452006-08-03 16:48:37 -0700850{
Michał Mirosław7ae740d2009-05-21 10:34:05 +0000851 return genl_register_family_with_ops(&netlbl_mgmt_gnl_family,
Johannes Bergc53ed742013-11-19 15:19:31 +0100852 netlbl_mgmt_genl_ops);
Paul Moored15c3452006-08-03 16:48:37 -0700853}