root/net/socket/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_inet_bh
  12. inet_bh
  13. dev_tint
  14. dev_ifconf
  15. sprintf_stats
  16. dev_get_info
  17. dev_ifsioc
  18. dev_ioctl
  19. eth_setup
  20. dev_init

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Interface (streams) handling functions.
   7  *
   8  * Version:     @(#)dev.c       1.28    20/12/93
   9  *
  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  * Fixes:       
  15  *              Alan Cox:       check_addr returns a value for a wrong subnet
  16  *                              ie not us but don't forward this!
  17  *              Alan Cox:       block timer if the inet_bh handler is running
  18  *              Alan Cox:       generic queue code added. A lot neater now
  19  *              C.E.Hawkins:    SIOCGIFCONF only reports 'upped' interfaces
  20  *              C.E.Hawkins:    IFF_PROMISC support
  21  *              Alan Cox:       Supports Donald Beckers new hardware 
  22  *                              multicast layer, but not yet multicast lists.
  23  *              Alan Cox:       ip_addr_match problems with class A/B nets.
  24  *              C.E.Hawkins     IP 0.0.0.0 and also same net route fix. [FIXME: Ought to cause ICMP_REDIRECT]
  25  *              Alan Cox:       Removed bogus subnet check now the subnet code
  26  *                              a) actually works for all A/B nets
  27  *                              b) doesn't forward off the same interface.
  28  *              Alan Cox:       Multiple extra protocols
  29  *              Alan Cox:       A Couple more escaped verify_area calls die
  30  *              Alan Cox:       IP_SET_DEV is gone (forever) as per Fred's comment.
  31  *              Alan Cox:       Grand tidy up ready for the big day.
  32  *              Alan Cox:       Handles dev_open errors correctly.
  33  *              Alan Cox:       IP part split from main section
  34  *
  35  *              This program is free software; you can redistribute it and/or
  36  *              modify it under the terms of the GNU General Public License
  37  *              as published by the Free Software Foundation; either version
  38  *              2 of the License, or (at your option) any later version.
  39  */
  40 
  41 #include <asm/segment.h>
  42 #include <asm/system.h>
  43 #include <asm/bitops.h>
  44 #include <linux/config.h>
  45 #include <linux/types.h>
  46 #include <linux/kernel.h>
  47 #include <linux/sched.h>
  48 #include <linux/string.h>
  49 #include <linux/mm.h>
  50 #include <linux/socket.h>
  51 #include <linux/sockios.h>
  52 #include <linux/in.h>
  53 #include <linux/errno.h>
  54 #include <linux/interrupt.h>
  55 #include <linux/if_ether.h>
  56 #include "inet.h"
  57 #include "dev.h"
  58 #include "eth.h"
  59 #include "ip.h"
  60 #include "route.h"
  61 #include "protocol.h"
  62 #include "tcp.h"
  63 #include "skbuff.h"
  64 #include "sock.h"
  65 #include "arp.h"
  66 #ifdef CONFIG_AX25
  67 #include "ax25/ax25.h"
  68 #endif
  69 #ifdef CONFIG_IPX
  70 #include "ipx/ipx.h"
  71 #endif
  72 
  73 
  74 #ifdef CONFIG_IPX
  75 
  76 /*
  77  *      These describe how each lowest level protocol is processed.
  78  */
  79  
  80 static struct packet_type ipx_8023_type = 
  81 {
  82         NET16(ETH_P_802_3),
  83         0,
  84         ipx_rcv,
  85         NULL,
  86         NULL
  87 };
  88 
  89 static struct packet_type ipx_packet_type = 
  90 {
  91         NET16(ETH_P_IPX),       /* IPX over DIX - eg PDIPX */
  92         0,
  93         ipx_rcv,
  94         NULL,
  95         &ipx_8023_type
  96 };
  97 
  98 #endif
  99 
 100 #ifdef CONFIG_AX25
 101 
 102 static struct packet_type ax25_packet_type = 
 103 {
 104         NET16(ETH_P_AX25),
 105         0,
 106         ax25_rcv,
 107         NULL,
 108 #ifdef CONFIG_IPX
 109         &ipx_packet_type
 110 #else
 111         NULL
 112 #endif
 113 };
 114 #endif
 115 
 116 
 117 static struct packet_type arp_packet_type = 
 118 {
 119         NET16(ETH_P_ARP),
 120         0,              /* copy */
 121         arp_rcv,
 122         NULL,
 123 #ifdef CONFIG_IPX
 124 #ifndef CONFIG_AX25
 125         &ipx_packet_type
 126 #else
 127         &ax25_packet_type
 128 #endif
 129 #else
 130         NULL            /* next */
 131 #endif
 132 };
 133 
 134 
 135 static struct packet_type ip_packet_type = 
 136 {
 137         NET16(ETH_P_IP),
 138         0,              /* copy */
 139         ip_rcv,
 140         NULL,
 141         &arp_packet_type
 142 };
 143 
 144 /*
 145  *      The list of known protocols. Note that
 146  *      SOCK_PACKET sockets dynamically alter this.
 147  */   
 148 
 149 #ifdef CONFIG_INET
 150 struct packet_type *ptype_base = &ip_packet_type;
 151 #else
 152 #ifdef CONFIG_AX25
 153 struct packet_type *ptype_base = &ax25_packet_type;
 154 #else
 155 struct packet_type *ptype_base = &ipx_packet_type;
 156 #endif
 157 #endif
 158 
 159 /* A queue of all the packets we have to deal with */
 160 static struct sk_buff *volatile backlog = NULL;
 161 
 162 
 163 
 164 /* 
 165  *      Return the lesser of the two values. 
 166  */
 167 
 168 static unsigned long
 169 min(unsigned long a, unsigned long b)
     /* [previous][next][first][last][top][bottom][index][help] */
 170 {
 171         if (a < b) 
 172                 return(a);
 173         return(b);
 174 }
 175 
 176 
 177 
 178 
 179 /*
 180  *      Add a protocol ID to the list of known protocols
 181  *      (see SOCK_PACKET code)
 182  */
 183  
 184 void dev_add_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 185 {
 186         struct packet_type *p1;
 187 
 188         pt->next = ptype_base;
 189 
 190         /* See if we need to copy it. */
 191         for (p1 = ptype_base; p1 != NULL; p1 = p1->next) 
 192         {
 193                 if (p1->type == pt->type) 
 194                 {
 195                         pt->copy = 1;
 196                         break;
 197                 }
 198         }
 199         ptype_base = pt;
 200 }
 201 
 202 
 203 /*      
 204  *      Remove a protocol ID from the list. Also used
 205  *      for SOCK_PACKET. Maybe one day we will do loadable
 206  *      protocol layers too.
 207  */
 208  
 209 void dev_remove_pack(struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 {
 211         struct packet_type *lpt, *pt1;
 212 
 213         if (pt == ptype_base) 
 214         {
 215                 ptype_base = pt->next;
 216                 return;
 217         }
 218 
 219         lpt = NULL;
 220         for (pt1 = ptype_base; pt1->next != NULL; pt1 = pt1->next) 
 221         {
 222                 if (pt1->next == pt ) 
 223                 {
 224                         cli();
 225                         if (!pt->copy && lpt) 
 226                                 lpt->copy = 0;
 227                         pt1->next = pt->next;
 228                         sti();
 229                         return;
 230                 }
 231 
 232                 if (pt1->next -> type == pt ->type) 
 233                 {
 234                         lpt = pt1->next;
 235                 }
 236         }
 237 }
 238 
 239 
 240 /*
 241  *      Find an interface in the list.
 242  */
 243 
 244 struct device *dev_get(char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         struct device *dev;
 247 
 248         for (dev = dev_base; dev != NULL; dev = dev->next) 
 249         {
 250                 if (strcmp(dev->name, name) == 0) 
 251                 return(dev);
 252         }
 253         return(NULL);
 254 }
 255 
 256 
 257 /*
 258  *      Prepare an interface for use. 
 259  */
 260 
 261 int dev_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 262 {
 263         int ret = 0;
 264 
 265         if (dev->open) 
 266                 ret = dev->open(dev);
 267         if (ret == 0) 
 268                 dev->flags |= (IFF_UP | IFF_RUNNING);
 269 
 270         return(ret);
 271 }
 272 
 273 
 274 /*
 275  *      Completely shutdown an interface. 
 276  */
 277  
 278 int dev_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 279 {
 280         if (dev->flags != 0) 
 281         {
 282                 int ct=0;
 283                 dev->flags = 0;
 284                 if (dev->stop) 
 285                         dev->stop(dev);
 286                 rt_flush(dev);
 287                 dev->pa_addr = 0;
 288                 dev->pa_dstaddr = 0;
 289                 dev->pa_brdaddr = 0;
 290                 dev->pa_mask = 0;
 291                 /* Purge any queued packets when we down the link */
 292                 while(ct<DEV_NUMBUFFS)
 293                 {
 294                         struct sk_buff *skb;
 295                         while((skb=skb_dequeue(&dev->buffs[ct]))!=NULL)
 296                                 if(skb->free)
 297                                         kfree_skb(skb,FREE_WRITE);
 298                         ct++;
 299                 }
 300         }
 301 
 302         return(0);
 303 }
 304 
 305 
 306 /*
 307  *      Send (or queue for sending) a packet.
 308  */
 309  
 310 void dev_queue_xmit(struct sk_buff *skb, struct device *dev, int pri)
     /* [previous][next][first][last][top][bottom][index][help] */
 311 {
 312         int where = 0;          /* used to say if the packet should go  */
 313                                 /* at the front or the back of the      */
 314                                 /* queue.                               */
 315 
 316         DPRINTF((DBG_DEV, "dev_queue_xmit(skb=%X, dev=%X, pri = %d)\n",
 317                                                         skb, dev, pri));
 318 
 319         if (dev == NULL) 
 320         {
 321                 printk("dev.c: dev_queue_xmit: dev = NULL\n");
 322                 return;
 323         }
 324  
 325         IS_SKB(skb);
 326     
 327         skb->dev = dev;
 328         if (skb->next != NULL) 
 329         {
 330                 /* Make sure we haven't missed an interrupt. */
 331                 dev->hard_start_xmit(NULL, dev);
 332                 return;
 333         }
 334 
 335         if (pri < 0) 
 336         {
 337                 pri = -pri-1;
 338                 where = 1;
 339         }
 340 
 341         if (pri >= DEV_NUMBUFFS) 
 342         {
 343                 printk("bad priority in dev_queue_xmit.\n");
 344                 pri = 1;
 345         }
 346 
 347         if (dev->hard_start_xmit(skb, dev) == 0) 
 348         {
 349                 /* It went out without fuss */
 350                 return;
 351         }
 352 
 353         /* The driver was busy.. */
 354         /* Put skb into a bidirectional circular linked list. */
 355         DPRINTF((DBG_DEV, "dev_queue_xmit dev->buffs[%d]=%X\n",
 356                                         pri, dev->buffs[pri]));
 357 
 358         /* Interrupts should already be cleared by hard_start_xmit. */
 359         cli();
 360         skb->magic = DEV_QUEUE_MAGIC;
 361         if(where)
 362                 skb_queue_head(&dev->buffs[pri],skb);
 363         else
 364                 skb_queue_tail(&dev->buffs[pri],skb);
 365         skb->magic = DEV_QUEUE_MAGIC;
 366         sti();
 367 }
 368 
 369 /*
 370  *      Receive a packet from a device driver and queue it for the upper
 371  *      (protocol) levels.  It always succeeds.
 372  */
 373 
 374 void netif_rx(struct sk_buff *skb)
     /* [previous][next][first][last][top][bottom][index][help] */
 375 {
 376         /* Set any necessary flags. */
 377         skb->sk = NULL;
 378         skb->free = 1;
 379   
 380         /* and add it to the "backlog" queue. */
 381         IS_SKB(skb);
 382         skb_queue_tail(&backlog,skb);
 383    
 384         /* If any packet arrived, mark it for processing. */
 385         if (backlog != NULL)
 386                 mark_bh(INET_BH);
 387 
 388         return;
 389 }
 390 
 391 
 392 /*
 393  *      The old interface to fetch a packet from a device driver.
 394  *      This function is the base level entry point for all drivers that
 395  *      want to send a packet to the upper (protocol) levels.  It takes
 396  *      care of de-multiplexing the packet to the various modules based
 397  *      on their protocol ID.
 398  *
 399  *       Return values:         1 <- exit I can't do any more
 400  *                              0 <- feed me more (i.e. "done", "OK"). 
 401  *
 402  *      THIS FUNCTION IS OBSOLETE: DO NOT USE IT ANY MORE!!!!
 403  */
 404 int dev_rint(unsigned char *buff, long len, int flags, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 405 {
 406         static int dropping = 0;
 407         struct sk_buff *skb = NULL;
 408         unsigned char *to;
 409         int amount, left;
 410         int len2;
 411 
 412         if (dev == NULL || buff == NULL || len <= 0)    
 413                 return(1);
 414         if (flags & IN_SKBUFF) 
 415         {
 416                 skb = (struct sk_buff *) buff;
 417         } 
 418         else 
 419         {
 420                 if (dropping) 
 421                 {
 422                         if (backlog != NULL)
 423                                 return(1);
 424                         printk("INET: dev_rint: no longer dropping packets.\n");
 425                         dropping = 0;
 426                 }
 427 
 428                 skb = alloc_skb(sizeof(*skb) + len, GFP_ATOMIC);
 429                 if (skb == NULL) 
 430                 {
 431                         printk("dev_rint: packet dropped on %s (no memory) !\n",
 432                                dev->name);
 433                         dropping = 1;
 434                         return(1);
 435                 }
 436 
 437                 /* First we copy the packet into a buffer, and save it for later. */
 438                 to = (unsigned char *) (skb + 1);
 439                 left = len;
 440                 len2 = len;
 441                 while (len2 > 0) 
 442                 {
 443                         amount = min(len2, (unsigned long) dev->rmem_end -
 444                                                 (unsigned long) buff);
 445                         memcpy(to, buff, amount);
 446                         len2 -= amount;
 447                         left -= amount;
 448                         buff += amount;
 449                         to += amount;
 450                         if ((unsigned long) buff == dev->rmem_end)
 451                                 buff = (unsigned char *) dev->rmem_start;
 452                 }
 453         }
 454         skb->len = len;
 455         skb->dev = dev;
 456         skb->free = 1;
 457 
 458         netif_rx(skb);
 459         /* OK, all done. */
 460         return(0);
 461 }
 462 
 463 
 464 /* 
 465  *      This routine causes all interfaces to try to send some data. 
 466  */
 467 
 468 void dev_transmit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 469 {
 470         struct device *dev;
 471 
 472         for (dev = dev_base; dev != NULL; dev = dev->next) 
 473         {
 474                 if (!dev->tbusy) 
 475                 {
 476                         dev_tint(dev);
 477                 }
 478         }
 479 }
 480 
 481 
 482 /* We need to know if we are re-entering the bottom level handler
 483    for the network */
 484    
 485 static volatile char in_bh = 0;
 486 
 487 int in_inet_bh()        /* Used by timer.c */
     /* [previous][next][first][last][top][bottom][index][help] */
 488 {
 489         return(in_bh==0?0:1);
 490 }
 491 
 492 /*
 493  * This function gets called periodically, to see if we can
 494  * process any data that came in from some interface.
 495  *
 496  */
 497 void inet_bh(void *tmp)
     /* [previous][next][first][last][top][bottom][index][help] */
 498 {
 499         struct sk_buff *skb;
 500         struct packet_type *ptype;
 501         unsigned short type;
 502         unsigned char flag = 0;
 503 
 504 
 505         /* Atomically check and mark our BUSY state. */
 506         if (set_bit(1, (void*)&in_bh))
 507                 return;
 508 
 509         /* Can we send anything now? */
 510         dev_transmit();
 511   
 512         /* Any data left to process? */
 513         while((skb=skb_dequeue(&backlog))!=NULL)
 514         {
 515                 flag=0;
 516                 sti();
 517                 /*
 518                  * Bump the pointer to the next structure.
 519                  * This assumes that the basic 'skb' pointer points to
 520                  * the MAC header, if any (as indicated by its "length"
 521                  * field).  Take care now!
 522                  */
 523                 skb->h.raw = (unsigned char *) (skb + 1) + skb->dev->hard_header_len;
 524                 skb->len -= skb->dev->hard_header_len;
 525 
 526                 /*
 527                  * Fetch the packet protocol ID.  This is also quite ugly, as
 528                  * it depends on the protocol driver (the interface itself) to
 529                  * know what the type is, or where to get it from.  The Ethernet
 530                  * interfaces fetch the ID from the two bytes in the Ethernet MAC
 531                  * header (the h_proto field in struct ethhdr), but drivers like
 532                  * SLIP and PLIP have no alternative but to force the type to be
 533                  * IP or something like that.  Sigh- FvK
 534                  */
 535                 type = skb->dev->type_trans(skb, skb->dev);
 536 
 537                 /*
 538                  * We got a packet ID.  Now loop over the "known protocols"
 539                  * table (which is actually a linked list, but this will
 540                  * change soon if I get my way- FvK), and forward the packet
 541                  * to anyone who wants it.
 542                  */
 543                 for (ptype = ptype_base; ptype != NULL; ptype = ptype->next) 
 544                 {
 545                         if (ptype->type == type) 
 546                         {
 547                                 struct sk_buff *skb2;
 548         
 549                                 if (ptype->copy) 
 550                                 {       /* copy if we need to   */
 551                                         skb2 = alloc_skb(skb->mem_len, GFP_ATOMIC);
 552                                         if (skb2 == NULL) 
 553                                                 continue;
 554                                         memcpy(skb2, (const void *) skb, skb->mem_len);
 555                                         skb2->mem_addr=skb2;
 556                                         skb2->h.raw = (unsigned char *)
 557                                         (
 558                                             (unsigned long) skb2 +
 559                                             (unsigned long) skb->h.raw -
 560                                             (unsigned long) skb
 561                                         );
 562                                         skb2->free = 1;
 563                                 } 
 564                                 else 
 565                                 {
 566                                         skb2 = skb;
 567                                 }
 568 
 569                                 /* This used to be in the 'else' part, but then
 570                                  * we don't have this flag set when we get a
 571                                  * protocol that *does* require copying... -FvK
 572                                  */
 573                                 flag = 1;
 574 
 575                                 /* Kick the protocol handler. */
 576                                 ptype->func(skb2, skb->dev, ptype);
 577                         }
 578                 }
 579 
 580                 /*
 581                  * That's odd.  We got an unknown packet.  Who's using
 582                  * stuff like Novell or Amoeba on this network??
 583                  */
 584                 if (!flag) 
 585                 {
 586                         DPRINTF((DBG_DEV,
 587                                 "INET: unknown packet type 0x%04X (ignored)\n", type));
 588                         skb->sk = NULL;
 589                         kfree_skb(skb, FREE_WRITE);
 590                 }
 591 
 592                 /* Again, see if we can transmit anything now. */
 593                 dev_transmit();
 594                 cli();
 595         }
 596         in_bh = 0;
 597         sti();
 598         dev_transmit(); /* Try and kick anything this processing produced */
 599 }
 600 
 601 
 602 /*
 603  *      This routine is called when an device driver (i.e. an
 604  *      interface) is * ready to transmit a packet.
 605  */
 606  
 607 void dev_tint(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 608 {
 609         int i;
 610         struct sk_buff *skb;
 611         
 612         for(i = 0;i < DEV_NUMBUFFS; i++) 
 613         {
 614                 while((skb=skb_dequeue(&dev->buffs[i]))!=NULL)
 615                 {
 616                         skb->magic = 0;
 617                         dev->queue_xmit(skb,dev,-i - 1);
 618                         if (dev->tbusy)
 619                                 return;
 620                 }
 621         }
 622 }
 623 
 624 
 625 /* 
 626  *      Perform a SIOCGIFCONF call. 
 627  */
 628 
 629 static int dev_ifconf(char *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 630 {
 631         struct ifconf ifc;
 632         struct ifreq ifr;
 633         struct device *dev;
 634         char *pos;
 635         int len;
 636         int err;
 637 
 638         /* Fetch the caller's info block. */
 639         err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifconf));
 640         if(err)
 641                 return -err;
 642         memcpy_fromfs(&ifc, arg, sizeof(struct ifconf));
 643         len = ifc.ifc_len;
 644         pos = ifc.ifc_buf;
 645 
 646         /* Loop over the interfaces, and write an info block for each. */
 647         for (dev = dev_base; dev != NULL; dev = dev->next) 
 648         {
 649                 if(!(dev->flags & IFF_UP))
 650                         continue;
 651                 memset(&ifr, 0, sizeof(struct ifreq));
 652                 strcpy(ifr.ifr_name, dev->name);
 653                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_family = dev->family;
 654                 (*(struct sockaddr_in *) &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
 655         
 656                 /* Write this block to the caller's space. */
 657                 memcpy_tofs(pos, &ifr, sizeof(struct ifreq));
 658                 pos += sizeof(struct ifreq);
 659                 len -= sizeof(struct ifreq);
 660                 if (len < sizeof(struct ifreq)) break;
 661         }
 662 
 663         /* All done.  Write the updated control block back to the caller. */
 664         ifc.ifc_len = (pos - ifc.ifc_buf);
 665         ifc.ifc_req = (struct ifreq *) ifc.ifc_buf;
 666         memcpy_tofs(arg, &ifc, sizeof(struct ifconf));
 667         return(pos - arg);
 668 }
 669 
 670 /* 
 671  *      Print device statistics. 
 672  */
 673  
 674 char *sprintf_stats(char *buffer, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 675 {
 676         char *pos = buffer;
 677         struct enet_statistics *stats = (dev->get_stats ? dev->get_stats(dev): NULL);
 678 
 679         if (stats)
 680                 pos += sprintf(pos, "%6s:%7d %4d %4d %4d %4d %8d %4d %4d %4d %5d %4d\n",
 681                    dev->name,
 682                    stats->rx_packets, stats->rx_errors,
 683                    stats->rx_dropped + stats->rx_missed_errors,
 684                    stats->rx_fifo_errors,
 685                    stats->rx_length_errors + stats->rx_over_errors
 686                    + stats->rx_crc_errors + stats->rx_frame_errors,
 687                    stats->tx_packets, stats->tx_errors, stats->tx_dropped,
 688                    stats->tx_fifo_errors, stats->collisions,
 689                    stats->tx_carrier_errors + stats->tx_aborted_errors
 690                    + stats->tx_window_errors + stats->tx_heartbeat_errors);
 691         else
 692                 pos += sprintf(pos, "%6s: No statistics available.\n", dev->name);
 693 
 694         return pos;
 695 }
 696 
 697 /*
 698  *      Called from the PROCfs module (/proc/net/dev).
 699  */
 700  
 701 int dev_get_info(char *buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
 702 {
 703         char *pos = buffer;
 704         struct device *dev;
 705 
 706         pos +=
 707         sprintf(pos,
 708               "Inter-|   Receive                  |  Transmit\n"
 709               " face |packets errs drop fifo frame|packets errs drop fifo colls carrier\n");
 710         for (dev = dev_base; dev != NULL; dev = dev->next) 
 711         {
 712                 pos = sprintf_stats(pos, dev);
 713         }
 714         return pos - buffer;
 715 }
 716 
 717 /*
 718  *      Perform the SIOCxIFxxx calls. 
 719  */
 720  
 721 static int dev_ifsioc(void *arg, unsigned int getset)
     /* [previous][next][first][last][top][bottom][index][help] */
 722 {
 723         struct ifreq ifr;
 724         struct device *dev;
 725         int ret;
 726         int err;
 727 
 728         /* Fetch the caller's info block. */
 729         err=verify_area(VERIFY_WRITE, arg, sizeof(struct ifreq));
 730         if(err)
 731                 return -err;
 732         memcpy_fromfs(&ifr, arg, sizeof(struct ifreq));
 733 
 734         /* See which interface the caller is talking about. */
 735         if ((dev = dev_get(ifr.ifr_name)) == NULL) 
 736                 return(-EINVAL);
 737 
 738         switch(getset) 
 739         {
 740                 case SIOCGIFFLAGS:
 741                         ifr.ifr_flags = dev->flags;
 742                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 743                         ret = 0;
 744                         break;
 745                 case SIOCSIFFLAGS:
 746                         {
 747                                 int old_flags = dev->flags;
 748                                 dev->flags = ifr.ifr_flags & (
 749                                         IFF_UP | IFF_BROADCAST | IFF_DEBUG | IFF_LOOPBACK |
 750                                         IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_RUNNING |
 751                                         IFF_NOARP | IFF_PROMISC | IFF_ALLMULTI);
 752                                 
 753                                 if ( (old_flags & IFF_PROMISC) && ((dev->flags & IFF_PROMISC) == 0))
 754                                         dev->set_multicast_list(dev,0,NULL);
 755                                 if ( (dev->flags & IFF_PROMISC) && ((old_flags & IFF_PROMISC) == 0))
 756                                         dev->set_multicast_list(dev,-1,NULL);
 757                                 if ((old_flags & IFF_UP) && ((dev->flags & IFF_UP) == 0)) 
 758                                 {
 759                                         ret = dev_close(dev);
 760                                 } 
 761                                 else
 762                                 {
 763                                         ret = (! (old_flags & IFF_UP) && (dev->flags & IFF_UP))
 764                                                 ? dev_open(dev) : 0;
 765                                         if(ret!=0)
 766                                                 dev->flags&=~IFF_UP;    /* Failed to come up so go down again */
 767                                 }
 768                         }
 769                         break;
 770                 case SIOCGIFADDR:
 771                         (*(struct sockaddr_in *)
 772                           &ifr.ifr_addr).sin_addr.s_addr = dev->pa_addr;
 773                         (*(struct sockaddr_in *)
 774                           &ifr.ifr_addr).sin_family = dev->family;
 775                         (*(struct sockaddr_in *)
 776                           &ifr.ifr_addr).sin_port = 0;
 777                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 778                         ret = 0;
 779                         break;
 780                 case SIOCSIFADDR:
 781                         dev->pa_addr = (*(struct sockaddr_in *)
 782                                          &ifr.ifr_addr).sin_addr.s_addr;
 783                         dev->family = ifr.ifr_addr.sa_family;
 784                         dev->pa_mask = ip_get_mask(dev->pa_addr);
 785                         dev->pa_brdaddr = dev->pa_addr | ~dev->pa_mask;
 786                         ret = 0;
 787                         break;
 788                 case SIOCGIFBRDADDR:
 789                         (*(struct sockaddr_in *)
 790                           &ifr.ifr_broadaddr).sin_addr.s_addr = dev->pa_brdaddr;
 791                         (*(struct sockaddr_in *)
 792                           &ifr.ifr_broadaddr).sin_family = dev->family;
 793                         (*(struct sockaddr_in *)
 794                           &ifr.ifr_broadaddr).sin_port = 0;
 795                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 796                         ret = 0;
 797                         break;
 798                 case SIOCSIFBRDADDR:
 799                         dev->pa_brdaddr = (*(struct sockaddr_in *)
 800                                             &ifr.ifr_broadaddr).sin_addr.s_addr;
 801                         ret = 0;
 802                         break;
 803                 case SIOCGIFDSTADDR:
 804                         (*(struct sockaddr_in *)
 805                           &ifr.ifr_dstaddr).sin_addr.s_addr = dev->pa_dstaddr;
 806                         (*(struct sockaddr_in *)
 807                                   &ifr.ifr_broadaddr).sin_family = dev->family;
 808                         (*(struct sockaddr_in *)
 809                                   &ifr.ifr_broadaddr).sin_port = 0;
 810                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 811                         ret = 0;
 812                         break;
 813                 case SIOCSIFDSTADDR:
 814                         dev->pa_dstaddr = (*(struct sockaddr_in *)
 815                                             &ifr.ifr_dstaddr).sin_addr.s_addr;
 816                         ret = 0;
 817                         break;
 818                 case SIOCGIFNETMASK:
 819                         (*(struct sockaddr_in *)
 820                           &ifr.ifr_netmask).sin_addr.s_addr = dev->pa_mask;
 821                         (*(struct sockaddr_in *)
 822                           &ifr.ifr_netmask).sin_family = dev->family;
 823                         (*(struct sockaddr_in *)
 824                           &ifr.ifr_netmask).sin_port = 0;
 825                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 826                         ret = 0;
 827                         break;
 828                 case SIOCSIFNETMASK:
 829                         dev->pa_mask = (*(struct sockaddr_in *)
 830                                  &ifr.ifr_netmask).sin_addr.s_addr;
 831                         ret = 0;
 832                         break;
 833                 case SIOCGIFMETRIC:
 834                         ifr.ifr_metric = dev->metric;
 835                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 836                         ret = 0;
 837                         break;
 838                 case SIOCSIFMETRIC:
 839                         dev->metric = ifr.ifr_metric;
 840                         ret = 0;
 841                         break;
 842                 case SIOCGIFMTU:
 843                         ifr.ifr_mtu = dev->mtu;
 844                         memcpy_tofs(arg, &ifr, sizeof(struct ifreq));
 845                         ret = 0;
 846                         break;
 847                 case SIOCSIFMTU:
 848                         dev->mtu = ifr.ifr_mtu;
 849                         ret = 0;
 850                         break;
 851                 case SIOCGIFMEM:
 852                         printk("NET: ioctl(SIOCGIFMEM, 0x%08X)\n", (int)arg);
 853                         ret = -EINVAL;
 854                         break;
 855                 case SIOCSIFMEM:
 856                         printk("NET: ioctl(SIOCSIFMEM, 0x%08X)\n", (int)arg);
 857                         ret = -EINVAL;
 858                         break;
 859                 case SIOCGIFHWADDR:
 860                         memcpy(ifr.ifr_hwaddr,dev->dev_addr, MAX_ADDR_LEN);
 861                         memcpy_tofs(arg,&ifr,sizeof(struct ifreq));
 862                         ret=0;
 863                         break;
 864                 default:
 865                         ret = -EINVAL;
 866         }       
 867         return(ret);
 868 }
 869 
 870 
 871 /*
 872  *      This function handles all "interface"-type I/O control requests. 
 873  */
 874  
 875 int dev_ioctl(unsigned int cmd, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 876 {
 877         int ret;
 878 
 879         switch(cmd) 
 880         {
 881                 case IP_SET_DEV:
 882                         printk("IP_SET_DEV is obsolete. You need newer network tools.\n");
 883                         ret= -EINVAL;
 884                 case SIOCGIFCONF:
 885                         (void) dev_ifconf((char *) arg);
 886                         ret = 0;
 887                         break;
 888                 case SIOCGIFFLAGS:
 889                 case SIOCSIFFLAGS:
 890                 case SIOCGIFADDR:
 891                 case SIOCSIFADDR:
 892                 case SIOCGIFDSTADDR:
 893                 case SIOCSIFDSTADDR:
 894                 case SIOCGIFBRDADDR:
 895                 case SIOCSIFBRDADDR:
 896                 case SIOCGIFNETMASK:
 897                 case SIOCSIFNETMASK:
 898                 case SIOCGIFMETRIC:
 899                 case SIOCSIFMETRIC:
 900                 case SIOCGIFMTU:
 901                 case SIOCSIFMTU:
 902                 case SIOCGIFMEM:
 903                 case SIOCSIFMEM:
 904                 case SIOCGIFHWADDR:
 905                         if (!suser()) 
 906                                 return(-EPERM);
 907                         ret = dev_ifsioc(arg, cmd);
 908                         break;
 909                 case SIOCSIFLINK:
 910                         if (!suser()) 
 911                                 return(-EPERM);
 912                 default:
 913                         ret = -EINVAL;
 914          }
 915 
 916         return(ret);
 917 }
 918 
 919 /*
 920  *      Setup an ethernet type interface
 921  */
 922  
 923 void eth_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 924 {
 925         struct device *d = dev_base;
 926 
 927         if (!str || !*str)
 928                 return;
 929                 
 930         /* Walk the device list */
 931         while (d) 
 932         {
 933                 if (!strcmp(str,d->name)) 
 934                 {
 935                         if (ints[0] > 0)
 936                                 d->irq=ints[1];
 937                         if (ints[0] > 1)
 938                                 d->base_addr=ints[2];
 939                         if (ints[0] > 2)
 940                                 d->mem_start=ints[3];
 941                         if (ints[0] > 3)
 942                                 d->mem_end=ints[4];
 943                         break;
 944                 }
 945                 d=d->next;
 946         }
 947 }
 948 
 949 
 950 /* 
 951  *      Initialize the DEV module. 
 952  */
 953  
 954 void dev_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 955 {
 956         struct device *dev, *dev2;
 957 
 958         /* Add the devices.
 959          * If the call to dev->init fails, the dev is removed
 960          * from the chain disconnecting the device until the
 961          * next reboot.
 962          */
 963         dev2 = NULL;
 964         for (dev = dev_base; dev != NULL; dev=dev->next) 
 965         {
 966                 if (dev->init && dev->init(dev)) 
 967                 {
 968                         if (dev2 == NULL) 
 969                                 dev_base = dev->next;
 970                         else 
 971                                 dev2->next = dev->next;
 972                 } 
 973                 else 
 974                 {
 975                         dev2 = dev;
 976                 }
 977         }
 978 
 979 }
 980 

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