| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors: |
|---|
| 2 | +/* Copyright (C) 2010-2020 B.A.T.M.A.N. contributors: |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * Marek Lindner |
|---|
| 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 "sysfs.h" |
|---|
| 20 | 8 | #include "main.h" |
|---|
| 21 | 9 | |
|---|
| 10 | +#include <asm/current.h> |
|---|
| 22 | 11 | #include <linux/atomic.h> |
|---|
| 23 | 12 | #include <linux/compiler.h> |
|---|
| 24 | 13 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 29 | 18 | #include <linux/kernel.h> |
|---|
| 30 | 19 | #include <linux/kobject.h> |
|---|
| 31 | 20 | #include <linux/kref.h> |
|---|
| 21 | +#include <linux/limits.h> |
|---|
| 32 | 22 | #include <linux/netdevice.h> |
|---|
| 33 | 23 | #include <linux/printk.h> |
|---|
| 34 | 24 | #include <linux/rculist.h> |
|---|
| 35 | 25 | #include <linux/rcupdate.h> |
|---|
| 36 | 26 | #include <linux/rtnetlink.h> |
|---|
| 27 | +#include <linux/sched.h> |
|---|
| 37 | 28 | #include <linux/slab.h> |
|---|
| 38 | 29 | #include <linux/stddef.h> |
|---|
| 39 | 30 | #include <linux/string.h> |
|---|
| 40 | 31 | #include <linux/stringify.h> |
|---|
| 41 | 32 | #include <linux/workqueue.h> |
|---|
| 42 | 33 | #include <uapi/linux/batadv_packet.h> |
|---|
| 34 | +#include <uapi/linux/batman_adv.h> |
|---|
| 43 | 35 | |
|---|
| 44 | 36 | #include "bridge_loop_avoidance.h" |
|---|
| 45 | 37 | #include "distributed-arp-table.h" |
|---|
| .. | .. |
|---|
| 47 | 39 | #include "gateway_common.h" |
|---|
| 48 | 40 | #include "hard-interface.h" |
|---|
| 49 | 41 | #include "log.h" |
|---|
| 42 | +#include "netlink.h" |
|---|
| 50 | 43 | #include "network-coding.h" |
|---|
| 51 | 44 | #include "soft-interface.h" |
|---|
| 45 | + |
|---|
| 46 | +/** |
|---|
| 47 | + * batadv_sysfs_deprecated() - Log use of deprecated batadv sysfs access |
|---|
| 48 | + * @attr: attribute which was accessed |
|---|
| 49 | + */ |
|---|
| 50 | +static void batadv_sysfs_deprecated(struct attribute *attr) |
|---|
| 51 | +{ |
|---|
| 52 | + pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of sysfs file \"%s\".\nUse batadv genl family instead", |
|---|
| 53 | + current->comm, task_pid_nr(current), attr->name); |
|---|
| 54 | +} |
|---|
| 52 | 55 | |
|---|
| 53 | 56 | static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) |
|---|
| 54 | 57 | { |
|---|
| .. | .. |
|---|
| 112 | 115 | return vlan; |
|---|
| 113 | 116 | } |
|---|
| 114 | 117 | |
|---|
| 115 | | -#define BATADV_UEV_TYPE_VAR "BATTYPE=" |
|---|
| 116 | | -#define BATADV_UEV_ACTION_VAR "BATACTION=" |
|---|
| 117 | | -#define BATADV_UEV_DATA_VAR "BATDATA=" |
|---|
| 118 | | - |
|---|
| 119 | | -static char *batadv_uev_action_str[] = { |
|---|
| 120 | | - "add", |
|---|
| 121 | | - "del", |
|---|
| 122 | | - "change", |
|---|
| 123 | | - "loopdetect", |
|---|
| 124 | | -}; |
|---|
| 125 | | - |
|---|
| 126 | | -static char *batadv_uev_type_str[] = { |
|---|
| 127 | | - "gw", |
|---|
| 128 | | - "bla", |
|---|
| 129 | | -}; |
|---|
| 130 | | - |
|---|
| 131 | 118 | /* Use this, if you have customized show and store functions for vlan attrs */ |
|---|
| 132 | 119 | #define BATADV_ATTR_VLAN(_name, _mode, _show, _store) \ |
|---|
| 133 | 120 | struct batadv_attribute batadv_attr_vlan_##_name = { \ |
|---|
| .. | .. |
|---|
| 153 | 140 | { \ |
|---|
| 154 | 141 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
|---|
| 155 | 142 | struct batadv_priv *bat_priv = netdev_priv(net_dev); \ |
|---|
| 143 | + ssize_t length; \ |
|---|
| 156 | 144 | \ |
|---|
| 157 | | - return __batadv_store_bool_attr(buff, count, _post_func, attr, \ |
|---|
| 158 | | - &bat_priv->_name, net_dev); \ |
|---|
| 145 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 146 | + length = __batadv_store_bool_attr(buff, count, _post_func, attr,\ |
|---|
| 147 | + &bat_priv->_name, net_dev); \ |
|---|
| 148 | + \ |
|---|
| 149 | + batadv_netlink_notify_mesh(bat_priv); \ |
|---|
| 150 | + \ |
|---|
| 151 | + return length; \ |
|---|
| 159 | 152 | } |
|---|
| 160 | 153 | |
|---|
| 161 | 154 | #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \ |
|---|
| .. | .. |
|---|
| 164 | 157 | { \ |
|---|
| 165 | 158 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
|---|
| 166 | 159 | \ |
|---|
| 160 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 167 | 161 | return sprintf(buff, "%s\n", \ |
|---|
| 168 | 162 | atomic_read(&bat_priv->_name) == 0 ? \ |
|---|
| 169 | 163 | "disabled" : "enabled"); \ |
|---|
| .. | .. |
|---|
| 185 | 179 | { \ |
|---|
| 186 | 180 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
|---|
| 187 | 181 | struct batadv_priv *bat_priv = netdev_priv(net_dev); \ |
|---|
| 182 | + ssize_t length; \ |
|---|
| 188 | 183 | \ |
|---|
| 189 | | - return __batadv_store_uint_attr(buff, count, _min, _max, \ |
|---|
| 190 | | - _post_func, attr, \ |
|---|
| 191 | | - &bat_priv->_var, net_dev, \ |
|---|
| 192 | | - NULL); \ |
|---|
| 184 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 185 | + length = __batadv_store_uint_attr(buff, count, _min, _max, \ |
|---|
| 186 | + _post_func, attr, \ |
|---|
| 187 | + &bat_priv->_var, net_dev, \ |
|---|
| 188 | + NULL); \ |
|---|
| 189 | + \ |
|---|
| 190 | + batadv_netlink_notify_mesh(bat_priv); \ |
|---|
| 191 | + \ |
|---|
| 192 | + return length; \ |
|---|
| 193 | 193 | } |
|---|
| 194 | 194 | |
|---|
| 195 | 195 | #define BATADV_ATTR_SIF_SHOW_UINT(_name, _var) \ |
|---|
| .. | .. |
|---|
| 198 | 198 | { \ |
|---|
| 199 | 199 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
|---|
| 200 | 200 | \ |
|---|
| 201 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 201 | 202 | return sprintf(buff, "%i\n", atomic_read(&bat_priv->_var)); \ |
|---|
| 202 | 203 | } \ |
|---|
| 203 | 204 | |
|---|
| .. | .. |
|---|
| 222 | 223 | attr, &vlan->_name, \ |
|---|
| 223 | 224 | bat_priv->soft_iface); \ |
|---|
| 224 | 225 | \ |
|---|
| 226 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 227 | + if (vlan->vid) \ |
|---|
| 228 | + batadv_netlink_notify_vlan(bat_priv, vlan); \ |
|---|
| 229 | + else \ |
|---|
| 230 | + batadv_netlink_notify_mesh(bat_priv); \ |
|---|
| 231 | + \ |
|---|
| 225 | 232 | batadv_softif_vlan_put(vlan); \ |
|---|
| 226 | 233 | return res; \ |
|---|
| 227 | 234 | } |
|---|
| .. | .. |
|---|
| 237 | 244 | atomic_read(&vlan->_name) == 0 ? \ |
|---|
| 238 | 245 | "disabled" : "enabled"); \ |
|---|
| 239 | 246 | \ |
|---|
| 247 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 240 | 248 | batadv_softif_vlan_put(vlan); \ |
|---|
| 241 | 249 | return res; \ |
|---|
| 242 | 250 | } |
|---|
| .. | .. |
|---|
| 255 | 263 | { \ |
|---|
| 256 | 264 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
|---|
| 257 | 265 | struct batadv_hard_iface *hard_iface; \ |
|---|
| 266 | + struct batadv_priv *bat_priv; \ |
|---|
| 258 | 267 | ssize_t length; \ |
|---|
| 259 | 268 | \ |
|---|
| 269 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 260 | 270 | hard_iface = batadv_hardif_get_by_netdev(net_dev); \ |
|---|
| 261 | 271 | if (!hard_iface) \ |
|---|
| 262 | 272 | return 0; \ |
|---|
| .. | .. |
|---|
| 266 | 276 | &hard_iface->_var, \ |
|---|
| 267 | 277 | hard_iface->soft_iface, \ |
|---|
| 268 | 278 | net_dev); \ |
|---|
| 279 | + \ |
|---|
| 280 | + if (hard_iface->soft_iface) { \ |
|---|
| 281 | + bat_priv = netdev_priv(hard_iface->soft_iface); \ |
|---|
| 282 | + batadv_netlink_notify_hardif(bat_priv, hard_iface); \ |
|---|
| 283 | + } \ |
|---|
| 269 | 284 | \ |
|---|
| 270 | 285 | batadv_hardif_put(hard_iface); \ |
|---|
| 271 | 286 | return length; \ |
|---|
| .. | .. |
|---|
| 279 | 294 | struct batadv_hard_iface *hard_iface; \ |
|---|
| 280 | 295 | ssize_t length; \ |
|---|
| 281 | 296 | \ |
|---|
| 297 | + batadv_sysfs_deprecated(attr); \ |
|---|
| 282 | 298 | hard_iface = batadv_hardif_get_by_netdev(net_dev); \ |
|---|
| 283 | 299 | if (!hard_iface) \ |
|---|
| 284 | 300 | return 0; \ |
|---|
| .. | .. |
|---|
| 423 | 439 | { |
|---|
| 424 | 440 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 425 | 441 | |
|---|
| 442 | + batadv_sysfs_deprecated(attr); |
|---|
| 426 | 443 | return sprintf(buff, "%s\n", bat_priv->algo_ops->name); |
|---|
| 427 | 444 | } |
|---|
| 428 | 445 | |
|---|
| .. | .. |
|---|
| 438 | 455 | { |
|---|
| 439 | 456 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 440 | 457 | int bytes_written; |
|---|
| 458 | + |
|---|
| 459 | + batadv_sysfs_deprecated(attr); |
|---|
| 441 | 460 | |
|---|
| 442 | 461 | /* GW mode is not available if the routing algorithm in use does not |
|---|
| 443 | 462 | * implement the GW API |
|---|
| .. | .. |
|---|
| 472 | 491 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
|---|
| 473 | 492 | char *curr_gw_mode_str; |
|---|
| 474 | 493 | int gw_mode_tmp = -1; |
|---|
| 494 | + |
|---|
| 495 | + batadv_sysfs_deprecated(attr); |
|---|
| 475 | 496 | |
|---|
| 476 | 497 | /* toggling GW mode is allowed only if the routing algorithm in use |
|---|
| 477 | 498 | * provides the GW API |
|---|
| .. | .. |
|---|
| 536 | 557 | batadv_gw_check_client_stop(bat_priv); |
|---|
| 537 | 558 | atomic_set(&bat_priv->gw.mode, (unsigned int)gw_mode_tmp); |
|---|
| 538 | 559 | batadv_gw_tvlv_container_update(bat_priv); |
|---|
| 560 | + |
|---|
| 561 | + batadv_netlink_notify_mesh(bat_priv); |
|---|
| 562 | + |
|---|
| 539 | 563 | return count; |
|---|
| 540 | 564 | } |
|---|
| 541 | 565 | |
|---|
| .. | .. |
|---|
| 543 | 567 | struct attribute *attr, char *buff) |
|---|
| 544 | 568 | { |
|---|
| 545 | 569 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 570 | + |
|---|
| 571 | + batadv_sysfs_deprecated(attr); |
|---|
| 546 | 572 | |
|---|
| 547 | 573 | /* GW selection class is not available if the routing algorithm in use |
|---|
| 548 | 574 | * does not implement the GW API |
|---|
| .. | .. |
|---|
| 562 | 588 | size_t count) |
|---|
| 563 | 589 | { |
|---|
| 564 | 590 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 591 | + ssize_t length; |
|---|
| 592 | + |
|---|
| 593 | + batadv_sysfs_deprecated(attr); |
|---|
| 565 | 594 | |
|---|
| 566 | 595 | /* setting the GW selection class is allowed only if the routing |
|---|
| 567 | 596 | * algorithm in use implements the GW API |
|---|
| .. | .. |
|---|
| 577 | 606 | return bat_priv->algo_ops->gw.store_sel_class(bat_priv, buff, |
|---|
| 578 | 607 | count); |
|---|
| 579 | 608 | |
|---|
| 580 | | - return __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE, |
|---|
| 581 | | - batadv_post_gw_reselect, attr, |
|---|
| 582 | | - &bat_priv->gw.sel_class, |
|---|
| 583 | | - bat_priv->soft_iface, NULL); |
|---|
| 609 | + length = __batadv_store_uint_attr(buff, count, 1, BATADV_TQ_MAX_VALUE, |
|---|
| 610 | + batadv_post_gw_reselect, attr, |
|---|
| 611 | + &bat_priv->gw.sel_class, |
|---|
| 612 | + bat_priv->soft_iface, NULL); |
|---|
| 613 | + |
|---|
| 614 | + batadv_netlink_notify_mesh(bat_priv); |
|---|
| 615 | + |
|---|
| 616 | + return length; |
|---|
| 584 | 617 | } |
|---|
| 585 | 618 | |
|---|
| 586 | 619 | static ssize_t batadv_show_gw_bwidth(struct kobject *kobj, |
|---|
| .. | .. |
|---|
| 588 | 621 | { |
|---|
| 589 | 622 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 590 | 623 | u32 down, up; |
|---|
| 624 | + |
|---|
| 625 | + batadv_sysfs_deprecated(attr); |
|---|
| 591 | 626 | |
|---|
| 592 | 627 | down = atomic_read(&bat_priv->gw.bandwidth_down); |
|---|
| 593 | 628 | up = atomic_read(&bat_priv->gw.bandwidth_up); |
|---|
| .. | .. |
|---|
| 600 | 635 | struct attribute *attr, char *buff, |
|---|
| 601 | 636 | size_t count) |
|---|
| 602 | 637 | { |
|---|
| 638 | + struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 603 | 639 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
|---|
| 640 | + ssize_t length; |
|---|
| 641 | + |
|---|
| 642 | + batadv_sysfs_deprecated(attr); |
|---|
| 604 | 643 | |
|---|
| 605 | 644 | if (buff[count - 1] == '\n') |
|---|
| 606 | 645 | buff[count - 1] = '\0'; |
|---|
| 607 | 646 | |
|---|
| 608 | | - return batadv_gw_bandwidth_set(net_dev, buff, count); |
|---|
| 647 | + length = batadv_gw_bandwidth_set(net_dev, buff, count); |
|---|
| 648 | + |
|---|
| 649 | + batadv_netlink_notify_mesh(bat_priv); |
|---|
| 650 | + |
|---|
| 651 | + return length; |
|---|
| 609 | 652 | } |
|---|
| 610 | 653 | |
|---|
| 611 | 654 | /** |
|---|
| .. | .. |
|---|
| 622 | 665 | { |
|---|
| 623 | 666 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
|---|
| 624 | 667 | |
|---|
| 668 | + batadv_sysfs_deprecated(attr); |
|---|
| 625 | 669 | return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark, |
|---|
| 626 | 670 | bat_priv->isolation_mark_mask); |
|---|
| 627 | 671 | } |
|---|
| .. | .. |
|---|
| 644 | 688 | struct batadv_priv *bat_priv = netdev_priv(net_dev); |
|---|
| 645 | 689 | u32 mark, mask; |
|---|
| 646 | 690 | char *mask_ptr; |
|---|
| 691 | + |
|---|
| 692 | + batadv_sysfs_deprecated(attr); |
|---|
| 647 | 693 | |
|---|
| 648 | 694 | /* parse the mask if it has been specified, otherwise assume the mask is |
|---|
| 649 | 695 | * the biggest possible |
|---|
| .. | .. |
|---|
| 672 | 718 | batadv_info(net_dev, |
|---|
| 673 | 719 | "New skb mark for extended isolation: %#.8x/%#.8x\n", |
|---|
| 674 | 720 | bat_priv->isolation_mark, bat_priv->isolation_mark_mask); |
|---|
| 721 | + |
|---|
| 722 | + batadv_netlink_notify_mesh(bat_priv); |
|---|
| 675 | 723 | |
|---|
| 676 | 724 | return count; |
|---|
| 677 | 725 | } |
|---|
| .. | .. |
|---|
| 898 | 946 | ssize_t length; |
|---|
| 899 | 947 | const char *ifname; |
|---|
| 900 | 948 | |
|---|
| 949 | + batadv_sysfs_deprecated(attr); |
|---|
| 950 | + |
|---|
| 901 | 951 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
|---|
| 902 | 952 | if (!hard_iface) |
|---|
| 903 | 953 | return 0; |
|---|
| .. | .. |
|---|
| 1002 | 1052 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
|---|
| 1003 | 1053 | struct batadv_store_mesh_work *store_work; |
|---|
| 1004 | 1054 | |
|---|
| 1055 | + batadv_sysfs_deprecated(attr); |
|---|
| 1056 | + |
|---|
| 1005 | 1057 | if (buff[count - 1] == '\n') |
|---|
| 1006 | 1058 | buff[count - 1] = '\0'; |
|---|
| 1007 | 1059 | |
|---|
| .. | .. |
|---|
| 1018 | 1070 | dev_hold(net_dev); |
|---|
| 1019 | 1071 | INIT_WORK(&store_work->work, batadv_store_mesh_iface_work); |
|---|
| 1020 | 1072 | store_work->net_dev = net_dev; |
|---|
| 1021 | | - strlcpy(store_work->soft_iface_name, buff, |
|---|
| 1073 | + strscpy(store_work->soft_iface_name, buff, |
|---|
| 1022 | 1074 | sizeof(store_work->soft_iface_name)); |
|---|
| 1023 | 1075 | |
|---|
| 1024 | 1076 | queue_work(batadv_event_workqueue, &store_work->work); |
|---|
| .. | .. |
|---|
| 1032 | 1084 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
|---|
| 1033 | 1085 | struct batadv_hard_iface *hard_iface; |
|---|
| 1034 | 1086 | ssize_t length; |
|---|
| 1087 | + |
|---|
| 1088 | + batadv_sysfs_deprecated(attr); |
|---|
| 1035 | 1089 | |
|---|
| 1036 | 1090 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
|---|
| 1037 | 1091 | if (!hard_iface) |
|---|
| .. | .. |
|---|
| 1079 | 1133 | { |
|---|
| 1080 | 1134 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
|---|
| 1081 | 1135 | struct batadv_hard_iface *hard_iface; |
|---|
| 1136 | + struct batadv_priv *bat_priv; |
|---|
| 1082 | 1137 | u32 tp_override; |
|---|
| 1083 | 1138 | u32 old_tp_override; |
|---|
| 1084 | 1139 | bool ret; |
|---|
| 1140 | + |
|---|
| 1141 | + batadv_sysfs_deprecated(attr); |
|---|
| 1085 | 1142 | |
|---|
| 1086 | 1143 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
|---|
| 1087 | 1144 | if (!hard_iface) |
|---|
| .. | .. |
|---|
| 1107 | 1164 | |
|---|
| 1108 | 1165 | atomic_set(&hard_iface->bat_v.throughput_override, tp_override); |
|---|
| 1109 | 1166 | |
|---|
| 1167 | + if (hard_iface->soft_iface) { |
|---|
| 1168 | + bat_priv = netdev_priv(hard_iface->soft_iface); |
|---|
| 1169 | + batadv_netlink_notify_hardif(bat_priv, hard_iface); |
|---|
| 1170 | + } |
|---|
| 1171 | + |
|---|
| 1110 | 1172 | out: |
|---|
| 1111 | 1173 | batadv_hardif_put(hard_iface); |
|---|
| 1112 | 1174 | return count; |
|---|
| .. | .. |
|---|
| 1119 | 1181 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
|---|
| 1120 | 1182 | struct batadv_hard_iface *hard_iface; |
|---|
| 1121 | 1183 | u32 tp_override; |
|---|
| 1184 | + |
|---|
| 1185 | + batadv_sysfs_deprecated(attr); |
|---|
| 1122 | 1186 | |
|---|
| 1123 | 1187 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
|---|
| 1124 | 1188 | if (!hard_iface) |
|---|
| .. | .. |
|---|
| 1205 | 1269 | kobject_del(*hardif_obj); |
|---|
| 1206 | 1270 | kobject_put(*hardif_obj); |
|---|
| 1207 | 1271 | *hardif_obj = NULL; |
|---|
| 1208 | | -} |
|---|
| 1209 | | - |
|---|
| 1210 | | -/** |
|---|
| 1211 | | - * batadv_throw_uevent() - Send an uevent with batman-adv specific env data |
|---|
| 1212 | | - * @bat_priv: the bat priv with all the soft interface information |
|---|
| 1213 | | - * @type: subsystem type of event. Stored in uevent's BATTYPE |
|---|
| 1214 | | - * @action: action type of event. Stored in uevent's BATACTION |
|---|
| 1215 | | - * @data: string with additional information to the event (ignored for |
|---|
| 1216 | | - * BATADV_UEV_DEL). Stored in uevent's BATDATA |
|---|
| 1217 | | - * |
|---|
| 1218 | | - * Return: 0 on success or negative error number in case of failure |
|---|
| 1219 | | - */ |
|---|
| 1220 | | -int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, |
|---|
| 1221 | | - enum batadv_uev_action action, const char *data) |
|---|
| 1222 | | -{ |
|---|
| 1223 | | - int ret = -ENOMEM; |
|---|
| 1224 | | - struct kobject *bat_kobj; |
|---|
| 1225 | | - char *uevent_env[4] = { NULL, NULL, NULL, NULL }; |
|---|
| 1226 | | - |
|---|
| 1227 | | - bat_kobj = &bat_priv->soft_iface->dev.kobj; |
|---|
| 1228 | | - |
|---|
| 1229 | | - uevent_env[0] = kasprintf(GFP_ATOMIC, |
|---|
| 1230 | | - "%s%s", BATADV_UEV_TYPE_VAR, |
|---|
| 1231 | | - batadv_uev_type_str[type]); |
|---|
| 1232 | | - if (!uevent_env[0]) |
|---|
| 1233 | | - goto out; |
|---|
| 1234 | | - |
|---|
| 1235 | | - uevent_env[1] = kasprintf(GFP_ATOMIC, |
|---|
| 1236 | | - "%s%s", BATADV_UEV_ACTION_VAR, |
|---|
| 1237 | | - batadv_uev_action_str[action]); |
|---|
| 1238 | | - if (!uevent_env[1]) |
|---|
| 1239 | | - goto out; |
|---|
| 1240 | | - |
|---|
| 1241 | | - /* If the event is DEL, ignore the data field */ |
|---|
| 1242 | | - if (action != BATADV_UEV_DEL) { |
|---|
| 1243 | | - uevent_env[2] = kasprintf(GFP_ATOMIC, |
|---|
| 1244 | | - "%s%s", BATADV_UEV_DATA_VAR, data); |
|---|
| 1245 | | - if (!uevent_env[2]) |
|---|
| 1246 | | - goto out; |
|---|
| 1247 | | - } |
|---|
| 1248 | | - |
|---|
| 1249 | | - ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); |
|---|
| 1250 | | -out: |
|---|
| 1251 | | - kfree(uevent_env[0]); |
|---|
| 1252 | | - kfree(uevent_env[1]); |
|---|
| 1253 | | - kfree(uevent_env[2]); |
|---|
| 1254 | | - |
|---|
| 1255 | | - if (ret) |
|---|
| 1256 | | - batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
|---|
| 1257 | | - "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", |
|---|
| 1258 | | - batadv_uev_type_str[type], |
|---|
| 1259 | | - batadv_uev_action_str[action], |
|---|
| 1260 | | - (action == BATADV_UEV_DEL ? "NULL" : data), ret); |
|---|
| 1261 | | - return ret; |
|---|
| 1262 | 1272 | } |
|---|