Sven Eckelmann | 7db7d9f | 2017-11-19 15:05:11 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sven Eckelmann | 7a79d71 | 2018-12-31 23:59:59 +0100 | [diff] [blame] | 2 | /* Copyright (C) 2016-2019 B.A.T.M.A.N. contributors: |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 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 | |
| 19 | #include "netlink.h" |
| 20 | #include "main.h" |
| 21 | |
Sven Eckelmann | f32ed4b | 2016-07-03 13:31:38 +0200 | [diff] [blame] | 22 | #include <linux/atomic.h> |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 23 | #include <linux/bitops.h> |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 24 | #include <linux/bug.h> |
Sven Eckelmann | 8dad6f0d | 2016-07-03 13:31:46 +0200 | [diff] [blame] | 25 | #include <linux/byteorder/generic.h> |
Sven Eckelmann | 9bcb94c | 2016-10-29 10:13:47 +0200 | [diff] [blame] | 26 | #include <linux/cache.h> |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 27 | #include <linux/err.h> |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 28 | #include <linux/errno.h> |
Sven Eckelmann | 9bcb94c | 2016-10-29 10:13:47 +0200 | [diff] [blame] | 29 | #include <linux/export.h> |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 30 | #include <linux/genetlink.h> |
Sven Eckelmann | b92b94a | 2017-11-19 17:12:02 +0100 | [diff] [blame] | 31 | #include <linux/gfp.h> |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 32 | #include <linux/if_ether.h> |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 33 | #include <linux/if_vlan.h> |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 34 | #include <linux/init.h> |
Sven Eckelmann | 9bcb94c | 2016-10-29 10:13:47 +0200 | [diff] [blame] | 35 | #include <linux/kernel.h> |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 36 | #include <linux/list.h> |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/netlink.h> |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 39 | #include <linux/printk.h> |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 40 | #include <linux/rtnetlink.h> |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 41 | #include <linux/skbuff.h> |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 42 | #include <linux/stddef.h> |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 43 | #include <linux/types.h> |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 44 | #include <net/genetlink.h> |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 45 | #include <net/netlink.h> |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 46 | #include <net/sock.h> |
Sven Eckelmann | fec149f | 2017-12-21 10:17:41 +0100 | [diff] [blame] | 47 | #include <uapi/linux/batadv_packet.h> |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 48 | #include <uapi/linux/batman_adv.h> |
| 49 | |
Matthias Schiffer | 07a3061 | 2016-07-03 13:31:35 +0200 | [diff] [blame] | 50 | #include "bat_algo.h" |
Andrew Lunn | 04f3f5b | 2016-07-03 13:31:45 +0200 | [diff] [blame] | 51 | #include "bridge_loop_avoidance.h" |
Linus Lüssing | 41aeefc | 2018-03-13 11:41:12 +0100 | [diff] [blame] | 52 | #include "distributed-arp-table.h" |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 53 | #include "gateway_client.h" |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 54 | #include "hard-interface.h" |
Linus Lüssing | 53dd9a6 | 2018-03-13 11:41:13 +0100 | [diff] [blame] | 55 | #include "multicast.h" |
Matthias Schiffer | 85cf8c8 | 2016-07-03 13:31:39 +0200 | [diff] [blame] | 56 | #include "originator.h" |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 57 | #include "soft-interface.h" |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 58 | #include "tp_meter.h" |
Matthias Schiffer | d34f055 | 2016-07-03 13:31:37 +0200 | [diff] [blame] | 59 | #include "translation-table.h" |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 60 | |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 61 | struct net; |
| 62 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 63 | struct genl_family batadv_netlink_family; |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 64 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 65 | /* multicast groups */ |
| 66 | enum batadv_netlink_multicast_groups { |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 67 | BATADV_NL_MCGRP_CONFIG, |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 68 | BATADV_NL_MCGRP_TPMETER, |
| 69 | }; |
| 70 | |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 71 | /** |
| 72 | * enum batadv_genl_ops_flags - flags for genl_ops's internal_flags |
| 73 | */ |
| 74 | enum batadv_genl_ops_flags { |
| 75 | /** |
| 76 | * @BATADV_FLAG_NEED_MESH: request requires valid soft interface in |
| 77 | * attribute BATADV_ATTR_MESH_IFINDEX and expects a pointer to it to be |
| 78 | * saved in info->user_ptr[0] |
| 79 | */ |
| 80 | BATADV_FLAG_NEED_MESH = BIT(0), |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * @BATADV_FLAG_NEED_HARDIF: request requires valid hard interface in |
| 84 | * attribute BATADV_ATTR_HARD_IFINDEX and expects a pointer to it to be |
| 85 | * saved in info->user_ptr[1] |
| 86 | */ |
| 87 | BATADV_FLAG_NEED_HARDIF = BIT(1), |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * @BATADV_FLAG_NEED_VLAN: request requires valid vlan in |
| 91 | * attribute BATADV_ATTR_VLANID and expects a pointer to it to be |
| 92 | * saved in info->user_ptr[1] |
| 93 | */ |
| 94 | BATADV_FLAG_NEED_VLAN = BIT(2), |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
stephen hemminger | deeb91f | 2016-08-31 15:17:00 -0700 | [diff] [blame] | 97 | static const struct genl_multicast_group batadv_netlink_mcgrps[] = { |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 98 | [BATADV_NL_MCGRP_CONFIG] = { .name = BATADV_NL_MCAST_GROUP_CONFIG }, |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 99 | [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER }, |
| 100 | }; |
| 101 | |
stephen hemminger | deeb91f | 2016-08-31 15:17:00 -0700 | [diff] [blame] | 102 | static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { |
Linus Lüssing | 41aeefc | 2018-03-13 11:41:12 +0100 | [diff] [blame] | 103 | [BATADV_ATTR_VERSION] = { .type = NLA_STRING }, |
| 104 | [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING }, |
| 105 | [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, |
| 106 | [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING }, |
| 107 | [BATADV_ATTR_MESH_ADDRESS] = { .len = ETH_ALEN }, |
| 108 | [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, |
| 109 | [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, |
| 110 | [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, |
| 111 | [BATADV_ATTR_ORIG_ADDRESS] = { .len = ETH_ALEN }, |
| 112 | [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 }, |
| 113 | [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 }, |
| 114 | [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 }, |
| 115 | [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 }, |
| 116 | [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG }, |
| 117 | [BATADV_ATTR_TT_ADDRESS] = { .len = ETH_ALEN }, |
| 118 | [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 }, |
| 119 | [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 }, |
| 120 | [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 }, |
| 121 | [BATADV_ATTR_TT_VID] = { .type = NLA_U16 }, |
| 122 | [BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 }, |
| 123 | [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG }, |
| 124 | [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 }, |
| 125 | [BATADV_ATTR_NEIGH_ADDRESS] = { .len = ETH_ALEN }, |
| 126 | [BATADV_ATTR_TQ] = { .type = NLA_U8 }, |
| 127 | [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 }, |
| 128 | [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 }, |
| 129 | [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 }, |
| 130 | [BATADV_ATTR_ROUTER] = { .len = ETH_ALEN }, |
| 131 | [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG }, |
| 132 | [BATADV_ATTR_BLA_ADDRESS] = { .len = ETH_ALEN }, |
| 133 | [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 }, |
| 134 | [BATADV_ATTR_BLA_BACKBONE] = { .len = ETH_ALEN }, |
| 135 | [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 }, |
| 136 | [BATADV_ATTR_DAT_CACHE_IP4ADDRESS] = { .type = NLA_U32 }, |
| 137 | [BATADV_ATTR_DAT_CACHE_HWADDRESS] = { .len = ETH_ALEN }, |
| 138 | [BATADV_ATTR_DAT_CACHE_VID] = { .type = NLA_U16 }, |
Linus Lüssing | 53dd9a6 | 2018-03-13 11:41:13 +0100 | [diff] [blame] | 139 | [BATADV_ATTR_MCAST_FLAGS] = { .type = NLA_U32 }, |
| 140 | [BATADV_ATTR_MCAST_FLAGS_PRIV] = { .type = NLA_U32 }, |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 141 | [BATADV_ATTR_VLANID] = { .type = NLA_U16 }, |
Sven Eckelmann | 9ab4cee | 2018-11-23 12:46:14 +0100 | [diff] [blame] | 142 | [BATADV_ATTR_AGGREGATED_OGMS_ENABLED] = { .type = NLA_U8 }, |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 143 | [BATADV_ATTR_AP_ISOLATION_ENABLED] = { .type = NLA_U8 }, |
| 144 | [BATADV_ATTR_ISOLATION_MARK] = { .type = NLA_U32 }, |
| 145 | [BATADV_ATTR_ISOLATION_MASK] = { .type = NLA_U32 }, |
Sven Eckelmann | d7e5250 | 2018-11-23 12:55:44 +0100 | [diff] [blame^] | 146 | [BATADV_ATTR_BONDING_ENABLED] = { .type = NLA_U8 }, |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 150 | * batadv_netlink_get_ifindex() - Extract an interface index from a message |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 151 | * @nlh: Message header |
| 152 | * @attrtype: Attribute which holds an interface index |
| 153 | * |
| 154 | * Return: interface index, or 0. |
| 155 | */ |
Matthias Schiffer | d34f055 | 2016-07-03 13:31:37 +0200 | [diff] [blame] | 156 | int |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 157 | batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype) |
| 158 | { |
| 159 | struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype); |
| 160 | |
| 161 | return attr ? nla_get_u32(attr) : 0; |
| 162 | } |
| 163 | |
| 164 | /** |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 165 | * batadv_netlink_mesh_fill_ap_isolation() - Add ap_isolation softif attribute |
| 166 | * @msg: Netlink message to dump into |
| 167 | * @bat_priv: the bat priv with all the soft interface information |
| 168 | * |
| 169 | * Return: 0 on success or negative error number in case of failure |
| 170 | */ |
| 171 | static int batadv_netlink_mesh_fill_ap_isolation(struct sk_buff *msg, |
| 172 | struct batadv_priv *bat_priv) |
| 173 | { |
| 174 | struct batadv_softif_vlan *vlan; |
| 175 | u8 ap_isolation; |
| 176 | |
| 177 | vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS); |
| 178 | if (!vlan) |
| 179 | return 0; |
| 180 | |
| 181 | ap_isolation = atomic_read(&vlan->ap_isolation); |
| 182 | batadv_softif_vlan_put(vlan); |
| 183 | |
| 184 | return nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED, |
| 185 | !!ap_isolation); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * batadv_option_set_ap_isolation() - Set ap_isolation from genl msg |
| 190 | * @attr: parsed BATADV_ATTR_AP_ISOLATION_ENABLED attribute |
| 191 | * @bat_priv: the bat priv with all the soft interface information |
| 192 | * |
| 193 | * Return: 0 on success or negative error number in case of failure |
| 194 | */ |
| 195 | static int batadv_netlink_set_mesh_ap_isolation(struct nlattr *attr, |
| 196 | struct batadv_priv *bat_priv) |
| 197 | { |
| 198 | struct batadv_softif_vlan *vlan; |
| 199 | |
| 200 | vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS); |
| 201 | if (!vlan) |
| 202 | return -ENOENT; |
| 203 | |
| 204 | atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr)); |
| 205 | batadv_softif_vlan_put(vlan); |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /** |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 211 | * batadv_netlink_mesh_fill() - Fill message with mesh attributes |
| 212 | * @msg: Netlink message to dump into |
| 213 | * @bat_priv: the bat priv with all the soft interface information |
| 214 | * @cmd: type of message to generate |
| 215 | * @portid: Port making netlink request |
| 216 | * @seq: sequence number for message |
| 217 | * @flags: Additional flags for message |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 218 | * |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 219 | * Return: 0 on success or negative error number in case of failure |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 220 | */ |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 221 | static int batadv_netlink_mesh_fill(struct sk_buff *msg, |
| 222 | struct batadv_priv *bat_priv, |
| 223 | enum batadv_nl_commands cmd, |
| 224 | u32 portid, u32 seq, int flags) |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 225 | { |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 226 | struct net_device *soft_iface = bat_priv->soft_iface; |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 227 | struct batadv_hard_iface *primary_if = NULL; |
| 228 | struct net_device *hard_iface; |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 229 | void *hdr; |
| 230 | |
| 231 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
| 232 | if (!hdr) |
| 233 | return -ENOBUFS; |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 234 | |
| 235 | if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) || |
| 236 | nla_put_string(msg, BATADV_ATTR_ALGO_NAME, |
Antonio Quartulli | 29824a5 | 2016-05-25 23:27:31 +0800 | [diff] [blame] | 237 | bat_priv->algo_ops->name) || |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 238 | nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) || |
| 239 | nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) || |
| 240 | nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN, |
Sven Eckelmann | f32ed4b | 2016-07-03 13:31:38 +0200 | [diff] [blame] | 241 | soft_iface->dev_addr) || |
| 242 | nla_put_u8(msg, BATADV_ATTR_TT_TTVN, |
| 243 | (u8)atomic_read(&bat_priv->tt.vn))) |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 244 | goto nla_put_failure; |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 245 | |
Sven Eckelmann | 8dad6f0d | 2016-07-03 13:31:46 +0200 | [diff] [blame] | 246 | #ifdef CONFIG_BATMAN_ADV_BLA |
| 247 | if (nla_put_u16(msg, BATADV_ATTR_BLA_CRC, |
| 248 | ntohs(bat_priv->bla.claim_dest.group))) |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 249 | goto nla_put_failure; |
Sven Eckelmann | 8dad6f0d | 2016-07-03 13:31:46 +0200 | [diff] [blame] | 250 | #endif |
| 251 | |
Linus Lüssing | 53dd9a6 | 2018-03-13 11:41:13 +0100 | [diff] [blame] | 252 | if (batadv_mcast_mesh_info_put(msg, bat_priv)) |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 253 | goto nla_put_failure; |
Linus Lüssing | 53dd9a6 | 2018-03-13 11:41:13 +0100 | [diff] [blame] | 254 | |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 255 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 256 | if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) { |
| 257 | hard_iface = primary_if->net_dev; |
| 258 | |
| 259 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, |
| 260 | hard_iface->ifindex) || |
| 261 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, |
| 262 | hard_iface->name) || |
| 263 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, |
| 264 | hard_iface->dev_addr)) |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 265 | goto nla_put_failure; |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 266 | } |
| 267 | |
Sven Eckelmann | 9ab4cee | 2018-11-23 12:46:14 +0100 | [diff] [blame] | 268 | if (nla_put_u8(msg, BATADV_ATTR_AGGREGATED_OGMS_ENABLED, |
| 269 | !!atomic_read(&bat_priv->aggregated_ogms))) |
| 270 | goto nla_put_failure; |
| 271 | |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 272 | if (batadv_netlink_mesh_fill_ap_isolation(msg, bat_priv)) |
| 273 | goto nla_put_failure; |
| 274 | |
| 275 | if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MARK, |
| 276 | bat_priv->isolation_mark)) |
| 277 | goto nla_put_failure; |
| 278 | |
| 279 | if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MASK, |
| 280 | bat_priv->isolation_mark_mask)) |
| 281 | goto nla_put_failure; |
| 282 | |
Sven Eckelmann | d7e5250 | 2018-11-23 12:55:44 +0100 | [diff] [blame^] | 283 | if (nla_put_u8(msg, BATADV_ATTR_BONDING_ENABLED, |
| 284 | !!atomic_read(&bat_priv->bonding))) |
| 285 | goto nla_put_failure; |
| 286 | |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 287 | if (primary_if) |
| 288 | batadv_hardif_put(primary_if); |
| 289 | |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 290 | genlmsg_end(msg, hdr); |
| 291 | return 0; |
| 292 | |
| 293 | nla_put_failure: |
| 294 | if (primary_if) |
| 295 | batadv_hardif_put(primary_if); |
| 296 | |
| 297 | genlmsg_cancel(msg, hdr); |
| 298 | return -EMSGSIZE; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * batadv_netlink_notify_mesh() - send softif attributes to listener |
| 303 | * @bat_priv: the bat priv with all the soft interface information |
| 304 | * |
| 305 | * Return: 0 on success, < 0 on error |
| 306 | */ |
| 307 | static int batadv_netlink_notify_mesh(struct batadv_priv *bat_priv) |
| 308 | { |
| 309 | struct sk_buff *msg; |
| 310 | int ret; |
| 311 | |
| 312 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 313 | if (!msg) |
| 314 | return -ENOMEM; |
| 315 | |
| 316 | ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_SET_MESH, |
| 317 | 0, 0, 0); |
| 318 | if (ret < 0) { |
| 319 | nlmsg_free(msg); |
| 320 | return ret; |
| 321 | } |
| 322 | |
| 323 | genlmsg_multicast_netns(&batadv_netlink_family, |
| 324 | dev_net(bat_priv->soft_iface), msg, 0, |
| 325 | BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * batadv_netlink_get_mesh() - Get softif attributes |
| 332 | * @skb: Netlink message with request data |
| 333 | * @info: receiver information |
| 334 | * |
| 335 | * Return: 0 on success or negative error number in case of failure |
| 336 | */ |
| 337 | static int batadv_netlink_get_mesh(struct sk_buff *skb, struct genl_info *info) |
| 338 | { |
| 339 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
| 340 | struct sk_buff *msg; |
| 341 | int ret; |
| 342 | |
| 343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 344 | if (!msg) |
| 345 | return -ENOMEM; |
| 346 | |
| 347 | ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_GET_MESH, |
| 348 | info->snd_portid, info->snd_seq, 0); |
| 349 | if (ret < 0) { |
| 350 | nlmsg_free(msg); |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | ret = genlmsg_reply(msg, info); |
| 355 | |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | /** |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 360 | * batadv_netlink_set_mesh() - Set softif attributes |
| 361 | * @skb: Netlink message with request data |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 362 | * @info: receiver information |
| 363 | * |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 364 | * Return: 0 on success or negative error number in case of failure |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 365 | */ |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 366 | static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info) |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 367 | { |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 368 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
Sven Eckelmann | 9ab4cee | 2018-11-23 12:46:14 +0100 | [diff] [blame] | 369 | struct nlattr *attr; |
| 370 | |
| 371 | if (info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]) { |
| 372 | attr = info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]; |
| 373 | |
| 374 | atomic_set(&bat_priv->aggregated_ogms, !!nla_get_u8(attr)); |
| 375 | } |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 376 | |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 377 | if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) { |
| 378 | attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]; |
| 379 | |
| 380 | batadv_netlink_set_mesh_ap_isolation(attr, bat_priv); |
| 381 | } |
| 382 | |
| 383 | if (info->attrs[BATADV_ATTR_ISOLATION_MARK]) { |
| 384 | attr = info->attrs[BATADV_ATTR_ISOLATION_MARK]; |
| 385 | |
| 386 | bat_priv->isolation_mark = nla_get_u32(attr); |
| 387 | } |
| 388 | |
| 389 | if (info->attrs[BATADV_ATTR_ISOLATION_MASK]) { |
| 390 | attr = info->attrs[BATADV_ATTR_ISOLATION_MASK]; |
| 391 | |
| 392 | bat_priv->isolation_mark_mask = nla_get_u32(attr); |
| 393 | } |
| 394 | |
Sven Eckelmann | d7e5250 | 2018-11-23 12:55:44 +0100 | [diff] [blame^] | 395 | if (info->attrs[BATADV_ATTR_BONDING_ENABLED]) { |
| 396 | attr = info->attrs[BATADV_ATTR_BONDING_ENABLED]; |
| 397 | |
| 398 | atomic_set(&bat_priv->bonding, !!nla_get_u8(attr)); |
| 399 | } |
| 400 | |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 401 | batadv_netlink_notify_mesh(bat_priv); |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 402 | |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 403 | return 0; |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 406 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 407 | * batadv_netlink_tp_meter_put() - Fill information of started tp_meter session |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 408 | * @msg: netlink message to be sent back |
| 409 | * @cookie: tp meter session cookie |
| 410 | * |
| 411 | * Return: 0 on success, < 0 on error |
| 412 | */ |
| 413 | static int |
| 414 | batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie) |
| 415 | { |
| 416 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) |
| 417 | return -ENOBUFS; |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 423 | * batadv_netlink_tpmeter_notify() - send tp_meter result via netlink to client |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 424 | * @bat_priv: the bat priv with all the soft interface information |
| 425 | * @dst: destination of tp_meter session |
| 426 | * @result: reason for tp meter session stop |
| 427 | * @test_time: total time ot the tp_meter session |
| 428 | * @total_bytes: bytes acked to the receiver |
| 429 | * @cookie: cookie of tp_meter session |
| 430 | * |
| 431 | * Return: 0 on success, < 0 on error |
| 432 | */ |
| 433 | int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, |
| 434 | u8 result, u32 test_time, u64 total_bytes, |
| 435 | u32 cookie) |
| 436 | { |
| 437 | struct sk_buff *msg; |
| 438 | void *hdr; |
| 439 | int ret; |
| 440 | |
| 441 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 442 | if (!msg) |
| 443 | return -ENOMEM; |
| 444 | |
| 445 | hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0, |
| 446 | BATADV_CMD_TP_METER); |
| 447 | if (!hdr) { |
| 448 | ret = -ENOBUFS; |
| 449 | goto err_genlmsg; |
| 450 | } |
| 451 | |
| 452 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) |
| 453 | goto nla_put_failure; |
| 454 | |
| 455 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time)) |
| 456 | goto nla_put_failure; |
| 457 | |
| 458 | if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes, |
| 459 | BATADV_ATTR_PAD)) |
| 460 | goto nla_put_failure; |
| 461 | |
| 462 | if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result)) |
| 463 | goto nla_put_failure; |
| 464 | |
| 465 | if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst)) |
| 466 | goto nla_put_failure; |
| 467 | |
| 468 | genlmsg_end(msg, hdr); |
| 469 | |
| 470 | genlmsg_multicast_netns(&batadv_netlink_family, |
| 471 | dev_net(bat_priv->soft_iface), msg, 0, |
| 472 | BATADV_NL_MCGRP_TPMETER, GFP_KERNEL); |
| 473 | |
| 474 | return 0; |
| 475 | |
| 476 | nla_put_failure: |
| 477 | genlmsg_cancel(msg, hdr); |
| 478 | ret = -EMSGSIZE; |
| 479 | |
| 480 | err_genlmsg: |
| 481 | nlmsg_free(msg); |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 486 | * batadv_netlink_tp_meter_start() - Start a new tp_meter session |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 487 | * @skb: received netlink message |
| 488 | * @info: receiver information |
| 489 | * |
| 490 | * Return: 0 on success, < 0 on error |
| 491 | */ |
| 492 | static int |
| 493 | batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info) |
| 494 | { |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 495 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 496 | struct sk_buff *msg = NULL; |
| 497 | u32 test_length; |
| 498 | void *msg_head; |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 499 | u32 cookie; |
| 500 | u8 *dst; |
| 501 | int ret; |
| 502 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 503 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) |
| 504 | return -EINVAL; |
| 505 | |
| 506 | if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]) |
| 507 | return -EINVAL; |
| 508 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 509 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); |
| 510 | |
| 511 | test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]); |
| 512 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 514 | if (!msg) { |
| 515 | ret = -ENOMEM; |
| 516 | goto out; |
| 517 | } |
| 518 | |
| 519 | msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, |
| 520 | &batadv_netlink_family, 0, |
| 521 | BATADV_CMD_TP_METER); |
| 522 | if (!msg_head) { |
| 523 | ret = -ENOBUFS; |
| 524 | goto out; |
| 525 | } |
| 526 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 527 | batadv_tp_start(bat_priv, dst, test_length, &cookie); |
| 528 | |
| 529 | ret = batadv_netlink_tp_meter_put(msg, cookie); |
| 530 | |
| 531 | out: |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 532 | if (ret) { |
| 533 | if (msg) |
| 534 | nlmsg_free(msg); |
| 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | genlmsg_end(msg, msg_head); |
| 539 | return genlmsg_reply(msg, info); |
| 540 | } |
| 541 | |
| 542 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 543 | * batadv_netlink_tp_meter_start() - Cancel a running tp_meter session |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 544 | * @skb: received netlink message |
| 545 | * @info: receiver information |
| 546 | * |
| 547 | * Return: 0 on success, < 0 on error |
| 548 | */ |
| 549 | static int |
| 550 | batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info) |
| 551 | { |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 552 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 553 | u8 *dst; |
| 554 | int ret = 0; |
| 555 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 556 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) |
| 557 | return -EINVAL; |
| 558 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 559 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); |
| 560 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 561 | batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL); |
| 562 | |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 566 | /** |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 567 | * batadv_netlink_hardif_fill() - Fill message with hardif attributes |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 568 | * @msg: Netlink message to dump into |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 569 | * @bat_priv: the bat priv with all the soft interface information |
| 570 | * @hard_iface: hard interface which was modified |
| 571 | * @cmd: type of message to generate |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 572 | * @portid: Port making netlink request |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 573 | * @seq: sequence number for message |
| 574 | * @flags: Additional flags for message |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 575 | * @cb: Control block containing additional options |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 576 | * |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 577 | * Return: 0 on success or negative error number in case of failure |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 578 | */ |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 579 | static int batadv_netlink_hardif_fill(struct sk_buff *msg, |
| 580 | struct batadv_priv *bat_priv, |
| 581 | struct batadv_hard_iface *hard_iface, |
| 582 | enum batadv_nl_commands cmd, |
| 583 | u32 portid, u32 seq, int flags, |
| 584 | struct netlink_callback *cb) |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 585 | { |
| 586 | struct net_device *net_dev = hard_iface->net_dev; |
| 587 | void *hdr; |
| 588 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 589 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 590 | if (!hdr) |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 591 | return -ENOBUFS; |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 592 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 593 | if (cb) |
| 594 | genl_dump_check_consistent(cb, hdr); |
| 595 | |
| 596 | if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, |
| 597 | bat_priv->soft_iface->ifindex)) |
| 598 | goto nla_put_failure; |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 599 | |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 600 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, |
| 601 | net_dev->ifindex) || |
| 602 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, |
| 603 | net_dev->name) || |
| 604 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, |
| 605 | net_dev->dev_addr)) |
| 606 | goto nla_put_failure; |
| 607 | |
| 608 | if (hard_iface->if_status == BATADV_IF_ACTIVE) { |
| 609 | if (nla_put_flag(msg, BATADV_ATTR_ACTIVE)) |
| 610 | goto nla_put_failure; |
| 611 | } |
| 612 | |
| 613 | genlmsg_end(msg, hdr); |
| 614 | return 0; |
| 615 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 616 | nla_put_failure: |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 617 | genlmsg_cancel(msg, hdr); |
| 618 | return -EMSGSIZE; |
| 619 | } |
| 620 | |
| 621 | /** |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 622 | * batadv_netlink_notify_hardif() - send hardif attributes to listener |
| 623 | * @bat_priv: the bat priv with all the soft interface information |
| 624 | * @hard_iface: hard interface which was modified |
| 625 | * |
| 626 | * Return: 0 on success, < 0 on error |
| 627 | */ |
| 628 | static int batadv_netlink_notify_hardif(struct batadv_priv *bat_priv, |
| 629 | struct batadv_hard_iface *hard_iface) |
| 630 | { |
| 631 | struct sk_buff *msg; |
| 632 | int ret; |
| 633 | |
| 634 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 635 | if (!msg) |
| 636 | return -ENOMEM; |
| 637 | |
| 638 | ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
| 639 | BATADV_CMD_SET_HARDIF, 0, 0, 0, NULL); |
| 640 | if (ret < 0) { |
| 641 | nlmsg_free(msg); |
| 642 | return ret; |
| 643 | } |
| 644 | |
| 645 | genlmsg_multicast_netns(&batadv_netlink_family, |
| 646 | dev_net(bat_priv->soft_iface), msg, 0, |
| 647 | BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * batadv_netlink_get_hardif() - Get hardif attributes |
| 654 | * @skb: Netlink message with request data |
| 655 | * @info: receiver information |
| 656 | * |
| 657 | * Return: 0 on success or negative error number in case of failure |
| 658 | */ |
| 659 | static int batadv_netlink_get_hardif(struct sk_buff *skb, |
| 660 | struct genl_info *info) |
| 661 | { |
| 662 | struct batadv_hard_iface *hard_iface = info->user_ptr[1]; |
| 663 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
| 664 | struct sk_buff *msg; |
| 665 | int ret; |
| 666 | |
| 667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 668 | if (!msg) |
| 669 | return -ENOMEM; |
| 670 | |
| 671 | ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
| 672 | BATADV_CMD_GET_HARDIF, |
| 673 | info->snd_portid, info->snd_seq, 0, |
| 674 | NULL); |
| 675 | if (ret < 0) { |
| 676 | nlmsg_free(msg); |
| 677 | return ret; |
| 678 | } |
| 679 | |
| 680 | ret = genlmsg_reply(msg, info); |
| 681 | |
| 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * batadv_netlink_set_hardif() - Set hardif attributes |
| 687 | * @skb: Netlink message with request data |
| 688 | * @info: receiver information |
| 689 | * |
| 690 | * Return: 0 on success or negative error number in case of failure |
| 691 | */ |
| 692 | static int batadv_netlink_set_hardif(struct sk_buff *skb, |
| 693 | struct genl_info *info) |
| 694 | { |
| 695 | struct batadv_hard_iface *hard_iface = info->user_ptr[1]; |
| 696 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
| 697 | |
| 698 | batadv_netlink_notify_hardif(bat_priv, hard_iface); |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * batadv_netlink_dump_hardif() - Dump all hard interface into a messages |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 705 | * @msg: Netlink message to dump into |
| 706 | * @cb: Parameters from query |
| 707 | * |
| 708 | * Return: error code, or length of reply message on success |
| 709 | */ |
| 710 | static int |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 711 | batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb) |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 712 | { |
| 713 | struct net *net = sock_net(cb->skb->sk); |
| 714 | struct net_device *soft_iface; |
| 715 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 716 | struct batadv_priv *bat_priv; |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 717 | int ifindex; |
| 718 | int portid = NETLINK_CB(cb->skb).portid; |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 719 | int skip = cb->args[0]; |
| 720 | int i = 0; |
| 721 | |
| 722 | ifindex = batadv_netlink_get_ifindex(cb->nlh, |
| 723 | BATADV_ATTR_MESH_IFINDEX); |
| 724 | if (!ifindex) |
| 725 | return -EINVAL; |
| 726 | |
| 727 | soft_iface = dev_get_by_index(net, ifindex); |
| 728 | if (!soft_iface) |
| 729 | return -ENODEV; |
| 730 | |
| 731 | if (!batadv_softif_is_valid(soft_iface)) { |
| 732 | dev_put(soft_iface); |
| 733 | return -ENODEV; |
| 734 | } |
| 735 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 736 | bat_priv = netdev_priv(soft_iface); |
| 737 | |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 738 | rtnl_lock(); |
| 739 | cb->seq = batadv_hardif_generation << 1 | 1; |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 740 | |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 741 | list_for_each_entry(hard_iface, &batadv_hardif_list, list) { |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 742 | if (hard_iface->soft_iface != soft_iface) |
| 743 | continue; |
| 744 | |
| 745 | if (i++ < skip) |
| 746 | continue; |
| 747 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 748 | if (batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
| 749 | BATADV_CMD_GET_HARDIF, |
| 750 | portid, cb->nlh->nlmsg_seq, |
| 751 | NLM_F_MULTI, cb)) { |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 752 | i--; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | |
Sven Eckelmann | fb69be6 | 2018-10-30 22:01:24 +0100 | [diff] [blame] | 757 | rtnl_unlock(); |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 758 | |
| 759 | dev_put(soft_iface); |
| 760 | |
| 761 | cb->args[0] = i; |
| 762 | |
| 763 | return msg->len; |
| 764 | } |
| 765 | |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 766 | /** |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 767 | * batadv_netlink_vlan_fill() - Fill message with vlan attributes |
| 768 | * @msg: Netlink message to dump into |
| 769 | * @bat_priv: the bat priv with all the soft interface information |
| 770 | * @vlan: vlan which was modified |
| 771 | * @cmd: type of message to generate |
| 772 | * @portid: Port making netlink request |
| 773 | * @seq: sequence number for message |
| 774 | * @flags: Additional flags for message |
| 775 | * |
| 776 | * Return: 0 on success or negative error number in case of failure |
| 777 | */ |
| 778 | static int batadv_netlink_vlan_fill(struct sk_buff *msg, |
| 779 | struct batadv_priv *bat_priv, |
| 780 | struct batadv_softif_vlan *vlan, |
| 781 | enum batadv_nl_commands cmd, |
| 782 | u32 portid, u32 seq, int flags) |
| 783 | { |
| 784 | void *hdr; |
| 785 | |
| 786 | hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
| 787 | if (!hdr) |
| 788 | return -ENOBUFS; |
| 789 | |
| 790 | if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, |
| 791 | bat_priv->soft_iface->ifindex)) |
| 792 | goto nla_put_failure; |
| 793 | |
| 794 | if (nla_put_u32(msg, BATADV_ATTR_VLANID, vlan->vid & VLAN_VID_MASK)) |
| 795 | goto nla_put_failure; |
| 796 | |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 797 | if (nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED, |
| 798 | !!atomic_read(&vlan->ap_isolation))) |
| 799 | goto nla_put_failure; |
| 800 | |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 801 | genlmsg_end(msg, hdr); |
| 802 | return 0; |
| 803 | |
| 804 | nla_put_failure: |
| 805 | genlmsg_cancel(msg, hdr); |
| 806 | return -EMSGSIZE; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * batadv_netlink_notify_vlan() - send vlan attributes to listener |
| 811 | * @bat_priv: the bat priv with all the soft interface information |
| 812 | * @vlan: vlan which was modified |
| 813 | * |
| 814 | * Return: 0 on success, < 0 on error |
| 815 | */ |
| 816 | static int batadv_netlink_notify_vlan(struct batadv_priv *bat_priv, |
| 817 | struct batadv_softif_vlan *vlan) |
| 818 | { |
| 819 | struct sk_buff *msg; |
| 820 | int ret; |
| 821 | |
| 822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 823 | if (!msg) |
| 824 | return -ENOMEM; |
| 825 | |
| 826 | ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, |
| 827 | BATADV_CMD_SET_VLAN, 0, 0, 0); |
| 828 | if (ret < 0) { |
| 829 | nlmsg_free(msg); |
| 830 | return ret; |
| 831 | } |
| 832 | |
| 833 | genlmsg_multicast_netns(&batadv_netlink_family, |
| 834 | dev_net(bat_priv->soft_iface), msg, 0, |
| 835 | BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
| 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | /** |
| 841 | * batadv_netlink_get_vlan() - Get vlan attributes |
| 842 | * @skb: Netlink message with request data |
| 843 | * @info: receiver information |
| 844 | * |
| 845 | * Return: 0 on success or negative error number in case of failure |
| 846 | */ |
| 847 | static int batadv_netlink_get_vlan(struct sk_buff *skb, struct genl_info *info) |
| 848 | { |
| 849 | struct batadv_softif_vlan *vlan = info->user_ptr[1]; |
| 850 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
| 851 | struct sk_buff *msg; |
| 852 | int ret; |
| 853 | |
| 854 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 855 | if (!msg) |
| 856 | return -ENOMEM; |
| 857 | |
| 858 | ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, BATADV_CMD_GET_VLAN, |
| 859 | info->snd_portid, info->snd_seq, 0); |
| 860 | if (ret < 0) { |
| 861 | nlmsg_free(msg); |
| 862 | return ret; |
| 863 | } |
| 864 | |
| 865 | ret = genlmsg_reply(msg, info); |
| 866 | |
| 867 | return ret; |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * batadv_netlink_set_vlan() - Get vlan attributes |
| 872 | * @skb: Netlink message with request data |
| 873 | * @info: receiver information |
| 874 | * |
| 875 | * Return: 0 on success or negative error number in case of failure |
| 876 | */ |
| 877 | static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info) |
| 878 | { |
| 879 | struct batadv_softif_vlan *vlan = info->user_ptr[1]; |
| 880 | struct batadv_priv *bat_priv = info->user_ptr[0]; |
Sven Eckelmann | e43d16b | 2018-11-23 12:51:55 +0100 | [diff] [blame] | 881 | struct nlattr *attr; |
| 882 | |
| 883 | if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) { |
| 884 | attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]; |
| 885 | |
| 886 | atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr)); |
| 887 | } |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 888 | |
| 889 | batadv_netlink_notify_vlan(bat_priv, vlan); |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | /** |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 895 | * batadv_get_softif_from_info() - Retrieve soft interface from genl attributes |
| 896 | * @net: the applicable net namespace |
| 897 | * @info: receiver information |
| 898 | * |
| 899 | * Return: Pointer to soft interface (with increased refcnt) on success, error |
| 900 | * pointer on error |
| 901 | */ |
| 902 | static struct net_device * |
| 903 | batadv_get_softif_from_info(struct net *net, struct genl_info *info) |
| 904 | { |
| 905 | struct net_device *soft_iface; |
| 906 | int ifindex; |
| 907 | |
| 908 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) |
| 909 | return ERR_PTR(-EINVAL); |
| 910 | |
| 911 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); |
| 912 | |
| 913 | soft_iface = dev_get_by_index(net, ifindex); |
| 914 | if (!soft_iface) |
| 915 | return ERR_PTR(-ENODEV); |
| 916 | |
| 917 | if (!batadv_softif_is_valid(soft_iface)) |
| 918 | goto err_put_softif; |
| 919 | |
| 920 | return soft_iface; |
| 921 | |
| 922 | err_put_softif: |
| 923 | dev_put(soft_iface); |
| 924 | |
| 925 | return ERR_PTR(-EINVAL); |
| 926 | } |
| 927 | |
| 928 | /** |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 929 | * batadv_get_hardif_from_info() - Retrieve hardif from genl attributes |
| 930 | * @bat_priv: the bat priv with all the soft interface information |
| 931 | * @net: the applicable net namespace |
| 932 | * @info: receiver information |
| 933 | * |
| 934 | * Return: Pointer to hard interface (with increased refcnt) on success, error |
| 935 | * pointer on error |
| 936 | */ |
| 937 | static struct batadv_hard_iface * |
| 938 | batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net, |
| 939 | struct genl_info *info) |
| 940 | { |
| 941 | struct batadv_hard_iface *hard_iface; |
| 942 | struct net_device *hard_dev; |
| 943 | unsigned int hardif_index; |
| 944 | |
| 945 | if (!info->attrs[BATADV_ATTR_HARD_IFINDEX]) |
| 946 | return ERR_PTR(-EINVAL); |
| 947 | |
| 948 | hardif_index = nla_get_u32(info->attrs[BATADV_ATTR_HARD_IFINDEX]); |
| 949 | |
| 950 | hard_dev = dev_get_by_index(net, hardif_index); |
| 951 | if (!hard_dev) |
| 952 | return ERR_PTR(-ENODEV); |
| 953 | |
| 954 | hard_iface = batadv_hardif_get_by_netdev(hard_dev); |
| 955 | if (!hard_iface) |
| 956 | goto err_put_harddev; |
| 957 | |
| 958 | if (hard_iface->soft_iface != bat_priv->soft_iface) |
| 959 | goto err_put_hardif; |
| 960 | |
| 961 | /* hard_dev is referenced by hard_iface and not needed here */ |
| 962 | dev_put(hard_dev); |
| 963 | |
| 964 | return hard_iface; |
| 965 | |
| 966 | err_put_hardif: |
| 967 | batadv_hardif_put(hard_iface); |
| 968 | err_put_harddev: |
| 969 | dev_put(hard_dev); |
| 970 | |
| 971 | return ERR_PTR(-EINVAL); |
| 972 | } |
| 973 | |
| 974 | /** |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 975 | * batadv_get_vlan_from_info() - Retrieve vlan from genl attributes |
| 976 | * @bat_priv: the bat priv with all the soft interface information |
| 977 | * @net: the applicable net namespace |
| 978 | * @info: receiver information |
| 979 | * |
| 980 | * Return: Pointer to vlan on success (with increased refcnt), error pointer |
| 981 | * on error |
| 982 | */ |
| 983 | static struct batadv_softif_vlan * |
| 984 | batadv_get_vlan_from_info(struct batadv_priv *bat_priv, struct net *net, |
| 985 | struct genl_info *info) |
| 986 | { |
| 987 | struct batadv_softif_vlan *vlan; |
| 988 | u16 vid; |
| 989 | |
| 990 | if (!info->attrs[BATADV_ATTR_VLANID]) |
| 991 | return ERR_PTR(-EINVAL); |
| 992 | |
| 993 | vid = nla_get_u16(info->attrs[BATADV_ATTR_VLANID]); |
| 994 | |
| 995 | vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG); |
| 996 | if (!vlan) |
| 997 | return ERR_PTR(-ENOENT); |
| 998 | |
| 999 | return vlan; |
| 1000 | } |
| 1001 | |
| 1002 | /** |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1003 | * batadv_pre_doit() - Prepare batman-adv genl doit request |
| 1004 | * @ops: requested netlink operation |
| 1005 | * @skb: Netlink message with request data |
| 1006 | * @info: receiver information |
| 1007 | * |
| 1008 | * Return: 0 on success or negative error number in case of failure |
| 1009 | */ |
| 1010 | static int batadv_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
| 1011 | struct genl_info *info) |
| 1012 | { |
| 1013 | struct net *net = genl_info_net(info); |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1014 | struct batadv_hard_iface *hard_iface; |
| 1015 | struct batadv_priv *bat_priv = NULL; |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1016 | struct batadv_softif_vlan *vlan; |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1017 | struct net_device *soft_iface; |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1018 | u8 user_ptr1_flags; |
| 1019 | u8 mesh_dep_flags; |
| 1020 | int ret; |
| 1021 | |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1022 | user_ptr1_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN; |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1023 | if (WARN_ON(hweight8(ops->internal_flags & user_ptr1_flags) > 1)) |
| 1024 | return -EINVAL; |
| 1025 | |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1026 | mesh_dep_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN; |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1027 | if (WARN_ON((ops->internal_flags & mesh_dep_flags) && |
| 1028 | (~ops->internal_flags & BATADV_FLAG_NEED_MESH))) |
| 1029 | return -EINVAL; |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1030 | |
| 1031 | if (ops->internal_flags & BATADV_FLAG_NEED_MESH) { |
| 1032 | soft_iface = batadv_get_softif_from_info(net, info); |
| 1033 | if (IS_ERR(soft_iface)) |
| 1034 | return PTR_ERR(soft_iface); |
| 1035 | |
| 1036 | bat_priv = netdev_priv(soft_iface); |
| 1037 | info->user_ptr[0] = bat_priv; |
| 1038 | } |
| 1039 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1040 | if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF) { |
| 1041 | hard_iface = batadv_get_hardif_from_info(bat_priv, net, info); |
| 1042 | if (IS_ERR(hard_iface)) { |
| 1043 | ret = PTR_ERR(hard_iface); |
| 1044 | goto err_put_softif; |
| 1045 | } |
| 1046 | |
| 1047 | info->user_ptr[1] = hard_iface; |
| 1048 | } |
| 1049 | |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1050 | if (ops->internal_flags & BATADV_FLAG_NEED_VLAN) { |
| 1051 | vlan = batadv_get_vlan_from_info(bat_priv, net, info); |
| 1052 | if (IS_ERR(vlan)) { |
| 1053 | ret = PTR_ERR(vlan); |
| 1054 | goto err_put_softif; |
| 1055 | } |
| 1056 | |
| 1057 | info->user_ptr[1] = vlan; |
| 1058 | } |
| 1059 | |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1060 | return 0; |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1061 | |
| 1062 | err_put_softif: |
| 1063 | if (bat_priv) |
| 1064 | dev_put(bat_priv->soft_iface); |
| 1065 | |
| 1066 | return ret; |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /** |
| 1070 | * batadv_post_doit() - End batman-adv genl doit request |
| 1071 | * @ops: requested netlink operation |
| 1072 | * @skb: Netlink message with request data |
| 1073 | * @info: receiver information |
| 1074 | */ |
| 1075 | static void batadv_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
| 1076 | struct genl_info *info) |
| 1077 | { |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1078 | struct batadv_hard_iface *hard_iface; |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1079 | struct batadv_softif_vlan *vlan; |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1080 | struct batadv_priv *bat_priv; |
| 1081 | |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1082 | if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF && |
| 1083 | info->user_ptr[1]) { |
| 1084 | hard_iface = info->user_ptr[1]; |
| 1085 | |
| 1086 | batadv_hardif_put(hard_iface); |
| 1087 | } |
| 1088 | |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1089 | if (ops->internal_flags & BATADV_FLAG_NEED_VLAN && info->user_ptr[1]) { |
| 1090 | vlan = info->user_ptr[1]; |
| 1091 | batadv_softif_vlan_put(vlan); |
| 1092 | } |
| 1093 | |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1094 | if (ops->internal_flags & BATADV_FLAG_NEED_MESH && info->user_ptr[0]) { |
| 1095 | bat_priv = info->user_ptr[0]; |
| 1096 | dev_put(bat_priv->soft_iface); |
| 1097 | } |
| 1098 | } |
| 1099 | |
Sven Eckelmann | ce1a21d | 2016-10-18 15:57:36 +0200 | [diff] [blame] | 1100 | static const struct genl_ops batadv_netlink_ops[] = { |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 1101 | { |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 1102 | .cmd = BATADV_CMD_GET_MESH, |
| 1103 | /* can be retrieved by unprivileged users */ |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 1104 | .policy = batadv_netlink_policy, |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 1105 | .doit = batadv_netlink_get_mesh, |
| 1106 | .internal_flags = BATADV_FLAG_NEED_MESH, |
Matthias Schiffer | 5da0aef | 2016-05-09 18:41:09 +0200 | [diff] [blame] | 1107 | }, |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 1108 | { |
| 1109 | .cmd = BATADV_CMD_TP_METER, |
| 1110 | .flags = GENL_ADMIN_PERM, |
| 1111 | .policy = batadv_netlink_policy, |
| 1112 | .doit = batadv_netlink_tp_meter_start, |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1113 | .internal_flags = BATADV_FLAG_NEED_MESH, |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 1114 | }, |
| 1115 | { |
| 1116 | .cmd = BATADV_CMD_TP_METER_CANCEL, |
| 1117 | .flags = GENL_ADMIN_PERM, |
| 1118 | .policy = batadv_netlink_policy, |
| 1119 | .doit = batadv_netlink_tp_meter_cancel, |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1120 | .internal_flags = BATADV_FLAG_NEED_MESH, |
Antonio Quartulli | 33a3bb4 | 2016-05-05 13:09:43 +0200 | [diff] [blame] | 1121 | }, |
Matthias Schiffer | 07a3061 | 2016-07-03 13:31:35 +0200 | [diff] [blame] | 1122 | { |
| 1123 | .cmd = BATADV_CMD_GET_ROUTING_ALGOS, |
| 1124 | .flags = GENL_ADMIN_PERM, |
| 1125 | .policy = batadv_netlink_policy, |
| 1126 | .dumpit = batadv_algo_dump, |
| 1127 | }, |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 1128 | { |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1129 | .cmd = BATADV_CMD_GET_HARDIF, |
| 1130 | /* can be retrieved by unprivileged users */ |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 1131 | .policy = batadv_netlink_policy, |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1132 | .dumpit = batadv_netlink_dump_hardif, |
| 1133 | .doit = batadv_netlink_get_hardif, |
| 1134 | .internal_flags = BATADV_FLAG_NEED_MESH | |
| 1135 | BATADV_FLAG_NEED_HARDIF, |
Matthias Schiffer | b60620c | 2016-07-03 13:31:36 +0200 | [diff] [blame] | 1136 | }, |
Matthias Schiffer | d34f055 | 2016-07-03 13:31:37 +0200 | [diff] [blame] | 1137 | { |
| 1138 | .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, |
| 1139 | .flags = GENL_ADMIN_PERM, |
| 1140 | .policy = batadv_netlink_policy, |
| 1141 | .dumpit = batadv_tt_local_dump, |
| 1142 | }, |
| 1143 | { |
| 1144 | .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, |
| 1145 | .flags = GENL_ADMIN_PERM, |
| 1146 | .policy = batadv_netlink_policy, |
| 1147 | .dumpit = batadv_tt_global_dump, |
| 1148 | }, |
Matthias Schiffer | 85cf8c8 | 2016-07-03 13:31:39 +0200 | [diff] [blame] | 1149 | { |
| 1150 | .cmd = BATADV_CMD_GET_ORIGINATORS, |
| 1151 | .flags = GENL_ADMIN_PERM, |
| 1152 | .policy = batadv_netlink_policy, |
| 1153 | .dumpit = batadv_orig_dump, |
| 1154 | }, |
| 1155 | { |
| 1156 | .cmd = BATADV_CMD_GET_NEIGHBORS, |
| 1157 | .flags = GENL_ADMIN_PERM, |
| 1158 | .policy = batadv_netlink_policy, |
| 1159 | .dumpit = batadv_hardif_neigh_dump, |
| 1160 | }, |
Sven Eckelmann | d7129da | 2016-07-03 13:31:42 +0200 | [diff] [blame] | 1161 | { |
| 1162 | .cmd = BATADV_CMD_GET_GATEWAYS, |
| 1163 | .flags = GENL_ADMIN_PERM, |
| 1164 | .policy = batadv_netlink_policy, |
| 1165 | .dumpit = batadv_gw_dump, |
| 1166 | }, |
Andrew Lunn | 04f3f5b | 2016-07-03 13:31:45 +0200 | [diff] [blame] | 1167 | { |
| 1168 | .cmd = BATADV_CMD_GET_BLA_CLAIM, |
| 1169 | .flags = GENL_ADMIN_PERM, |
| 1170 | .policy = batadv_netlink_policy, |
| 1171 | .dumpit = batadv_bla_claim_dump, |
| 1172 | }, |
Simon Wunderlich | ea4152e | 2016-07-03 13:31:47 +0200 | [diff] [blame] | 1173 | { |
| 1174 | .cmd = BATADV_CMD_GET_BLA_BACKBONE, |
| 1175 | .flags = GENL_ADMIN_PERM, |
| 1176 | .policy = batadv_netlink_policy, |
| 1177 | .dumpit = batadv_bla_backbone_dump, |
| 1178 | }, |
Linus Lüssing | 41aeefc | 2018-03-13 11:41:12 +0100 | [diff] [blame] | 1179 | { |
| 1180 | .cmd = BATADV_CMD_GET_DAT_CACHE, |
| 1181 | .flags = GENL_ADMIN_PERM, |
| 1182 | .policy = batadv_netlink_policy, |
| 1183 | .dumpit = batadv_dat_cache_dump, |
| 1184 | }, |
Linus Lüssing | 53dd9a6 | 2018-03-13 11:41:13 +0100 | [diff] [blame] | 1185 | { |
| 1186 | .cmd = BATADV_CMD_GET_MCAST_FLAGS, |
| 1187 | .flags = GENL_ADMIN_PERM, |
| 1188 | .policy = batadv_netlink_policy, |
| 1189 | .dumpit = batadv_mcast_flags_dump, |
| 1190 | }, |
Sven Eckelmann | 6004051 | 2018-11-23 12:14:56 +0100 | [diff] [blame] | 1191 | { |
| 1192 | .cmd = BATADV_CMD_SET_MESH, |
| 1193 | .flags = GENL_ADMIN_PERM, |
| 1194 | .policy = batadv_netlink_policy, |
| 1195 | .doit = batadv_netlink_set_mesh, |
| 1196 | .internal_flags = BATADV_FLAG_NEED_MESH, |
| 1197 | }, |
Sven Eckelmann | 5c55a40 | 2018-11-23 12:33:17 +0100 | [diff] [blame] | 1198 | { |
| 1199 | .cmd = BATADV_CMD_SET_HARDIF, |
| 1200 | .flags = GENL_ADMIN_PERM, |
| 1201 | .policy = batadv_netlink_policy, |
| 1202 | .doit = batadv_netlink_set_hardif, |
| 1203 | .internal_flags = BATADV_FLAG_NEED_MESH | |
| 1204 | BATADV_FLAG_NEED_HARDIF, |
| 1205 | }, |
Sven Eckelmann | 49e7e37 | 2018-11-23 12:41:08 +0100 | [diff] [blame] | 1206 | { |
| 1207 | .cmd = BATADV_CMD_GET_VLAN, |
| 1208 | /* can be retrieved by unprivileged users */ |
| 1209 | .policy = batadv_netlink_policy, |
| 1210 | .doit = batadv_netlink_get_vlan, |
| 1211 | .internal_flags = BATADV_FLAG_NEED_MESH | |
| 1212 | BATADV_FLAG_NEED_VLAN, |
| 1213 | }, |
| 1214 | { |
| 1215 | .cmd = BATADV_CMD_SET_VLAN, |
| 1216 | .flags = GENL_ADMIN_PERM, |
| 1217 | .policy = batadv_netlink_policy, |
| 1218 | .doit = batadv_netlink_set_vlan, |
| 1219 | .internal_flags = BATADV_FLAG_NEED_MESH | |
| 1220 | BATADV_FLAG_NEED_VLAN, |
| 1221 | }, |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 1222 | }; |
| 1223 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 1224 | struct genl_family batadv_netlink_family __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1225 | .hdrsize = 0, |
| 1226 | .name = BATADV_NL_NAME, |
| 1227 | .version = 1, |
| 1228 | .maxattr = BATADV_ATTR_MAX, |
| 1229 | .netnsok = true, |
Sven Eckelmann | c4a7a8d | 2018-11-23 12:00:28 +0100 | [diff] [blame] | 1230 | .pre_doit = batadv_pre_doit, |
| 1231 | .post_doit = batadv_post_doit, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1232 | .module = THIS_MODULE, |
| 1233 | .ops = batadv_netlink_ops, |
| 1234 | .n_ops = ARRAY_SIZE(batadv_netlink_ops), |
| 1235 | .mcgrps = batadv_netlink_mcgrps, |
| 1236 | .n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps), |
| 1237 | }; |
| 1238 | |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 1239 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1240 | * batadv_netlink_register() - register batadv genl netlink family |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 1241 | */ |
| 1242 | void __init batadv_netlink_register(void) |
| 1243 | { |
| 1244 | int ret; |
| 1245 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1246 | ret = genl_register_family(&batadv_netlink_family); |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 1247 | if (ret) |
| 1248 | pr_warn("unable to register netlink family"); |
| 1249 | } |
| 1250 | |
| 1251 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 1252 | * batadv_netlink_unregister() - unregister batadv genl netlink family |
Matthias Schiffer | 09748a2 | 2016-05-09 18:41:08 +0200 | [diff] [blame] | 1253 | */ |
| 1254 | void batadv_netlink_unregister(void) |
| 1255 | { |
| 1256 | genl_unregister_family(&batadv_netlink_family); |
| 1257 | } |