netlink.c 16 KB

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