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

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