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

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