hdlc.c (ebf8889bd1fe3615991ff4494635d237280652a2) hdlc.c (40d25142f2ef27084fc317ac8bb5bae460c8ea72)
1/*
2 * Generic HDLC support routines for Linux
3 *
1/*
2 * Generic HDLC support routines for Linux
3 *
4 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
4 * Copyright (C) 1999 - 2008 Krzysztof Halasa <khc@pm.waw.pl>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
9 *
10 * Currently supported:
11 * * raw IP-in-HDLC
12 * * Cisco HDLC

--- 21 unchanged lines hidden (view full) ---

34#include <linux/inetdevice.h>
35#include <linux/lapb.h>
36#include <linux/rtnetlink.h>
37#include <linux/notifier.h>
38#include <linux/hdlc.h>
39#include <net/net_namespace.h>
40
41
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
9 *
10 * Currently supported:
11 * * raw IP-in-HDLC
12 * * Cisco HDLC

--- 21 unchanged lines hidden (view full) ---

34#include <linux/inetdevice.h>
35#include <linux/lapb.h>
36#include <linux/rtnetlink.h>
37#include <linux/notifier.h>
38#include <linux/hdlc.h>
39#include <net/net_namespace.h>
40
41
42static const char* version = "HDLC support module revision 1.21";
42static const char* version = "HDLC support module revision 1.22";
43
44#undef DEBUG_LINK
45
46static struct hdlc_proto *first_proto = NULL;
47
48
49static int hdlc_change_mtu(struct net_device *dev, int new_mtu)
50{

--- 10 unchanged lines hidden (view full) ---

61 return hdlc_stats(dev);
62}
63
64
65
66static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
67 struct packet_type *p, struct net_device *orig_dev)
68{
43
44#undef DEBUG_LINK
45
46static struct hdlc_proto *first_proto = NULL;
47
48
49static int hdlc_change_mtu(struct net_device *dev, int new_mtu)
50{

--- 10 unchanged lines hidden (view full) ---

61 return hdlc_stats(dev);
62}
63
64
65
66static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
67 struct packet_type *p, struct net_device *orig_dev)
68{
69 struct hdlc_device_desc *desc = dev_to_desc(dev);
69 struct hdlc_device *hdlc = dev_to_hdlc(dev);
70
71 if (dev->nd_net != &init_net) {
72 kfree_skb(skb);
73 return 0;
74 }
75
70
71 if (dev->nd_net != &init_net) {
72 kfree_skb(skb);
73 return 0;
74 }
75
76 if (desc->netif_rx)
77 return desc->netif_rx(skb);
78
79 desc->stats.rx_dropped++; /* Shouldn't happen */
80 dev_kfree_skb(skb);
81 return NET_RX_DROP;
76 BUG_ON(!hdlc->proto->netif_rx);
77 return hdlc->proto->netif_rx(skb);
82}
83
84
85
86static inline void hdlc_proto_start(struct net_device *dev)
87{
88 hdlc_device *hdlc = dev_to_hdlc(dev);
89 if (hdlc->proto->start)
78}
79
80
81
82static inline void hdlc_proto_start(struct net_device *dev)
83{
84 hdlc_device *hdlc = dev_to_hdlc(dev);
85 if (hdlc->proto->start)
90 return hdlc->proto->start(dev);
86 hdlc->proto->start(dev);
91}
92
93
94
95static inline void hdlc_proto_stop(struct net_device *dev)
96{
97 hdlc_device *hdlc = dev_to_hdlc(dev);
98 if (hdlc->proto->stop)
87}
88
89
90
91static inline void hdlc_proto_stop(struct net_device *dev)
92{
93 hdlc_device *hdlc = dev_to_hdlc(dev);
94 if (hdlc->proto->stop)
99 return hdlc->proto->stop(dev);
95 hdlc->proto->stop(dev);
100}
101
102
103
104static int hdlc_device_event(struct notifier_block *this, unsigned long event,
105 void *ptr)
106{
107 struct net_device *dev = ptr;

--- 150 unchanged lines hidden (view full) ---

258 hdlc->carrier = 1;
259 hdlc->open = 0;
260 spin_lock_init(&hdlc->state_lock);
261}
262
263struct net_device *alloc_hdlcdev(void *priv)
264{
265 struct net_device *dev;
96}
97
98
99
100static int hdlc_device_event(struct notifier_block *this, unsigned long event,
101 void *ptr)
102{
103 struct net_device *dev = ptr;

--- 150 unchanged lines hidden (view full) ---

254 hdlc->carrier = 1;
255 hdlc->open = 0;
256 spin_lock_init(&hdlc->state_lock);
257}
258
259struct net_device *alloc_hdlcdev(void *priv)
260{
261 struct net_device *dev;
266 dev = alloc_netdev(sizeof(struct hdlc_device_desc) +
267 sizeof(hdlc_device), "hdlc%d", hdlc_setup);
262 dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d", hdlc_setup);
268 if (dev)
269 dev_to_hdlc(dev)->priv = priv;
270 return dev;
271}
272
273void unregister_hdlc_device(struct net_device *dev)
274{
275 rtnl_lock();
276 unregister_netdevice(dev);
277 detach_hdlc_protocol(dev);
278 rtnl_unlock();
279}
280
281
282
283int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
263 if (dev)
264 dev_to_hdlc(dev)->priv = priv;
265 return dev;
266}
267
268void unregister_hdlc_device(struct net_device *dev)
269{
270 rtnl_lock();
271 unregister_netdevice(dev);
272 detach_hdlc_protocol(dev);
273 rtnl_unlock();
274}
275
276
277
278int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
284 int (*rx)(struct sk_buff *skb), size_t size)
279 size_t size)
285{
286 detach_hdlc_protocol(dev);
287
288 if (!try_module_get(proto->module))
289 return -ENOSYS;
290
291 if (size)
292 if ((dev_to_hdlc(dev)->state = kmalloc(size,
293 GFP_KERNEL)) == NULL) {
294 printk(KERN_WARNING "Memory squeeze on"
295 " hdlc_proto_attach()\n");
296 module_put(proto->module);
297 return -ENOBUFS;
298 }
299 dev_to_hdlc(dev)->proto = proto;
280{
281 detach_hdlc_protocol(dev);
282
283 if (!try_module_get(proto->module))
284 return -ENOSYS;
285
286 if (size)
287 if ((dev_to_hdlc(dev)->state = kmalloc(size,
288 GFP_KERNEL)) == NULL) {
289 printk(KERN_WARNING "Memory squeeze on"
290 " hdlc_proto_attach()\n");
291 module_put(proto->module);
292 return -ENOBUFS;
293 }
294 dev_to_hdlc(dev)->proto = proto;
300 dev_to_desc(dev)->netif_rx = rx;
301 return 0;
302}
303
304
305void detach_hdlc_protocol(struct net_device *dev)
306{
307 hdlc_device *hdlc = dev_to_hdlc(dev);
308

--- 80 unchanged lines hidden ---
295 return 0;
296}
297
298
299void detach_hdlc_protocol(struct net_device *dev)
300{
301 hdlc_device *hdlc = dev_to_hdlc(dev);
302

--- 80 unchanged lines hidden ---