This source file includes following definitions.
- batadv_debugfs_deprecated
 
- batadv_algorithms_open
 
- neighbors_open
 
- batadv_originators_open
 
- batadv_originators_hardif_open
 
- batadv_gateways_open
 
- batadv_transtable_global_open
 
- batadv_bla_claim_table_open
 
- batadv_bla_backbone_table_open
 
- batadv_dat_cache_open
 
- batadv_transtable_local_open
 
- batadv_nc_nodes_open
 
- batadv_mcast_flags_open
 
- batadv_debugfs_init
 
- batadv_debugfs_destroy
 
- batadv_debugfs_add_hardif
 
- batadv_debugfs_rename_hardif
 
- batadv_debugfs_del_hardif
 
- batadv_debugfs_add_meshif
 
- batadv_debugfs_rename_meshif
 
- batadv_debugfs_del_meshif
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 #include "debugfs.h"
   8 #include "main.h"
   9 
  10 #include <asm/current.h>
  11 #include <linux/dcache.h>
  12 #include <linux/debugfs.h>
  13 #include <linux/errno.h>
  14 #include <linux/export.h>
  15 #include <linux/fs.h>
  16 #include <linux/netdevice.h>
  17 #include <linux/printk.h>
  18 #include <linux/sched.h>
  19 #include <linux/seq_file.h>
  20 #include <linux/stat.h>
  21 #include <linux/stddef.h>
  22 #include <linux/stringify.h>
  23 #include <linux/sysfs.h>
  24 #include <net/net_namespace.h>
  25 
  26 #include "bat_algo.h"
  27 #include "bridge_loop_avoidance.h"
  28 #include "distributed-arp-table.h"
  29 #include "gateway_client.h"
  30 #include "icmp_socket.h"
  31 #include "log.h"
  32 #include "multicast.h"
  33 #include "network-coding.h"
  34 #include "originator.h"
  35 #include "translation-table.h"
  36 
  37 static struct dentry *batadv_debugfs;
  38 
  39 
  40 
  41 
  42 
  43 
  44 void batadv_debugfs_deprecated(struct file *file, const char *alt)
  45 {
  46         struct dentry *dentry = file_dentry(file);
  47         const char *name = dentry->d_name.name;
  48 
  49         pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of debugfs file \"%s\".\n%s",
  50                             current->comm, task_pid_nr(current), name, alt);
  51 }
  52 
  53 static int batadv_algorithms_open(struct inode *inode, struct file *file)
  54 {
  55         batadv_debugfs_deprecated(file,
  56                                   "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n");
  57         return single_open(file, batadv_algo_seq_print_text, NULL);
  58 }
  59 
  60 static int neighbors_open(struct inode *inode, struct file *file)
  61 {
  62         struct net_device *net_dev = (struct net_device *)inode->i_private;
  63 
  64         batadv_debugfs_deprecated(file,
  65                                   "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n");
  66         return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev);
  67 }
  68 
  69 static int batadv_originators_open(struct inode *inode, struct file *file)
  70 {
  71         struct net_device *net_dev = (struct net_device *)inode->i_private;
  72 
  73         batadv_debugfs_deprecated(file,
  74                                   "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n");
  75         return single_open(file, batadv_orig_seq_print_text, net_dev);
  76 }
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 static int batadv_originators_hardif_open(struct inode *inode,
  87                                           struct file *file)
  88 {
  89         struct net_device *net_dev = (struct net_device *)inode->i_private;
  90 
  91         batadv_debugfs_deprecated(file,
  92                                   "Use genl command BATADV_CMD_GET_HARDIFS instead\n");
  93         return single_open(file, batadv_orig_hardif_seq_print_text, net_dev);
  94 }
  95 
  96 static int batadv_gateways_open(struct inode *inode, struct file *file)
  97 {
  98         struct net_device *net_dev = (struct net_device *)inode->i_private;
  99 
 100         batadv_debugfs_deprecated(file,
 101                                   "Use genl command BATADV_CMD_GET_GATEWAYS instead\n");
 102         return single_open(file, batadv_gw_client_seq_print_text, net_dev);
 103 }
 104 
 105 static int batadv_transtable_global_open(struct inode *inode, struct file *file)
 106 {
 107         struct net_device *net_dev = (struct net_device *)inode->i_private;
 108 
 109         batadv_debugfs_deprecated(file,
 110                                   "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n");
 111         return single_open(file, batadv_tt_global_seq_print_text, net_dev);
 112 }
 113 
 114 #ifdef CONFIG_BATMAN_ADV_BLA
 115 static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
 116 {
 117         struct net_device *net_dev = (struct net_device *)inode->i_private;
 118 
 119         batadv_debugfs_deprecated(file,
 120                                   "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n");
 121         return single_open(file, batadv_bla_claim_table_seq_print_text,
 122                            net_dev);
 123 }
 124 
 125 static int batadv_bla_backbone_table_open(struct inode *inode,
 126                                           struct file *file)
 127 {
 128         struct net_device *net_dev = (struct net_device *)inode->i_private;
 129 
 130         batadv_debugfs_deprecated(file,
 131                                   "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n");
 132         return single_open(file, batadv_bla_backbone_table_seq_print_text,
 133                            net_dev);
 134 }
 135 
 136 #endif
 137 
 138 #ifdef CONFIG_BATMAN_ADV_DAT
 139 
 140 
 141 
 142 
 143 
 144 
 145 
 146 static int batadv_dat_cache_open(struct inode *inode, struct file *file)
 147 {
 148         struct net_device *net_dev = (struct net_device *)inode->i_private;
 149 
 150         batadv_debugfs_deprecated(file,
 151                                   "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n");
 152         return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
 153 }
 154 #endif
 155 
 156 static int batadv_transtable_local_open(struct inode *inode, struct file *file)
 157 {
 158         struct net_device *net_dev = (struct net_device *)inode->i_private;
 159 
 160         batadv_debugfs_deprecated(file,
 161                                   "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n");
 162         return single_open(file, batadv_tt_local_seq_print_text, net_dev);
 163 }
 164 
 165 struct batadv_debuginfo {
 166         struct attribute attr;
 167         const struct file_operations fops;
 168 };
 169 
 170 #ifdef CONFIG_BATMAN_ADV_NC
 171 static int batadv_nc_nodes_open(struct inode *inode, struct file *file)
 172 {
 173         struct net_device *net_dev = (struct net_device *)inode->i_private;
 174 
 175         batadv_debugfs_deprecated(file, "");
 176         return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
 177 }
 178 #endif
 179 
 180 #ifdef CONFIG_BATMAN_ADV_MCAST
 181 
 182 
 183 
 184 
 185 
 186 
 187 
 188 static int batadv_mcast_flags_open(struct inode *inode, struct file *file)
 189 {
 190         struct net_device *net_dev = (struct net_device *)inode->i_private;
 191 
 192         batadv_debugfs_deprecated(file,
 193                                   "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n");
 194         return single_open(file, batadv_mcast_flags_seq_print_text, net_dev);
 195 }
 196 #endif
 197 
 198 #define BATADV_DEBUGINFO(_name, _mode, _open)           \
 199 struct batadv_debuginfo batadv_debuginfo_##_name = {    \
 200         .attr = {                                       \
 201                 .name = __stringify(_name),             \
 202                 .mode = _mode,                          \
 203         },                                              \
 204         .fops = {                                       \
 205                 .owner = THIS_MODULE,                   \
 206                 .open = _open,                          \
 207                 .read   = seq_read,                     \
 208                 .llseek = seq_lseek,                    \
 209                 .release = single_release,              \
 210         },                                              \
 211 }
 212 
 213 
 214 
 215 
 216 static BATADV_DEBUGINFO(routing_algos, 0444, batadv_algorithms_open);
 217 
 218 static struct batadv_debuginfo *batadv_general_debuginfos[] = {
 219         &batadv_debuginfo_routing_algos,
 220         NULL,
 221 };
 222 
 223 
 224 static BATADV_DEBUGINFO(neighbors, 0444, neighbors_open);
 225 static BATADV_DEBUGINFO(originators, 0444, batadv_originators_open);
 226 static BATADV_DEBUGINFO(gateways, 0444, batadv_gateways_open);
 227 static BATADV_DEBUGINFO(transtable_global, 0444, batadv_transtable_global_open);
 228 #ifdef CONFIG_BATMAN_ADV_BLA
 229 static BATADV_DEBUGINFO(bla_claim_table, 0444, batadv_bla_claim_table_open);
 230 static BATADV_DEBUGINFO(bla_backbone_table, 0444,
 231                         batadv_bla_backbone_table_open);
 232 #endif
 233 #ifdef CONFIG_BATMAN_ADV_DAT
 234 static BATADV_DEBUGINFO(dat_cache, 0444, batadv_dat_cache_open);
 235 #endif
 236 static BATADV_DEBUGINFO(transtable_local, 0444, batadv_transtable_local_open);
 237 #ifdef CONFIG_BATMAN_ADV_NC
 238 static BATADV_DEBUGINFO(nc_nodes, 0444, batadv_nc_nodes_open);
 239 #endif
 240 #ifdef CONFIG_BATMAN_ADV_MCAST
 241 static BATADV_DEBUGINFO(mcast_flags, 0444, batadv_mcast_flags_open);
 242 #endif
 243 
 244 static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
 245         &batadv_debuginfo_neighbors,
 246         &batadv_debuginfo_originators,
 247         &batadv_debuginfo_gateways,
 248         &batadv_debuginfo_transtable_global,
 249 #ifdef CONFIG_BATMAN_ADV_BLA
 250         &batadv_debuginfo_bla_claim_table,
 251         &batadv_debuginfo_bla_backbone_table,
 252 #endif
 253 #ifdef CONFIG_BATMAN_ADV_DAT
 254         &batadv_debuginfo_dat_cache,
 255 #endif
 256         &batadv_debuginfo_transtable_local,
 257 #ifdef CONFIG_BATMAN_ADV_NC
 258         &batadv_debuginfo_nc_nodes,
 259 #endif
 260 #ifdef CONFIG_BATMAN_ADV_MCAST
 261         &batadv_debuginfo_mcast_flags,
 262 #endif
 263         NULL,
 264 };
 265 
 266 #define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open)            \
 267 struct batadv_debuginfo batadv_hardif_debuginfo_##_name = {     \
 268         .attr = {                                               \
 269                 .name = __stringify(_name),                     \
 270                 .mode = _mode,                                  \
 271         },                                                      \
 272         .fops = {                                               \
 273                 .owner = THIS_MODULE,                           \
 274                 .open = _open,                                  \
 275                 .read   = seq_read,                             \
 276                 .llseek = seq_lseek,                            \
 277                 .release = single_release,                      \
 278         },                                                      \
 279 }
 280 
 281 static BATADV_HARDIF_DEBUGINFO(originators, 0444,
 282                                batadv_originators_hardif_open);
 283 
 284 static struct batadv_debuginfo *batadv_hardif_debuginfos[] = {
 285         &batadv_hardif_debuginfo_originators,
 286         NULL,
 287 };
 288 
 289 
 290 
 291 
 292 void batadv_debugfs_init(void)
 293 {
 294         struct batadv_debuginfo **bat_debug;
 295 
 296         batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
 297 
 298         for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug)
 299                 debugfs_create_file(((*bat_debug)->attr).name,
 300                                     S_IFREG | ((*bat_debug)->attr).mode,
 301                                     batadv_debugfs, NULL, &(*bat_debug)->fops);
 302 }
 303 
 304 
 305 
 306 
 307 void batadv_debugfs_destroy(void)
 308 {
 309         debugfs_remove_recursive(batadv_debugfs);
 310         batadv_debugfs = NULL;
 311 }
 312 
 313 
 314 
 315 
 316 
 317 
 318 void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
 319 {
 320         struct net *net = dev_net(hard_iface->net_dev);
 321         struct batadv_debuginfo **bat_debug;
 322 
 323         if (net != &init_net)
 324                 return;
 325 
 326         hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name,
 327                                                    batadv_debugfs);
 328 
 329         for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug)
 330                 debugfs_create_file(((*bat_debug)->attr).name,
 331                                     S_IFREG | ((*bat_debug)->attr).mode,
 332                                     hard_iface->debug_dir, hard_iface->net_dev,
 333                                     &(*bat_debug)->fops);
 334 }
 335 
 336 
 337 
 338 
 339 
 340 void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
 341 {
 342         const char *name = hard_iface->net_dev->name;
 343         struct dentry *dir;
 344 
 345         dir = hard_iface->debug_dir;
 346         if (!dir)
 347                 return;
 348 
 349         debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
 350 }
 351 
 352 
 353 
 354 
 355 
 356 
 357 void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
 358 {
 359         struct net *net = dev_net(hard_iface->net_dev);
 360 
 361         if (net != &init_net)
 362                 return;
 363 
 364         if (batadv_debugfs) {
 365                 debugfs_remove_recursive(hard_iface->debug_dir);
 366                 hard_iface->debug_dir = NULL;
 367         }
 368 }
 369 
 370 
 371 
 372 
 373 
 374 
 375 
 376 int batadv_debugfs_add_meshif(struct net_device *dev)
 377 {
 378         struct batadv_priv *bat_priv = netdev_priv(dev);
 379         struct batadv_debuginfo **bat_debug;
 380         struct net *net = dev_net(dev);
 381 
 382         if (net != &init_net)
 383                 return 0;
 384 
 385         bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
 386 
 387         batadv_socket_setup(bat_priv);
 388 
 389         if (batadv_debug_log_setup(bat_priv) < 0)
 390                 goto rem_attr;
 391 
 392         for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug)
 393                 debugfs_create_file(((*bat_debug)->attr).name,
 394                                     S_IFREG | ((*bat_debug)->attr).mode,
 395                                     bat_priv->debug_dir, dev,
 396                                     &(*bat_debug)->fops);
 397 
 398         batadv_nc_init_debugfs(bat_priv);
 399 
 400         return 0;
 401 rem_attr:
 402         debugfs_remove_recursive(bat_priv->debug_dir);
 403         bat_priv->debug_dir = NULL;
 404         return -ENOMEM;
 405 }
 406 
 407 
 408 
 409 
 410 
 411 void batadv_debugfs_rename_meshif(struct net_device *dev)
 412 {
 413         struct batadv_priv *bat_priv = netdev_priv(dev);
 414         const char *name = dev->name;
 415         struct dentry *dir;
 416 
 417         dir = bat_priv->debug_dir;
 418         if (!dir)
 419                 return;
 420 
 421         debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
 422 }
 423 
 424 
 425 
 426 
 427 
 428 void batadv_debugfs_del_meshif(struct net_device *dev)
 429 {
 430         struct batadv_priv *bat_priv = netdev_priv(dev);
 431         struct net *net = dev_net(dev);
 432 
 433         if (net != &init_net)
 434                 return;
 435 
 436         batadv_debug_log_cleanup(bat_priv);
 437 
 438         if (batadv_debugfs) {
 439                 debugfs_remove_recursive(bat_priv->debug_dir);
 440                 bat_priv->debug_dir = NULL;
 441         }
 442 }