root/net/socket.c

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

DEFINITIONS

This source file includes following definitions.
  1. move_addr_to_kernel
  2. move_addr_to_user
  3. get_fd
  4. socki_lookup
  5. sockfd_lookup
  6. sock_alloc
  7. sock_release_peer
  8. sock_release
  9. sock_lseek
  10. sock_read
  11. sock_write
  12. sock_readdir
  13. sock_ioctl
  14. sock_select
  15. sock_close
  16. sock_fasync
  17. sock_wake_async
  18. sock_awaitconn
  19. sock_socket
  20. sock_socketpair
  21. sock_bind
  22. sock_listen
  23. sock_accept
  24. sock_connect
  25. sock_getsockname
  26. sock_getpeername
  27. sock_send
  28. sock_sendto
  29. sock_recv
  30. sock_recvfrom
  31. sock_setsockopt
  32. sock_getsockopt
  33. sock_shutdown
  34. sock_fcntl
  35. sys_socketcall
  36. sock_register
  37. sock_unregister
  38. proto_init
  39. sock_init

   1 /*
   2  * NET          An implementation of the SOCKET network access protocol.
   3  *
   4  * Version:     @(#)socket.c    1.0.5   05/25/93
   5  *
   6  * Authors:     Orest Zborowski, <obz@Kodak.COM>
   7  *              Ross Biro, <bir7@leland.Stanford.Edu>
   8  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
   9  *
  10  * Fixes:
  11  *              Anonymous       :       NOTSOCK/BADF cleanup. Error fix in
  12  *                                      shutdown()
  13  *              Alan Cox        :       verify_area() fixes
  14  *              Alan Cox        :       Removed DDI
  15  *              Jonathan Kamens :       SOCK_DGRAM reconnect bug
  16  *              Alan Cox        :       Moved a load of checks to the very
  17  *                                      top level.
  18  *              Alan Cox        :       Move address structures to/from user
  19  *                                      mode above the protocol layers.
  20  *              Rob Janssen     :       Allow 0 length sends.
  21  *              Alan Cox        :       Asynchronous I/O support (cribbed from the
  22  *                                      tty drivers).
  23  *
  24  *
  25  *              This program is free software; you can redistribute it and/or
  26  *              modify it under the terms of the GNU General Public License
  27  *              as published by the Free Software Foundation; either version
  28  *              2 of the License, or (at your option) any later version.
  29  *
  30  *
  31  *      This module is effectively the top level interface to the BSD socket
  32  *      paradigm. Because it is very simple it works well for Unix domain sockets,
  33  *      but requires a whole layer of substructure for the other protocols.
  34  *
  35  *      In addition it lacks an effective kernel -> kernel interface to go with
  36  *      the user one.
  37  */
  38 
  39 #include <linux/config.h>
  40 #include <linux/signal.h>
  41 #include <linux/errno.h>
  42 #include <linux/sched.h>
  43 #include <linux/kernel.h>
  44 #include <linux/major.h>
  45 #include <linux/stat.h>
  46 #include <linux/socket.h>
  47 #include <linux/fcntl.h>
  48 #include <linux/net.h>
  49 #include <linux/interrupt.h>
  50 #include <linux/netdevice.h>
  51 
  52 #include <asm/system.h>
  53 #include <asm/segment.h>
  54 
  55 static int sock_lseek(struct inode *inode, struct file *file, off_t offset,
  56                       int whence);
  57 static int sock_read(struct inode *inode, struct file *file, char *buf,
  58                      int size);
  59 static int sock_write(struct inode *inode, struct file *file, char *buf,
  60                       int size);
  61 static int sock_readdir(struct inode *inode, struct file *file,
  62                         struct dirent *dirent, int count);
  63 static void sock_close(struct inode *inode, struct file *file);
  64 static int sock_select(struct inode *inode, struct file *file, int which, select_table *seltable);
  65 static int sock_ioctl(struct inode *inode, struct file *file,
  66                       unsigned int cmd, unsigned long arg);
  67 static int sock_fasync(struct inode *inode, struct file *filp, int on);
  68                    
  69 
  70 
  71 /*
  72  *      Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
  73  *      in the operation structures but are done directly via the socketcall() multiplexor.
  74  */
  75 
  76 static struct file_operations socket_file_ops = {
  77         sock_lseek,
  78         sock_read,
  79         sock_write,
  80         sock_readdir,
  81         sock_select,
  82         sock_ioctl,
  83         NULL,                   /* mmap */
  84         NULL,                   /* no special open code... */
  85         sock_close,
  86         NULL,                   /* no fsync */
  87         sock_fasync
  88 };
  89 
  90 /*
  91  *      The list of sockets - make this atomic.
  92  */
  93 static struct socket sockets[NSOCKETS];
  94 /*
  95  *      Used to wait for a socket.
  96  */
  97 static struct wait_queue *socket_wait_free = NULL;
  98 /*
  99  *      The protocol list. Each protocol is registered in here.
 100  */
 101 static struct proto_ops *pops[NPROTO];
 102 
 103 #define last_socket     (sockets + NSOCKETS - 1)
 104 
 105 
 106 /*
 107  *      Support routines. Move socket addresses back and forth across the kernel/user
 108  *      divide and look after the messy bits.
 109  */
 110 
 111 #define MAX_SOCK_ADDR   128             /* 108 for Unix domain - 16 for IP, 16 for IPX, about 80 for AX.25 */
 112  
 113 static int move_addr_to_kernel(void *uaddr, int ulen, void *kaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 114 {
 115         int err;
 116         if(ulen<0||ulen>MAX_SOCK_ADDR)
 117                 return -EINVAL;
 118         if(ulen==0)
 119                 return 0;
 120         if((err=verify_area(VERIFY_READ,uaddr,ulen))<0)
 121                 return err;
 122         memcpy_fromfs(kaddr,uaddr,ulen);
 123         return 0;
 124 }
 125 
 126 static int move_addr_to_user(void *kaddr, int klen, void *uaddr, int *ulen)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         int err;
 129         int len;
 130 
 131                 
 132         if((err=verify_area(VERIFY_WRITE,ulen,sizeof(*ulen)))<0)
 133                 return err;
 134         len=get_fs_long(ulen);
 135         if(len>klen)
 136                 len=klen;
 137         if(len<0 || len> MAX_SOCK_ADDR)
 138                 return -EINVAL;
 139         if(len)
 140         {
 141                 if((err=verify_area(VERIFY_WRITE,uaddr,len))<0)
 142                         return err;
 143                 memcpy_tofs(uaddr,kaddr,len);
 144         }
 145         put_fs_long(len,ulen);
 146         return 0;
 147 }
 148 
 149 /*
 150  *      Obtains the first available file descriptor and sets it up for use. 
 151  */
 152 
 153 static int get_fd(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155         int fd;
 156         struct file *file;
 157 
 158         /*
 159          *      Find a file descriptor suitable for return to the user. 
 160          */
 161 
 162         file = get_empty_filp();
 163         if (!file) 
 164                 return(-1);
 165 
 166         for (fd = 0; fd < NR_OPEN; ++fd)
 167                 if (!current->files->fd[fd]) 
 168                         break;
 169         if (fd == NR_OPEN) 
 170         {
 171                 file->f_count = 0;
 172                 return(-1);
 173         }
 174 
 175         FD_CLR(fd, &current->files->close_on_exec);
 176                 current->files->fd[fd] = file;
 177         file->f_op = &socket_file_ops;
 178         file->f_mode = 3;
 179         file->f_flags = O_RDWR;
 180         file->f_count = 1;
 181         file->f_inode = inode;
 182         if (inode) 
 183                 inode->i_count++;
 184         file->f_pos = 0;
 185         return(fd);
 186 }
 187 
 188 
 189 /*
 190  *      Go from an inode to its socket slot.
 191  */
 192 
 193 struct socket *socki_lookup(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 194 {
 195         struct socket *sock;
 196 
 197         if ((sock = inode->i_socket) != NULL) 
 198         {
 199                 if (sock->state != SS_FREE && SOCK_INODE(sock) == inode)
 200                         return sock;
 201                 printk("socket.c: uhhuh. stale inode->i_socket pointer\n");
 202         }
 203         for (sock = sockets; sock <= last_socket; ++sock)
 204                 if (sock->state != SS_FREE && SOCK_INODE(sock) == inode) 
 205                 {
 206                         printk("socket.c: uhhuh. Found socket despite no inode->i_socket pointer\n");
 207                         return(sock);
 208                 }
 209                 return(NULL);
 210 }
 211 
 212 /*
 213  *      Go from a file number to its socket slot.
 214  */
 215 
 216 static inline struct socket *sockfd_lookup(int fd, struct file **pfile)
     /* [previous][next][first][last][top][bottom][index][help] */
 217 {
 218         struct file *file;
 219 
 220         if (fd < 0 || fd >= NR_OPEN || !(file = current->files->fd[fd])) 
 221                 return(NULL);
 222 
 223         if (pfile) 
 224                 *pfile = file;
 225 
 226         return(socki_lookup(file->f_inode));
 227 }
 228 
 229 /*
 230  *      Allocate a socket. Wait if we are out of sockets.
 231  */
 232 
 233 static struct socket *sock_alloc(int wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 234 {
 235         struct socket *sock;
 236 
 237         while (1) 
 238         {
 239                 cli();
 240                 for (sock = sockets; sock <= last_socket; ++sock) 
 241                 {
 242                         if (sock->state == SS_FREE) 
 243                         {
 244                         /*
 245                          *      Got one..
 246                          */
 247                                 sock->state = SS_UNCONNECTED;
 248                                 sti();
 249                                 sock->flags = 0;
 250                                 sock->ops = NULL;
 251                                 sock->data = NULL;
 252                                 sock->conn = NULL;
 253                                 sock->iconn = NULL;
 254                                 sock->fasync_list = NULL;
 255                         /*
 256                          * This really shouldn't be necessary, but everything
 257                          * else depends on inodes, so we grab it.
 258                          * Sleeps are also done on the i_wait member of this
 259                          * inode.  The close system call will iput this inode
 260                          * for us.
 261                          */
 262                                 if (!(SOCK_INODE(sock) = get_empty_inode())) 
 263                                 {
 264                                         printk("NET: sock_alloc: no more inodes\n");
 265                                         sock->state = SS_FREE;
 266                                         return(NULL);
 267                                 }
 268                                 SOCK_INODE(sock)->i_mode = S_IFSOCK;
 269                                 SOCK_INODE(sock)->i_uid = current->uid;
 270                                 SOCK_INODE(sock)->i_gid = current->gid;
 271                                 SOCK_INODE(sock)->i_socket = sock;
 272 
 273                                 sock->wait = &SOCK_INODE(sock)->i_wait;
 274                                 return(sock);
 275                         }
 276                 }
 277                 sti();
 278                 /*
 279                  *      If its a 'now or never request' then return.
 280                  */
 281                 if (!wait) 
 282                         return(NULL);
 283                 /*
 284                  *      Sleep on the socket free'ing queue.
 285                  */
 286                 interruptible_sleep_on(&socket_wait_free);
 287                 /*
 288                  *      If we have been interrupted then return.
 289                  */
 290                 if (current->signal & ~current->blocked) 
 291                 {
 292                         return(NULL);
 293                 }
 294         }
 295 }
 296 
 297 /*
 298  *      Release a socket.
 299  */
 300 
 301 static inline void sock_release_peer(struct socket *peer)
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303         peer->state = SS_DISCONNECTING;
 304         wake_up_interruptible(peer->wait);
 305 }
 306 
 307 
 308 static void sock_release(struct socket *sock)
     /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         int oldstate;
 311         struct inode *inode;
 312         struct socket *peersock, *nextsock;
 313 
 314         if ((oldstate = sock->state) != SS_UNCONNECTED)
 315                 sock->state = SS_DISCONNECTING;
 316 
 317         /*
 318          *      Wake up anyone waiting for connections. 
 319          */
 320 
 321         for (peersock = sock->iconn; peersock; peersock = nextsock) 
 322         {
 323                 nextsock = peersock->next;
 324                 sock_release_peer(peersock);
 325         }
 326 
 327         /*
 328          * Wake up anyone we're connected to. First, we release the
 329          * protocol, to give it a chance to flush data, etc.
 330          */
 331 
 332         peersock = (oldstate == SS_CONNECTED) ? sock->conn : NULL;
 333         if (sock->ops) 
 334                 sock->ops->release(sock, peersock);
 335         if (peersock)
 336                 sock_release_peer(peersock);
 337         inode = SOCK_INODE(sock);
 338         sock->state = SS_FREE;          /* this really releases us */
 339         
 340         /*
 341          *      This will wake anyone waiting for a free socket.
 342          */
 343         wake_up_interruptible(&socket_wait_free);
 344 
 345         /*
 346          *      We need to do this. If sock alloc was called we already have an inode. 
 347          */
 348          
 349         iput(inode);
 350 }
 351 
 352 /*
 353  *      Sockets are not seekable.
 354  */
 355 
 356 static int sock_lseek(struct inode *inode, struct file *file, off_t offset, int whence)
     /* [previous][next][first][last][top][bottom][index][help] */
 357 {
 358         return(-ESPIPE);
 359 }
 360 
 361 /*
 362  *      Read data from a socket. ubuf is a user mode pointer. We make sure the user
 363  *      area ubuf...ubuf+size-1 is writable before asking the protocol.
 364  */
 365 
 366 static int sock_read(struct inode *inode, struct file *file, char *ubuf, int size)
     /* [previous][next][first][last][top][bottom][index][help] */
 367 {
 368         struct socket *sock;
 369         int err;
 370   
 371         if (!(sock = socki_lookup(inode))) 
 372         {
 373                 printk("NET: sock_read: can't find socket for inode!\n");
 374                 return(-EBADF);
 375         }
 376         if (sock->flags & SO_ACCEPTCON) 
 377                 return(-EINVAL);
 378 
 379         if(size<0)
 380                 return -EINVAL;
 381         if(size==0)
 382                 return 0;
 383         if ((err=verify_area(VERIFY_WRITE,ubuf,size))<0)
 384                 return err;
 385         return(sock->ops->read(sock, ubuf, size, (file->f_flags & O_NONBLOCK)));
 386 }
 387 
 388 /*
 389  *      Write data to a socket. We verify that the user area ubuf..ubuf+size-1 is
 390  *      readable by the user process.
 391  */
 392 
 393 static int sock_write(struct inode *inode, struct file *file, char *ubuf, int size)
     /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395         struct socket *sock;
 396         int err;
 397         
 398         if (!(sock = socki_lookup(inode))) 
 399         {
 400                 printk("NET: sock_write: can't find socket for inode!\n");
 401                 return(-EBADF);
 402         }
 403 
 404         if (sock->flags & SO_ACCEPTCON) 
 405                 return(-EINVAL);
 406         
 407         if(size<0)
 408                 return -EINVAL;
 409         if(size==0)
 410                 return 0;
 411                 
 412         if ((err=verify_area(VERIFY_READ,ubuf,size))<0)
 413                 return err;
 414         return(sock->ops->write(sock, ubuf, size,(file->f_flags & O_NONBLOCK)));
 415 }
 416 
 417 /*
 418  *      You can't read directories from a socket!
 419  */
 420  
 421 static int sock_readdir(struct inode *inode, struct file *file, struct dirent *dirent,
     /* [previous][next][first][last][top][bottom][index][help] */
 422              int count)
 423 {
 424         return(-EBADF);
 425 }
 426 
 427 /*
 428  *      With an ioctl arg may well be a user mode pointer, but we don't know what to do
 429  *      with it - thats up to the protocol still.
 430  */
 431 
 432 int sock_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
     /* [previous][next][first][last][top][bottom][index][help] */
 433            unsigned long arg)
 434 {
 435         struct socket *sock;
 436 
 437         if (!(sock = socki_lookup(inode))) 
 438         {
 439                 printk("NET: sock_ioctl: can't find socket for inode!\n");
 440                 return(-EBADF);
 441         }
 442         return(sock->ops->ioctl(sock, cmd, arg));
 443 }
 444 
 445 
 446 static int sock_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 447 {
 448         struct socket *sock;
 449 
 450         if (!(sock = socki_lookup(inode))) 
 451         {
 452                 printk("NET: sock_select: can't find socket for inode!\n");
 453                 return(0);
 454         }
 455 
 456         /*
 457          *      We can't return errors to select, so its either yes or no. 
 458          */
 459 
 460         if (sock->ops && sock->ops->select)
 461                 return(sock->ops->select(sock, sel_type, wait));
 462         return(0);
 463 }
 464 
 465 
 466 void sock_close(struct inode *inode, struct file *filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 467 {
 468         struct socket *sock;
 469 
 470         /*
 471          *      It's possible the inode is NULL if we're closing an unfinished socket. 
 472          */
 473 
 474         if (!inode) 
 475                 return;
 476 
 477         if (!(sock = socki_lookup(inode))) 
 478         {
 479                 printk("NET: sock_close: can't find socket for inode!\n");
 480                 return;
 481         }
 482         sock_fasync(inode, filp, 0);
 483         sock_release(sock);
 484 }
 485 
 486 /*
 487  *      Update the socket async list
 488  */
 489  
 490 static int sock_fasync(struct inode *inode, struct file *filp, int on)
     /* [previous][next][first][last][top][bottom][index][help] */
 491 {
 492         struct fasync_struct *fa, *fna=NULL, **prev;
 493         struct socket *sock;
 494         unsigned long flags;
 495         
 496         if (on)
 497         {
 498                 fna=(struct fasync_struct *)kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
 499                 if(fna==NULL)
 500                         return -ENOMEM;
 501         }
 502 
 503         sock = socki_lookup(inode);
 504         
 505         prev=&(sock->fasync_list);
 506         
 507         save_flags(flags);
 508         cli();
 509         
 510         for(fa=*prev; fa!=NULL; prev=&fa->fa_next,fa=*prev)
 511                 if(fa->fa_file==filp)
 512                         break;
 513         
 514         if(on)
 515         {
 516                 if(fa!=NULL)
 517                 {
 518                         kfree_s(fna,sizeof(struct fasync_struct));
 519                         restore_flags(flags);
 520                         return 0;
 521                 }
 522                 fna->fa_file=filp;
 523                 fna->magic=FASYNC_MAGIC;
 524                 fna->fa_next=sock->fasync_list;
 525                 sock->fasync_list=fna;
 526         }
 527         else
 528         {
 529                 if(fa!=NULL)
 530                 {
 531                         *prev=fa->fa_next;
 532                         kfree_s(fa,sizeof(struct fasync_struct));
 533                 }
 534         }
 535         restore_flags(flags);
 536         return 0;
 537 }
 538 
 539 int sock_wake_async(struct socket *sock)
     /* [previous][next][first][last][top][bottom][index][help] */
 540 {
 541         if (!sock || !sock->fasync_list)
 542                 return -1;
 543         kill_fasync(sock->fasync_list, SIGIO);
 544         return 0;
 545 }
 546 
 547         
 548 /*
 549  *      Wait for a connection.
 550  */
 551 
 552 int sock_awaitconn(struct socket *mysock, struct socket *servsock)
     /* [previous][next][first][last][top][bottom][index][help] */
 553 {
 554         struct socket *last;
 555 
 556         /*
 557          *      We must be listening
 558          */
 559         if (!(servsock->flags & SO_ACCEPTCON)) 
 560         {
 561                 return(-EINVAL);
 562         }
 563 
 564         /*
 565          *      Put ourselves on the server's incomplete connection queue. 
 566          */
 567          
 568         mysock->next = NULL;
 569         cli();
 570         if (!(last = servsock->iconn)) 
 571                 servsock->iconn = mysock;
 572         else 
 573         {
 574                 while (last->next) 
 575                         last = last->next;
 576                 last->next = mysock;
 577         }
 578         mysock->state = SS_CONNECTING;
 579         mysock->conn = servsock;
 580         sti();
 581 
 582         /*
 583          * Wake up server, then await connection. server will set state to
 584          * SS_CONNECTED if we're connected.
 585          */
 586         wake_up_interruptible(servsock->wait);
 587         if (mysock->state != SS_CONNECTED) 
 588         {
 589                 interruptible_sleep_on(mysock->wait);
 590                 if (mysock->state != SS_CONNECTED &&
 591                     mysock->state != SS_DISCONNECTING) 
 592                 {
 593                 /*
 594                  * if we're not connected we could have been
 595                  * 1) interrupted, so we need to remove ourselves
 596                  *    from the server list
 597                  * 2) rejected (mysock->conn == NULL), and have
 598                  *    already been removed from the list
 599                  */
 600                         if (mysock->conn == servsock) 
 601                         {
 602                                 cli();
 603                                 if ((last = servsock->iconn) == mysock)
 604                                         servsock->iconn = mysock->next;
 605                                 else 
 606                                 {
 607                                         while (last->next != mysock) 
 608                                                 last = last->next;
 609                                         last->next = mysock->next;
 610                                 }
 611                                 sti();
 612                         }
 613                         return(mysock->conn ? -EINTR : -EACCES);
 614                 }
 615         }
 616         return(0);
 617 }
 618 
 619 
 620 /*
 621  *      Perform the socket system call. we locate the appropriate
 622  *      family, then create a fresh socket.
 623  */
 624 
 625 static int sock_socket(int family, int type, int protocol)
     /* [previous][next][first][last][top][bottom][index][help] */
 626 {
 627         int i, fd;
 628         struct socket *sock;
 629         struct proto_ops *ops;
 630 
 631         /* Locate the correct protocol family. */
 632         for (i = 0; i < NPROTO; ++i) 
 633         {
 634                 if (pops[i] == NULL) continue;
 635                 if (pops[i]->family == family) 
 636                         break;
 637         }
 638 
 639         if (i == NPROTO) 
 640         {
 641                 return -EINVAL;
 642         }
 643 
 644         ops = pops[i];
 645 
 646 /*
 647  *      Check that this is a type that we know how to manipulate and
 648  *      the protocol makes sense here. The family can still reject the
 649  *      protocol later.
 650  */
 651   
 652         if ((type != SOCK_STREAM && type != SOCK_DGRAM &&
 653                 type != SOCK_SEQPACKET && type != SOCK_RAW &&
 654                 type != SOCK_PACKET) || protocol < 0)
 655                         return(-EINVAL);
 656 
 657 /*
 658  *      Allocate the socket and allow the family to set things up. if
 659  *      the protocol is 0, the family is instructed to select an appropriate
 660  *      default.
 661  */
 662 
 663         if (!(sock = sock_alloc(1))) 
 664         {
 665                 printk("sock_socket: no more sockets\n");
 666                 return(-EAGAIN);
 667         }
 668 
 669         sock->type = type;
 670         sock->ops = ops;
 671         if ((i = sock->ops->create(sock, protocol)) < 0) 
 672         {
 673                 sock_release(sock);
 674                 return(i);
 675         }
 676 
 677         if ((fd = get_fd(SOCK_INODE(sock))) < 0) 
 678         {
 679                 sock_release(sock);
 680                 return(-EINVAL);
 681         }
 682 
 683         return(fd);
 684 }
 685 
 686 /*
 687  *      Create a pair of connected sockets.
 688  */
 689 
 690 static int sock_socketpair(int family, int type, int protocol, unsigned long usockvec[2])
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         int fd1, fd2, i;
 693         struct socket *sock1, *sock2;
 694         int er;
 695 
 696         /*
 697          * Obtain the first socket and check if the underlying protocol
 698          * supports the socketpair call.
 699          */
 700 
 701         if ((fd1 = sock_socket(family, type, protocol)) < 0) 
 702                 return(fd1);
 703         sock1 = sockfd_lookup(fd1, NULL);
 704         if (!sock1->ops->socketpair) 
 705         {
 706                 sys_close(fd1);
 707                 return(-EINVAL);
 708         }
 709 
 710         /*
 711          *      Now grab another socket and try to connect the two together. 
 712          */
 713 
 714         if ((fd2 = sock_socket(family, type, protocol)) < 0) 
 715         {
 716                 sys_close(fd1);
 717                 return(-EINVAL);
 718         }
 719 
 720         sock2 = sockfd_lookup(fd2, NULL);
 721         if ((i = sock1->ops->socketpair(sock1, sock2)) < 0) 
 722         {
 723                 sys_close(fd1);
 724                 sys_close(fd2);
 725                 return(i);
 726         }
 727 
 728         sock1->conn = sock2;
 729         sock2->conn = sock1;
 730         sock1->state = SS_CONNECTED;
 731         sock2->state = SS_CONNECTED;
 732 
 733         er=verify_area(VERIFY_WRITE, usockvec, 2 * sizeof(int));
 734         if(er)
 735         {
 736                 sys_close(fd1);
 737                 sys_close(fd2);
 738                 return er;
 739         }
 740         put_fs_long(fd1, &usockvec[0]);
 741         put_fs_long(fd2, &usockvec[1]);
 742 
 743         return(0);
 744 }
 745 
 746 
 747 /*
 748  *      Bind a name to a socket. Nothing much to do here since its
 749  *      the protocol's responsibility to handle the local address.
 750  *
 751  *      We move the socket address to kernel space before we call
 752  *      the protocol layer (having also checked the address is ok).
 753  */
 754  
 755 static int sock_bind(int fd, struct sockaddr *umyaddr, int addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 756 {
 757         struct socket *sock;
 758         int i;
 759         char address[MAX_SOCK_ADDR];
 760         int err;
 761 
 762         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 763                 return(-EBADF);
 764         
 765         if (!(sock = sockfd_lookup(fd, NULL))) 
 766                 return(-ENOTSOCK);
 767   
 768         if((err=move_addr_to_kernel(umyaddr,addrlen,address))<0)
 769                 return err;
 770   
 771         if ((i = sock->ops->bind(sock, (struct sockaddr *)address, addrlen)) < 0) 
 772         {
 773                 return(i);
 774         }
 775         return(0);
 776 }
 777 
 778 
 779 /*
 780  *      Perform a listen. Basically, we allow the protocol to do anything
 781  *      necessary for a listen, and if that works, we mark the socket as
 782  *      ready for listening.
 783  */
 784 
 785 static int sock_listen(int fd, int backlog)
     /* [previous][next][first][last][top][bottom][index][help] */
 786 {
 787         struct socket *sock;
 788 
 789         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 790                 return(-EBADF);
 791         if (!(sock = sockfd_lookup(fd, NULL))) 
 792                 return(-ENOTSOCK);
 793 
 794         if (sock->state != SS_UNCONNECTED) 
 795         {
 796                 return(-EINVAL);
 797         }
 798 
 799         if (sock->ops && sock->ops->listen)
 800                 sock->ops->listen(sock, backlog);
 801         sock->flags |= SO_ACCEPTCON;
 802         return(0);
 803 }
 804 
 805 
 806 /*
 807  *      For accept, we attempt to create a new socket, set up the link
 808  *      with the client, wake up the client, then return the new
 809  *      connected fd. We collect the address of the connector in kernel
 810  *      space and move it to user at the very end. This is buggy because
 811  *      we open the socket then return an error.
 812  */
 813 
 814 static int sock_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 815 {
 816         struct file *file;
 817         struct socket *sock, *newsock;
 818         int i;
 819         char address[MAX_SOCK_ADDR];
 820         int len;
 821 
 822         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 823                 return(-EBADF);
 824         if (!(sock = sockfd_lookup(fd, &file))) 
 825                 return(-ENOTSOCK);
 826         if (sock->state != SS_UNCONNECTED) 
 827         {
 828                 return(-EINVAL);
 829         }
 830         if (!(sock->flags & SO_ACCEPTCON)) 
 831         {
 832                 return(-EINVAL);
 833         }
 834 
 835         if (!(newsock = sock_alloc(0))) 
 836         {
 837                 printk("NET: sock_accept: no more sockets\n");
 838                 return(-EAGAIN);
 839         }
 840         newsock->type = sock->type;
 841         newsock->ops = sock->ops;
 842         if ((i = sock->ops->dup(newsock, sock)) < 0) 
 843         {
 844                 sock_release(newsock);
 845                 return(i);
 846         }
 847 
 848         i = newsock->ops->accept(sock, newsock, file->f_flags);
 849         if ( i < 0) 
 850         {
 851                 sock_release(newsock);
 852                 return(i);
 853         }
 854 
 855         if ((fd = get_fd(SOCK_INODE(newsock))) < 0) 
 856         {
 857                 sock_release(newsock);
 858                 return(-EINVAL);
 859         }
 860 
 861         if (upeer_sockaddr)
 862         {
 863                 newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 1);
 864                 move_addr_to_user(address,len, upeer_sockaddr, upeer_addrlen);
 865         }
 866         return(fd);
 867 }
 868 
 869 
 870 /*
 871  *      Attempt to connect to a socket with the server address.  The address
 872  *      is in user space so we verify it is OK and move it to kernel space.
 873  */
 874  
 875 static int sock_connect(int fd, struct sockaddr *uservaddr, int addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 876 {
 877         struct socket *sock;
 878         struct file *file;
 879         int i;
 880         char address[MAX_SOCK_ADDR];
 881         int err;
 882 
 883         if (fd < 0 || fd >= NR_OPEN || (file=current->files->fd[fd]) == NULL)
 884                 return(-EBADF);
 885         if (!(sock = sockfd_lookup(fd, &file)))
 886                 return(-ENOTSOCK);
 887 
 888         if((err=move_addr_to_kernel(uservaddr,addrlen,address))<0)
 889                 return err;
 890   
 891         switch(sock->state) 
 892         {
 893                 case SS_UNCONNECTED:
 894                         /* This is ok... continue with connect */
 895                         break;
 896                 case SS_CONNECTED:
 897                         /* Socket is already connected */
 898                         if(sock->type == SOCK_DGRAM) /* Hack for now - move this all into the protocol */
 899                                 break;
 900                         return -EISCONN;
 901                 case SS_CONNECTING:
 902                         /* Not yet connected... we will check this. */
 903                 
 904                         /*
 905                          *      FIXME:  for all protocols what happens if you start
 906                          *      an async connect fork and both children connect. Clean
 907                          *      this up in the protocols!
 908                          */
 909                         return(sock->ops->connect(sock, uservaddr,
 910                                   addrlen, file->f_flags));
 911                 default:
 912                         return(-EINVAL);
 913         }
 914         i = sock->ops->connect(sock, (struct sockaddr *)address, addrlen, file->f_flags);
 915         if (i < 0) 
 916         {
 917                 return(i);
 918         }
 919         return(0);
 920 }
 921 
 922 /*
 923  *      Get the local address ('name') of a socket object. Move the obtained
 924  *      name to user space.
 925  */
 926 
 927 static int sock_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 928 {
 929         struct socket *sock;
 930         char address[MAX_SOCK_ADDR];
 931         int len;
 932         int err;
 933         
 934         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 935                 return(-EBADF);
 936         if (!(sock = sockfd_lookup(fd, NULL)))
 937                 return(-ENOTSOCK);
 938 
 939         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
 940         if(err)
 941                 return err;
 942         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 943                 return err;
 944         return 0;
 945 }
 946 
 947 /*
 948  *      Get the remote address ('name') of a socket object. Move the obtained
 949  *      name to user space.
 950  */
 951  
 952 static int sock_getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 953 {
 954         struct socket *sock;
 955         char address[MAX_SOCK_ADDR];
 956         int len;
 957         int err;
 958 
 959         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 960                 return(-EBADF);
 961         if (!(sock = sockfd_lookup(fd, NULL)))
 962                 return(-ENOTSOCK);
 963 
 964         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
 965         if(err)
 966                 return err;
 967         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 968                 return err;
 969         return 0;
 970 }
 971 
 972 /*
 973  *      Send a datagram down a socket. The datagram as with write() is
 974  *      in user space. We check it can be read.
 975  */
 976 
 977 static int sock_send(int fd, void * buff, int len, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 978 {
 979         struct socket *sock;
 980         struct file *file;
 981         int err;
 982 
 983         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 984                 return(-EBADF);
 985         if (!(sock = sockfd_lookup(fd, NULL))) 
 986                 return(-ENOTSOCK);
 987 
 988         if(len<0)
 989                 return -EINVAL;
 990         err=verify_area(VERIFY_READ, buff, len);
 991         if(err)
 992                 return err;
 993         return(sock->ops->send(sock, buff, len, (file->f_flags & O_NONBLOCK), flags));
 994 }
 995 
 996 /*
 997  *      Send a datagram to a given address. We move the address into kernel
 998  *      space and check the user space data area is readable before invoking
 999  *      the protocol.
1000  */
1001 
1002 static int sock_sendto(int fd, void * buff, int len, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
1003            struct sockaddr *addr, int addr_len)
1004 {
1005         struct socket *sock;
1006         struct file *file;
1007         char address[MAX_SOCK_ADDR];
1008         int err;
1009         
1010         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1011                 return(-EBADF);
1012         if (!(sock = sockfd_lookup(fd, NULL)))
1013                 return(-ENOTSOCK);
1014 
1015         if(len<0)
1016                 return -EINVAL;
1017         err=verify_area(VERIFY_READ,buff,len);
1018         if(err)
1019                 return err;
1020         
1021         if((err=move_addr_to_kernel(addr,addr_len,address))<0)
1022                 return err;
1023 
1024         return(sock->ops->sendto(sock, buff, len, (file->f_flags & O_NONBLOCK),
1025                 flags, (struct sockaddr *)address, addr_len));
1026 }
1027 
1028 
1029 /*
1030  *      Receive a datagram from a socket. This isn't really right. The BSD manual
1031  *      pages explicitly state that recv is recvfrom with a NULL to argument. The
1032  *      Linux stack gets the right results for the wrong reason and this need to
1033  *      be tidied in the inet layer and removed from here.
1034  *      We check the buffer is writable and valid.
1035  */
1036 
1037 static int sock_recv(int fd, void * buff, int len, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1038 {
1039         struct socket *sock;
1040         struct file *file;
1041         int err;
1042 
1043         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1044                 return(-EBADF);
1045 
1046         if (!(sock = sockfd_lookup(fd, NULL))) 
1047                 return(-ENOTSOCK);
1048                 
1049         if(len<0)
1050                 return -EINVAL;
1051         if(len==0)
1052                 return 0;
1053         err=verify_area(VERIFY_WRITE, buff, len);
1054         if(err)
1055                 return err;
1056 
1057         return(sock->ops->recv(sock, buff, len,(file->f_flags & O_NONBLOCK), flags));
1058 }
1059 
1060 /*
1061  *      Receive a frame from the socket and optionally record the address of the 
1062  *      sender. We verify the buffers are writable and if needed move the
1063  *      sender address from kernel to user space.
1064  */
1065 
1066 static int sock_recvfrom(int fd, void * buff, int len, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
1067              struct sockaddr *addr, int *addr_len)
1068 {
1069         struct socket *sock;
1070         struct file *file;
1071         char address[MAX_SOCK_ADDR];
1072         int err;
1073         int alen;
1074         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1075                 return(-EBADF);
1076         if (!(sock = sockfd_lookup(fd, NULL))) 
1077                 return(-ENOTSOCK);
1078         if(len<0)
1079                 return -EINVAL;
1080         if(len==0)
1081                 return 0;
1082 
1083         err=verify_area(VERIFY_WRITE,buff,len);
1084         if(err)
1085                 return err;
1086   
1087         len=sock->ops->recvfrom(sock, buff, len, (file->f_flags & O_NONBLOCK),
1088                      flags, (struct sockaddr *)address, &alen);
1089 
1090         if(len<0)
1091                 return len;
1092         if(addr!=NULL && (err=move_addr_to_user(address,alen, addr, addr_len))<0)
1093                 return err;
1094 
1095         return len;
1096 }
1097 
1098 /*
1099  *      Set a socket option. Because we don't know the option lengths we have
1100  *      to pass the user mode parameter for the protocols to sort out.
1101  */
1102  
1103 static int sock_setsockopt(int fd, int level, int optname, char *optval, int optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1104 {
1105         struct socket *sock;
1106         struct file *file;
1107         
1108         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1109                 return(-EBADF);
1110         if (!(sock = sockfd_lookup(fd, NULL))) 
1111                 return(-ENOTSOCK);
1112 
1113         return(sock->ops->setsockopt(sock, level, optname, optval, optlen));
1114 }
1115 
1116 /*
1117  *      Get a socket option. Because we don't know the option lengths we have
1118  *      to pass a user mode parameter for the protocols to sort out.
1119  */
1120 
1121 static int sock_getsockopt(int fd, int level, int optname, char *optval, int *optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1122 {
1123         struct socket *sock;
1124         struct file *file;
1125 
1126         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1127                 return(-EBADF);
1128         if (!(sock = sockfd_lookup(fd, NULL)))
1129                 return(-ENOTSOCK);
1130             
1131         if (!sock->ops || !sock->ops->getsockopt) 
1132                 return(0);
1133         return(sock->ops->getsockopt(sock, level, optname, optval, optlen));
1134 }
1135 
1136 
1137 /*
1138  *      Shutdown a socket.
1139  */
1140  
1141 static int sock_shutdown(int fd, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
1142 {
1143         struct socket *sock;
1144         struct file *file;
1145 
1146         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1147                 return(-EBADF);
1148         if (!(sock = sockfd_lookup(fd, NULL))) 
1149                 return(-ENOTSOCK);
1150 
1151         return(sock->ops->shutdown(sock, how));
1152 }
1153 
1154 
1155 /*
1156  *      Perform a file control on a socket file descriptor.
1157  */
1158 
1159 int sock_fcntl(struct file *filp, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1160 {
1161         struct socket *sock;
1162 
1163         sock = socki_lookup (filp->f_inode);
1164         if (sock != NULL && sock->ops != NULL && sock->ops->fcntl != NULL)
1165                 return(sock->ops->fcntl(sock, cmd, arg));
1166         return(-EINVAL);
1167 }
1168 
1169 
1170 /*
1171  *      System call vectors. Since I (RIB) want to rewrite sockets as streams,
1172  *      we have this level of indirection. Not a lot of overhead, since more of
1173  *      the work is done via read/write/select directly.
1174  *
1175  *      I'm now expanding this up to a higher level to separate the assorted
1176  *      kernel/user space manipulations and global assumptions from the protocol
1177  *      layers proper - AC.
1178  */
1179 
1180 asmlinkage int sys_socketcall(int call, unsigned long *args)
     /* [previous][next][first][last][top][bottom][index][help] */
1181 {
1182         int er;
1183         switch(call) 
1184         {
1185                 case SYS_SOCKET:
1186                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1187                         if(er)
1188                                 return er;
1189                         return(sock_socket(get_fs_long(args+0),
1190                                 get_fs_long(args+1),
1191                                 get_fs_long(args+2)));
1192                 case SYS_BIND:
1193                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1194                         if(er)
1195                                 return er;
1196                         return(sock_bind(get_fs_long(args+0),
1197                                 (struct sockaddr *)get_fs_long(args+1),
1198                                 get_fs_long(args+2)));
1199                 case SYS_CONNECT:
1200                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1201                         if(er)
1202                                 return er;
1203                         return(sock_connect(get_fs_long(args+0),
1204                                 (struct sockaddr *)get_fs_long(args+1),
1205                                 get_fs_long(args+2)));
1206                 case SYS_LISTEN:
1207                         er=verify_area(VERIFY_READ, args, 2 * sizeof(long));
1208                         if(er)
1209                                 return er;
1210                         return(sock_listen(get_fs_long(args+0),
1211                                 get_fs_long(args+1)));
1212                 case SYS_ACCEPT:
1213                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1214                         if(er)
1215                                 return er;
1216                         return(sock_accept(get_fs_long(args+0),
1217                                 (struct sockaddr *)get_fs_long(args+1),
1218                                 (int *)get_fs_long(args+2)));
1219                 case SYS_GETSOCKNAME:
1220                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1221                         if(er)
1222                                 return er;
1223                         return(sock_getsockname(get_fs_long(args+0),
1224                                 (struct sockaddr *)get_fs_long(args+1),
1225                                 (int *)get_fs_long(args+2)));
1226                 case SYS_GETPEERNAME:
1227                         er=verify_area(VERIFY_READ, args, 3 * sizeof(long));
1228                         if(er)
1229                                 return er;
1230                         return(sock_getpeername(get_fs_long(args+0),
1231                                 (struct sockaddr *)get_fs_long(args+1),
1232                                 (int *)get_fs_long(args+2)));
1233                 case SYS_SOCKETPAIR:
1234                         er=verify_area(VERIFY_READ, args, 4 * sizeof(long));
1235                         if(er)
1236                                 return er;
1237                         return(sock_socketpair(get_fs_long(args+0),
1238                                 get_fs_long(args+1),
1239                                 get_fs_long(args+2),
1240                                 (unsigned long *)get_fs_long(args+3)));
1241                 case SYS_SEND:
1242                         er=verify_area(VERIFY_READ, args, 4 * sizeof(unsigned long));
1243                         if(er)
1244                                 return er;
1245                         return(sock_send(get_fs_long(args+0),
1246                                 (void *)get_fs_long(args+1),
1247                                 get_fs_long(args+2),
1248                                 get_fs_long(args+3)));
1249                 case SYS_SENDTO:
1250                         er=verify_area(VERIFY_READ, args, 6 * sizeof(unsigned long));
1251                         if(er)
1252                                 return er;
1253                         return(sock_sendto(get_fs_long(args+0),
1254                                 (void *)get_fs_long(args+1),
1255                                 get_fs_long(args+2),
1256                                 get_fs_long(args+3),
1257                                 (struct sockaddr *)get_fs_long(args+4),
1258                                 get_fs_long(args+5)));
1259                 case SYS_RECV:
1260                         er=verify_area(VERIFY_READ, args, 4 * sizeof(unsigned long));
1261                         if(er)
1262                                 return er;
1263                         return(sock_recv(get_fs_long(args+0),
1264                                 (void *)get_fs_long(args+1),
1265                                 get_fs_long(args+2),
1266                                 get_fs_long(args+3)));
1267                 case SYS_RECVFROM:
1268                         er=verify_area(VERIFY_READ, args, 6 * sizeof(unsigned long));
1269                         if(er)
1270                                 return er;
1271                         return(sock_recvfrom(get_fs_long(args+0),
1272                                 (void *)get_fs_long(args+1),
1273                                 get_fs_long(args+2),
1274                                 get_fs_long(args+3),
1275                                 (struct sockaddr *)get_fs_long(args+4),
1276                                 (int *)get_fs_long(args+5)));
1277                 case SYS_SHUTDOWN:
1278                         er=verify_area(VERIFY_READ, args, 2* sizeof(unsigned long));
1279                         if(er)
1280                                 return er;
1281                         return(sock_shutdown(get_fs_long(args+0),
1282                                 get_fs_long(args+1)));
1283                 case SYS_SETSOCKOPT:
1284                         er=verify_area(VERIFY_READ, args, 5*sizeof(unsigned long));
1285                         if(er)
1286                                 return er;
1287                         return(sock_setsockopt(get_fs_long(args+0),
1288                                 get_fs_long(args+1),
1289                                 get_fs_long(args+2),
1290                                 (char *)get_fs_long(args+3),
1291                                 get_fs_long(args+4)));
1292                 case SYS_GETSOCKOPT:
1293                         er=verify_area(VERIFY_READ, args, 5*sizeof(unsigned long));
1294                         if(er)
1295                                 return er;
1296                         return(sock_getsockopt(get_fs_long(args+0),
1297                                 get_fs_long(args+1),
1298                                 get_fs_long(args+2),
1299                                 (char *)get_fs_long(args+3),
1300                                 (int *)get_fs_long(args+4)));
1301                 default:
1302                         return(-EINVAL);
1303         }
1304 }
1305 
1306 /*
1307  *      This function is called by a protocol handler that wants to
1308  *      advertise its address family, and have it linked into the
1309  *      SOCKET module.
1310  */
1311  
1312 int sock_register(int family, struct proto_ops *ops)
     /* [previous][next][first][last][top][bottom][index][help] */
1313 {
1314         int i;
1315 
1316         cli();
1317         for(i = 0; i < NPROTO; i++) 
1318         {
1319                 if (pops[i] != NULL) 
1320                         continue;
1321                 pops[i] = ops;
1322                 pops[i]->family = family;
1323                 sti();
1324                 return(i);
1325         }
1326         sti();
1327         return(-ENOMEM);
1328 }
1329 
1330 /*
1331  *      This function is called by a protocol handler that wants to
1332  *      remove its address family, and have it unlinked from the
1333  *      SOCKET module.
1334  */
1335  
1336 int sock_unregister(int family)
     /* [previous][next][first][last][top][bottom][index][help] */
1337 {
1338         int i;
1339 
1340         cli();
1341         for(i = 0; i < NPROTO; i++) 
1342         {
1343                 if (pops[i] == NULL) 
1344                         continue;
1345                 if(pops[i]->family == family)
1346                 {
1347                         pops[i]=NULL;
1348                         sti();
1349                         return(i);
1350                 }
1351         }
1352         sti();
1353         return(-ENOENT);
1354 }
1355 
1356 void proto_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1357 {
1358         extern struct net_proto protocols[];    /* Network protocols */
1359         struct net_proto *pro;
1360 
1361         /* Kick all configured protocols. */
1362         pro = protocols;
1363         while (pro->name != NULL) 
1364         {
1365                 (*pro->init_func)(pro);
1366                 pro++;
1367         }
1368         /* We're all done... */
1369 }
1370 
1371 
1372 void sock_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1373 {
1374         struct socket *sock;
1375         int i;
1376 
1377         printk("Swansea University Computer Society NET3.017\n");
1378 
1379         /*
1380          *      Release all sockets. 
1381          */
1382         for (sock = sockets; sock <= last_socket; ++sock)
1383                 sock->state = SS_FREE;
1384 
1385         /*
1386          *      Initialize all address (protocol) families. 
1387          */
1388          
1389         for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
1390 
1391         /*
1392          *      Initialize the protocols module. 
1393          */
1394 
1395         proto_init();
1396 
1397 #ifdef CONFIG_NET
1398         /* 
1399          *      Initialize the DEV module. 
1400          */
1401 
1402         dev_init();
1403   
1404         /*
1405          *      And the bottom half handler 
1406          */
1407 
1408         bh_base[NET_BH].routine= net_bh;
1409 #endif  
1410   
1411 }

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