netlink.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /* Copyright (C) 2016 B.A.T.M.A.N. contributors:
  2. *
  3. * Matthias Schiffer
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "netlink.h"
  18. #include "main.h"
  19. #include <linux/atomic.h>
  20. #include <linux/byteorder/generic.h>
  21. #include <linux/errno.h>
  22. #include <linux/fs.h>
  23. #include <linux/genetlink.h>
  24. #include <linux/if_ether.h>
  25. #include <linux/init.h>
  26. #include <linux/netdevice.h>
  27. #include <linux/netlink.h>
  28. #include <linux/printk.h>
  29. #include <linux/rculist.h>
  30. #include <linux/rcupdate.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/stddef.h>
  33. #include <linux/types.h>
  34. #include <net/genetlink.h>
  35. #include <net/netlink.h>
  36. #include <net/sock.h>
  37. #include <uapi/linux/batman_adv.h>
  38. #include "bat_algo.h"
  39. #include "bridge_loop_avoidance.h"
  40. #include "gateway_client.h"
  41. #include "hard-interface.h"
  42. #include "originator.h"
  43. #include "packet.h"
  44. #include "soft-interface.h"
  45. #include "tp_meter.h"
  46. #include "translation-table.h"
  47. struct genl_family batadv_netlink_family = {
  48. .id = GENL_ID_GENERATE,
  49. .hdrsize = 0,
  50. .name = BATADV_NL_NAME,
  51. .version = 1,
  52. .maxattr = BATADV_ATTR_MAX,
  53. .netnsok = true,
  54. };
  55. /* multicast groups */
  56. enum batadv_netlink_multicast_groups {
  57. BATADV_NL_MCGRP_TPMETER,
  58. };
  59. static const struct genl_multicast_group batadv_netlink_mcgrps[] = {
  60. [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER },
  61. };
  62. static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
  63. [BATADV_ATTR_VERSION] = { .type = NLA_STRING },
  64. [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
  65. [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
  66. [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING },
  67. [BATADV_ATTR_MESH_ADDRESS] = { .len = ETH_ALEN },
  68. [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
  69. [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING },
  70. [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN },
  71. [BATADV_ATTR_ORIG_ADDRESS] = { .len = ETH_ALEN },
  72. [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
  73. [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
  74. [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
  75. [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
  76. [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
  77. [BATADV_ATTR_TT_ADDRESS] = { .len = ETH_ALEN },
  78. [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
  79. [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
  80. [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
  81. [BATADV_ATTR_TT_VID] = { .type = NLA_U16 },
  82. [BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 },
  83. [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
  84. [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
  85. [BATADV_ATTR_NEIGH_ADDRESS] = { .len = ETH_ALEN },
  86. [BATADV_ATTR_TQ] = { .type = NLA_U8 },
  87. [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
  88. [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
  89. [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
  90. [BATADV_ATTR_ROUTER] = { .len = ETH_ALEN },
  91. [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
  92. [BATADV_ATTR_BLA_ADDRESS] = { .len = ETH_ALEN },
  93. [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
  94. [BATADV_ATTR_BLA_BACKBONE] = { .len = ETH_ALEN },
  95. [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
  96. };
  97. /**
  98. * batadv_netlink_get_ifindex - Extract an interface index from a message
  99. * @nlh: Message header
  100. * @attrtype: Attribute which holds an interface index
  101. *
  102. * Return: interface index, or 0.
  103. */
  104. int
  105. batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype)
  106. {
  107. struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype);
  108. return attr ? nla_get_u32(attr) : 0;
  109. }
  110. /**
  111. * batadv_netlink_mesh_info_put - fill in generic information about mesh
  112. * interface
  113. * @msg: netlink message to be sent back
  114. * @soft_iface: interface for which the data should be taken
  115. *
  116. * Return: 0 on success, < 0 on error
  117. */
  118. static int
  119. batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface)
  120. {
  121. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  122. struct batadv_hard_iface *primary_if = NULL;
  123. struct net_device *hard_iface;
  124. int ret = -ENOBUFS;
  125. if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) ||
  126. nla_put_string(msg, BATADV_ATTR_ALGO_NAME,
  127. bat_priv->algo_ops->name) ||
  128. nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) ||
  129. nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) ||
  130. nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN,
  131. soft_iface->dev_addr) ||
  132. nla_put_u8(msg, BATADV_ATTR_TT_TTVN,
  133. (u8)atomic_read(&bat_priv->tt.vn)))
  134. goto out;
  135. #ifdef CONFIG_BATMAN_ADV_BLA
  136. if (nla_put_u16(msg, BATADV_ATTR_BLA_CRC,
  137. ntohs(bat_priv->bla.claim_dest.group)))
  138. goto out;
  139. #endif
  140. primary_if = batadv_primary_if_get_selected(bat_priv);
  141. if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) {
  142. hard_iface = primary_if->net_dev;
  143. if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
  144. hard_iface->ifindex) ||
  145. nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
  146. hard_iface->name) ||
  147. nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
  148. hard_iface->dev_addr))
  149. goto out;
  150. }
  151. ret = 0;
  152. out:
  153. if (primary_if)
  154. batadv_hardif_put(primary_if);
  155. return ret;
  156. }
  157. /**
  158. * batadv_netlink_get_mesh_info - handle incoming BATADV_CMD_GET_MESH_INFO
  159. * netlink request
  160. * @skb: received netlink message
  161. * @info: receiver information
  162. *
  163. * Return: 0 on success, < 0 on error
  164. */
  165. static int
  166. batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info)
  167. {
  168. struct net *net = genl_info_net(info);
  169. struct net_device *soft_iface;
  170. struct sk_buff *msg = NULL;
  171. void *msg_head;
  172. int ifindex;
  173. int ret;
  174. if (!info->attrs[BATADV_ATTR_MESH_IFINDEX])
  175. return -EINVAL;
  176. ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]);
  177. if (!ifindex)
  178. return -EINVAL;
  179. soft_iface = dev_get_by_index(net, ifindex);
  180. if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
  181. ret = -ENODEV;
  182. goto out;
  183. }
  184. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  185. if (!msg) {
  186. ret = -ENOMEM;
  187. goto out;
  188. }
  189. msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq,
  190. &batadv_netlink_family, 0,
  191. BATADV_CMD_GET_MESH_INFO);
  192. if (!msg_head) {
  193. ret = -ENOBUFS;
  194. goto out;
  195. }
  196. ret = batadv_netlink_mesh_info_put(msg, soft_iface);
  197. out:
  198. if (soft_iface)
  199. dev_put(soft_iface);
  200. if (ret) {
  201. if (msg)
  202. nlmsg_free(msg);
  203. return ret;
  204. }
  205. genlmsg_end(msg, msg_head);
  206. return genlmsg_reply(msg, info);
  207. }
  208. /**
  209. * batadv_netlink_tp_meter_put - Fill information of started tp_meter session
  210. * @msg: netlink message to be sent back
  211. * @cookie: tp meter session cookie
  212. *
  213. * Return: 0 on success, < 0 on error
  214. */
  215. static int
  216. batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie)
  217. {
  218. if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
  219. return -ENOBUFS;
  220. return 0;
  221. }
  222. /**
  223. * batadv_netlink_tpmeter_notify - send tp_meter result via netlink to client
  224. * @bat_priv: the bat priv with all the soft interface information
  225. * @dst: destination of tp_meter session
  226. * @result: reason for tp meter session stop
  227. * @test_time: total time ot the tp_meter session
  228. * @total_bytes: bytes acked to the receiver
  229. * @cookie: cookie of tp_meter session
  230. *
  231. * Return: 0 on success, < 0 on error
  232. */
  233. int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst,
  234. u8 result, u32 test_time, u64 total_bytes,
  235. u32 cookie)
  236. {
  237. struct sk_buff *msg;
  238. void *hdr;
  239. int ret;
  240. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  241. if (!msg)
  242. return -ENOMEM;
  243. hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0,
  244. BATADV_CMD_TP_METER);
  245. if (!hdr) {
  246. ret = -ENOBUFS;
  247. goto err_genlmsg;
  248. }
  249. if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie))
  250. goto nla_put_failure;
  251. if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time))
  252. goto nla_put_failure;
  253. if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes,
  254. BATADV_ATTR_PAD))
  255. goto nla_put_failure;
  256. if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result))
  257. goto nla_put_failure;
  258. if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst))
  259. goto nla_put_failure;
  260. genlmsg_end(msg, hdr);
  261. genlmsg_multicast_netns(&batadv_netlink_family,
  262. dev_net(bat_priv->soft_iface), msg, 0,
  263. BATADV_NL_MCGRP_TPMETER, GFP_KERNEL);
  264. return 0;
  265. nla_put_failure:
  266. genlmsg_cancel(msg, hdr);
  267. ret = -EMSGSIZE;
  268. err_genlmsg:
  269. nlmsg_free(msg);
  270. return ret;
  271. }
  272. /**
  273. * batadv_netlink_tp_meter_start - Start a new tp_meter session
  274. * @skb: received netlink message
  275. * @info: receiver information
  276. *
  277. * Return: 0 on success, < 0 on error
  278. */
  279. static int
  280. batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info)
  281. {
  282. struct net *net = genl_info_net(info);
  283. struct net_device *soft_iface;
  284. struct batadv_priv *bat_priv;
  285. struct sk_buff *msg = NULL;
  286. u32 test_length;
  287. void *msg_head;
  288. int ifindex;
  289. u32 cookie;
  290. u8 *dst;
  291. int ret;
  292. if (!info->attrs[BATADV_ATTR_MESH_IFINDEX])
  293. return -EINVAL;
  294. if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
  295. return -EINVAL;
  296. if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME])
  297. return -EINVAL;
  298. ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]);
  299. if (!ifindex)
  300. return -EINVAL;
  301. dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
  302. test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]);
  303. soft_iface = dev_get_by_index(net, ifindex);
  304. if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
  305. ret = -ENODEV;
  306. goto out;
  307. }
  308. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  309. if (!msg) {
  310. ret = -ENOMEM;
  311. goto out;
  312. }
  313. msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq,
  314. &batadv_netlink_family, 0,
  315. BATADV_CMD_TP_METER);
  316. if (!msg_head) {
  317. ret = -ENOBUFS;
  318. goto out;
  319. }
  320. bat_priv = netdev_priv(soft_iface);
  321. batadv_tp_start(bat_priv, dst, test_length, &cookie);
  322. ret = batadv_netlink_tp_meter_put(msg, cookie);
  323. out:
  324. if (soft_iface)
  325. dev_put(soft_iface);
  326. if (ret) {
  327. if (msg)
  328. nlmsg_free(msg);
  329. return ret;
  330. }
  331. genlmsg_end(msg, msg_head);
  332. return genlmsg_reply(msg, info);
  333. }
  334. /**
  335. * batadv_netlink_tp_meter_start - Cancel a running tp_meter session
  336. * @skb: received netlink message
  337. * @info: receiver information
  338. *
  339. * Return: 0 on success, < 0 on error
  340. */
  341. static int
  342. batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info)
  343. {
  344. struct net *net = genl_info_net(info);
  345. struct net_device *soft_iface;
  346. struct batadv_priv *bat_priv;
  347. int ifindex;
  348. u8 *dst;
  349. int ret = 0;
  350. if (!info->attrs[BATADV_ATTR_MESH_IFINDEX])
  351. return -EINVAL;
  352. if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS])
  353. return -EINVAL;
  354. ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]);
  355. if (!ifindex)
  356. return -EINVAL;
  357. dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]);
  358. soft_iface = dev_get_by_index(net, ifindex);
  359. if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
  360. ret = -ENODEV;
  361. goto out;
  362. }
  363. bat_priv = netdev_priv(soft_iface);
  364. batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL);
  365. out:
  366. if (soft_iface)
  367. dev_put(soft_iface);
  368. return ret;
  369. }
  370. /**
  371. * batadv_netlink_dump_hardif_entry - Dump one hard interface into a message
  372. * @msg: Netlink message to dump into
  373. * @portid: Port making netlink request
  374. * @seq: Sequence number of netlink message
  375. * @hard_iface: Hard interface to dump
  376. *
  377. * Return: error code, or 0 on success
  378. */
  379. static int
  380. batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq,
  381. struct batadv_hard_iface *hard_iface)
  382. {
  383. struct net_device *net_dev = hard_iface->net_dev;
  384. void *hdr;
  385. hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI,
  386. BATADV_CMD_GET_HARDIFS);
  387. if (!hdr)
  388. return -EMSGSIZE;
  389. if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX,
  390. net_dev->ifindex) ||
  391. nla_put_string(msg, BATADV_ATTR_HARD_IFNAME,
  392. net_dev->name) ||
  393. nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN,
  394. net_dev->dev_addr))
  395. goto nla_put_failure;
  396. if (hard_iface->if_status == BATADV_IF_ACTIVE) {
  397. if (nla_put_flag(msg, BATADV_ATTR_ACTIVE))
  398. goto nla_put_failure;
  399. }
  400. genlmsg_end(msg, hdr);
  401. return 0;
  402. nla_put_failure:
  403. genlmsg_cancel(msg, hdr);
  404. return -EMSGSIZE;
  405. }
  406. /**
  407. * batadv_netlink_dump_hardifs - Dump all hard interface into a messages
  408. * @msg: Netlink message to dump into
  409. * @cb: Parameters from query
  410. *
  411. * Return: error code, or length of reply message on success
  412. */
  413. static int
  414. batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb)
  415. {
  416. struct net *net = sock_net(cb->skb->sk);
  417. struct net_device *soft_iface;
  418. struct batadv_hard_iface *hard_iface;
  419. int ifindex;
  420. int portid = NETLINK_CB(cb->skb).portid;
  421. int seq = cb->nlh->nlmsg_seq;
  422. int skip = cb->args[0];
  423. int i = 0;
  424. ifindex = batadv_netlink_get_ifindex(cb->nlh,
  425. BATADV_ATTR_MESH_IFINDEX);
  426. if (!ifindex)
  427. return -EINVAL;
  428. soft_iface = dev_get_by_index(net, ifindex);
  429. if (!soft_iface)
  430. return -ENODEV;
  431. if (!batadv_softif_is_valid(soft_iface)) {
  432. dev_put(soft_iface);
  433. return -ENODEV;
  434. }
  435. rcu_read_lock();
  436. list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
  437. if (hard_iface->soft_iface != soft_iface)
  438. continue;
  439. if (i++ < skip)
  440. continue;
  441. if (batadv_netlink_dump_hardif_entry(msg, portid, seq,
  442. hard_iface)) {
  443. i--;
  444. break;
  445. }
  446. }
  447. rcu_read_unlock();
  448. dev_put(soft_iface);
  449. cb->args[0] = i;
  450. return msg->len;
  451. }
  452. static struct genl_ops batadv_netlink_ops[] = {
  453. {
  454. .cmd = BATADV_CMD_GET_MESH_INFO,
  455. .flags = GENL_ADMIN_PERM,
  456. .policy = batadv_netlink_policy,
  457. .doit = batadv_netlink_get_mesh_info,
  458. },
  459. {
  460. .cmd = BATADV_CMD_TP_METER,
  461. .flags = GENL_ADMIN_PERM,
  462. .policy = batadv_netlink_policy,
  463. .doit = batadv_netlink_tp_meter_start,
  464. },
  465. {
  466. .cmd = BATADV_CMD_TP_METER_CANCEL,
  467. .flags = GENL_ADMIN_PERM,
  468. .policy = batadv_netlink_policy,
  469. .doit = batadv_netlink_tp_meter_cancel,
  470. },
  471. {
  472. .cmd = BATADV_CMD_GET_ROUTING_ALGOS,
  473. .flags = GENL_ADMIN_PERM,
  474. .policy = batadv_netlink_policy,
  475. .dumpit = batadv_algo_dump,
  476. },
  477. {
  478. .cmd = BATADV_CMD_GET_HARDIFS,
  479. .flags = GENL_ADMIN_PERM,
  480. .policy = batadv_netlink_policy,
  481. .dumpit = batadv_netlink_dump_hardifs,
  482. },
  483. {
  484. .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL,
  485. .flags = GENL_ADMIN_PERM,
  486. .policy = batadv_netlink_policy,
  487. .dumpit = batadv_tt_local_dump,
  488. },
  489. {
  490. .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL,
  491. .flags = GENL_ADMIN_PERM,
  492. .policy = batadv_netlink_policy,
  493. .dumpit = batadv_tt_global_dump,
  494. },
  495. {
  496. .cmd = BATADV_CMD_GET_ORIGINATORS,
  497. .flags = GENL_ADMIN_PERM,
  498. .policy = batadv_netlink_policy,
  499. .dumpit = batadv_orig_dump,
  500. },
  501. {
  502. .cmd = BATADV_CMD_GET_NEIGHBORS,
  503. .flags = GENL_ADMIN_PERM,
  504. .policy = batadv_netlink_policy,
  505. .dumpit = batadv_hardif_neigh_dump,
  506. },
  507. {
  508. .cmd = BATADV_CMD_GET_GATEWAYS,
  509. .flags = GENL_ADMIN_PERM,
  510. .policy = batadv_netlink_policy,
  511. .dumpit = batadv_gw_dump,
  512. },
  513. {
  514. .cmd = BATADV_CMD_GET_BLA_CLAIM,
  515. .flags = GENL_ADMIN_PERM,
  516. .policy = batadv_netlink_policy,
  517. .dumpit = batadv_bla_claim_dump,
  518. },
  519. {
  520. .cmd = BATADV_CMD_GET_BLA_BACKBONE,
  521. .flags = GENL_ADMIN_PERM,
  522. .policy = batadv_netlink_policy,
  523. .dumpit = batadv_bla_backbone_dump,
  524. },
  525. };
  526. /**
  527. * batadv_netlink_register - register batadv genl netlink family
  528. */
  529. void __init batadv_netlink_register(void)
  530. {
  531. int ret;
  532. ret = genl_register_family_with_ops_groups(&batadv_netlink_family,
  533. batadv_netlink_ops,
  534. batadv_netlink_mcgrps);
  535. if (ret)
  536. pr_warn("unable to register netlink family");
  537. }
  538. /**
  539. * batadv_netlink_unregister - unregister batadv genl netlink family
  540. */
  541. void batadv_netlink_unregister(void)
  542. {
  543. genl_unregister_family(&batadv_netlink_family);
  544. }