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

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