aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wan
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wan')
-rw-r--r--drivers/net/wan/hdlc.c24
-rw-r--r--drivers/net/wan/hdlc_cisco.c5
-rw-r--r--drivers/net/wan/hdlc_fr.c53
-rw-r--r--drivers/net/wan/hdlc_ppp.c2
-rw-r--r--drivers/net/wan/hdlc_raw.c2
-rw-r--r--drivers/net/wan/hdlc_raw_eth.c6
-rw-r--r--drivers/net/wan/hdlc_x25.c10
7 files changed, 46 insertions, 56 deletions
diff --git a/drivers/net/wan/hdlc.c b/drivers/net/wan/hdlc.c
index d553e6f32851..39951d0c34d6 100644
--- a/drivers/net/wan/hdlc.c
+++ b/drivers/net/wan/hdlc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Generic HDLC support routines for Linux 2 * Generic HDLC support routines for Linux
3 * 3 *
4 * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl> 4 * Copyright (C) 1999 - 2008 Krzysztof Halasa <khc@pm.waw.pl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 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 7 * under the terms of version 2 of the GNU General Public License
@@ -39,7 +39,7 @@
39#include <net/net_namespace.h> 39#include <net/net_namespace.h>
40 40
41 41
42static const char* version = "HDLC support module revision 1.21"; 42static const char* version = "HDLC support module revision 1.22";
43 43
44#undef DEBUG_LINK 44#undef DEBUG_LINK
45 45
@@ -66,19 +66,15 @@ static struct net_device_stats *hdlc_get_stats(struct net_device *dev)
66static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev, 66static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
67 struct packet_type *p, struct net_device *orig_dev) 67 struct packet_type *p, struct net_device *orig_dev)
68{ 68{
69 struct hdlc_device_desc *desc = dev_to_desc(dev); 69 struct hdlc_device *hdlc = dev_to_hdlc(dev);
70 70
71 if (dev->nd_net != &init_net) { 71 if (dev->nd_net != &init_net) {
72 kfree_skb(skb); 72 kfree_skb(skb);
73 return 0; 73 return 0;
74 } 74 }
75 75
76 if (desc->netif_rx) 76 BUG_ON(!hdlc->proto->netif_rx);
77 return desc->netif_rx(skb); 77 return hdlc->proto->netif_rx(skb);
78
79 desc->stats.rx_dropped++; /* Shouldn't happen */
80 dev_kfree_skb(skb);
81 return NET_RX_DROP;
82} 78}
83 79
84 80
@@ -87,7 +83,7 @@ static inline void hdlc_proto_start(struct net_device *dev)
87{ 83{
88 hdlc_device *hdlc = dev_to_hdlc(dev); 84 hdlc_device *hdlc = dev_to_hdlc(dev);
89 if (hdlc->proto->start) 85 if (hdlc->proto->start)
90 return hdlc->proto->start(dev); 86 hdlc->proto->start(dev);
91} 87}
92 88
93 89
@@ -96,7 +92,7 @@ static inline void hdlc_proto_stop(struct net_device *dev)
96{ 92{
97 hdlc_device *hdlc = dev_to_hdlc(dev); 93 hdlc_device *hdlc = dev_to_hdlc(dev);
98 if (hdlc->proto->stop) 94 if (hdlc->proto->stop)
99 return hdlc->proto->stop(dev); 95 hdlc->proto->stop(dev);
100} 96}
101 97
102 98
@@ -263,8 +259,7 @@ static void hdlc_setup(struct net_device *dev)
263struct net_device *alloc_hdlcdev(void *priv) 259struct net_device *alloc_hdlcdev(void *priv)
264{ 260{
265 struct net_device *dev; 261 struct net_device *dev;
266 dev = alloc_netdev(sizeof(struct hdlc_device_desc) + 262 dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d", hdlc_setup);
267 sizeof(hdlc_device), "hdlc%d", hdlc_setup);
268 if (dev) 263 if (dev)
269 dev_to_hdlc(dev)->priv = priv; 264 dev_to_hdlc(dev)->priv = priv;
270 return dev; 265 return dev;
@@ -281,7 +276,7 @@ void unregister_hdlc_device(struct net_device *dev)
281 276
282 277
283int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, 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{ 280{
286 detach_hdlc_protocol(dev); 281 detach_hdlc_protocol(dev);
287 282
@@ -297,7 +292,6 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto,
297 return -ENOBUFS; 292 return -ENOBUFS;
298 } 293 }
299 dev_to_hdlc(dev)->proto = proto; 294 dev_to_hdlc(dev)->proto = proto;
300 dev_to_desc(dev)->netif_rx = rx;
301 return 0; 295 return 0;
302} 296}
303 297
diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c
index 038a6e748bbf..7133c688cf20 100644
--- a/drivers/net/wan/hdlc_cisco.c
+++ b/drivers/net/wan/hdlc_cisco.c
@@ -250,7 +250,7 @@ static int cisco_rx(struct sk_buff *skb)
250 return NET_RX_DROP; 250 return NET_RX_DROP;
251 251
252 rx_error: 252 rx_error:
253 dev_to_desc(dev)->stats.rx_errors++; /* Mark error */ 253 dev_to_hdlc(dev)->stats.rx_errors++; /* Mark error */
254 dev_kfree_skb_any(skb); 254 dev_kfree_skb_any(skb);
255 return NET_RX_DROP; 255 return NET_RX_DROP;
256} 256}
@@ -314,6 +314,7 @@ static struct hdlc_proto proto = {
314 .stop = cisco_stop, 314 .stop = cisco_stop,
315 .type_trans = cisco_type_trans, 315 .type_trans = cisco_type_trans,
316 .ioctl = cisco_ioctl, 316 .ioctl = cisco_ioctl,
317 .netif_rx = cisco_rx,
317 .module = THIS_MODULE, 318 .module = THIS_MODULE,
318}; 319};
319 320
@@ -360,7 +361,7 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr)
360 if (result) 361 if (result)
361 return result; 362 return result;
362 363
363 result = attach_hdlc_protocol(dev, &proto, cisco_rx, 364 result = attach_hdlc_protocol(dev, &proto,
364 sizeof(struct cisco_state)); 365 sizeof(struct cisco_state));
365 if (result) 366 if (result)
366 return result; 367 return result;
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 071a64cacd5c..c4ab0326f911 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -42,7 +42,6 @@
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/skbuff.h> 43#include <linux/skbuff.h>
44#include <linux/pkt_sched.h> 44#include <linux/pkt_sched.h>
45#include <linux/random.h>
46#include <linux/inetdevice.h> 45#include <linux/inetdevice.h>
47#include <linux/lapb.h> 46#include <linux/lapb.h>
48#include <linux/rtnetlink.h> 47#include <linux/rtnetlink.h>
@@ -136,6 +135,10 @@ typedef struct pvc_device_struct {
136 }state; 135 }state;
137}pvc_device; 136}pvc_device;
138 137
138struct pvc_desc {
139 struct net_device_stats stats;
140 pvc_device *pvc;
141};
139 142
140struct frad_state { 143struct frad_state {
141 fr_proto settings; 144 fr_proto settings;
@@ -171,17 +174,20 @@ static inline void dlci_to_q922(u8 *hdr, u16 dlci)
171} 174}
172 175
173 176
174static inline struct frad_state * state(hdlc_device *hdlc) 177static inline struct frad_state* state(hdlc_device *hdlc)
175{ 178{
176 return(struct frad_state *)(hdlc->state); 179 return(struct frad_state *)(hdlc->state);
177} 180}
178 181
179 182static inline struct pvc_desc* pvcdev_to_desc(struct net_device *dev)
180static __inline__ pvc_device* dev_to_pvc(struct net_device *dev)
181{ 183{
182 return dev->priv; 184 return dev->priv;
183} 185}
184 186
187static inline struct net_device_stats* pvc_get_stats(struct net_device *dev)
188{
189 return &pvcdev_to_desc(dev)->stats;
190}
185 191
186static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci) 192static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
187{ 193{
@@ -351,7 +357,7 @@ static int fr_hard_header(struct sk_buff **skb_p, u16 dlci)
351 357
352static int pvc_open(struct net_device *dev) 358static int pvc_open(struct net_device *dev)
353{ 359{
354 pvc_device *pvc = dev_to_pvc(dev); 360 pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
355 361
356 if ((pvc->frad->flags & IFF_UP) == 0) 362 if ((pvc->frad->flags & IFF_UP) == 0)
357 return -EIO; /* Frad must be UP in order to activate PVC */ 363 return -EIO; /* Frad must be UP in order to activate PVC */
@@ -371,7 +377,7 @@ static int pvc_open(struct net_device *dev)
371 377
372static int pvc_close(struct net_device *dev) 378static int pvc_close(struct net_device *dev)
373{ 379{
374 pvc_device *pvc = dev_to_pvc(dev); 380 pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
375 381
376 if (--pvc->open_count == 0) { 382 if (--pvc->open_count == 0) {
377 hdlc_device *hdlc = dev_to_hdlc(pvc->frad); 383 hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
@@ -390,7 +396,7 @@ static int pvc_close(struct net_device *dev)
390 396
391static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 397static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
392{ 398{
393 pvc_device *pvc = dev_to_pvc(dev); 399 pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
394 fr_proto_pvc_info info; 400 fr_proto_pvc_info info;
395 401
396 if (ifr->ifr_settings.type == IF_GET_PROTO) { 402 if (ifr->ifr_settings.type == IF_GET_PROTO) {
@@ -416,17 +422,9 @@ static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
416 return -EINVAL; 422 return -EINVAL;
417} 423}
418 424
419
420static inline struct net_device_stats *pvc_get_stats(struct net_device *dev)
421{
422 return &dev_to_desc(dev)->stats;
423}
424
425
426
427static int pvc_xmit(struct sk_buff *skb, struct net_device *dev) 425static int pvc_xmit(struct sk_buff *skb, struct net_device *dev)
428{ 426{
429 pvc_device *pvc = dev_to_pvc(dev); 427 pvc_device *pvc = pvcdev_to_desc(dev)->pvc;
430 struct net_device_stats *stats = pvc_get_stats(dev); 428 struct net_device_stats *stats = pvc_get_stats(dev);
431 429
432 if (pvc->state.active) { 430 if (pvc->state.active) {
@@ -957,7 +955,7 @@ static int fr_rx(struct sk_buff *skb)
957 955
958 956
959 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { 957 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
960 dev_to_desc(frad)->stats.rx_dropped++; 958 dev_to_hdlc(frad)->stats.rx_dropped++;
961 return NET_RX_DROP; 959 return NET_RX_DROP;
962 } 960 }
963 961
@@ -1018,7 +1016,7 @@ static int fr_rx(struct sk_buff *skb)
1018 } 1016 }
1019 1017
1020 rx_error: 1018 rx_error:
1021 dev_to_desc(frad)->stats.rx_errors++; /* Mark error */ 1019 dev_to_hdlc(frad)->stats.rx_errors++; /* Mark error */
1022 dev_kfree_skb_any(skb); 1020 dev_kfree_skb_any(skb);
1023 return NET_RX_DROP; 1021 return NET_RX_DROP;
1024} 1022}
@@ -1109,11 +1107,10 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
1109 used = pvc_is_used(pvc); 1107 used = pvc_is_used(pvc);
1110 1108
1111 if (type == ARPHRD_ETHER) 1109 if (type == ARPHRD_ETHER)
1112 dev = alloc_netdev(sizeof(struct net_device_stats), 1110 dev = alloc_netdev(sizeof(struct pvc_desc), "pvceth%d",
1113 "pvceth%d", ether_setup); 1111 ether_setup);
1114 else 1112 else
1115 dev = alloc_netdev(sizeof(struct net_device_stats), 1113 dev = alloc_netdev(sizeof(struct pvc_desc), "pvc%d", pvc_setup);
1116 "pvc%d", pvc_setup);
1117 1114
1118 if (!dev) { 1115 if (!dev) {
1119 printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n", 1116 printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
@@ -1122,10 +1119,9 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
1122 return -ENOBUFS; 1119 return -ENOBUFS;
1123 } 1120 }
1124 1121
1125 if (type == ARPHRD_ETHER) { 1122 if (type == ARPHRD_ETHER)
1126 memcpy(dev->dev_addr, "\x00\x01", 2); 1123 random_ether_addr(dev->dev_addr);
1127 get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2); 1124 else {
1128 } else {
1129 *(__be16*)dev->dev_addr = htons(dlci); 1125 *(__be16*)dev->dev_addr = htons(dlci);
1130 dlci_to_q922(dev->broadcast, dlci); 1126 dlci_to_q922(dev->broadcast, dlci);
1131 } 1127 }
@@ -1137,7 +1133,7 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
1137 dev->change_mtu = pvc_change_mtu; 1133 dev->change_mtu = pvc_change_mtu;
1138 dev->mtu = HDLC_MAX_MTU; 1134 dev->mtu = HDLC_MAX_MTU;
1139 dev->tx_queue_len = 0; 1135 dev->tx_queue_len = 0;
1140 dev->priv = pvc; 1136 pvcdev_to_desc(dev)->pvc = pvc;
1141 1137
1142 result = dev_alloc_name(dev, dev->name); 1138 result = dev_alloc_name(dev, dev->name);
1143 if (result < 0) { 1139 if (result < 0) {
@@ -1219,6 +1215,7 @@ static struct hdlc_proto proto = {
1219 .stop = fr_stop, 1215 .stop = fr_stop,
1220 .detach = fr_destroy, 1216 .detach = fr_destroy,
1221 .ioctl = fr_ioctl, 1217 .ioctl = fr_ioctl,
1218 .netif_rx = fr_rx,
1222 .module = THIS_MODULE, 1219 .module = THIS_MODULE,
1223}; 1220};
1224 1221
@@ -1277,7 +1274,7 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
1277 return result; 1274 return result;
1278 1275
1279 if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */ 1276 if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
1280 result = attach_hdlc_protocol(dev, &proto, fr_rx, 1277 result = attach_hdlc_protocol(dev, &proto,
1281 sizeof(struct frad_state)); 1278 sizeof(struct frad_state));
1282 if (result) 1279 if (result)
1283 return result; 1280 return result;
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index 519e1550e2e7..10396d9686f4 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -122,7 +122,7 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr)
122 if (result) 122 if (result)
123 return result; 123 return result;
124 124
125 result = attach_hdlc_protocol(dev, &proto, NULL, 125 result = attach_hdlc_protocol(dev, &proto,
126 sizeof(struct ppp_state)); 126 sizeof(struct ppp_state));
127 if (result) 127 if (result)
128 return result; 128 return result;
diff --git a/drivers/net/wan/hdlc_raw.c b/drivers/net/wan/hdlc_raw.c
index e23bc6656267..bbbb819d764c 100644
--- a/drivers/net/wan/hdlc_raw.c
+++ b/drivers/net/wan/hdlc_raw.c
@@ -82,7 +82,7 @@ static int raw_ioctl(struct net_device *dev, struct ifreq *ifr)
82 if (result) 82 if (result)
83 return result; 83 return result;
84 84
85 result = attach_hdlc_protocol(dev, &proto, NULL, 85 result = attach_hdlc_protocol(dev, &proto,
86 sizeof(raw_hdlc_proto)); 86 sizeof(raw_hdlc_proto));
87 if (result) 87 if (result)
88 return result; 88 return result;
diff --git a/drivers/net/wan/hdlc_raw_eth.c b/drivers/net/wan/hdlc_raw_eth.c
index 8895394e6006..d20c685f6711 100644
--- a/drivers/net/wan/hdlc_raw_eth.c
+++ b/drivers/net/wan/hdlc_raw_eth.c
@@ -18,7 +18,6 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/skbuff.h> 19#include <linux/skbuff.h>
20#include <linux/pkt_sched.h> 20#include <linux/pkt_sched.h>
21#include <linux/random.h>
22#include <linux/inetdevice.h> 21#include <linux/inetdevice.h>
23#include <linux/lapb.h> 22#include <linux/lapb.h>
24#include <linux/rtnetlink.h> 23#include <linux/rtnetlink.h>
@@ -96,7 +95,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
96 if (result) 95 if (result)
97 return result; 96 return result;
98 97
99 result = attach_hdlc_protocol(dev, &proto, NULL, 98 result = attach_hdlc_protocol(dev, &proto,
100 sizeof(raw_hdlc_proto)); 99 sizeof(raw_hdlc_proto));
101 if (result) 100 if (result)
102 return result; 101 return result;
@@ -107,8 +106,7 @@ static int raw_eth_ioctl(struct net_device *dev, struct ifreq *ifr)
107 ether_setup(dev); 106 ether_setup(dev);
108 dev->change_mtu = old_ch_mtu; 107 dev->change_mtu = old_ch_mtu;
109 dev->tx_queue_len = old_qlen; 108 dev->tx_queue_len = old_qlen;
110 memcpy(dev->dev_addr, "\x00\x01", 2); 109 random_ether_addr(dev->dev_addr);
111 get_random_bytes(dev->dev_addr + 2, ETH_ALEN - 2);
112 netif_dormant_off(dev); 110 netif_dormant_off(dev);
113 return 0; 111 return 0;
114 } 112 }
diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
index cd7b22f50edc..c15cc11e399b 100644
--- a/drivers/net/wan/hdlc_x25.c
+++ b/drivers/net/wan/hdlc_x25.c
@@ -164,17 +164,17 @@ static void x25_close(struct net_device *dev)
164 164
165static int x25_rx(struct sk_buff *skb) 165static int x25_rx(struct sk_buff *skb)
166{ 166{
167 struct hdlc_device_desc *desc = dev_to_desc(skb->dev); 167 struct hdlc_device *hdlc = dev_to_hdlc(skb->dev);
168 168
169 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { 169 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
170 desc->stats.rx_dropped++; 170 hdlc->stats.rx_dropped++;
171 return NET_RX_DROP; 171 return NET_RX_DROP;
172 } 172 }
173 173
174 if (lapb_data_received(skb->dev, skb) == LAPB_OK) 174 if (lapb_data_received(skb->dev, skb) == LAPB_OK)
175 return NET_RX_SUCCESS; 175 return NET_RX_SUCCESS;
176 176
177 desc->stats.rx_errors++; 177 hdlc->stats.rx_errors++;
178 dev_kfree_skb_any(skb); 178 dev_kfree_skb_any(skb);
179 return NET_RX_DROP; 179 return NET_RX_DROP;
180} 180}
@@ -184,6 +184,7 @@ static struct hdlc_proto proto = {
184 .open = x25_open, 184 .open = x25_open,
185 .close = x25_close, 185 .close = x25_close,
186 .ioctl = x25_ioctl, 186 .ioctl = x25_ioctl,
187 .netif_rx = x25_rx,
187 .module = THIS_MODULE, 188 .module = THIS_MODULE,
188}; 189};
189 190
@@ -211,8 +212,7 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr)
211 if (result) 212 if (result)
212 return result; 213 return result;
213 214
214 if ((result = attach_hdlc_protocol(dev, &proto, 215 if ((result = attach_hdlc_protocol(dev, &proto, 0)))
215 x25_rx, 0)) != 0)
216 return result; 216 return result;
217 dev->hard_start_xmit = x25_xmit; 217 dev->hard_start_xmit = x25_xmit;
218 dev->type = ARPHRD_X25; 218 dev->type = ARPHRD_X25;