netlink.c 17 KB

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