netlink.c 16 KB

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