root/net/netrom/af_netrom.c

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

DEFINITIONS

This source file includes following definitions.
  1. nr_remove_socket
  2. nr_kill_by_device
  3. nr_device_event
  4. nr_insert_socket
  5. nr_find_listener
  6. nr_find_socket
  7. nr_find_peer
  8. nr_destroy_timer
  9. nr_destroy_socket
  10. nr_fcntl
  11. nr_setsockopt
  12. nr_getsockopt
  13. nr_listen
  14. def_callback1
  15. def_callback2
  16. nr_create
  17. nr_make_new
  18. nr_dup
  19. nr_release
  20. nr_bind
  21. nr_connect
  22. nr_socketpair
  23. nr_accept
  24. nr_getname
  25. nr_rx_frame
  26. nr_sendmsg
  27. nr_recvmsg
  28. nr_shutdown
  29. nr_select
  30. nr_ioctl
  31. nr_get_info
  32. nr_proto_init

   1 /*
   2  *      NET/ROM release 003
   3  *
   4  *      This is ALPHA test software. This code may break your machine, randomly fail to work with new 
   5  *      releases, misbehave and/or generally screw up. It might even work. 
   6  *
   7  *      This code REQUIRES 1.3.0 or higher/ NET3.029
   8  *
   9  *      This module:
  10  *              This module is free software; you can redistribute it and/or
  11  *              modify it under the terms of the GNU General Public License
  12  *              as published by the Free Software Foundation; either version
  13  *              2 of the License, or (at your option) any later version.
  14  *
  15  *      History
  16  *      NET/ROM 001     Jonathan(G4KLX) Cloned from the AX25 code.
  17  *      NET/ROM 002     Darryl(G7LED)   Fixes and address enhancement.
  18  *                      Jonathan(G4KLX) Complete bind re-think.
  19  *                      Alan(GW4PTS)    Trivial tweaks into new format.
  20  *      NET/ROM 003     Jonathan(G4KLX) Added G8BPQ extensions.
  21  *                                      Added NET/ROM routing ioctl.
  22  *                      Darryl(G7LED)   Fix autobinding (on connect).
  23  *                                      Fixed nr_release(), set TCP_CLOSE, wakeup app
  24  *                                      context, THEN make the sock dead.
  25  *                                      Circuit ID check before allocating it on
  26  *                                      a connection.
  27  *                      Alan(GW4PTS)    sendmsg/recvmsg only. Fixed connect clear bug
  28  *                                      inherited from AX.25
  29  */
  30   
  31 #include <linux/config.h>
  32 #ifdef CONFIG_NETROM
  33 #include <linux/errno.h>
  34 #include <linux/types.h>
  35 #include <linux/socket.h>
  36 #include <linux/in.h>
  37 #include <linux/kernel.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/stat.h>
  44 #include <net/ax25.h>
  45 #include <linux/inet.h>
  46 #include <linux/netdevice.h>
  47 #include <linux/if_arp.h>
  48 #include <linux/skbuff.h>
  49 #include <net/sock.h>
  50 #include <asm/segment.h>
  51 #include <asm/system.h>
  52 #include <linux/fcntl.h>
  53 #include <linux/termios.h>      /* For TIOCINQ/OUTQ */
  54 #include <linux/mm.h>
  55 #include <linux/interrupt.h>
  56 #include <linux/notifier.h>
  57 #include <net/netrom.h>
  58 #include <linux/proc_fs.h>
  59 #include <net/ip.h>
  60 #include <net/arp.h>
  61 #include <linux/if_arp.h>
  62 
  63 /************************************************************************\
  64 *                                                                       *
  65 *                       Handlers for the socket list                    *
  66 *                                                                       *
  67 \************************************************************************/
  68 
  69 struct nr_parms_struct nr_default;
  70 
  71 static unsigned short circuit = 0x101;
  72 
  73 static struct sock *volatile nr_list = NULL;
  74 
  75 /*
  76  *      Socket removal during an interrupt is now safe.
  77  */
  78 static void nr_remove_socket(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         struct sock *s;
  81         unsigned long flags;
  82         
  83         save_flags(flags);
  84         cli();
  85 
  86         if ((s = nr_list) == sk) {
  87                 nr_list = s->next;
  88                 restore_flags(flags);
  89                 return;
  90         }
  91 
  92         while (s != NULL && s->next != NULL) {
  93                 if (s->next == sk) {
  94                         s->next = sk->next;
  95                         restore_flags(flags);
  96                         return;
  97                 }
  98 
  99                 s = s->next;
 100         }
 101 
 102         restore_flags(flags);
 103 }
 104 
 105 /*
 106  *      Kill all bound sockets on a dropped device.
 107  */
 108 static void nr_kill_by_device(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110         struct sock *s;
 111         
 112         for (s = nr_list; s != NULL; s = s->next) {
 113                 if (s->nr->device == dev) {
 114                         s->nr->state  = NR_STATE_0;
 115                         s->nr->device = NULL;
 116                         s->state = TCP_CLOSE;
 117                         s->err   = ENETUNREACH;
 118                         s->state_change(s);
 119                         s->dead  = 1;
 120                 }
 121         }
 122 }
 123 
 124 /*
 125  *      Handle device status changes.
 126  */
 127 static int nr_device_event(struct notifier_block *this, unsigned long event, void *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129         struct device *dev = (struct device *)ptr;
 130 
 131         if (event != NETDEV_DOWN)
 132                 return NOTIFY_DONE;
 133                 
 134         nr_kill_by_device(dev);
 135         nr_rt_device_down(dev);
 136         
 137         return NOTIFY_DONE;
 138 }
 139 
 140 /*
 141  *      Add a socket to the bound sockets list.
 142  */
 143 static void nr_insert_socket(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 144 {
 145         unsigned long flags;
 146 
 147         save_flags(flags);
 148         cli();
 149 
 150         sk->next = nr_list;
 151         nr_list  = sk;
 152 
 153         restore_flags(flags);
 154 }
 155 
 156 /*
 157  *      Find a socket that wants to accept the Connect Request we just
 158  *      received.
 159  */
 160 static struct sock *nr_find_listener(ax25_address *addr, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 161 {
 162         unsigned long flags;
 163         struct sock *s;
 164 
 165         save_flags(flags);
 166         cli();
 167 
 168         for (s = nr_list; s != NULL; s = s->next) {
 169                 if (ax25cmp(&s->nr->source_addr, addr) == 0 && s->type == type && s->state == TCP_LISTEN) {
 170                         restore_flags(flags);
 171                         return s;
 172                 }
 173         }
 174 
 175         restore_flags(flags);
 176         return NULL;
 177 }
 178 
 179 /*
 180  *      Find a connected NET/ROM socket given my circuit IDs.
 181  */
 182 static struct sock *nr_find_socket(unsigned char index, unsigned char id, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 183 {
 184         struct sock *s;
 185         unsigned long flags;
 186 
 187         save_flags(flags);
 188         cli();
 189 
 190         for (s = nr_list; s != NULL; s = s->next) {
 191                 if (s->nr->my_index == index && s->nr->my_id == id && s->type == type) {
 192                         restore_flags(flags);
 193                         return s;
 194                 }
 195         }
 196 
 197         restore_flags(flags);
 198 
 199         return NULL;
 200 }
 201 
 202 /*
 203  *      Find a connected NET/ROM socket given their circuit IDs.
 204  */
 205 static struct sock *nr_find_peer(unsigned char index, unsigned char id, int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 {
 207         struct sock *s;
 208         unsigned long flags;
 209 
 210         save_flags(flags);
 211         cli();
 212 
 213         for (s = nr_list; s != NULL; s = s->next) {
 214                 if (s->nr->your_index == index && s->nr->your_id == id && s->type == type) {
 215                         restore_flags(flags);
 216                         return s;
 217                 }
 218         }
 219 
 220         restore_flags(flags);
 221 
 222         return NULL;
 223 }
 224 
 225 /*
 226  *      Deferred destroy.
 227  */
 228 void nr_destory_socket(struct sock *);
 229 
 230 /*
 231  *      Handler for deferred kills.
 232  */
 233 static void nr_destroy_timer(unsigned long data)
     /* [previous][next][first][last][top][bottom][index][help] */
 234 {
 235         nr_destroy_socket((struct sock *)data);
 236 }
 237 
 238 /*
 239  *      This is called from user mode and the timers. Thus it protects itself against
 240  *      interrupt users but doesn't worry about being called during work.
 241  *      Once it is removed from the queue no interrupt or bottom half will
 242  *      touch it and we are (fairly 8-) ) safe.
 243  */
 244 void nr_destroy_socket(struct sock *sk) /* Not static as its used by the timer */
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         struct sk_buff *skb;
 247         unsigned long flags;
 248         
 249         save_flags(flags);
 250         cli();
 251         
 252         del_timer(&sk->timer);
 253         
 254         nr_remove_socket(sk);
 255         nr_clear_queues(sk);            /* Flush the queues */
 256         
 257         while ((skb = skb_dequeue(&sk->receive_queue)) != NULL) {
 258                 if (skb->sk != sk) {                    /* A pending connection */
 259                         skb->sk->dead = 1;      /* Queue the unaccepted socket for death */
 260                         nr_set_timer(skb->sk);
 261                         skb->sk->nr->state = NR_STATE_0;
 262                 }
 263 
 264                 kfree_skb(skb, FREE_READ);
 265         }
 266         
 267         if (sk->wmem_alloc || sk->rmem_alloc) { /* Defer: outstanding buffers */
 268                 init_timer(&sk->timer);
 269                 sk->timer.expires  = jiffies + 10 * HZ;
 270                 sk->timer.function = nr_destroy_timer;
 271                 sk->timer.data     = (unsigned long)sk;
 272                 add_timer(&sk->timer);
 273         } else {
 274                 kfree_s(sk->nr, sizeof(*sk->nr));
 275                 kfree_s(sk, sizeof(*sk));
 276         }
 277 
 278         restore_flags(flags);
 279 }
 280 
 281 /*******************************************************************************************************************\
 282 *                                                                                                                   *
 283 * Handling for system calls applied via the various interfaces to a NET/ROM socket object                           *
 284 *                                                                                                                   *
 285 \*******************************************************************************************************************/
 286  
 287 static int nr_fcntl(struct socket *sock, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 288 {
 289         switch(cmd)
 290         {
 291                 default:
 292                         return(-EINVAL);
 293         }
 294 }
 295 
 296 static int nr_setsockopt(struct socket *sock, int level, int optname,
     /* [previous][next][first][last][top][bottom][index][help] */
 297         char *optval, int optlen)
 298 {
 299         struct sock *sk;
 300         int err, opt;
 301 
 302         sk = (struct sock *)sock->data;
 303         
 304         if (level == SOL_SOCKET)
 305                 return sock_setsockopt(sk, level, optname, optval, optlen);
 306 
 307         if (level != SOL_NETROM)
 308                 return -EOPNOTSUPP;
 309 
 310         if (optval == NULL)
 311                 return -EINVAL;
 312 
 313         if ((err = verify_area(VERIFY_READ, optval, sizeof(int))) != 0)
 314                 return err;
 315 
 316         opt = get_fs_long((unsigned long *)optval);
 317         
 318         switch (optname) {
 319                 case NETROM_T1:
 320                         if (opt < 1)
 321                                 return -EINVAL;
 322                         sk->nr->rtt = (opt * PR_SLOWHZ) / 2;
 323                         return 0;
 324 
 325                 case NETROM_T2:
 326                         if (opt < 1)
 327                                 return -EINVAL;
 328                         sk->nr->t2 = opt * PR_SLOWHZ;
 329                         return 0;
 330                         
 331                 case NETROM_N2:
 332                         if (opt < 1 || opt > 31)
 333                                 return -EINVAL;
 334                         sk->nr->n2 = opt;
 335                         return 0;
 336                         
 337                 case NETROM_HDRINCL:
 338                         sk->nr->hdrincl = opt ? 1 : 0;
 339                         return 0;
 340                         
 341                 default:
 342                         return -ENOPROTOOPT;
 343         }
 344 }
 345 
 346 static int nr_getsockopt(struct socket *sock, int level, int optname,
     /* [previous][next][first][last][top][bottom][index][help] */
 347         char *optval, int *optlen)
 348 {
 349         struct sock *sk;
 350         int val = 0;
 351         int err; 
 352 
 353         sk = (struct sock *)sock->data;
 354         
 355         if (level == SOL_SOCKET)
 356                 return sock_getsockopt(sk, level, optname, optval, optlen);
 357         
 358         if (level != SOL_NETROM)
 359                 return -EOPNOTSUPP;
 360         
 361         switch (optname) {
 362                 case NETROM_T1:
 363                         val = (sk->nr->t1 * 2) / PR_SLOWHZ;
 364                         break;
 365                         
 366                 case NETROM_T2:
 367                         val = sk->nr->t2 / PR_SLOWHZ;
 368                         break;
 369                         
 370                 case NETROM_N2:
 371                         val = sk->nr->n2;
 372                         break;
 373                                                 
 374                 case NETROM_HDRINCL:
 375                         val = sk->nr->hdrincl;
 376                         break;
 377 
 378                 default:
 379                         return -ENOPROTOOPT;
 380         }
 381 
 382         if ((err = verify_area(VERIFY_WRITE, optlen, sizeof(int))) != 0)
 383                 return err;
 384 
 385         put_fs_long(sizeof(int), (unsigned long *)optlen);
 386 
 387         if ((err = verify_area(VERIFY_WRITE, optval, sizeof(int))) != 0)
 388                 return err;
 389 
 390         put_fs_long(val, (unsigned long *)optval);
 391 
 392         return 0;
 393 }
 394 
 395 static int nr_listen(struct socket *sock, int backlog)
     /* [previous][next][first][last][top][bottom][index][help] */
 396 {
 397         struct sock *sk = (struct sock *)sock->data;
 398 
 399         if (sk->type == SOCK_SEQPACKET && sk->state != TCP_LISTEN) {
 400                 memset(&sk->nr->user_addr, '\0', sizeof(ax25_address));
 401                 sk->max_ack_backlog = backlog;
 402                 sk->state           = TCP_LISTEN;
 403                 return 0;
 404         }
 405 
 406         return -EOPNOTSUPP;
 407 }
 408 
 409 static void def_callback1(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
 410 {
 411         if (!sk->dead)
 412                 wake_up_interruptible(sk->sleep);
 413 }
 414 
 415 static void def_callback2(struct sock *sk, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 416 {
 417         if (!sk->dead)
 418                 wake_up_interruptible(sk->sleep);
 419 }
 420 
 421 static int nr_create(struct socket *sock, int protocol)
     /* [previous][next][first][last][top][bottom][index][help] */
 422 {
 423         struct sock *sk;
 424         nr_cb *nr;
 425 
 426         if (sock->type != SOCK_SEQPACKET || protocol != 0)
 427                 return -ESOCKTNOSUPPORT;
 428 
 429         if ((sk = (struct sock *)kmalloc(sizeof(*sk), GFP_ATOMIC)) == NULL)
 430                 return -ENOMEM;
 431 
 432         if ((nr = (nr_cb *)kmalloc(sizeof(*nr), GFP_ATOMIC)) == NULL) {
 433                 kfree_s(sk, sizeof(*sk));
 434                 return -ENOMEM;
 435         }
 436 
 437         skb_queue_head_init(&sk->receive_queue);
 438         skb_queue_head_init(&sk->write_queue);
 439         skb_queue_head_init(&sk->back_log);
 440 
 441         init_timer(&sk->timer);
 442 
 443         sk->socket        = sock;
 444         sk->type          = sock->type;
 445         sk->protocol      = protocol;
 446         sk->dead          = 0;
 447         sk->next          = NULL;
 448         sk->broadcast     = 0;
 449         sk->allocation    = GFP_KERNEL;
 450         sk->rcvbuf        = SK_RMEM_MAX;
 451         sk->sndbuf        = SK_WMEM_MAX;
 452         sk->wmem_alloc    = 0;
 453         sk->rmem_alloc    = 0;
 454         sk->inuse         = 0;
 455         sk->debug         = 0;
 456         sk->destroy       = 0;
 457         sk->prot          = NULL;       /* So we use default free mechanisms */
 458         sk->err           = 0;
 459         sk->localroute    = 0;
 460         sk->send_head     = NULL;
 461         sk->state         = TCP_CLOSE;
 462         sk->shutdown      = 0;
 463         sk->priority      = SOPRI_NORMAL;
 464         sk->ack_backlog   = 0;
 465         sk->mtu           = NETROM_MTU; /* 236 */
 466         sk->zapped        = 1;
 467         sk->window        = nr_default.window;
 468 
 469         sk->state_change = def_callback1;
 470         sk->data_ready   = def_callback2;
 471         sk->write_space  = def_callback1;
 472         sk->error_report = def_callback1;
 473 
 474         if (sock != NULL) {
 475                 sock->data = (void *)sk;
 476                 sk->sleep  = sock->wait;
 477         }
 478 
 479         skb_queue_head_init(&nr->ack_queue);
 480         skb_queue_head_init(&nr->reseq_queue);
 481         skb_queue_head_init(&nr->frag_queue);
 482 
 483         nr->my_index = 0;
 484         nr->my_id    = 0;
 485         nr->rtt      = nr_default.timeout / 2;
 486         nr->t1       = nr_default.timeout;
 487         nr->t2       = nr_default.ack_delay;
 488         nr->n2       = nr_default.tries;
 489 
 490         nr->t1timer  = 0;
 491         nr->t2timer  = 0;
 492         nr->t4timer  = 0;
 493         nr->n2count  = 0;
 494 
 495         nr->va       = 0;
 496         nr->vr       = 0;
 497         nr->vs       = 0;
 498         nr->vl       = 0;
 499 
 500         nr->your_index = 0;
 501         nr->your_id    = 0;
 502 
 503         nr->my_index   = 0;
 504         nr->my_id      = 0;
 505 
 506         nr->bpqext     = 1;
 507         nr->fraglen    = 0;
 508         nr->hdrincl    = 0;
 509         nr->state      = NR_STATE_0;
 510         nr->device     = NULL;
 511 
 512         memset(&nr->source_addr, '\0', sizeof(ax25_address));
 513         memset(&nr->user_addr,   '\0', sizeof(ax25_address));
 514         memset(&nr->dest_addr,   '\0', sizeof(ax25_address));
 515 
 516         nr->sk = sk;
 517         sk->nr = nr;
 518 
 519         return 0;
 520 }
 521 
 522 static struct sock *nr_make_new(struct sock *osk)
     /* [previous][next][first][last][top][bottom][index][help] */
 523 {
 524         struct sock *sk;
 525         nr_cb *nr;
 526 
 527         if (osk->type != SOCK_SEQPACKET)
 528                 return NULL;
 529 
 530         if ((sk = (struct sock *)kmalloc(sizeof(*sk), GFP_ATOMIC)) == NULL)
 531                 return NULL;
 532 
 533         if ((nr = (nr_cb *)kmalloc(sizeof(*nr), GFP_ATOMIC)) == NULL) {
 534                 kfree_s(sk, sizeof(*sk));
 535                 return NULL;
 536         }
 537 
 538         skb_queue_head_init(&sk->receive_queue);
 539         skb_queue_head_init(&sk->write_queue);
 540         skb_queue_head_init(&sk->back_log);
 541 
 542         init_timer(&sk->timer);
 543 
 544         sk->type        = osk->type;
 545         sk->socket      = osk->socket;
 546         sk->dead        = 0;
 547         sk->next        = NULL;
 548         sk->priority    = osk->priority;
 549         sk->broadcast   = 0;
 550         sk->protocol    = osk->protocol;
 551         sk->rcvbuf      = osk->rcvbuf;
 552         sk->sndbuf      = osk->sndbuf;
 553         sk->wmem_alloc  = 0;
 554         sk->rmem_alloc  = 0;
 555         sk->inuse       = 0;
 556         sk->ack_backlog = 0;
 557         sk->destroy     = 0;
 558         sk->prot        = NULL; /* So we use default free mechanisms */
 559         sk->err         = 0;
 560         sk->localroute  = 0;
 561         sk->send_head   = NULL;
 562         sk->debug       = osk->debug;
 563         sk->state       = TCP_ESTABLISHED;
 564         sk->window      = osk->window;
 565         sk->shutdown    = 0;
 566         sk->mtu         = osk->mtu;
 567         sk->sleep       = osk->sleep;
 568         sk->zapped      = osk->zapped;
 569 
 570         sk->state_change = def_callback1;
 571         sk->data_ready   = def_callback2;
 572         sk->write_space  = def_callback1;
 573         sk->error_report = def_callback1;
 574 
 575         skb_queue_head_init(&nr->ack_queue);
 576         skb_queue_head_init(&nr->reseq_queue);
 577         skb_queue_head_init(&nr->frag_queue);
 578 
 579         nr->rtt      = osk->nr->rtt;
 580         nr->t1       = osk->nr->t1;
 581         nr->t2       = osk->nr->t2;
 582         nr->n2       = osk->nr->n2;
 583 
 584         nr->device   = osk->nr->device;
 585         nr->bpqext   = osk->nr->bpqext;
 586         nr->hdrincl  = osk->nr->hdrincl;
 587         nr->fraglen  = 0;
 588 
 589         nr->t1timer  = 0;
 590         nr->t2timer  = 0;
 591         nr->t4timer  = 0;
 592         nr->n2count  = 0;
 593 
 594         nr->va       = 0;
 595         nr->vr       = 0;
 596         nr->vs       = 0;
 597         nr->vl       = 0;
 598         
 599         sk->nr = nr;
 600         nr->sk = sk;
 601 
 602         return sk;
 603 }
 604 
 605 static int nr_dup(struct socket *newsock, struct socket *oldsock)
     /* [previous][next][first][last][top][bottom][index][help] */
 606 {
 607         struct sock *sk = (struct sock *)oldsock->data;
 608 
 609         return nr_create(newsock, sk->protocol);
 610 }
 611 
 612 static int nr_release(struct socket *sock, struct socket *peer)
     /* [previous][next][first][last][top][bottom][index][help] */
 613 {
 614         struct sock *sk = (struct sock *)sock->data;
 615 
 616         if (sk == NULL) return 0;
 617 
 618         if (sk->type == SOCK_SEQPACKET) {
 619                 switch (sk->nr->state) {
 620                         case NR_STATE_0:
 621                                 sk->state     = TCP_CLOSE;
 622                                 sk->state_change(sk);
 623                                 sk->dead      = 1;
 624                                 nr_destroy_socket(sk);
 625                                 break;
 626 
 627                         case NR_STATE_1:
 628                                 sk->nr->state = NR_STATE_0;
 629                                 sk->state     = TCP_CLOSE;
 630                                 sk->state_change(sk);
 631                                 sk->dead      = 1;
 632                                 nr_destroy_socket(sk);
 633                                 break;
 634 
 635                         case NR_STATE_2:
 636                                 nr_write_internal(sk, NR_DISCACK);
 637                                 sk->nr->state = NR_STATE_0;
 638                                 sk->state     = TCP_CLOSE;
 639                                 sk->state_change(sk);
 640                                 sk->dead      = 1;
 641                                 nr_destroy_socket(sk);
 642                                 break;                  
 643 
 644                         case NR_STATE_3:
 645                                 nr_clear_queues(sk);
 646                                 sk->nr->n2count = 0;
 647                                 nr_write_internal(sk, NR_DISCREQ);
 648                                 sk->nr->t1timer = sk->nr->t1 = nr_calculate_t1(sk);
 649                                 sk->nr->t2timer = 0;
 650                                 sk->nr->t4timer = 0;
 651                                 sk->nr->state   = NR_STATE_2;
 652                                 sk->state       = TCP_CLOSE;
 653                                 sk->state_change(sk);
 654                                 sk->dead        = 1;
 655                                 sk->destroy     = 1;
 656                                 break;
 657 
 658                         default:
 659                                 break;
 660                 }
 661         } else {
 662                 sk->state = TCP_CLOSE;
 663                 sk->state_change(sk);
 664                 sk->dead = 1;
 665                 nr_destroy_socket(sk);
 666         }
 667 
 668         sock->data = NULL;      
 669         sk->socket = NULL;      /* Not used, but we should do this. **/
 670 
 671         return 0;
 672 }
 673 
 674 static int nr_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 675 {
 676         struct sock *sk;
 677         struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
 678         struct device *dev;
 679         ax25_address *user, *source;
 680         
 681         sk = (struct sock *)sock->data;
 682 
 683         if (sk->zapped == 0)
 684                 return -EIO;
 685                 
 686         if (addr_len != sizeof(struct sockaddr_ax25) && addr_len != sizeof(struct full_sockaddr_ax25))
 687                 return -EINVAL;
 688 
 689 #ifdef DONTDO
 690         if (nr_find_listener(&addr->fsa_ax25.sax25_call, sk->type) != NULL) {
 691                 if (sk->debug)
 692                         printk("NET/ROM: bind failed: in use\n");
 693                 return -EADDRINUSE;
 694         }
 695 #endif
 696 
 697         if ((dev = nr_dev_get(&addr->fsa_ax25.sax25_call)) == NULL) {
 698                 if (sk->debug)
 699                         printk("NET/ROM: bind failed: invalid node callsign\n");
 700                 return -EADDRNOTAVAIL;
 701         }
 702 
 703         /*
 704          * Only the super user can set an arbitrary user callsign.
 705          */
 706         if (addr->fsa_ax25.sax25_ndigis == 1) {
 707                 if (!suser())
 708                         return -EPERM;
 709                 memcpy(&sk->nr->user_addr,   &addr->fsa_digipeater[0],   sizeof(ax25_address));
 710                 memcpy(&sk->nr->source_addr, &addr->fsa_ax25.sax25_call, sizeof(ax25_address));
 711         } else {
 712                 source = &addr->fsa_ax25.sax25_call;
 713 
 714                 if ((user = ax25_findbyuid(current->euid)) == NULL) {
 715                         if (ax25_uid_policy && !suser())
 716                                 return -EPERM;
 717                         user = source;
 718                 }
 719 
 720                 memcpy(&sk->nr->user_addr,   user,   sizeof(ax25_address));
 721                 memcpy(&sk->nr->source_addr, source, sizeof(ax25_address));
 722         }
 723 
 724         sk->nr->device = dev;
 725         nr_insert_socket(sk);
 726 
 727         sk->zapped = 0;
 728 
 729         if (sk->debug)
 730                 printk("NET/ROM: socket is bound\n");
 731 
 732         return 0;
 733 }
 734 
 735 static int nr_connect(struct socket *sock, struct sockaddr *uaddr,
     /* [previous][next][first][last][top][bottom][index][help] */
 736         int addr_len, int flags)
 737 {
 738         struct sock *sk = (struct sock *)sock->data;
 739         struct sockaddr_ax25 *addr = (struct sockaddr_ax25 *)uaddr;
 740         ax25_address *user, *source = NULL;
 741         struct device *dev;
 742         
 743         if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
 744                 sock->state = SS_CONNECTED;
 745                 return 0;       /* Connect completed during a ERESTARTSYS event */
 746         }
 747         
 748         if (sk->state == TCP_CLOSE && sock->state == SS_CONNECTING) {
 749                 sock->state = SS_UNCONNECTED;
 750                 return -ECONNREFUSED;
 751         }
 752         
 753         if (sk->state == TCP_ESTABLISHED && sk->type == SOCK_SEQPACKET)
 754                 return -EISCONN;        /* No reconnect on a seqpacket socket */
 755                 
 756         sk->state   = TCP_CLOSE;        
 757         sock->state = SS_UNCONNECTED;
 758 
 759         if (addr_len != sizeof(struct sockaddr_ax25))
 760                 return -EINVAL;
 761 
 762         if ((dev = nr_dev_first()) == NULL)
 763                 return -ENETUNREACH;
 764                 
 765         if (sk->zapped) {       /* Must bind first - autobinding in this may or may not work */
 766                 sk->zapped = 0;
 767 
 768                 source = (ax25_address *)dev->dev_addr;
 769 
 770                 if ((user = ax25_findbyuid(current->euid)) == NULL) {
 771                         if (ax25_uid_policy && !suser())
 772                                 return -EPERM;
 773                         user = source;
 774                 }
 775 
 776                 memcpy(&sk->nr->user_addr,   user,   sizeof(ax25_address));
 777                 memcpy(&sk->nr->source_addr, source, sizeof(ax25_address));
 778 
 779                 sk->nr->device = dev;
 780 
 781                 nr_insert_socket(sk);           /* Finish the bind */
 782         }
 783 
 784         memcpy(&sk->nr->dest_addr, &addr->sax25_call, sizeof(ax25_address));
 785 
 786         while (nr_find_socket((unsigned char)circuit / 256, (unsigned char)circuit % 256, SOCK_SEQPACKET) != NULL)
 787                 circuit++;
 788 
 789         sk->nr->my_index = circuit / 256;
 790         sk->nr->my_id    = circuit % 256;
 791 
 792         circuit++;
 793         
 794         /* Move to connecting socket, start sending Connect Requests */
 795         sock->state   = SS_CONNECTING;
 796         sk->state     = TCP_SYN_SENT;
 797         nr_establish_data_link(sk);
 798         sk->nr->state = NR_STATE_1;
 799         nr_set_timer(sk);
 800         
 801         /* Now the loop */
 802         if (sk->state != TCP_ESTABLISHED && (flags & O_NONBLOCK))
 803                 return -EINPROGRESS;
 804                 
 805         cli();  /* To avoid races on the sleep */
 806 
 807         /*
 808          * A Connect Ack with Choke or timeout or failed routing will go to closed.
 809          */
 810         while (sk->state == TCP_SYN_SENT) {
 811                 interruptible_sleep_on(sk->sleep);
 812                 if (current->signal & ~current->blocked) {
 813                         sti();
 814                         return -ERESTARTSYS;
 815                 }
 816         }
 817 
 818         if (sk->state != TCP_ESTABLISHED) {
 819                 sti();
 820                 sock->state = SS_UNCONNECTED;
 821                 return sock_error(sk);  /* Always set at this point */
 822         }
 823         
 824         sock->state = SS_CONNECTED;
 825 
 826         sti();
 827         
 828         return 0;
 829 }
 830         
 831 static int nr_socketpair(struct socket *sock1, struct socket *sock2)
     /* [previous][next][first][last][top][bottom][index][help] */
 832 {
 833         return -EOPNOTSUPP;
 834 }
 835 
 836 static int nr_accept(struct socket *sock, struct socket *newsock, int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 837 {
 838         struct sock *sk;
 839         struct sock *newsk;
 840         struct sk_buff *skb;
 841 
 842         if (newsock->data)
 843                 kfree_s(newsock->data, sizeof(struct sock));
 844 
 845         newsock->data = NULL;
 846         
 847         sk = (struct sock *)sock->data;
 848 
 849         if (sk->type != SOCK_SEQPACKET)
 850                 return -EOPNOTSUPP;
 851         
 852         if (sk->state != TCP_LISTEN)
 853                 return -EINVAL;
 854                 
 855         /* The write queue this time is holding sockets ready to use
 856            hooked into the SABM we saved */
 857         do {
 858                 cli();
 859                 if ((skb = skb_dequeue(&sk->receive_queue)) == NULL) {
 860                         if (flags & O_NONBLOCK) {
 861                                 sti();
 862                                 return 0;
 863                         }
 864                         interruptible_sleep_on(sk->sleep);
 865                         if (current->signal & ~current->blocked) {
 866                                 sti();
 867                                 return -ERESTARTSYS;
 868                         }
 869                 }
 870         } while (skb == NULL);
 871 
 872         newsk = skb->sk;
 873         newsk->pair = NULL;
 874         sti();
 875 
 876         /* Now attach up the new socket */
 877         skb->sk = NULL;
 878         kfree_skb(skb, FREE_READ);
 879         sk->ack_backlog--;
 880         newsock->data = newsk;
 881 
 882         return 0;
 883 }
 884 
 885 static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
     /* [previous][next][first][last][top][bottom][index][help] */
 886         int *uaddr_len, int peer)
 887 {
 888         struct full_sockaddr_ax25 *sax = (struct full_sockaddr_ax25 *)uaddr;
 889         struct sock *sk;
 890         
 891         sk = (struct sock *)sock->data;
 892         
 893         if (peer != 0) {
 894                 if (sk->state != TCP_ESTABLISHED)
 895                         return -ENOTCONN;
 896                 sax->fsa_ax25.sax25_family = AF_NETROM;
 897                 sax->fsa_ax25.sax25_ndigis = 1;
 898                 memcpy(&sax->fsa_ax25.sax25_call, &sk->nr->user_addr, sizeof(ax25_address));
 899                 memcpy(&sax->fsa_digipeater[0],   &sk->nr->dest_addr, sizeof(ax25_address));
 900                 *uaddr_len = sizeof(struct sockaddr_ax25) + sizeof(ax25_address);
 901         } else {
 902                 sax->fsa_ax25.sax25_family = AF_NETROM;
 903                 sax->fsa_ax25.sax25_ndigis = 0;
 904                 memcpy(&sax->fsa_ax25.sax25_call, &sk->nr->source_addr, sizeof(ax25_address));
 905                 *uaddr_len = sizeof(struct sockaddr_ax25);
 906         }
 907 
 908         return 0;
 909 }
 910  
 911 int nr_rx_frame(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 912 {
 913         struct sock *sk;
 914         struct sock *make;      
 915         ax25_address *src, *dest, *user;
 916         unsigned short circuit_index, circuit_id;
 917         unsigned short frametype, window, timeout;
 918         
 919 
 920         skb->sk = NULL;         /* Initially we don't know who its for */
 921 
 922         /*
 923          *      skb->data points to the netrom frame start
 924          */
 925         
 926         src  = (ax25_address *)(skb->data + 0);
 927         dest = (ax25_address *)(skb->data + 7);
 928 
 929         circuit_index = skb->data[15];
 930         circuit_id    = skb->data[16];
 931         frametype     = skb->data[19];
 932 
 933 #ifdef CONFIG_INET
 934         /*
 935          * Check for an incoming IP over NET/ROM frame.
 936          */
 937          if ((frametype & 0x0F) == NR_PROTOEXT && circuit_index == NR_PROTO_IP && circuit_id == NR_PROTO_IP) {
 938                 skb_pull(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
 939                 skb->h.raw = skb->data;
 940 
 941                 return nr_rx_ip(skb, dev);
 942          }
 943 #endif
 944 
 945         /*
 946          * Find an existing socket connection, based on circuit ID, if its
 947          * a Connect Request base it on their circuit ID.
 948          */
 949         if (((frametype & 0x0F) != NR_CONNREQ && (sk = nr_find_socket(circuit_index, circuit_id, SOCK_SEQPACKET)) != NULL) ||
 950             ((frametype & 0x0F) == NR_CONNREQ && (sk = nr_find_peer(circuit_index, circuit_id, SOCK_SEQPACKET)) != NULL)) {
 951                 skb->h.raw = skb->data;
 952 
 953                 if ((frametype & 0x0F) == NR_CONNACK && skb->len == 22)
 954                         sk->nr->bpqext = 1;
 955                 else
 956                         sk->nr->bpqext = 0;
 957 
 958                 return nr_process_rx_frame(sk, skb);
 959         }
 960 
 961         if ((frametype & 0x0F) != NR_CONNREQ)
 962                 return 0;
 963                 
 964         sk = nr_find_listener(dest, SOCK_SEQPACKET);
 965 
 966         user   = (ax25_address *)(skb->data + 21);
 967 
 968         if (sk == NULL || sk->ack_backlog == sk->max_ack_backlog || (make = nr_make_new(sk)) == NULL) {
 969                 nr_transmit_dm(skb);
 970                 return 0;
 971         }
 972 
 973         window = skb->data[20];
 974 
 975         skb->sk             = make;
 976         make->state         = TCP_ESTABLISHED;
 977 
 978         /* Fill in his circuit details */
 979         memcpy(&make->nr->source_addr, dest, sizeof(ax25_address));
 980         memcpy(&make->nr->dest_addr,   src,  sizeof(ax25_address));
 981         memcpy(&make->nr->user_addr,   user, sizeof(ax25_address));
 982 
 983         make->nr->your_index = circuit_index;
 984         make->nr->your_id    = circuit_id;
 985 
 986         make->nr->my_index   = circuit / 256;
 987         make->nr->my_id      = circuit % 256;
 988         
 989         circuit++;
 990 
 991         /* Window negotiation */
 992         if (window < make->window)
 993                 make->window = window;
 994 
 995         /* L4 timeout negotiation */
 996         if (skb->len == 37) {
 997                 timeout = skb->data[36] * 256 + skb->data[35];
 998                 if (timeout * PR_SLOWHZ < make->nr->rtt * 2)
 999                         make->nr->rtt = (timeout * PR_SLOWHZ) / 2;
1000                 make->nr->bpqext = 1;
1001         } else {
1002                 make->nr->bpqext = 0;
1003         }
1004 
1005         nr_write_internal(make, NR_CONNACK);
1006 
1007         make->nr->condition = 0x00;
1008         make->nr->vs        = 0;
1009         make->nr->va        = 0;
1010         make->nr->vr        = 0;
1011         make->nr->vl        = 0;
1012         make->nr->state     = NR_STATE_3;
1013         sk->ack_backlog++;
1014         make->pair = sk;
1015 
1016         nr_insert_socket(make);
1017 
1018         skb_queue_head(&sk->receive_queue, skb);
1019 
1020         nr_set_timer(make);
1021 
1022         if (!sk->dead)
1023                 sk->data_ready(sk, skb->len);
1024 
1025         return 1;
1026 }
1027 
1028 static int nr_sendmsg(struct socket *sock, struct msghdr *msg, int len, int noblock, int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1029 {
1030         struct sock *sk = (struct sock *)sock->data;
1031         struct sockaddr_ax25 *usax = (struct sockaddr_ax25 *)msg->msg_name;
1032         int err;
1033         struct sockaddr_ax25 sax;
1034         struct sk_buff *skb;
1035         unsigned char *asmptr;
1036         int size;
1037         
1038         if (sk->err)
1039                 return sock_error(sk);
1040 
1041         if (flags)
1042                 return -EINVAL;
1043 
1044         if (sk->zapped)
1045                 return -EADDRNOTAVAIL;
1046 
1047         if (sk->nr->device == NULL)
1048                 return -ENETUNREACH;
1049                 
1050         if (usax) {
1051                 if (msg->msg_namelen < sizeof(sax))
1052                         return -EINVAL;
1053                 memcpy(&sax, usax, sizeof(sax));
1054                 if (sk->type == SOCK_SEQPACKET && memcmp(&sk->nr->dest_addr, &sax.sax25_call, sizeof(ax25_address)) != 0)
1055                         return -EISCONN;
1056                 if (sax.sax25_family != AF_NETROM)
1057                         return -EINVAL;
1058         } else {
1059                 if (sk->state != TCP_ESTABLISHED)
1060                         return -ENOTCONN;
1061                 sax.sax25_family = AF_NETROM;
1062                 memcpy(&sax.sax25_call, &sk->nr->dest_addr, sizeof(ax25_address));
1063         }
1064         
1065         if (sk->debug)
1066                 printk("NET/ROM: sendto: Addresses built.\n");
1067 
1068         /* Build a packet */
1069         if (sk->debug)
1070                 printk("NET/ROM: sendto: building packet.\n");
1071 
1072         size = len + AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + NR_NETWORK_LEN + NR_TRANSPORT_LEN;
1073 
1074         if ((skb = sock_alloc_send_skb(sk, size, 0, 0, &err)) == NULL)
1075                 return err;
1076 
1077         skb->sk   = sk;
1078         skb->free = 1;
1079         skb->arp  = 1;
1080 
1081         skb_reserve(skb, size - len);
1082         
1083         /*
1084          *      Push down the NET/ROM header
1085          */
1086 
1087         asmptr = skb_push(skb, NR_TRANSPORT_LEN);
1088 
1089         if (sk->debug)
1090                 printk("Building NET/ROM Header.\n");
1091 
1092         /* Build a NET/ROM Transport header */
1093 
1094         *asmptr++ = sk->nr->your_index;
1095         *asmptr++ = sk->nr->your_id;
1096         *asmptr++ = 0;          /* To be filled in later */
1097         *asmptr++ = 0;          /*      Ditto            */
1098         *asmptr++ = NR_INFO;
1099         
1100         if (sk->debug)
1101                 printk("Built header.\n");
1102 
1103         /*
1104          *      Put the data on the end
1105          */
1106 
1107         skb->h.raw = skb_put(skb, len);
1108 
1109         asmptr = skb->h.raw;
1110         
1111         if (sk->debug)
1112                 printk("NET/ROM: Appending user data\n");
1113 
1114         /* User data follows immediately after the NET/ROM transport header */
1115         memcpy_fromiovec(asmptr, msg->msg_iov, len);
1116 
1117         if (sk->debug)
1118                 printk("NET/ROM: Transmitting buffer\n");
1119 
1120         if (sk->state != TCP_ESTABLISHED) {
1121                 kfree_skb(skb, FREE_WRITE);
1122                 return -ENOTCONN;
1123         }
1124 
1125         nr_output(sk, skb);     /* Shove it onto the queue */
1126 
1127         return len;
1128 }
1129 
1130 
1131 static int nr_recvmsg(struct socket *sock, struct msghdr *msg, int size, int noblock,
     /* [previous][next][first][last][top][bottom][index][help] */
1132                    int flags, int *addr_len)
1133 {
1134         struct sock *sk = (struct sock *)sock->data;
1135         struct sockaddr_ax25 *sax = (struct sockaddr_ax25 *)msg->msg_name;
1136         int copied;
1137         struct sk_buff *skb;
1138         int er;
1139 
1140         if (sk->err)
1141                 return sock_error(sk);
1142         
1143         if (addr_len != NULL)
1144                 *addr_len = sizeof(*sax);
1145 
1146         /*
1147          * This works for seqpacket too. The receiver has ordered the queue for
1148          * us! We do one quick check first though
1149          */
1150         if (sk->type == SOCK_SEQPACKET && sk->state != TCP_ESTABLISHED)
1151                 return -ENOTCONN;
1152 
1153         /* Now we can treat all alike */
1154         if ((skb = skb_recv_datagram(sk, flags, noblock, &er)) == NULL)
1155                 return er;
1156 
1157         if (!sk->nr->hdrincl) {
1158                 skb_pull(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
1159                 skb->h.raw = skb->data;
1160         }
1161 
1162         copied = (size < skb->len) ? size : skb->len;
1163         skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
1164         
1165         if (sax != NULL) {
1166                 struct sockaddr_ax25 addr;
1167                 
1168                 addr.sax25_family = AF_NETROM;
1169                 memcpy(&addr.sax25_call, skb->data + 7, sizeof(ax25_address));
1170 
1171                 memcpy(sax, &addr, sizeof(*sax));
1172 
1173                 *addr_len = sizeof(*sax);
1174         }
1175 
1176         skb_free_datagram(skb);
1177 
1178         return copied;
1179 }               
1180 
1181 static int nr_shutdown(struct socket *sk, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
1182 {
1183         return -EOPNOTSUPP;
1184 }
1185 
1186 static int nr_select(struct socket *sock , int sel_type, select_table *wait)
     /* [previous][next][first][last][top][bottom][index][help] */
1187 {
1188         struct sock *sk = (struct sock *)sock->data;
1189 
1190         return datagram_select(sk, sel_type, wait);
1191 }
1192 
1193 static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1194 {
1195         struct sock *sk = (struct sock *)sock->data;
1196         int err;
1197         long amount = 0;
1198 
1199         switch (cmd) {
1200                 case TIOCOUTQ:
1201                         if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
1202                                 return err;
1203                         amount = sk->sndbuf - sk->wmem_alloc;
1204                         if (amount < 0)
1205                                 amount = 0;
1206                         put_fs_long(amount, (unsigned long *)arg);
1207                         return 0;
1208 
1209                 case TIOCINQ:
1210                 {
1211                         struct sk_buff *skb;
1212                         /* These two are safe on a single CPU system as only user tasks fiddle here */
1213                         if ((skb = skb_peek(&sk->receive_queue)) != NULL)
1214                                 amount = skb->len - 20;
1215                         if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(unsigned long))) != 0)
1216                                 return err;
1217                         put_fs_long(amount, (unsigned long *)arg);
1218                         return 0;
1219                 }
1220 
1221                 case SIOCGSTAMP:
1222                         if (sk != NULL) {
1223                                 if (sk->stamp.tv_sec==0)
1224                                         return -ENOENT;
1225                                 if ((err = verify_area(VERIFY_WRITE,(void *)arg,sizeof(struct timeval))) != 0)
1226                                         return err;
1227                                 memcpy_tofs((void *)arg, &sk->stamp, sizeof(struct timeval));
1228                                 return 0;
1229                         }
1230                         return -EINVAL;
1231 
1232                 case SIOCGIFADDR:
1233                 case SIOCSIFADDR:
1234                 case SIOCGIFDSTADDR:
1235                 case SIOCSIFDSTADDR:
1236                 case SIOCGIFBRDADDR:
1237                 case SIOCSIFBRDADDR:
1238                 case SIOCGIFNETMASK:
1239                 case SIOCSIFNETMASK:
1240                 case SIOCGIFMETRIC:
1241                 case SIOCSIFMETRIC:
1242                         return -EINVAL;
1243 
1244                 case SIOCADDRT:
1245                 case SIOCDELRT:
1246                 case SIOCNRDECOBS:
1247                 case SIOCNRRTCTL:
1248                         if (!suser()) return -EPERM;
1249                         return nr_rt_ioctl(cmd, (void *)arg);
1250 
1251                 case SIOCNRGETPARMS:
1252                 {
1253                         struct nr_parms_struct nr_parms;
1254                         if ((err = verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct nr_parms_struct))) != 0)
1255                                 return err;
1256                         memcpy_fromfs(&nr_parms, (void *)arg, sizeof(struct nr_parms_struct));
1257                         nr_parms = nr_default;
1258                         memcpy_tofs((void *)arg, &nr_parms, sizeof(struct nr_parms_struct));
1259                         return 0;
1260                 }
1261 
1262                 case SIOCNRSETPARMS:
1263                 {
1264                         struct nr_parms_struct nr_parms;
1265                         if (!suser()) return -EPERM;
1266                         if ((err = verify_area(VERIFY_READ, (void *)arg, sizeof(struct nr_parms_struct))) != 0)
1267                                 return err;
1268                         memcpy_fromfs(&nr_parms, (void *)arg, sizeof(struct nr_parms_struct));
1269                         nr_default = nr_parms;
1270                         return 0;
1271                 }
1272                 
1273                 default:
1274                         return dev_ioctl(cmd, (void *)arg);
1275         }
1276 
1277         /*NOTREACHED*/
1278         return(0);
1279 }
1280 
1281 static int nr_get_info(char *buffer, char **start, off_t offset, int length, int dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
1282 {
1283         struct sock *s;
1284         struct device *dev;
1285         const char *devname;
1286         int len = 0;
1287         off_t pos = 0;
1288         off_t begin = 0;
1289   
1290         cli();
1291 
1292         len += sprintf(buffer, "user_addr dest_node src_node  dev    my  your  st vs vr va    t1     t2    n2  rtt wnd Snd-Q Rcv-Q\n");
1293 
1294         for (s = nr_list; s != NULL; s = s->next) {
1295                 if ((dev = s->nr->device) == NULL)
1296                         devname = "???";
1297                 else
1298                         devname = dev->name;
1299         
1300                 len += sprintf(buffer + len, "%-9s ",
1301                         ax2asc(&s->nr->user_addr));
1302                 len += sprintf(buffer + len, "%-9s ",
1303                         ax2asc(&s->nr->dest_addr));
1304                 len += sprintf(buffer + len, "%-9s %-3s  %02X/%02X %02X/%02X %2d %2d %2d %2d %3d/%03d %2d/%02d %2d/%02d %3d %3d %5ld %5ld\n",
1305                         ax2asc(&s->nr->source_addr),
1306                         devname, s->nr->my_index, s->nr->my_id,
1307                         s->nr->your_index, s->nr->your_id,
1308                         s->nr->state,
1309                         s->nr->vs, s->nr->vr, s->nr->va,
1310                         s->nr->t1timer / PR_SLOWHZ,
1311                         s->nr->t1      / PR_SLOWHZ,
1312                         s->nr->t2timer / PR_SLOWHZ,
1313                         s->nr->t2      / PR_SLOWHZ,
1314                         s->nr->n2count, s->nr->n2,
1315                         s->nr->rtt     / PR_SLOWHZ,
1316                         s->window,
1317                         s->wmem_alloc, s->rmem_alloc);
1318                 
1319                 pos = begin + len;
1320 
1321                 if (pos < offset) {
1322                         len   = 0;
1323                         begin = pos;
1324                 }
1325                 
1326                 if (pos > offset + length)
1327                         break;
1328         }
1329 
1330         sti();
1331 
1332         *start = buffer + (offset - begin);
1333         len   -= (offset - begin);
1334 
1335         if (len > length) len = length;
1336 
1337         return(len);
1338 } 
1339 
1340 static struct proto_ops nr_proto_ops = {
1341         AF_NETROM,
1342         
1343         nr_create,
1344         nr_dup,
1345         nr_release,
1346         nr_bind,
1347         nr_connect,
1348         nr_socketpair,
1349         nr_accept,
1350         nr_getname,
1351         nr_select,
1352         nr_ioctl,
1353         nr_listen,
1354         nr_shutdown,
1355         nr_setsockopt,
1356         nr_getsockopt,
1357         nr_fcntl,
1358         nr_sendmsg,
1359         nr_recvmsg
1360 };
1361 
1362 static struct notifier_block nr_dev_notifier = {
1363         nr_device_event,
1364         0
1365 };
1366 
1367 void nr_proto_init(struct net_proto *pro)
     /* [previous][next][first][last][top][bottom][index][help] */
1368 {
1369         sock_register(nr_proto_ops.family, &nr_proto_ops);
1370         register_netdevice_notifier(&nr_dev_notifier);
1371         printk("G4KLX NET/ROM for Linux. Version 0.4 ALPHA for AX25.030 Linux 1.3.45\n");
1372 
1373         nr_default.quality    = NR_DEFAULT_QUAL;
1374         nr_default.obs_count  = NR_DEFAULT_OBS;
1375         nr_default.ttl        = NR_DEFAULT_TTL;
1376         nr_default.timeout    = NR_DEFAULT_T1;
1377         nr_default.ack_delay  = NR_DEFAULT_T2;
1378         nr_default.busy_delay = NR_DEFAULT_T4;
1379         nr_default.tries      = NR_DEFAULT_N2;
1380         nr_default.window     = NR_DEFAULT_WINDOW;
1381 
1382         proc_net_register(&(struct proc_dir_entry) {
1383                 PROC_NET_NR, 2, "nr",
1384                 S_IFREG | S_IRUGO, 1, 0, 0,
1385                 0, &proc_net_inode_operations, 
1386                 nr_get_info
1387         });
1388         proc_net_register(&(struct proc_dir_entry) {
1389                 PROC_NET_NR_NEIGH, 8, "nr_neigh",
1390                 S_IFREG | S_IRUGO, 1, 0, 0,
1391                 0, &proc_net_inode_operations, 
1392                 nr_neigh_get_info
1393         });
1394         proc_net_register(&(struct proc_dir_entry) {
1395                 PROC_NET_NR_NODES, 8, "nr_nodes",
1396                 S_IFREG | S_IRUGO, 1, 0, 0,
1397                 0, &proc_net_inode_operations, 
1398                 nr_nodes_get_info
1399         });
1400 }
1401 
1402 #endif

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