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_ioctl
  13. sock_select
  14. sock_close
  15. sock_fasync
  16. sock_wake_async
  17. find_protocol_family
  18. sys_socket
  19. sys_socketpair
  20. sys_bind
  21. sys_listen
  22. sys_accept
  23. sys_connect
  24. sys_getsockname
  25. sys_getpeername
  26. sys_send
  27. sys_sendto
  28. sys_recv
  29. sys_recvfrom
  30. sys_setsockopt
  31. sys_getsockopt
  32. sys_shutdown
  33. sys_sendmsg
  34. sys_recvmsg
  35. sock_fcntl
  36. sys_socketcall
  37. sock_register
  38. sock_unregister
  39. proto_init
  40. sock_init
  41. socket_get_info

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

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