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

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