196cb8e33SPaul Moore /* 296cb8e33SPaul Moore * NetLabel CIPSO/IPv4 Support 396cb8e33SPaul Moore * 496cb8e33SPaul Moore * This file defines the CIPSO/IPv4 functions for the NetLabel system. The 596cb8e33SPaul Moore * NetLabel system manages static and dynamic label mappings for network 696cb8e33SPaul Moore * protocols such as CIPSO and RIPSO. 796cb8e33SPaul Moore * 882c21bfaSPaul Moore * Author: Paul Moore <paul@paul-moore.com> 996cb8e33SPaul Moore * 1096cb8e33SPaul Moore */ 1196cb8e33SPaul Moore 1296cb8e33SPaul Moore /* 1396cb8e33SPaul Moore * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 1496cb8e33SPaul Moore * 1596cb8e33SPaul Moore * This program is free software; you can redistribute it and/or modify 1696cb8e33SPaul Moore * it under the terms of the GNU General Public License as published by 1796cb8e33SPaul Moore * the Free Software Foundation; either version 2 of the License, or 1896cb8e33SPaul Moore * (at your option) any later version. 1996cb8e33SPaul Moore * 2096cb8e33SPaul Moore * This program is distributed in the hope that it will be useful, 2196cb8e33SPaul Moore * but WITHOUT ANY WARRANTY; without even the implied warranty of 2296cb8e33SPaul Moore * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 2396cb8e33SPaul Moore * the GNU General Public License for more details. 2496cb8e33SPaul Moore * 2596cb8e33SPaul Moore * You should have received a copy of the GNU General Public License 26d484ff15SJeff Kirsher * along with this program; if not, see <http://www.gnu.org/licenses/>. 2796cb8e33SPaul Moore * 2896cb8e33SPaul Moore */ 2996cb8e33SPaul Moore 3096cb8e33SPaul Moore #include <linux/types.h> 3196cb8e33SPaul Moore #include <linux/socket.h> 3296cb8e33SPaul Moore #include <linux/string.h> 3396cb8e33SPaul Moore #include <linux/skbuff.h> 3432f50cdeSPaul Moore #include <linux/audit.h> 355a0e3ad6STejun Heo #include <linux/slab.h> 3696cb8e33SPaul Moore #include <net/sock.h> 3796cb8e33SPaul Moore #include <net/netlink.h> 3896cb8e33SPaul Moore #include <net/genetlink.h> 3996cb8e33SPaul Moore #include <net/netlabel.h> 4096cb8e33SPaul Moore #include <net/cipso_ipv4.h> 4160063497SArun Sharma #include <linux/atomic.h> 4296cb8e33SPaul Moore 4396cb8e33SPaul Moore #include "netlabel_user.h" 4496cb8e33SPaul Moore #include "netlabel_cipso_v4.h" 4523bcdc1aSPaul Moore #include "netlabel_mgmt.h" 46b1edeb10SPaul Moore #include "netlabel_domainhash.h" 4796cb8e33SPaul Moore 48fd385855SPaul Moore /* Argument struct for cipso_v4_doi_walk() */ 49fd385855SPaul Moore struct netlbl_cipsov4_doiwalk_arg { 50fd385855SPaul Moore struct netlink_callback *nl_cb; 51fd385855SPaul Moore struct sk_buff *skb; 52fd385855SPaul Moore u32 seq; 53fd385855SPaul Moore }; 54fd385855SPaul Moore 55b1edeb10SPaul Moore /* Argument struct for netlbl_domhsh_walk() */ 56b1edeb10SPaul Moore struct netlbl_domhsh_walk_arg { 57b1edeb10SPaul Moore struct netlbl_audit *audit_info; 58b1edeb10SPaul Moore u32 doi; 59b1edeb10SPaul Moore }; 60b1edeb10SPaul Moore 6196cb8e33SPaul Moore /* NetLabel Generic NETLINK CIPSOv4 family */ 6296cb8e33SPaul Moore static struct genl_family netlbl_cipsov4_gnl_family = { 6396cb8e33SPaul Moore .id = GENL_ID_GENERATE, 6496cb8e33SPaul Moore .hdrsize = 0, 6596cb8e33SPaul Moore .name = NETLBL_NLTYPE_CIPSOV4_NAME, 6696cb8e33SPaul Moore .version = NETLBL_PROTO_VERSION, 67fd385855SPaul Moore .maxattr = NLBL_CIPSOV4_A_MAX, 6896cb8e33SPaul Moore }; 6996cb8e33SPaul Moore 70fd385855SPaul Moore /* NetLabel Netlink attribute policy */ 71ef7c79edSPatrick McHardy static const struct nla_policy netlbl_cipsov4_genl_policy[NLBL_CIPSOV4_A_MAX + 1] = { 72fd385855SPaul Moore [NLBL_CIPSOV4_A_DOI] = { .type = NLA_U32 }, 73fd385855SPaul Moore [NLBL_CIPSOV4_A_MTYPE] = { .type = NLA_U32 }, 74fd385855SPaul Moore [NLBL_CIPSOV4_A_TAG] = { .type = NLA_U8 }, 75fd385855SPaul Moore [NLBL_CIPSOV4_A_TAGLST] = { .type = NLA_NESTED }, 76fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSLVLLOC] = { .type = NLA_U32 }, 77fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSLVLREM] = { .type = NLA_U32 }, 78fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSLVL] = { .type = NLA_NESTED }, 79fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSLVLLST] = { .type = NLA_NESTED }, 80fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSCATLOC] = { .type = NLA_U32 }, 81fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSCATREM] = { .type = NLA_U32 }, 82fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSCAT] = { .type = NLA_NESTED }, 83fd385855SPaul Moore [NLBL_CIPSOV4_A_MLSCATLST] = { .type = NLA_NESTED }, 84fd385855SPaul Moore }; 8596cb8e33SPaul Moore 8696cb8e33SPaul Moore /* 8796cb8e33SPaul Moore * Helper Functions 8896cb8e33SPaul Moore */ 8996cb8e33SPaul Moore 9096cb8e33SPaul Moore /** 91fd385855SPaul Moore * netlbl_cipsov4_add_common - Parse the common sections of a ADD message 92fd385855SPaul Moore * @info: the Generic NETLINK info block 93fd385855SPaul Moore * @doi_def: the CIPSO V4 DOI definition 94fd385855SPaul Moore * 95fd385855SPaul Moore * Description: 96fd385855SPaul Moore * Parse the common sections of a ADD message and fill in the related values 97fd385855SPaul Moore * in @doi_def. Returns zero on success, negative values on failure. 98fd385855SPaul Moore * 99fd385855SPaul Moore */ 100fd385855SPaul Moore static int netlbl_cipsov4_add_common(struct genl_info *info, 101fd385855SPaul Moore struct cipso_v4_doi *doi_def) 102fd385855SPaul Moore { 103fd385855SPaul Moore struct nlattr *nla; 104fd385855SPaul Moore int nla_rem; 105fd385855SPaul Moore u32 iter = 0; 106fd385855SPaul Moore 107fd385855SPaul Moore doi_def->doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); 108fd385855SPaul Moore 109fd385855SPaul Moore if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_TAGLST], 110fd385855SPaul Moore NLBL_CIPSOV4_A_MAX, 111fd385855SPaul Moore netlbl_cipsov4_genl_policy) != 0) 112fd385855SPaul Moore return -EINVAL; 113fd385855SPaul Moore 114fd385855SPaul Moore nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem) 1158f4c1f9bSThomas Graf if (nla_type(nla) == NLBL_CIPSOV4_A_TAG) { 1162a2f11c2SPaul Moore if (iter >= CIPSO_V4_TAG_MAXCNT) 117fd385855SPaul Moore return -EINVAL; 118fd385855SPaul Moore doi_def->tags[iter++] = nla_get_u8(nla); 119fd385855SPaul Moore } 1202a2f11c2SPaul Moore while (iter < CIPSO_V4_TAG_MAXCNT) 1212a2f11c2SPaul Moore doi_def->tags[iter++] = CIPSO_V4_TAG_INVALID; 122fd385855SPaul Moore 123fd385855SPaul Moore return 0; 124fd385855SPaul Moore } 12596cb8e33SPaul Moore 12696cb8e33SPaul Moore /* 12796cb8e33SPaul Moore * NetLabel Command Handlers 12896cb8e33SPaul Moore */ 12996cb8e33SPaul Moore 13096cb8e33SPaul Moore /** 13196cb8e33SPaul Moore * netlbl_cipsov4_add_std - Adds a CIPSO V4 DOI definition 132fd385855SPaul Moore * @info: the Generic NETLINK info block 1336c2e8ac0SPaul Moore * @audit_info: NetLabel audit information 13496cb8e33SPaul Moore * 13596cb8e33SPaul Moore * Description: 13615c45f7bSPaul Moore * Create a new CIPSO_V4_MAP_TRANS DOI definition based on the given ADD 13715c45f7bSPaul Moore * message and add it to the CIPSO V4 engine. Return zero on success and 13815c45f7bSPaul Moore * non-zero on error. 13996cb8e33SPaul Moore * 14096cb8e33SPaul Moore */ 1416c2e8ac0SPaul Moore static int netlbl_cipsov4_add_std(struct genl_info *info, 1426c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 14396cb8e33SPaul Moore { 14496cb8e33SPaul Moore int ret_val = -EINVAL; 14596cb8e33SPaul Moore struct cipso_v4_doi *doi_def = NULL; 146fd385855SPaul Moore struct nlattr *nla_a; 147fd385855SPaul Moore struct nlattr *nla_b; 148fd385855SPaul Moore int nla_a_rem; 149fd385855SPaul Moore int nla_b_rem; 150caff5b6aSPaul Moore u32 iter; 15196cb8e33SPaul Moore 15232f50cdeSPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_TAGLST] || 153fd385855SPaul Moore !info->attrs[NLBL_CIPSOV4_A_MLSLVLLST]) 154fd385855SPaul Moore return -EINVAL; 155fd385855SPaul Moore 156fd385855SPaul Moore if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], 157fd385855SPaul Moore NLBL_CIPSOV4_A_MAX, 158fd385855SPaul Moore netlbl_cipsov4_genl_policy) != 0) 159fd385855SPaul Moore return -EINVAL; 16096cb8e33SPaul Moore 16196cb8e33SPaul Moore doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); 162fd385855SPaul Moore if (doi_def == NULL) 163fd385855SPaul Moore return -ENOMEM; 16496cb8e33SPaul Moore doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL); 16596cb8e33SPaul Moore if (doi_def->map.std == NULL) { 16696cb8e33SPaul Moore ret_val = -ENOMEM; 16796cb8e33SPaul Moore goto add_std_failure; 16896cb8e33SPaul Moore } 16915c45f7bSPaul Moore doi_def->type = CIPSO_V4_MAP_TRANS; 17096cb8e33SPaul Moore 171fd385855SPaul Moore ret_val = netlbl_cipsov4_add_common(info, doi_def); 172fd385855SPaul Moore if (ret_val != 0) 17396cb8e33SPaul Moore goto add_std_failure; 1741fd2a25bSPaul Moore ret_val = -EINVAL; 175fd385855SPaul Moore 176fd385855SPaul Moore nla_for_each_nested(nla_a, 177fd385855SPaul Moore info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], 178fd385855SPaul Moore nla_a_rem) 1798f4c1f9bSThomas Graf if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) { 1801fd2a25bSPaul Moore if (nla_validate_nested(nla_a, 1811fd2a25bSPaul Moore NLBL_CIPSOV4_A_MAX, 1821fd2a25bSPaul Moore netlbl_cipsov4_genl_policy) != 0) 1831fd2a25bSPaul Moore goto add_std_failure; 184fd385855SPaul Moore nla_for_each_nested(nla_b, nla_a, nla_b_rem) 1858f4c1f9bSThomas Graf switch (nla_type(nla_b)) { 186fd385855SPaul Moore case NLBL_CIPSOV4_A_MLSLVLLOC: 1871fd2a25bSPaul Moore if (nla_get_u32(nla_b) > 1881fd2a25bSPaul Moore CIPSO_V4_MAX_LOC_LVLS) 1891fd2a25bSPaul Moore goto add_std_failure; 190fd385855SPaul Moore if (nla_get_u32(nla_b) >= 191fd385855SPaul Moore doi_def->map.std->lvl.local_size) 192fd385855SPaul Moore doi_def->map.std->lvl.local_size = 193fd385855SPaul Moore nla_get_u32(nla_b) + 1; 19496cb8e33SPaul Moore break; 195fd385855SPaul Moore case NLBL_CIPSOV4_A_MLSLVLREM: 1961fd2a25bSPaul Moore if (nla_get_u32(nla_b) > 1971fd2a25bSPaul Moore CIPSO_V4_MAX_REM_LVLS) 1981fd2a25bSPaul Moore goto add_std_failure; 199fd385855SPaul Moore if (nla_get_u32(nla_b) >= 200fd385855SPaul Moore doi_def->map.std->lvl.cipso_size) 201fd385855SPaul Moore doi_def->map.std->lvl.cipso_size = 202fd385855SPaul Moore nla_get_u32(nla_b) + 1; 203fd385855SPaul Moore break; 20496cb8e33SPaul Moore } 20596cb8e33SPaul Moore } 20696cb8e33SPaul Moore doi_def->map.std->lvl.local = kcalloc(doi_def->map.std->lvl.local_size, 20796cb8e33SPaul Moore sizeof(u32), 20896cb8e33SPaul Moore GFP_KERNEL); 20996cb8e33SPaul Moore if (doi_def->map.std->lvl.local == NULL) { 21096cb8e33SPaul Moore ret_val = -ENOMEM; 21196cb8e33SPaul Moore goto add_std_failure; 21296cb8e33SPaul Moore } 21396cb8e33SPaul Moore doi_def->map.std->lvl.cipso = kcalloc(doi_def->map.std->lvl.cipso_size, 21496cb8e33SPaul Moore sizeof(u32), 21596cb8e33SPaul Moore GFP_KERNEL); 21696cb8e33SPaul Moore if (doi_def->map.std->lvl.cipso == NULL) { 21796cb8e33SPaul Moore ret_val = -ENOMEM; 21896cb8e33SPaul Moore goto add_std_failure; 21996cb8e33SPaul Moore } 220caff5b6aSPaul Moore for (iter = 0; iter < doi_def->map.std->lvl.local_size; iter++) 221caff5b6aSPaul Moore doi_def->map.std->lvl.local[iter] = CIPSO_V4_INV_LVL; 222caff5b6aSPaul Moore for (iter = 0; iter < doi_def->map.std->lvl.cipso_size; iter++) 223caff5b6aSPaul Moore doi_def->map.std->lvl.cipso[iter] = CIPSO_V4_INV_LVL; 224fd385855SPaul Moore nla_for_each_nested(nla_a, 225fd385855SPaul Moore info->attrs[NLBL_CIPSOV4_A_MLSLVLLST], 226fd385855SPaul Moore nla_a_rem) 2278f4c1f9bSThomas Graf if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) { 228fd385855SPaul Moore struct nlattr *lvl_loc; 229fd385855SPaul Moore struct nlattr *lvl_rem; 23096cb8e33SPaul Moore 231fd385855SPaul Moore lvl_loc = nla_find_nested(nla_a, 232fd385855SPaul Moore NLBL_CIPSOV4_A_MLSLVLLOC); 233fd385855SPaul Moore lvl_rem = nla_find_nested(nla_a, 234fd385855SPaul Moore NLBL_CIPSOV4_A_MLSLVLREM); 235fd385855SPaul Moore if (lvl_loc == NULL || lvl_rem == NULL) 236fd385855SPaul Moore goto add_std_failure; 237fd385855SPaul Moore doi_def->map.std->lvl.local[nla_get_u32(lvl_loc)] = 238fd385855SPaul Moore nla_get_u32(lvl_rem); 239fd385855SPaul Moore doi_def->map.std->lvl.cipso[nla_get_u32(lvl_rem)] = 240fd385855SPaul Moore nla_get_u32(lvl_loc); 241fd385855SPaul Moore } 242fd385855SPaul Moore 243fd385855SPaul Moore if (info->attrs[NLBL_CIPSOV4_A_MLSCATLST]) { 244fd385855SPaul Moore if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSCATLST], 245fd385855SPaul Moore NLBL_CIPSOV4_A_MAX, 246fd385855SPaul Moore netlbl_cipsov4_genl_policy) != 0) 247fd385855SPaul Moore goto add_std_failure; 248fd385855SPaul Moore 249fd385855SPaul Moore nla_for_each_nested(nla_a, 250fd385855SPaul Moore info->attrs[NLBL_CIPSOV4_A_MLSCATLST], 251fd385855SPaul Moore nla_a_rem) 2528f4c1f9bSThomas Graf if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) { 253fd385855SPaul Moore if (nla_validate_nested(nla_a, 254fd385855SPaul Moore NLBL_CIPSOV4_A_MAX, 255fd385855SPaul Moore netlbl_cipsov4_genl_policy) != 0) 256fd385855SPaul Moore goto add_std_failure; 257fd385855SPaul Moore nla_for_each_nested(nla_b, nla_a, nla_b_rem) 2588f4c1f9bSThomas Graf switch (nla_type(nla_b)) { 259fd385855SPaul Moore case NLBL_CIPSOV4_A_MLSCATLOC: 2601fd2a25bSPaul Moore if (nla_get_u32(nla_b) > 2611fd2a25bSPaul Moore CIPSO_V4_MAX_LOC_CATS) 2621fd2a25bSPaul Moore goto add_std_failure; 263fd385855SPaul Moore if (nla_get_u32(nla_b) >= 264fd385855SPaul Moore doi_def->map.std->cat.local_size) 265fd385855SPaul Moore doi_def->map.std->cat.local_size = 266fd385855SPaul Moore nla_get_u32(nla_b) + 1; 267fd385855SPaul Moore break; 268fd385855SPaul Moore case NLBL_CIPSOV4_A_MLSCATREM: 2691fd2a25bSPaul Moore if (nla_get_u32(nla_b) > 2701fd2a25bSPaul Moore CIPSO_V4_MAX_REM_CATS) 2711fd2a25bSPaul Moore goto add_std_failure; 272fd385855SPaul Moore if (nla_get_u32(nla_b) >= 273fd385855SPaul Moore doi_def->map.std->cat.cipso_size) 274fd385855SPaul Moore doi_def->map.std->cat.cipso_size = 275fd385855SPaul Moore nla_get_u32(nla_b) + 1; 276fd385855SPaul Moore break; 277fd385855SPaul Moore } 278fd385855SPaul Moore } 279fd385855SPaul Moore doi_def->map.std->cat.local = kcalloc( 280fd385855SPaul Moore doi_def->map.std->cat.local_size, 28196cb8e33SPaul Moore sizeof(u32), 28296cb8e33SPaul Moore GFP_KERNEL); 28396cb8e33SPaul Moore if (doi_def->map.std->cat.local == NULL) { 28496cb8e33SPaul Moore ret_val = -ENOMEM; 28596cb8e33SPaul Moore goto add_std_failure; 28696cb8e33SPaul Moore } 287fd385855SPaul Moore doi_def->map.std->cat.cipso = kcalloc( 288fd385855SPaul Moore doi_def->map.std->cat.cipso_size, 28996cb8e33SPaul Moore sizeof(u32), 29096cb8e33SPaul Moore GFP_KERNEL); 29196cb8e33SPaul Moore if (doi_def->map.std->cat.cipso == NULL) { 29296cb8e33SPaul Moore ret_val = -ENOMEM; 29396cb8e33SPaul Moore goto add_std_failure; 29496cb8e33SPaul Moore } 295caff5b6aSPaul Moore for (iter = 0; iter < doi_def->map.std->cat.local_size; iter++) 296caff5b6aSPaul Moore doi_def->map.std->cat.local[iter] = CIPSO_V4_INV_CAT; 297caff5b6aSPaul Moore for (iter = 0; iter < doi_def->map.std->cat.cipso_size; iter++) 298caff5b6aSPaul Moore doi_def->map.std->cat.cipso[iter] = CIPSO_V4_INV_CAT; 299fd385855SPaul Moore nla_for_each_nested(nla_a, 300fd385855SPaul Moore info->attrs[NLBL_CIPSOV4_A_MLSCATLST], 301fd385855SPaul Moore nla_a_rem) 3028f4c1f9bSThomas Graf if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) { 303fd385855SPaul Moore struct nlattr *cat_loc; 304fd385855SPaul Moore struct nlattr *cat_rem; 30596cb8e33SPaul Moore 306fd385855SPaul Moore cat_loc = nla_find_nested(nla_a, 307fd385855SPaul Moore NLBL_CIPSOV4_A_MLSCATLOC); 308fd385855SPaul Moore cat_rem = nla_find_nested(nla_a, 309fd385855SPaul Moore NLBL_CIPSOV4_A_MLSCATREM); 310fd385855SPaul Moore if (cat_loc == NULL || cat_rem == NULL) 31196cb8e33SPaul Moore goto add_std_failure; 312fd385855SPaul Moore doi_def->map.std->cat.local[ 313fd385855SPaul Moore nla_get_u32(cat_loc)] = 314fd385855SPaul Moore nla_get_u32(cat_rem); 315fd385855SPaul Moore doi_def->map.std->cat.cipso[ 316fd385855SPaul Moore nla_get_u32(cat_rem)] = 317fd385855SPaul Moore nla_get_u32(cat_loc); 318fd385855SPaul Moore } 31996cb8e33SPaul Moore } 32096cb8e33SPaul Moore 3216c2e8ac0SPaul Moore ret_val = cipso_v4_doi_add(doi_def, audit_info); 32296cb8e33SPaul Moore if (ret_val != 0) 32396cb8e33SPaul Moore goto add_std_failure; 32496cb8e33SPaul Moore return 0; 32596cb8e33SPaul Moore 32696cb8e33SPaul Moore add_std_failure: 32796cb8e33SPaul Moore if (doi_def) 328b1edeb10SPaul Moore cipso_v4_doi_free(doi_def); 32996cb8e33SPaul Moore return ret_val; 33096cb8e33SPaul Moore } 33196cb8e33SPaul Moore 33296cb8e33SPaul Moore /** 33396cb8e33SPaul Moore * netlbl_cipsov4_add_pass - Adds a CIPSO V4 DOI definition 334fd385855SPaul Moore * @info: the Generic NETLINK info block 3356c2e8ac0SPaul Moore * @audit_info: NetLabel audit information 33696cb8e33SPaul Moore * 33796cb8e33SPaul Moore * Description: 33896cb8e33SPaul Moore * Create a new CIPSO_V4_MAP_PASS DOI definition based on the given ADD message 33996cb8e33SPaul Moore * and add it to the CIPSO V4 engine. Return zero on success and non-zero on 34096cb8e33SPaul Moore * error. 34196cb8e33SPaul Moore * 34296cb8e33SPaul Moore */ 3436c2e8ac0SPaul Moore static int netlbl_cipsov4_add_pass(struct genl_info *info, 3446c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 34596cb8e33SPaul Moore { 346fd385855SPaul Moore int ret_val; 34796cb8e33SPaul Moore struct cipso_v4_doi *doi_def = NULL; 34896cb8e33SPaul Moore 34932f50cdeSPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_TAGLST]) 350fd385855SPaul Moore return -EINVAL; 35196cb8e33SPaul Moore 35296cb8e33SPaul Moore doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); 353fd385855SPaul Moore if (doi_def == NULL) 354fd385855SPaul Moore return -ENOMEM; 35596cb8e33SPaul Moore doi_def->type = CIPSO_V4_MAP_PASS; 35696cb8e33SPaul Moore 357fd385855SPaul Moore ret_val = netlbl_cipsov4_add_common(info, doi_def); 358fd385855SPaul Moore if (ret_val != 0) 35996cb8e33SPaul Moore goto add_pass_failure; 36096cb8e33SPaul Moore 3616c2e8ac0SPaul Moore ret_val = cipso_v4_doi_add(doi_def, audit_info); 36296cb8e33SPaul Moore if (ret_val != 0) 36396cb8e33SPaul Moore goto add_pass_failure; 36496cb8e33SPaul Moore return 0; 36596cb8e33SPaul Moore 36696cb8e33SPaul Moore add_pass_failure: 367b1edeb10SPaul Moore cipso_v4_doi_free(doi_def); 36896cb8e33SPaul Moore return ret_val; 36996cb8e33SPaul Moore } 37096cb8e33SPaul Moore 37196cb8e33SPaul Moore /** 372d91d4079SPaul Moore * netlbl_cipsov4_add_local - Adds a CIPSO V4 DOI definition 373d91d4079SPaul Moore * @info: the Generic NETLINK info block 3746c2e8ac0SPaul Moore * @audit_info: NetLabel audit information 375d91d4079SPaul Moore * 376d91d4079SPaul Moore * Description: 377d91d4079SPaul Moore * Create a new CIPSO_V4_MAP_LOCAL DOI definition based on the given ADD 378d91d4079SPaul Moore * message and add it to the CIPSO V4 engine. Return zero on success and 379d91d4079SPaul Moore * non-zero on error. 380d91d4079SPaul Moore * 381d91d4079SPaul Moore */ 3826c2e8ac0SPaul Moore static int netlbl_cipsov4_add_local(struct genl_info *info, 3836c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 384d91d4079SPaul Moore { 385d91d4079SPaul Moore int ret_val; 386d91d4079SPaul Moore struct cipso_v4_doi *doi_def = NULL; 387d91d4079SPaul Moore 388d91d4079SPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_TAGLST]) 389d91d4079SPaul Moore return -EINVAL; 390d91d4079SPaul Moore 391d91d4079SPaul Moore doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL); 392d91d4079SPaul Moore if (doi_def == NULL) 393d91d4079SPaul Moore return -ENOMEM; 394d91d4079SPaul Moore doi_def->type = CIPSO_V4_MAP_LOCAL; 395d91d4079SPaul Moore 396d91d4079SPaul Moore ret_val = netlbl_cipsov4_add_common(info, doi_def); 397d91d4079SPaul Moore if (ret_val != 0) 398d91d4079SPaul Moore goto add_local_failure; 399d91d4079SPaul Moore 4006c2e8ac0SPaul Moore ret_val = cipso_v4_doi_add(doi_def, audit_info); 401d91d4079SPaul Moore if (ret_val != 0) 402d91d4079SPaul Moore goto add_local_failure; 403d91d4079SPaul Moore return 0; 404d91d4079SPaul Moore 405d91d4079SPaul Moore add_local_failure: 406d91d4079SPaul Moore cipso_v4_doi_free(doi_def); 407d91d4079SPaul Moore return ret_val; 408d91d4079SPaul Moore } 409d91d4079SPaul Moore 410d91d4079SPaul Moore /** 41196cb8e33SPaul Moore * netlbl_cipsov4_add - Handle an ADD message 41296cb8e33SPaul Moore * @skb: the NETLINK buffer 41396cb8e33SPaul Moore * @info: the Generic NETLINK info block 41496cb8e33SPaul Moore * 41596cb8e33SPaul Moore * Description: 41696cb8e33SPaul Moore * Create a new DOI definition based on the given ADD message and add it to the 41796cb8e33SPaul Moore * CIPSO V4 engine. Returns zero on success, negative values on failure. 41896cb8e33SPaul Moore * 41996cb8e33SPaul Moore */ 42096cb8e33SPaul Moore static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info) 42196cb8e33SPaul Moore 42296cb8e33SPaul Moore { 42396cb8e33SPaul Moore int ret_val = -EINVAL; 42495d4e6beSPaul Moore struct netlbl_audit audit_info; 42596cb8e33SPaul Moore 42632f50cdeSPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_DOI] || 42732f50cdeSPaul Moore !info->attrs[NLBL_CIPSOV4_A_MTYPE]) 428fd385855SPaul Moore return -EINVAL; 42996cb8e33SPaul Moore 43095d4e6beSPaul Moore netlbl_netlink_auditinfo(skb, &audit_info); 4316c2e8ac0SPaul Moore switch (nla_get_u32(info->attrs[NLBL_CIPSOV4_A_MTYPE])) { 43215c45f7bSPaul Moore case CIPSO_V4_MAP_TRANS: 4336c2e8ac0SPaul Moore ret_val = netlbl_cipsov4_add_std(info, &audit_info); 43496cb8e33SPaul Moore break; 43596cb8e33SPaul Moore case CIPSO_V4_MAP_PASS: 4366c2e8ac0SPaul Moore ret_val = netlbl_cipsov4_add_pass(info, &audit_info); 43796cb8e33SPaul Moore break; 438d91d4079SPaul Moore case CIPSO_V4_MAP_LOCAL: 4396c2e8ac0SPaul Moore ret_val = netlbl_cipsov4_add_local(info, &audit_info); 440d91d4079SPaul Moore break; 44196cb8e33SPaul Moore } 44223bcdc1aSPaul Moore if (ret_val == 0) 443c783f1ceSPaul Moore atomic_inc(&netlabel_mgmt_protocount); 44496cb8e33SPaul Moore 44596cb8e33SPaul Moore return ret_val; 44696cb8e33SPaul Moore } 44796cb8e33SPaul Moore 44896cb8e33SPaul Moore /** 44996cb8e33SPaul Moore * netlbl_cipsov4_list - Handle a LIST message 45096cb8e33SPaul Moore * @skb: the NETLINK buffer 45196cb8e33SPaul Moore * @info: the Generic NETLINK info block 45296cb8e33SPaul Moore * 45396cb8e33SPaul Moore * Description: 454fd385855SPaul Moore * Process a user generated LIST message and respond accordingly. While the 455fd385855SPaul Moore * response message generated by the kernel is straightforward, determining 456fd385855SPaul Moore * before hand the size of the buffer to allocate is not (we have to generate 457fd385855SPaul Moore * the message to know the size). In order to keep this function sane what we 458fd385855SPaul Moore * do is allocate a buffer of NLMSG_GOODSIZE and try to fit the response in 459fd385855SPaul Moore * that size, if we fail then we restart with a larger buffer and try again. 460fd385855SPaul Moore * We continue in this manner until we hit a limit of failed attempts then we 461fd385855SPaul Moore * give up and just send an error message. Returns zero on success and 462fd385855SPaul Moore * negative values on error. 46396cb8e33SPaul Moore * 46496cb8e33SPaul Moore */ 46596cb8e33SPaul Moore static int netlbl_cipsov4_list(struct sk_buff *skb, struct genl_info *info) 46696cb8e33SPaul Moore { 467fd385855SPaul Moore int ret_val; 468fd385855SPaul Moore struct sk_buff *ans_skb = NULL; 469fd385855SPaul Moore u32 nlsze_mult = 1; 470fd385855SPaul Moore void *data; 47196cb8e33SPaul Moore u32 doi; 472fd385855SPaul Moore struct nlattr *nla_a; 473fd385855SPaul Moore struct nlattr *nla_b; 474fd385855SPaul Moore struct cipso_v4_doi *doi_def; 475fd385855SPaul Moore u32 iter; 47696cb8e33SPaul Moore 477fd385855SPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_DOI]) { 478fd385855SPaul Moore ret_val = -EINVAL; 47996cb8e33SPaul Moore goto list_failure; 480fd385855SPaul Moore } 48196cb8e33SPaul Moore 482fd385855SPaul Moore list_start: 483339bf98fSThomas Graf ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE * nlsze_mult, GFP_KERNEL); 48496cb8e33SPaul Moore if (ans_skb == NULL) { 48596cb8e33SPaul Moore ret_val = -ENOMEM; 48696cb8e33SPaul Moore goto list_failure; 48796cb8e33SPaul Moore } 48817c157c8SThomas Graf data = genlmsg_put_reply(ans_skb, info, &netlbl_cipsov4_gnl_family, 48917c157c8SThomas Graf 0, NLBL_CIPSOV4_C_LIST); 490fd385855SPaul Moore if (data == NULL) { 491fd385855SPaul Moore ret_val = -ENOMEM; 492fd385855SPaul Moore goto list_failure; 493fd385855SPaul Moore } 49496cb8e33SPaul Moore 495fd385855SPaul Moore doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); 496fd385855SPaul Moore 497fd385855SPaul Moore rcu_read_lock(); 498fd385855SPaul Moore doi_def = cipso_v4_doi_getdef(doi); 499fd385855SPaul Moore if (doi_def == NULL) { 500fd385855SPaul Moore ret_val = -EINVAL; 50156196701SPaul Moore goto list_failure_lock; 502fd385855SPaul Moore } 503fd385855SPaul Moore 504fd385855SPaul Moore ret_val = nla_put_u32(ans_skb, NLBL_CIPSOV4_A_MTYPE, doi_def->type); 505fd385855SPaul Moore if (ret_val != 0) 506fd385855SPaul Moore goto list_failure_lock; 507fd385855SPaul Moore 508fd385855SPaul Moore nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_TAGLST); 509fd385855SPaul Moore if (nla_a == NULL) { 510fd385855SPaul Moore ret_val = -ENOMEM; 511fd385855SPaul Moore goto list_failure_lock; 512fd385855SPaul Moore } 513fd385855SPaul Moore for (iter = 0; 514fd385855SPaul Moore iter < CIPSO_V4_TAG_MAXCNT && 515fd385855SPaul Moore doi_def->tags[iter] != CIPSO_V4_TAG_INVALID; 516fd385855SPaul Moore iter++) { 517fd385855SPaul Moore ret_val = nla_put_u8(ans_skb, 518fd385855SPaul Moore NLBL_CIPSOV4_A_TAG, 519fd385855SPaul Moore doi_def->tags[iter]); 520fd385855SPaul Moore if (ret_val != 0) 521fd385855SPaul Moore goto list_failure_lock; 522fd385855SPaul Moore } 523fd385855SPaul Moore nla_nest_end(ans_skb, nla_a); 524fd385855SPaul Moore 525fd385855SPaul Moore switch (doi_def->type) { 52615c45f7bSPaul Moore case CIPSO_V4_MAP_TRANS: 527fd385855SPaul Moore nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVLLST); 528fd385855SPaul Moore if (nla_a == NULL) { 529fd385855SPaul Moore ret_val = -ENOMEM; 530fd385855SPaul Moore goto list_failure_lock; 531fd385855SPaul Moore } 532fd385855SPaul Moore for (iter = 0; 533fd385855SPaul Moore iter < doi_def->map.std->lvl.local_size; 534fd385855SPaul Moore iter++) { 535fd385855SPaul Moore if (doi_def->map.std->lvl.local[iter] == 536fd385855SPaul Moore CIPSO_V4_INV_LVL) 537fd385855SPaul Moore continue; 538fd385855SPaul Moore 539fd385855SPaul Moore nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVL); 540fd385855SPaul Moore if (nla_b == NULL) { 541fd385855SPaul Moore ret_val = -ENOMEM; 542fd385855SPaul Moore goto list_retry; 543fd385855SPaul Moore } 544fd385855SPaul Moore ret_val = nla_put_u32(ans_skb, 545fd385855SPaul Moore NLBL_CIPSOV4_A_MLSLVLLOC, 546fd385855SPaul Moore iter); 547fd385855SPaul Moore if (ret_val != 0) 548fd385855SPaul Moore goto list_retry; 549fd385855SPaul Moore ret_val = nla_put_u32(ans_skb, 550fd385855SPaul Moore NLBL_CIPSOV4_A_MLSLVLREM, 551fd385855SPaul Moore doi_def->map.std->lvl.local[iter]); 552fd385855SPaul Moore if (ret_val != 0) 553fd385855SPaul Moore goto list_retry; 554fd385855SPaul Moore nla_nest_end(ans_skb, nla_b); 555fd385855SPaul Moore } 556fd385855SPaul Moore nla_nest_end(ans_skb, nla_a); 557fd385855SPaul Moore 558fd385855SPaul Moore nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCATLST); 559fd385855SPaul Moore if (nla_a == NULL) { 560fd385855SPaul Moore ret_val = -ENOMEM; 561fd385855SPaul Moore goto list_retry; 562fd385855SPaul Moore } 563fd385855SPaul Moore for (iter = 0; 564fd385855SPaul Moore iter < doi_def->map.std->cat.local_size; 565fd385855SPaul Moore iter++) { 566fd385855SPaul Moore if (doi_def->map.std->cat.local[iter] == 567fd385855SPaul Moore CIPSO_V4_INV_CAT) 568fd385855SPaul Moore continue; 569fd385855SPaul Moore 570fd385855SPaul Moore nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCAT); 571fd385855SPaul Moore if (nla_b == NULL) { 572fd385855SPaul Moore ret_val = -ENOMEM; 573fd385855SPaul Moore goto list_retry; 574fd385855SPaul Moore } 575fd385855SPaul Moore ret_val = nla_put_u32(ans_skb, 576fd385855SPaul Moore NLBL_CIPSOV4_A_MLSCATLOC, 577fd385855SPaul Moore iter); 578fd385855SPaul Moore if (ret_val != 0) 579fd385855SPaul Moore goto list_retry; 580fd385855SPaul Moore ret_val = nla_put_u32(ans_skb, 581fd385855SPaul Moore NLBL_CIPSOV4_A_MLSCATREM, 582fd385855SPaul Moore doi_def->map.std->cat.local[iter]); 583fd385855SPaul Moore if (ret_val != 0) 584fd385855SPaul Moore goto list_retry; 585fd385855SPaul Moore nla_nest_end(ans_skb, nla_b); 586fd385855SPaul Moore } 587fd385855SPaul Moore nla_nest_end(ans_skb, nla_a); 588fd385855SPaul Moore 589fd385855SPaul Moore break; 590fd385855SPaul Moore } 591fd385855SPaul Moore rcu_read_unlock(); 592fd385855SPaul Moore 593fd385855SPaul Moore genlmsg_end(ans_skb, data); 594fe785beeSDenis V. Lunev return genlmsg_reply(ans_skb, info); 59596cb8e33SPaul Moore 596fd385855SPaul Moore list_retry: 597fd385855SPaul Moore /* XXX - this limit is a guesstimate */ 598fd385855SPaul Moore if (nlsze_mult < 4) { 599fd385855SPaul Moore rcu_read_unlock(); 600fd385855SPaul Moore kfree_skb(ans_skb); 60183aa2e96SDenis V. Lunev nlsze_mult *= 2; 602fd385855SPaul Moore goto list_start; 603fd385855SPaul Moore } 604fd385855SPaul Moore list_failure_lock: 605fd385855SPaul Moore rcu_read_unlock(); 60696cb8e33SPaul Moore list_failure: 607fd385855SPaul Moore kfree_skb(ans_skb); 608fd385855SPaul Moore return ret_val; 609fd385855SPaul Moore } 610fd385855SPaul Moore 611fd385855SPaul Moore /** 612fd385855SPaul Moore * netlbl_cipsov4_listall_cb - cipso_v4_doi_walk() callback for LISTALL 613fd385855SPaul Moore * @doi_def: the CIPSOv4 DOI definition 614fd385855SPaul Moore * @arg: the netlbl_cipsov4_doiwalk_arg structure 615fd385855SPaul Moore * 616fd385855SPaul Moore * Description: 617fd385855SPaul Moore * This function is designed to be used as a callback to the 618fd385855SPaul Moore * cipso_v4_doi_walk() function for use in generating a response for a LISTALL 619fd385855SPaul Moore * message. Returns the size of the message on success, negative values on 620fd385855SPaul Moore * failure. 621fd385855SPaul Moore * 622fd385855SPaul Moore */ 623fd385855SPaul Moore static int netlbl_cipsov4_listall_cb(struct cipso_v4_doi *doi_def, void *arg) 624fd385855SPaul Moore { 625fd385855SPaul Moore int ret_val = -ENOMEM; 626fd385855SPaul Moore struct netlbl_cipsov4_doiwalk_arg *cb_arg = arg; 627fd385855SPaul Moore void *data; 628fd385855SPaul Moore 62915e47304SEric W. Biederman data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, 63017c157c8SThomas Graf cb_arg->seq, &netlbl_cipsov4_gnl_family, 63117c157c8SThomas Graf NLM_F_MULTI, NLBL_CIPSOV4_C_LISTALL); 632fd385855SPaul Moore if (data == NULL) 633fd385855SPaul Moore goto listall_cb_failure; 634fd385855SPaul Moore 635fd385855SPaul Moore ret_val = nla_put_u32(cb_arg->skb, NLBL_CIPSOV4_A_DOI, doi_def->doi); 636fd385855SPaul Moore if (ret_val != 0) 637fd385855SPaul Moore goto listall_cb_failure; 638fd385855SPaul Moore ret_val = nla_put_u32(cb_arg->skb, 639fd385855SPaul Moore NLBL_CIPSOV4_A_MTYPE, 640fd385855SPaul Moore doi_def->type); 641fd385855SPaul Moore if (ret_val != 0) 642fd385855SPaul Moore goto listall_cb_failure; 643fd385855SPaul Moore 644*053c095aSJohannes Berg genlmsg_end(cb_arg->skb, data); 645*053c095aSJohannes Berg return 0; 646fd385855SPaul Moore 647fd385855SPaul Moore listall_cb_failure: 648fd385855SPaul Moore genlmsg_cancel(cb_arg->skb, data); 64996cb8e33SPaul Moore return ret_val; 65096cb8e33SPaul Moore } 65196cb8e33SPaul Moore 65296cb8e33SPaul Moore /** 65396cb8e33SPaul Moore * netlbl_cipsov4_listall - Handle a LISTALL message 65496cb8e33SPaul Moore * @skb: the NETLINK buffer 655fd385855SPaul Moore * @cb: the NETLINK callback 65696cb8e33SPaul Moore * 65796cb8e33SPaul Moore * Description: 65896cb8e33SPaul Moore * Process a user generated LISTALL message and respond accordingly. Returns 65996cb8e33SPaul Moore * zero on success and negative values on error. 66096cb8e33SPaul Moore * 66196cb8e33SPaul Moore */ 662fd385855SPaul Moore static int netlbl_cipsov4_listall(struct sk_buff *skb, 663fd385855SPaul Moore struct netlink_callback *cb) 66496cb8e33SPaul Moore { 665fd385855SPaul Moore struct netlbl_cipsov4_doiwalk_arg cb_arg; 66656196701SPaul Moore u32 doi_skip = cb->args[0]; 66796cb8e33SPaul Moore 668fd385855SPaul Moore cb_arg.nl_cb = cb; 669fd385855SPaul Moore cb_arg.skb = skb; 670fd385855SPaul Moore cb_arg.seq = cb->nlh->nlmsg_seq; 67196cb8e33SPaul Moore 672fd385855SPaul Moore cipso_v4_doi_walk(&doi_skip, netlbl_cipsov4_listall_cb, &cb_arg); 67396cb8e33SPaul Moore 674fd385855SPaul Moore cb->args[0] = doi_skip; 675fd385855SPaul Moore return skb->len; 67696cb8e33SPaul Moore } 67796cb8e33SPaul Moore 67896cb8e33SPaul Moore /** 679b1edeb10SPaul Moore * netlbl_cipsov4_remove_cb - netlbl_cipsov4_remove() callback for REMOVE 680b1edeb10SPaul Moore * @entry: LSM domain mapping entry 681b1edeb10SPaul Moore * @arg: the netlbl_domhsh_walk_arg structure 682b1edeb10SPaul Moore * 683b1edeb10SPaul Moore * Description: 684b1edeb10SPaul Moore * This function is intended for use by netlbl_cipsov4_remove() as the callback 685b1edeb10SPaul Moore * for the netlbl_domhsh_walk() function; it removes LSM domain map entries 686b1edeb10SPaul Moore * which are associated with the CIPSO DOI specified in @arg. Returns zero on 687b1edeb10SPaul Moore * success, negative values on failure. 688b1edeb10SPaul Moore * 689b1edeb10SPaul Moore */ 690b1edeb10SPaul Moore static int netlbl_cipsov4_remove_cb(struct netlbl_dom_map *entry, void *arg) 691b1edeb10SPaul Moore { 692b1edeb10SPaul Moore struct netlbl_domhsh_walk_arg *cb_arg = arg; 693b1edeb10SPaul Moore 6946a8b7f0cSPaul Moore if (entry->def.type == NETLBL_NLTYPE_CIPSOV4 && 6956a8b7f0cSPaul Moore entry->def.cipso->doi == cb_arg->doi) 696b1edeb10SPaul Moore return netlbl_domhsh_remove_entry(entry, cb_arg->audit_info); 697b1edeb10SPaul Moore 698b1edeb10SPaul Moore return 0; 699b1edeb10SPaul Moore } 700b1edeb10SPaul Moore 701b1edeb10SPaul Moore /** 70296cb8e33SPaul Moore * netlbl_cipsov4_remove - Handle a REMOVE message 70396cb8e33SPaul Moore * @skb: the NETLINK buffer 70496cb8e33SPaul Moore * @info: the Generic NETLINK info block 70596cb8e33SPaul Moore * 70696cb8e33SPaul Moore * Description: 70796cb8e33SPaul Moore * Process a user generated REMOVE message and respond accordingly. Returns 70896cb8e33SPaul Moore * zero on success, negative values on failure. 70996cb8e33SPaul Moore * 71096cb8e33SPaul Moore */ 71196cb8e33SPaul Moore static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) 71296cb8e33SPaul Moore { 713fd385855SPaul Moore int ret_val = -EINVAL; 714b1edeb10SPaul Moore struct netlbl_domhsh_walk_arg cb_arg; 71595d4e6beSPaul Moore struct netlbl_audit audit_info; 716b1edeb10SPaul Moore u32 skip_bkt = 0; 717b1edeb10SPaul Moore u32 skip_chain = 0; 71896cb8e33SPaul Moore 71995d4e6beSPaul Moore if (!info->attrs[NLBL_CIPSOV4_A_DOI]) 72095d4e6beSPaul Moore return -EINVAL; 72195d4e6beSPaul Moore 72295d4e6beSPaul Moore netlbl_netlink_auditinfo(skb, &audit_info); 7236c2e8ac0SPaul Moore cb_arg.doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]); 724b1edeb10SPaul Moore cb_arg.audit_info = &audit_info; 725b1edeb10SPaul Moore ret_val = netlbl_domhsh_walk(&skip_bkt, &skip_chain, 726b1edeb10SPaul Moore netlbl_cipsov4_remove_cb, &cb_arg); 727b1edeb10SPaul Moore if (ret_val == 0 || ret_val == -ENOENT) { 7286c2e8ac0SPaul Moore ret_val = cipso_v4_doi_remove(cb_arg.doi, &audit_info); 72923bcdc1aSPaul Moore if (ret_val == 0) 730c783f1ceSPaul Moore atomic_dec(&netlabel_mgmt_protocount); 731b1edeb10SPaul Moore } 73295d4e6beSPaul Moore 73396cb8e33SPaul Moore return ret_val; 73496cb8e33SPaul Moore } 73596cb8e33SPaul Moore 73696cb8e33SPaul Moore /* 73796cb8e33SPaul Moore * NetLabel Generic NETLINK Command Definitions 73896cb8e33SPaul Moore */ 73996cb8e33SPaul Moore 7404534de83SJohannes Berg static const struct genl_ops netlbl_cipsov4_ops[] = { 741227c43c3SPavel Emelyanov { 74296cb8e33SPaul Moore .cmd = NLBL_CIPSOV4_C_ADD, 743fd385855SPaul Moore .flags = GENL_ADMIN_PERM, 744fd385855SPaul Moore .policy = netlbl_cipsov4_genl_policy, 74596cb8e33SPaul Moore .doit = netlbl_cipsov4_add, 74696cb8e33SPaul Moore .dumpit = NULL, 747227c43c3SPavel Emelyanov }, 748227c43c3SPavel Emelyanov { 74996cb8e33SPaul Moore .cmd = NLBL_CIPSOV4_C_REMOVE, 750fd385855SPaul Moore .flags = GENL_ADMIN_PERM, 751fd385855SPaul Moore .policy = netlbl_cipsov4_genl_policy, 75296cb8e33SPaul Moore .doit = netlbl_cipsov4_remove, 75396cb8e33SPaul Moore .dumpit = NULL, 754227c43c3SPavel Emelyanov }, 755227c43c3SPavel Emelyanov { 75696cb8e33SPaul Moore .cmd = NLBL_CIPSOV4_C_LIST, 75796cb8e33SPaul Moore .flags = 0, 758fd385855SPaul Moore .policy = netlbl_cipsov4_genl_policy, 75996cb8e33SPaul Moore .doit = netlbl_cipsov4_list, 76096cb8e33SPaul Moore .dumpit = NULL, 761227c43c3SPavel Emelyanov }, 762227c43c3SPavel Emelyanov { 76396cb8e33SPaul Moore .cmd = NLBL_CIPSOV4_C_LISTALL, 76496cb8e33SPaul Moore .flags = 0, 765fd385855SPaul Moore .policy = netlbl_cipsov4_genl_policy, 766fd385855SPaul Moore .doit = NULL, 767fd385855SPaul Moore .dumpit = netlbl_cipsov4_listall, 768227c43c3SPavel Emelyanov }, 76996cb8e33SPaul Moore }; 77096cb8e33SPaul Moore 77196cb8e33SPaul Moore /* 77296cb8e33SPaul Moore * NetLabel Generic NETLINK Protocol Functions 77396cb8e33SPaul Moore */ 77496cb8e33SPaul Moore 77596cb8e33SPaul Moore /** 77696cb8e33SPaul Moore * netlbl_cipsov4_genl_init - Register the CIPSOv4 NetLabel component 77796cb8e33SPaul Moore * 77896cb8e33SPaul Moore * Description: 77996cb8e33SPaul Moore * Register the CIPSOv4 packet NetLabel component with the Generic NETLINK 78096cb8e33SPaul Moore * mechanism. Returns zero on success, negative values on failure. 78196cb8e33SPaul Moore * 78296cb8e33SPaul Moore */ 78305705e4eSPavel Emelyanov int __init netlbl_cipsov4_genl_init(void) 78496cb8e33SPaul Moore { 7857ae740dfSMichał Mirosław return genl_register_family_with_ops(&netlbl_cipsov4_gnl_family, 786c53ed742SJohannes Berg netlbl_cipsov4_ops); 78796cb8e33SPaul Moore } 788