root/net/inet/af_inet.c

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

DEFINITIONS

This source file includes following definitions.
  1. sk_inuse
  2. get_new_socknum
  3. put_sock
  4. remove_sock
  5. destroy_sock
  6. inet_fcntl
  7. inet_setsockopt
  8. inet_getsockopt
  9. inet_autobind
  10. inet_listen
  11. def_callback1
  12. def_callback2
  13. inet_create
  14. inet_dup
  15. inet_release
  16. inet_bind
  17. inet_error
  18. inet_connect
  19. inet_socketpair
  20. inet_accept
  21. inet_getname
  22. inet_recvfrom
  23. inet_recv
  24. inet_read
  25. inet_send
  26. inet_write
  27. inet_sendto
  28. inet_shutdown
  29. inet_select
  30. inet_ioctl
  31. get_sock
  32. inet_proto_init

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              AF_INET protocol family socket handler.
   7  *
   8  * Version:     @(#)af_inet.c   (from sock.c) 1.0.17    06/02/93
   9  *
  10  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *              Florian La Roche, <flla@stud.uni-sb.de>
  13  *              Alan Cox, <A.Cox@swansea.ac.uk>
  14  *
  15  * Changes (see also sock.c)
  16  *
  17  *              A.N.Kuznetsov   :       Socket death error in accept().
  18  *              John Richardson :       Fix non blocking error in connect()
  19  *                                      so sockets that fail to connect
  20  *                                      don't return -EINPROGRESS.
  21  *              Alan Cox        :       Asynchronous I/O support
  22  *              Alan Cox        :       Keep correct socket pointer on sock structures
  23  *                                      when accept() ed
  24  *
  25  *              This program is free software; you can redistribute it and/or
  26  *              modify it under the terms of the GNU General Public License
  27  *              as published by the Free Software Foundation; either version
  28  *              2 of the License, or (at your option) any later version.
  29  */
  30 
  31 #include <linux/config.h>
  32 #include <linux/errno.h>
  33 #include <linux/types.h>
  34 #include <linux/socket.h>
  35 #include <linux/in.h>
  36 #include <linux/kernel.h>
  37 #include <linux/major.h>
  38 #include <linux/sched.h>
  39 #include <linux/timer.h>
  40 #include <linux/string.h>
  41 #include <linux/sockios.h>
  42 #include <linux/net.h>
  43 #include <linux/fcntl.h>
  44 #include <linux/mm.h>
  45 #include <linux/interrupt.h>
  46 
  47 #include <asm/segment.h>
  48 #include <asm/system.h>
  49 
  50 #include <linux/inet.h>
  51 #include <linux/netdevice.h>
  52 #include "ip.h"
  53 #include "protocol.h"
  54 #include "arp.h"
  55 #include "rarp.h"
  56 #include "route.h"
  57 #include "tcp.h"
  58 #include "udp.h"
  59 #include <linux/skbuff.h>
  60 #include "sock.h"
  61 #include "raw.h"
  62 #include "icmp.h"
  63 
  64 #define min(a,b)        ((a)<(b)?(a):(b))
  65 
  66 extern struct proto packet_prot;
  67 
  68 
  69 /*
  70  *      See if a socket number is in use.
  71  */
  72  
  73 static int sk_inuse(struct proto *prot, int num)
     /* [previous][next][first][last][top][bottom][index][help] */
  74 {
  75         struct sock *sk;
  76 
  77         for(sk = prot->sock_array[num & (SOCK_ARRAY_SIZE -1 )];
  78                 sk != NULL;  sk=sk->next) 
  79         {
  80                 if (sk->num == num) 
  81                         return(1);
  82         }
  83         return(0);
  84 }
  85 
  86 
  87 /*
  88  *      Pick a new socket number
  89  */
  90 
  91 unsigned short get_new_socknum(struct proto *prot, unsigned short base)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93         static int start=0;
  94 
  95         /*
  96          * Used to cycle through the port numbers so the
  97          * chances of a confused connection drop.
  98          */
  99          
 100         int i, j;
 101         int best = 0;
 102         int size = 32767; /* a big num. */
 103         struct sock *sk;
 104 
 105         if (base == 0) 
 106                 base = PROT_SOCK+1+(start % 1024);
 107         if (base <= PROT_SOCK) 
 108         {
 109                 base += PROT_SOCK+(start % 1024);
 110         }
 111 
 112         /* Now look through the entire array and try to find an empty ptr. */
 113         for(i=0; i < SOCK_ARRAY_SIZE; i++) 
 114         {
 115                 j = 0;
 116                 sk = prot->sock_array[(i+base+1) &(SOCK_ARRAY_SIZE -1)];
 117                 while(sk != NULL) 
 118                 {
 119                         sk = sk->next;
 120                         j++;
 121                 }
 122                 if (j == 0) 
 123                 {
 124                         start =(i+1+start )%1024;
 125                         return(i+base+1);
 126                 }
 127                 if (j < size) 
 128                 {
 129                         best = i;
 130                         size = j;
 131                 }
 132         }
 133 
 134         /* Now make sure the one we want is not in use. */
 135 
 136         while(sk_inuse(prot, base +best+1)) 
 137         {
 138                 best += SOCK_ARRAY_SIZE;
 139         }
 140         return(best+base+1);
 141 }
 142 
 143 /*
 144  *      Add a socket into the socket tables by number.
 145  */
 146 
 147 void put_sock(unsigned short num, struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 148 {
 149         struct sock *sk1;
 150         struct sock *sk2;
 151         int mask;
 152 
 153         sk->num = num;
 154         sk->next = NULL;
 155         num = num &(SOCK_ARRAY_SIZE -1);
 156 
 157         /* We can't have an interrupt re-enter here. */
 158         cli();
 159         if (sk->prot->sock_array[num] == NULL) 
 160         {
 161                 sk->prot->sock_array[num] = sk;
 162                 sti();
 163                 return;
 164         }
 165         sti();
 166         for(mask = 0xff000000; mask != 0xffffffff; mask = (mask >> 8) | mask) 
 167         {
 168                 if ((mask & sk->saddr) &&
 169                     (mask & sk->saddr) != (mask & 0xffffffff)) 
 170                 {
 171                         mask = mask << 8;
 172                         break;
 173                 }
 174         }
 175         cli();
 176         sk1 = sk->prot->sock_array[num];
 177         for(sk2 = sk1; sk2 != NULL; sk2=sk2->next) 
 178         {
 179                 if (!(sk2->saddr & mask)) 
 180                 {
 181                         if (sk2 == sk1) 
 182                         {
 183                                 sk->next = sk->prot->sock_array[num];
 184                                 sk->prot->sock_array[num] = sk;
 185                                 sti();
 186                                 return;
 187                         }
 188                         sk->next = sk2;
 189                         sk1->next= sk;
 190                         sti();
 191                         return;
 192                 }
 193                 sk1 = sk2;
 194         }
 195 
 196         /* Goes at the end. */
 197         sk->next = NULL;
 198         sk1->next = sk;
 199         sti();
 200 }
 201 
 202 /*
 203  *      Remove a socket from the socket tables.
 204  */
 205 
 206 static void remove_sock(struct sock *sk1)
     /* [previous][next][first][last][top][bottom][index][help] */
 207 {
 208         struct sock *sk2;
 209 
 210         if (!sk1->prot) 
 211         {
 212                 printk("sock.c: remove_sock: sk1->prot == NULL\n");
 213                 return;
 214         }
 215 
 216         /* We can't have this changing out from under us. */
 217         cli();
 218         sk2 = sk1->prot->sock_array[sk1->num &(SOCK_ARRAY_SIZE -1)];
 219         if (sk2 == sk1) 
 220         {
 221                 sk1->prot->sock_array[sk1->num &(SOCK_ARRAY_SIZE -1)] = sk1->next;
 222                 sti();
 223                 return;
 224         }
 225 
 226         while(sk2 && sk2->next != sk1) 
 227         {
 228                 sk2 = sk2->next;
 229         }
 230 
 231         if (sk2) 
 232         {
 233                 sk2->next = sk1->next;
 234                 sti();
 235                 return;
 236         }
 237         sti();
 238 }
 239 
 240 /*
 241  *      Destroy an AF_INET socket
 242  */
 243  
 244 void destroy_sock(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         struct sk_buff *skb;
 247 
 248         sk->inuse = 1;                  /* just to be safe. */
 249 
 250         /* Incase it's sleeping somewhere. */
 251         if (!sk->dead) 
 252                 sk->write_space(sk);
 253 
 254         remove_sock(sk);
 255   
 256         /* Now we can no longer get new packets. */
 257         delete_timer(sk);
 258 
 259         while ((skb = tcp_dequeue_partial(sk)) != NULL) {
 260                 IS_SKB(skb);
 261                 kfree_skb(skb, FREE_WRITE);
 262         }
 263 
 264         /* Cleanup up the write buffer. */
 265         while((skb = skb_dequeue(&sk->write_queue)) != NULL) {
 266                 IS_SKB(skb);
 267                 kfree_skb(skb, FREE_WRITE);
 268         }
 269         
 270         /*
 271          *      Don't discard received data until the user side kills its
 272          *      half of the socket.
 273          */
 274 
 275         if (sk->dead) 
 276         {
 277                 while((skb=skb_dequeue(&sk->receive_queue))!=NULL) 
 278                 {
 279                 /*
 280                  * This will take care of closing sockets that were
 281                  * listening and didn't accept everything.
 282                  */
 283                         if (skb->sk != NULL && skb->sk != sk) 
 284                         {
 285                                 IS_SKB(skb);
 286                                 skb->sk->dead = 1;
 287                                 skb->sk->prot->close(skb->sk, 0);
 288                         }
 289                         IS_SKB(skb);
 290                         kfree_skb(skb, FREE_READ);
 291                 }
 292         }       
 293 
 294         /* Now we need to clean up the send head. */
 295         cli();
 296         for(skb = sk->send_head; skb != NULL; )
 297         {
 298                 struct sk_buff *skb2;
 299 
 300                 /*
 301                  * We need to remove skb from the transmit queue,
 302                  * or maybe the arp queue.
 303                  */
 304                 if (skb->next  && skb->prev) {
 305 /*                      printk("destroy_sock: unlinked skb\n");*/
 306                         IS_SKB(skb);
 307                         skb_unlink(skb);
 308                 }
 309                 skb->dev = NULL;
 310                 skb2 = skb->link3;
 311                 kfree_skb(skb, FREE_WRITE);
 312                 skb = skb2;
 313         }
 314         sk->send_head = NULL;
 315         sti();
 316 
 317         /* And now the backlog. */
 318         while((skb=skb_dequeue(&sk->back_log))!=NULL) 
 319         {
 320                 /* this should never happen. */
 321 /*              printk("cleaning back_log\n");*/
 322                 kfree_skb(skb, FREE_READ);
 323         }
 324 
 325         /* Now if it has a half accepted/ closed socket. */
 326         if (sk->pair) 
 327         {
 328                 sk->pair->dead = 1;
 329                 sk->pair->prot->close(sk->pair, 0);
 330                 sk->pair = NULL;
 331         }
 332 
 333         /*
 334          * Now if everything is gone we can free the socket
 335          * structure, otherwise we need to keep it around until
 336          * everything is gone.
 337          */
 338 
 339           if (sk->dead && sk->rmem_alloc == 0 && sk->wmem_alloc == 0) 
 340           {
 341                 kfree_s((void *)sk,sizeof(*sk));
 342           } 
 343           else 
 344           {
 345                 /* this should never happen. */
 346                 /* actually it can if an ack has just been sent. */
 347                 sk->destroy = 1;
 348                 sk->ack_backlog = 0;
 349                 sk->inuse = 0;
 350                 reset_timer(sk, TIME_DESTROY, SOCK_DESTROY_TIME);
 351         }
 352 }
 353 
 354 /*
 355  *      The routines beyond this point handle the behaviour of an AF_INET
 356  *      socket object. Mostly it punts to the subprotocols of IP to do
 357  *      the work.
 358  */
 359  
 360 static int inet_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 361 {
 362         struct sock *sk;
 363 
 364         sk = (struct sock *) sock->data;
 365 
 366         switch(cmd) 
 367         {
 368                 case F_SETOWN:
 369                         /*
 370                          * This is a little restrictive, but it's the only
 371                          * way to make sure that you can't send a sigurg to
 372                          * another process.
 373                          */
 374                         if (!suser() && current->pgrp != -arg &&
 375                                 current->pid != arg) return(-EPERM);
 376                         sk->proc = arg;
 377                         return(0);
 378                 case F_GETOWN:
 379                         return(sk->proc);
 380                 default:
 381                         return(-EINVAL);
 382         }
 383 }
 384 
 385 /*
 386  *      Set socket options on an inet socket.
 387  */
 388  
 389 static int inet_setsockopt(struct socket *sock, int level, int optname,
     /* [previous][next][first][last][top][bottom][index][help] */
 390                     char *optval, int optlen)
 391 {
 392         struct sock *sk = (struct sock *) sock->data;  
 393         if (level == SOL_SOCKET)
 394                 return sock_setsockopt(sk,level,optname,optval,optlen);
 395         if (sk->prot->setsockopt==NULL)
 396                 return(-EOPNOTSUPP);
 397         else
 398                 return sk->prot->setsockopt(sk,level,optname,optval,optlen);
 399 }
 400 
 401 /*
 402  *      Get a socket option on an AF_INET socket.
 403  */
 404 
 405 static int inet_getsockopt(struct socket *sock, int level, int optname,
     /* [previous][next][first][last][top][bottom][index][help] */
 406                     char *optval, int *optlen)
 407 {
 408         struct sock *sk = (struct sock *) sock->data;   
 409         if (level == SOL_SOCKET) 
 410                 return sock_getsockopt(sk,level,optname,optval,optlen);
 411         if(sk->prot->getsockopt==NULL)          
 412                 return(-EOPNOTSUPP);
 413         else
 414                 return sk->prot->getsockopt(sk,level,optname,optval,optlen);
 415 }
 416 
 417 /*
 418  *      Automatically bind an unbound socket.
 419  */
 420 
 421 static int inet_autobind(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 422 {
 423         /* We may need to bind the socket. */
 424         if (sk->num == 0) 
 425         {
 426                 sk->num = get_new_socknum(sk->prot, 0);
 427                 if (sk->num == 0) 
 428                         return(-EAGAIN);
 429                 put_sock(sk->num, sk);
 430                 sk->dummy_th.source = ntohs(sk->num);
 431         }
 432         return 0;
 433 }
 434 
 435 /*
 436  *      Move a socket into listening state.
 437  */
 438  
 439 static int inet_listen(struct socket *sock, int backlog)
     /* [previous][next][first][last][top][bottom][index][help] */
 440 {
 441         struct sock *sk = (struct sock *) sock->data;
 442 
 443         if(inet_autobind(sk)!=0)
 444                 return -EAGAIN;
 445 
 446         /* We might as well re use these. */ 
 447         sk->max_ack_backlog = backlog;
 448         if (sk->state != TCP_LISTEN) 
 449         {
 450                 sk->ack_backlog = 0;
 451                 sk->state = TCP_LISTEN;
 452         }
 453         return(0);
 454 }
 455 
 456 /*
 457  *      Default callbacks for user INET sockets. These just wake up
 458  *      the user owning the socket.
 459  */
 460 
 461 static void def_callback1(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 462 {
 463         if(!sk->dead)
 464                 wake_up_interruptible(sk->sleep);
 465 }
 466 
 467 static void def_callback2(struct sock *sk,int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 468 {
 469         if(!sk->dead)
 470         {
 471                 wake_up_interruptible(sk->sleep);
 472                 sock_wake_async(sk->socket);
 473         }
 474 }
 475 
 476 
 477 /*
 478  *      Create an inet socket.
 479  *
 480  *      FIXME: Gcc would generate much better code if we set the parameters
 481  *      up in in-memory structure order. Gcc68K even more so
 482  */
 483 
 484 static int inet_create(struct socket *sock, int protocol)
     /* [previous][next][first][last][top][bottom][index][help] */
 485 {
 486         struct sock *sk;
 487         struct proto *prot;
 488         int err;
 489 
 490         sk = (struct sock *) kmalloc(sizeof(*sk), GFP_KERNEL);
 491         if (sk == NULL) 
 492                 return(-ENOBUFS);
 493         sk->num = 0;
 494         sk->reuse = 0;
 495         switch(sock->type) 
 496         {
 497                 case SOCK_STREAM:
 498                 case SOCK_SEQPACKET:
 499                         if (protocol && protocol != IPPROTO_TCP) 
 500                         {
 501                                 kfree_s((void *)sk, sizeof(*sk));
 502                                 return(-EPROTONOSUPPORT);
 503                         }
 504                         protocol = IPPROTO_TCP;
 505                         sk->no_check = TCP_NO_CHECK;
 506                         prot = &tcp_prot;
 507                         break;
 508 
 509                 case SOCK_DGRAM:
 510                         if (protocol && protocol != IPPROTO_UDP) 
 511                         {
 512                                 kfree_s((void *)sk, sizeof(*sk));
 513                                 return(-EPROTONOSUPPORT);
 514                         }
 515                         protocol = IPPROTO_UDP;
 516                         sk->no_check = UDP_NO_CHECK;
 517                         prot=&udp_prot;
 518                         break;
 519       
 520                 case SOCK_RAW:
 521                         if (!suser()) 
 522                         {
 523                                 kfree_s((void *)sk, sizeof(*sk));
 524                                 return(-EPERM);
 525                         }
 526                         if (!protocol) 
 527                         {
 528                                 kfree_s((void *)sk, sizeof(*sk));
 529                                 return(-EPROTONOSUPPORT);
 530                         }
 531                         prot = &raw_prot;
 532                         sk->reuse = 1;
 533                         sk->no_check = 0;       /*
 534                                                  * Doesn't matter no checksum is
 535                                                  * performed anyway.
 536                                                  */
 537                         sk->num = protocol;
 538                         break;
 539 
 540                 case SOCK_PACKET:
 541                         if (!suser()) 
 542                         {
 543                                 kfree_s((void *)sk, sizeof(*sk));
 544                                 return(-EPERM);
 545                         }
 546                         if (!protocol) 
 547                         {
 548                                 kfree_s((void *)sk, sizeof(*sk));
 549                                 return(-EPROTONOSUPPORT);
 550                         }
 551                         prot = &packet_prot;
 552                         sk->reuse = 1;
 553                         sk->no_check = 0;       /* Doesn't matter no checksum is
 554                                                  * performed anyway.
 555                                                  */
 556                         sk->num = protocol;
 557                         break;
 558 
 559                 default:
 560                         kfree_s((void *)sk, sizeof(*sk));
 561                         return(-ESOCKTNOSUPPORT);
 562         }
 563         sk->socket = sock;
 564 #ifdef CONFIG_TCP_NAGLE_OFF
 565         sk->nonagle = 1;
 566 #else    
 567         sk->nonagle = 0;
 568 #endif  
 569         sk->type = sock->type;
 570         sk->stamp.tv_sec=0;
 571         sk->protocol = protocol;
 572         sk->wmem_alloc = 0;
 573         sk->rmem_alloc = 0;
 574         sk->sndbuf = SK_WMEM_MAX;
 575         sk->rcvbuf = SK_RMEM_MAX;
 576         sk->pair = NULL;
 577         sk->opt = NULL;
 578         sk->write_seq = 0;
 579         sk->acked_seq = 0;
 580         sk->copied_seq = 0;
 581         sk->fin_seq = 0;
 582         sk->urg_seq = 0;
 583         sk->urg_data = 0;
 584         sk->proc = 0;
 585         sk->rtt = 0;                            /*TCP_WRITE_TIME << 3;*/
 586         sk->rto = TCP_TIMEOUT_INIT;             /*TCP_WRITE_TIME*/
 587         sk->mdev = 0;
 588         sk->backoff = 0;
 589         sk->packets_out = 0;
 590         sk->cong_window = 1; /* start with only sending one packet at a time. */
 591         sk->cong_count = 0;
 592         sk->ssthresh = 0;
 593         sk->max_window = 0;
 594         sk->urginline = 0;
 595         sk->intr = 0;
 596         sk->linger = 0;
 597         sk->destroy = 0;
 598         sk->priority = 1;
 599         sk->shutdown = 0;
 600         sk->keepopen = 0;
 601         sk->zapped = 0;
 602         sk->done = 0;
 603         sk->ack_backlog = 0;
 604         sk->window = 0;
 605         sk->bytes_rcv = 0;
 606         sk->state = TCP_CLOSE;
 607         sk->dead = 0;
 608         sk->ack_timed = 0;
 609         sk->partial = NULL;
 610         sk->user_mss = 0;
 611         sk->debug = 0;
 612 
 613         /* this is how many unacked bytes we will accept for this socket.  */
 614         sk->max_unacked = 2048; /* needs to be at most 2 full packets. */
 615 
 616         /* how many packets we should send before forcing an ack. 
 617            if this is set to zero it is the same as sk->delay_acks = 0 */
 618         sk->max_ack_backlog = 0;
 619         sk->inuse = 0;
 620         sk->delay_acks = 0;
 621         skb_queue_head_init(&sk->write_queue);
 622         skb_queue_head_init(&sk->receive_queue);
 623         sk->mtu = 576;
 624         sk->prot = prot;
 625         sk->sleep = sock->wait;
 626         sk->daddr = 0;
 627         sk->saddr = 0 /* ip_my_addr() */;
 628         sk->err = 0;
 629         sk->next = NULL;
 630         sk->pair = NULL;
 631         sk->send_tail = NULL;
 632         sk->send_head = NULL;
 633         sk->timeout = 0;
 634         sk->broadcast = 0;
 635         sk->localroute = 0;
 636         init_timer(&sk->timer);
 637         sk->timer.data = (unsigned long)sk;
 638         sk->timer.function = &net_timer;
 639         skb_queue_head_init(&sk->back_log);
 640         sk->blog = 0;
 641         sock->data =(void *) sk;
 642         sk->dummy_th.doff = sizeof(sk->dummy_th)/4;
 643         sk->dummy_th.res1=0;
 644         sk->dummy_th.res2=0;
 645         sk->dummy_th.urg_ptr = 0;
 646         sk->dummy_th.fin = 0;
 647         sk->dummy_th.syn = 0;
 648         sk->dummy_th.rst = 0;
 649         sk->dummy_th.psh = 0;
 650         sk->dummy_th.ack = 0;
 651         sk->dummy_th.urg = 0;
 652         sk->dummy_th.dest = 0;
 653         sk->ip_tos=0;
 654         sk->ip_ttl=64;
 655         
 656         sk->state_change = def_callback1;
 657         sk->data_ready = def_callback2;
 658         sk->write_space = def_callback1;
 659         sk->error_report = def_callback1;
 660 
 661         if (sk->num) 
 662         {
 663         /*
 664          * It assumes that any protocol which allows
 665          * the user to assign a number at socket
 666          * creation time automatically
 667          * shares.
 668          */
 669                 put_sock(sk->num, sk);
 670                 sk->dummy_th.source = ntohs(sk->num);
 671         }
 672 
 673         if (sk->prot->init) 
 674         {
 675                 err = sk->prot->init(sk);
 676                 if (err != 0) 
 677                 {
 678                         destroy_sock(sk);
 679                         return(err);
 680                 }
 681         }
 682         return(0);
 683 }
 684 
 685 
 686 /*
 687  *      Duplicate a socket.
 688  */
 689  
 690 static int inet_dup(struct socket *newsock, struct socket *oldsock)
     /* [previous][next][first][last][top][bottom][index][help] */
 691 {
 692         return(inet_create(newsock,((struct sock *)(oldsock->data))->protocol));
 693 }
 694 
 695 
 696 /*
 697  *      The peer socket should always be NULL (or else). When we call this
 698  *      function we are destroying the object and from then on nobody
 699  *      should refer to it.
 700  */
 701  
 702 static int inet_release(struct socket *sock, struct socket *peer)
     /* [previous][next][first][last][top][bottom][index][help] */
 703 {
 704         struct sock *sk = (struct sock *) sock->data;
 705         if (sk == NULL) 
 706                 return(0);
 707 
 708         sk->state_change(sk);
 709 
 710         /* Start closing the connection.  This may take a while. */
 711 
 712         /*
 713          * If linger is set, we don't return until the close
 714          * is complete.  Other wise we return immediately. The
 715          * actually closing is done the same either way.
 716          */
 717 
 718         if (sk->linger == 0) 
 719         {
 720                 sk->prot->close(sk,0);
 721                 sk->dead = 1;
 722         } 
 723         else 
 724         {
 725                 sk->prot->close(sk, 0);
 726                 cli();
 727                 if (sk->lingertime)
 728                         current->timeout = jiffies + HZ*sk->lingertime;
 729                 while(sk->state != TCP_CLOSE && current->timeout>0) 
 730                 {
 731                         interruptible_sleep_on(sk->sleep);
 732                         if (current->signal & ~current->blocked) 
 733                         {
 734                                 break;
 735 #if 0
 736                                 /* not working now - closes can't be restarted */
 737                                 sti();
 738                                 current->timeout=0;
 739                                 return(-ERESTARTSYS);
 740 #endif
 741                         }
 742                 }
 743                 current->timeout=0;
 744                 sti();
 745                 sk->dead = 1;
 746         }
 747         sk->inuse = 1;
 748 
 749         /* This will destroy it. */
 750         release_sock(sk);
 751         sock->data = NULL;
 752         sk->socket = NULL;
 753         return(0);
 754 }
 755 
 756 
 757 /* this needs to be changed to disallow
 758    the rebinding of sockets.   What error
 759    should it return? */
 760 
 761 static int inet_bind(struct socket *sock, struct sockaddr *uaddr,
     /* [previous][next][first][last][top][bottom][index][help] */
 762                int addr_len)
 763 {
 764         struct sockaddr_in *addr=(struct sockaddr_in *)uaddr;
 765         struct sock *sk=(struct sock *)sock->data, *sk2;
 766         unsigned short snum;
 767         int chk_addr_ret;
 768 
 769         /* check this error. */
 770         if (sk->state != TCP_CLOSE)
 771                 return(-EIO);
 772         if (sk->num != 0) 
 773                 return(-EINVAL);
 774 
 775         if(addr_len<sizeof(struct sockaddr_in))
 776                 return -EINVAL;
 777 
 778         snum = ntohs(addr->sin_port);
 779 
 780         /*
 781          * We can't just leave the socket bound wherever it is, it might
 782          * be bound to a privileged port. However, since there seems to
 783          * be a bug here, we will leave it if the port is not privileged.
 784          */
 785         if (snum == 0) 
 786         {
 787                 snum = get_new_socknum(sk->prot, 0);
 788         }
 789         if (snum < PROT_SOCK && !suser()) 
 790                 return(-EACCES);
 791 
 792         chk_addr_ret = ip_chk_addr(addr->sin_addr.s_addr);
 793         if (addr->sin_addr.s_addr != 0 && chk_addr_ret != IS_MYADDR)
 794                 return(-EADDRNOTAVAIL); /* Source address MUST be ours! */
 795         
 796         if (chk_addr_ret || addr->sin_addr.s_addr == 0)
 797                 sk->saddr = addr->sin_addr.s_addr;
 798 
 799         /* Make sure we are allowed to bind here. */
 800         cli();
 801 outside_loop:
 802         for(sk2 = sk->prot->sock_array[snum & (SOCK_ARRAY_SIZE -1)];
 803                                         sk2 != NULL; sk2 = sk2->next) 
 804         {
 805 /* should be below! */
 806                 if (sk2->num != snum) continue;
 807                 if (sk2->dead) 
 808                 {
 809                         destroy_sock(sk2);
 810                         goto outside_loop;
 811                 }
 812                 if (!sk->reuse) 
 813                 {
 814                         sti();
 815                         return(-EADDRINUSE);
 816                 }
 817                 
 818                 if (sk2->num != snum) 
 819                         continue;               /* more than one */
 820                 if (sk2->saddr != sk->saddr) 
 821                         continue;       /* socket per slot ! -FB */
 822                 if (!sk2->reuse) 
 823                 {
 824                         sti();
 825                         return(-EADDRINUSE);
 826                 }
 827         }
 828         sti();
 829 
 830         remove_sock(sk);
 831         put_sock(snum, sk);
 832         sk->dummy_th.source = ntohs(sk->num);
 833         sk->daddr = 0;
 834         sk->dummy_th.dest = 0;
 835         return(0);
 836 }
 837 
 838 /*
 839  *      Handle sk->err properly. The cli/sti matter.
 840  */
 841  
 842 static int inet_error(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 843 {
 844         unsigned long flags;
 845         int err;
 846         save_flags(flags);
 847         cli();  
 848         err=sk->err;
 849         sk->err=0;
 850         sti();
 851         return -err;
 852 }
 853 
 854 /*
 855  *      Connect to a remote host. There is regrettably still a little
 856  *      TCP 'magic' in here.
 857  */
 858  
 859 static int inet_connect(struct socket *sock, struct sockaddr * uaddr,
     /* [previous][next][first][last][top][bottom][index][help] */
 860                   int addr_len, int flags)
 861 {
 862         struct sock *sk=(struct sock *)sock->data;
 863         int err;
 864         sock->conn = NULL;
 865 
 866         if (sock->state == SS_CONNECTING && tcp_connected(sk->state))
 867         {
 868                 sock->state = SS_CONNECTED;
 869                 /* Connection completing after a connect/EINPROGRESS/select/connect */
 870                 return 0;       /* Rock and roll */
 871         }
 872 
 873         if (sock->state == SS_CONNECTING && sk->protocol == IPPROTO_TCP && (flags & O_NONBLOCK))
 874                 return -EALREADY;       /* Connecting is currently in progress */
 875         
 876         if (sock->state != SS_CONNECTING) 
 877         {
 878                 /* We may need to bind the socket. */
 879                 if(inet_autobind(sk)!=0)
 880                         return(-EAGAIN);
 881                 if (sk->prot->connect == NULL) 
 882                         return(-EOPNOTSUPP);
 883                 err = sk->prot->connect(sk, (struct sockaddr_in *)uaddr, addr_len);
 884                 if (err < 0) 
 885                         return(err);
 886                 sock->state = SS_CONNECTING;
 887         }
 888         
 889         if (sk->state > TCP_FIN_WAIT2 && sock->state==SS_CONNECTING)
 890         {
 891                 sock->state=SS_UNCONNECTED;
 892                 cli();
 893                 err=sk->err;
 894                 sk->err=0;
 895                 sti();
 896                 return -err;
 897         }
 898 
 899         if (sk->state != TCP_ESTABLISHED &&(flags & O_NONBLOCK)) 
 900                 return(-EINPROGRESS);
 901 
 902         cli(); /* avoid the race condition */
 903         while(sk->state == TCP_SYN_SENT || sk->state == TCP_SYN_RECV) 
 904         {
 905                 interruptible_sleep_on(sk->sleep);
 906                 if (current->signal & ~current->blocked) 
 907                 {
 908                         sti();
 909                         return(-ERESTARTSYS);
 910                 }
 911                 /* This fixes a nasty in the tcp/ip code. There is a hideous hassle with
 912                    icmp error packets wanting to close a tcp or udp socket. */
 913                 if(sk->err && sk->protocol == IPPROTO_TCP)
 914                 {
 915                         sti();
 916                         sock->state = SS_UNCONNECTED;
 917                         err = -sk->err;
 918                         sk->err=0;
 919                         return err; /* set by tcp_err() */
 920                 }
 921         }
 922         sti();
 923         sock->state = SS_CONNECTED;
 924 
 925         if (sk->state != TCP_ESTABLISHED && sk->err) 
 926         {
 927                 sock->state = SS_UNCONNECTED;
 928                 err=sk->err;
 929                 sk->err=0;
 930                 return(-err);
 931         }
 932         return(0);
 933 }
 934 
 935 
 936 static int inet_socketpair(struct socket *sock1, struct socket *sock2)
     /* [previous][next][first][last][top][bottom][index][help] */
 937 {
 938          return(-EOPNOTSUPP);
 939 }
 940 
 941 
 942 /*
 943  *      FIXME: Get BSD behaviour
 944  */
 945 
 946 static int inet_accept(struct socket *sock, struct socket *newsock, int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 947 {
 948         struct sock *sk1, *sk2;
 949         int err;
 950 
 951         sk1 = (struct sock *) sock->data;
 952 
 953         /*
 954          * We've been passed an extra socket.
 955          * We need to free it up because the tcp module creates
 956          * it's own when it accepts one.
 957          */
 958         if (newsock->data)
 959         {
 960                 struct sock *sk=(struct sock *)newsock->data;
 961                 newsock->data=NULL;
 962                 sk->dead = 1;
 963                 destroy_sock(sk);
 964         }
 965   
 966         if (sk1->prot->accept == NULL) 
 967                 return(-EOPNOTSUPP);
 968 
 969         /* Restore the state if we have been interrupted, and then returned. */
 970         if (sk1->pair != NULL ) 
 971         {
 972                 sk2 = sk1->pair;
 973                 sk1->pair = NULL;
 974         } 
 975         else
 976         {
 977                 sk2 = sk1->prot->accept(sk1,flags);
 978                 if (sk2 == NULL) 
 979                 {
 980                         if (sk1->err <= 0)
 981                                 printk("Warning sock.c:sk1->err <= 0.  Returning non-error.\n");
 982                         err=sk1->err;
 983                         sk1->err=0;
 984                         return(-err);
 985                 }
 986         }
 987         newsock->data = (void *)sk2;
 988         sk2->sleep = newsock->wait;
 989         sk2->socket = newsock;
 990         newsock->conn = NULL;
 991         if (flags & O_NONBLOCK) 
 992                 return(0);
 993 
 994         cli(); /* avoid the race. */
 995         while(sk2->state == TCP_SYN_RECV) 
 996         {
 997                 interruptible_sleep_on(sk2->sleep);
 998                 if (current->signal & ~current->blocked) 
 999                 {
1000                         sti();
1001                         sk1->pair = sk2;
1002                         sk2->sleep = NULL;
1003                         sk2->socket=NULL;
1004                         newsock->data = NULL;
1005                         return(-ERESTARTSYS);
1006                 }
1007         }
1008         sti();
1009 
1010         if (sk2->state != TCP_ESTABLISHED && sk2->err > 0) 
1011         {
1012                 err = -sk2->err;
1013                 sk2->err=0;
1014                 sk2->dead=1;    /* ANK */
1015                 destroy_sock(sk2);
1016                 newsock->data = NULL;
1017                 return(err);
1018         }
1019         newsock->state = SS_CONNECTED;
1020         return(0);
1021 }
1022 
1023 
1024 /*
1025  *      This does both peername and sockname.
1026  */
1027  
1028 static int inet_getname(struct socket *sock, struct sockaddr *uaddr,
     /* [previous][next][first][last][top][bottom][index][help] */
1029                  int *uaddr_len, int peer)
1030 {
1031         struct sockaddr_in *sin=(struct sockaddr_in *)uaddr;
1032         struct sock *sk;
1033   
1034         sin->sin_family = AF_INET;
1035         sk = (struct sock *) sock->data;
1036         if (peer) 
1037         {
1038                 if (!tcp_connected(sk->state)) 
1039                         return(-ENOTCONN);
1040                 sin->sin_port = sk->dummy_th.dest;
1041                 sin->sin_addr.s_addr = sk->daddr;
1042         } 
1043         else 
1044         {
1045                 sin->sin_port = sk->dummy_th.source;
1046                 if (sk->saddr == 0) 
1047                         sin->sin_addr.s_addr = ip_my_addr();
1048                 else 
1049                         sin->sin_addr.s_addr = sk->saddr;
1050         }
1051         *uaddr_len = sizeof(*sin);
1052         return(0);
1053 }
1054 
1055 
1056 /*
1057  *      The assorted BSD I/O operations
1058  */
1059 
1060 static int inet_recvfrom(struct socket *sock, void *ubuf, int size, int noblock, 
     /* [previous][next][first][last][top][bottom][index][help] */
1061                    unsigned flags, struct sockaddr *sin, int *addr_len )
1062 {
1063         struct sock *sk = (struct sock *) sock->data;
1064         
1065         if (sk->prot->recvfrom == NULL) 
1066                 return(-EOPNOTSUPP);
1067         if(sk->err)
1068                 return inet_error(sk);
1069         /* We may need to bind the socket. */
1070         if(inet_autobind(sk)!=0)
1071                 return(-EAGAIN);
1072         return(sk->prot->recvfrom(sk, (unsigned char *) ubuf, size, noblock, flags,
1073                              (struct sockaddr_in*)sin, addr_len));
1074 }
1075 
1076 
1077 static int inet_recv(struct socket *sock, void *ubuf, int size, int noblock,
     /* [previous][next][first][last][top][bottom][index][help] */
1078           unsigned flags)
1079 {
1080         /* BSD explicitly states these are the same - so we do it this way to be sure */
1081         return inet_recvfrom(sock,ubuf,size,noblock,flags,NULL,NULL);
1082 }
1083 
1084 static int inet_read(struct socket *sock, char *ubuf, int size, int noblock)
     /* [previous][next][first][last][top][bottom][index][help] */
1085 {
1086         struct sock *sk = (struct sock *) sock->data;
1087         
1088         if(sk->err)
1089                 return inet_error(sk);
1090         /* We may need to bind the socket. */
1091         if(inet_autobind(sk))
1092                 return(-EAGAIN);        
1093         return(sk->prot->read(sk, (unsigned char *) ubuf, size, noblock, 0));
1094 }
1095 
1096 static int inet_send(struct socket *sock, void *ubuf, int size, int noblock, 
     /* [previous][next][first][last][top][bottom][index][help] */
1097                unsigned flags)
1098 {
1099         struct sock *sk = (struct sock *) sock->data;
1100         if (sk->shutdown & SEND_SHUTDOWN) 
1101         {
1102                 send_sig(SIGPIPE, current, 1);
1103                 return(-EPIPE);
1104         }
1105         if(sk->err)
1106                 return inet_error(sk);
1107         /* We may need to bind the socket. */
1108         if(inet_autobind(sk)!=0)
1109                 return(-EAGAIN);
1110         return(sk->prot->write(sk, (unsigned char *) ubuf, size, noblock, flags));
1111 }
1112 
1113 static int inet_write(struct socket *sock, char *ubuf, int size, int noblock)
     /* [previous][next][first][last][top][bottom][index][help] */
1114 {
1115         return inet_send(sock,ubuf,size,noblock,0);
1116 }
1117 
1118 static int inet_sendto(struct socket *sock, void *ubuf, int size, int noblock, 
     /* [previous][next][first][last][top][bottom][index][help] */
1119             unsigned flags, struct sockaddr *sin, int addr_len)
1120 {
1121         struct sock *sk = (struct sock *) sock->data;
1122         if (sk->shutdown & SEND_SHUTDOWN) 
1123         {
1124                 send_sig(SIGPIPE, current, 1);
1125                 return(-EPIPE);
1126         }
1127         if (sk->prot->sendto == NULL) 
1128                 return(-EOPNOTSUPP);
1129         if(sk->err)
1130                 return inet_error(sk);
1131         /* We may need to bind the socket. */
1132         if(inet_autobind(sk)!=0)
1133                 return -EAGAIN;
1134         return(sk->prot->sendto(sk, (unsigned char *) ubuf, size, noblock, flags, 
1135                            (struct sockaddr_in *)sin, addr_len));
1136 }
1137 
1138 
1139 static int inet_shutdown(struct socket *sock, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
1140 {
1141         struct sock *sk=(struct sock*)sock->data;
1142 
1143         /*
1144          * This should really check to make sure
1145          * the socket is a TCP socket. (WHY AC...)
1146          */
1147         how++; /* maps 0->1 has the advantage of making bit 1 rcvs and
1148                        1->2 bit 2 snds.
1149                        2->3 */
1150         if ((how & ~SHUTDOWN_MASK) || how==0)   /* MAXINT->0 */
1151                 return(-EINVAL);
1152         if (sock->state == SS_CONNECTING && sk->state == TCP_ESTABLISHED)
1153                 sock->state = SS_CONNECTED;
1154         if (!tcp_connected(sk->state)) 
1155                 return(-ENOTCONN);
1156         sk->shutdown |= how;
1157         if (sk->prot->shutdown)
1158                 sk->prot->shutdown(sk, how);
1159         return(0);
1160 }
1161 
1162 
1163 static int inet_select(struct socket *sock, int sel_type, select_table *wait )
     /* [previous][next][first][last][top][bottom][index][help] */
1164 {
1165         struct sock *sk=(struct sock *) sock->data;
1166         if (sk->prot->select == NULL) 
1167         {
1168                 return(0);
1169         }
1170         return(sk->prot->select(sk, sel_type, wait));
1171 }
1172 
1173 /*
1174  *      ioctl() calls you can issue on an INET socket. Most of these are
1175  *      device configuration and stuff and very rarely used. Some ioctls
1176  *      pass on to the socket itself.
1177  *
1178  *      NOTE: I like the idea of a module for the config stuff. ie ifconfig
1179  *      loads the devconfigure module does its configuring and unloads it.
1180  *      There's a good 20K of config code hanging around the kernel.
1181  */
1182 
1183 static int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1184 {
1185         struct sock *sk=(struct sock *)sock->data;
1186         int err;
1187 
1188         switch(cmd) 
1189         {
1190                 case FIOSETOWN:
1191                 case SIOCSPGRP:
1192                         err=verify_area(VERIFY_READ,(int *)arg,sizeof(long));
1193                         if(err)
1194                                 return err;
1195                         sk->proc = get_fs_long((int *) arg);
1196                         return(0);
1197                 case FIOGETOWN:
1198                 case SIOCGPGRP:
1199                         err=verify_area(VERIFY_WRITE,(void *) arg, sizeof(long));
1200                         if(err)
1201                                 return err;
1202                         put_fs_long(sk->proc,(int *)arg);
1203                         return(0);                      
1204                 case SIOCGSTAMP:
1205                         if(sk->stamp.tv_sec==0)
1206                                 return -ENOENT;
1207                         err=verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval));
1208                         if(err)
1209                                 return err;
1210                         memcpy_tofs((void *)arg,&sk->stamp,sizeof(struct timeval));
1211                         return 0;
1212                 case SIOCADDRT: case SIOCADDRTOLD:
1213                 case SIOCDELRT: case SIOCDELRTOLD:
1214                         return(ip_rt_ioctl(cmd,(void *) arg));
1215                 case SIOCDARP:
1216                 case SIOCGARP:
1217                 case SIOCSARP:
1218                         return(arp_ioctl(cmd,(void *) arg));
1219 #ifdef CONFIG_INET_RARP                 
1220                 case SIOCDRARP:
1221                 case SIOCGRARP:
1222                 case SIOCSRARP:
1223                         return(rarp_ioctl(cmd,(void *) arg));
1224 #endif
1225                 case SIOCGIFCONF:
1226                 case SIOCGIFFLAGS:
1227                 case SIOCSIFFLAGS:
1228                 case SIOCGIFADDR:
1229                 case SIOCSIFADDR:
1230                 case SIOCGIFDSTADDR:
1231                 case SIOCSIFDSTADDR:
1232                 case SIOCGIFBRDADDR:
1233                 case SIOCSIFBRDADDR:
1234                 case SIOCGIFNETMASK:
1235                 case SIOCSIFNETMASK:
1236                 case SIOCGIFMETRIC:
1237                 case SIOCSIFMETRIC:
1238                 case SIOCGIFMEM:
1239                 case SIOCSIFMEM:
1240                 case SIOCGIFMTU:
1241                 case SIOCSIFMTU:
1242                 case SIOCSIFLINK:
1243                 case SIOCGIFHWADDR:
1244                 case SIOCSIFHWADDR:
1245                 case OLD_SIOCGIFHWADDR:
1246                 case SIOCSIFMAP:
1247                 case SIOCGIFMAP:
1248                 case SIOCDEVPRIVATE:
1249                 case SIOCSIFSLAVE:
1250                 case SIOCGIFSLAVE:
1251                         return(dev_ioctl(cmd,(void *) arg));
1252 
1253                 default:
1254                         if (sk->prot->ioctl==NULL) 
1255                                 return(-EINVAL);
1256                         return(sk->prot->ioctl(sk, cmd, arg));
1257         }
1258         /*NOTREACHED*/
1259         return(0);
1260 }
1261 
1262 /*
1263  * This routine must find a socket given a TCP or UDP header.
1264  * Everything is assumed to be in net order.
1265  *
1266  * We give priority to more closely bound ports: if some socket
1267  * is bound to a particular foreign address, it will get the packet
1268  * rather than somebody listening to any address..
1269  */
1270 
1271 struct sock *get_sock(struct proto *prot, unsigned short num,
     /* [previous][next][first][last][top][bottom][index][help] */
1272                                 unsigned long raddr,
1273                                 unsigned short rnum, unsigned long laddr)
1274 {
1275         struct sock *s;
1276         struct sock *result = NULL;
1277         int badness = -1;
1278         unsigned short hnum;
1279 
1280         hnum = ntohs(num);
1281 
1282         /*
1283          * SOCK_ARRAY_SIZE must be a power of two.  This will work better
1284          * than a prime unless 3 or more sockets end up using the same
1285          * array entry.  This should not be a problem because most
1286          * well known sockets don't overlap that much, and for
1287          * the other ones, we can just be careful about picking our
1288          * socket number when we choose an arbitrary one.
1289          */
1290 
1291         for(s = prot->sock_array[hnum & (SOCK_ARRAY_SIZE - 1)];
1292                         s != NULL; s = s->next) 
1293         {
1294                 int score = 0;
1295 
1296                 if (s->num != hnum) 
1297                         continue;
1298 
1299                 if(s->dead && (s->state == TCP_CLOSE))
1300                         continue;
1301                 /* local address matches? */
1302                 if (s->saddr) {
1303                         if (s->saddr != laddr)
1304                                 continue;
1305                         score++;
1306                 }
1307                 /* remote address matches? */
1308                 if (s->daddr) {
1309                         if (s->daddr != raddr)
1310                                 continue;
1311                         score++;
1312                 }
1313                 /* remote port matches? */
1314                 if (s->dummy_th.dest) {
1315                         if (s->dummy_th.dest != rnum)
1316                                 continue;
1317                         score++;
1318                 }
1319                 /* perfect match? */
1320                 if (score == 3)
1321                         return s;
1322                 /* no, check if this is the best so far.. */
1323                 if (score <= badness)
1324                         continue;
1325                 result = s;
1326                 badness = score;
1327         }
1328         return result;
1329 }
1330 
1331 static struct proto_ops inet_proto_ops = {
1332         AF_INET,
1333 
1334         inet_create,
1335         inet_dup,
1336         inet_release,
1337         inet_bind,
1338         inet_connect,
1339         inet_socketpair,
1340         inet_accept,
1341         inet_getname, 
1342         inet_read,
1343         inet_write,
1344         inet_select,
1345         inet_ioctl,
1346         inet_listen,
1347         inet_send,
1348         inet_recv,
1349         inet_sendto,
1350         inet_recvfrom,
1351         inet_shutdown,
1352         inet_setsockopt,
1353         inet_getsockopt,
1354         inet_fcntl,
1355 };
1356 
1357 extern unsigned long seq_offset;
1358 
1359 /*
1360  *      Called by socket.c on kernel startup.  
1361  */
1362  
1363 void inet_proto_init(struct net_proto *pro)
     /* [previous][next][first][last][top][bottom][index][help] */
1364 {
1365         struct inet_protocol *p;
1366         int i;
1367 
1368 
1369         printk("Swansea University Computer Society TCP/IP for NET3.017\n");
1370 
1371         /*
1372          *      Tell SOCKET that we are alive... 
1373          */
1374    
1375         (void) sock_register(inet_proto_ops.family, &inet_proto_ops);
1376 
1377         seq_offset = CURRENT_TIME*250;
1378 
1379         /*
1380          *      Add all the protocols. 
1381          */
1382          
1383         for(i = 0; i < SOCK_ARRAY_SIZE; i++) 
1384         {
1385                 tcp_prot.sock_array[i] = NULL;
1386                 udp_prot.sock_array[i] = NULL;
1387                 raw_prot.sock_array[i] = NULL;
1388         }
1389 
1390         printk("IP Protocols: ");
1391         for(p = inet_protocol_base; p != NULL;) 
1392         {
1393                 struct inet_protocol *tmp = (struct inet_protocol *) p->next;
1394                 inet_add_protocol(p);
1395                 printk("%s%s",p->name,tmp?", ":"\n");
1396                 p = tmp;
1397         }
1398         /*
1399          *      Set the ARP module up
1400          */
1401         arp_init();
1402         /*
1403          *      Set the IP module up
1404          */
1405         ip_init();
1406 }
1407 

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