netlabel_mgmt.c 18 KB

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