@@ -53,6 +53,12 @@ struct netlbl_calipso_doiwalk_arg {
5353 u32 seq ;
5454};
5555
56+ /* Argument struct for netlbl_domhsh_walk() */
57+ struct netlbl_domhsh_walk_arg {
58+ struct netlbl_audit * audit_info ;
59+ u32 doi ;
60+ };
61+
5662/* NetLabel Generic NETLINK CALIPSO family */
5763static struct genl_family netlbl_calipso_gnl_family = {
5864 .id = GENL_ID_GENERATE ,
@@ -257,6 +263,64 @@ static int netlbl_calipso_listall(struct sk_buff *skb,
257263 return skb -> len ;
258264}
259265
266+ /**
267+ * netlbl_calipso_remove_cb - netlbl_calipso_remove() callback for REMOVE
268+ * @entry: LSM domain mapping entry
269+ * @arg: the netlbl_domhsh_walk_arg structure
270+ *
271+ * Description:
272+ * This function is intended for use by netlbl_calipso_remove() as the callback
273+ * for the netlbl_domhsh_walk() function; it removes LSM domain map entries
274+ * which are associated with the CALIPSO DOI specified in @arg. Returns zero on
275+ * success, negative values on failure.
276+ *
277+ */
278+ static int netlbl_calipso_remove_cb (struct netlbl_dom_map * entry , void * arg )
279+ {
280+ struct netlbl_domhsh_walk_arg * cb_arg = arg ;
281+
282+ if (entry -> def .type == NETLBL_NLTYPE_CALIPSO &&
283+ entry -> def .calipso -> doi == cb_arg -> doi )
284+ return netlbl_domhsh_remove_entry (entry , cb_arg -> audit_info );
285+
286+ return 0 ;
287+ }
288+
289+ /**
290+ * netlbl_calipso_remove - Handle a REMOVE message
291+ * @skb: the NETLINK buffer
292+ * @info: the Generic NETLINK info block
293+ *
294+ * Description:
295+ * Process a user generated REMOVE message and respond accordingly. Returns
296+ * zero on success, negative values on failure.
297+ *
298+ */
299+ static int netlbl_calipso_remove (struct sk_buff * skb , struct genl_info * info )
300+ {
301+ int ret_val = - EINVAL ;
302+ struct netlbl_domhsh_walk_arg cb_arg ;
303+ struct netlbl_audit audit_info ;
304+ u32 skip_bkt = 0 ;
305+ u32 skip_chain = 0 ;
306+
307+ if (!info -> attrs [NLBL_CALIPSO_A_DOI ])
308+ return - EINVAL ;
309+
310+ netlbl_netlink_auditinfo (skb , & audit_info );
311+ cb_arg .doi = nla_get_u32 (info -> attrs [NLBL_CALIPSO_A_DOI ]);
312+ cb_arg .audit_info = & audit_info ;
313+ ret_val = netlbl_domhsh_walk (& skip_bkt , & skip_chain ,
314+ netlbl_calipso_remove_cb , & cb_arg );
315+ if (ret_val == 0 || ret_val == - ENOENT ) {
316+ ret_val = calipso_doi_remove (cb_arg .doi , & audit_info );
317+ if (ret_val == 0 )
318+ atomic_dec (& netlabel_mgmt_protocount );
319+ }
320+
321+ return ret_val ;
322+ }
323+
260324/* NetLabel Generic NETLINK Command Definitions
261325 */
262326
@@ -269,6 +333,13 @@ static const struct genl_ops netlbl_calipso_ops[] = {
269333 .dumpit = NULL ,
270334 },
271335 {
336+ .cmd = NLBL_CALIPSO_C_REMOVE ,
337+ .flags = GENL_ADMIN_PERM ,
338+ .policy = calipso_genl_policy ,
339+ .doit = netlbl_calipso_remove ,
340+ .dumpit = NULL ,
341+ },
342+ {
272343 .cmd = NLBL_CALIPSO_C_LIST ,
273344 .flags = 0 ,
274345 .policy = calipso_genl_policy ,
@@ -362,6 +433,27 @@ void calipso_doi_free(struct calipso_doi *doi_def)
362433 ops -> doi_free (doi_def );
363434}
364435
436+ /**
437+ * calipso_doi_remove - Remove an existing DOI from the CALIPSO protocol engine
438+ * @doi: the DOI value
439+ * @audit_secid: the LSM secid to use in the audit message
440+ *
441+ * Description:
442+ * Removes a DOI definition from the CALIPSO engine. The NetLabel routines will
443+ * be called to release their own LSM domain mappings as well as our own
444+ * domain list. Returns zero on success and negative values on failure.
445+ *
446+ */
447+ int calipso_doi_remove (u32 doi , struct netlbl_audit * audit_info )
448+ {
449+ int ret_val = - ENOMSG ;
450+ const struct netlbl_calipso_ops * ops = netlbl_calipso_ops_get ();
451+
452+ if (ops )
453+ ret_val = ops -> doi_remove (doi , audit_info );
454+ return ret_val ;
455+ }
456+
365457/**
366458 * calipso_doi_getdef - Returns a reference to a valid DOI definition
367459 * @doi: the DOI value
0 commit comments