Lines Matching +full:short +full:- +full:circuit
1 // SPDX-License-Identifier: GPL-2.0-or-later
59 static unsigned short circuit = 0x101; variable
79 lockdep_set_class(&txq->_xmit_lock, &nr_netdev_xmit_lock_key); in nr_set_lockdep_one()
84 lockdep_set_class(&dev->addr_list_lock, &nr_netdev_addr_lock_key); in nr_set_lockdep_key()
107 if (nr_sk(s)->device == dev) in nr_kill_by_device()
151 if (!ax25cmp(&nr_sk(s)->source_addr, addr) && in nr_find_listener()
152 s->sk_state == TCP_LISTEN) { in nr_find_listener()
163 * Find a connected NET/ROM socket given my circuit IDs.
173 if (nr->my_index == index && nr->my_id == id) { in nr_find_socket()
185 * Find a connected NET/ROM socket given their circuit IDs.
196 if (nr->your_index == index && nr->your_id == id && in nr_find_peer()
197 !ax25cmp(&nr->dest_addr, dest)) { in nr_find_peer()
209 * Find next free circuit ID.
211 static unsigned short nr_find_next_circuit(void) in nr_find_next_circuit()
213 unsigned short id = circuit; in nr_find_next_circuit()
255 * will touch it and we are (fairly 8-) ) safe.
271 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { in nr_destroy_socket()
272 if (skb->sk != sk) { /* A pending connection */ in nr_destroy_socket()
274 sock_set_flag(skb->sk, SOCK_DEAD); in nr_destroy_socket()
275 nr_start_heartbeat(skb->sk); in nr_destroy_socket()
276 nr_sk(skb->sk)->state = NR_STATE_0; in nr_destroy_socket()
284 sk->sk_timer.function = nr_destroy_timer; in nr_destroy_socket()
285 sk->sk_timer.expires = jiffies + 2 * HZ; in nr_destroy_socket()
286 add_timer(&sk->sk_timer); in nr_destroy_socket()
299 struct sock *sk = sock->sk; in nr_setsockopt()
304 return -ENOPROTOOPT; in nr_setsockopt()
307 return -EINVAL; in nr_setsockopt()
310 return -EFAULT; in nr_setsockopt()
315 return -EINVAL; in nr_setsockopt()
316 nr->t1 = opt * HZ; in nr_setsockopt()
321 return -EINVAL; in nr_setsockopt()
322 nr->t2 = opt * HZ; in nr_setsockopt()
327 return -EINVAL; in nr_setsockopt()
328 nr->n2 = opt; in nr_setsockopt()
333 return -EINVAL; in nr_setsockopt()
334 nr->t4 = opt * HZ; in nr_setsockopt()
339 return -EINVAL; in nr_setsockopt()
340 nr->idle = opt * 60 * HZ; in nr_setsockopt()
344 return -ENOPROTOOPT; in nr_setsockopt()
351 struct sock *sk = sock->sk; in nr_getsockopt()
357 return -ENOPROTOOPT; in nr_getsockopt()
360 return -EFAULT; in nr_getsockopt()
363 return -EINVAL; in nr_getsockopt()
367 val = nr->t1 / HZ; in nr_getsockopt()
371 val = nr->t2 / HZ; in nr_getsockopt()
375 val = nr->n2; in nr_getsockopt()
379 val = nr->t4 / HZ; in nr_getsockopt()
383 val = nr->idle / (60 * HZ); in nr_getsockopt()
387 return -ENOPROTOOPT; in nr_getsockopt()
393 return -EFAULT; in nr_getsockopt()
395 return copy_to_user(optval, &val, len) ? -EFAULT : 0; in nr_getsockopt()
400 struct sock *sk = sock->sk; in nr_listen()
403 if (sock->state != SS_UNCONNECTED) { in nr_listen()
405 return -EINVAL; in nr_listen()
408 if (sk->sk_state != TCP_LISTEN) { in nr_listen()
409 memset(&nr_sk(sk)->user_addr, 0, AX25_ADDR_LEN); in nr_listen()
410 sk->sk_max_ack_backlog = backlog; in nr_listen()
411 sk->sk_state = TCP_LISTEN; in nr_listen()
417 return -EOPNOTSUPP; in nr_listen()
433 return -EAFNOSUPPORT; in nr_create()
435 if (sock->type != SOCK_SEQPACKET || protocol != 0) in nr_create()
436 return -ESOCKTNOSUPPORT; in nr_create()
440 return -ENOMEM; in nr_create()
446 sock->ops = &nr_proto_ops; in nr_create()
447 sk->sk_protocol = protocol; in nr_create()
449 skb_queue_head_init(&nr->ack_queue); in nr_create()
450 skb_queue_head_init(&nr->reseq_queue); in nr_create()
451 skb_queue_head_init(&nr->frag_queue); in nr_create()
455 nr->t1 = in nr_create()
457 nr->t2 = in nr_create()
459 nr->n2 = in nr_create()
461 nr->t4 = in nr_create()
463 nr->idle = in nr_create()
465 nr->window = READ_ONCE(sysctl_netrom_transport_requested_window_size); in nr_create()
467 nr->bpqext = 1; in nr_create()
468 nr->state = NR_STATE_0; in nr_create()
478 if (osk->sk_type != SOCK_SEQPACKET) in nr_make_new()
481 sk = sk_alloc(sock_net(osk), PF_NETROM, GFP_ATOMIC, osk->sk_prot, 0); in nr_make_new()
489 sk->sk_type = osk->sk_type; in nr_make_new()
490 sk->sk_priority = osk->sk_priority; in nr_make_new()
491 sk->sk_protocol = osk->sk_protocol; in nr_make_new()
492 sk->sk_rcvbuf = osk->sk_rcvbuf; in nr_make_new()
493 sk->sk_sndbuf = osk->sk_sndbuf; in nr_make_new()
494 sk->sk_state = TCP_ESTABLISHED; in nr_make_new()
497 skb_queue_head_init(&nr->ack_queue); in nr_make_new()
498 skb_queue_head_init(&nr->reseq_queue); in nr_make_new()
499 skb_queue_head_init(&nr->frag_queue); in nr_make_new()
505 nr->t1 = onr->t1; in nr_make_new()
506 nr->t2 = onr->t2; in nr_make_new()
507 nr->n2 = onr->n2; in nr_make_new()
508 nr->t4 = onr->t4; in nr_make_new()
509 nr->idle = onr->idle; in nr_make_new()
510 nr->window = onr->window; in nr_make_new()
512 nr->device = onr->device; in nr_make_new()
513 nr->bpqext = onr->bpqext; in nr_make_new()
520 struct sock *sk = sock->sk; in nr_release()
530 switch (nr->state) { in nr_release()
540 nr->n2count = 0; in nr_release()
546 nr->state = NR_STATE_2; in nr_release()
547 sk->sk_state = TCP_CLOSE; in nr_release()
548 sk->sk_shutdown |= SEND_SHUTDOWN; in nr_release()
549 sk->sk_state_change(sk); in nr_release()
557 sock->sk = NULL; in nr_release()
566 struct sock *sk = sock->sk; in nr_bind()
576 return -EINVAL; in nr_bind()
580 return -EINVAL; in nr_bind()
582 …if (addr_len < (addr->fsa_ax25.sax25_ndigis * sizeof(ax25_address) + sizeof(struct sockaddr_ax25))… in nr_bind()
584 return -EINVAL; in nr_bind()
586 if (addr->fsa_ax25.sax25_family != AF_NETROM) { in nr_bind()
588 return -EINVAL; in nr_bind()
590 if ((dev = nr_dev_get(&addr->fsa_ax25.sax25_call)) == NULL) { in nr_bind()
592 return -EADDRNOTAVAIL; in nr_bind()
598 if (addr->fsa_ax25.sax25_ndigis == 1) { in nr_bind()
602 return -EPERM; in nr_bind()
604 nr->user_addr = addr->fsa_digipeater[0]; in nr_bind()
605 nr->source_addr = addr->fsa_ax25.sax25_call; in nr_bind()
607 source = &addr->fsa_ax25.sax25_call; in nr_bind()
611 nr->user_addr = user->call; in nr_bind()
617 return -EPERM; in nr_bind()
619 nr->user_addr = *source; in nr_bind()
622 nr->source_addr = *source; in nr_bind()
625 nr->device = dev; in nr_bind()
638 struct sock *sk = sock->sk; in nr_connect()
647 if (sk->sk_state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) { in nr_connect()
648 sock->state = SS_CONNECTED; in nr_connect()
652 if (sk->sk_state == TCP_CLOSE && sock->state == SS_CONNECTING) { in nr_connect()
653 sock->state = SS_UNCONNECTED; in nr_connect()
654 err = -ECONNREFUSED; in nr_connect()
658 if (sk->sk_state == TCP_ESTABLISHED) { in nr_connect()
659 err = -EISCONN; /* No reconnect on a seqpacket socket */ in nr_connect()
663 if (sock->state == SS_CONNECTING) { in nr_connect()
664 err = -EALREADY; in nr_connect()
668 sk->sk_state = TCP_CLOSE; in nr_connect()
669 sock->state = SS_UNCONNECTED; in nr_connect()
672 err = -EINVAL; in nr_connect()
675 if (addr->sax25_family != AF_NETROM) { in nr_connect()
676 err = -EINVAL; in nr_connect()
679 if (sock_flag(sk, SOCK_ZAPPED)) { /* Must bind first - autobinding in this may or may not work */ in nr_connect()
683 err = -ENETUNREACH; in nr_connect()
686 source = (const ax25_address *)dev->dev_addr; in nr_connect()
690 nr->user_addr = user->call; in nr_connect()
695 err = -EPERM; in nr_connect()
698 nr->user_addr = *source; in nr_connect()
701 nr->source_addr = *source; in nr_connect()
702 nr->device = dev; in nr_connect()
708 nr->dest_addr = addr->sax25_call; in nr_connect()
711 circuit = nr_find_next_circuit(); in nr_connect()
714 nr->my_index = circuit / 256; in nr_connect()
715 nr->my_id = circuit % 256; in nr_connect()
717 circuit++; in nr_connect()
720 sock->state = SS_CONNECTING; in nr_connect()
721 sk->sk_state = TCP_SYN_SENT; in nr_connect()
725 nr->state = NR_STATE_1; in nr_connect()
730 if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) { in nr_connect()
731 err = -EINPROGRESS; in nr_connect()
739 if (sk->sk_state == TCP_SYN_SENT) { in nr_connect()
745 if (sk->sk_state != TCP_SYN_SENT) in nr_connect()
753 err = -ERESTARTSYS; in nr_connect()
761 if (sk->sk_state != TCP_ESTABLISHED) { in nr_connect()
762 sock->state = SS_UNCONNECTED; in nr_connect()
767 sock->state = SS_CONNECTED; in nr_connect()
784 if ((sk = sock->sk) == NULL) in nr_accept()
785 return -EINVAL; in nr_accept()
788 if (sk->sk_type != SOCK_SEQPACKET) { in nr_accept()
789 err = -EOPNOTSUPP; in nr_accept()
793 if (sk->sk_state != TCP_LISTEN) { in nr_accept()
794 err = -EINVAL; in nr_accept()
804 skb = skb_dequeue(&sk->sk_receive_queue); in nr_accept()
809 err = -EWOULDBLOCK; in nr_accept()
818 err = -ERESTARTSYS; in nr_accept()
825 newsk = skb->sk; in nr_accept()
842 struct sock *sk = sock->sk; in nr_getname()
846 memset(&sax->fsa_ax25, 0, sizeof(struct sockaddr_ax25)); in nr_getname()
850 if (sk->sk_state != TCP_ESTABLISHED) { in nr_getname()
852 return -ENOTCONN; in nr_getname()
854 sax->fsa_ax25.sax25_family = AF_NETROM; in nr_getname()
855 sax->fsa_ax25.sax25_ndigis = 1; in nr_getname()
856 sax->fsa_ax25.sax25_call = nr->user_addr; in nr_getname()
857 memset(sax->fsa_digipeater, 0, sizeof(sax->fsa_digipeater)); in nr_getname()
858 sax->fsa_digipeater[0] = nr->dest_addr; in nr_getname()
861 sax->fsa_ax25.sax25_family = AF_NETROM; in nr_getname()
862 sax->fsa_ax25.sax25_ndigis = 0; in nr_getname()
863 sax->fsa_ax25.sax25_call = nr->source_addr; in nr_getname()
877 unsigned short circuit_index, circuit_id; in nr_rx_frame()
878 unsigned short peer_circuit_index, peer_circuit_id; in nr_rx_frame()
879 unsigned short frametype, flags, window, timeout; in nr_rx_frame()
885 * skb->data points to the netrom frame start in nr_rx_frame()
888 src = (ax25_address *)(skb->data + 0); in nr_rx_frame()
889 dest = (ax25_address *)(skb->data + 7); in nr_rx_frame()
891 circuit_index = skb->data[15]; in nr_rx_frame()
892 circuit_id = skb->data[16]; in nr_rx_frame()
893 peer_circuit_index = skb->data[17]; in nr_rx_frame()
894 peer_circuit_id = skb->data[18]; in nr_rx_frame()
895 frametype = skb->data[19] & 0x0F; in nr_rx_frame()
896 flags = skb->data[19] & 0xF0; in nr_rx_frame()
910 * Find an existing socket connection, based on circuit ID, if it's in nr_rx_frame()
911 * a Connect Request base it on their circuit ID. in nr_rx_frame()
913 * Circuit ID 0/0 is not valid but it could still be a "reset" for a in nr_rx_frame()
914 * circuit that no longer exists at the other end ... in nr_rx_frame()
933 if (frametype == NR_CONNACK && skb->len == 22) in nr_rx_frame()
934 nr_sk(sk)->bpqext = 1; in nr_rx_frame()
936 nr_sk(sk)->bpqext = 0; in nr_rx_frame()
952 * apparently kills BPQ boxes... :-( in nr_rx_frame()
966 user = (ax25_address *)(skb->data + 21); in nr_rx_frame()
978 window = skb->data[20]; in nr_rx_frame()
981 skb->sk = make; in nr_rx_frame()
982 skb->destructor = sock_efree; in nr_rx_frame()
983 make->sk_state = TCP_ESTABLISHED; in nr_rx_frame()
985 /* Fill in his circuit details */ in nr_rx_frame()
987 nr_make->source_addr = *dest; in nr_rx_frame()
988 nr_make->dest_addr = *src; in nr_rx_frame()
989 nr_make->user_addr = *user; in nr_rx_frame()
991 nr_make->your_index = circuit_index; in nr_rx_frame()
992 nr_make->your_id = circuit_id; in nr_rx_frame()
995 circuit = nr_find_next_circuit(); in nr_rx_frame()
998 nr_make->my_index = circuit / 256; in nr_rx_frame()
999 nr_make->my_id = circuit % 256; in nr_rx_frame()
1001 circuit++; in nr_rx_frame()
1004 if (window < nr_make->window) in nr_rx_frame()
1005 nr_make->window = window; in nr_rx_frame()
1008 if (skb->len == 37) { in nr_rx_frame()
1009 timeout = skb->data[36] * 256 + skb->data[35]; in nr_rx_frame()
1010 if (timeout * HZ < nr_make->t1) in nr_rx_frame()
1011 nr_make->t1 = timeout * HZ; in nr_rx_frame()
1012 nr_make->bpqext = 1; in nr_rx_frame()
1014 nr_make->bpqext = 0; in nr_rx_frame()
1019 nr_make->condition = 0x00; in nr_rx_frame()
1020 nr_make->vs = 0; in nr_rx_frame()
1021 nr_make->va = 0; in nr_rx_frame()
1022 nr_make->vr = 0; in nr_rx_frame()
1023 nr_make->vl = 0; in nr_rx_frame()
1024 nr_make->state = NR_STATE_3; in nr_rx_frame()
1026 skb_queue_head(&sk->sk_receive_queue, skb); in nr_rx_frame()
1029 sk->sk_data_ready(sk); in nr_rx_frame()
1044 struct sock *sk = sock->sk; in nr_sendmsg()
1046 DECLARE_SOCKADDR(struct sockaddr_ax25 *, usax, msg->msg_name); in nr_sendmsg()
1053 if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_CMSG_COMPAT)) in nr_sendmsg()
1054 return -EINVAL; in nr_sendmsg()
1058 err = -EADDRNOTAVAIL; in nr_sendmsg()
1062 if (sk->sk_shutdown & SEND_SHUTDOWN) { in nr_sendmsg()
1064 err = -EPIPE; in nr_sendmsg()
1068 if (nr->device == NULL) { in nr_sendmsg()
1069 err = -ENETUNREACH; in nr_sendmsg()
1074 if (msg->msg_namelen < sizeof(sax)) { in nr_sendmsg()
1075 err = -EINVAL; in nr_sendmsg()
1079 if (ax25cmp(&nr->dest_addr, &sax.sax25_call) != 0) { in nr_sendmsg()
1080 err = -EISCONN; in nr_sendmsg()
1084 err = -EINVAL; in nr_sendmsg()
1088 if (sk->sk_state != TCP_ESTABLISHED) { in nr_sendmsg()
1089 err = -ENOTCONN; in nr_sendmsg()
1093 sax.sax25_call = nr->dest_addr; in nr_sendmsg()
1096 /* Build a packet - the conventional user limit is 236 bytes. We can in nr_sendmsg()
1099 err = -EMSGSIZE; in nr_sendmsg()
1105 if ((skb = sock_alloc_send_skb(sk, size, msg->msg_flags & MSG_DONTWAIT, &err)) == NULL) in nr_sendmsg()
1108 skb_reserve(skb, size - len); in nr_sendmsg()
1119 *asmptr++ = nr->your_index; in nr_sendmsg()
1120 *asmptr++ = nr->your_id; in nr_sendmsg()
1133 err = -EFAULT; in nr_sendmsg()
1137 if (sk->sk_state != TCP_ESTABLISHED) { in nr_sendmsg()
1139 err = -ENOTCONN; in nr_sendmsg()
1154 struct sock *sk = sock->sk; in nr_recvmsg()
1155 DECLARE_SOCKADDR(struct sockaddr_ax25 *, sax, msg->msg_name); in nr_recvmsg()
1166 if (sk->sk_state != TCP_ESTABLISHED) { in nr_recvmsg()
1168 return -ENOTCONN; in nr_recvmsg()
1179 copied = skb->len; in nr_recvmsg()
1183 msg->msg_flags |= MSG_TRUNC; in nr_recvmsg()
1195 sax->sax25_family = AF_NETROM; in nr_recvmsg()
1196 skb_copy_from_linear_data_offset(skb, 7, sax->sax25_call.ax25_call, in nr_recvmsg()
1198 msg->msg_namelen = sizeof(*sax); in nr_recvmsg()
1210 struct sock *sk = sock->sk; in nr_ioctl()
1218 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk); in nr_ioctl()
1231 if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) in nr_ioctl()
1232 amount = skb->len; in nr_ioctl()
1247 return -EINVAL; in nr_ioctl()
1253 return -EPERM; in nr_ioctl()
1257 return -ENOIOCTLCMD; in nr_ioctl()
1293 …ode dev my your st vs vr va t1 t2 t4 idle n2 wnd Snd-Q Rcv-Q inode\n"); in nr_info_show()
1300 if ((dev = nr->device) == NULL) in nr_info_show()
1303 devname = dev->name; in nr_info_show()
1305 seq_printf(seq, "%-9s ", ax2asc(buf, &nr->user_addr)); in nr_info_show()
1306 seq_printf(seq, "%-9s ", ax2asc(buf, &nr->dest_addr)); in nr_info_show()
1308 "%-9s %-3s %02X/%02X %02X/%02X %2d %3d %3d %3d %3lu/%03lu %2lu/%02lu %3lu/%03lu %3lu/%03lu %2d/%02… in nr_info_show()
1309 ax2asc(buf, &nr->source_addr), in nr_info_show()
1311 nr->my_index, in nr_info_show()
1312 nr->my_id, in nr_info_show()
1313 nr->your_index, in nr_info_show()
1314 nr->your_id, in nr_info_show()
1315 nr->state, in nr_info_show()
1316 nr->vs, in nr_info_show()
1317 nr->vr, in nr_info_show()
1318 nr->va, in nr_info_show()
1319 ax25_display_timer(&nr->t1timer) / HZ, in nr_info_show()
1320 nr->t1 / HZ, in nr_info_show()
1321 ax25_display_timer(&nr->t2timer) / HZ, in nr_info_show()
1322 nr->t2 / HZ, in nr_info_show()
1323 ax25_display_timer(&nr->t4timer) / HZ, in nr_info_show()
1324 nr->t4 / HZ, in nr_info_show()
1325 ax25_display_timer(&nr->idletimer) / (60 * HZ), in nr_info_show()
1326 nr->idle / (60 * HZ), in nr_info_show()
1327 nr->n2count, in nr_info_show()
1328 nr->n2, in nr_info_show()
1329 nr->window, in nr_info_show()
1332 s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L); in nr_info_show()
1398 pr_err("NET/ROM: %s - nr_ndevs parameter too large\n", in nr_proto_init()
1400 rc = -EINVAL; in nr_proto_init()
1406 pr_err("NET/ROM: %s - unable to allocate device array\n", in nr_proto_init()
1408 rc = -ENOMEM; in nr_proto_init()
1419 rc = -ENOMEM; in nr_proto_init()
1423 dev->base_addr = i; in nr_proto_init()
1452 rc = -ENOMEM; in nr_proto_init()
1483 while (--i >= 0) { in nr_proto_init()