netlabel_calipso.c (a5e34490c3160e09814403d040765b0ae0003121) | netlabel_calipso.c (e1ce69df7e6e8cbdca78ae831ecf435b12b4c168) |
---|---|
1/* 2 * NetLabel CALIPSO/IPv6 Support 3 * 4 * This file defines the CALIPSO/IPv6 functions for the NetLabel system. The 5 * NetLabel system manages static and dynamic label mappings for network 6 * protocols such as CIPSO and CALIPSO. 7 * 8 * Authors: Paul Moore <paul@paul-moore.com> --- 32 unchanged lines hidden (view full) --- 41#include <net/calipso.h> 42#include <linux/atomic.h> 43 44#include "netlabel_user.h" 45#include "netlabel_calipso.h" 46#include "netlabel_mgmt.h" 47#include "netlabel_domainhash.h" 48 | 1/* 2 * NetLabel CALIPSO/IPv6 Support 3 * 4 * This file defines the CALIPSO/IPv6 functions for the NetLabel system. The 5 * NetLabel system manages static and dynamic label mappings for network 6 * protocols such as CIPSO and CALIPSO. 7 * 8 * Authors: Paul Moore <paul@paul-moore.com> --- 32 unchanged lines hidden (view full) --- 41#include <net/calipso.h> 42#include <linux/atomic.h> 43 44#include "netlabel_user.h" 45#include "netlabel_calipso.h" 46#include "netlabel_mgmt.h" 47#include "netlabel_domainhash.h" 48 |
49/* Argument struct for calipso_doi_walk() */ 50struct netlbl_calipso_doiwalk_arg { 51 struct netlink_callback *nl_cb; 52 struct sk_buff *skb; 53 u32 seq; 54}; 55 |
|
49/* NetLabel Generic NETLINK CALIPSO family */ 50static struct genl_family netlbl_calipso_gnl_family = { 51 .id = GENL_ID_GENERATE, 52 .hdrsize = 0, 53 .name = NETLBL_NLTYPE_CALIPSO_NAME, 54 .version = NETLBL_PROTO_VERSION, 55 .maxattr = NLBL_CALIPSO_A_MAX, 56}; --- 121 unchanged lines hidden (view full) --- 178 179list_failure_put: 180 calipso_doi_putdef(doi_def); 181list_failure: 182 kfree_skb(ans_skb); 183 return ret_val; 184} 185 | 56/* NetLabel Generic NETLINK CALIPSO family */ 57static struct genl_family netlbl_calipso_gnl_family = { 58 .id = GENL_ID_GENERATE, 59 .hdrsize = 0, 60 .name = NETLBL_NLTYPE_CALIPSO_NAME, 61 .version = NETLBL_PROTO_VERSION, 62 .maxattr = NLBL_CALIPSO_A_MAX, 63}; --- 121 unchanged lines hidden (view full) --- 185 186list_failure_put: 187 calipso_doi_putdef(doi_def); 188list_failure: 189 kfree_skb(ans_skb); 190 return ret_val; 191} 192 |
193/** 194 * netlbl_calipso_listall_cb - calipso_doi_walk() callback for LISTALL 195 * @doi_def: the CALIPSO DOI definition 196 * @arg: the netlbl_calipso_doiwalk_arg structure 197 * 198 * Description: 199 * This function is designed to be used as a callback to the 200 * calipso_doi_walk() function for use in generating a response for a LISTALL 201 * message. Returns the size of the message on success, negative values on 202 * failure. 203 * 204 */ 205static int netlbl_calipso_listall_cb(struct calipso_doi *doi_def, void *arg) 206{ 207 int ret_val = -ENOMEM; 208 struct netlbl_calipso_doiwalk_arg *cb_arg = arg; 209 void *data; 210 211 data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).portid, 212 cb_arg->seq, &netlbl_calipso_gnl_family, 213 NLM_F_MULTI, NLBL_CALIPSO_C_LISTALL); 214 if (!data) 215 goto listall_cb_failure; 216 217 ret_val = nla_put_u32(cb_arg->skb, NLBL_CALIPSO_A_DOI, doi_def->doi); 218 if (ret_val != 0) 219 goto listall_cb_failure; 220 ret_val = nla_put_u32(cb_arg->skb, 221 NLBL_CALIPSO_A_MTYPE, 222 doi_def->type); 223 if (ret_val != 0) 224 goto listall_cb_failure; 225 226 genlmsg_end(cb_arg->skb, data); 227 return 0; 228 229listall_cb_failure: 230 genlmsg_cancel(cb_arg->skb, data); 231 return ret_val; 232} 233 234/** 235 * netlbl_calipso_listall - Handle a LISTALL message 236 * @skb: the NETLINK buffer 237 * @cb: the NETLINK callback 238 * 239 * Description: 240 * Process a user generated LISTALL message and respond accordingly. Returns 241 * zero on success and negative values on error. 242 * 243 */ 244static int netlbl_calipso_listall(struct sk_buff *skb, 245 struct netlink_callback *cb) 246{ 247 struct netlbl_calipso_doiwalk_arg cb_arg; 248 u32 doi_skip = cb->args[0]; 249 250 cb_arg.nl_cb = cb; 251 cb_arg.skb = skb; 252 cb_arg.seq = cb->nlh->nlmsg_seq; 253 254 calipso_doi_walk(&doi_skip, netlbl_calipso_listall_cb, &cb_arg); 255 256 cb->args[0] = doi_skip; 257 return skb->len; 258} 259 |
|
186/* NetLabel Generic NETLINK Command Definitions 187 */ 188 189static const struct genl_ops netlbl_calipso_ops[] = { 190 { 191 .cmd = NLBL_CALIPSO_C_ADD, 192 .flags = GENL_ADMIN_PERM, 193 .policy = calipso_genl_policy, 194 .doit = netlbl_calipso_add, 195 .dumpit = NULL, 196 }, 197 { 198 .cmd = NLBL_CALIPSO_C_LIST, 199 .flags = 0, 200 .policy = calipso_genl_policy, 201 .doit = netlbl_calipso_list, 202 .dumpit = NULL, 203 }, | 260/* NetLabel Generic NETLINK Command Definitions 261 */ 262 263static const struct genl_ops netlbl_calipso_ops[] = { 264 { 265 .cmd = NLBL_CALIPSO_C_ADD, 266 .flags = GENL_ADMIN_PERM, 267 .policy = calipso_genl_policy, 268 .doit = netlbl_calipso_add, 269 .dumpit = NULL, 270 }, 271 { 272 .cmd = NLBL_CALIPSO_C_LIST, 273 .flags = 0, 274 .policy = calipso_genl_policy, 275 .doit = netlbl_calipso_list, 276 .dumpit = NULL, 277 }, |
278 { 279 .cmd = NLBL_CALIPSO_C_LISTALL, 280 .flags = 0, 281 .policy = calipso_genl_policy, 282 .doit = NULL, 283 .dumpit = netlbl_calipso_listall, 284 }, |
|
204}; 205 206/* NetLabel Generic NETLINK Protocol Functions 207 */ 208 209/** 210 * netlbl_calipso_genl_init - Register the CALIPSO NetLabel component 211 * --- 99 unchanged lines hidden (view full) --- 311 */ 312void calipso_doi_putdef(struct calipso_doi *doi_def) 313{ 314 const struct netlbl_calipso_ops *ops = netlbl_calipso_ops_get(); 315 316 if (ops) 317 ops->doi_putdef(doi_def); 318} | 285}; 286 287/* NetLabel Generic NETLINK Protocol Functions 288 */ 289 290/** 291 * netlbl_calipso_genl_init - Register the CALIPSO NetLabel component 292 * --- 99 unchanged lines hidden (view full) --- 392 */ 393void calipso_doi_putdef(struct calipso_doi *doi_def) 394{ 395 const struct netlbl_calipso_ops *ops = netlbl_calipso_ops_get(); 396 397 if (ops) 398 ops->doi_putdef(doi_def); 399} |
400 401/** 402 * calipso_doi_walk - Iterate through the DOI definitions 403 * @skip_cnt: skip past this number of DOI definitions, updated 404 * @callback: callback for each DOI definition 405 * @cb_arg: argument for the callback function 406 * 407 * Description: 408 * Iterate over the DOI definition list, skipping the first @skip_cnt entries. 409 * For each entry call @callback, if @callback returns a negative value stop 410 * 'walking' through the list and return. Updates the value in @skip_cnt upon 411 * return. Returns zero on success, negative values on failure. 412 * 413 */ 414int calipso_doi_walk(u32 *skip_cnt, 415 int (*callback)(struct calipso_doi *doi_def, void *arg), 416 void *cb_arg) 417{ 418 int ret_val = -ENOMSG; 419 const struct netlbl_calipso_ops *ops = netlbl_calipso_ops_get(); 420 421 if (ops) 422 ret_val = ops->doi_walk(skip_cnt, callback, cb_arg); 423 return ret_val; 424} |
|