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

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