Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

6lowpan: add debugfs support

This patch will introduce a 6lowpan entry into the debugfs if enabled.
Inside this 6lowpan directory we create a subdirectories of all 6lowpan
interfaces to offer a per interface debugfs support.

Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Alexander Aring and committed by
Marcel Holtmann
b1815fd9 00f59314

+120 -1
+3
include/net/6lowpan.h
··· 53 53 #ifndef __6LOWPAN_H__ 54 54 #define __6LOWPAN_H__ 55 55 56 + #include <linux/debugfs.h> 57 + 56 58 #include <net/ipv6.h> 57 59 #include <net/net_namespace.h> 58 60 ··· 100 98 101 99 struct lowpan_priv { 102 100 enum lowpan_lltypes lltype; 101 + struct dentry *iface_debugfs; 103 102 104 103 /* must be last */ 105 104 u8 priv[0] __aligned(sizeof(void *));
+28
net/6lowpan/6lowpan_i.h
··· 1 + #ifndef __6LOWPAN_I_H 2 + #define __6LOWPAN_I_H 3 + 4 + #include <linux/netdevice.h> 5 + 6 + #ifdef CONFIG_6LOWPAN_DEBUGFS 7 + int lowpan_dev_debugfs_init(struct net_device *dev); 8 + void lowpan_dev_debugfs_exit(struct net_device *dev); 9 + 10 + int __init lowpan_debugfs_init(void); 11 + void lowpan_debugfs_exit(void); 12 + #else 13 + static inline int lowpan_dev_debugfs_init(struct net_device *dev) 14 + { 15 + return 0; 16 + } 17 + 18 + static inline void lowpan_dev_debugfs_exit(struct net_device *dev) { } 19 + 20 + static inline int __init lowpan_debugfs_init(void) 21 + { 22 + return 0; 23 + } 24 + 25 + static inline void lowpan_debugfs_exit(void) { } 26 + #endif /* CONFIG_6LOWPAN_DEBUGFS */ 27 + 28 + #endif /* __6LOWPAN_I_H */
+8
net/6lowpan/Kconfig
··· 5 5 This enables IPv6 over Low power Wireless Personal Area Network - 6 6 "6LoWPAN" which is supported by IEEE 802.15.4 or Bluetooth stacks. 7 7 8 + config 6LOWPAN_DEBUGFS 9 + bool "6LoWPAN debugfs support" 10 + depends on 6LOWPAN 11 + depends on DEBUG_FS 12 + ---help--- 13 + This enables 6LoWPAN debugfs support. For example to manipulate 14 + IPHC context information at runtime. 15 + 8 16 menuconfig 6LOWPAN_NHC 9 17 tristate "Next Header and Generic Header Compression Support" 10 18 depends on 6LOWPAN
+1
net/6lowpan/Makefile
··· 1 1 obj-$(CONFIG_6LOWPAN) += 6lowpan.o 2 2 3 3 6lowpan-y := core.o iphc.o nhc.o 4 + 6lowpan-$(CONFIG_6LOWPAN_DEBUGFS) += debugfs.o 4 5 5 6 #rfc6282 nhcs 6 7 obj-$(CONFIG_6LOWPAN_NHC_DEST) += nhc_dest.o
+27 -1
net/6lowpan/core.c
··· 15 15 16 16 #include <net/6lowpan.h> 17 17 18 + #include "6lowpan_i.h" 19 + 18 20 int lowpan_register_netdevice(struct net_device *dev, 19 21 enum lowpan_lltypes lltype) 20 22 { 23 + int ret; 24 + 21 25 dev->addr_len = EUI64_ADDR_LEN; 22 26 dev->type = ARPHRD_6LOWPAN; 23 27 dev->mtu = IPV6_MIN_MTU; ··· 29 25 30 26 lowpan_priv(dev)->lltype = lltype; 31 27 32 - return register_netdevice(dev); 28 + ret = lowpan_dev_debugfs_init(dev); 29 + if (ret < 0) 30 + return ret; 31 + 32 + ret = register_netdevice(dev); 33 + if (ret < 0) 34 + lowpan_dev_debugfs_exit(dev); 35 + 36 + return ret; 33 37 } 34 38 EXPORT_SYMBOL(lowpan_register_netdevice); 35 39 ··· 56 44 void lowpan_unregister_netdevice(struct net_device *dev) 57 45 { 58 46 unregister_netdevice(dev); 47 + lowpan_dev_debugfs_exit(dev); 59 48 } 60 49 EXPORT_SYMBOL(lowpan_unregister_netdevice); 61 50 ··· 70 57 71 58 static int __init lowpan_module_init(void) 72 59 { 60 + int ret; 61 + 62 + ret = lowpan_debugfs_init(); 63 + if (ret < 0) 64 + return ret; 65 + 73 66 request_module_nowait("ipv6"); 74 67 75 68 request_module_nowait("nhc_dest"); ··· 88 69 89 70 return 0; 90 71 } 72 + 73 + static void __exit lowpan_module_exit(void) 74 + { 75 + lowpan_debugfs_exit(); 76 + } 77 + 91 78 module_init(lowpan_module_init); 79 + module_exit(lowpan_module_exit); 92 80 93 81 MODULE_LICENSE("GPL");
+53
net/6lowpan/debugfs.c
··· 1 + /* This program is free software; you can redistribute it and/or modify 2 + * it under the terms of the GNU General Public License version 2 3 + * as published by the Free Software Foundation. 4 + * 5 + * This program is distributed in the hope that it will be useful, 6 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8 + * GNU General Public License for more details. 9 + * 10 + * Authors: 11 + * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de> 12 + * Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. 13 + */ 14 + 15 + #include <net/6lowpan.h> 16 + 17 + #include "6lowpan_i.h" 18 + 19 + static struct dentry *lowpan_debugfs; 20 + 21 + int lowpan_dev_debugfs_init(struct net_device *dev) 22 + { 23 + struct lowpan_priv *lpriv = lowpan_priv(dev); 24 + 25 + /* creating the root */ 26 + lpriv->iface_debugfs = debugfs_create_dir(dev->name, lowpan_debugfs); 27 + if (!lpriv->iface_debugfs) 28 + goto fail; 29 + 30 + return 0; 31 + 32 + fail: 33 + return -EINVAL; 34 + } 35 + 36 + void lowpan_dev_debugfs_exit(struct net_device *dev) 37 + { 38 + debugfs_remove_recursive(lowpan_priv(dev)->iface_debugfs); 39 + } 40 + 41 + int __init lowpan_debugfs_init(void) 42 + { 43 + lowpan_debugfs = debugfs_create_dir("6lowpan", NULL); 44 + if (!lowpan_debugfs) 45 + return -EINVAL; 46 + 47 + return 0; 48 + } 49 + 50 + void lowpan_debugfs_exit(void) 51 + { 52 + debugfs_remove_recursive(lowpan_debugfs); 53 + }