6lowpan: introduce generic 6lowpan private data
Subsystems (6)
Alexander Aring
maintainercover 6lowpan: introduce generic 6lowpan private data
Hi,
I already thought many times to introduce something like that. Here is a draft for introducing the generic 6lowpan private data into each lowpan interface. For the beginning I introduced the enum "lltype" which contains the LL type of a lowpan interface.
Use cases for such feature (LL types):
- If we do in upper layers (6LoWPAN/IPv6) a evaluation of dev->type then the value is on all lowpan interfaces "APRHRD_6LOWPAN". If we checked on "dev->type" and it's ARPHRD_6LOWPAN we can safe use lowpan_priv to get 6LoWPAN generic private data. With this data we can check the LL type which can be currently BTLE or IEEE802154. This could be useful to make different handling in iphc compress/decompress and evaluating LL private data of skb control block "skb->cb".
Example (802.15.4 has different address handling functionality):
switch (lowpan_priv(dev)->lltype) {
case LOWPAN_LLTYPE_BTLE:
/* do EUI64 btle handling */
break;
case LOWPAN_LLTYPE_IEEE802154:
/* do complicated short/extended address handling */
/* we can surely call skb->cb to some other private data from LL
which was set before iphc compress/decompress function call */
break;}
The handling is currently for 802.15.4 is in generic 6lowpan code currently not quite. This should be handled by private data. At the moment btle use the same handling like for 802.15.4 extended address. Nevertheless is we can cleanup some handling then in generic iphc functionality.
This also possible in layers like IPv6, just doing a check on APRHRD_6LOWPAN before calling lowpan_priv(dev)->lltype, then we are sure that the private data of the interface is a 6LoWPAN interface and we can cast it to lowpan_priv. Then we can do 6LoWPAN generic stuff OR 6lowpan specific LL stuff.
- In Lukasz Duda RFC for introducing stateful address compression, I saw some behaviour which such functionality is also useful. Currently we don't have a allocated space for a 6LoWPAN generic space which is assigned to a lowpan interface. When LL layers (BTLE, IEEE802154) calls iphc compress/decompress Lukasz had no change to access some room which is needed for storing the context information into a table. The workaround for this feature was to add allocate a static data room for the table and doing a lookup/match of netdev name. Which a generic 6lowpan private data room per each lowpan interface we can put this table according to the netdev private room, which means in short: no lookup is needed anymore, just dereferencing lowpan_priv.
In upper layer like IPv6 Lukasz could use that to get the stateful context table information as an example for doing 6LoWPAN generic stuff in upper layers.
Note about the implementation for LL 6LoWPAN private pointer:
I stole some mechanism from wireless for that. See [0], the vif struct is part of sdata which is also part of private data of a wireless interface (mac80211). I hope I can just adapt this behaviour.
- Alex
[0] http://lxr.free-electrons.com/source/include/net/mac80211.h#L1366
changes since PATCH (was RFC before):
- rename ll_type,ll_foo to lltype, llfoo
- add documentation for generic 6lowpan interfaces API
- add net/6lowpan/core.c for core functionality, like setup or cleanup lowpan netdev interfaces, which is necessary e.g. heap allocation/free
- add LOWPAN_PRIV_SIZE for provide API functionality to calculate private data
- rebase to current bluetooth-next/master
- add documentation in cc for the Documentation branch
changes since v2:
- rename L2/l2 to LL/ll. I think the usually word in ietf for L2 is LL which means "link layer". Also ipv6 stack use ll for variables like lladdr -> link layer address.
- rebase to current bluetooth-next/master
- remove some brackets in function lowpan_priv.
Alexander Aring (4):
Bluetooth: 6lowpan: change netdev_priv to lowpan_dev 6lowpan: add generic 6lowpan netdev private data 6lowpan: move module_init into core functionality
documentation: networking: add 6lowpan documentation
Documentation/networking/6lowpan.txt | 51 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + include/net/6lowpan.h | 23 ++++++++++++++++ net/6lowpan/Makefile | 2 +- net/6lowpan/core.c | 40 ++++++++++++++++++++++++++++ net/6lowpan/iphc.c | 19 -------------- net/bluetooth/6lowpan.c | 11 +++++--- net/ieee802154/6lowpan/6lowpan_i.h | 3 ++- net/ieee802154/6lowpan/core.c | 4 ++- 9 files changed, 128 insertions(+), 26 deletions(-) create mode 100644 Documentation/networking/6lowpan.txt create mode 100644 net/6lowpan/core.c
Signature · 1 line
2.5.0
Alexander Aring
maintainerPATCH 1/4 Bluetooth: 6lowpan: change netdev_priv to lowpan_dev
The usually way to get the btle lowpan private data is to use the introduced lowpan_dev inline function. This patch will cleanup by using lowpan_dev consequently.
--- net/bluetooth/6lowpan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bluetooth/6lowpan.c +1 -1
@@ -859,7 +859,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)SET_NETDEV_DEV (netdev, &chan->conn->hcon->hdev->dev);SET_NETDEV_DEVTYPE (netdev, &bt_type); - *dev =netdev_priv (netdev); + *dev =lowpan_dev (netdev); (*dev)->netdev = netdev; (*dev)->hdev = chan->conn->hcon->hdev;INIT_LIST_HEAD (&(*dev)->peers);
Signature · 1 line
2.5.0
Alexander Aring
maintainerPATCH 2/4 6lowpan: add generic 6lowpan netdev private data
In reply to Alexander AringThis patch introduced the 6lowpan netdev private data struct. We name it lowpan_priv and it's placed at the beginning of netdev private data. All lowpan interfaces should allocate this room at first of netdev private data. 6LoWPAN LL private data can be allocate by additional netdev private data, e.g. dev->priv_size should be "sizeof(struct lowpan_priv) + sizeof(LL_LOWPAN_PRIVATE_DATA)".
--- include/net/6lowpan.h | 23 +++++++++++++++++++++++ net/6lowpan/Makefile | 2 +- net/6lowpan/core.c | 20 ++++++++++++++++++++ net/bluetooth/6lowpan.c | 9 ++++++--- net/ieee802154/6lowpan/6lowpan_i.h | 3 ++- net/ieee802154/6lowpan/core.c | 4 +++- 6 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 net/6lowpan/core.c
include/net/6lowpan.h +23 -0
@@ -197,6 +197,27 @@#define LOWPAN_NHC_UDP_CS_P_11 0xF3/* source & dest = 0xF0B + 4bit inline */ #define LOWPAN_NHC_UDP_CS_C 0x04/* checksum elided */ +#define LOWPAN_PRIV_SIZE (llpriv_size) \ + (sizeof(struct lowpan_priv) + llpriv_size) + +enum lowpan_lltypes { +LOWPAN_LLTYPE_BTLE , +LOWPAN_LLTYPE_IEEE802154 , +}; + +struct lowpan_priv { +enum lowpan_lltypes lltype; + +/* must be last */ +u8 priv[0 ]__aligned(sizeof(void *)) ; +}; + +static inline +struct lowpan_priv *lowpan_priv (const struct net_device *dev) +{ +return netdev_priv (dev); +} +#ifdef DEBUG /* print data in line */ static inline void raw_dump_inline(const char *caller, char *msg,
@@ -372,6 +393,8 @@ lowpan_uncompress_size(const struct sk_buff *skb, u16 *dgram_offset)return skb->len + uncomp_header - ret; } +void lowpan_netdev_setup (struct net_device *dev,enum lowpan_lltypes lltype); + int lowpan_header_decompress(struct sk_buff *skb, struct net_device *dev, const u8 *saddr, const u8 saddr_type,
net/6lowpan/Makefile +1 -1
@@ -1,6 +1,6 @@ obj-$(CONFIG_6LOWPAN) += 6lowpan.o -6lowpan-y := iphc.o nhc.o +6lowpan-y := core.o iphc.o nhc.o #rfc6282 nhcs obj-$(CONFIG_6LOWPAN_NHC_DEST) += nhc_dest.o
net/6lowpan/core.c new file +20 -0
@@ -0,0 +1,20 @@ +/* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* Authors: +* (C) 2015 Pengutronix, Alexander Aring <[email protected]> +*/ + +#include <net/6lowpan.h> + +void lowpan_netdev_setup (struct net_device *dev,enum lowpan_lltypes lltype) +{ +lowpan_priv (dev)->lltype = lltype; +} +EXPORT_SYMBOL (lowpan_netdev_setup);
net/bluetooth/6lowpan.c +6 -3
@@ -85,7 +85,7 @@ struct lowpan_dev {static inline struct lowpan_dev *lowpan_dev (const struct net_device *netdev) { -return netdev_priv (netdev); +return (struct lowpan_dev *)lowpan_priv (netdev)->priv; }static inline void peer_add (struct lowpan_dev *dev,struct lowpan_peer *peer)
@@ -848,8 +848,9 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)struct net_device *netdev;int err =0 ; - netdev =alloc_netdev (sizeof (struct lowpan_dev ),IFACE_NAME_TEMPLATE , -NET_NAME_UNKNOWN , netdev_setup); + netdev =alloc_netdev (LOWPAN_PRIV_SIZE (sizeof (struct lowpan_dev )), +IFACE_NAME_TEMPLATE ,NET_NAME_UNKNOWN , + netdev_setup);if (!netdev)return -ENOMEM ;
@@ -869,6 +870,8 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)list_add_rcu (&(*dev)->list, &bt_6lowpan_devices);spin_unlock (&devices_lock); +lowpan_netdev_setup (netdev,LOWPAN_LLTYPE_BTLE ); + err =register_netdev (netdev);if (err <0 ) {BT_INFO ("register_netdev failed %d" , err);
net/ieee802154/6lowpan/6lowpan_i.h +2 -1
@@ -5,6 +5,7 @@#include <net/ieee802154_netdev.h> #include <net/inet_frag.h> +#include <net/6lowpan.h> struct lowpan_create_arg {u16 tag;
@@ -46,7 +47,7 @@ struct lowpan_dev_info {static inline struct lowpan_dev_info *lowpan_dev_info (const struct net_device *dev) { -return netdev_priv (dev); +return (struct lowpan_dev_info *)lowpan_priv (dev)->priv; }int lowpan_frag_rcv (struct sk_buff *skb,const u8 frag_type);
net/ieee802154/6lowpan/core.c +3 -1
@@ -138,6 +138,8 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,/* Set the lowpan hardware address to the wpan hardware address. */ memcpy (dev->dev_addr, real_dev->dev_addr,IEEE802154_ADDR_LEN ); +lowpan_netdev_setup (dev,LOWPAN_LLTYPE_IEEE802154 ); + ret =register_netdevice (dev);if (ret >=0 ) { real_dev->ieee802154_ptr->lowpan_dev = dev;
@@ -162,7 +164,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)static struct rtnl_link_ops lowpan_link_ops__read_mostly = { .kind ="lowpan" , - .priv_size =sizeof (struct lowpan_dev_info ), + .priv_size =LOWPAN_PRIV_SIZE (sizeof (struct lowpan_dev_info )), .setup = lowpan_setup, .newlink = lowpan_newlink, .dellink = lowpan_dellink,
Signature · 1 line
2.5.0
Alexander Aring
maintainerPATCH 3/4 6lowpan: move module_init into core functionality
In reply to Alexander AringThis patch moves module_init of 6lowpan module into core functionality of 6lowpan module. To load the ipv6 module at probing of the 6lowpan module should be core functionality. Loading next header compression modules is iphc specific. Nevertheless we only support IPHC for the generic 6LoWPAN branch right now so we can put it into the core functionality. If possible new compression formats are introduced nhc should load only when iphc is build.
--- net/6lowpan/core.c | 20 ++++++++++++++++++++ net/6lowpan/iphc.c | 19 ------------------- 2 files changed, 20 insertions(+), 19 deletions(-)
net/6lowpan/core.c +20 -0
@@ -11,6 +11,8 @@* (C) 2015 Pengutronix, Alexander Aring <[email protected]> */ +#include <linux/module.h> +#include <net/6lowpan.h> void lowpan_netdev_setup (struct net_device *dev,enum lowpan_lltypes lltype)
@@ -18,3 +20,21 @@ void lowpan_netdev_setup(struct net_device *dev, enum lowpan_lltypes lltype)lowpan_priv (dev)->lltype = lltype; }EXPORT_SYMBOL (lowpan_netdev_setup); + +static int __init lowpan_module_init (void ) +{ +request_module_nowait ("ipv6" ); + +request_module_nowait ("nhc_dest" ); +request_module_nowait ("nhc_fragment" ); +request_module_nowait ("nhc_hop" ); +request_module_nowait ("nhc_ipv6" ); +request_module_nowait ("nhc_mobility" ); +request_module_nowait ("nhc_routing" ); +request_module_nowait ("nhc_udp" ); + +return 0 ; +} +module_init (lowpan_module_init); + +MODULE_LICENSE ("GPL" );
net/6lowpan/iphc.c +0 -19
@@ -48,7 +48,6 @@#include <linux/bitops.h> #include <linux/if_arp.h> -#include <linux/module.h> #include <linux/netdevice.h> #include <net/6lowpan.h> #include <net/ipv6.h>
@@ -610,21 +609,3 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,return 0 ; }EXPORT_SYMBOL_GPL (lowpan_header_compress); - -static int __init lowpan_module_init (void ) -{ -request_module_nowait ("ipv6" ); - -request_module_nowait ("nhc_dest" ); -request_module_nowait ("nhc_fragment" ); -request_module_nowait ("nhc_hop" ); -request_module_nowait ("nhc_ipv6" ); -request_module_nowait ("nhc_mobility" ); -request_module_nowait ("nhc_routing" ); -request_module_nowait ("nhc_udp" ); - -return 0 ; -} -module_init (lowpan_module_init); - -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.5.0
Alexander Aring
maintainerPATCH 4/4 documentation: networking: add 6lowpan documentation
In reply to Alexander AringThis patch adds a 6lowpan.txt into the networking documentation directory. Currently this documentation describes how the lowpan private data of net devices will be handled.
--- Documentation/networking/6lowpan.txt | 51 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 52 insertions(+) create mode 100644 Documentation/networking/6lowpan.txt
Documentation/networking/6lowpan.txt new file +51 -0
@@ -0,0 +1,51 @@ + +Netdev private dataroom for 6lowpan interfaces: + +All 6lowpan able net devices, means all interfaces with ARPHRD_6LOWPAN, +must have "struct lowpan_priv" placed at beginning of netdev_priv. + +The priv_size of each interface should be calculate by: + + dev->priv_size = LOWPAN_PRIV_SIZE(LL_6LOWPAN_PRIV_DATA); + +Where LL_PRIV_6LOWPAN_DATA is sizeof linklayer 6lowpan private data struct. +To access the LL_PRIV_6LOWPAN_DATA structure you can cast: + + lowpan_priv(dev)-priv; + +to your LL_6LOWPAN_PRIV_DATA structure. + +Before registering the lowpan netdev interface you must run: + + lowpan_netdev_setup(dev, LOWPAN_LLTYPE_FOOBAR); + +wheres LOWPAN_LLTYPE_FOOBAR is a define for your 6LoWPAN linklayer type of +enum lowpan_lltypes. + +Example to evaluate the private usually you can do: + +static inline sturct lowpan_priv_foobar * +lowpan_foobar_priv(struct net_device *dev) +{ + return (sturct lowpan_priv_foobar *)lowpan_priv(dev)->priv; +} + +switch (dev->type) { +case ARPHRD_6LOWPAN: + lowpan_priv = lowpan_priv(dev); + /* do great stuff which is ARPHRD_6LOWPAN related */ + switch (lowpan_priv->lltype) { + case LOWPAN_LLTYPE_FOOBAR: + /* do 802.15.4 6LoWPAN handling here */ + lowpan_foobar_priv(dev)->bar = foo; + break; + ... + } + break; +... +} + +In case of generic 6lowpan branch ("net/6lowpan") you can remove the check +on ARPHRD_6LOWPAN, because you can be sure that these function are called +by ARPHRD_6LOWPAN interfaces. +
MAINTAINERS +1 -0
@@ -158,6 +158,7 @@ L: [email protected] S: Maintained F: net/6lowpan/ F: include/net/6lowpan.h +F: Documentation/networking/6lowpan.txt 6PACK NETWORK DRIVER FOR AX.25 M: Andreas Koensgen <[email protected]>
Signature · 1 line
2.5.0
Marcel Holtmann
maintainerHi Alex,
Quoted 100 lines
I already thought many times to introduce something like that. Here is a draft for introducing the generic 6lowpan private data into each lowpan interface. For the beginning I introduced the enum "lltype" which contains the LL type of a lowpan interface.
Use cases for such feature (LL types):
- If we do in upper layers (6LoWPAN/IPv6) a evaluation of
dev->typethen the value is on all lowpan interfaces "APRHRD_6LOWPAN". If we checked on "dev->type" and it'sARPHRD_6LOWPANwe can safe uselowpan_privto get 6LoWPAN generic private data. With this data we can check the LL type which can be currently BTLE or IEEE802154. This could be useful to make different handling in iphc compress/decompress and evaluating LL private data of skb control block "skb->cb".Example (802.15.4 has different address handling functionality):
switch (lowpan_priv(dev)->lltype) {
caseLOWPAN_LLTYPE_BTLE:/* do EUI64 btle handling */ break; case LOWPAN_LLTYPE_IEEE802154: /* do complicated short/extended address handling */ /* we can surely call skb->cb to some other private data from LL which was set before iphc compress/decompress function call */ break;}
The handling is currently for 802.15.4 is in generic 6lowpan code currently not quite. This should be handled by private data. At the moment btle use the same handling like for 802.15.4 extended address. Nevertheless is we can cleanup some handling then in generic iphc functionality.
This also possible in layers like IPv6, just doing a check on
APRHRD_6LOWPANbefore calling lowpan_priv(dev)->lltype, then we are sure that the private data of the interface is a 6LoWPAN interface and we can cast it tolowpan_priv. Then we can do 6LoWPAN generic stuff OR 6lowpan specific LL stuff.- In Lukasz Duda RFC for introducing stateful address compression, I saw some behaviour which such functionality is also useful. Currently we don't have a allocated space for a 6LoWPAN generic space which is assigned to a lowpan interface. When LL layers (BTLE, IEEE802154) calls iphc compress/decompress Lukasz had no change to access some room which is needed for storing the context information into a table. The workaround for this feature was to add allocate a static data room for the table and doing a lookup/match of netdev name. Which a generic 6lowpan private data room per each lowpan interface we can put this table according to the netdev private room, which means in short: no lookup is needed anymore, just dereferencing
lowpan_priv.In upper layer like IPv6 Lukasz could use that to get the stateful context table information as an example for doing 6LoWPAN generic stuff in upper layers.
Note about the implementation for LL 6LoWPAN private pointer:
I stole some mechanism from wireless for that. See [0], the vif struct is part of sdata which is also part of private data of a wireless interface (mac80211). I hope I can just adapt this behaviour.
- Alex
Cc Jonathan Corbet <[email protected]>[0] http://lxr.free-electrons.com/source/include/net/mac80211.h#L1366
changes since PATCH (was RFC before):
- rename ll_type,ll_foo to lltype, llfoo
- add documentation for generic 6lowpan interfaces API
- addnet/6lowpan/core.cfor core functionality, like setup or cleanup lowpan netdev interfaces, which is necessary e.g. heap allocation/free
- addLOWPAN_PRIV_SIZEfor provide API functionality to calculate private data
- rebase to current bluetooth-next/master
- add documentation in cc for the Documentation branchchanges since v2:
- rename L2/l2 to LL/ll. I think the usually word in ietf for L2 is LL which means "link layer". Also ipv6 stack use ll for variables like lladdr -> link layer address.
- rebase to current bluetooth-next/master
- remove some brackets in functionlowpan_priv.Alexander Aring (4):
Bluetooth: 6lowpan: changenetdev_privtolowpan_dev6lowpan: add generic 6lowpan netdev private data 6lowpan: movemodule_initinto core functionality
documentation: networking: add 6lowpan documentationDocumentation/networking/6lowpan.txt | 51 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + include/net/6lowpan.h | 23 ++++++++++++++++ net/6lowpan/Makefile | 2 +- net/6lowpan/core.c | 40 ++++++++++++++++++++++++++++ net/6lowpan/iphc.c | 19 -------------- net/bluetooth/6lowpan.c | 11 +++++--- net/ieee802154/6lowpan/6lowpan_i.h | 3 ++- net/ieee802154/6lowpan/core.c | 4 ++- 9 files changed, 128 insertions(+), 26 deletions(-)
Quoted 2 lines
create mode 100644
Documentation/networking/6lowpan.txtcreate mode 100644net/6lowpan/core.c
I went ahead and applied all 4 patches to bluetooth-next tree. That way they get exposure.
Regards
Marcel