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