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

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