Skip to content

Commit

Permalink
ieee802154: 6lowpan: change dev vars to wdev and ldev
Browse files Browse the repository at this point in the history
Inside the IEEE 802.15.4 6LoWPAN subsystem we use two interfaces which
are wpan and lowpan interfaces. Instead of using always the variable
name "dev" for both we rename the "dev" variable to wdev which means the
wpan net_device and ldev which means a lowpan net_device. This avoids
confusing and always looking back to see which net_device is meant by
the variable name "dev".

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>
  • Loading branch information
Alexander Aring authored and Marcel Holtmann committed Sep 17, 2015
1 parent 517a546 commit f460658
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 84 deletions.
2 changes: 1 addition & 1 deletion net/ieee802154/6lowpan/6lowpan_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a)

/* private device info */
struct lowpan_dev_info {
struct net_device *real_dev; /* real WPAN device ptr */
struct net_device *wdev; /* wpan device ptr */
u16 fragment_tag;
};

Expand Down
89 changes: 44 additions & 45 deletions net/ieee802154/6lowpan/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ static struct header_ops lowpan_header_ops = {
static struct lock_class_key lowpan_tx_busylock;
static struct lock_class_key lowpan_netdev_xmit_lock_key;

static void lowpan_set_lockdep_class_one(struct net_device *dev,
static void lowpan_set_lockdep_class_one(struct net_device *ldev,
struct netdev_queue *txq,
void *_unused)
{
lockdep_set_class(&txq->_xmit_lock,
&lowpan_netdev_xmit_lock_key);
}

static int lowpan_dev_init(struct net_device *dev)
static int lowpan_dev_init(struct net_device *ldev)
{
netdev_for_each_tx_queue(dev, lowpan_set_lockdep_class_one, NULL);
dev->qdisc_tx_busylock = &lowpan_tx_busylock;
netdev_for_each_tx_queue(ldev, lowpan_set_lockdep_class_one, NULL);
ldev->qdisc_tx_busylock = &lowpan_tx_busylock;
return 0;
}

Expand All @@ -81,23 +81,23 @@ static const struct net_device_ops lowpan_netdev_ops = {
.ndo_start_xmit = lowpan_xmit,
};

static void lowpan_setup(struct net_device *dev)
static void lowpan_setup(struct net_device *ldev)
{
dev->addr_len = IEEE802154_ADDR_LEN;
memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
dev->type = ARPHRD_6LOWPAN;
ldev->addr_len = IEEE802154_ADDR_LEN;
memset(ldev->broadcast, 0xff, IEEE802154_ADDR_LEN);
ldev->type = ARPHRD_6LOWPAN;
/* Frame Control + Sequence Number + Address fields + Security Header */
dev->hard_header_len = 2 + 1 + 20 + 14;
dev->needed_tailroom = 2; /* FCS */
dev->mtu = IPV6_MIN_MTU;
dev->priv_flags |= IFF_NO_QUEUE;
dev->flags = IFF_BROADCAST | IFF_MULTICAST;
dev->watchdog_timeo = 0;

dev->netdev_ops = &lowpan_netdev_ops;
dev->header_ops = &lowpan_header_ops;
dev->destructor = free_netdev;
dev->features |= NETIF_F_NETNS_LOCAL;
ldev->hard_header_len = 2 + 1 + 20 + 14;
ldev->needed_tailroom = 2; /* FCS */
ldev->mtu = IPV6_MIN_MTU;
ldev->priv_flags |= IFF_NO_QUEUE;
ldev->flags = IFF_BROADCAST | IFF_MULTICAST;
ldev->watchdog_timeo = 0;

ldev->netdev_ops = &lowpan_netdev_ops;
ldev->header_ops = &lowpan_header_ops;
ldev->destructor = free_netdev;
ldev->features |= NETIF_F_NETNS_LOCAL;
}

static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
Expand All @@ -109,46 +109,46 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
return 0;
}

static int lowpan_newlink(struct net *src_net, struct net_device *dev,
static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
struct nlattr *tb[], struct nlattr *data[])
{
struct net_device *real_dev;
struct net_device *wdev;
int ret;

ASSERT_RTNL();

pr_debug("adding new link\n");

if (!tb[IFLA_LINK] ||
!net_eq(dev_net(dev), &init_net))
!net_eq(dev_net(ldev), &init_net))
return -EINVAL;
/* find and hold real wpan device */
real_dev = dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK]));
if (!real_dev)
/* find and hold wpan device */
wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
if (!wdev)
return -ENODEV;
if (real_dev->type != ARPHRD_IEEE802154) {
dev_put(real_dev);
if (wdev->type != ARPHRD_IEEE802154) {
dev_put(wdev);
return -EINVAL;
}

if (real_dev->ieee802154_ptr->lowpan_dev) {
dev_put(real_dev);
if (wdev->ieee802154_ptr->lowpan_dev) {
dev_put(wdev);
return -EBUSY;
}

lowpan_dev_info(dev)->real_dev = real_dev;
lowpan_dev_info(ldev)->wdev = wdev;
/* Set the lowpan hardware address to the wpan hardware address. */
memcpy(dev->dev_addr, real_dev->dev_addr, IEEE802154_ADDR_LEN);
memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN);

lowpan_netdev_setup(dev, LOWPAN_LLTYPE_IEEE802154);
lowpan_netdev_setup(ldev, LOWPAN_LLTYPE_IEEE802154);

ret = register_netdevice(dev);
ret = register_netdevice(ldev);
if (ret < 0) {
dev_put(real_dev);
dev_put(wdev);
return ret;
}

real_dev->ieee802154_ptr->lowpan_dev = dev;
wdev->ieee802154_ptr->lowpan_dev = ldev;
if (!open_count)
lowpan_rx_init();

Expand All @@ -157,10 +157,9 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
return 0;
}

static void lowpan_dellink(struct net_device *dev, struct list_head *head)
static void lowpan_dellink(struct net_device *ldev, struct list_head *head)
{
struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
struct net_device *real_dev = lowpan_dev->real_dev;
struct net_device *wdev = lowpan_dev_info(ldev)->wdev;

ASSERT_RTNL();

Expand All @@ -169,9 +168,9 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
if (!open_count)
lowpan_rx_exit();

real_dev->ieee802154_ptr->lowpan_dev = NULL;
unregister_netdevice(dev);
dev_put(real_dev);
wdev->ieee802154_ptr->lowpan_dev = NULL;
unregister_netdevice(ldev);
dev_put(wdev);
}

static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
Expand All @@ -196,9 +195,9 @@ static inline void lowpan_netlink_fini(void)
static int lowpan_device_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct net_device *wdev = netdev_notifier_info_to_dev(ptr);

if (dev->type != ARPHRD_IEEE802154)
if (wdev->type != ARPHRD_IEEE802154)
goto out;

switch (event) {
Expand All @@ -207,8 +206,8 @@ static int lowpan_device_event(struct notifier_block *unused,
* also delete possible lowpan interfaces which belongs
* to the wpan interface.
*/
if (dev->ieee802154_ptr && dev->ieee802154_ptr->lowpan_dev)
lowpan_dellink(dev->ieee802154_ptr->lowpan_dev, NULL);
if (wdev->ieee802154_ptr && wdev->ieee802154_ptr->lowpan_dev)
lowpan_dellink(wdev->ieee802154_ptr->lowpan_dev, NULL);
break;
default:
break;
Expand Down
14 changes: 7 additions & 7 deletions net/ieee802154/6lowpan/reassembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static struct lowpan_frag_info *lowpan_cb(struct sk_buff *skb)
static struct inet_frags lowpan_frags;

static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
struct sk_buff *prev, struct net_device *dev);
struct sk_buff *prev, struct net_device *ldev);

static unsigned int lowpan_hash_frag(u16 tag, u16 d_size,
const struct ieee802154_addr *saddr,
Expand Down Expand Up @@ -141,7 +141,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
struct sk_buff *skb, const u8 frag_type)
{
struct sk_buff *prev, *next;
struct net_device *dev;
struct net_device *ldev;
int end, offset;

if (fq->q.flags & INET_FRAG_COMPLETE)
Expand Down Expand Up @@ -195,8 +195,8 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
else
fq->q.fragments = skb;

dev = skb->dev;
if (dev)
ldev = skb->dev;
if (ldev)
skb->dev = NULL;

fq->q.stamp = skb->tstamp;
Expand All @@ -215,7 +215,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
unsigned long orefdst = skb->_skb_refdst;

skb->_skb_refdst = 0UL;
res = lowpan_frag_reasm(fq, prev, dev);
res = lowpan_frag_reasm(fq, prev, ldev);
skb->_skb_refdst = orefdst;
return res;
}
Expand All @@ -235,7 +235,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
* the last and the first frames arrived and all the bits are here.
*/
static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
struct net_device *dev)
struct net_device *ldev)
{
struct sk_buff *fp, *head = fq->q.fragments;
int sum_truesize;
Expand Down Expand Up @@ -313,7 +313,7 @@ static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
sub_frag_mem_limit(fq->q.net, sum_truesize);

head->next = NULL;
head->dev = dev;
head->dev = ldev;
head->tstamp = fq->q.stamp;

fq->q.fragments = NULL;
Expand Down
22 changes: 11 additions & 11 deletions net/ieee802154/6lowpan/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "6lowpan_i.h"

static int lowpan_give_skb_to_device(struct sk_buff *skb,
struct net_device *dev)
struct net_device *wdev)
{
skb->dev = dev->ieee802154_ptr->lowpan_dev;
skb->dev = wdev->ieee802154_ptr->lowpan_dev;
skb->protocol = htons(ETH_P_IPV6);
skb->pkt_type = PACKET_HOST;

Expand Down Expand Up @@ -61,21 +61,21 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
IEEE802154_ADDR_LEN, iphc0, iphc1);
}

static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
struct packet_type *pt, struct net_device *orig_wdev)
{
struct ieee802154_hdr hdr;
int ret;

if (dev->type != ARPHRD_IEEE802154 ||
!dev->ieee802154_ptr->lowpan_dev)
if (wdev->type != ARPHRD_IEEE802154 ||
!wdev->ieee802154_ptr->lowpan_dev)
goto drop;

skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
goto drop;

if (!netif_running(dev))
if (!netif_running(wdev))
goto drop_skb;

if (skb->pkt_type == PACKET_OTHERHOST)
Expand All @@ -88,23 +88,23 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
/* Pull off the 1-byte of 6lowpan header. */
skb_pull(skb, 1);
return lowpan_give_skb_to_device(skb, dev);
return lowpan_give_skb_to_device(skb, wdev);
} else {
switch (skb->data[0] & 0xe0) {
case LOWPAN_DISPATCH_IPHC: /* ipv6 datagram */
ret = iphc_decompress(skb, &hdr);
if (ret < 0)
goto drop_skb;

return lowpan_give_skb_to_device(skb, dev);
return lowpan_give_skb_to_device(skb, wdev);
case LOWPAN_DISPATCH_FRAG1: /* first fragment header */
ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
if (ret == 1) {
ret = iphc_decompress(skb, &hdr);
if (ret < 0)
goto drop_skb;

return lowpan_give_skb_to_device(skb, dev);
return lowpan_give_skb_to_device(skb, wdev);
} else if (ret == -1) {
return NET_RX_DROP;
} else {
Expand All @@ -117,7 +117,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
if (ret < 0)
goto drop_skb;

return lowpan_give_skb_to_device(skb, dev);
return lowpan_give_skb_to_device(skb, wdev);
} else if (ret == -1) {
return NET_RX_DROP;
} else {
Expand Down
Loading

0 comments on commit f460658

Please sign in to comment.