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