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