netlabel_mgmt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  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. *
  8. * Author: Paul Moore <paul.moore@hp.com>
  9. *
  10. */
  11. /*
  12. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (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 of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  22. * the GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #include <linux/types.h>
  30. #include <linux/socket.h>
  31. #include <linux/string.h>
  32. #include <linux/skbuff.h>
  33. #include <net/sock.h>
  34. #include <net/netlink.h>
  35. #include <net/genetlink.h>
  36. #include <net/netlabel.h>
  37. #include <net/cipso_ipv4.h>
  38. #include "netlabel_domainhash.h"
  39. #include "netlabel_user.h"
  40. #include "netlabel_mgmt.h"
  41. /* NetLabel configured protocol count */
  42. static DEFINE_SPINLOCK(netlabel_mgmt_protocount_lock);
  43. static u32 netlabel_mgmt_protocount = 0;
  44. /* Argument struct for netlbl_domhsh_walk() */
  45. struct netlbl_domhsh_walk_arg {
  46. struct netlink_callback *nl_cb;
  47. struct sk_buff *skb;
  48. u32 seq;
  49. };
  50. /* NetLabel Generic NETLINK CIPSOv4 family */
  51. static struct genl_family netlbl_mgmt_gnl_family = {
  52. .id = GENL_ID_GENERATE,
  53. .hdrsize = 0,
  54. .name = NETLBL_NLTYPE_MGMT_NAME,
  55. .version = NETLBL_PROTO_VERSION,
  56. .maxattr = NLBL_MGMT_A_MAX,
  57. };
  58. /* NetLabel Netlink attribute policy */
  59. static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = {
  60. [NLBL_MGMT_A_DOMAIN] = { .type = NLA_NUL_STRING },
  61. [NLBL_MGMT_A_PROTOCOL] = { .type = NLA_U32 },
  62. [NLBL_MGMT_A_VERSION] = { .type = NLA_U32 },
  63. [NLBL_MGMT_A_CV4DOI] = { .type = NLA_U32 },
  64. };
  65. /*
  66. * NetLabel Misc Management Functions
  67. */
  68. /**
  69. * netlbl_mgmt_protocount_inc - Increment the configured labeled protocol count
  70. *
  71. * Description:
  72. * Increment the number of labeled protocol configurations in the current
  73. * NetLabel configuration. Keep track of this for use in determining if
  74. * NetLabel label enforcement should be active/enabled or not in the LSM.
  75. *
  76. */
  77. void netlbl_mgmt_protocount_inc(void)
  78. {
  79. spin_lock(&netlabel_mgmt_protocount_lock);
  80. netlabel_mgmt_protocount++;
  81. spin_unlock(&netlabel_mgmt_protocount_lock);
  82. }
  83. /**
  84. * netlbl_mgmt_protocount_dec - Decrement the configured labeled protocol count
  85. *
  86. * Description:
  87. * Decrement the number of labeled protocol configurations in the current
  88. * NetLabel configuration. Keep track of this for use in determining if
  89. * NetLabel label enforcement should be active/enabled or not in the LSM.
  90. *
  91. */
  92. void netlbl_mgmt_protocount_dec(void)
  93. {
  94. spin_lock(&netlabel_mgmt_protocount_lock);
  95. if (netlabel_mgmt_protocount > 0)
  96. netlabel_mgmt_protocount--;
  97. spin_unlock(&netlabel_mgmt_protocount_lock);
  98. }
  99. /**
  100. * netlbl_mgmt_protocount_value - Return the number of configured protocols
  101. *
  102. * Description:
  103. * Return the number of labeled protocols in the current NetLabel
  104. * configuration. This value is useful in determining if NetLabel label
  105. * enforcement should be active/enabled or not in the LSM.
  106. *
  107. */
  108. u32 netlbl_mgmt_protocount_value(void)
  109. {
  110. u32 val;
  111. rcu_read_lock();
  112. val = netlabel_mgmt_protocount;
  113. rcu_read_unlock();
  114. return val;
  115. }
  116. /*
  117. * NetLabel Command Handlers
  118. */
  119. /**
  120. * netlbl_mgmt_add - Handle an ADD message
  121. * @skb: the NETLINK buffer
  122. * @info: the Generic NETLINK info block
  123. *
  124. * Description:
  125. * Process a user generated ADD message and add the domains from the message
  126. * to the hash table. See netlabel.h for a description of the message format.
  127. * Returns zero on success, negative values on failure.
  128. *
  129. */
  130. static int netlbl_mgmt_add(struct sk_buff *skb, struct genl_info *info)
  131. {
  132. int ret_val = -EINVAL;
  133. struct netlbl_dom_map *entry = NULL;
  134. size_t tmp_size;
  135. u32 tmp_val;
  136. struct netlbl_audit audit_info;
  137. if (!info->attrs[NLBL_MGMT_A_DOMAIN] ||
  138. !info->attrs[NLBL_MGMT_A_PROTOCOL])
  139. goto add_failure;
  140. netlbl_netlink_auditinfo(skb, &audit_info);
  141. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  142. if (entry == NULL) {
  143. ret_val = -ENOMEM;
  144. goto add_failure;
  145. }
  146. tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
  147. entry->domain = kmalloc(tmp_size, GFP_KERNEL);
  148. if (entry->domain == NULL) {
  149. ret_val = -ENOMEM;
  150. goto add_failure;
  151. }
  152. entry->type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
  153. nla_strlcpy(entry->domain, info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
  154. switch (entry->type) {
  155. case NETLBL_NLTYPE_UNLABELED:
  156. ret_val = netlbl_domhsh_add(entry, &audit_info);
  157. break;
  158. case NETLBL_NLTYPE_CIPSOV4:
  159. if (!info->attrs[NLBL_MGMT_A_CV4DOI])
  160. goto add_failure;
  161. tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
  162. /* We should be holding a rcu_read_lock() here while we hold
  163. * the result but since the entry will always be deleted when
  164. * the CIPSO DOI is deleted we aren't going to keep the
  165. * lock. */
  166. rcu_read_lock();
  167. entry->type_def.cipsov4 = cipso_v4_doi_getdef(tmp_val);
  168. if (entry->type_def.cipsov4 == NULL) {
  169. rcu_read_unlock();
  170. goto add_failure;
  171. }
  172. ret_val = netlbl_domhsh_add(entry, &audit_info);
  173. rcu_read_unlock();
  174. break;
  175. default:
  176. goto add_failure;
  177. }
  178. if (ret_val != 0)
  179. goto add_failure;
  180. return 0;
  181. add_failure:
  182. if (entry)
  183. kfree(entry->domain);
  184. kfree(entry);
  185. return ret_val;
  186. }
  187. /**
  188. * netlbl_mgmt_remove - Handle a REMOVE message
  189. * @skb: the NETLINK buffer
  190. * @info: the Generic NETLINK info block
  191. *
  192. * Description:
  193. * Process a user generated REMOVE message and remove the specified domain
  194. * mappings. Returns zero on success, negative values on failure.
  195. *
  196. */
  197. static int netlbl_mgmt_remove(struct sk_buff *skb, struct genl_info *info)
  198. {
  199. char *domain;
  200. struct netlbl_audit audit_info;
  201. if (!info->attrs[NLBL_MGMT_A_DOMAIN])
  202. return -EINVAL;
  203. netlbl_netlink_auditinfo(skb, &audit_info);
  204. domain = nla_data(info->attrs[NLBL_MGMT_A_DOMAIN]);
  205. return netlbl_domhsh_remove(domain, &audit_info);
  206. }
  207. /**
  208. * netlbl_mgmt_listall_cb - netlbl_domhsh_walk() callback for LISTALL
  209. * @entry: the domain mapping hash table entry
  210. * @arg: the netlbl_domhsh_walk_arg structure
  211. *
  212. * Description:
  213. * This function is designed to be used as a callback to the
  214. * netlbl_domhsh_walk() function for use in generating a response for a LISTALL
  215. * message. Returns the size of the message on success, negative values on
  216. * failure.
  217. *
  218. */
  219. static int netlbl_mgmt_listall_cb(struct netlbl_dom_map *entry, void *arg)
  220. {
  221. int ret_val = -ENOMEM;
  222. struct netlbl_domhsh_walk_arg *cb_arg = arg;
  223. void *data;
  224. data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).pid,
  225. cb_arg->seq, &netlbl_mgmt_gnl_family,
  226. NLM_F_MULTI, NLBL_MGMT_C_LISTALL);
  227. if (data == NULL)
  228. goto listall_cb_failure;
  229. ret_val = nla_put_string(cb_arg->skb,
  230. NLBL_MGMT_A_DOMAIN,
  231. entry->domain);
  232. if (ret_val != 0)
  233. goto listall_cb_failure;
  234. ret_val = nla_put_u32(cb_arg->skb, NLBL_MGMT_A_PROTOCOL, entry->type);
  235. if (ret_val != 0)
  236. goto listall_cb_failure;
  237. switch (entry->type) {
  238. case NETLBL_NLTYPE_CIPSOV4:
  239. ret_val = nla_put_u32(cb_arg->skb,
  240. NLBL_MGMT_A_CV4DOI,
  241. entry->type_def.cipsov4->doi);
  242. if (ret_val != 0)
  243. goto listall_cb_failure;
  244. break;
  245. }
  246. cb_arg->seq++;
  247. return genlmsg_end(cb_arg->skb, data);
  248. listall_cb_failure:
  249. genlmsg_cancel(cb_arg->skb, data);
  250. return ret_val;
  251. }
  252. /**
  253. * netlbl_mgmt_listall - Handle a LISTALL message
  254. * @skb: the NETLINK buffer
  255. * @cb: the NETLINK callback
  256. *
  257. * Description:
  258. * Process a user generated LISTALL message and dumps the domain hash table in
  259. * a form suitable for use in a kernel generated LISTALL message. Returns zero
  260. * on success, negative values on failure.
  261. *
  262. */
  263. static int netlbl_mgmt_listall(struct sk_buff *skb,
  264. struct netlink_callback *cb)
  265. {
  266. struct netlbl_domhsh_walk_arg cb_arg;
  267. u32 skip_bkt = cb->args[0];
  268. u32 skip_chain = cb->args[1];
  269. cb_arg.nl_cb = cb;
  270. cb_arg.skb = skb;
  271. cb_arg.seq = cb->nlh->nlmsg_seq;
  272. netlbl_domhsh_walk(&skip_bkt,
  273. &skip_chain,
  274. netlbl_mgmt_listall_cb,
  275. &cb_arg);
  276. cb->args[0] = skip_bkt;
  277. cb->args[1] = skip_chain;
  278. return skb->len;
  279. }
  280. /**
  281. * netlbl_mgmt_adddef - Handle an ADDDEF message
  282. * @skb: the NETLINK buffer
  283. * @info: the Generic NETLINK info block
  284. *
  285. * Description:
  286. * Process a user generated ADDDEF message and respond accordingly. Returns
  287. * zero on success, negative values on failure.
  288. *
  289. */
  290. static int netlbl_mgmt_adddef(struct sk_buff *skb, struct genl_info *info)
  291. {
  292. int ret_val = -EINVAL;
  293. struct netlbl_dom_map *entry = NULL;
  294. u32 tmp_val;
  295. struct netlbl_audit audit_info;
  296. if (!info->attrs[NLBL_MGMT_A_PROTOCOL])
  297. goto adddef_failure;
  298. netlbl_netlink_auditinfo(skb, &audit_info);
  299. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  300. if (entry == NULL) {
  301. ret_val = -ENOMEM;
  302. goto adddef_failure;
  303. }
  304. entry->type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
  305. switch (entry->type) {
  306. case NETLBL_NLTYPE_UNLABELED:
  307. ret_val = netlbl_domhsh_add_default(entry, &audit_info);
  308. break;
  309. case NETLBL_NLTYPE_CIPSOV4:
  310. if (!info->attrs[NLBL_MGMT_A_CV4DOI])
  311. goto adddef_failure;
  312. tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
  313. /* We should be holding a rcu_read_lock() here while we hold
  314. * the result but since the entry will always be deleted when
  315. * the CIPSO DOI is deleted we aren't going to keep the
  316. * lock. */
  317. rcu_read_lock();
  318. entry->type_def.cipsov4 = cipso_v4_doi_getdef(tmp_val);
  319. if (entry->type_def.cipsov4 == NULL) {
  320. rcu_read_unlock();
  321. goto adddef_failure;
  322. }
  323. ret_val = netlbl_domhsh_add_default(entry, &audit_info);
  324. rcu_read_unlock();
  325. break;
  326. default:
  327. goto adddef_failure;
  328. }
  329. if (ret_val != 0)
  330. goto adddef_failure;
  331. return 0;
  332. adddef_failure:
  333. kfree(entry);
  334. return ret_val;
  335. }
  336. /**
  337. * netlbl_mgmt_removedef - Handle a REMOVEDEF message
  338. * @skb: the NETLINK buffer
  339. * @info: the Generic NETLINK info block
  340. *
  341. * Description:
  342. * Process a user generated REMOVEDEF message and remove the default domain
  343. * mapping. Returns zero on success, negative values on failure.
  344. *
  345. */
  346. static int netlbl_mgmt_removedef(struct sk_buff *skb, struct genl_info *info)
  347. {
  348. struct netlbl_audit audit_info;
  349. netlbl_netlink_auditinfo(skb, &audit_info);
  350. return netlbl_domhsh_remove_default(&audit_info);
  351. }
  352. /**
  353. * netlbl_mgmt_listdef - Handle a LISTDEF message
  354. * @skb: the NETLINK buffer
  355. * @info: the Generic NETLINK info block
  356. *
  357. * Description:
  358. * Process a user generated LISTDEF message and dumps the default domain
  359. * mapping in a form suitable for use in a kernel generated LISTDEF message.
  360. * Returns zero on success, negative values on failure.
  361. *
  362. */
  363. static int netlbl_mgmt_listdef(struct sk_buff *skb, struct genl_info *info)
  364. {
  365. int ret_val = -ENOMEM;
  366. struct sk_buff *ans_skb = NULL;
  367. void *data;
  368. struct netlbl_dom_map *entry;
  369. ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  370. if (ans_skb == NULL)
  371. return -ENOMEM;
  372. data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
  373. 0, NLBL_MGMT_C_LISTDEF);
  374. if (data == NULL)
  375. goto listdef_failure;
  376. rcu_read_lock();
  377. entry = netlbl_domhsh_getentry(NULL);
  378. if (entry == NULL) {
  379. ret_val = -ENOENT;
  380. goto listdef_failure_lock;
  381. }
  382. ret_val = nla_put_u32(ans_skb, NLBL_MGMT_A_PROTOCOL, entry->type);
  383. if (ret_val != 0)
  384. goto listdef_failure_lock;
  385. switch (entry->type) {
  386. case NETLBL_NLTYPE_CIPSOV4:
  387. ret_val = nla_put_u32(ans_skb,
  388. NLBL_MGMT_A_CV4DOI,
  389. entry->type_def.cipsov4->doi);
  390. if (ret_val != 0)
  391. goto listdef_failure_lock;
  392. break;
  393. }
  394. rcu_read_unlock();
  395. genlmsg_end(ans_skb, data);
  396. ret_val = genlmsg_reply(ans_skb, info);
  397. if (ret_val != 0)
  398. goto listdef_failure;
  399. return 0;
  400. listdef_failure_lock:
  401. rcu_read_unlock();
  402. listdef_failure:
  403. kfree_skb(ans_skb);
  404. return ret_val;
  405. }
  406. /**
  407. * netlbl_mgmt_protocols_cb - Write an individual PROTOCOL message response
  408. * @skb: the skb to write to
  409. * @seq: the NETLINK sequence number
  410. * @cb: the NETLINK callback
  411. * @protocol: the NetLabel protocol to use in the message
  412. *
  413. * Description:
  414. * This function is to be used in conjunction with netlbl_mgmt_protocols() to
  415. * answer a application's PROTOCOLS message. Returns the size of the message
  416. * on success, negative values on failure.
  417. *
  418. */
  419. static int netlbl_mgmt_protocols_cb(struct sk_buff *skb,
  420. struct netlink_callback *cb,
  421. u32 protocol)
  422. {
  423. int ret_val = -ENOMEM;
  424. void *data;
  425. data = genlmsg_put(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
  426. &netlbl_mgmt_gnl_family, NLM_F_MULTI,
  427. NLBL_MGMT_C_PROTOCOLS);
  428. if (data == NULL)
  429. goto protocols_cb_failure;
  430. ret_val = nla_put_u32(skb, NLBL_MGMT_A_PROTOCOL, protocol);
  431. if (ret_val != 0)
  432. goto protocols_cb_failure;
  433. return genlmsg_end(skb, data);
  434. protocols_cb_failure:
  435. genlmsg_cancel(skb, data);
  436. return ret_val;
  437. }
  438. /**
  439. * netlbl_mgmt_protocols - Handle a PROTOCOLS message
  440. * @skb: the NETLINK buffer
  441. * @cb: the NETLINK callback
  442. *
  443. * Description:
  444. * Process a user generated PROTOCOLS message and respond accordingly.
  445. *
  446. */
  447. static int netlbl_mgmt_protocols(struct sk_buff *skb,
  448. struct netlink_callback *cb)
  449. {
  450. u32 protos_sent = cb->args[0];
  451. if (protos_sent == 0) {
  452. if (netlbl_mgmt_protocols_cb(skb,
  453. cb,
  454. NETLBL_NLTYPE_UNLABELED) < 0)
  455. goto protocols_return;
  456. protos_sent++;
  457. }
  458. if (protos_sent == 1) {
  459. if (netlbl_mgmt_protocols_cb(skb,
  460. cb,
  461. NETLBL_NLTYPE_CIPSOV4) < 0)
  462. goto protocols_return;
  463. protos_sent++;
  464. }
  465. protocols_return:
  466. cb->args[0] = protos_sent;
  467. return skb->len;
  468. }
  469. /**
  470. * netlbl_mgmt_version - Handle a VERSION message
  471. * @skb: the NETLINK buffer
  472. * @info: the Generic NETLINK info block
  473. *
  474. * Description:
  475. * Process a user generated VERSION message and respond accordingly. Returns
  476. * zero on success, negative values on failure.
  477. *
  478. */
  479. static int netlbl_mgmt_version(struct sk_buff *skb, struct genl_info *info)
  480. {
  481. int ret_val = -ENOMEM;
  482. struct sk_buff *ans_skb = NULL;
  483. void *data;
  484. ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  485. if (ans_skb == NULL)
  486. return -ENOMEM;
  487. data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family,
  488. 0, NLBL_MGMT_C_VERSION);
  489. if (data == NULL)
  490. goto version_failure;
  491. ret_val = nla_put_u32(ans_skb,
  492. NLBL_MGMT_A_VERSION,
  493. NETLBL_PROTO_VERSION);
  494. if (ret_val != 0)
  495. goto version_failure;
  496. genlmsg_end(ans_skb, data);
  497. ret_val = genlmsg_reply(ans_skb, info);
  498. if (ret_val != 0)
  499. goto version_failure;
  500. return 0;
  501. version_failure:
  502. kfree_skb(ans_skb);
  503. return ret_val;
  504. }
  505. /*
  506. * NetLabel Generic NETLINK Command Definitions
  507. */
  508. static struct genl_ops netlbl_mgmt_genl_c_add = {
  509. .cmd = NLBL_MGMT_C_ADD,
  510. .flags = GENL_ADMIN_PERM,
  511. .policy = netlbl_mgmt_genl_policy,
  512. .doit = netlbl_mgmt_add,
  513. .dumpit = NULL,
  514. };
  515. static struct genl_ops netlbl_mgmt_genl_c_remove = {
  516. .cmd = NLBL_MGMT_C_REMOVE,
  517. .flags = GENL_ADMIN_PERM,
  518. .policy = netlbl_mgmt_genl_policy,
  519. .doit = netlbl_mgmt_remove,
  520. .dumpit = NULL,
  521. };
  522. static struct genl_ops netlbl_mgmt_genl_c_listall = {
  523. .cmd = NLBL_MGMT_C_LISTALL,
  524. .flags = 0,
  525. .policy = netlbl_mgmt_genl_policy,
  526. .doit = NULL,
  527. .dumpit = netlbl_mgmt_listall,
  528. };
  529. static struct genl_ops netlbl_mgmt_genl_c_adddef = {
  530. .cmd = NLBL_MGMT_C_ADDDEF,
  531. .flags = GENL_ADMIN_PERM,
  532. .policy = netlbl_mgmt_genl_policy,
  533. .doit = netlbl_mgmt_adddef,
  534. .dumpit = NULL,
  535. };
  536. static struct genl_ops netlbl_mgmt_genl_c_removedef = {
  537. .cmd = NLBL_MGMT_C_REMOVEDEF,
  538. .flags = GENL_ADMIN_PERM,
  539. .policy = netlbl_mgmt_genl_policy,
  540. .doit = netlbl_mgmt_removedef,
  541. .dumpit = NULL,
  542. };
  543. static struct genl_ops netlbl_mgmt_genl_c_listdef = {
  544. .cmd = NLBL_MGMT_C_LISTDEF,
  545. .flags = 0,
  546. .policy = netlbl_mgmt_genl_policy,
  547. .doit = netlbl_mgmt_listdef,
  548. .dumpit = NULL,
  549. };
  550. static struct genl_ops netlbl_mgmt_genl_c_protocols = {
  551. .cmd = NLBL_MGMT_C_PROTOCOLS,
  552. .flags = 0,
  553. .policy = netlbl_mgmt_genl_policy,
  554. .doit = NULL,
  555. .dumpit = netlbl_mgmt_protocols,
  556. };
  557. static struct genl_ops netlbl_mgmt_genl_c_version = {
  558. .cmd = NLBL_MGMT_C_VERSION,
  559. .flags = 0,
  560. .policy = netlbl_mgmt_genl_policy,
  561. .doit = netlbl_mgmt_version,
  562. .dumpit = NULL,
  563. };
  564. /*
  565. * NetLabel Generic NETLINK Protocol Functions
  566. */
  567. /**
  568. * netlbl_mgmt_genl_init - Register the NetLabel management component
  569. *
  570. * Description:
  571. * Register the NetLabel management component with the Generic NETLINK
  572. * mechanism. Returns zero on success, negative values on failure.
  573. *
  574. */
  575. int netlbl_mgmt_genl_init(void)
  576. {
  577. int ret_val;
  578. ret_val = genl_register_family(&netlbl_mgmt_gnl_family);
  579. if (ret_val != 0)
  580. return ret_val;
  581. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  582. &netlbl_mgmt_genl_c_add);
  583. if (ret_val != 0)
  584. return ret_val;
  585. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  586. &netlbl_mgmt_genl_c_remove);
  587. if (ret_val != 0)
  588. return ret_val;
  589. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  590. &netlbl_mgmt_genl_c_listall);
  591. if (ret_val != 0)
  592. return ret_val;
  593. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  594. &netlbl_mgmt_genl_c_adddef);
  595. if (ret_val != 0)
  596. return ret_val;
  597. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  598. &netlbl_mgmt_genl_c_removedef);
  599. if (ret_val != 0)
  600. return ret_val;
  601. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  602. &netlbl_mgmt_genl_c_listdef);
  603. if (ret_val != 0)
  604. return ret_val;
  605. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  606. &netlbl_mgmt_genl_c_protocols);
  607. if (ret_val != 0)
  608. return ret_val;
  609. ret_val = genl_register_ops(&netlbl_mgmt_gnl_family,
  610. &netlbl_mgmt_genl_c_version);
  611. if (ret_val != 0)
  612. return ret_val;
  613. return 0;
  614. }