[PATCH] uml: fix sleep length bug
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / um / drivers / net_kern.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2001 Lennert Buytenhek (buytenh@gnu.org) and
3 * James Leu (jleu@mindspring.net).
4 * Copyright (C) 2001 by various other people who didn't put their name here.
5 * Licensed under the GPL.
6 */
7
8#include "linux/config.h"
9#include "linux/kernel.h"
10#include "linux/netdevice.h"
11#include "linux/rtnetlink.h"
12#include "linux/skbuff.h"
13#include "linux/socket.h"
14#include "linux/spinlock.h"
15#include "linux/module.h"
16#include "linux/init.h"
17#include "linux/etherdevice.h"
18#include "linux/list.h"
19#include "linux/inetdevice.h"
20#include "linux/ctype.h"
21#include "linux/bootmem.h"
22#include "linux/ethtool.h"
d052d1be 23#include "linux/platform_device.h"
1da177e4
LT
24#include "asm/uaccess.h"
25#include "user_util.h"
26#include "kern_util.h"
27#include "net_kern.h"
28#include "net_user.h"
29#include "mconsole_kern.h"
30#include "init.h"
31#include "irq_user.h"
32#include "irq_kern.h"
33
bf61f50d
PBG
34static inline void set_ether_mac(struct net_device *dev, unsigned char *addr)
35{
36 memcpy(dev->dev_addr, addr, ETH_ALEN);
37}
38
1da177e4
LT
39#define DRIVER_NAME "uml-netdev"
40
41static DEFINE_SPINLOCK(opened_lock);
9010772c 42static LIST_HEAD(opened);
1da177e4
LT
43
44static int uml_net_rx(struct net_device *dev)
45{
46 struct uml_net_private *lp = dev->priv;
47 int pkt_len;
48 struct sk_buff *skb;
49
50 /* If we can't allocate memory, try again next round. */
51 skb = dev_alloc_skb(dev->mtu);
52 if (skb == NULL) {
53 lp->stats.rx_dropped++;
54 return 0;
55 }
56
57 skb->dev = dev;
58 skb_put(skb, dev->mtu);
59 skb->mac.raw = skb->data;
60 pkt_len = (*lp->read)(lp->fd, &skb, lp);
61
62 if (pkt_len > 0) {
63 skb_trim(skb, pkt_len);
64 skb->protocol = (*lp->protocol)(skb);
65 netif_rx(skb);
66
67 lp->stats.rx_bytes += skb->len;
68 lp->stats.rx_packets++;
69 return pkt_len;
70 }
71
72 kfree_skb(skb);
73 return pkt_len;
74}
75
71c8d4c3
PBG
76static void uml_dev_close(void* dev)
77{
78 dev_close( (struct net_device *) dev);
79}
80
1da177e4
LT
81irqreturn_t uml_net_interrupt(int irq, void *dev_id, struct pt_regs *regs)
82{
83 struct net_device *dev = dev_id;
84 struct uml_net_private *lp = dev->priv;
85 int err;
86
87 if(!netif_running(dev))
88 return(IRQ_NONE);
89
90 spin_lock(&lp->lock);
91 while((err = uml_net_rx(dev)) > 0) ;
92 if(err < 0) {
71c8d4c3 93 DECLARE_WORK(close_work, uml_dev_close, dev);
1da177e4
LT
94 printk(KERN_ERR
95 "Device '%s' read returned %d, shutting it down\n",
96 dev->name, err);
71c8d4c3
PBG
97 /* dev_close can't be called in interrupt context, and takes
98 * again lp->lock.
99 * And dev_close() can be safely called multiple times on the
100 * same device, since it tests for (dev->flags & IFF_UP). So
101 * there's no harm in delaying the device shutdown. */
102 schedule_work(&close_work);
1da177e4
LT
103 goto out;
104 }
105 reactivate_fd(lp->fd, UM_ETH_IRQ);
106
71c8d4c3 107out:
1da177e4
LT
108 spin_unlock(&lp->lock);
109 return(IRQ_HANDLED);
110}
111
112static int uml_net_open(struct net_device *dev)
113{
114 struct uml_net_private *lp = dev->priv;
1da177e4
LT
115 int err;
116
1da177e4
LT
117 if(lp->fd >= 0){
118 err = -ENXIO;
119 goto out;
120 }
121
122 if(!lp->have_mac){
0e76422c 123 dev_ip_addr(dev, &lp->mac[2]);
1da177e4
LT
124 set_ether_mac(dev, lp->mac);
125 }
126
127 lp->fd = (*lp->open)(&lp->user);
128 if(lp->fd < 0){
129 err = lp->fd;
130 goto out;
131 }
132
133 err = um_request_irq(dev->irq, lp->fd, IRQ_READ, uml_net_interrupt,
bd6aa650 134 IRQF_DISABLED | IRQF_SHARED, dev->name, dev);
1da177e4
LT
135 if(err != 0){
136 printk(KERN_ERR "uml_net_open: failed to get irq(%d)\n", err);
1da177e4 137 err = -ENETUNREACH;
14d9ead0 138 goto out_close;
1da177e4
LT
139 }
140
141 lp->tl.data = (unsigned long) &lp->user;
142 netif_start_queue(dev);
143
144 /* clear buffer - it can happen that the host side of the interface
145 * is full when we get here. In this case, new data is never queued,
146 * SIGIOs never arrive, and the net never works.
147 */
148 while((err = uml_net_rx(dev)) > 0) ;
149
14d9ead0
JD
150 spin_lock(&opened_lock);
151 list_add(&lp->list, &opened);
152 spin_unlock(&opened_lock);
153
154 return 0;
155out_close:
156 if(lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
157 lp->fd = -1;
158out:
14d9ead0 159 return err;
1da177e4
LT
160}
161
162static int uml_net_close(struct net_device *dev)
163{
164 struct uml_net_private *lp = dev->priv;
165
166 netif_stop_queue(dev);
1da177e4 167
1da177e4
LT
168 free_irq(dev->irq, dev);
169 if(lp->close != NULL)
170 (*lp->close)(lp->fd, &lp->user);
171 lp->fd = -1;
172
14d9ead0
JD
173 spin_lock(&opened_lock);
174 list_del(&lp->list);
175 spin_unlock(&opened_lock);
176
1da177e4
LT
177 return 0;
178}
179
180static int uml_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
181{
182 struct uml_net_private *lp = dev->priv;
183 unsigned long flags;
184 int len;
185
186 netif_stop_queue(dev);
187
188 spin_lock_irqsave(&lp->lock, flags);
189
190 len = (*lp->write)(lp->fd, &skb, lp);
191
192 if(len == skb->len) {
193 lp->stats.tx_packets++;
194 lp->stats.tx_bytes += skb->len;
195 dev->trans_start = jiffies;
196 netif_start_queue(dev);
197
198 /* this is normally done in the interrupt when tx finishes */
199 netif_wake_queue(dev);
200 }
201 else if(len == 0){
202 netif_start_queue(dev);
203 lp->stats.tx_dropped++;
204 }
205 else {
206 netif_start_queue(dev);
207 printk(KERN_ERR "uml_net_start_xmit: failed(%d)\n", len);
208 }
209
210 spin_unlock_irqrestore(&lp->lock, flags);
211
212 dev_kfree_skb(skb);
213
214 return 0;
215}
216
217static struct net_device_stats *uml_net_get_stats(struct net_device *dev)
218{
219 struct uml_net_private *lp = dev->priv;
220 return &lp->stats;
221}
222
223static void uml_net_set_multicast_list(struct net_device *dev)
224{
225 if (dev->flags & IFF_PROMISC) return;
226 else if (dev->mc_count) dev->flags |= IFF_ALLMULTI;
227 else dev->flags &= ~IFF_ALLMULTI;
228}
229
230static void uml_net_tx_timeout(struct net_device *dev)
231{
232 dev->trans_start = jiffies;
233 netif_wake_queue(dev);
234}
235
236static int uml_net_set_mac(struct net_device *dev, void *addr)
237{
238 struct uml_net_private *lp = dev->priv;
239 struct sockaddr *hwaddr = addr;
240
48af05ed 241 spin_lock_irq(&lp->lock);
bf61f50d 242 set_ether_mac(dev, hwaddr->sa_data);
48af05ed 243 spin_unlock_irq(&lp->lock);
1da177e4
LT
244
245 return(0);
246}
247
248static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
249{
250 struct uml_net_private *lp = dev->priv;
251 int err = 0;
252
48af05ed 253 spin_lock_irq(&lp->lock);
1da177e4
LT
254
255 new_mtu = (*lp->set_mtu)(new_mtu, &lp->user);
256 if(new_mtu < 0){
257 err = new_mtu;
258 goto out;
259 }
260
261 dev->mtu = new_mtu;
262
263 out:
48af05ed 264 spin_unlock_irq(&lp->lock);
1da177e4
LT
265 return err;
266}
267
6d387484
CH
268static void uml_net_get_drvinfo(struct net_device *dev,
269 struct ethtool_drvinfo *info)
1da177e4 270{
6d387484
CH
271 strcpy(info->driver, DRIVER_NAME);
272 strcpy(info->version, "42");
1da177e4
LT
273}
274
6d387484
CH
275static struct ethtool_ops uml_net_ethtool_ops = {
276 .get_drvinfo = uml_net_get_drvinfo,
277 .get_link = ethtool_op_get_link,
278};
279
1da177e4
LT
280void uml_net_user_timer_expire(unsigned long _conn)
281{
282#ifdef undef
283 struct connection *conn = (struct connection *)_conn;
284
285 dprintk(KERN_INFO "uml_net_user_timer_expire [%p]\n", conn);
286 do_connect(conn);
287#endif
288}
289
290static DEFINE_SPINLOCK(devices_lock);
9010772c 291static LIST_HEAD(devices);
1da177e4 292
3ae5eaec
RK
293static struct platform_driver uml_net_driver = {
294 .driver = {
295 .name = DRIVER_NAME,
296 },
1da177e4
LT
297};
298static int driver_registered;
299
300static int eth_configure(int n, void *init, char *mac,
301 struct transport *transport)
302{
303 struct uml_net *device;
304 struct net_device *dev;
305 struct uml_net_private *lp;
306 int save, err, size;
307
308 size = transport->private_size + sizeof(struct uml_net_private) +
309 sizeof(((struct uml_net_private *) 0)->user);
310
311 device = kmalloc(sizeof(*device), GFP_KERNEL);
312 if (device == NULL) {
313 printk(KERN_ERR "eth_configure failed to allocate uml_net\n");
314 return(1);
315 }
316
317 memset(device, 0, sizeof(*device));
318 INIT_LIST_HEAD(&device->list);
319 device->index = n;
320
321 spin_lock(&devices_lock);
322 list_add(&device->list, &devices);
323 spin_unlock(&devices_lock);
324
325 if (setup_etheraddr(mac, device->mac))
326 device->have_mac = 1;
327
328 printk(KERN_INFO "Netdevice %d ", n);
329 if (device->have_mac)
330 printk("(%02x:%02x:%02x:%02x:%02x:%02x) ",
331 device->mac[0], device->mac[1],
332 device->mac[2], device->mac[3],
333 device->mac[4], device->mac[5]);
334 printk(": ");
335 dev = alloc_etherdev(size);
336 if (dev == NULL) {
337 printk(KERN_ERR "eth_configure: failed to allocate device\n");
338 return 1;
339 }
340
e56a7885
PBG
341 lp = dev->priv;
342 /* This points to the transport private data. It's still clear, but we
343 * must memset it to 0 *now*. Let's help the drivers. */
344 memset(lp, 0, size);
345
1da177e4
LT
346 /* sysfs register */
347 if (!driver_registered) {
3ae5eaec 348 platform_driver_register(&uml_net_driver);
1da177e4
LT
349 driver_registered = 1;
350 }
351 device->pdev.id = n;
352 device->pdev.name = DRIVER_NAME;
353 platform_device_register(&device->pdev);
354 SET_NETDEV_DEV(dev,&device->pdev.dev);
355
356 /* If this name ends up conflicting with an existing registered
357 * netdevice, that is OK, register_netdev{,ice}() will notice this
358 * and fail.
359 */
360 snprintf(dev->name, sizeof(dev->name), "eth%d", n);
361 device->dev = dev;
362
363 (*transport->kern->init)(dev, init);
364
365 dev->mtu = transport->user->max_packet;
366 dev->open = uml_net_open;
367 dev->hard_start_xmit = uml_net_start_xmit;
368 dev->stop = uml_net_close;
369 dev->get_stats = uml_net_get_stats;
370 dev->set_multicast_list = uml_net_set_multicast_list;
371 dev->tx_timeout = uml_net_tx_timeout;
372 dev->set_mac_address = uml_net_set_mac;
373 dev->change_mtu = uml_net_change_mtu;
6d387484 374 dev->ethtool_ops = &uml_net_ethtool_ops;
1da177e4
LT
375 dev->watchdog_timeo = (HZ >> 1);
376 dev->irq = UM_ETH_IRQ;
377
378 rtnl_lock();
379 err = register_netdevice(dev);
380 rtnl_unlock();
381 if (err) {
382 device->dev = NULL;
383 /* XXX: should we call ->remove() here? */
384 free_netdev(dev);
385 return 1;
386 }
1da177e4
LT
387
388 /* lp.user is the first four bytes of the transport data, which
389 * has already been initialized. This structure assignment will
390 * overwrite that, so we make sure that .user gets overwritten with
391 * what it already has.
392 */
393 save = lp->user[0];
394 *lp = ((struct uml_net_private)
395 { .list = LIST_HEAD_INIT(lp->list),
396 .dev = dev,
397 .fd = -1,
398 .mac = { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0},
399 .have_mac = device->have_mac,
400 .protocol = transport->kern->protocol,
401 .open = transport->user->open,
402 .close = transport->user->close,
403 .remove = transport->user->remove,
404 .read = transport->kern->read,
405 .write = transport->kern->write,
406 .add_address = transport->user->add_address,
407 .delete_address = transport->user->delete_address,
408 .set_mtu = transport->user->set_mtu,
409 .user = { save } });
410
411 init_timer(&lp->tl);
412 spin_lock_init(&lp->lock);
413 lp->tl.function = uml_net_user_timer_expire;
414 if (lp->have_mac)
415 memcpy(lp->mac, device->mac, sizeof(lp->mac));
416
417 if (transport->user->init)
418 (*transport->user->init)(&lp->user, dev);
419
420 if (device->have_mac)
421 set_ether_mac(dev, device->mac);
422
14d9ead0 423 return 0;
1da177e4
LT
424}
425
426static struct uml_net *find_device(int n)
427{
428 struct uml_net *device;
429 struct list_head *ele;
430
431 spin_lock(&devices_lock);
432 list_for_each(ele, &devices){
433 device = list_entry(ele, struct uml_net, list);
434 if(device->index == n)
435 goto out;
436 }
437 device = NULL;
438 out:
439 spin_unlock(&devices_lock);
440 return(device);
441}
442
443static int eth_parse(char *str, int *index_out, char **str_out)
444{
445 char *end;
446 int n;
447
448 n = simple_strtoul(str, &end, 0);
449 if(end == str){
450 printk(KERN_ERR "eth_setup: Failed to parse '%s'\n", str);
451 return(1);
452 }
453 if(n < 0){
454 printk(KERN_ERR "eth_setup: device %d is negative\n", n);
455 return(1);
456 }
457 str = end;
458 if(*str != '='){
459 printk(KERN_ERR
460 "eth_setup: expected '=' after device number\n");
461 return(1);
462 }
463 str++;
464 if(find_device(n)){
465 printk(KERN_ERR "eth_setup: Device %d already configured\n",
466 n);
467 return(1);
468 }
469 if(index_out) *index_out = n;
470 *str_out = str;
471 return(0);
472}
473
474struct eth_init {
475 struct list_head list;
476 char *init;
477 int index;
478};
479
480/* Filled in at boot time. Will need locking if the transports become
481 * modular.
482 */
483struct list_head transports = LIST_HEAD_INIT(transports);
484
485/* Filled in during early boot */
486struct list_head eth_cmd_line = LIST_HEAD_INIT(eth_cmd_line);
487
488static int check_transport(struct transport *transport, char *eth, int n,
489 void **init_out, char **mac_out)
490{
491 int len;
492
493 len = strlen(transport->name);
494 if(strncmp(eth, transport->name, len))
495 return(0);
496
497 eth += len;
498 if(*eth == ',')
499 eth++;
500 else if(*eth != '\0')
501 return(0);
502
503 *init_out = kmalloc(transport->setup_size, GFP_KERNEL);
504 if(*init_out == NULL)
505 return(1);
506
507 if(!transport->setup(eth, mac_out, *init_out)){
508 kfree(*init_out);
509 *init_out = NULL;
510 }
511 return(1);
512}
513
514void register_transport(struct transport *new)
515{
516 struct list_head *ele, *next;
517 struct eth_init *eth;
518 void *init;
519 char *mac = NULL;
520 int match;
521
522 list_add(&new->list, &transports);
523
524 list_for_each_safe(ele, next, &eth_cmd_line){
525 eth = list_entry(ele, struct eth_init, list);
526 match = check_transport(new, eth->init, eth->index, &init,
527 &mac);
528 if(!match)
529 continue;
530 else if(init != NULL){
531 eth_configure(eth->index, init, mac, new);
532 kfree(init);
533 }
534 list_del(&eth->list);
535 }
536}
537
538static int eth_setup_common(char *str, int index)
539{
540 struct list_head *ele;
541 struct transport *transport;
542 void *init;
543 char *mac = NULL;
544
545 list_for_each(ele, &transports){
546 transport = list_entry(ele, struct transport, list);
547 if(!check_transport(transport, str, index, &init, &mac))
548 continue;
549 if(init != NULL){
550 eth_configure(index, init, mac, transport);
551 kfree(init);
552 }
553 return(1);
554 }
555 return(0);
556}
557
558static int eth_setup(char *str)
559{
560 struct eth_init *new;
561 int n, err;
562
563 err = eth_parse(str, &n, &str);
564 if(err) return(1);
565
566 new = alloc_bootmem(sizeof(new));
567 if (new == NULL){
568 printk("eth_init : alloc_bootmem failed\n");
569 return(1);
570 }
571
572 INIT_LIST_HEAD(&new->list);
573 new->index = n;
574 new->init = str;
575
576 list_add_tail(&new->list, &eth_cmd_line);
577 return(1);
578}
579
580__setup("eth", eth_setup);
581__uml_help(eth_setup,
582"eth[0-9]+=<transport>,<options>\n"
583" Configure a network device.\n\n"
584);
585
586#if 0
587static int eth_init(void)
588{
589 struct list_head *ele, *next;
590 struct eth_init *eth;
591
592 list_for_each_safe(ele, next, &eth_cmd_line){
593 eth = list_entry(ele, struct eth_init, list);
594
595 if(eth_setup_common(eth->init, eth->index))
596 list_del(&eth->list);
597 }
598
599 return(1);
600}
601__initcall(eth_init);
602#endif
603
604static int net_config(char *str)
605{
606 int n, err;
607
608 err = eth_parse(str, &n, &str);
609 if(err) return(err);
610
970d6e3a 611 str = kstrdup(str, GFP_KERNEL);
1da177e4
LT
612 if(str == NULL){
613 printk(KERN_ERR "net_config failed to strdup string\n");
614 return(-1);
615 }
616 err = !eth_setup_common(str, n);
617 if(err)
618 kfree(str);
619 return(err);
620}
621
29d56cfe
JD
622static int net_id(char **str, int *start_out, int *end_out)
623{
624 char *end;
625 int n;
626
627 n = simple_strtoul(*str, &end, 0);
628 if((*end != '\0') || (end == *str))
629 return -1;
630
631 *start_out = n;
632 *end_out = n;
633 *str = end;
634 return n;
635}
636
637static int net_remove(int n)
1da177e4
LT
638{
639 struct uml_net *device;
640 struct net_device *dev;
641 struct uml_net_private *lp;
1da177e4
LT
642
643 device = find_device(n);
644 if(device == NULL)
29d56cfe 645 return -ENODEV;
1da177e4
LT
646
647 dev = device->dev;
648 lp = dev->priv;
29d56cfe
JD
649 if(lp->fd > 0)
650 return -EBUSY;
1da177e4
LT
651 if(lp->remove != NULL) (*lp->remove)(&lp->user);
652 unregister_netdev(dev);
653 platform_device_unregister(&device->pdev);
654
655 list_del(&device->list);
656 kfree(device);
657 free_netdev(dev);
29d56cfe 658 return 0;
1da177e4
LT
659}
660
661static struct mc_device net_mc = {
662 .name = "eth",
663 .config = net_config,
664 .get_config = NULL,
29d56cfe 665 .id = net_id,
1da177e4
LT
666 .remove = net_remove,
667};
668
669static int uml_inetaddr_event(struct notifier_block *this, unsigned long event,
670 void *ptr)
671{
672 struct in_ifaddr *ifa = ptr;
1da177e4
LT
673 struct net_device *dev = ifa->ifa_dev->dev;
674 struct uml_net_private *lp;
675 void (*proc)(unsigned char *, unsigned char *, void *);
676 unsigned char addr_buf[4], netmask_buf[4];
677
678 if(dev->open != uml_net_open) return(NOTIFY_DONE);
679
680 lp = dev->priv;
681
682 proc = NULL;
683 switch (event){
684 case NETDEV_UP:
685 proc = lp->add_address;
686 break;
687 case NETDEV_DOWN:
688 proc = lp->delete_address;
689 break;
690 }
691 if(proc != NULL){
0e76422c
BS
692 memcpy(addr_buf, &ifa->ifa_address, sizeof(addr_buf));
693 memcpy(netmask_buf, &ifa->ifa_mask, sizeof(netmask_buf));
1da177e4
LT
694 (*proc)(addr_buf, netmask_buf, &lp->user);
695 }
696 return(NOTIFY_DONE);
697}
698
699struct notifier_block uml_inetaddr_notifier = {
700 .notifier_call = uml_inetaddr_event,
701};
702
703static int uml_net_init(void)
704{
705 struct list_head *ele;
706 struct uml_net_private *lp;
707 struct in_device *ip;
708 struct in_ifaddr *in;
709
710 mconsole_register_dev(&net_mc);
711 register_inetaddr_notifier(&uml_inetaddr_notifier);
712
713 /* Devices may have been opened already, so the uml_inetaddr_notifier
714 * didn't get a chance to run for them. This fakes it so that
715 * addresses which have already been set up get handled properly.
716 */
717 list_for_each(ele, &opened){
718 lp = list_entry(ele, struct uml_net_private, list);
719 ip = lp->dev->ip_ptr;
720 if(ip == NULL) continue;
721 in = ip->ifa_list;
722 while(in != NULL){
723 uml_inetaddr_event(NULL, NETDEV_UP, in);
724 in = in->ifa_next;
725 }
726 }
727
728 return(0);
729}
730
731__initcall(uml_net_init);
732
733static void close_devices(void)
734{
735 struct list_head *ele;
736 struct uml_net_private *lp;
737
738 list_for_each(ele, &opened){
739 lp = list_entry(ele, struct uml_net_private, list);
8d93c700 740 free_irq(lp->dev->irq, lp->dev);
1da177e4
LT
741 if((lp->close != NULL) && (lp->fd >= 0))
742 (*lp->close)(lp->fd, &lp->user);
743 if(lp->remove != NULL) (*lp->remove)(&lp->user);
744 }
745}
746
747__uml_exitcall(close_devices);
748
749int setup_etheraddr(char *str, unsigned char *addr)
750{
751 char *end;
752 int i;
753
754 if(str == NULL)
755 return(0);
756 for(i=0;i<6;i++){
757 addr[i] = simple_strtoul(str, &end, 16);
758 if((end == str) ||
759 ((*end != ':') && (*end != ',') && (*end != '\0'))){
760 printk(KERN_ERR
761 "setup_etheraddr: failed to parse '%s' "
762 "as an ethernet address\n", str);
763 return(0);
764 }
765 str = end + 1;
766 }
767 if(addr[0] & 1){
768 printk(KERN_ERR
769 "Attempt to assign a broadcast ethernet address to a "
770 "device disallowed\n");
771 return(0);
772 }
773 return(1);
774}
775
0e76422c 776void dev_ip_addr(void *d, unsigned char *bin_buf)
1da177e4
LT
777{
778 struct net_device *dev = d;
779 struct in_device *ip = dev->ip_ptr;
780 struct in_ifaddr *in;
1da177e4
LT
781
782 if((ip == NULL) || ((in = ip->ifa_list) == NULL)){
783 printk(KERN_WARNING "dev_ip_addr - device not assigned an "
784 "IP address\n");
785 return;
786 }
0e76422c 787 memcpy(bin_buf, &in->ifa_address, sizeof(in->ifa_address));
1da177e4
LT
788}
789
1da177e4
LT
790struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
791{
792 if((skb != NULL) && (skb_tailroom(skb) < extra)){
793 struct sk_buff *skb2;
794
795 skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
796 dev_kfree_skb(skb);
797 skb = skb2;
798 }
799 if(skb != NULL) skb_put(skb, extra);
800 return(skb);
801}
802
803void iter_addresses(void *d, void (*cb)(unsigned char *, unsigned char *,
804 void *),
805 void *arg)
806{
807 struct net_device *dev = d;
808 struct in_device *ip = dev->ip_ptr;
809 struct in_ifaddr *in;
810 unsigned char address[4], netmask[4];
811
812 if(ip == NULL) return;
813 in = ip->ifa_list;
814 while(in != NULL){
0e76422c
BS
815 memcpy(address, &in->ifa_address, sizeof(address));
816 memcpy(netmask, &in->ifa_mask, sizeof(netmask));
1da177e4
LT
817 (*cb)(address, netmask, arg);
818 in = in->ifa_next;
819 }
820}
821
822int dev_netmask(void *d, void *m)
823{
824 struct net_device *dev = d;
825 struct in_device *ip = dev->ip_ptr;
826 struct in_ifaddr *in;
827 __u32 *mask_out = m;
828
829 if(ip == NULL)
830 return(1);
831
832 in = ip->ifa_list;
833 if(in == NULL)
834 return(1);
835
836 *mask_out = in->ifa_mask;
837 return(0);
838}
839
840void *get_output_buffer(int *len_out)
841{
842 void *ret;
843
844 ret = (void *) __get_free_pages(GFP_KERNEL, 0);
845 if(ret) *len_out = PAGE_SIZE;
846 else *len_out = 0;
847 return(ret);
848}
849
850void free_output_buffer(void *buffer)
851{
852 free_pages((unsigned long) buffer, 0);
853}
854
855int tap_setup_common(char *str, char *type, char **dev_name, char **mac_out,
856 char **gate_addr)
857{
858 char *remain;
859
860 remain = split_if_spec(str, dev_name, mac_out, gate_addr, NULL);
861 if(remain != NULL){
862 printk("tap_setup_common - Extra garbage on specification : "
863 "'%s'\n", remain);
864 return(1);
865 }
866
867 return(0);
868}
869
870unsigned short eth_protocol(struct sk_buff *skb)
871{
872 return(eth_type_trans(skb, skb->dev));
873}
874
875/*
876 * Overrides for Emacs so that we follow Linus's tabbing style.
877 * Emacs will notice this stuff at the end of the file and automatically
878 * adjust the settings for this buffer only. This must remain at the end
879 * of the file.
880 * ---------------------------------------------------------------------------
881 * Local variables:
882 * c-file-style: "linux"
883 * End:
884 */