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         int err=-EOPNOTSUPP;
 674         
 675         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 676                 return(-EBADF);
 677         if (!(sock = sockfd_lookup(fd, NULL))) 
 678                 return(-ENOTSOCK);
 679 
 680         if (sock->state != SS_UNCONNECTED) 
 681                 return(-EINVAL);
 682 
 683         if (sock->ops && sock->ops->listen)
 684         {
 685                 err=sock->ops->listen(sock, backlog);
 686                 if(!err)
 687                         sock->flags |= SO_ACCEPTCON;
 688         }
 689         return(err);
 690 }
 691 
 692 
 693 /*
 694  *      For accept, we attempt to create a new socket, set up the link
 695  *      with the client, wake up the client, then return the new
 696  *      connected fd. We collect the address of the connector in kernel
 697  *      space and move it to user at the very end. This is buggy because
 698  *      we open the socket then return an error.
 699  */
 700 
 701 asmlinkage int sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 702 {
 703         struct file *file;
 704         struct socket *sock, *newsock;
 705         int i;
 706         char address[MAX_SOCK_ADDR];
 707         int len;
 708 
 709         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 710                 return(-EBADF);
 711         if (!(sock = sockfd_lookup(fd, &file))) 
 712                 return(-ENOTSOCK);
 713         if (sock->state != SS_UNCONNECTED) 
 714         {
 715                 return(-EINVAL);
 716         }
 717         if (!(sock->flags & SO_ACCEPTCON)) 
 718         {
 719                 return(-EINVAL);
 720         }
 721 
 722         if (!(newsock = sock_alloc())) 
 723         {
 724                 printk("NET: sock_accept: no more sockets\n");
 725                 return(-ENOSR); /* Was: EAGAIN, but we are out of system
 726                                    resources! */
 727         }
 728         newsock->type = sock->type;
 729         newsock->ops = sock->ops;
 730         if ((i = sock->ops->dup(newsock, sock)) < 0) 
 731         {
 732                 sock_release(newsock);
 733                 return(i);
 734         }
 735 
 736         i = newsock->ops->accept(sock, newsock, file->f_flags);
 737         if ( i < 0) 
 738         {
 739                 sock_release(newsock);
 740                 return(i);
 741         }
 742 
 743         if ((fd = get_fd(SOCK_INODE(newsock))) < 0) 
 744         {
 745                 sock_release(newsock);
 746                 return(-EINVAL);
 747         }
 748 
 749         if (upeer_sockaddr)
 750         {
 751                 newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 1);
 752                 move_addr_to_user(address,len, upeer_sockaddr, upeer_addrlen);
 753         }
 754         return(fd);
 755 }
 756 
 757 
 758 /*
 759  *      Attempt to connect to a socket with the server address.  The address
 760  *      is in user space so we verify it is OK and move it to kernel space.
 761  */
 762  
 763 asmlinkage int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 764 {
 765         struct socket *sock;
 766         struct file *file;
 767         int i;
 768         char address[MAX_SOCK_ADDR];
 769         int err;
 770 
 771         if (fd < 0 || fd >= NR_OPEN || (file=current->files->fd[fd]) == NULL)
 772                 return(-EBADF);
 773         if (!(sock = sockfd_lookup(fd, &file)))
 774                 return(-ENOTSOCK);
 775 
 776         if((err=move_addr_to_kernel(uservaddr,addrlen,address))<0)
 777                 return err;
 778   
 779         switch(sock->state) 
 780         {
 781                 case SS_UNCONNECTED:
 782                         /* This is ok... continue with connect */
 783                         break;
 784                 case SS_CONNECTED:
 785                         /* Socket is already connected */
 786                         if(sock->type == SOCK_DGRAM) /* Hack for now - move this all into the protocol */
 787                                 break;
 788                         return -EISCONN;
 789                 case SS_CONNECTING:
 790                         /* Not yet connected... we will check this. */
 791                 
 792                         /*
 793                          *      FIXME:  for all protocols what happens if you start
 794                          *      an async connect fork and both children connect. Clean
 795                          *      this up in the protocols!
 796                          */
 797                         break;
 798                 default:
 799                         return(-EINVAL);
 800         }
 801         i = sock->ops->connect(sock, (struct sockaddr *)address, addrlen, file->f_flags);
 802         if (i < 0) 
 803         {
 804                 return(i);
 805         }
 806         return(0);
 807 }
 808 
 809 /*
 810  *      Get the local address ('name') of a socket object. Move the obtained
 811  *      name to user space.
 812  */
 813 
 814 asmlinkage int sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 815 {
 816         struct socket *sock;
 817         char address[MAX_SOCK_ADDR];
 818         int len;
 819         int err;
 820         
 821         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 822                 return(-EBADF);
 823         if (!(sock = sockfd_lookup(fd, NULL)))
 824                 return(-ENOTSOCK);
 825 
 826         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
 827         if(err)
 828                 return err;
 829         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 830                 return err;
 831         return 0;
 832 }
 833 
 834 /*
 835  *      Get the remote address ('name') of a socket object. Move the obtained
 836  *      name to user space.
 837  */
 838  
 839 asmlinkage int sys_getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 840 {
 841         struct socket *sock;
 842         char address[MAX_SOCK_ADDR];
 843         int len;
 844         int err;
 845 
 846         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 847                 return(-EBADF);
 848         if (!(sock = sockfd_lookup(fd, NULL)))
 849                 return(-ENOTSOCK);
 850 
 851         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
 852         if(err)
 853                 return err;
 854         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 855                 return err;
 856         return 0;
 857 }
 858 
 859 /*
 860  *      Send a datagram down a socket. The datagram as with write() is
 861  *      in user space. We check it can be read.
 862  */
 863 
 864 asmlinkage int sys_send(int fd, void * buff, int len, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 865 {
 866         struct socket *sock;
 867         struct file *file;
 868         int err;
 869         struct msghdr msg;
 870         struct iovec iov;
 871 
 872         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 873                 return(-EBADF);
 874         if (!(sock = sockfd_lookup(fd, NULL))) 
 875                 return(-ENOTSOCK);
 876 
 877         if(len<0)
 878                 return -EINVAL;
 879         err=verify_area(VERIFY_READ, buff, len);
 880         if(err)
 881                 return err;
 882                 
 883         iov.iov_base=buff;
 884         iov.iov_len=len;
 885         msg.msg_name=NULL;
 886         msg.msg_iov=&iov;
 887         msg.msg_iovlen=1;
 888         msg.msg_accrights=NULL;
 889         return(sock->ops->sendmsg(sock, &msg, len, (file->f_flags & O_NONBLOCK), flags));
 890 }
 891 
 892 /*
 893  *      Send a datagram to a given address. We move the address into kernel
 894  *      space and check the user space data area is readable before invoking
 895  *      the protocol.
 896  */
 897 
 898 asmlinkage int sys_sendto(int fd, void * buff, int len, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
 899            struct sockaddr *addr, int addr_len)
 900 {
 901         struct socket *sock;
 902         struct file *file;
 903         char address[MAX_SOCK_ADDR];
 904         int err;
 905         struct msghdr msg;
 906         struct iovec iov;
 907         
 908         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 909                 return(-EBADF);
 910         if (!(sock = sockfd_lookup(fd, NULL)))
 911                 return(-ENOTSOCK);
 912 
 913         if(len<0)
 914                 return -EINVAL;
 915         err=verify_area(VERIFY_READ,buff,len);
 916         if(err)
 917                 return err;
 918         
 919         if((err=move_addr_to_kernel(addr,addr_len,address))<0)
 920                 return err;
 921                 
 922         iov.iov_base=buff;
 923         iov.iov_len=len;
 924         msg.msg_name=address;
 925         msg.msg_namelen=addr_len;
 926         msg.msg_iov=&iov;
 927         msg.msg_iovlen=1;
 928         msg.msg_accrights=NULL;
 929         return(sock->ops->sendmsg(sock, &msg, len, (file->f_flags & O_NONBLOCK),
 930                 flags));
 931 }
 932 
 933 
 934 /*
 935  *      Receive a datagram from a socket. Call the protocol recvmsg method
 936  */
 937 
 938 asmlinkage int sys_recv(int fd, void * ubuf, int size, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 939 {
 940         struct iovec iov;
 941         struct msghdr msg;
 942         struct socket *sock;
 943         struct file *file;
 944         int err;
 945 
 946         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 947                 return(-EBADF);
 948 
 949         if (!(sock = sockfd_lookup(fd, NULL))) 
 950                 return(-ENOTSOCK);
 951                 
 952         if(size<0)
 953                 return -EINVAL;
 954         if(size==0)
 955                 return 0;
 956         err=verify_area(VERIFY_WRITE, ubuf, size);
 957         if(err)
 958                 return err;
 959                 
 960         msg.msg_name=NULL;
 961         msg.msg_iov=&iov;
 962         msg.msg_iovlen=1;
 963         msg.msg_accrights=NULL;
 964         iov.iov_base=ubuf;
 965         iov.iov_len=size;
 966 
 967         return(sock->ops->recvmsg(sock, &msg, size,(file->f_flags & O_NONBLOCK), flags,&msg.msg_namelen));
 968 }
 969 
 970 /*
 971  *      Receive a frame from the socket and optionally record the address of the 
 972  *      sender. We verify the buffers are writable and if needed move the
 973  *      sender address from kernel to user space.
 974  */
 975 
 976 asmlinkage int sys_recvfrom(int fd, void * ubuf, int size, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
 977              struct sockaddr *addr, int *addr_len)
 978 {
 979         struct socket *sock;
 980         struct file *file;
 981         struct iovec iov;
 982         struct msghdr msg;
 983         char address[MAX_SOCK_ADDR];
 984         int err;
 985         int alen;
 986         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 987                 return(-EBADF);
 988         if (!(sock = sockfd_lookup(fd, NULL))) 
 989                 return(-ENOTSOCK);
 990         if(size<0)
 991                 return -EINVAL;
 992         if(size==0)
 993                 return 0;
 994 
 995         err=verify_area(VERIFY_WRITE,ubuf,size);
 996         if(err)
 997                 return err;
 998   
 999         msg.msg_accrights=NULL;
1000         msg.msg_iovlen=0;
1001         msg.msg_iov=&iov;
1002         iov.iov_len=size;
1003         iov.iov_base=ubuf;
1004         msg.msg_name=address;
1005         msg.msg_namelen=MAX_SOCK_ADDR;
1006         size=sock->ops->recvmsg(sock, &msg, size, (file->f_flags & O_NONBLOCK),
1007                      flags, &alen);
1008 
1009         if(size<0)
1010                 return size;
1011         if(addr!=NULL && (err=move_addr_to_user(address,alen, addr, addr_len))<0)
1012                 return err;
1013 
1014         return size;
1015 }
1016 
1017 /*
1018  *      Set a socket option. Because we don't know the option lengths we have
1019  *      to pass the user mode parameter for the protocols to sort out.
1020  */
1021  
1022 asmlinkage int sys_setsockopt(int fd, int level, int optname, char *optval, int optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1023 {
1024         struct socket *sock;
1025         struct file *file;
1026         
1027         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1028                 return(-EBADF);
1029         if (!(sock = sockfd_lookup(fd, NULL))) 
1030                 return(-ENOTSOCK);
1031 
1032         return(sock->ops->setsockopt(sock, level, optname, optval, optlen));
1033 }
1034 
1035 /*
1036  *      Get a socket option. Because we don't know the option lengths we have
1037  *      to pass a user mode parameter for the protocols to sort out.
1038  */
1039 
1040 asmlinkage int sys_getsockopt(int fd, int level, int optname, char *optval, int *optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1041 {
1042         struct socket *sock;
1043         struct file *file;
1044 
1045         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1046                 return(-EBADF);
1047         if (!(sock = sockfd_lookup(fd, NULL)))
1048                 return(-ENOTSOCK);
1049             
1050         if (!sock->ops->getsockopt) 
1051                 return(0);
1052         return(sock->ops->getsockopt(sock, level, optname, optval, optlen));
1053 }
1054 
1055 
1056 /*
1057  *      Shutdown a socket.
1058  */
1059  
1060 asmlinkage int sys_shutdown(int fd, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
1061 {
1062         struct socket *sock;
1063         struct file *file;
1064 
1065         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1066                 return(-EBADF);
1067         if (!(sock = sockfd_lookup(fd, NULL))) 
1068                 return(-ENOTSOCK);
1069 
1070         return(sock->ops->shutdown(sock, how));
1071 }
1072 
1073 /*
1074  *      BSD sendmsg interface
1075  */
1076  
1077 asmlinkage int sys_sendmsg(int fd, struct msghdr *msg, unsigned int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1078 {
1079         struct socket *sock;
1080         struct file *file;
1081         char address[MAX_SOCK_ADDR];
1082         struct iovec iov[MAX_IOVEC];
1083         struct msghdr msg_sys;
1084         int err;
1085         int total_len;
1086         
1087         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1088                 return(-EBADF);
1089         if (!(sock = sockfd_lookup(fd, NULL)))
1090                 return(-ENOTSOCK);
1091         
1092         err=verify_area(VERIFY_READ, msg,sizeof(struct msghdr));
1093         if(err)
1094                 return err;
1095         memcpy_fromfs(&msg_sys,msg,sizeof(struct msghdr));
1096         if(msg_sys.msg_iovlen>MAX_IOVEC)
1097                 return -EINVAL;
1098         err=verify_iovec(&msg_sys,iov,address, VERIFY_READ);
1099         if(err<0)
1100                 return err;
1101         total_len=err;
1102         
1103         if(sock->ops->sendmsg==NULL)
1104                 return -EOPNOTSUPP;
1105         return sock->ops->sendmsg(sock, &msg_sys, total_len, (file->f_flags&O_NONBLOCK), flags);
1106 }
1107 
1108 /*
1109  *      BSD recvmsg interface
1110  */
1111  
1112 asmlinkage int sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1113 {
1114         struct socket *sock;
1115         struct file *file;
1116         char address[MAX_SOCK_ADDR];
1117         struct iovec iov[MAX_IOVEC];
1118         struct msghdr msg_sys;
1119         int err;
1120         int total_len;
1121         int addr_len;
1122         int len;
1123         
1124         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1125                 return(-EBADF);
1126         if (!(sock = sockfd_lookup(fd, NULL)))
1127                 return(-ENOTSOCK);
1128         
1129         err=verify_area(VERIFY_READ, msg,sizeof(struct msghdr));
1130         if(err)
1131                 return err;
1132         memcpy_fromfs(&msg_sys,msg,sizeof(struct msghdr));
1133         if(msg_sys.msg_iovlen>MAX_IOVEC)
1134                 return -EINVAL;
1135         err=verify_iovec(&msg_sys,iov,address, VERIFY_WRITE);
1136         if(err<0)
1137                 return err;
1138         total_len=err;
1139         
1140         if(sock->ops->recvmsg==NULL)
1141                 return -EOPNOTSUPP;
1142         len=sock->ops->recvmsg(sock, &msg_sys, total_len, (file->f_flags&O_NONBLOCK), flags, &addr_len);
1143         if(len<0)
1144                 return len;
1145         /*
1146          *      Fixme: writing actual length into original msghdr.
1147          */
1148         if(msg_sys.msg_name!=NULL && (err=move_addr_to_user(address,addr_len, msg_sys.msg_name, &msg_sys.msg_namelen))<0)
1149                 return err;
1150         return len;
1151 }
1152 
1153 
1154 /*
1155  *      Perform a file control on a socket file descriptor.
1156  */
1157 
1158 int sock_fcntl(struct file *filp, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1159 {
1160         struct socket *sock;
1161 
1162         sock = socki_lookup (filp->f_inode);
1163         if (sock != NULL && sock->ops != NULL && sock->ops->fcntl != NULL)
1164                 return(sock->ops->fcntl(sock, cmd, arg));
1165         return(-EINVAL);
1166 }
1167 
1168 
1169 /*
1170  *      System call vectors. Since I (RIB) want to rewrite sockets as streams,
1171  *      we have this level of indirection. Not a lot of overhead, since more of
1172  *      the work is done via read/write/select directly.
1173  *
1174  *      I'm now expanding this up to a higher level to separate the assorted
1175  *      kernel/user space manipulations and global assumptions from the protocol
1176  *      layers proper - AC.
1177  *
1178  *      Argument checking cleaned up. Saved 20% in size.
1179  */
1180 
1181 asmlinkage int sys_socketcall(int call, unsigned long *args)
     /* [previous][next][first][last][top][bottom][index][help] */
1182 {
1183         int er;
1184         unsigned char nargs[18]={0,3,3,3,2,3,3,3,
1185                                  4,4,4,6,6,2,5,5,3,3};
1186 
1187         unsigned long a0,a1;
1188                                  
1189         if(call<1||call>SYS_RECVMSG)
1190                 return -EINVAL;
1191                 
1192         er=verify_area(VERIFY_READ, args, nargs[call] * sizeof(unsigned long));
1193         if(er)
1194                 return er;
1195                 
1196         a0=get_user(args);
1197         a1=get_user(args+1);
1198         
1199                 
1200         switch(call) 
1201         {
1202                 case SYS_SOCKET:
1203                         return(sys_socket(a0,a1,get_user(args+2)));
1204                 case SYS_BIND:
1205                         return(sys_bind(a0,(struct sockaddr *)a1,
1206                                         get_user(args+2)));
1207                 case SYS_CONNECT:
1208                         return(sys_connect(a0, (struct sockaddr *)a1,
1209                                            get_user(args+2)));
1210                 case SYS_LISTEN:
1211                         return(sys_listen(a0,a1));
1212                 case SYS_ACCEPT:
1213                         return(sys_accept(a0,(struct sockaddr *)a1,
1214                                           (int *)get_user(args+2)));
1215                 case SYS_GETSOCKNAME:
1216                         return(sys_getsockname(a0,(struct sockaddr *)a1,
1217                                                (int *)get_user(args+2)));
1218                 case SYS_GETPEERNAME:
1219                         return(sys_getpeername(a0, (struct sockaddr *)a1,
1220                                                (int *)get_user(args+2)));
1221                 case SYS_SOCKETPAIR:
1222                         return(sys_socketpair(a0,a1,
1223                                               get_user(args+2),
1224                                               (int *)get_user(args+3)));
1225                 case SYS_SEND:
1226                         return(sys_send(a0,
1227                                 (void *)a1,
1228                                 get_user(args+2),
1229                                 get_user(args+3)));
1230                 case SYS_SENDTO:
1231                         return(sys_sendto(a0,(void *)a1,
1232                                 get_user(args+2),
1233                                 get_user(args+3),
1234                                 (struct sockaddr *)get_user(args+4),
1235                                 get_user(args+5)));
1236                 case SYS_RECV:
1237                         return(sys_recv(a0,
1238                                 (void *)a1,
1239                                 get_user(args+2),
1240                                 get_user(args+3)));
1241                 case SYS_RECVFROM:
1242                         return(sys_recvfrom(a0,
1243                                 (void *)a1,
1244                                 get_user(args+2),
1245                                 get_user(args+3),
1246                                 (struct sockaddr *)get_user(args+4),
1247                                 (int *)get_user(args+5)));
1248                 case SYS_SHUTDOWN:
1249                         return(sys_shutdown(a0,a1));
1250                 case SYS_SETSOCKOPT:
1251                         return(sys_setsockopt(a0,
1252                                 a1,
1253                                 get_user(args+2),
1254                                 (char *)get_user(args+3),
1255                                 get_user(args+4)));
1256                 case SYS_GETSOCKOPT:
1257                         return(sys_getsockopt(a0,
1258                                 a1,
1259                                 get_user(args+2),
1260                                 (char *)get_user(args+3),
1261                                 (int *)get_user(args+4)));
1262                 case SYS_SENDMSG:
1263                                 return sys_sendmsg(a0,
1264                                         (struct msghdr *) a1,
1265                                         get_user(args+2));
1266                 case SYS_RECVMSG:
1267                                 return sys_recvmsg(a0,
1268                                         (struct msghdr *) a1,
1269                                         get_user(args+2));
1270         }
1271         return -EINVAL; /* to keep gcc happy */
1272 }
1273 
1274 /*
1275  *      This function is called by a protocol handler that wants to
1276  *      advertise its address family, and have it linked into the
1277  *      SOCKET module.
1278  */
1279  
1280 int sock_register(int family, struct proto_ops *ops)
     /* [previous][next][first][last][top][bottom][index][help] */
1281 {
1282         int i;
1283 
1284         cli();
1285         for(i = 0; i < NPROTO; i++) 
1286         {
1287                 if (pops[i] != NULL) 
1288                         continue;
1289                 pops[i] = ops;
1290                 pops[i]->family = family;
1291                 sti();
1292                 return(i);
1293         }
1294         sti();
1295         return(-ENOMEM);
1296 }
1297 
1298 /*
1299  *      This function is called by a protocol handler that wants to
1300  *      remove its address family, and have it unlinked from the
1301  *      SOCKET module.
1302  */
1303  
1304 int sock_unregister(int family)
     /* [previous][next][first][last][top][bottom][index][help] */
1305 {
1306         int i;
1307 
1308         cli();
1309         for(i = 0; i < NPROTO; i++) 
1310         {
1311                 if (pops[i] == NULL) 
1312                         continue;
1313                 if (pops[i]->family == family)
1314                 {
1315                         pops[i]=NULL;
1316                         sti();
1317                         return(i);
1318                 }
1319         }
1320         sti();
1321         return(-ENOENT);
1322 }
1323 
1324 void proto_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1325 {
1326         extern struct net_proto protocols[];    /* Network protocols */
1327         struct net_proto *pro;
1328 
1329         /* Kick all configured protocols. */
1330         pro = protocols;
1331         while (pro->name != NULL) 
1332         {
1333                 (*pro->init_func)(pro);
1334                 pro++;
1335         }
1336         /* We're all done... */
1337 }
1338 
1339 
1340 void sock_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1341 {
1342         int i;
1343 
1344         printk("Swansea University Computer Society NET3.033 for Linux 1.3.38\n");
1345 
1346         /*
1347          *      Initialize all address (protocol) families. 
1348          */
1349          
1350         for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
1351         
1352         /*
1353          *      The netlink device handler may be needed early.
1354          */
1355 
1356 #ifdef CONFIG_NETLINK
1357         init_netlink();
1358 #endif           
1359         /*
1360          *      Attach the routing/device information port.
1361          */
1362 
1363 #if defined(CONFIG_RTNETLINK)
1364         netlink_attach(NETLINK_ROUTE, netlink_donothing);
1365 #endif
1366 
1367         /*
1368          *      Attach the firewall module if configured
1369          */
1370          
1371 #ifdef CONFIG_FIREWALL   
1372         fwchain_init();
1373 #endif
1374 
1375         /*
1376          *      Initialize the protocols module. 
1377          */
1378 
1379         proto_init();
1380 }
1381 
1382 int socket_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
1383 {
1384         int len = sprintf(buffer, "sockets: used %d\n", sockets_in_use);
1385         if (offset >= len)
1386         {
1387                 *start = buffer;
1388                 return 0;
1389         }
1390         *start = buffer + offset;
1391         len -= offset;
1392         if (len > length)
1393                 len = length;
1394         return len;
1395 }

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