| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -/* Copyright (C) 2016-2018 B.A.T.M.A.N. contributors: |
|---|
| 2 | +/* Copyright (C) 2016-2020 B.A.T.M.A.N. contributors: |
|---|
| 3 | 3 | * |
|---|
| 4 | 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 | 5 | */ |
|---|
| 18 | 6 | |
|---|
| 19 | 7 | #include "netlink.h" |
|---|
| 20 | 8 | #include "main.h" |
|---|
| 21 | 9 | |
|---|
| 22 | 10 | #include <linux/atomic.h> |
|---|
| 11 | +#include <linux/bitops.h> |
|---|
| 12 | +#include <linux/bug.h> |
|---|
| 23 | 13 | #include <linux/byteorder/generic.h> |
|---|
| 24 | 14 | #include <linux/cache.h> |
|---|
| 15 | +#include <linux/err.h> |
|---|
| 25 | 16 | #include <linux/errno.h> |
|---|
| 26 | 17 | #include <linux/export.h> |
|---|
| 27 | 18 | #include <linux/genetlink.h> |
|---|
| 28 | 19 | #include <linux/gfp.h> |
|---|
| 29 | 20 | #include <linux/if_ether.h> |
|---|
| 21 | +#include <linux/if_vlan.h> |
|---|
| 30 | 22 | #include <linux/init.h> |
|---|
| 31 | 23 | #include <linux/kernel.h> |
|---|
| 24 | +#include <linux/limits.h> |
|---|
| 25 | +#include <linux/list.h> |
|---|
| 32 | 26 | #include <linux/netdevice.h> |
|---|
| 33 | 27 | #include <linux/netlink.h> |
|---|
| 34 | 28 | #include <linux/printk.h> |
|---|
| 35 | | -#include <linux/rculist.h> |
|---|
| 36 | | -#include <linux/rcupdate.h> |
|---|
| 29 | +#include <linux/rtnetlink.h> |
|---|
| 37 | 30 | #include <linux/skbuff.h> |
|---|
| 38 | 31 | #include <linux/stddef.h> |
|---|
| 39 | 32 | #include <linux/types.h> |
|---|
| 40 | 33 | #include <net/genetlink.h> |
|---|
| 34 | +#include <net/net_namespace.h> |
|---|
| 41 | 35 | #include <net/netlink.h> |
|---|
| 42 | 36 | #include <net/sock.h> |
|---|
| 43 | 37 | #include <uapi/linux/batadv_packet.h> |
|---|
| .. | .. |
|---|
| 47 | 41 | #include "bridge_loop_avoidance.h" |
|---|
| 48 | 42 | #include "distributed-arp-table.h" |
|---|
| 49 | 43 | #include "gateway_client.h" |
|---|
| 44 | +#include "gateway_common.h" |
|---|
| 50 | 45 | #include "hard-interface.h" |
|---|
| 46 | +#include "log.h" |
|---|
| 51 | 47 | #include "multicast.h" |
|---|
| 48 | +#include "network-coding.h" |
|---|
| 52 | 49 | #include "originator.h" |
|---|
| 53 | 50 | #include "soft-interface.h" |
|---|
| 54 | 51 | #include "tp_meter.h" |
|---|
| .. | .. |
|---|
| 58 | 55 | |
|---|
| 59 | 56 | /* multicast groups */ |
|---|
| 60 | 57 | enum batadv_netlink_multicast_groups { |
|---|
| 58 | + BATADV_NL_MCGRP_CONFIG, |
|---|
| 61 | 59 | BATADV_NL_MCGRP_TPMETER, |
|---|
| 62 | 60 | }; |
|---|
| 63 | 61 | |
|---|
| 62 | +/** |
|---|
| 63 | + * enum batadv_genl_ops_flags - flags for genl_ops's internal_flags |
|---|
| 64 | + */ |
|---|
| 65 | +enum batadv_genl_ops_flags { |
|---|
| 66 | + /** |
|---|
| 67 | + * @BATADV_FLAG_NEED_MESH: request requires valid soft interface in |
|---|
| 68 | + * attribute BATADV_ATTR_MESH_IFINDEX and expects a pointer to it to be |
|---|
| 69 | + * saved in info->user_ptr[0] |
|---|
| 70 | + */ |
|---|
| 71 | + BATADV_FLAG_NEED_MESH = BIT(0), |
|---|
| 72 | + |
|---|
| 73 | + /** |
|---|
| 74 | + * @BATADV_FLAG_NEED_HARDIF: request requires valid hard interface in |
|---|
| 75 | + * attribute BATADV_ATTR_HARD_IFINDEX and expects a pointer to it to be |
|---|
| 76 | + * saved in info->user_ptr[1] |
|---|
| 77 | + */ |
|---|
| 78 | + BATADV_FLAG_NEED_HARDIF = BIT(1), |
|---|
| 79 | + |
|---|
| 80 | + /** |
|---|
| 81 | + * @BATADV_FLAG_NEED_VLAN: request requires valid vlan in |
|---|
| 82 | + * attribute BATADV_ATTR_VLANID and expects a pointer to it to be |
|---|
| 83 | + * saved in info->user_ptr[1] |
|---|
| 84 | + */ |
|---|
| 85 | + BATADV_FLAG_NEED_VLAN = BIT(2), |
|---|
| 86 | +}; |
|---|
| 87 | + |
|---|
| 64 | 88 | static const struct genl_multicast_group batadv_netlink_mcgrps[] = { |
|---|
| 89 | + [BATADV_NL_MCGRP_CONFIG] = { .name = BATADV_NL_MCAST_GROUP_CONFIG }, |
|---|
| 65 | 90 | [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER }, |
|---|
| 66 | 91 | }; |
|---|
| 67 | 92 | |
|---|
| .. | .. |
|---|
| 104 | 129 | [BATADV_ATTR_DAT_CACHE_VID] = { .type = NLA_U16 }, |
|---|
| 105 | 130 | [BATADV_ATTR_MCAST_FLAGS] = { .type = NLA_U32 }, |
|---|
| 106 | 131 | [BATADV_ATTR_MCAST_FLAGS_PRIV] = { .type = NLA_U32 }, |
|---|
| 132 | + [BATADV_ATTR_VLANID] = { .type = NLA_U16 }, |
|---|
| 133 | + [BATADV_ATTR_AGGREGATED_OGMS_ENABLED] = { .type = NLA_U8 }, |
|---|
| 134 | + [BATADV_ATTR_AP_ISOLATION_ENABLED] = { .type = NLA_U8 }, |
|---|
| 135 | + [BATADV_ATTR_ISOLATION_MARK] = { .type = NLA_U32 }, |
|---|
| 136 | + [BATADV_ATTR_ISOLATION_MASK] = { .type = NLA_U32 }, |
|---|
| 137 | + [BATADV_ATTR_BONDING_ENABLED] = { .type = NLA_U8 }, |
|---|
| 138 | + [BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED] = { .type = NLA_U8 }, |
|---|
| 139 | + [BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED] = { .type = NLA_U8 }, |
|---|
| 140 | + [BATADV_ATTR_FRAGMENTATION_ENABLED] = { .type = NLA_U8 }, |
|---|
| 141 | + [BATADV_ATTR_GW_BANDWIDTH_DOWN] = { .type = NLA_U32 }, |
|---|
| 142 | + [BATADV_ATTR_GW_BANDWIDTH_UP] = { .type = NLA_U32 }, |
|---|
| 143 | + [BATADV_ATTR_GW_MODE] = { .type = NLA_U8 }, |
|---|
| 144 | + [BATADV_ATTR_GW_SEL_CLASS] = { .type = NLA_U32 }, |
|---|
| 145 | + [BATADV_ATTR_HOP_PENALTY] = { .type = NLA_U8 }, |
|---|
| 146 | + [BATADV_ATTR_LOG_LEVEL] = { .type = NLA_U32 }, |
|---|
| 147 | + [BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED] = { .type = NLA_U8 }, |
|---|
| 148 | + [BATADV_ATTR_MULTICAST_FANOUT] = { .type = NLA_U32 }, |
|---|
| 149 | + [BATADV_ATTR_NETWORK_CODING_ENABLED] = { .type = NLA_U8 }, |
|---|
| 150 | + [BATADV_ATTR_ORIG_INTERVAL] = { .type = NLA_U32 }, |
|---|
| 151 | + [BATADV_ATTR_ELP_INTERVAL] = { .type = NLA_U32 }, |
|---|
| 152 | + [BATADV_ATTR_THROUGHPUT_OVERRIDE] = { .type = NLA_U32 }, |
|---|
| 107 | 153 | }; |
|---|
| 108 | 154 | |
|---|
| 109 | 155 | /** |
|---|
| .. | .. |
|---|
| 122 | 168 | } |
|---|
| 123 | 169 | |
|---|
| 124 | 170 | /** |
|---|
| 125 | | - * batadv_netlink_mesh_info_put() - fill in generic information about mesh |
|---|
| 126 | | - * interface |
|---|
| 127 | | - * @msg: netlink message to be sent back |
|---|
| 128 | | - * @soft_iface: interface for which the data should be taken |
|---|
| 171 | + * batadv_netlink_mesh_fill_ap_isolation() - Add ap_isolation softif attribute |
|---|
| 172 | + * @msg: Netlink message to dump into |
|---|
| 173 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 129 | 174 | * |
|---|
| 130 | | - * Return: 0 on success, < 0 on error |
|---|
| 175 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 131 | 176 | */ |
|---|
| 132 | | -static int |
|---|
| 133 | | -batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface) |
|---|
| 177 | +static int batadv_netlink_mesh_fill_ap_isolation(struct sk_buff *msg, |
|---|
| 178 | + struct batadv_priv *bat_priv) |
|---|
| 134 | 179 | { |
|---|
| 135 | | - struct batadv_priv *bat_priv = netdev_priv(soft_iface); |
|---|
| 180 | + struct batadv_softif_vlan *vlan; |
|---|
| 181 | + u8 ap_isolation; |
|---|
| 182 | + |
|---|
| 183 | + vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS); |
|---|
| 184 | + if (!vlan) |
|---|
| 185 | + return 0; |
|---|
| 186 | + |
|---|
| 187 | + ap_isolation = atomic_read(&vlan->ap_isolation); |
|---|
| 188 | + batadv_softif_vlan_put(vlan); |
|---|
| 189 | + |
|---|
| 190 | + return nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED, |
|---|
| 191 | + !!ap_isolation); |
|---|
| 192 | +} |
|---|
| 193 | + |
|---|
| 194 | +/** |
|---|
| 195 | + * batadv_option_set_ap_isolation() - Set ap_isolation from genl msg |
|---|
| 196 | + * @attr: parsed BATADV_ATTR_AP_ISOLATION_ENABLED attribute |
|---|
| 197 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 198 | + * |
|---|
| 199 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 200 | + */ |
|---|
| 201 | +static int batadv_netlink_set_mesh_ap_isolation(struct nlattr *attr, |
|---|
| 202 | + struct batadv_priv *bat_priv) |
|---|
| 203 | +{ |
|---|
| 204 | + struct batadv_softif_vlan *vlan; |
|---|
| 205 | + |
|---|
| 206 | + vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS); |
|---|
| 207 | + if (!vlan) |
|---|
| 208 | + return -ENOENT; |
|---|
| 209 | + |
|---|
| 210 | + atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr)); |
|---|
| 211 | + batadv_softif_vlan_put(vlan); |
|---|
| 212 | + |
|---|
| 213 | + return 0; |
|---|
| 214 | +} |
|---|
| 215 | + |
|---|
| 216 | +/** |
|---|
| 217 | + * batadv_netlink_mesh_fill() - Fill message with mesh attributes |
|---|
| 218 | + * @msg: Netlink message to dump into |
|---|
| 219 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 220 | + * @cmd: type of message to generate |
|---|
| 221 | + * @portid: Port making netlink request |
|---|
| 222 | + * @seq: sequence number for message |
|---|
| 223 | + * @flags: Additional flags for message |
|---|
| 224 | + * |
|---|
| 225 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 226 | + */ |
|---|
| 227 | +static int batadv_netlink_mesh_fill(struct sk_buff *msg, |
|---|
| 228 | + struct batadv_priv *bat_priv, |
|---|
| 229 | + enum batadv_nl_commands cmd, |
|---|
| 230 | + u32 portid, u32 seq, int flags) |
|---|
| 231 | +{ |
|---|
| 232 | + struct net_device *soft_iface = bat_priv->soft_iface; |
|---|
| 136 | 233 | struct batadv_hard_iface *primary_if = NULL; |
|---|
| 137 | 234 | struct net_device *hard_iface; |
|---|
| 138 | | - int ret = -ENOBUFS; |
|---|
| 235 | + void *hdr; |
|---|
| 236 | + |
|---|
| 237 | + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
|---|
| 238 | + if (!hdr) |
|---|
| 239 | + return -ENOBUFS; |
|---|
| 139 | 240 | |
|---|
| 140 | 241 | if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) || |
|---|
| 141 | 242 | nla_put_string(msg, BATADV_ATTR_ALGO_NAME, |
|---|
| .. | .. |
|---|
| 146 | 247 | soft_iface->dev_addr) || |
|---|
| 147 | 248 | nla_put_u8(msg, BATADV_ATTR_TT_TTVN, |
|---|
| 148 | 249 | (u8)atomic_read(&bat_priv->tt.vn))) |
|---|
| 149 | | - goto out; |
|---|
| 250 | + goto nla_put_failure; |
|---|
| 150 | 251 | |
|---|
| 151 | 252 | #ifdef CONFIG_BATMAN_ADV_BLA |
|---|
| 152 | 253 | if (nla_put_u16(msg, BATADV_ATTR_BLA_CRC, |
|---|
| 153 | 254 | ntohs(bat_priv->bla.claim_dest.group))) |
|---|
| 154 | | - goto out; |
|---|
| 255 | + goto nla_put_failure; |
|---|
| 155 | 256 | #endif |
|---|
| 156 | 257 | |
|---|
| 157 | 258 | if (batadv_mcast_mesh_info_put(msg, bat_priv)) |
|---|
| 158 | | - goto out; |
|---|
| 259 | + goto nla_put_failure; |
|---|
| 159 | 260 | |
|---|
| 160 | 261 | primary_if = batadv_primary_if_get_selected(bat_priv); |
|---|
| 161 | 262 | if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) { |
|---|
| .. | .. |
|---|
| 167 | 268 | hard_iface->name) || |
|---|
| 168 | 269 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, |
|---|
| 169 | 270 | hard_iface->dev_addr)) |
|---|
| 170 | | - goto out; |
|---|
| 271 | + goto nla_put_failure; |
|---|
| 171 | 272 | } |
|---|
| 172 | 273 | |
|---|
| 173 | | - ret = 0; |
|---|
| 274 | + if (nla_put_u8(msg, BATADV_ATTR_AGGREGATED_OGMS_ENABLED, |
|---|
| 275 | + !!atomic_read(&bat_priv->aggregated_ogms))) |
|---|
| 276 | + goto nla_put_failure; |
|---|
| 174 | 277 | |
|---|
| 175 | | - out: |
|---|
| 278 | + if (batadv_netlink_mesh_fill_ap_isolation(msg, bat_priv)) |
|---|
| 279 | + goto nla_put_failure; |
|---|
| 280 | + |
|---|
| 281 | + if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MARK, |
|---|
| 282 | + bat_priv->isolation_mark)) |
|---|
| 283 | + goto nla_put_failure; |
|---|
| 284 | + |
|---|
| 285 | + if (nla_put_u32(msg, BATADV_ATTR_ISOLATION_MASK, |
|---|
| 286 | + bat_priv->isolation_mark_mask)) |
|---|
| 287 | + goto nla_put_failure; |
|---|
| 288 | + |
|---|
| 289 | + if (nla_put_u8(msg, BATADV_ATTR_BONDING_ENABLED, |
|---|
| 290 | + !!atomic_read(&bat_priv->bonding))) |
|---|
| 291 | + goto nla_put_failure; |
|---|
| 292 | + |
|---|
| 293 | +#ifdef CONFIG_BATMAN_ADV_BLA |
|---|
| 294 | + if (nla_put_u8(msg, BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED, |
|---|
| 295 | + !!atomic_read(&bat_priv->bridge_loop_avoidance))) |
|---|
| 296 | + goto nla_put_failure; |
|---|
| 297 | +#endif /* CONFIG_BATMAN_ADV_BLA */ |
|---|
| 298 | + |
|---|
| 299 | +#ifdef CONFIG_BATMAN_ADV_DAT |
|---|
| 300 | + if (nla_put_u8(msg, BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED, |
|---|
| 301 | + !!atomic_read(&bat_priv->distributed_arp_table))) |
|---|
| 302 | + goto nla_put_failure; |
|---|
| 303 | +#endif /* CONFIG_BATMAN_ADV_DAT */ |
|---|
| 304 | + |
|---|
| 305 | + if (nla_put_u8(msg, BATADV_ATTR_FRAGMENTATION_ENABLED, |
|---|
| 306 | + !!atomic_read(&bat_priv->fragmentation))) |
|---|
| 307 | + goto nla_put_failure; |
|---|
| 308 | + |
|---|
| 309 | + if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_DOWN, |
|---|
| 310 | + atomic_read(&bat_priv->gw.bandwidth_down))) |
|---|
| 311 | + goto nla_put_failure; |
|---|
| 312 | + |
|---|
| 313 | + if (nla_put_u32(msg, BATADV_ATTR_GW_BANDWIDTH_UP, |
|---|
| 314 | + atomic_read(&bat_priv->gw.bandwidth_up))) |
|---|
| 315 | + goto nla_put_failure; |
|---|
| 316 | + |
|---|
| 317 | + if (nla_put_u8(msg, BATADV_ATTR_GW_MODE, |
|---|
| 318 | + atomic_read(&bat_priv->gw.mode))) |
|---|
| 319 | + goto nla_put_failure; |
|---|
| 320 | + |
|---|
| 321 | + if (bat_priv->algo_ops->gw.get_best_gw_node && |
|---|
| 322 | + bat_priv->algo_ops->gw.is_eligible) { |
|---|
| 323 | + /* GW selection class is not available if the routing algorithm |
|---|
| 324 | + * in use does not implement the GW API |
|---|
| 325 | + */ |
|---|
| 326 | + if (nla_put_u32(msg, BATADV_ATTR_GW_SEL_CLASS, |
|---|
| 327 | + atomic_read(&bat_priv->gw.sel_class))) |
|---|
| 328 | + goto nla_put_failure; |
|---|
| 329 | + } |
|---|
| 330 | + |
|---|
| 331 | + if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY, |
|---|
| 332 | + atomic_read(&bat_priv->hop_penalty))) |
|---|
| 333 | + goto nla_put_failure; |
|---|
| 334 | + |
|---|
| 335 | +#ifdef CONFIG_BATMAN_ADV_DEBUG |
|---|
| 336 | + if (nla_put_u32(msg, BATADV_ATTR_LOG_LEVEL, |
|---|
| 337 | + atomic_read(&bat_priv->log_level))) |
|---|
| 338 | + goto nla_put_failure; |
|---|
| 339 | +#endif /* CONFIG_BATMAN_ADV_DEBUG */ |
|---|
| 340 | + |
|---|
| 341 | +#ifdef CONFIG_BATMAN_ADV_MCAST |
|---|
| 342 | + if (nla_put_u8(msg, BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED, |
|---|
| 343 | + !atomic_read(&bat_priv->multicast_mode))) |
|---|
| 344 | + goto nla_put_failure; |
|---|
| 345 | + |
|---|
| 346 | + if (nla_put_u32(msg, BATADV_ATTR_MULTICAST_FANOUT, |
|---|
| 347 | + atomic_read(&bat_priv->multicast_fanout))) |
|---|
| 348 | + goto nla_put_failure; |
|---|
| 349 | +#endif /* CONFIG_BATMAN_ADV_MCAST */ |
|---|
| 350 | + |
|---|
| 351 | +#ifdef CONFIG_BATMAN_ADV_NC |
|---|
| 352 | + if (nla_put_u8(msg, BATADV_ATTR_NETWORK_CODING_ENABLED, |
|---|
| 353 | + !!atomic_read(&bat_priv->network_coding))) |
|---|
| 354 | + goto nla_put_failure; |
|---|
| 355 | +#endif /* CONFIG_BATMAN_ADV_NC */ |
|---|
| 356 | + |
|---|
| 357 | + if (nla_put_u32(msg, BATADV_ATTR_ORIG_INTERVAL, |
|---|
| 358 | + atomic_read(&bat_priv->orig_interval))) |
|---|
| 359 | + goto nla_put_failure; |
|---|
| 360 | + |
|---|
| 176 | 361 | if (primary_if) |
|---|
| 177 | 362 | batadv_hardif_put(primary_if); |
|---|
| 363 | + |
|---|
| 364 | + genlmsg_end(msg, hdr); |
|---|
| 365 | + return 0; |
|---|
| 366 | + |
|---|
| 367 | +nla_put_failure: |
|---|
| 368 | + if (primary_if) |
|---|
| 369 | + batadv_hardif_put(primary_if); |
|---|
| 370 | + |
|---|
| 371 | + genlmsg_cancel(msg, hdr); |
|---|
| 372 | + return -EMSGSIZE; |
|---|
| 373 | +} |
|---|
| 374 | + |
|---|
| 375 | +/** |
|---|
| 376 | + * batadv_netlink_notify_mesh() - send softif attributes to listener |
|---|
| 377 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 378 | + * |
|---|
| 379 | + * Return: 0 on success, < 0 on error |
|---|
| 380 | + */ |
|---|
| 381 | +int batadv_netlink_notify_mesh(struct batadv_priv *bat_priv) |
|---|
| 382 | +{ |
|---|
| 383 | + struct sk_buff *msg; |
|---|
| 384 | + int ret; |
|---|
| 385 | + |
|---|
| 386 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 387 | + if (!msg) |
|---|
| 388 | + return -ENOMEM; |
|---|
| 389 | + |
|---|
| 390 | + ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_SET_MESH, |
|---|
| 391 | + 0, 0, 0); |
|---|
| 392 | + if (ret < 0) { |
|---|
| 393 | + nlmsg_free(msg); |
|---|
| 394 | + return ret; |
|---|
| 395 | + } |
|---|
| 396 | + |
|---|
| 397 | + genlmsg_multicast_netns(&batadv_netlink_family, |
|---|
| 398 | + dev_net(bat_priv->soft_iface), msg, 0, |
|---|
| 399 | + BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
|---|
| 400 | + |
|---|
| 401 | + return 0; |
|---|
| 402 | +} |
|---|
| 403 | + |
|---|
| 404 | +/** |
|---|
| 405 | + * batadv_netlink_get_mesh() - Get softif attributes |
|---|
| 406 | + * @skb: Netlink message with request data |
|---|
| 407 | + * @info: receiver information |
|---|
| 408 | + * |
|---|
| 409 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 410 | + */ |
|---|
| 411 | +static int batadv_netlink_get_mesh(struct sk_buff *skb, struct genl_info *info) |
|---|
| 412 | +{ |
|---|
| 413 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 414 | + struct sk_buff *msg; |
|---|
| 415 | + int ret; |
|---|
| 416 | + |
|---|
| 417 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 418 | + if (!msg) |
|---|
| 419 | + return -ENOMEM; |
|---|
| 420 | + |
|---|
| 421 | + ret = batadv_netlink_mesh_fill(msg, bat_priv, BATADV_CMD_GET_MESH, |
|---|
| 422 | + info->snd_portid, info->snd_seq, 0); |
|---|
| 423 | + if (ret < 0) { |
|---|
| 424 | + nlmsg_free(msg); |
|---|
| 425 | + return ret; |
|---|
| 426 | + } |
|---|
| 427 | + |
|---|
| 428 | + ret = genlmsg_reply(msg, info); |
|---|
| 178 | 429 | |
|---|
| 179 | 430 | return ret; |
|---|
| 180 | 431 | } |
|---|
| 181 | 432 | |
|---|
| 182 | 433 | /** |
|---|
| 183 | | - * batadv_netlink_get_mesh_info() - handle incoming BATADV_CMD_GET_MESH_INFO |
|---|
| 184 | | - * netlink request |
|---|
| 185 | | - * @skb: received netlink message |
|---|
| 434 | + * batadv_netlink_set_mesh() - Set softif attributes |
|---|
| 435 | + * @skb: Netlink message with request data |
|---|
| 186 | 436 | * @info: receiver information |
|---|
| 187 | 437 | * |
|---|
| 188 | | - * Return: 0 on success, < 0 on error |
|---|
| 438 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 189 | 439 | */ |
|---|
| 190 | | -static int |
|---|
| 191 | | -batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) |
|---|
| 440 | +static int batadv_netlink_set_mesh(struct sk_buff *skb, struct genl_info *info) |
|---|
| 192 | 441 | { |
|---|
| 193 | | - struct net *net = genl_info_net(info); |
|---|
| 194 | | - struct net_device *soft_iface; |
|---|
| 195 | | - struct sk_buff *msg = NULL; |
|---|
| 196 | | - void *msg_head; |
|---|
| 197 | | - int ifindex; |
|---|
| 198 | | - int ret; |
|---|
| 442 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 443 | + struct nlattr *attr; |
|---|
| 199 | 444 | |
|---|
| 200 | | - if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) |
|---|
| 201 | | - return -EINVAL; |
|---|
| 445 | + if (info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]) { |
|---|
| 446 | + attr = info->attrs[BATADV_ATTR_AGGREGATED_OGMS_ENABLED]; |
|---|
| 202 | 447 | |
|---|
| 203 | | - ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); |
|---|
| 204 | | - if (!ifindex) |
|---|
| 205 | | - return -EINVAL; |
|---|
| 206 | | - |
|---|
| 207 | | - soft_iface = dev_get_by_index(net, ifindex); |
|---|
| 208 | | - if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { |
|---|
| 209 | | - ret = -ENODEV; |
|---|
| 210 | | - goto out; |
|---|
| 448 | + atomic_set(&bat_priv->aggregated_ogms, !!nla_get_u8(attr)); |
|---|
| 211 | 449 | } |
|---|
| 212 | 450 | |
|---|
| 213 | | - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 214 | | - if (!msg) { |
|---|
| 215 | | - ret = -ENOMEM; |
|---|
| 216 | | - goto out; |
|---|
| 451 | + if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) { |
|---|
| 452 | + attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]; |
|---|
| 453 | + |
|---|
| 454 | + batadv_netlink_set_mesh_ap_isolation(attr, bat_priv); |
|---|
| 217 | 455 | } |
|---|
| 218 | 456 | |
|---|
| 219 | | - msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, |
|---|
| 220 | | - &batadv_netlink_family, 0, |
|---|
| 221 | | - BATADV_CMD_GET_MESH_INFO); |
|---|
| 222 | | - if (!msg_head) { |
|---|
| 223 | | - ret = -ENOBUFS; |
|---|
| 224 | | - goto out; |
|---|
| 457 | + if (info->attrs[BATADV_ATTR_ISOLATION_MARK]) { |
|---|
| 458 | + attr = info->attrs[BATADV_ATTR_ISOLATION_MARK]; |
|---|
| 459 | + |
|---|
| 460 | + bat_priv->isolation_mark = nla_get_u32(attr); |
|---|
| 225 | 461 | } |
|---|
| 226 | 462 | |
|---|
| 227 | | - ret = batadv_netlink_mesh_info_put(msg, soft_iface); |
|---|
| 463 | + if (info->attrs[BATADV_ATTR_ISOLATION_MASK]) { |
|---|
| 464 | + attr = info->attrs[BATADV_ATTR_ISOLATION_MASK]; |
|---|
| 228 | 465 | |
|---|
| 229 | | - out: |
|---|
| 230 | | - if (soft_iface) |
|---|
| 231 | | - dev_put(soft_iface); |
|---|
| 232 | | - |
|---|
| 233 | | - if (ret) { |
|---|
| 234 | | - if (msg) |
|---|
| 235 | | - nlmsg_free(msg); |
|---|
| 236 | | - return ret; |
|---|
| 466 | + bat_priv->isolation_mark_mask = nla_get_u32(attr); |
|---|
| 237 | 467 | } |
|---|
| 238 | 468 | |
|---|
| 239 | | - genlmsg_end(msg, msg_head); |
|---|
| 240 | | - return genlmsg_reply(msg, info); |
|---|
| 469 | + if (info->attrs[BATADV_ATTR_BONDING_ENABLED]) { |
|---|
| 470 | + attr = info->attrs[BATADV_ATTR_BONDING_ENABLED]; |
|---|
| 471 | + |
|---|
| 472 | + atomic_set(&bat_priv->bonding, !!nla_get_u8(attr)); |
|---|
| 473 | + } |
|---|
| 474 | + |
|---|
| 475 | +#ifdef CONFIG_BATMAN_ADV_BLA |
|---|
| 476 | + if (info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]) { |
|---|
| 477 | + attr = info->attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED]; |
|---|
| 478 | + |
|---|
| 479 | + atomic_set(&bat_priv->bridge_loop_avoidance, |
|---|
| 480 | + !!nla_get_u8(attr)); |
|---|
| 481 | + batadv_bla_status_update(bat_priv->soft_iface); |
|---|
| 482 | + } |
|---|
| 483 | +#endif /* CONFIG_BATMAN_ADV_BLA */ |
|---|
| 484 | + |
|---|
| 485 | +#ifdef CONFIG_BATMAN_ADV_DAT |
|---|
| 486 | + if (info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]) { |
|---|
| 487 | + attr = info->attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED]; |
|---|
| 488 | + |
|---|
| 489 | + atomic_set(&bat_priv->distributed_arp_table, |
|---|
| 490 | + !!nla_get_u8(attr)); |
|---|
| 491 | + batadv_dat_status_update(bat_priv->soft_iface); |
|---|
| 492 | + } |
|---|
| 493 | +#endif /* CONFIG_BATMAN_ADV_DAT */ |
|---|
| 494 | + |
|---|
| 495 | + if (info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED]) { |
|---|
| 496 | + attr = info->attrs[BATADV_ATTR_FRAGMENTATION_ENABLED]; |
|---|
| 497 | + |
|---|
| 498 | + atomic_set(&bat_priv->fragmentation, !!nla_get_u8(attr)); |
|---|
| 499 | + batadv_update_min_mtu(bat_priv->soft_iface); |
|---|
| 500 | + } |
|---|
| 501 | + |
|---|
| 502 | + if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]) { |
|---|
| 503 | + attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]; |
|---|
| 504 | + |
|---|
| 505 | + atomic_set(&bat_priv->gw.bandwidth_down, nla_get_u32(attr)); |
|---|
| 506 | + batadv_gw_tvlv_container_update(bat_priv); |
|---|
| 507 | + } |
|---|
| 508 | + |
|---|
| 509 | + if (info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]) { |
|---|
| 510 | + attr = info->attrs[BATADV_ATTR_GW_BANDWIDTH_UP]; |
|---|
| 511 | + |
|---|
| 512 | + atomic_set(&bat_priv->gw.bandwidth_up, nla_get_u32(attr)); |
|---|
| 513 | + batadv_gw_tvlv_container_update(bat_priv); |
|---|
| 514 | + } |
|---|
| 515 | + |
|---|
| 516 | + if (info->attrs[BATADV_ATTR_GW_MODE]) { |
|---|
| 517 | + u8 gw_mode; |
|---|
| 518 | + |
|---|
| 519 | + attr = info->attrs[BATADV_ATTR_GW_MODE]; |
|---|
| 520 | + gw_mode = nla_get_u8(attr); |
|---|
| 521 | + |
|---|
| 522 | + if (gw_mode <= BATADV_GW_MODE_SERVER) { |
|---|
| 523 | + /* Invoking batadv_gw_reselect() is not enough to really |
|---|
| 524 | + * de-select the current GW. It will only instruct the |
|---|
| 525 | + * gateway client code to perform a re-election the next |
|---|
| 526 | + * time that this is needed. |
|---|
| 527 | + * |
|---|
| 528 | + * When gw client mode is being switched off the current |
|---|
| 529 | + * GW must be de-selected explicitly otherwise no GW_ADD |
|---|
| 530 | + * uevent is thrown on client mode re-activation. This |
|---|
| 531 | + * is operation is performed in |
|---|
| 532 | + * batadv_gw_check_client_stop(). |
|---|
| 533 | + */ |
|---|
| 534 | + batadv_gw_reselect(bat_priv); |
|---|
| 535 | + |
|---|
| 536 | + /* always call batadv_gw_check_client_stop() before |
|---|
| 537 | + * changing the gateway state |
|---|
| 538 | + */ |
|---|
| 539 | + batadv_gw_check_client_stop(bat_priv); |
|---|
| 540 | + atomic_set(&bat_priv->gw.mode, gw_mode); |
|---|
| 541 | + batadv_gw_tvlv_container_update(bat_priv); |
|---|
| 542 | + } |
|---|
| 543 | + } |
|---|
| 544 | + |
|---|
| 545 | + if (info->attrs[BATADV_ATTR_GW_SEL_CLASS] && |
|---|
| 546 | + bat_priv->algo_ops->gw.get_best_gw_node && |
|---|
| 547 | + bat_priv->algo_ops->gw.is_eligible) { |
|---|
| 548 | + /* setting the GW selection class is allowed only if the routing |
|---|
| 549 | + * algorithm in use implements the GW API |
|---|
| 550 | + */ |
|---|
| 551 | + |
|---|
| 552 | + u32 sel_class_max = 0xffffffffu; |
|---|
| 553 | + u32 sel_class; |
|---|
| 554 | + |
|---|
| 555 | + attr = info->attrs[BATADV_ATTR_GW_SEL_CLASS]; |
|---|
| 556 | + sel_class = nla_get_u32(attr); |
|---|
| 557 | + |
|---|
| 558 | + if (!bat_priv->algo_ops->gw.store_sel_class) |
|---|
| 559 | + sel_class_max = BATADV_TQ_MAX_VALUE; |
|---|
| 560 | + |
|---|
| 561 | + if (sel_class >= 1 && sel_class <= sel_class_max) { |
|---|
| 562 | + atomic_set(&bat_priv->gw.sel_class, sel_class); |
|---|
| 563 | + batadv_gw_reselect(bat_priv); |
|---|
| 564 | + } |
|---|
| 565 | + } |
|---|
| 566 | + |
|---|
| 567 | + if (info->attrs[BATADV_ATTR_HOP_PENALTY]) { |
|---|
| 568 | + attr = info->attrs[BATADV_ATTR_HOP_PENALTY]; |
|---|
| 569 | + |
|---|
| 570 | + atomic_set(&bat_priv->hop_penalty, nla_get_u8(attr)); |
|---|
| 571 | + } |
|---|
| 572 | + |
|---|
| 573 | +#ifdef CONFIG_BATMAN_ADV_DEBUG |
|---|
| 574 | + if (info->attrs[BATADV_ATTR_LOG_LEVEL]) { |
|---|
| 575 | + attr = info->attrs[BATADV_ATTR_LOG_LEVEL]; |
|---|
| 576 | + |
|---|
| 577 | + atomic_set(&bat_priv->log_level, |
|---|
| 578 | + nla_get_u32(attr) & BATADV_DBG_ALL); |
|---|
| 579 | + } |
|---|
| 580 | +#endif /* CONFIG_BATMAN_ADV_DEBUG */ |
|---|
| 581 | + |
|---|
| 582 | +#ifdef CONFIG_BATMAN_ADV_MCAST |
|---|
| 583 | + if (info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]) { |
|---|
| 584 | + attr = info->attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED]; |
|---|
| 585 | + |
|---|
| 586 | + atomic_set(&bat_priv->multicast_mode, !nla_get_u8(attr)); |
|---|
| 587 | + } |
|---|
| 588 | + |
|---|
| 589 | + if (info->attrs[BATADV_ATTR_MULTICAST_FANOUT]) { |
|---|
| 590 | + attr = info->attrs[BATADV_ATTR_MULTICAST_FANOUT]; |
|---|
| 591 | + |
|---|
| 592 | + atomic_set(&bat_priv->multicast_fanout, nla_get_u32(attr)); |
|---|
| 593 | + } |
|---|
| 594 | +#endif /* CONFIG_BATMAN_ADV_MCAST */ |
|---|
| 595 | + |
|---|
| 596 | +#ifdef CONFIG_BATMAN_ADV_NC |
|---|
| 597 | + if (info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED]) { |
|---|
| 598 | + attr = info->attrs[BATADV_ATTR_NETWORK_CODING_ENABLED]; |
|---|
| 599 | + |
|---|
| 600 | + atomic_set(&bat_priv->network_coding, !!nla_get_u8(attr)); |
|---|
| 601 | + batadv_nc_status_update(bat_priv->soft_iface); |
|---|
| 602 | + } |
|---|
| 603 | +#endif /* CONFIG_BATMAN_ADV_NC */ |
|---|
| 604 | + |
|---|
| 605 | + if (info->attrs[BATADV_ATTR_ORIG_INTERVAL]) { |
|---|
| 606 | + u32 orig_interval; |
|---|
| 607 | + |
|---|
| 608 | + attr = info->attrs[BATADV_ATTR_ORIG_INTERVAL]; |
|---|
| 609 | + orig_interval = nla_get_u32(attr); |
|---|
| 610 | + |
|---|
| 611 | + orig_interval = min_t(u32, orig_interval, INT_MAX); |
|---|
| 612 | + orig_interval = max_t(u32, orig_interval, 2 * BATADV_JITTER); |
|---|
| 613 | + |
|---|
| 614 | + atomic_set(&bat_priv->orig_interval, orig_interval); |
|---|
| 615 | + } |
|---|
| 616 | + |
|---|
| 617 | + batadv_netlink_notify_mesh(bat_priv); |
|---|
| 618 | + |
|---|
| 619 | + return 0; |
|---|
| 241 | 620 | } |
|---|
| 242 | 621 | |
|---|
| 243 | 622 | /** |
|---|
| .. | .. |
|---|
| 261 | 640 | * @bat_priv: the bat priv with all the soft interface information |
|---|
| 262 | 641 | * @dst: destination of tp_meter session |
|---|
| 263 | 642 | * @result: reason for tp meter session stop |
|---|
| 264 | | - * @test_time: total time ot the tp_meter session |
|---|
| 643 | + * @test_time: total time of the tp_meter session |
|---|
| 265 | 644 | * @total_bytes: bytes acked to the receiver |
|---|
| 266 | 645 | * @cookie: cookie of tp_meter session |
|---|
| 267 | 646 | * |
|---|
| .. | .. |
|---|
| 329 | 708 | static int |
|---|
| 330 | 709 | batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info) |
|---|
| 331 | 710 | { |
|---|
| 332 | | - struct net *net = genl_info_net(info); |
|---|
| 333 | | - struct net_device *soft_iface; |
|---|
| 334 | | - struct batadv_priv *bat_priv; |
|---|
| 711 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 335 | 712 | struct sk_buff *msg = NULL; |
|---|
| 336 | 713 | u32 test_length; |
|---|
| 337 | 714 | void *msg_head; |
|---|
| 338 | | - int ifindex; |
|---|
| 339 | 715 | u32 cookie; |
|---|
| 340 | 716 | u8 *dst; |
|---|
| 341 | 717 | int ret; |
|---|
| 342 | | - |
|---|
| 343 | | - if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) |
|---|
| 344 | | - return -EINVAL; |
|---|
| 345 | 718 | |
|---|
| 346 | 719 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) |
|---|
| 347 | 720 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 349 | 722 | if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]) |
|---|
| 350 | 723 | return -EINVAL; |
|---|
| 351 | 724 | |
|---|
| 352 | | - ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); |
|---|
| 353 | | - if (!ifindex) |
|---|
| 354 | | - return -EINVAL; |
|---|
| 355 | | - |
|---|
| 356 | 725 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); |
|---|
| 357 | 726 | |
|---|
| 358 | 727 | test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]); |
|---|
| 359 | | - |
|---|
| 360 | | - soft_iface = dev_get_by_index(net, ifindex); |
|---|
| 361 | | - if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { |
|---|
| 362 | | - ret = -ENODEV; |
|---|
| 363 | | - goto out; |
|---|
| 364 | | - } |
|---|
| 365 | 728 | |
|---|
| 366 | 729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 367 | 730 | if (!msg) { |
|---|
| .. | .. |
|---|
| 377 | 740 | goto out; |
|---|
| 378 | 741 | } |
|---|
| 379 | 742 | |
|---|
| 380 | | - bat_priv = netdev_priv(soft_iface); |
|---|
| 381 | 743 | batadv_tp_start(bat_priv, dst, test_length, &cookie); |
|---|
| 382 | 744 | |
|---|
| 383 | 745 | ret = batadv_netlink_tp_meter_put(msg, cookie); |
|---|
| 384 | 746 | |
|---|
| 385 | 747 | out: |
|---|
| 386 | | - if (soft_iface) |
|---|
| 387 | | - dev_put(soft_iface); |
|---|
| 388 | | - |
|---|
| 389 | 748 | if (ret) { |
|---|
| 390 | 749 | if (msg) |
|---|
| 391 | 750 | nlmsg_free(msg); |
|---|
| .. | .. |
|---|
| 406 | 765 | static int |
|---|
| 407 | 766 | batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info) |
|---|
| 408 | 767 | { |
|---|
| 409 | | - struct net *net = genl_info_net(info); |
|---|
| 410 | | - struct net_device *soft_iface; |
|---|
| 411 | | - struct batadv_priv *bat_priv; |
|---|
| 412 | | - int ifindex; |
|---|
| 768 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 413 | 769 | u8 *dst; |
|---|
| 414 | 770 | int ret = 0; |
|---|
| 415 | | - |
|---|
| 416 | | - if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) |
|---|
| 417 | | - return -EINVAL; |
|---|
| 418 | 771 | |
|---|
| 419 | 772 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) |
|---|
| 420 | 773 | return -EINVAL; |
|---|
| 421 | 774 | |
|---|
| 422 | | - ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); |
|---|
| 423 | | - if (!ifindex) |
|---|
| 424 | | - return -EINVAL; |
|---|
| 425 | | - |
|---|
| 426 | 775 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); |
|---|
| 427 | 776 | |
|---|
| 428 | | - soft_iface = dev_get_by_index(net, ifindex); |
|---|
| 429 | | - if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { |
|---|
| 430 | | - ret = -ENODEV; |
|---|
| 431 | | - goto out; |
|---|
| 432 | | - } |
|---|
| 433 | | - |
|---|
| 434 | | - bat_priv = netdev_priv(soft_iface); |
|---|
| 435 | 777 | batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL); |
|---|
| 436 | | - |
|---|
| 437 | | -out: |
|---|
| 438 | | - if (soft_iface) |
|---|
| 439 | | - dev_put(soft_iface); |
|---|
| 440 | 778 | |
|---|
| 441 | 779 | return ret; |
|---|
| 442 | 780 | } |
|---|
| 443 | 781 | |
|---|
| 444 | 782 | /** |
|---|
| 445 | | - * batadv_netlink_dump_hardif_entry() - Dump one hard interface into a message |
|---|
| 783 | + * batadv_netlink_hardif_fill() - Fill message with hardif attributes |
|---|
| 446 | 784 | * @msg: Netlink message to dump into |
|---|
| 785 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 786 | + * @hard_iface: hard interface which was modified |
|---|
| 787 | + * @cmd: type of message to generate |
|---|
| 447 | 788 | * @portid: Port making netlink request |
|---|
| 448 | | - * @seq: Sequence number of netlink message |
|---|
| 449 | | - * @hard_iface: Hard interface to dump |
|---|
| 789 | + * @seq: sequence number for message |
|---|
| 790 | + * @flags: Additional flags for message |
|---|
| 791 | + * @cb: Control block containing additional options |
|---|
| 450 | 792 | * |
|---|
| 451 | | - * Return: error code, or 0 on success |
|---|
| 793 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 452 | 794 | */ |
|---|
| 453 | | -static int |
|---|
| 454 | | -batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq, |
|---|
| 455 | | - struct batadv_hard_iface *hard_iface) |
|---|
| 795 | +static int batadv_netlink_hardif_fill(struct sk_buff *msg, |
|---|
| 796 | + struct batadv_priv *bat_priv, |
|---|
| 797 | + struct batadv_hard_iface *hard_iface, |
|---|
| 798 | + enum batadv_nl_commands cmd, |
|---|
| 799 | + u32 portid, u32 seq, int flags, |
|---|
| 800 | + struct netlink_callback *cb) |
|---|
| 456 | 801 | { |
|---|
| 457 | 802 | struct net_device *net_dev = hard_iface->net_dev; |
|---|
| 458 | 803 | void *hdr; |
|---|
| 459 | 804 | |
|---|
| 460 | | - hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, |
|---|
| 461 | | - BATADV_CMD_GET_HARDIFS); |
|---|
| 805 | + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
|---|
| 462 | 806 | if (!hdr) |
|---|
| 463 | | - return -EMSGSIZE; |
|---|
| 807 | + return -ENOBUFS; |
|---|
| 808 | + |
|---|
| 809 | + if (cb) |
|---|
| 810 | + genl_dump_check_consistent(cb, hdr); |
|---|
| 811 | + |
|---|
| 812 | + if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, |
|---|
| 813 | + bat_priv->soft_iface->ifindex)) |
|---|
| 814 | + goto nla_put_failure; |
|---|
| 464 | 815 | |
|---|
| 465 | 816 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, |
|---|
| 466 | 817 | net_dev->ifindex) || |
|---|
| .. | .. |
|---|
| 475 | 826 | goto nla_put_failure; |
|---|
| 476 | 827 | } |
|---|
| 477 | 828 | |
|---|
| 829 | + if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY, |
|---|
| 830 | + atomic_read(&hard_iface->hop_penalty))) |
|---|
| 831 | + goto nla_put_failure; |
|---|
| 832 | + |
|---|
| 833 | +#ifdef CONFIG_BATMAN_ADV_BATMAN_V |
|---|
| 834 | + if (nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL, |
|---|
| 835 | + atomic_read(&hard_iface->bat_v.elp_interval))) |
|---|
| 836 | + goto nla_put_failure; |
|---|
| 837 | + |
|---|
| 838 | + if (nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE, |
|---|
| 839 | + atomic_read(&hard_iface->bat_v.throughput_override))) |
|---|
| 840 | + goto nla_put_failure; |
|---|
| 841 | +#endif /* CONFIG_BATMAN_ADV_BATMAN_V */ |
|---|
| 842 | + |
|---|
| 478 | 843 | genlmsg_end(msg, hdr); |
|---|
| 479 | 844 | return 0; |
|---|
| 480 | 845 | |
|---|
| 481 | | - nla_put_failure: |
|---|
| 846 | +nla_put_failure: |
|---|
| 482 | 847 | genlmsg_cancel(msg, hdr); |
|---|
| 483 | 848 | return -EMSGSIZE; |
|---|
| 484 | 849 | } |
|---|
| 485 | 850 | |
|---|
| 486 | 851 | /** |
|---|
| 487 | | - * batadv_netlink_dump_hardifs() - Dump all hard interface into a messages |
|---|
| 852 | + * batadv_netlink_notify_hardif() - send hardif attributes to listener |
|---|
| 853 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 854 | + * @hard_iface: hard interface which was modified |
|---|
| 855 | + * |
|---|
| 856 | + * Return: 0 on success, < 0 on error |
|---|
| 857 | + */ |
|---|
| 858 | +int batadv_netlink_notify_hardif(struct batadv_priv *bat_priv, |
|---|
| 859 | + struct batadv_hard_iface *hard_iface) |
|---|
| 860 | +{ |
|---|
| 861 | + struct sk_buff *msg; |
|---|
| 862 | + int ret; |
|---|
| 863 | + |
|---|
| 864 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 865 | + if (!msg) |
|---|
| 866 | + return -ENOMEM; |
|---|
| 867 | + |
|---|
| 868 | + ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
|---|
| 869 | + BATADV_CMD_SET_HARDIF, 0, 0, 0, NULL); |
|---|
| 870 | + if (ret < 0) { |
|---|
| 871 | + nlmsg_free(msg); |
|---|
| 872 | + return ret; |
|---|
| 873 | + } |
|---|
| 874 | + |
|---|
| 875 | + genlmsg_multicast_netns(&batadv_netlink_family, |
|---|
| 876 | + dev_net(bat_priv->soft_iface), msg, 0, |
|---|
| 877 | + BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
|---|
| 878 | + |
|---|
| 879 | + return 0; |
|---|
| 880 | +} |
|---|
| 881 | + |
|---|
| 882 | +/** |
|---|
| 883 | + * batadv_netlink_get_hardif() - Get hardif attributes |
|---|
| 884 | + * @skb: Netlink message with request data |
|---|
| 885 | + * @info: receiver information |
|---|
| 886 | + * |
|---|
| 887 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 888 | + */ |
|---|
| 889 | +static int batadv_netlink_get_hardif(struct sk_buff *skb, |
|---|
| 890 | + struct genl_info *info) |
|---|
| 891 | +{ |
|---|
| 892 | + struct batadv_hard_iface *hard_iface = info->user_ptr[1]; |
|---|
| 893 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 894 | + struct sk_buff *msg; |
|---|
| 895 | + int ret; |
|---|
| 896 | + |
|---|
| 897 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 898 | + if (!msg) |
|---|
| 899 | + return -ENOMEM; |
|---|
| 900 | + |
|---|
| 901 | + ret = batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
|---|
| 902 | + BATADV_CMD_GET_HARDIF, |
|---|
| 903 | + info->snd_portid, info->snd_seq, 0, |
|---|
| 904 | + NULL); |
|---|
| 905 | + if (ret < 0) { |
|---|
| 906 | + nlmsg_free(msg); |
|---|
| 907 | + return ret; |
|---|
| 908 | + } |
|---|
| 909 | + |
|---|
| 910 | + ret = genlmsg_reply(msg, info); |
|---|
| 911 | + |
|---|
| 912 | + return ret; |
|---|
| 913 | +} |
|---|
| 914 | + |
|---|
| 915 | +/** |
|---|
| 916 | + * batadv_netlink_set_hardif() - Set hardif attributes |
|---|
| 917 | + * @skb: Netlink message with request data |
|---|
| 918 | + * @info: receiver information |
|---|
| 919 | + * |
|---|
| 920 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 921 | + */ |
|---|
| 922 | +static int batadv_netlink_set_hardif(struct sk_buff *skb, |
|---|
| 923 | + struct genl_info *info) |
|---|
| 924 | +{ |
|---|
| 925 | + struct batadv_hard_iface *hard_iface = info->user_ptr[1]; |
|---|
| 926 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 927 | + struct nlattr *attr; |
|---|
| 928 | + |
|---|
| 929 | + if (info->attrs[BATADV_ATTR_HOP_PENALTY]) { |
|---|
| 930 | + attr = info->attrs[BATADV_ATTR_HOP_PENALTY]; |
|---|
| 931 | + |
|---|
| 932 | + atomic_set(&hard_iface->hop_penalty, nla_get_u8(attr)); |
|---|
| 933 | + } |
|---|
| 934 | + |
|---|
| 935 | +#ifdef CONFIG_BATMAN_ADV_BATMAN_V |
|---|
| 936 | + |
|---|
| 937 | + if (info->attrs[BATADV_ATTR_ELP_INTERVAL]) { |
|---|
| 938 | + attr = info->attrs[BATADV_ATTR_ELP_INTERVAL]; |
|---|
| 939 | + |
|---|
| 940 | + atomic_set(&hard_iface->bat_v.elp_interval, nla_get_u32(attr)); |
|---|
| 941 | + } |
|---|
| 942 | + |
|---|
| 943 | + if (info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) { |
|---|
| 944 | + attr = info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]; |
|---|
| 945 | + |
|---|
| 946 | + atomic_set(&hard_iface->bat_v.throughput_override, |
|---|
| 947 | + nla_get_u32(attr)); |
|---|
| 948 | + } |
|---|
| 949 | +#endif /* CONFIG_BATMAN_ADV_BATMAN_V */ |
|---|
| 950 | + |
|---|
| 951 | + batadv_netlink_notify_hardif(bat_priv, hard_iface); |
|---|
| 952 | + |
|---|
| 953 | + return 0; |
|---|
| 954 | +} |
|---|
| 955 | + |
|---|
| 956 | +/** |
|---|
| 957 | + * batadv_netlink_dump_hardif() - Dump all hard interface into a messages |
|---|
| 488 | 958 | * @msg: Netlink message to dump into |
|---|
| 489 | 959 | * @cb: Parameters from query |
|---|
| 490 | 960 | * |
|---|
| 491 | 961 | * Return: error code, or length of reply message on success |
|---|
| 492 | 962 | */ |
|---|
| 493 | 963 | static int |
|---|
| 494 | | -batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb) |
|---|
| 964 | +batadv_netlink_dump_hardif(struct sk_buff *msg, struct netlink_callback *cb) |
|---|
| 495 | 965 | { |
|---|
| 496 | 966 | struct net *net = sock_net(cb->skb->sk); |
|---|
| 497 | 967 | struct net_device *soft_iface; |
|---|
| 498 | 968 | struct batadv_hard_iface *hard_iface; |
|---|
| 969 | + struct batadv_priv *bat_priv; |
|---|
| 499 | 970 | int ifindex; |
|---|
| 500 | 971 | int portid = NETLINK_CB(cb->skb).portid; |
|---|
| 501 | | - int seq = cb->nlh->nlmsg_seq; |
|---|
| 502 | 972 | int skip = cb->args[0]; |
|---|
| 503 | 973 | int i = 0; |
|---|
| 504 | 974 | |
|---|
| .. | .. |
|---|
| 516 | 986 | return -ENODEV; |
|---|
| 517 | 987 | } |
|---|
| 518 | 988 | |
|---|
| 519 | | - rcu_read_lock(); |
|---|
| 989 | + bat_priv = netdev_priv(soft_iface); |
|---|
| 520 | 990 | |
|---|
| 521 | | - list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
|---|
| 991 | + rtnl_lock(); |
|---|
| 992 | + cb->seq = batadv_hardif_generation << 1 | 1; |
|---|
| 993 | + |
|---|
| 994 | + list_for_each_entry(hard_iface, &batadv_hardif_list, list) { |
|---|
| 522 | 995 | if (hard_iface->soft_iface != soft_iface) |
|---|
| 523 | 996 | continue; |
|---|
| 524 | 997 | |
|---|
| 525 | 998 | if (i++ < skip) |
|---|
| 526 | 999 | continue; |
|---|
| 527 | 1000 | |
|---|
| 528 | | - if (batadv_netlink_dump_hardif_entry(msg, portid, seq, |
|---|
| 529 | | - hard_iface)) { |
|---|
| 1001 | + if (batadv_netlink_hardif_fill(msg, bat_priv, hard_iface, |
|---|
| 1002 | + BATADV_CMD_GET_HARDIF, |
|---|
| 1003 | + portid, cb->nlh->nlmsg_seq, |
|---|
| 1004 | + NLM_F_MULTI, cb)) { |
|---|
| 530 | 1005 | i--; |
|---|
| 531 | 1006 | break; |
|---|
| 532 | 1007 | } |
|---|
| 533 | 1008 | } |
|---|
| 534 | 1009 | |
|---|
| 535 | | - rcu_read_unlock(); |
|---|
| 1010 | + rtnl_unlock(); |
|---|
| 536 | 1011 | |
|---|
| 537 | 1012 | dev_put(soft_iface); |
|---|
| 538 | 1013 | |
|---|
| .. | .. |
|---|
| 541 | 1016 | return msg->len; |
|---|
| 542 | 1017 | } |
|---|
| 543 | 1018 | |
|---|
| 544 | | -static const struct genl_ops batadv_netlink_ops[] = { |
|---|
| 1019 | +/** |
|---|
| 1020 | + * batadv_netlink_vlan_fill() - Fill message with vlan attributes |
|---|
| 1021 | + * @msg: Netlink message to dump into |
|---|
| 1022 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 1023 | + * @vlan: vlan which was modified |
|---|
| 1024 | + * @cmd: type of message to generate |
|---|
| 1025 | + * @portid: Port making netlink request |
|---|
| 1026 | + * @seq: sequence number for message |
|---|
| 1027 | + * @flags: Additional flags for message |
|---|
| 1028 | + * |
|---|
| 1029 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 1030 | + */ |
|---|
| 1031 | +static int batadv_netlink_vlan_fill(struct sk_buff *msg, |
|---|
| 1032 | + struct batadv_priv *bat_priv, |
|---|
| 1033 | + struct batadv_softif_vlan *vlan, |
|---|
| 1034 | + enum batadv_nl_commands cmd, |
|---|
| 1035 | + u32 portid, u32 seq, int flags) |
|---|
| 1036 | +{ |
|---|
| 1037 | + void *hdr; |
|---|
| 1038 | + |
|---|
| 1039 | + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, flags, cmd); |
|---|
| 1040 | + if (!hdr) |
|---|
| 1041 | + return -ENOBUFS; |
|---|
| 1042 | + |
|---|
| 1043 | + if (nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, |
|---|
| 1044 | + bat_priv->soft_iface->ifindex)) |
|---|
| 1045 | + goto nla_put_failure; |
|---|
| 1046 | + |
|---|
| 1047 | + if (nla_put_u32(msg, BATADV_ATTR_VLANID, vlan->vid & VLAN_VID_MASK)) |
|---|
| 1048 | + goto nla_put_failure; |
|---|
| 1049 | + |
|---|
| 1050 | + if (nla_put_u8(msg, BATADV_ATTR_AP_ISOLATION_ENABLED, |
|---|
| 1051 | + !!atomic_read(&vlan->ap_isolation))) |
|---|
| 1052 | + goto nla_put_failure; |
|---|
| 1053 | + |
|---|
| 1054 | + genlmsg_end(msg, hdr); |
|---|
| 1055 | + return 0; |
|---|
| 1056 | + |
|---|
| 1057 | +nla_put_failure: |
|---|
| 1058 | + genlmsg_cancel(msg, hdr); |
|---|
| 1059 | + return -EMSGSIZE; |
|---|
| 1060 | +} |
|---|
| 1061 | + |
|---|
| 1062 | +/** |
|---|
| 1063 | + * batadv_netlink_notify_vlan() - send vlan attributes to listener |
|---|
| 1064 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 1065 | + * @vlan: vlan which was modified |
|---|
| 1066 | + * |
|---|
| 1067 | + * Return: 0 on success, < 0 on error |
|---|
| 1068 | + */ |
|---|
| 1069 | +int batadv_netlink_notify_vlan(struct batadv_priv *bat_priv, |
|---|
| 1070 | + struct batadv_softif_vlan *vlan) |
|---|
| 1071 | +{ |
|---|
| 1072 | + struct sk_buff *msg; |
|---|
| 1073 | + int ret; |
|---|
| 1074 | + |
|---|
| 1075 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 1076 | + if (!msg) |
|---|
| 1077 | + return -ENOMEM; |
|---|
| 1078 | + |
|---|
| 1079 | + ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, |
|---|
| 1080 | + BATADV_CMD_SET_VLAN, 0, 0, 0); |
|---|
| 1081 | + if (ret < 0) { |
|---|
| 1082 | + nlmsg_free(msg); |
|---|
| 1083 | + return ret; |
|---|
| 1084 | + } |
|---|
| 1085 | + |
|---|
| 1086 | + genlmsg_multicast_netns(&batadv_netlink_family, |
|---|
| 1087 | + dev_net(bat_priv->soft_iface), msg, 0, |
|---|
| 1088 | + BATADV_NL_MCGRP_CONFIG, GFP_KERNEL); |
|---|
| 1089 | + |
|---|
| 1090 | + return 0; |
|---|
| 1091 | +} |
|---|
| 1092 | + |
|---|
| 1093 | +/** |
|---|
| 1094 | + * batadv_netlink_get_vlan() - Get vlan attributes |
|---|
| 1095 | + * @skb: Netlink message with request data |
|---|
| 1096 | + * @info: receiver information |
|---|
| 1097 | + * |
|---|
| 1098 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 1099 | + */ |
|---|
| 1100 | +static int batadv_netlink_get_vlan(struct sk_buff *skb, struct genl_info *info) |
|---|
| 1101 | +{ |
|---|
| 1102 | + struct batadv_softif_vlan *vlan = info->user_ptr[1]; |
|---|
| 1103 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 1104 | + struct sk_buff *msg; |
|---|
| 1105 | + int ret; |
|---|
| 1106 | + |
|---|
| 1107 | + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
|---|
| 1108 | + if (!msg) |
|---|
| 1109 | + return -ENOMEM; |
|---|
| 1110 | + |
|---|
| 1111 | + ret = batadv_netlink_vlan_fill(msg, bat_priv, vlan, BATADV_CMD_GET_VLAN, |
|---|
| 1112 | + info->snd_portid, info->snd_seq, 0); |
|---|
| 1113 | + if (ret < 0) { |
|---|
| 1114 | + nlmsg_free(msg); |
|---|
| 1115 | + return ret; |
|---|
| 1116 | + } |
|---|
| 1117 | + |
|---|
| 1118 | + ret = genlmsg_reply(msg, info); |
|---|
| 1119 | + |
|---|
| 1120 | + return ret; |
|---|
| 1121 | +} |
|---|
| 1122 | + |
|---|
| 1123 | +/** |
|---|
| 1124 | + * batadv_netlink_set_vlan() - Get vlan attributes |
|---|
| 1125 | + * @skb: Netlink message with request data |
|---|
| 1126 | + * @info: receiver information |
|---|
| 1127 | + * |
|---|
| 1128 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 1129 | + */ |
|---|
| 1130 | +static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info) |
|---|
| 1131 | +{ |
|---|
| 1132 | + struct batadv_softif_vlan *vlan = info->user_ptr[1]; |
|---|
| 1133 | + struct batadv_priv *bat_priv = info->user_ptr[0]; |
|---|
| 1134 | + struct nlattr *attr; |
|---|
| 1135 | + |
|---|
| 1136 | + if (info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]) { |
|---|
| 1137 | + attr = info->attrs[BATADV_ATTR_AP_ISOLATION_ENABLED]; |
|---|
| 1138 | + |
|---|
| 1139 | + atomic_set(&vlan->ap_isolation, !!nla_get_u8(attr)); |
|---|
| 1140 | + } |
|---|
| 1141 | + |
|---|
| 1142 | + batadv_netlink_notify_vlan(bat_priv, vlan); |
|---|
| 1143 | + |
|---|
| 1144 | + return 0; |
|---|
| 1145 | +} |
|---|
| 1146 | + |
|---|
| 1147 | +/** |
|---|
| 1148 | + * batadv_get_softif_from_info() - Retrieve soft interface from genl attributes |
|---|
| 1149 | + * @net: the applicable net namespace |
|---|
| 1150 | + * @info: receiver information |
|---|
| 1151 | + * |
|---|
| 1152 | + * Return: Pointer to soft interface (with increased refcnt) on success, error |
|---|
| 1153 | + * pointer on error |
|---|
| 1154 | + */ |
|---|
| 1155 | +static struct net_device * |
|---|
| 1156 | +batadv_get_softif_from_info(struct net *net, struct genl_info *info) |
|---|
| 1157 | +{ |
|---|
| 1158 | + struct net_device *soft_iface; |
|---|
| 1159 | + int ifindex; |
|---|
| 1160 | + |
|---|
| 1161 | + if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) |
|---|
| 1162 | + return ERR_PTR(-EINVAL); |
|---|
| 1163 | + |
|---|
| 1164 | + ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); |
|---|
| 1165 | + |
|---|
| 1166 | + soft_iface = dev_get_by_index(net, ifindex); |
|---|
| 1167 | + if (!soft_iface) |
|---|
| 1168 | + return ERR_PTR(-ENODEV); |
|---|
| 1169 | + |
|---|
| 1170 | + if (!batadv_softif_is_valid(soft_iface)) |
|---|
| 1171 | + goto err_put_softif; |
|---|
| 1172 | + |
|---|
| 1173 | + return soft_iface; |
|---|
| 1174 | + |
|---|
| 1175 | +err_put_softif: |
|---|
| 1176 | + dev_put(soft_iface); |
|---|
| 1177 | + |
|---|
| 1178 | + return ERR_PTR(-EINVAL); |
|---|
| 1179 | +} |
|---|
| 1180 | + |
|---|
| 1181 | +/** |
|---|
| 1182 | + * batadv_get_hardif_from_info() - Retrieve hardif from genl attributes |
|---|
| 1183 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 1184 | + * @net: the applicable net namespace |
|---|
| 1185 | + * @info: receiver information |
|---|
| 1186 | + * |
|---|
| 1187 | + * Return: Pointer to hard interface (with increased refcnt) on success, error |
|---|
| 1188 | + * pointer on error |
|---|
| 1189 | + */ |
|---|
| 1190 | +static struct batadv_hard_iface * |
|---|
| 1191 | +batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net, |
|---|
| 1192 | + struct genl_info *info) |
|---|
| 1193 | +{ |
|---|
| 1194 | + struct batadv_hard_iface *hard_iface; |
|---|
| 1195 | + struct net_device *hard_dev; |
|---|
| 1196 | + unsigned int hardif_index; |
|---|
| 1197 | + |
|---|
| 1198 | + if (!info->attrs[BATADV_ATTR_HARD_IFINDEX]) |
|---|
| 1199 | + return ERR_PTR(-EINVAL); |
|---|
| 1200 | + |
|---|
| 1201 | + hardif_index = nla_get_u32(info->attrs[BATADV_ATTR_HARD_IFINDEX]); |
|---|
| 1202 | + |
|---|
| 1203 | + hard_dev = dev_get_by_index(net, hardif_index); |
|---|
| 1204 | + if (!hard_dev) |
|---|
| 1205 | + return ERR_PTR(-ENODEV); |
|---|
| 1206 | + |
|---|
| 1207 | + hard_iface = batadv_hardif_get_by_netdev(hard_dev); |
|---|
| 1208 | + if (!hard_iface) |
|---|
| 1209 | + goto err_put_harddev; |
|---|
| 1210 | + |
|---|
| 1211 | + if (hard_iface->soft_iface != bat_priv->soft_iface) |
|---|
| 1212 | + goto err_put_hardif; |
|---|
| 1213 | + |
|---|
| 1214 | + /* hard_dev is referenced by hard_iface and not needed here */ |
|---|
| 1215 | + dev_put(hard_dev); |
|---|
| 1216 | + |
|---|
| 1217 | + return hard_iface; |
|---|
| 1218 | + |
|---|
| 1219 | +err_put_hardif: |
|---|
| 1220 | + batadv_hardif_put(hard_iface); |
|---|
| 1221 | +err_put_harddev: |
|---|
| 1222 | + dev_put(hard_dev); |
|---|
| 1223 | + |
|---|
| 1224 | + return ERR_PTR(-EINVAL); |
|---|
| 1225 | +} |
|---|
| 1226 | + |
|---|
| 1227 | +/** |
|---|
| 1228 | + * batadv_get_vlan_from_info() - Retrieve vlan from genl attributes |
|---|
| 1229 | + * @bat_priv: the bat priv with all the soft interface information |
|---|
| 1230 | + * @net: the applicable net namespace |
|---|
| 1231 | + * @info: receiver information |
|---|
| 1232 | + * |
|---|
| 1233 | + * Return: Pointer to vlan on success (with increased refcnt), error pointer |
|---|
| 1234 | + * on error |
|---|
| 1235 | + */ |
|---|
| 1236 | +static struct batadv_softif_vlan * |
|---|
| 1237 | +batadv_get_vlan_from_info(struct batadv_priv *bat_priv, struct net *net, |
|---|
| 1238 | + struct genl_info *info) |
|---|
| 1239 | +{ |
|---|
| 1240 | + struct batadv_softif_vlan *vlan; |
|---|
| 1241 | + u16 vid; |
|---|
| 1242 | + |
|---|
| 1243 | + if (!info->attrs[BATADV_ATTR_VLANID]) |
|---|
| 1244 | + return ERR_PTR(-EINVAL); |
|---|
| 1245 | + |
|---|
| 1246 | + vid = nla_get_u16(info->attrs[BATADV_ATTR_VLANID]); |
|---|
| 1247 | + |
|---|
| 1248 | + vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG); |
|---|
| 1249 | + if (!vlan) |
|---|
| 1250 | + return ERR_PTR(-ENOENT); |
|---|
| 1251 | + |
|---|
| 1252 | + return vlan; |
|---|
| 1253 | +} |
|---|
| 1254 | + |
|---|
| 1255 | +/** |
|---|
| 1256 | + * batadv_pre_doit() - Prepare batman-adv genl doit request |
|---|
| 1257 | + * @ops: requested netlink operation |
|---|
| 1258 | + * @skb: Netlink message with request data |
|---|
| 1259 | + * @info: receiver information |
|---|
| 1260 | + * |
|---|
| 1261 | + * Return: 0 on success or negative error number in case of failure |
|---|
| 1262 | + */ |
|---|
| 1263 | +static int batadv_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
|---|
| 1264 | + struct genl_info *info) |
|---|
| 1265 | +{ |
|---|
| 1266 | + struct net *net = genl_info_net(info); |
|---|
| 1267 | + struct batadv_hard_iface *hard_iface; |
|---|
| 1268 | + struct batadv_priv *bat_priv = NULL; |
|---|
| 1269 | + struct batadv_softif_vlan *vlan; |
|---|
| 1270 | + struct net_device *soft_iface; |
|---|
| 1271 | + u8 user_ptr1_flags; |
|---|
| 1272 | + u8 mesh_dep_flags; |
|---|
| 1273 | + int ret; |
|---|
| 1274 | + |
|---|
| 1275 | + user_ptr1_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN; |
|---|
| 1276 | + if (WARN_ON(hweight8(ops->internal_flags & user_ptr1_flags) > 1)) |
|---|
| 1277 | + return -EINVAL; |
|---|
| 1278 | + |
|---|
| 1279 | + mesh_dep_flags = BATADV_FLAG_NEED_HARDIF | BATADV_FLAG_NEED_VLAN; |
|---|
| 1280 | + if (WARN_ON((ops->internal_flags & mesh_dep_flags) && |
|---|
| 1281 | + (~ops->internal_flags & BATADV_FLAG_NEED_MESH))) |
|---|
| 1282 | + return -EINVAL; |
|---|
| 1283 | + |
|---|
| 1284 | + if (ops->internal_flags & BATADV_FLAG_NEED_MESH) { |
|---|
| 1285 | + soft_iface = batadv_get_softif_from_info(net, info); |
|---|
| 1286 | + if (IS_ERR(soft_iface)) |
|---|
| 1287 | + return PTR_ERR(soft_iface); |
|---|
| 1288 | + |
|---|
| 1289 | + bat_priv = netdev_priv(soft_iface); |
|---|
| 1290 | + info->user_ptr[0] = bat_priv; |
|---|
| 1291 | + } |
|---|
| 1292 | + |
|---|
| 1293 | + if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF) { |
|---|
| 1294 | + hard_iface = batadv_get_hardif_from_info(bat_priv, net, info); |
|---|
| 1295 | + if (IS_ERR(hard_iface)) { |
|---|
| 1296 | + ret = PTR_ERR(hard_iface); |
|---|
| 1297 | + goto err_put_softif; |
|---|
| 1298 | + } |
|---|
| 1299 | + |
|---|
| 1300 | + info->user_ptr[1] = hard_iface; |
|---|
| 1301 | + } |
|---|
| 1302 | + |
|---|
| 1303 | + if (ops->internal_flags & BATADV_FLAG_NEED_VLAN) { |
|---|
| 1304 | + vlan = batadv_get_vlan_from_info(bat_priv, net, info); |
|---|
| 1305 | + if (IS_ERR(vlan)) { |
|---|
| 1306 | + ret = PTR_ERR(vlan); |
|---|
| 1307 | + goto err_put_softif; |
|---|
| 1308 | + } |
|---|
| 1309 | + |
|---|
| 1310 | + info->user_ptr[1] = vlan; |
|---|
| 1311 | + } |
|---|
| 1312 | + |
|---|
| 1313 | + return 0; |
|---|
| 1314 | + |
|---|
| 1315 | +err_put_softif: |
|---|
| 1316 | + if (bat_priv) |
|---|
| 1317 | + dev_put(bat_priv->soft_iface); |
|---|
| 1318 | + |
|---|
| 1319 | + return ret; |
|---|
| 1320 | +} |
|---|
| 1321 | + |
|---|
| 1322 | +/** |
|---|
| 1323 | + * batadv_post_doit() - End batman-adv genl doit request |
|---|
| 1324 | + * @ops: requested netlink operation |
|---|
| 1325 | + * @skb: Netlink message with request data |
|---|
| 1326 | + * @info: receiver information |
|---|
| 1327 | + */ |
|---|
| 1328 | +static void batadv_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
|---|
| 1329 | + struct genl_info *info) |
|---|
| 1330 | +{ |
|---|
| 1331 | + struct batadv_hard_iface *hard_iface; |
|---|
| 1332 | + struct batadv_softif_vlan *vlan; |
|---|
| 1333 | + struct batadv_priv *bat_priv; |
|---|
| 1334 | + |
|---|
| 1335 | + if (ops->internal_flags & BATADV_FLAG_NEED_HARDIF && |
|---|
| 1336 | + info->user_ptr[1]) { |
|---|
| 1337 | + hard_iface = info->user_ptr[1]; |
|---|
| 1338 | + |
|---|
| 1339 | + batadv_hardif_put(hard_iface); |
|---|
| 1340 | + } |
|---|
| 1341 | + |
|---|
| 1342 | + if (ops->internal_flags & BATADV_FLAG_NEED_VLAN && info->user_ptr[1]) { |
|---|
| 1343 | + vlan = info->user_ptr[1]; |
|---|
| 1344 | + batadv_softif_vlan_put(vlan); |
|---|
| 1345 | + } |
|---|
| 1346 | + |
|---|
| 1347 | + if (ops->internal_flags & BATADV_FLAG_NEED_MESH && info->user_ptr[0]) { |
|---|
| 1348 | + bat_priv = info->user_ptr[0]; |
|---|
| 1349 | + dev_put(bat_priv->soft_iface); |
|---|
| 1350 | + } |
|---|
| 1351 | +} |
|---|
| 1352 | + |
|---|
| 1353 | +static const struct genl_small_ops batadv_netlink_ops[] = { |
|---|
| 545 | 1354 | { |
|---|
| 546 | | - .cmd = BATADV_CMD_GET_MESH_INFO, |
|---|
| 547 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 548 | | - .policy = batadv_netlink_policy, |
|---|
| 549 | | - .doit = batadv_netlink_get_mesh_info, |
|---|
| 1355 | + .cmd = BATADV_CMD_GET_MESH, |
|---|
| 1356 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1357 | + /* can be retrieved by unprivileged users */ |
|---|
| 1358 | + .doit = batadv_netlink_get_mesh, |
|---|
| 1359 | + .internal_flags = BATADV_FLAG_NEED_MESH, |
|---|
| 550 | 1360 | }, |
|---|
| 551 | 1361 | { |
|---|
| 552 | 1362 | .cmd = BATADV_CMD_TP_METER, |
|---|
| 553 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 554 | | - .policy = batadv_netlink_policy, |
|---|
| 1363 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1364 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 555 | 1365 | .doit = batadv_netlink_tp_meter_start, |
|---|
| 1366 | + .internal_flags = BATADV_FLAG_NEED_MESH, |
|---|
| 556 | 1367 | }, |
|---|
| 557 | 1368 | { |
|---|
| 558 | 1369 | .cmd = BATADV_CMD_TP_METER_CANCEL, |
|---|
| 559 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 560 | | - .policy = batadv_netlink_policy, |
|---|
| 1370 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1371 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 561 | 1372 | .doit = batadv_netlink_tp_meter_cancel, |
|---|
| 1373 | + .internal_flags = BATADV_FLAG_NEED_MESH, |
|---|
| 562 | 1374 | }, |
|---|
| 563 | 1375 | { |
|---|
| 564 | 1376 | .cmd = BATADV_CMD_GET_ROUTING_ALGOS, |
|---|
| 565 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 566 | | - .policy = batadv_netlink_policy, |
|---|
| 1377 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1378 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 567 | 1379 | .dumpit = batadv_algo_dump, |
|---|
| 568 | 1380 | }, |
|---|
| 569 | 1381 | { |
|---|
| 570 | | - .cmd = BATADV_CMD_GET_HARDIFS, |
|---|
| 571 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 572 | | - .policy = batadv_netlink_policy, |
|---|
| 573 | | - .dumpit = batadv_netlink_dump_hardifs, |
|---|
| 1382 | + .cmd = BATADV_CMD_GET_HARDIF, |
|---|
| 1383 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1384 | + /* can be retrieved by unprivileged users */ |
|---|
| 1385 | + .dumpit = batadv_netlink_dump_hardif, |
|---|
| 1386 | + .doit = batadv_netlink_get_hardif, |
|---|
| 1387 | + .internal_flags = BATADV_FLAG_NEED_MESH | |
|---|
| 1388 | + BATADV_FLAG_NEED_HARDIF, |
|---|
| 574 | 1389 | }, |
|---|
| 575 | 1390 | { |
|---|
| 576 | 1391 | .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, |
|---|
| 577 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 578 | | - .policy = batadv_netlink_policy, |
|---|
| 1392 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1393 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 579 | 1394 | .dumpit = batadv_tt_local_dump, |
|---|
| 580 | 1395 | }, |
|---|
| 581 | 1396 | { |
|---|
| 582 | 1397 | .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, |
|---|
| 583 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 584 | | - .policy = batadv_netlink_policy, |
|---|
| 1398 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1399 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 585 | 1400 | .dumpit = batadv_tt_global_dump, |
|---|
| 586 | 1401 | }, |
|---|
| 587 | 1402 | { |
|---|
| 588 | 1403 | .cmd = BATADV_CMD_GET_ORIGINATORS, |
|---|
| 589 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 590 | | - .policy = batadv_netlink_policy, |
|---|
| 1404 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1405 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 591 | 1406 | .dumpit = batadv_orig_dump, |
|---|
| 592 | 1407 | }, |
|---|
| 593 | 1408 | { |
|---|
| 594 | 1409 | .cmd = BATADV_CMD_GET_NEIGHBORS, |
|---|
| 595 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 596 | | - .policy = batadv_netlink_policy, |
|---|
| 1410 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1411 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 597 | 1412 | .dumpit = batadv_hardif_neigh_dump, |
|---|
| 598 | 1413 | }, |
|---|
| 599 | 1414 | { |
|---|
| 600 | 1415 | .cmd = BATADV_CMD_GET_GATEWAYS, |
|---|
| 601 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 602 | | - .policy = batadv_netlink_policy, |
|---|
| 1416 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1417 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 603 | 1418 | .dumpit = batadv_gw_dump, |
|---|
| 604 | 1419 | }, |
|---|
| 605 | 1420 | { |
|---|
| 606 | 1421 | .cmd = BATADV_CMD_GET_BLA_CLAIM, |
|---|
| 607 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 608 | | - .policy = batadv_netlink_policy, |
|---|
| 1422 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1423 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 609 | 1424 | .dumpit = batadv_bla_claim_dump, |
|---|
| 610 | 1425 | }, |
|---|
| 611 | 1426 | { |
|---|
| 612 | 1427 | .cmd = BATADV_CMD_GET_BLA_BACKBONE, |
|---|
| 613 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 614 | | - .policy = batadv_netlink_policy, |
|---|
| 1428 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1429 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 615 | 1430 | .dumpit = batadv_bla_backbone_dump, |
|---|
| 616 | 1431 | }, |
|---|
| 617 | 1432 | { |
|---|
| 618 | 1433 | .cmd = BATADV_CMD_GET_DAT_CACHE, |
|---|
| 619 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 620 | | - .policy = batadv_netlink_policy, |
|---|
| 1434 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1435 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 621 | 1436 | .dumpit = batadv_dat_cache_dump, |
|---|
| 622 | 1437 | }, |
|---|
| 623 | 1438 | { |
|---|
| 624 | 1439 | .cmd = BATADV_CMD_GET_MCAST_FLAGS, |
|---|
| 625 | | - .flags = GENL_ADMIN_PERM, |
|---|
| 626 | | - .policy = batadv_netlink_policy, |
|---|
| 1440 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1441 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 627 | 1442 | .dumpit = batadv_mcast_flags_dump, |
|---|
| 628 | 1443 | }, |
|---|
| 629 | | - |
|---|
| 1444 | + { |
|---|
| 1445 | + .cmd = BATADV_CMD_SET_MESH, |
|---|
| 1446 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1447 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 1448 | + .doit = batadv_netlink_set_mesh, |
|---|
| 1449 | + .internal_flags = BATADV_FLAG_NEED_MESH, |
|---|
| 1450 | + }, |
|---|
| 1451 | + { |
|---|
| 1452 | + .cmd = BATADV_CMD_SET_HARDIF, |
|---|
| 1453 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1454 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 1455 | + .doit = batadv_netlink_set_hardif, |
|---|
| 1456 | + .internal_flags = BATADV_FLAG_NEED_MESH | |
|---|
| 1457 | + BATADV_FLAG_NEED_HARDIF, |
|---|
| 1458 | + }, |
|---|
| 1459 | + { |
|---|
| 1460 | + .cmd = BATADV_CMD_GET_VLAN, |
|---|
| 1461 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1462 | + /* can be retrieved by unprivileged users */ |
|---|
| 1463 | + .doit = batadv_netlink_get_vlan, |
|---|
| 1464 | + .internal_flags = BATADV_FLAG_NEED_MESH | |
|---|
| 1465 | + BATADV_FLAG_NEED_VLAN, |
|---|
| 1466 | + }, |
|---|
| 1467 | + { |
|---|
| 1468 | + .cmd = BATADV_CMD_SET_VLAN, |
|---|
| 1469 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1470 | + .flags = GENL_UNS_ADMIN_PERM, |
|---|
| 1471 | + .doit = batadv_netlink_set_vlan, |
|---|
| 1472 | + .internal_flags = BATADV_FLAG_NEED_MESH | |
|---|
| 1473 | + BATADV_FLAG_NEED_VLAN, |
|---|
| 1474 | + }, |
|---|
| 630 | 1475 | }; |
|---|
| 631 | 1476 | |
|---|
| 632 | 1477 | struct genl_family batadv_netlink_family __ro_after_init = { |
|---|
| .. | .. |
|---|
| 634 | 1479 | .name = BATADV_NL_NAME, |
|---|
| 635 | 1480 | .version = 1, |
|---|
| 636 | 1481 | .maxattr = BATADV_ATTR_MAX, |
|---|
| 1482 | + .policy = batadv_netlink_policy, |
|---|
| 637 | 1483 | .netnsok = true, |
|---|
| 1484 | + .pre_doit = batadv_pre_doit, |
|---|
| 1485 | + .post_doit = batadv_post_doit, |
|---|
| 638 | 1486 | .module = THIS_MODULE, |
|---|
| 639 | | - .ops = batadv_netlink_ops, |
|---|
| 640 | | - .n_ops = ARRAY_SIZE(batadv_netlink_ops), |
|---|
| 1487 | + .small_ops = batadv_netlink_ops, |
|---|
| 1488 | + .n_small_ops = ARRAY_SIZE(batadv_netlink_ops), |
|---|
| 641 | 1489 | .mcgrps = batadv_netlink_mcgrps, |
|---|
| 642 | 1490 | .n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps), |
|---|
| 643 | 1491 | }; |
|---|