root/net/inet/dev.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. min
  2. dev_add_pack
  3. dev_remove_pack
  4. dev_get
  5. dev_open
  6. dev_close
  7. register_netdevice_notifier
  8. unregister_netdevice_notifier
  9. dev_queue_xmit
  10. netif_rx
  11. dev_rint
  12. dev_transmit
  13. in_net_bh
  14. net_bh
  15. dev_tint
  16. dev_ifconf
  17. sprintf_stats
  18. dev_get_info
  19. bad_mask
  20. dev_ifsioc
  21. dev_ioctl
  22. dev_init

   1 /*
   2  *      NET3    Protocol independent device support routines.
   3  *
   4  *              This program is free software; you can redistribute it and/or
   5  *              modify it under the terms of the GNU General Public License
   6  *              as published by the Free Software Foundation; either version
   7  *              2 of the License, or (at your option) any later version.
   8  *
   9  *      Derived from the non IP parts of dev.c 1.0.19
  10  *              Authors:        Ross Biro, <bir7@leland.Stanford.Edu>
  11  *                              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *                              Mark Evans, <evansmp@uhura.aston.ac.uk>
  13  *
  14  *      Additional Authors:
  15  *              Florian la Roche <rzsfl@rz.uni-sb.de>
  16  *              Alan Cox <gw4pts@gw4pts.ampr.org>
  17  *              David Hinds <dhinds@allegro.stanford.edu>
  18  *
  19  *      Changes:
  20  *              Alan Cox        :       device private ioctl copies fields back.
  21  *              Alan Cox        :       Transmit queue code does relevant stunts to
  22  *                                      keep the queue safe.
  23  *              Alan Cox        :       Fixed double lock.
  24  *              Alan Cox        :       Fixed promisc NULL pointer trap
  25  *              ????????        :       Support the full private ioctl range
  26  *              Alan Cox        :       Moved ioctl permission check into drivers
  27  *              Tim Kordas      :       SIOCADDMULTI/SIOCDELMULTI
  28  *              Alan Cox        :       100 backlog just doesn't cut it when
  29  *                                      you start doing multicast video 8)
  30  *              Alan Cox        :       Rewrote net_bh and list manager.
  31  *              Alan Cox        :       Fix ETH_P_ALL echoback lengths.
  32  *
  33  *      Cleaned up and recommented by Alan Cox 2nd April 1994. I hope to have
  34  *      the rest as well commented in the end.
  35  */
  36 
  37 /*
  38  *      A lot of these includes will be going walkies very soon 
  39  */
  40  
  41 #include <asm/segment.h>
  42 #include <asm/system.h>
  43 #include <asm/bitops.h>
  44 #include <linux/config.h>
  45 #include <linux/types.h>
  46 #include <linux/kernel.h>
  47 #include <linux/sched.h>
  48 #include <linux/string.h>
  49 #include <linux/mm.h>
  50 #include <linux/socket.h>
  51 #include <linux/sockios.h>
  52 #include <linux/in.h>
  53 #include <linux/errno.h>
  54 #include <linux/interrupt.h>
  55 #include <linux/if_ether.h>
  56 #include <linux/inet.h>
  57 #include <linux/netdevice.h>
  58 #include <linux/etherdevice.h>
  59 #include <linux/notifier.h>
  60 #include "ip.h"
  61 #include "route.h"
  62 #include <linux/skbuff.h>
  63 #include "sock.h"
  64 #include "arp.h"
  65 
  66 
  67 /*
  68  *      The list of packet types we will receive (as opposed to discard)
  69  *      and the routines to invoke.
  70  */
  71 
  72 struct packet_type *ptype_base = NULL;
  73 
  74 /*
  75  *      Our notifier list
  76  */
  77  
  78 struct notifier_block *netdev_chain=NULL;
  79 
  80 /*
  81  *      Device drivers call our routines to queue packets here. We empty the
  82  *      queue in the bottom half handler.
  83  */
  84 
  85 static struct sk_buff_head backlog = 
  86 {
  87         (struct sk_buff *)&backlog, (struct sk_buff *)&backlog
  88 #ifdef CONFIG_SKB_CHECK
  89         ,SK_HEAD_SKB
  90 #endif
  91 };
  92 
  93 /* 
  94  *      We don't overdo the queue or we will thrash memory badly.
  95  */
  96  
  97 static int backlog_size = 0;
  98 
  99 /*
 100  *      Return the lesser of the two values. 
 101  */
 102  
 103 static __inline__ unsigned long min(unsigned long a, unsigned long b)
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105   return (a < b)? a : b;
 106 }
 107 
 108 
 109 /******************************************************************************************
 110 
 111                 Protocol management and registration routines
 112 
 113 *******************************************************************************************/
 114 
 115 /*
 116  *      For efficiency
 117  */
 118 
 119 static int dev_nit=0;
 120 
 121 /*
 122  *      Add a protocol ID to the list. Now that the input handler is
 123  *      smarter we can dispense with all the messy stuff that used to be
 124  *      here.
 125  */
 126  
 127 void dev_add_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129         if(pt->type==htons(ETH_P_ALL))
 130                 dev_nit++;
 131         pt->next = ptype_base;
 132         ptype_base = pt;
 133 }
 134 
 135 
 136 /*
 137  *      Remove a protocol ID from the list.
 138  */
 139  
 140 void dev_remove_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142         struct packet_type **pt1;
 143         if(pt->type==htons(ETH_P_ALL))
 144                 dev_nit--;
 145         for(pt1=&ptype_base; (*pt1)!=NULL; pt1=&((*pt1)->next))
 146         {
 147                 if(pt==(*pt1))
 148                 {
 149                         *pt1=pt->next;
 150                         return;
 151                 }
 152         }
 153 }
 154 
 155 /*****************************************************************************************
 156 
 157                             Device Interface Subroutines
 158 
 159 ******************************************************************************************/
 160 
 161 /* 
 162  *      Find an interface by name.
 163  */
 164  
 165 struct device *dev_get(char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167         struct device *dev;
 168 
 169         for (dev = dev_base; dev != NULL; dev = dev->next) 
 170         {
 171                 if (strcmp(dev->name, name) == 0)
 172                         return(dev);
 173         }
 174         return(NULL);
 175 }
 176 
 177 
 178 /*
 179  *      Prepare an interface for use. 
 180  */
 181  
 182 int dev_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184         int ret = 0;
 185 
 186         /*
 187          *      Call device private open method
 188          */
 189         if (dev->open) 
 190                 ret = dev->open(dev);
 191 
 192         /*
 193          *      If it went open OK then set the flags
 194          */
 195          
 196         if (ret == 0) 
 197         {
 198                 dev->flags |= (IFF_UP | IFF_RUNNING);
 199                 /*
 200                  *      Initialise multicasting status 
 201                  */
 202 #ifdef CONFIG_IP_MULTICAST
 203                 /* 
 204                  *      Join the all host group 
 205                  */
 206                 ip_mc_allhost(dev);
 207 #endif                          
 208                 dev_mc_upload(dev);
 209                 notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
 210         }
 211         return(ret);
 212 }
 213 
 214 
 215 /*
 216  *      Completely shutdown an interface.
 217  */
 218  
 219 int dev_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 220 {
 221         /*
 222          *      Only close a device if it is up.
 223          */
 224          
 225         if (dev->flags != 0) 
 226         {
 227                 int ct=0;
 228                 dev->flags = 0;
 229                 /*
 230                  *      Call the device specific close. This cannot fail.
 231                  */
 232                 if (dev->stop) 
 233                         dev->stop(dev);
 234                         
 235                 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
 236 #if 0           
 237                 /*
 238                  *      Delete the route to the device.
 239                  */
 240 #ifdef CONFIG_INET               
 241                 ip_rt_flush(dev);
 242                 arp_device_down(dev);
 243 #endif          
 244 #ifdef CONFIG_IPX
 245                 ipxrtr_device_down(dev);
 246 #endif  
 247 #endif
 248                 /*
 249                  *      Flush the multicast chain
 250                  */
 251                 dev_mc_discard(dev);
 252                 /*
 253                  *      Blank the IP addresses
 254                  */
 255                 dev->pa_addr = 0;
 256                 dev->pa_dstaddr = 0;
 257                 dev->pa_brdaddr = 0;
 258                 dev->pa_mask = 0;
 259                 /*
 260                  *      Purge any queued packets when we down the link 
 261                  */
 262                 while(ct<DEV_NUMBUFFS)
 263                 {
 264                         struct sk_buff *skb;
 265                         while((skb=skb_dequeue(&dev->buffs[ct]))!=NULL)
 266                                 if(skb->free)
 267                                         kfree_skb(skb,FREE_WRITE);
 268                         ct++;
 269                 }
 270         }
 271         return(0);
 272 }
 273 
 274 
 275 /*
 276  *      Device change register/unregister. These are not inline or static
 277  *      as we export them to the world.
 278  */
 279 
 280 int register_netdevice_notifier(struct notifier_block *nb)
     /* [previous][next][first][last][top][bottom][index][help] */
 281 {
 282         return notifier_chain_register(&netdev_chain, nb);
 283 }
 284 
 285 int unregister_netdevice_notifier(struct notifier_block *nb)
     /* [previous][next][first][last][top][bottom][index][help] */
 286 {
 287         return notifier_chain_unregister(&netdev_chain,nb);
 288 }
 289 
 290 
 291 
 292 /*
 293  *      Send (or queue for sending) a packet. 
 294  *
 295  *      IMPORTANT: When this is called to resend frames. The caller MUST
 296  *      already have locked the sk_buff. Apart from that we do the
 297  *      rest of the magic.
 298  */
 299 
 300 void dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
     /* [previous][next][first][last][top][bottom][index][help] */
 301 {
 302         unsigned long flags;
 303         int nitcount;
 304         struct packet_type *ptype;
 305         int where = 0;          /* used to say if the packet should go  */
 306                                 /* at the front or the back of the      */
 307                                 /* queue - front is a retransmit try    */
 308 
 309         if (dev == NULL) 
 310         {
 311                 printk("dev.c: dev_queue_xmit: dev = NULL\n");
 312                 return;
 313         }
 314         
 315         if(pri>=0 && !skb_device_locked(skb))
 316                 skb_device_lock(skb);   /* Shove a lock on the frame */
 317 #ifdef CONFIG_SLAVE_BALANCING
 318         save_flags(flags);
 319         cli();
 320         if(dev->slave!=NULL && dev->slave->pkt_queue < dev->pkt_queue &&
 321                                 (dev->slave->flags & IFF_UP))
 322                 dev=dev->slave;
 323         restore_flags(flags);
 324 #endif          
 325 #ifdef CONFIG_SKB_CHECK 
 326         IS_SKB(skb);
 327 #endif    
 328         skb->dev = dev;
 329 
 330         /*
 331          *      This just eliminates some race conditions, but not all... 
 332          */
 333 
 334         if (skb->next != NULL) 
 335         {
 336                 /*
 337                  *      Make sure we haven't missed an interrupt. 
 338                  */
 339                 printk("dev_queue_xmit: worked around a missed interrupt\n");
 340                 start_bh_atomic();
 341                 dev->hard_start_xmit(NULL, dev);
 342                 end_bh_atomic();
 343                 return;
 344         }
 345 
 346         /*
 347          *      Negative priority is used to flag a frame that is being pulled from the
 348          *      queue front as a retransmit attempt. It therefore goes back on the queue
 349          *      start on a failure.
 350          */
 351          
 352         if (pri < 0) 
 353         {
 354                 pri = -pri-1;
 355                 where = 1;
 356         }
 357 
 358         if (pri >= DEV_NUMBUFFS) 
 359         {
 360                 printk("bad priority in dev_queue_xmit.\n");
 361                 pri = 1;
 362         }
 363 
 364         /*
 365          *      If the address has not been resolved. Call the device header rebuilder.
 366          *      This can cover all protocols and technically not just ARP either.
 367          */
 368          
 369         if (!skb->arp && dev->rebuild_header(skb->data, dev, skb->raddr, skb)) {
 370                 return;
 371         }
 372 
 373         save_flags(flags);
 374         cli();  
 375         if (!where) {
 376 #ifdef CONFIG_SLAVE_BALANCING   
 377                 skb->in_dev_queue=1;
 378 #endif          
 379                 skb_queue_tail(dev->buffs + pri,skb);
 380                 skb_device_unlock(skb);         /* Buffer is on the device queue and can be freed safely */
 381                 skb = skb_dequeue(dev->buffs + pri);
 382                 skb_device_lock(skb);           /* New buffer needs locking down */
 383 #ifdef CONFIG_SLAVE_BALANCING           
 384                 skb->in_dev_queue=0;
 385 #endif          
 386         }
 387         restore_flags(flags);
 388 
 389         /* copy outgoing packets to any sniffer packet handlers */
 390         if(!where)
 391         {
 392                 for (nitcount= dev_nit, ptype = ptype_base; nitcount > 0 && ptype != NULL; ptype = ptype->next) 
 393                 {
 394                         /* Never send packets back to the socket
 395                          * they originated from - MvS (miquels@drinkel.ow.org)
 396                          */
 397                         if (ptype->type == htons(ETH_P_ALL) &&
 398                            (ptype->dev == dev || !ptype->dev) &&
 399                            ((struct sock *)ptype->data != skb->sk))
 400                         {
 401                                 struct sk_buff *skb2;
 402                                 if ((skb2 = skb_clone(skb, GFP_ATOMIC)) == NULL)
 403                                         break;
 404                                 /*
 405                                  *      The protocol knows this has (for other paths) been taken off
 406                                  *      and adds it back.
 407                                  */
 408                                 skb2->len-=skb->dev->hard_header_len;
 409                                 ptype->func(skb2, skb->dev, ptype);
 410                                 nitcount--;
 411                         }
 412                 }
 413         }
 414         start_bh_atomic();
 415         if (dev->hard_start_xmit(skb, dev) == 0) {
 416                 end_bh_atomic();
 417                 /*
 418                  *      Packet is now solely the responsibility of the driver
 419                  */
 420                 return;
 421         }
 422         end_bh_atomic();
 423 
 424         /*
 425          *      Transmission failed, put skb back into a list. Once on the list it's safe and
 426          *      no longer device locked (it can be freed safely from the device queue)
 427          */
 428         cli();
 429 #ifdef CONFIG_SLAVE_BALANCING
 430         skb->in_dev_queue=1;
 431         dev->pkt_queue++;
 432 #endif          
 433         skb_device_unlock(skb);
 434         skb_queue_head(dev->buffs + pri,skb);
 435         restore_flags(flags);
 436 }
 437 
 438 /*
 439  *      Receive a packet from a device driver and queue it for the upper
 440  *      (protocol) levels.  It always succeeds. This is the recommended 
 441  *      interface to use.
 442  */
 443 
 444 void netif_rx(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 445 {
 446         static int dropping = 0;
 447 
 448         /*
 449          *      Any received buffers are un-owned and should be discarded
 450          *      when freed. These will be updated later as the frames get
 451          *      owners.
 452          */
 453         skb->sk = NULL;
 454         skb->free = 1;
 455         if(skb->stamp.tv_sec==0)
 456                 skb->stamp = xtime;
 457 
 458         /*
 459          *      Check that we aren't overdoing things.
 460          */
 461 
 462         if (!backlog_size)
 463                 dropping = 0;
 464         else if (backlog_size > 300)
 465                 dropping = 1;
 466 
 467         if (dropping) 
 468         {
 469                 kfree_skb(skb, FREE_READ);
 470                 return;
 471         }
 472 
 473         /*
 474          *      Add it to the "backlog" queue. 
 475          */
 476 #ifdef CONFIG_SKB_CHECK
 477         IS_SKB(skb);
 478 #endif  
 479         skb_queue_tail(&backlog,skb);
 480         backlog_size++;
 481   
 482         /*
 483          *      If any packet arrived, mark it for processing after the
 484          *      hardware interrupt returns.
 485          */
 486 
 487         mark_bh(NET_BH);
 488         return;
 489 }
 490 
 491 
 492 /*
 493  *      The old interface to fetch a packet from a device driver.
 494  *      This function is the base level entry point for all drivers that
 495  *      want to send a packet to the upper (protocol) levels.  It takes
 496  *      care of de-multiplexing the packet to the various modules based
 497  *      on their protocol ID.
 498  *
 499  *      Return values:  1 <- exit I can't do any more
 500  *                      0 <- feed me more (i.e. "done", "OK"). 
 501  *
 502  *      This function is OBSOLETE and should not be used by any new
 503  *      device.
 504  */
 505 
 506 int dev_rint(unsigned char *buff, long len, int flags, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 507 {
 508         static int dropping = 0;
 509         struct sk_buff *skb = NULL;
 510         unsigned char *to;
 511         int amount, left;
 512         int len2;
 513 
 514         if (dev == NULL || buff == NULL || len <= 0) 
 515                 return(1);
 516 
 517         if (flags & IN_SKBUFF) 
 518         {
 519                 skb = (struct sk_buff *) buff;
 520         }
 521         else
 522         {
 523                 if (dropping) 
 524                 {
 525                         if (skb_peek(&backlog) != NULL)
 526                                 return(1);
 527                         printk("INET: dev_rint: no longer dropping packets.\n");
 528                         dropping = 0;
 529                 }
 530 
 531                 skb = alloc_skb(len, GFP_ATOMIC);
 532                 if (skb == NULL) 
 533                 {
 534                         printk("dev_rint: packet dropped on %s (no memory) !\n",
 535                                dev->name);
 536                         dropping = 1;
 537                         return(1);
 538                 }
 539 
 540                 /* 
 541                  *      First we copy the packet into a buffer, and save it for later. We
 542                  *      in effect handle the incoming data as if it were from a circular buffer
 543                  */
 544 
 545                 to = skb->data;
 546                 left = len;
 547 
 548                 len2 = len;
 549                 while (len2 > 0) 
 550                 {
 551                         amount = min(len2, (unsigned long) dev->rmem_end -
 552                                                 (unsigned long) buff);
 553                         memcpy(to, buff, amount);
 554                         len2 -= amount;
 555                         left -= amount;
 556                         buff += amount;
 557                         to += amount;
 558                         if ((unsigned long) buff == dev->rmem_end)
 559                                 buff = (unsigned char *) dev->rmem_start;
 560                 }
 561         }
 562 
 563         /*
 564          *      Tag the frame and kick it to the proper receive routine
 565          */
 566          
 567         skb->len = len;
 568         skb->dev = dev;
 569         skb->free = 1;
 570 
 571         netif_rx(skb);
 572         /*
 573          *      OK, all done. 
 574          */
 575         return(0);
 576 }
 577 
 578 
 579 /*
 580  *      This routine causes all interfaces to try to send some data. 
 581  */
 582  
 583 void dev_transmit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 584 {
 585         struct device *dev;
 586 
 587         for (dev = dev_base; dev != NULL; dev = dev->next) 
 588         {
 589                 if (dev->flags != 0 && !dev->tbusy) {
 590                         /*
 591                          *      Kick the device
 592                          */
 593                         dev_tint(dev);
 594                 }
 595         }
 596 }
 597 
 598 
 599 /**********************************************************************************
 600 
 601                         Receive Queue Processor
 602                         
 603 ***********************************************************************************/
 604 
 605 /*
 606  *      This is a single non-reentrant routine which takes the received packet
 607  *      queue and throws it at the networking layers in the hope that something
 608  *      useful will emerge.
 609  */
 610  
 611 volatile char in_bh = 0;        /* Non-reentrant remember */
 612 
 613 int in_net_bh() /* Used by timer.c */
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         return(in_bh==0?0:1);
 616 }
 617 
 618 /*
 619  *      When we are called the queue is ready to grab, the interrupts are
 620  *      on and hardware can interrupt and queue to the receive queue a we
 621  *      run with no problems.
 622  *      This is run as a bottom half after an interrupt handler that does
 623  *      mark_bh(NET_BH);
 624  */
 625  
 626 void net_bh(void *tmp)
     /* [previous][next][first][last][top][bottom][index][help] */
 627 {
 628         struct sk_buff *skb;
 629         struct packet_type *ptype;
 630         struct packet_type *pt_prev;
 631         unsigned short type;
 632 
 633         /*
 634          *      Atomically check and mark our BUSY state. 
 635          */
 636 
 637         if (set_bit(1, (void*)&in_bh))
 638                 return;
 639 
 640         /*
 641          *      Can we send anything now? We want to clear the
 642          *      decks for any more sends that get done as we
 643          *      process the input.
 644          */
 645 
 646         dev_transmit();
 647   
 648         /*
 649          *      Any data left to process. This may occur because a
 650          *      mark_bh() is done after we empty the queue including
 651          *      that from the device which does a mark_bh() just after
 652          */
 653 
 654         cli();
 655         
 656         /*
 657          *      While the queue is not empty
 658          */
 659          
 660         while((skb=skb_dequeue(&backlog))!=NULL)
 661         {
 662                 /*
 663                  *      We have a packet. Therefore the queue has shrunk
 664                  */
 665                 backlog_size--;
 666 
 667                 sti();
 668                 
 669                /*
 670                 *       Bump the pointer to the next structure.
 671                 *       This assumes that the basic 'skb' pointer points to
 672                 *       the MAC header, if any (as indicated by its "length"
 673                 *       field).  Take care now!
 674                 */
 675 
 676                 skb->h.raw = skb->data + skb->dev->hard_header_len;
 677                 skb->len -= skb->dev->hard_header_len;
 678 
 679                /*
 680                 *       Fetch the packet protocol ID.  This is also quite ugly, as
 681                 *       it depends on the protocol driver (the interface itself) to
 682                 *       know what the type is, or where to get it from.  The Ethernet
 683                 *       interfaces fetch the ID from the two bytes in the Ethernet MAC
 684                 *       header (the h_proto field in struct ethhdr), but other drivers
 685                 *       may either use the ethernet ID's or extra ones that do not
 686                 *       clash (eg ETH_P_AX25). We could set this before we queue the
 687                 *       frame. In fact I may change this when I have time.
 688                 */
 689                 
 690                 type = skb->dev->type_trans(skb, skb->dev);
 691 
 692                 /*
 693                  *      We got a packet ID.  Now loop over the "known protocols"
 694                  *      table (which is actually a linked list, but this will
 695                  *      change soon if I get my way- FvK), and forward the packet
 696                  *      to anyone who wants it.
 697                  *
 698                  *      [FvK didn't get his way but he is right this ought to be
 699                  *      hashed so we typically get a single hit. The speed cost
 700                  *      here is minimal but no doubt adds up at the 4,000+ pkts/second
 701                  *      rate we can hit flat out]
 702                  */
 703                 pt_prev = NULL;
 704                 for (ptype = ptype_base; ptype != NULL; ptype = ptype->next) 
 705                 {
 706                         if ((ptype->type == type || ptype->type == htons(ETH_P_ALL)) && (!ptype->dev || ptype->dev==skb->dev))
 707                         {
 708                                 /*
 709                                  *      We already have a match queued. Deliver
 710                                  *      to it and then remember the new match
 711                                  */
 712                                 if(pt_prev)
 713                                 {
 714                                         struct sk_buff *skb2;
 715 
 716                                         skb2=skb_clone(skb, GFP_ATOMIC);
 717 
 718                                         /*
 719                                          *      Kick the protocol handler. This should be fast
 720                                          *      and efficient code.
 721                                          */
 722 
 723                                         if(skb2)
 724                                                 pt_prev->func(skb2, skb->dev, pt_prev);
 725                                 }
 726                                 /* Remember the current last to do */
 727                                 pt_prev=ptype;
 728                         }
 729                 } /* End of protocol list loop */
 730                 
 731                 /*
 732                  *      Is there a last item to send to ?
 733                  */
 734 
 735                 if(pt_prev)
 736                         pt_prev->func(skb, skb->dev, pt_prev);
 737                 /*
 738                  *      Has an unknown packet has been received ?
 739                  */
 740          
 741                 else
 742                         kfree_skb(skb, FREE_WRITE);
 743 
 744                 /*
 745                  *      Again, see if we can transmit anything now. 
 746                  *      [Ought to take this out judging by tests it slows
 747                  *       us down not speeds us up]
 748                  */
 749 
 750                 dev_transmit();
 751                 cli();
 752         }       /* End of queue loop */
 753         
 754         /*
 755          *      We have emptied the queue
 756          */
 757          
 758         in_bh = 0;
 759         sti();
 760         
 761         /*
 762          *      One last output flush.
 763          */
 764          
 765         dev_transmit();
 766 }
 767 
 768 
 769 /*
 770  *      This routine is called when an device driver (i.e. an
 771  *      interface) is ready to transmit a packet.
 772  */
 773  
 774 void dev_tint(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 775 {
 776         int i;
 777         struct sk_buff *skb;
 778         unsigned long flags;
 779         
 780         save_flags(flags);      
 781         /*
 782          *      Work the queues in priority order
 783          */
 784          
 785         for(i = 0;i < DEV_NUMBUFFS; i++) 
 786         {
 787                 /*
 788                  *      Pull packets from the queue
 789                  */
 790                  
 791 
 792                 cli();
 793                 while((skb=skb_dequeue(&dev->buffs[i]))!=NULL)
 794                 {
 795                         /*
 796                          *      Stop anyone freeing the buffer while we retransmit it
 797                          */
 798                         skb_device_lock(skb);
 799                         restore_flags(flags);
 800                         /*
 801                          *      Feed them to the output stage and if it fails
 802                          *      indicate they re-queue at the front.
 803                          */
 804                         dev_queue_xmit(skb,dev,-i - 1);
 805                         /*
 806                          *      If we can take no more then stop here.
 807                          */
 808                         if (dev->tbusy)
 809                                 return;
 810                         cli();
 811                 }
 812         }
 813         restore_flags(flags);
 814 }
 815 
 816 
 817 /*
 818  *      Perform a SIOCGIFCONF call. This structure will change
 819  *      size shortly, and there is nothing I can do about it.
 820  *      Thus we will need a 'compatibility mode'.
 821  */
 822 
 823 static int dev_ifconf(char *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 824 {
 825         struct ifconf ifc;
 826         struct ifreq ifr;
 827         struct device *dev;
 828         char *pos;
 829         int len;
 830         int err;
 831 
 832         /*
 833          *      Fetch the caller's info block. 
 834          */
 835          
 836         err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
 837         if(err)
 838                 return err;
 839         memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
 840         len = ifc.ifc_len;
 841         pos = ifc.ifc_buf;
 842 
 843         /*
 844          *      We now walk the device list filling each active device
 845          *      into the array.
 846          */
 847          
 848         err=verify_area(VERIFY_WRITE,pos,len);
 849         if(err)
 850                 return err;
 851         
 852         /*
 853          *      Loop over the interfaces, and write an info block for each. 
 854          */
 855 
 856         for (dev = dev_base; dev != NULL; dev = dev->next) 
 857         {
 858                 if(!(dev->flags & IFF_UP))      /* Downed devices don't count */
 859                         continue;
 860                 memset(&ifr, 0, sizeof(struct ifreq));
 861                 strcpy(ifr.ifr_name, dev->name);
 862                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
 863                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
 864 
 865                 /*
 866                  *      Write this block to the caller's space. 
 867                  */
 868                  
 869                 memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
 870                 pos += sizeof(struct ifreq);
 871                 len -= sizeof(struct ifreq);
 872                 
 873                 /*
 874                  *      Have we run out of space here ?
 875                  */
 876         
 877                 if (len < sizeof(struct ifreq)) 
 878                         break;
 879         }
 880 
 881         /*
 882          *      All done.  Write the updated control block back to the caller. 
 883          */
 884          
 885         ifc.ifc_len = (pos - ifc.ifc_buf);
 886         ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
 887         memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
 888         
 889         /*
 890          *      Report how much was filled in
 891          */
 892          
 893         return(pos - arg);
 894 }
 895 
 896 
 897 /*
 898  *      This is invoked by the /proc filesystem handler to display a device
 899  *      in detail.
 900  */
 901 
 902 static int sprintf_stats(char *buffer, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 903 {
 904         struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
 905         int size;
 906         
 907         if (stats)
 908                 size = sprintf(buffer, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
 909                    dev->name,
 910                    stats->rx_packets, stats->rx_errors,
 911                    stats->rx_dropped + stats->rx_missed_errors,
 912                    stats->rx_fifo_errors,
 913                    stats->rx_length_errors + stats->rx_over_errors
 914                    + stats->rx_crc_errors + stats->rx_frame_errors,
 915                    stats->tx_packets, stats->tx_errors, stats->tx_dropped,
 916                    stats->tx_fifo_errors, stats->collisions,
 917                    stats->tx_carrier_errors + stats->tx_aborted_errors
 918                    + stats->tx_window_errors + stats->tx_heartbeat_errors);
 919         else
 920                 size = sprintf(buffer, "%6s: No statistics available.\n", dev->name);
 921 
 922         return size;
 923 }
 924 
 925 /*
 926  *      Called from the PROCfs module. This now uses the new arbitrary sized /proc/net interface
 927  *      to create /proc/net/dev
 928  */
 929  
 930 int dev_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
 931 {
 932         int len=0;
 933         off_t begin=0;
 934         off_t pos=0;
 935         int size;
 936         
 937         struct device *dev;
 938 
 939 
 940         size = sprintf(buffer, "Inter-|   Receive                  |  Transmit\n"
 941                             " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
 942         
 943         pos+=size;
 944         len+=size;
 945         
 946 
 947         for (dev = dev_base; dev != NULL; dev = dev->next) 
 948         {
 949                 size = sprintf_stats(buffer+len, dev);
 950                 len+=size;
 951                 pos=begin+len;
 952                                 
 953                 if(pos<offset)
 954                 {
 955                         len=0;
 956                         begin=pos;
 957                 }
 958                 if(pos>offset+length)
 959                         break;
 960         }
 961         
 962         *start=buffer+(offset-begin);   /* Start of wanted data */
 963         len-=(offset-begin);            /* Start slop */
 964         if(len>length)
 965                 len=length;             /* Ending slop */
 966         return len;
 967 }
 968 
 969 
 970 /*
 971  *      This checks bitmasks for the ioctl calls for devices.
 972  */
 973  
 974 static inline int bad_mask(unsigned long mask, unsigned long addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 975 {
 976         if (addr & (mask = ~mask))
 977                 return 1;
 978         mask = ntohl(mask);
 979         if (mask & (mask+1))
 980                 return 1;
 981         return 0;
 982 }
 983 
 984 /*
 985  *      Perform the SIOCxIFxxx calls. 
 986  *
 987  *      The socket layer has seen an ioctl the address family thinks is
 988  *      for the device. At this point we get invoked to make a decision
 989  */
 990  
 991 static int dev_ifsioc(void *arg, unsigned int getset)
     /* [previous][next][first][last][top][bottom][index][help] */
 992 {
 993         struct ifreq ifr;
 994         struct device *dev;
 995         int ret;
 996 
 997         /*
 998          *      Fetch the caller's info block into kernel space
 999          */
1000 
1001         int err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
1002         if(err)
1003                 return err;
1004         
1005         memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
1006 
1007         /*
1008          *      See which interface the caller is talking about. 
1009          */
1010          
1011         if ((dev = dev_get(ifr.ifr_name)) == NULL) 
1012                 return(-ENODEV);
1013 
1014         switch(getset) 
1015         {
1016                 case SIOCGIFFLAGS:      /* Get interface flags */
1017                         ifr.ifr_flags = dev->flags;
1018                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1019                         ret = 0;
1020                         break;
1021                 case SIOCSIFFLAGS:      /* Set interface flags */
1022                         {
1023                                 int old_flags = dev->flags;
1024 #ifdef CONFIG_SLAVE_BALANCING                           
1025                                 if(dev->flags&IFF_SLAVE)
1026                                         return -EBUSY;
1027 #endif                                  
1028                                 dev->flags = ifr.ifr_flags & (
1029                                         IFF_UP | IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
1030                                         IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
1031                                         IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI | IFF_SLAVE | IFF_MASTER
1032                                         | IFF_MULTICAST);
1033 #ifdef CONFIG_SLAVE_BALANCING                           
1034                                 if(!(dev->flags&IFF_MASTER) && dev->slave)
1035                                 {
1036                                         dev->slave->flags&=~IFF_SLAVE;
1037                                         dev->slave=NULL;
1038                                 }
1039 #endif
1040                                 /*
1041                                  *      Load in the correct multicast list now the flags have changed.
1042                                  */                             
1043 
1044                                 dev_mc_upload(dev);
1045 #if 0
1046                                 if( dev->set_multicast_list!=NULL)
1047                                 {
1048                                 
1049                                         /*
1050                                          *      Has promiscuous mode been turned off
1051                                          */     
1052                                 
1053                                         if ( (old_flags & IFF_PROMISC) && ((dev->flags & IFF_PROMISC) == 0))
1054                                                 dev->set_multicast_list(dev,0,NULL);
1055                                         
1056                                         /*
1057                                          *      Has it been turned on
1058                                          */
1059         
1060                                         if ( (dev->flags & IFF_PROMISC) && ((old_flags & IFF_PROMISC) == 0))
1061                                                 dev->set_multicast_list(dev,-1,NULL);
1062                                 }
1063 #endif                                  
1064                                 /*
1065                                  *      Have we downed the interface
1066                                  */
1067                 
1068                                 if ((old_flags & IFF_UP) && ((dev->flags & IFF_UP) == 0)) 
1069                                 {
1070                                         ret = dev_close(dev);
1071                                 }
1072                                 else
1073                                 {
1074                                         /*
1075                                          *      Have we upped the interface 
1076                                          */
1077                                          
1078                                         ret = (! (old_flags & IFF_UP) && (dev->flags & IFF_UP))
1079                                                 ? dev_open(dev) : 0;
1080                                         /* 
1081                                          *      Check the flags.
1082                                          */
1083                                         if(ret<0)
1084                                                 dev->flags&=~IFF_UP;    /* Didn't open so down the if */
1085                                 }
1086                         }
1087                         break;
1088                 
1089                 case SIOCGIFADDR:       /* Get interface address (and family) */
1090                         (*(struct sockaddr_in *)
1091                                   &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
1092                         (*(struct sockaddr_in *)
1093                                   &ifr.ifr_addr).sin_family = dev->family;
1094                         (*(struct sockaddr_in *)
1095                                   &ifr.ifr_addr).sin_port = 0;
1096                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1097                         ret = 0;
1098                         break;
1099         
1100                 case SIOCSIFADDR:       /* Set interface address (and family) */
1101                         dev->pa_addr = (*(struct sockaddr_in *)
1102                                  &ifr.ifr_addr).sin_addr.s_addr;
1103                         dev->family = ifr.ifr_addr.sa_family;
1104                         
1105 #ifdef CONFIG_INET      
1106                         /* This is naughty. When net-032e comes out It wants moving into the net032
1107                            code not the kernel. Till then it can sit here (SIGH) */             
1108                         dev->pa_mask = ip_get_mask(dev->pa_addr);
1109 #endif                  
1110                         dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
1111                         ret = 0;
1112                         break;
1113                         
1114                 case SIOCGIFBRDADDR:    /* Get the broadcast address */
1115                         (*(struct sockaddr_in *)
1116                                 &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
1117                         (*(struct sockaddr_in *)
1118                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1119                         (*(struct sockaddr_in *)
1120                                 &ifr.ifr_broadaddr).sin_port = 0;
1121                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1122                         ret = 0;
1123                         break;
1124 
1125                 case SIOCSIFBRDADDR:    /* Set the broadcast address */
1126                         dev->pa_brdaddr = (*(struct sockaddr_in *)
1127                                 &ifr.ifr_broadaddr).sin_addr.s_addr;
1128                         ret = 0;
1129                         break;
1130                         
1131                 case SIOCGIFDSTADDR:    /* Get the destination address (for point-to-point links) */
1132                         (*(struct sockaddr_in *)
1133                                 &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
1134                         (*(struct sockaddr_in *)
1135                                 &ifr.ifr_broadaddr).sin_family = dev->family;
1136                         (*(struct sockaddr_in *)
1137                                 &ifr.ifr_broadaddr).sin_port = 0;
1138                                 memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1139                         ret = 0;
1140                         break;
1141         
1142                 case SIOCSIFDSTADDR:    /* Set the destination address (for point-to-point links) */
1143                         dev->pa_dstaddr = (*(struct sockaddr_in *)
1144                                 &ifr.ifr_dstaddr).sin_addr.s_addr;
1145                         ret = 0;
1146                         break;
1147                         
1148                 case SIOCGIFNETMASK:    /* Get the netmask for the interface */
1149                         (*(struct sockaddr_in *)
1150                                 &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
1151                         (*(struct sockaddr_in *)
1152                                 &ifr.ifr_netmask).sin_family = dev->family;
1153                         (*(struct sockaddr_in *)
1154                                 &ifr.ifr_netmask).sin_port = 0;
1155                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1156                         ret = 0;
1157                         break;
1158 
1159                 case SIOCSIFNETMASK:    /* Set the netmask for the interface */
1160                         {
1161                                 unsigned long mask = (*(struct sockaddr_in *)
1162                                         &ifr.ifr_netmask).sin_addr.s_addr;
1163                                 ret = -EINVAL;
1164                                 /*
1165                                  *      The mask we set must be legal.
1166                                  */
1167                                 if (bad_mask(mask,0))
1168                                         break;
1169                                 dev->pa_mask = mask;
1170                                 ret = 0;
1171                         }
1172                         break;
1173                         
1174                 case SIOCGIFMETRIC:     /* Get the metric on the interface (currently unused) */
1175                         
1176                         ifr.ifr_metric = dev->metric;
1177                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1178                         ret = 0;
1179                         break;
1180                         
1181                 case SIOCSIFMETRIC:     /* Set the metric on the interface (currently unused) */
1182                         dev->metric = ifr.ifr_metric;
1183                         ret = 0;
1184                         break;
1185         
1186                 case SIOCGIFMTU:        /* Get the MTU of a device */
1187                         ifr.ifr_mtu = dev->mtu;
1188                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
1189                         ret = 0;
1190                         break;
1191         
1192                 case SIOCSIFMTU:        /* Set the MTU of a device */
1193                 
1194                         /*
1195                          *      MTU must be positive and under the page size problem
1196                          */
1197                          
1198                         if(ifr.ifr_mtu<1 || ifr.ifr_mtu>3800)
1199                                 return -EINVAL;
1200                         dev->mtu = ifr.ifr_mtu;
1201                         ret = 0;
1202                         break;
1203         
1204                 case SIOCGIFMEM:        /* Get the per device memory space. We can add this but currently
1205                                            do not support it */
1206                         printk("NET: ioctl(SIOCGIFMEM, %p)\n", arg);
1207                         ret = -EINVAL;
1208                         break;
1209                 
1210                 case SIOCSIFMEM:        /* Set the per device memory buffer space. Not applicable in our case */
1211                         printk("NET: ioctl(SIOCSIFMEM, %p)\n", arg);
1212                         ret = -EINVAL;
1213                         break;
1214 
1215                 case OLD_SIOCGIFHWADDR: /* Get the hardware address. This will change and SIFHWADDR will be added */
1216                         memcpy(ifr.old_ifr_hwaddr,dev->dev_addr, MAX_ADDR_LEN);
1217                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1218                         ret=0;
1219                         break;
1220 
1221                 case SIOCGIFHWADDR:
1222                         memcpy(ifr.ifr_hwaddr.sa_data,dev->dev_addr, MAX_ADDR_LEN);
1223                         ifr.ifr_hwaddr.sa_family=dev->type;                     
1224                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1225                         ret=0;
1226                         break;
1227                         
1228                 case SIOCSIFHWADDR:
1229                         if(dev->set_mac_address==NULL)
1230                                 return -EOPNOTSUPP;
1231                         if(ifr.ifr_hwaddr.sa_family!=dev->type)
1232                                 return -EINVAL;
1233                         ret=dev->set_mac_address(dev,ifr.ifr_hwaddr.sa_data);
1234                         break;
1235                         
1236                 case SIOCGIFMAP:
1237                         ifr.ifr_map.mem_start=dev->mem_start;
1238                         ifr.ifr_map.mem_end=dev->mem_end;
1239                         ifr.ifr_map.base_addr=dev->base_addr;
1240                         ifr.ifr_map.irq=dev->irq;
1241                         ifr.ifr_map.dma=dev->dma;
1242                         ifr.ifr_map.port=dev->if_port;
1243                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1244                         ret=0;
1245                         break;
1246                         
1247                 case SIOCSIFMAP:
1248                         if(dev->set_config==NULL)
1249                                 return -EOPNOTSUPP;
1250                         return dev->set_config(dev,&ifr.ifr_map);
1251                         
1252                 case SIOCGIFSLAVE:
1253 #ifdef CONFIG_SLAVE_BALANCING           
1254                         if(dev->slave==NULL)
1255                                 return -ENOENT;
1256                         strncpy(ifr.ifr_name,dev->name,sizeof(ifr.ifr_name));
1257                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1258                         ret=0;
1259 #else
1260                         return -ENOENT;
1261 #endif                  
1262                         break;
1263 #ifdef CONFIG_SLAVE_BALANCING                   
1264                 case SIOCSIFSLAVE:
1265                 {
1266                 
1267                 /*
1268                  *      Fun game. Get the device up and the flags right without
1269                  *      letting some scummy user confuse us.
1270                  */
1271                         unsigned long flags;
1272                         struct device *slave=dev_get(ifr.ifr_slave);
1273                         save_flags(flags);
1274                         if(slave==NULL)
1275                         {
1276                                 return -ENODEV;
1277                         }
1278                         cli();
1279                         if((slave->flags&(IFF_UP|IFF_RUNNING))!=(IFF_UP|IFF_RUNNING))
1280                         {
1281                                 restore_flags(flags);
1282                                 return -EINVAL;
1283                         }
1284                         if(dev->flags&IFF_SLAVE)
1285                         {
1286                                 restore_flags(flags);
1287                                 return -EBUSY;
1288                         }
1289                         if(dev->slave!=NULL)
1290                         {
1291                                 restore_flags(flags);
1292                                 return -EBUSY;
1293                         }
1294                         if(slave->flags&IFF_SLAVE)
1295                         {
1296                                 restore_flags(flags);
1297                                 return -EBUSY;
1298                         }
1299                         dev->slave=slave;
1300                         slave->flags|=IFF_SLAVE;
1301                         dev->flags|=IFF_MASTER;
1302                         restore_flags(flags);
1303                         ret=0;
1304                 }
1305                 break;
1306 #endif                  
1307 
1308                 case SIOCADDMULTI:
1309                         if(dev->set_multicast_list==NULL)
1310                                 return -EINVAL;
1311                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1312                                 return -EINVAL;
1313                         dev_mc_add(dev,ifr.ifr_hwaddr.sa_data, dev->addr_len, 1);
1314                         return 0;
1315 
1316                 case SIOCDELMULTI:
1317                         if(dev->set_multicast_list==NULL)
1318                                 return -EINVAL;
1319                         if(ifr.ifr_hwaddr.sa_family!=AF_UNSPEC)
1320                                 return -EINVAL;
1321                         dev_mc_delete(dev,ifr.ifr_hwaddr.sa_data,dev->addr_len, 1);
1322                         return 0;
1323                 /*
1324                  *      Unknown or private ioctl
1325                  */
1326 
1327                 default:
1328                         if((getset >= SIOCDEVPRIVATE) &&
1329                            (getset <= (SIOCDEVPRIVATE + 15))) {
1330                                 if(dev->do_ioctl==NULL)
1331                                         return -EOPNOTSUPP;
1332                                 ret=dev->do_ioctl(dev, &ifr, getset);
1333                                 memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
1334                                 break;
1335                         }
1336                         
1337                         ret = -EINVAL;
1338         }
1339         return(ret);
1340 }
1341 
1342 
1343 /*
1344  *      This function handles all "interface"-type I/O control requests. The actual
1345  *      'doing' part of this is dev_ifsioc above.
1346  */
1347 
1348 int dev_ioctl(unsigned int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1349 {
1350         switch(cmd) 
1351         {
1352                 case SIOCGIFCONF:
1353                         (void) dev_ifconf((char *) arg);
1354                         return 0;
1355 
1356                 /*
1357                  *      Ioctl calls that can be done by all.
1358                  */
1359                  
1360                 case SIOCGIFFLAGS:
1361                 case SIOCGIFADDR:
1362                 case SIOCGIFDSTADDR:
1363                 case SIOCGIFBRDADDR:
1364                 case SIOCGIFNETMASK:
1365                 case SIOCGIFMETRIC:
1366                 case SIOCGIFMTU:
1367                 case SIOCGIFMEM:
1368                 case SIOCGIFHWADDR:
1369                 case SIOCSIFHWADDR:
1370                 case OLD_SIOCGIFHWADDR:
1371                 case SIOCGIFSLAVE:
1372                 case SIOCGIFMAP:
1373                         return dev_ifsioc(arg, cmd);
1374 
1375                 /*
1376                  *      Ioctl calls requiring the power of a superuser
1377                  */
1378                  
1379                 case SIOCSIFFLAGS:
1380                 case SIOCSIFADDR:
1381                 case SIOCSIFDSTADDR:
1382                 case SIOCSIFBRDADDR:
1383                 case SIOCSIFNETMASK:
1384                 case SIOCSIFMETRIC:
1385                 case SIOCSIFMTU:
1386                 case SIOCSIFMEM:
1387                 case SIOCSIFMAP:
1388                 case SIOCSIFSLAVE:
1389                 case SIOCADDMULTI:
1390                 case SIOCDELMULTI:
1391                         if (!suser())
1392                                 return -EPERM;
1393                         return dev_ifsioc(arg, cmd);
1394         
1395                 case SIOCSIFLINK:
1396                         return -EINVAL;
1397 
1398                 /*
1399                  *      Unknown or private ioctl.
1400                  */     
1401                  
1402                 default:
1403                         if((cmd >= SIOCDEVPRIVATE) &&
1404                            (cmd <= (SIOCDEVPRIVATE + 15))) {
1405                                 return dev_ifsioc(arg, cmd);
1406                         }
1407                         return -EINVAL;
1408         }
1409 }
1410 
1411 
1412 /*
1413  *      Initialize the DEV module. At boot time this walks the device list and
1414  *      unhooks any devices that fail to initialise (normally hardware not 
1415  *      present) and leaves us with a valid list of present and active devices.
1416  *
1417  *      The PCMCIA code may need to change this a little, and add a pair
1418  *      of register_inet_device() unregister_inet_device() calls. This will be
1419  *      needed for ethernet as modules support.
1420  */
1421  
1422 void dev_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1423 {
1424         struct device *dev, *dev2;
1425 
1426         /*
1427          *      Add the devices.
1428          *      If the call to dev->init fails, the dev is removed
1429          *      from the chain disconnecting the device until the
1430          *      next reboot.
1431          */
1432          
1433         dev2 = NULL;
1434         for (dev = dev_base; dev != NULL; dev=dev->next) 
1435         {
1436                 if (dev->init && dev->init(dev)) 
1437                 {
1438                         /*
1439                          *      It failed to come up. Unhook it.
1440                          */
1441                          
1442                         if (dev2 == NULL) 
1443                                 dev_base = dev->next;
1444                         else 
1445                                 dev2->next = dev->next;
1446                 } 
1447                 else
1448                 {
1449                         dev2 = dev;
1450                 }
1451         }
1452 }

/* [previous][next][first][last][top][bottom][index][help] */