Path: blob/master/net/netlabel/netlabel_cipso_v4.c
15109 views
/*1* NetLabel CIPSO/IPv4 Support2*3* This file defines the CIPSO/IPv4 functions for the NetLabel system. The4* NetLabel system manages static and dynamic label mappings for network5* protocols such as CIPSO and RIPSO.6*7* Author: Paul Moore <[email protected]>8*9*/1011/*12* (c) Copyright Hewlett-Packard Development Company, L.P., 200613*14* This program is free software; you can redistribute it and/or modify15* it under the terms of the GNU General Public License as published by16* the Free Software Foundation; either version 2 of the License, or17* (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 of21* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See22* the GNU General Public License for more details.23*24* You should have received a copy of the GNU General Public License25* along with this program; if not, write to the Free Software26* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA27*28*/2930#include <linux/types.h>31#include <linux/socket.h>32#include <linux/string.h>33#include <linux/skbuff.h>34#include <linux/audit.h>35#include <linux/slab.h>36#include <net/sock.h>37#include <net/netlink.h>38#include <net/genetlink.h>39#include <net/netlabel.h>40#include <net/cipso_ipv4.h>41#include <asm/atomic.h>4243#include "netlabel_user.h"44#include "netlabel_cipso_v4.h"45#include "netlabel_mgmt.h"46#include "netlabel_domainhash.h"4748/* Argument struct for cipso_v4_doi_walk() */49struct netlbl_cipsov4_doiwalk_arg {50struct netlink_callback *nl_cb;51struct sk_buff *skb;52u32 seq;53};5455/* Argument struct for netlbl_domhsh_walk() */56struct netlbl_domhsh_walk_arg {57struct netlbl_audit *audit_info;58u32 doi;59};6061/* NetLabel Generic NETLINK CIPSOv4 family */62static struct genl_family netlbl_cipsov4_gnl_family = {63.id = GENL_ID_GENERATE,64.hdrsize = 0,65.name = NETLBL_NLTYPE_CIPSOV4_NAME,66.version = NETLBL_PROTO_VERSION,67.maxattr = NLBL_CIPSOV4_A_MAX,68};6970/* NetLabel Netlink attribute policy */71static const struct nla_policy netlbl_cipsov4_genl_policy[NLBL_CIPSOV4_A_MAX + 1] = {72[NLBL_CIPSOV4_A_DOI] = { .type = NLA_U32 },73[NLBL_CIPSOV4_A_MTYPE] = { .type = NLA_U32 },74[NLBL_CIPSOV4_A_TAG] = { .type = NLA_U8 },75[NLBL_CIPSOV4_A_TAGLST] = { .type = NLA_NESTED },76[NLBL_CIPSOV4_A_MLSLVLLOC] = { .type = NLA_U32 },77[NLBL_CIPSOV4_A_MLSLVLREM] = { .type = NLA_U32 },78[NLBL_CIPSOV4_A_MLSLVL] = { .type = NLA_NESTED },79[NLBL_CIPSOV4_A_MLSLVLLST] = { .type = NLA_NESTED },80[NLBL_CIPSOV4_A_MLSCATLOC] = { .type = NLA_U32 },81[NLBL_CIPSOV4_A_MLSCATREM] = { .type = NLA_U32 },82[NLBL_CIPSOV4_A_MLSCAT] = { .type = NLA_NESTED },83[NLBL_CIPSOV4_A_MLSCATLST] = { .type = NLA_NESTED },84};8586/*87* Helper Functions88*/8990/**91* netlbl_cipsov4_add_common - Parse the common sections of a ADD message92* @info: the Generic NETLINK info block93* @doi_def: the CIPSO V4 DOI definition94*95* Description:96* Parse the common sections of a ADD message and fill in the related values97* in @doi_def. Returns zero on success, negative values on failure.98*99*/100static int netlbl_cipsov4_add_common(struct genl_info *info,101struct cipso_v4_doi *doi_def)102{103struct nlattr *nla;104int nla_rem;105u32 iter = 0;106107doi_def->doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);108109if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_TAGLST],110NLBL_CIPSOV4_A_MAX,111netlbl_cipsov4_genl_policy) != 0)112return -EINVAL;113114nla_for_each_nested(nla, info->attrs[NLBL_CIPSOV4_A_TAGLST], nla_rem)115if (nla_type(nla) == NLBL_CIPSOV4_A_TAG) {116if (iter >= CIPSO_V4_TAG_MAXCNT)117return -EINVAL;118doi_def->tags[iter++] = nla_get_u8(nla);119}120while (iter < CIPSO_V4_TAG_MAXCNT)121doi_def->tags[iter++] = CIPSO_V4_TAG_INVALID;122123return 0;124}125126/*127* NetLabel Command Handlers128*/129130/**131* netlbl_cipsov4_add_std - Adds a CIPSO V4 DOI definition132* @info: the Generic NETLINK info block133* @audit_info: NetLabel audit information134*135* Description:136* Create a new CIPSO_V4_MAP_TRANS DOI definition based on the given ADD137* message and add it to the CIPSO V4 engine. Return zero on success and138* non-zero on error.139*140*/141static int netlbl_cipsov4_add_std(struct genl_info *info,142struct netlbl_audit *audit_info)143{144int ret_val = -EINVAL;145struct cipso_v4_doi *doi_def = NULL;146struct nlattr *nla_a;147struct nlattr *nla_b;148int nla_a_rem;149int nla_b_rem;150u32 iter;151152if (!info->attrs[NLBL_CIPSOV4_A_TAGLST] ||153!info->attrs[NLBL_CIPSOV4_A_MLSLVLLST])154return -EINVAL;155156if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSLVLLST],157NLBL_CIPSOV4_A_MAX,158netlbl_cipsov4_genl_policy) != 0)159return -EINVAL;160161doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);162if (doi_def == NULL)163return -ENOMEM;164doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);165if (doi_def->map.std == NULL) {166ret_val = -ENOMEM;167goto add_std_failure;168}169doi_def->type = CIPSO_V4_MAP_TRANS;170171ret_val = netlbl_cipsov4_add_common(info, doi_def);172if (ret_val != 0)173goto add_std_failure;174ret_val = -EINVAL;175176nla_for_each_nested(nla_a,177info->attrs[NLBL_CIPSOV4_A_MLSLVLLST],178nla_a_rem)179if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) {180if (nla_validate_nested(nla_a,181NLBL_CIPSOV4_A_MAX,182netlbl_cipsov4_genl_policy) != 0)183goto add_std_failure;184nla_for_each_nested(nla_b, nla_a, nla_b_rem)185switch (nla_type(nla_b)) {186case NLBL_CIPSOV4_A_MLSLVLLOC:187if (nla_get_u32(nla_b) >188CIPSO_V4_MAX_LOC_LVLS)189goto add_std_failure;190if (nla_get_u32(nla_b) >=191doi_def->map.std->lvl.local_size)192doi_def->map.std->lvl.local_size =193nla_get_u32(nla_b) + 1;194break;195case NLBL_CIPSOV4_A_MLSLVLREM:196if (nla_get_u32(nla_b) >197CIPSO_V4_MAX_REM_LVLS)198goto add_std_failure;199if (nla_get_u32(nla_b) >=200doi_def->map.std->lvl.cipso_size)201doi_def->map.std->lvl.cipso_size =202nla_get_u32(nla_b) + 1;203break;204}205}206doi_def->map.std->lvl.local = kcalloc(doi_def->map.std->lvl.local_size,207sizeof(u32),208GFP_KERNEL);209if (doi_def->map.std->lvl.local == NULL) {210ret_val = -ENOMEM;211goto add_std_failure;212}213doi_def->map.std->lvl.cipso = kcalloc(doi_def->map.std->lvl.cipso_size,214sizeof(u32),215GFP_KERNEL);216if (doi_def->map.std->lvl.cipso == NULL) {217ret_val = -ENOMEM;218goto add_std_failure;219}220for (iter = 0; iter < doi_def->map.std->lvl.local_size; iter++)221doi_def->map.std->lvl.local[iter] = CIPSO_V4_INV_LVL;222for (iter = 0; iter < doi_def->map.std->lvl.cipso_size; iter++)223doi_def->map.std->lvl.cipso[iter] = CIPSO_V4_INV_LVL;224nla_for_each_nested(nla_a,225info->attrs[NLBL_CIPSOV4_A_MLSLVLLST],226nla_a_rem)227if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSLVL) {228struct nlattr *lvl_loc;229struct nlattr *lvl_rem;230231lvl_loc = nla_find_nested(nla_a,232NLBL_CIPSOV4_A_MLSLVLLOC);233lvl_rem = nla_find_nested(nla_a,234NLBL_CIPSOV4_A_MLSLVLREM);235if (lvl_loc == NULL || lvl_rem == NULL)236goto add_std_failure;237doi_def->map.std->lvl.local[nla_get_u32(lvl_loc)] =238nla_get_u32(lvl_rem);239doi_def->map.std->lvl.cipso[nla_get_u32(lvl_rem)] =240nla_get_u32(lvl_loc);241}242243if (info->attrs[NLBL_CIPSOV4_A_MLSCATLST]) {244if (nla_validate_nested(info->attrs[NLBL_CIPSOV4_A_MLSCATLST],245NLBL_CIPSOV4_A_MAX,246netlbl_cipsov4_genl_policy) != 0)247goto add_std_failure;248249nla_for_each_nested(nla_a,250info->attrs[NLBL_CIPSOV4_A_MLSCATLST],251nla_a_rem)252if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) {253if (nla_validate_nested(nla_a,254NLBL_CIPSOV4_A_MAX,255netlbl_cipsov4_genl_policy) != 0)256goto add_std_failure;257nla_for_each_nested(nla_b, nla_a, nla_b_rem)258switch (nla_type(nla_b)) {259case NLBL_CIPSOV4_A_MLSCATLOC:260if (nla_get_u32(nla_b) >261CIPSO_V4_MAX_LOC_CATS)262goto add_std_failure;263if (nla_get_u32(nla_b) >=264doi_def->map.std->cat.local_size)265doi_def->map.std->cat.local_size =266nla_get_u32(nla_b) + 1;267break;268case NLBL_CIPSOV4_A_MLSCATREM:269if (nla_get_u32(nla_b) >270CIPSO_V4_MAX_REM_CATS)271goto add_std_failure;272if (nla_get_u32(nla_b) >=273doi_def->map.std->cat.cipso_size)274doi_def->map.std->cat.cipso_size =275nla_get_u32(nla_b) + 1;276break;277}278}279doi_def->map.std->cat.local = kcalloc(280doi_def->map.std->cat.local_size,281sizeof(u32),282GFP_KERNEL);283if (doi_def->map.std->cat.local == NULL) {284ret_val = -ENOMEM;285goto add_std_failure;286}287doi_def->map.std->cat.cipso = kcalloc(288doi_def->map.std->cat.cipso_size,289sizeof(u32),290GFP_KERNEL);291if (doi_def->map.std->cat.cipso == NULL) {292ret_val = -ENOMEM;293goto add_std_failure;294}295for (iter = 0; iter < doi_def->map.std->cat.local_size; iter++)296doi_def->map.std->cat.local[iter] = CIPSO_V4_INV_CAT;297for (iter = 0; iter < doi_def->map.std->cat.cipso_size; iter++)298doi_def->map.std->cat.cipso[iter] = CIPSO_V4_INV_CAT;299nla_for_each_nested(nla_a,300info->attrs[NLBL_CIPSOV4_A_MLSCATLST],301nla_a_rem)302if (nla_type(nla_a) == NLBL_CIPSOV4_A_MLSCAT) {303struct nlattr *cat_loc;304struct nlattr *cat_rem;305306cat_loc = nla_find_nested(nla_a,307NLBL_CIPSOV4_A_MLSCATLOC);308cat_rem = nla_find_nested(nla_a,309NLBL_CIPSOV4_A_MLSCATREM);310if (cat_loc == NULL || cat_rem == NULL)311goto add_std_failure;312doi_def->map.std->cat.local[313nla_get_u32(cat_loc)] =314nla_get_u32(cat_rem);315doi_def->map.std->cat.cipso[316nla_get_u32(cat_rem)] =317nla_get_u32(cat_loc);318}319}320321ret_val = cipso_v4_doi_add(doi_def, audit_info);322if (ret_val != 0)323goto add_std_failure;324return 0;325326add_std_failure:327if (doi_def)328cipso_v4_doi_free(doi_def);329return ret_val;330}331332/**333* netlbl_cipsov4_add_pass - Adds a CIPSO V4 DOI definition334* @info: the Generic NETLINK info block335* @audit_info: NetLabel audit information336*337* Description:338* Create a new CIPSO_V4_MAP_PASS DOI definition based on the given ADD message339* and add it to the CIPSO V4 engine. Return zero on success and non-zero on340* error.341*342*/343static int netlbl_cipsov4_add_pass(struct genl_info *info,344struct netlbl_audit *audit_info)345{346int ret_val;347struct cipso_v4_doi *doi_def = NULL;348349if (!info->attrs[NLBL_CIPSOV4_A_TAGLST])350return -EINVAL;351352doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);353if (doi_def == NULL)354return -ENOMEM;355doi_def->type = CIPSO_V4_MAP_PASS;356357ret_val = netlbl_cipsov4_add_common(info, doi_def);358if (ret_val != 0)359goto add_pass_failure;360361ret_val = cipso_v4_doi_add(doi_def, audit_info);362if (ret_val != 0)363goto add_pass_failure;364return 0;365366add_pass_failure:367cipso_v4_doi_free(doi_def);368return ret_val;369}370371/**372* netlbl_cipsov4_add_local - Adds a CIPSO V4 DOI definition373* @info: the Generic NETLINK info block374* @audit_info: NetLabel audit information375*376* Description:377* Create a new CIPSO_V4_MAP_LOCAL DOI definition based on the given ADD378* message and add it to the CIPSO V4 engine. Return zero on success and379* non-zero on error.380*381*/382static int netlbl_cipsov4_add_local(struct genl_info *info,383struct netlbl_audit *audit_info)384{385int ret_val;386struct cipso_v4_doi *doi_def = NULL;387388if (!info->attrs[NLBL_CIPSOV4_A_TAGLST])389return -EINVAL;390391doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);392if (doi_def == NULL)393return -ENOMEM;394doi_def->type = CIPSO_V4_MAP_LOCAL;395396ret_val = netlbl_cipsov4_add_common(info, doi_def);397if (ret_val != 0)398goto add_local_failure;399400ret_val = cipso_v4_doi_add(doi_def, audit_info);401if (ret_val != 0)402goto add_local_failure;403return 0;404405add_local_failure:406cipso_v4_doi_free(doi_def);407return ret_val;408}409410/**411* netlbl_cipsov4_add - Handle an ADD message412* @skb: the NETLINK buffer413* @info: the Generic NETLINK info block414*415* Description:416* Create a new DOI definition based on the given ADD message and add it to the417* CIPSO V4 engine. Returns zero on success, negative values on failure.418*419*/420static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info)421422{423int ret_val = -EINVAL;424struct netlbl_audit audit_info;425426if (!info->attrs[NLBL_CIPSOV4_A_DOI] ||427!info->attrs[NLBL_CIPSOV4_A_MTYPE])428return -EINVAL;429430netlbl_netlink_auditinfo(skb, &audit_info);431switch (nla_get_u32(info->attrs[NLBL_CIPSOV4_A_MTYPE])) {432case CIPSO_V4_MAP_TRANS:433ret_val = netlbl_cipsov4_add_std(info, &audit_info);434break;435case CIPSO_V4_MAP_PASS:436ret_val = netlbl_cipsov4_add_pass(info, &audit_info);437break;438case CIPSO_V4_MAP_LOCAL:439ret_val = netlbl_cipsov4_add_local(info, &audit_info);440break;441}442if (ret_val == 0)443atomic_inc(&netlabel_mgmt_protocount);444445return ret_val;446}447448/**449* netlbl_cipsov4_list - Handle a LIST message450* @skb: the NETLINK buffer451* @info: the Generic NETLINK info block452*453* Description:454* Process a user generated LIST message and respond accordingly. While the455* response message generated by the kernel is straightforward, determining456* before hand the size of the buffer to allocate is not (we have to generate457* the message to know the size). In order to keep this function sane what we458* do is allocate a buffer of NLMSG_GOODSIZE and try to fit the response in459* that size, if we fail then we restart with a larger buffer and try again.460* We continue in this manner until we hit a limit of failed attempts then we461* give up and just send an error message. Returns zero on success and462* negative values on error.463*464*/465static int netlbl_cipsov4_list(struct sk_buff *skb, struct genl_info *info)466{467int ret_val;468struct sk_buff *ans_skb = NULL;469u32 nlsze_mult = 1;470void *data;471u32 doi;472struct nlattr *nla_a;473struct nlattr *nla_b;474struct cipso_v4_doi *doi_def;475u32 iter;476477if (!info->attrs[NLBL_CIPSOV4_A_DOI]) {478ret_val = -EINVAL;479goto list_failure;480}481482list_start:483ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE * nlsze_mult, GFP_KERNEL);484if (ans_skb == NULL) {485ret_val = -ENOMEM;486goto list_failure;487}488data = genlmsg_put_reply(ans_skb, info, &netlbl_cipsov4_gnl_family,4890, NLBL_CIPSOV4_C_LIST);490if (data == NULL) {491ret_val = -ENOMEM;492goto list_failure;493}494495doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);496497rcu_read_lock();498doi_def = cipso_v4_doi_getdef(doi);499if (doi_def == NULL) {500ret_val = -EINVAL;501goto list_failure_lock;502}503504ret_val = nla_put_u32(ans_skb, NLBL_CIPSOV4_A_MTYPE, doi_def->type);505if (ret_val != 0)506goto list_failure_lock;507508nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_TAGLST);509if (nla_a == NULL) {510ret_val = -ENOMEM;511goto list_failure_lock;512}513for (iter = 0;514iter < CIPSO_V4_TAG_MAXCNT &&515doi_def->tags[iter] != CIPSO_V4_TAG_INVALID;516iter++) {517ret_val = nla_put_u8(ans_skb,518NLBL_CIPSOV4_A_TAG,519doi_def->tags[iter]);520if (ret_val != 0)521goto list_failure_lock;522}523nla_nest_end(ans_skb, nla_a);524525switch (doi_def->type) {526case CIPSO_V4_MAP_TRANS:527nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVLLST);528if (nla_a == NULL) {529ret_val = -ENOMEM;530goto list_failure_lock;531}532for (iter = 0;533iter < doi_def->map.std->lvl.local_size;534iter++) {535if (doi_def->map.std->lvl.local[iter] ==536CIPSO_V4_INV_LVL)537continue;538539nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSLVL);540if (nla_b == NULL) {541ret_val = -ENOMEM;542goto list_retry;543}544ret_val = nla_put_u32(ans_skb,545NLBL_CIPSOV4_A_MLSLVLLOC,546iter);547if (ret_val != 0)548goto list_retry;549ret_val = nla_put_u32(ans_skb,550NLBL_CIPSOV4_A_MLSLVLREM,551doi_def->map.std->lvl.local[iter]);552if (ret_val != 0)553goto list_retry;554nla_nest_end(ans_skb, nla_b);555}556nla_nest_end(ans_skb, nla_a);557558nla_a = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCATLST);559if (nla_a == NULL) {560ret_val = -ENOMEM;561goto list_retry;562}563for (iter = 0;564iter < doi_def->map.std->cat.local_size;565iter++) {566if (doi_def->map.std->cat.local[iter] ==567CIPSO_V4_INV_CAT)568continue;569570nla_b = nla_nest_start(ans_skb, NLBL_CIPSOV4_A_MLSCAT);571if (nla_b == NULL) {572ret_val = -ENOMEM;573goto list_retry;574}575ret_val = nla_put_u32(ans_skb,576NLBL_CIPSOV4_A_MLSCATLOC,577iter);578if (ret_val != 0)579goto list_retry;580ret_val = nla_put_u32(ans_skb,581NLBL_CIPSOV4_A_MLSCATREM,582doi_def->map.std->cat.local[iter]);583if (ret_val != 0)584goto list_retry;585nla_nest_end(ans_skb, nla_b);586}587nla_nest_end(ans_skb, nla_a);588589break;590}591rcu_read_unlock();592593genlmsg_end(ans_skb, data);594return genlmsg_reply(ans_skb, info);595596list_retry:597/* XXX - this limit is a guesstimate */598if (nlsze_mult < 4) {599rcu_read_unlock();600kfree_skb(ans_skb);601nlsze_mult *= 2;602goto list_start;603}604list_failure_lock:605rcu_read_unlock();606list_failure:607kfree_skb(ans_skb);608return ret_val;609}610611/**612* netlbl_cipsov4_listall_cb - cipso_v4_doi_walk() callback for LISTALL613* @doi_def: the CIPSOv4 DOI definition614* @arg: the netlbl_cipsov4_doiwalk_arg structure615*616* Description:617* This function is designed to be used as a callback to the618* cipso_v4_doi_walk() function for use in generating a response for a LISTALL619* message. Returns the size of the message on success, negative values on620* failure.621*622*/623static int netlbl_cipsov4_listall_cb(struct cipso_v4_doi *doi_def, void *arg)624{625int ret_val = -ENOMEM;626struct netlbl_cipsov4_doiwalk_arg *cb_arg = arg;627void *data;628629data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).pid,630cb_arg->seq, &netlbl_cipsov4_gnl_family,631NLM_F_MULTI, NLBL_CIPSOV4_C_LISTALL);632if (data == NULL)633goto listall_cb_failure;634635ret_val = nla_put_u32(cb_arg->skb, NLBL_CIPSOV4_A_DOI, doi_def->doi);636if (ret_val != 0)637goto listall_cb_failure;638ret_val = nla_put_u32(cb_arg->skb,639NLBL_CIPSOV4_A_MTYPE,640doi_def->type);641if (ret_val != 0)642goto listall_cb_failure;643644return genlmsg_end(cb_arg->skb, data);645646listall_cb_failure:647genlmsg_cancel(cb_arg->skb, data);648return ret_val;649}650651/**652* netlbl_cipsov4_listall - Handle a LISTALL message653* @skb: the NETLINK buffer654* @cb: the NETLINK callback655*656* Description:657* Process a user generated LISTALL message and respond accordingly. Returns658* zero on success and negative values on error.659*660*/661static int netlbl_cipsov4_listall(struct sk_buff *skb,662struct netlink_callback *cb)663{664struct netlbl_cipsov4_doiwalk_arg cb_arg;665u32 doi_skip = cb->args[0];666667cb_arg.nl_cb = cb;668cb_arg.skb = skb;669cb_arg.seq = cb->nlh->nlmsg_seq;670671cipso_v4_doi_walk(&doi_skip, netlbl_cipsov4_listall_cb, &cb_arg);672673cb->args[0] = doi_skip;674return skb->len;675}676677/**678* netlbl_cipsov4_remove_cb - netlbl_cipsov4_remove() callback for REMOVE679* @entry: LSM domain mapping entry680* @arg: the netlbl_domhsh_walk_arg structure681*682* Description:683* This function is intended for use by netlbl_cipsov4_remove() as the callback684* for the netlbl_domhsh_walk() function; it removes LSM domain map entries685* which are associated with the CIPSO DOI specified in @arg. Returns zero on686* success, negative values on failure.687*688*/689static int netlbl_cipsov4_remove_cb(struct netlbl_dom_map *entry, void *arg)690{691struct netlbl_domhsh_walk_arg *cb_arg = arg;692693if (entry->type == NETLBL_NLTYPE_CIPSOV4 &&694entry->type_def.cipsov4->doi == cb_arg->doi)695return netlbl_domhsh_remove_entry(entry, cb_arg->audit_info);696697return 0;698}699700/**701* netlbl_cipsov4_remove - Handle a REMOVE message702* @skb: the NETLINK buffer703* @info: the Generic NETLINK info block704*705* Description:706* Process a user generated REMOVE message and respond accordingly. Returns707* zero on success, negative values on failure.708*709*/710static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)711{712int ret_val = -EINVAL;713struct netlbl_domhsh_walk_arg cb_arg;714struct netlbl_audit audit_info;715u32 skip_bkt = 0;716u32 skip_chain = 0;717718if (!info->attrs[NLBL_CIPSOV4_A_DOI])719return -EINVAL;720721netlbl_netlink_auditinfo(skb, &audit_info);722cb_arg.doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);723cb_arg.audit_info = &audit_info;724ret_val = netlbl_domhsh_walk(&skip_bkt, &skip_chain,725netlbl_cipsov4_remove_cb, &cb_arg);726if (ret_val == 0 || ret_val == -ENOENT) {727ret_val = cipso_v4_doi_remove(cb_arg.doi, &audit_info);728if (ret_val == 0)729atomic_dec(&netlabel_mgmt_protocount);730}731732return ret_val;733}734735/*736* NetLabel Generic NETLINK Command Definitions737*/738739static struct genl_ops netlbl_cipsov4_ops[] = {740{741.cmd = NLBL_CIPSOV4_C_ADD,742.flags = GENL_ADMIN_PERM,743.policy = netlbl_cipsov4_genl_policy,744.doit = netlbl_cipsov4_add,745.dumpit = NULL,746},747{748.cmd = NLBL_CIPSOV4_C_REMOVE,749.flags = GENL_ADMIN_PERM,750.policy = netlbl_cipsov4_genl_policy,751.doit = netlbl_cipsov4_remove,752.dumpit = NULL,753},754{755.cmd = NLBL_CIPSOV4_C_LIST,756.flags = 0,757.policy = netlbl_cipsov4_genl_policy,758.doit = netlbl_cipsov4_list,759.dumpit = NULL,760},761{762.cmd = NLBL_CIPSOV4_C_LISTALL,763.flags = 0,764.policy = netlbl_cipsov4_genl_policy,765.doit = NULL,766.dumpit = netlbl_cipsov4_listall,767},768};769770/*771* NetLabel Generic NETLINK Protocol Functions772*/773774/**775* netlbl_cipsov4_genl_init - Register the CIPSOv4 NetLabel component776*777* Description:778* Register the CIPSOv4 packet NetLabel component with the Generic NETLINK779* mechanism. Returns zero on success, negative values on failure.780*781*/782int __init netlbl_cipsov4_genl_init(void)783{784return genl_register_family_with_ops(&netlbl_cipsov4_gnl_family,785netlbl_cipsov4_ops, ARRAY_SIZE(netlbl_cipsov4_ops));786}787788789