^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * DECnet An implementation of the DECnet protocol suite for the LINUX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * operating system. DECnet is implemented using the BSD Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * interface as the means of communication with the user level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * DECnet Network Services Protocol (Input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Author: Eduardo Marcelo Serrat <emserrat@geocities.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Steve Whitehouse: Split into dn_nsp_in.c and dn_nsp_out.c from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * original dn_nsp.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Steve Whitehouse: Updated to work with my new routing architecture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Steve Whitehouse: Add changes from Eduardo Serrat's patches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Steve Whitehouse: Put all ack handling code in a common routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Steve Whitehouse: Put other common bits into dn_nsp_rx()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Steve Whitehouse: More checks on skb->len to catch bogus packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Fixed various race conditions and possible nasties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Steve Whitehouse: Now handles returned conninit frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * David S. Miller: New socket locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Steve Whitehouse: Fixed lockup when socket filtering was enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Paul Koning: Fix to push CC sockets into RUN when acks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Steve Whitehouse:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Patrick Caulfield: Checking conninits for correctness & sending of error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * responses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Steve Whitehouse: Added backlog congestion level return codes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Patrick Caulfield:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Steve Whitehouse: Added flow control support (outbound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Steve Whitehouse: Prepare for nonlinear skbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) (c) 1995-1998 E.M. Serrat emserrat@geocities.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <linux/termios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <linux/netfilter_decnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <net/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <net/dn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <net/dn_nsp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <net/dn_dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <net/dn_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern int decnet_log_martians;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void dn_log_martian(struct sk_buff *skb, const char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (decnet_log_martians) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) char *devname = skb->dev ? skb->dev->name : "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) net_info_ratelimited("DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) msg, devname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) le16_to_cpu(cb->src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) le16_to_cpu(cb->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) le16_to_cpu(cb->src_port),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) le16_to_cpu(cb->dst_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * For this function we've flipped the cross-subchannel bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * if the message is an otherdata or linkservice message. Thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * we can use it to work out what to update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void dn_ack(struct sock *sk, struct sk_buff *skb, unsigned short ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned short type = ((ack >> 12) & 0x0003);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int wakeup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case 0: /* ACK - Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (dn_after(ack, scp->ackrcv_dat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) scp->ackrcv_dat = ack & 0x0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) wakeup |= dn_nsp_check_xmit_queue(sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) &scp->data_xmit_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case 1: /* NAK - Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case 2: /* ACK - OtherData */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (dn_after(ack, scp->ackrcv_oth)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) scp->ackrcv_oth = ack & 0x0fff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) wakeup |= dn_nsp_check_xmit_queue(sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) &scp->other_xmit_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) case 3: /* NAK - OtherData */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (wakeup && !sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * This function is a universal ack processor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int dn_process_ack(struct sock *sk, struct sk_buff *skb, int oth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __le16 *ptr = (__le16 *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned short ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (skb->len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) len += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if ((ack & 0x4000) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (oth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ack ^= 0x2000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dn_ack(sk, skb, ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (skb->len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if ((ack = le16_to_cpu(*ptr)) & 0x8000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) len += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if ((ack & 0x4000) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (oth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ack ^= 0x2000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) dn_ack(sk, skb, ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * dn_check_idf - Check an image data field format is correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @pptr: Pointer to pointer to image data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @len: Pointer to length of image data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @max: The maximum allowed length of the data in the image data field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * @follow_on: Check that this many bytes exist beyond the end of the image data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Returns: 0 if ok, -1 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static inline int dn_check_idf(unsigned char **pptr, int *len, unsigned char max, unsigned char follow_on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) unsigned char *ptr = *pptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned char flen = *ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) (*len)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (flen > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if ((flen + follow_on) > *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) *len -= flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *pptr = ptr + flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * Table of reason codes to pass back to node which sent us a badly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * formed message, plus text messages for the log. A zero entry in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * the reason field means "don't reply" otherwise a disc init is sent with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * the specified reason code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) unsigned short reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) const char *text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } ci_err_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) { 0, "CI: Truncated message" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) { NSP_REASON_ID, "CI: Destination username error" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) { NSP_REASON_ID, "CI: Destination username type" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) { NSP_REASON_US, "CI: Source username error" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) { 0, "CI: Truncated at menuver" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) { 0, "CI: Truncated before access or user data" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) { NSP_REASON_IO, "CI: Access data format error" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) { NSP_REASON_IO, "CI: User data format error" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * This function uses a slightly different lookup method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * to find its sockets, since it searches on object name/number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * rather than port numbers. Various tests are done to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * the incoming data is in the correct format before it is queued to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * a socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static struct sock *dn_find_listener(struct sk_buff *skb, unsigned short *reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct nsp_conn_init_msg *msg = (struct nsp_conn_init_msg *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct sockaddr_dn dstaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct sockaddr_dn srcaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned char type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int dstlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int srclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) unsigned char menuver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) memset(&dstaddr, 0, sizeof(struct sockaddr_dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) memset(&srcaddr, 0, sizeof(struct sockaddr_dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * 1. Decode & remove message header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cb->src_port = msg->srcaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) cb->dst_port = msg->dstaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) cb->services = msg->services;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) cb->info = msg->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) cb->segsize = le16_to_cpu(msg->segsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (!pskb_may_pull(skb, sizeof(*msg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) skb_pull(skb, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ptr = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * 2. Check destination end username format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dstlen = dn_username2sockaddr(ptr, len, &dstaddr, &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (dstlen < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (type > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) len -= dstlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ptr += dstlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * 3. Check source end username format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) srclen = dn_username2sockaddr(ptr, len, &srcaddr, &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (srclen < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) len -= srclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ptr += srclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (len < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) menuver = *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * 4. Check that optional data actually exists if menuver says it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if ((menuver & (DN_MENUVER_ACC | DN_MENUVER_USR)) && (len < 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * 5. Check optional access data format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (menuver & DN_MENUVER_ACC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (dn_check_idf(&ptr, &len, 39, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (dn_check_idf(&ptr, &len, 39, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (dn_check_idf(&ptr, &len, 39, (menuver & DN_MENUVER_USR) ? 1 : 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * 6. Check optional user data format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (menuver & DN_MENUVER_USR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (dn_check_idf(&ptr, &len, 16, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * 7. Look up socket based on destination end username
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return dn_sklist_find_listener(&dstaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) dn_log_martian(skb, ci_err_table[err].text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) *reason = ci_err_table[err].reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static void dn_nsp_conn_init(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (sk_acceptq_is_full(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) sk_acceptq_added(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) skb_queue_tail(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (skb->len < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ptr = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) cb->services = *ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) cb->info = *ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) cb->segsize = le16_to_cpu(*(__le16 *)ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if ((scp->state == DN_CI) || (scp->state == DN_CD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) scp->persist = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) scp->addrrem = cb->src_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) scp->state = DN_RUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) scp->services_rem = cb->services;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) scp->info_rem = cb->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) scp->segsize_rem = cb->segsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if ((scp->services_rem & NSP_FC_MASK) == NSP_FC_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) scp->max_window = decnet_no_fc_max_cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (skb->len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) u16 dlen = *skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if ((dlen <= 16) && (dlen <= skb->len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) scp->conndata_in.opt_optl = cpu_to_le16(dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) skb_copy_from_linear_data_offset(skb, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) scp->conndata_in.opt_data, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) dn_nsp_send_link(sk, DN_NOCHANGE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static void dn_nsp_conn_ack(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (scp->state == DN_CI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) scp->state = DN_CD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) scp->persist = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) unsigned short reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (skb->len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) reason = le16_to_cpu(*(__le16 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) scp->discdata_in.opt_status = cpu_to_le16(reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) scp->discdata_in.opt_optl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) memset(scp->discdata_in.opt_data, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (skb->len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) u16 dlen = *skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if ((dlen <= 16) && (dlen <= skb->len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) scp->discdata_in.opt_optl = cpu_to_le16(dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) skb_copy_from_linear_data_offset(skb, 1, scp->discdata_in.opt_data, dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) scp->addrrem = cb->src_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) switch (scp->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) case DN_CI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case DN_CD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) scp->state = DN_RJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) sk->sk_err = ECONNREFUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case DN_RUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) sk->sk_shutdown |= SHUTDOWN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) scp->state = DN_DN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) case DN_DI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) scp->state = DN_DIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (sk->sk_socket->state != SS_UNCONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) sk->sk_socket->state = SS_DISCONNECTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * It appears that its possible for remote machines to send disc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * init messages with no port identifier if we are in the CI and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * possibly also the CD state. Obviously we shouldn't reply with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * a message if we don't know what the end point is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (scp->addrrem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) dn_nsp_send_disc(sk, NSP_DISCCONF, NSP_REASON_DC, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) scp->persist_fxn = dn_destroy_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) scp->persist = dn_nsp_persist(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * disc_conf messages are also called no_resources or no_link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * messages depending upon the "reason" field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static void dn_nsp_disc_conf(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) unsigned short reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (skb->len != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) reason = le16_to_cpu(*(__le16 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) switch (scp->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) case DN_CI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) scp->state = DN_NR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) case DN_DR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (reason == NSP_REASON_DC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) scp->state = DN_DRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (reason == NSP_REASON_NL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) scp->state = DN_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) case DN_DI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) scp->state = DN_DIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) case DN_RUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) sk->sk_shutdown |= SHUTDOWN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) case DN_CC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) scp->state = DN_CN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (!sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (sk->sk_socket->state != SS_UNCONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) sk->sk_socket->state = SS_DISCONNECTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) scp->persist_fxn = dn_destroy_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) scp->persist = dn_nsp_persist(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static void dn_nsp_linkservice(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) unsigned short segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) unsigned char lsflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) signed char fcval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int wake_up = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) char *ptr = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) unsigned char fctype = scp->services_rem & NSP_FC_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (skb->len != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) segnum = le16_to_cpu(*(__le16 *)ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) lsflags = *(unsigned char *)ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) fcval = *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * Here we ignore erronous packets which should really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * should cause a connection abort. It is not critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * for now though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (lsflags & 0xf8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (seq_next(scp->numoth_rcv, segnum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) seq_add(&scp->numoth_rcv, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) switch(lsflags & 0x04) { /* FCVAL INT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) case 0x00: /* Normal Request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) switch(lsflags & 0x03) { /* FCVAL MOD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) case 0x00: /* Request count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (fcval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) unsigned char p_fcval = -fcval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if ((scp->flowrem_dat > p_fcval) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) (fctype == NSP_FC_SCMC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) scp->flowrem_dat -= p_fcval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) } else if (fcval > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) scp->flowrem_dat += fcval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) wake_up = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) case 0x01: /* Stop outgoing data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) scp->flowrem_sw = DN_DONTSEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) case 0x02: /* Ok to start again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) scp->flowrem_sw = DN_SEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) dn_nsp_output(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) wake_up = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) case 0x04: /* Interrupt Request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (fcval > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) scp->flowrem_oth += fcval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) wake_up = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (wake_up && !sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) dn_nsp_send_oth_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * Copy of sock_queue_rcv_skb (from sock.h) without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * bh_lock_sock() (its already held when this is called) which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * also allows data and other data to be queued to a socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static __inline__ int dn_queue_skb(struct sock *sk, struct sk_buff *skb, int sig, struct sk_buff_head *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) number of warnings when compiling with -W --ANK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) (unsigned int)sk->sk_rcvbuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) err = sk_filter(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) skb_set_owner_r(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) skb_queue_tail(queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static void dn_nsp_otherdata(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) unsigned short segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (skb->len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (seq_next(scp->numoth_rcv, segnum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) if (dn_queue_skb(sk, skb, SIGURG, &scp->other_receive_queue) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) seq_add(&scp->numoth_rcv, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) scp->other_report = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) dn_nsp_send_oth_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (!queued)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static void dn_nsp_data(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) unsigned short segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (skb->len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) cb->segnum = segnum = le16_to_cpu(*(__le16 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (seq_next(scp->numdat_rcv, segnum)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (dn_queue_skb(sk, skb, SIGIO, &sk->sk_receive_queue) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) seq_add(&scp->numdat_rcv, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if ((scp->flowloc_sw == DN_SEND) && dn_congested(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) scp->flowloc_sw = DN_DONTSEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) dn_nsp_send_link(sk, DN_DONTSEND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) dn_nsp_send_data_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!queued)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * If one of our conninit messages is returned, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * deals with it. It puts the socket into the NO_COMMUNICATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static void dn_returned_conn_init(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (scp->state == DN_CI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) scp->state = DN_NC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) sk->sk_state = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static int dn_nsp_no_socket(struct sk_buff *skb, unsigned short reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) int ret = NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Must not reply to returned packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (cb->rt_flags & DN_RT_F_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if ((reason != NSP_REASON_OK) && ((cb->nsp_flags & 0x0c) == 0x08)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) switch (cb->nsp_flags & 0x70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) case 0x60: /* (Retransmitted) Connect Init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) dn_nsp_return_disc(skb, NSP_DISCINIT, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ret = NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) case 0x20: /* Connect Confirm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) dn_nsp_return_disc(skb, NSP_DISCCONF, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) ret = NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) static int dn_nsp_rx_packet(struct net *net, struct sock *sk2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct sock *sk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unsigned char *ptr = (unsigned char *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) unsigned short reason = NSP_REASON_NL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!pskb_may_pull(skb, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) cb->nsp_flags = *ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (decnet_debug_level & 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) printk(KERN_DEBUG "dn_nsp_rx: Message type 0x%02x\n", (int)cb->nsp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (cb->nsp_flags & 0x83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * Filter out conninits and useless packet types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if ((cb->nsp_flags & 0x0c) == 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) switch (cb->nsp_flags & 0x70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) case 0x00: /* NOP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) case 0x70: /* Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) case 0x50: /* Reserved, Phase II node init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) case 0x60:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (unlikely(cb->rt_flags & DN_RT_F_RTS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) sk = dn_find_listener(skb, &reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (!pskb_may_pull(skb, 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * Grab the destination address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) cb->dst_port = *(__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) cb->src_port = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * If not a connack, grab the source address too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (pskb_may_pull(skb, 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) cb->src_port = *(__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) skb_pull(skb, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * Returned packets...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * Swap src & dst and look up in the normal way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (unlikely(cb->rt_flags & DN_RT_F_RTS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) swap(cb->dst_port, cb->src_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) swap(cb->dst, cb->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * Find the socket to which this skb is destined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) sk = dn_find_by_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) got_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) if (sk != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* Reset backoff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) scp->nsp_rxtshift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * We linearize everything except data segments here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (cb->nsp_flags & ~0x60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (unlikely(skb_linearize(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) return sk_receive_skb(sk, skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return dn_nsp_no_socket(skb, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) free_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) int dn_nsp_rx(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) return NF_HOOK(NFPROTO_DECNET, NF_DN_LOCAL_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) dn_nsp_rx_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * This is the main receive routine for sockets. It is called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) * from the above when the socket is not busy, and also from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * sock_release() when there is a backlog queued up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct dn_scp *scp = DN_SK(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (cb->rt_flags & DN_RT_F_RTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (cb->nsp_flags == 0x18 || cb->nsp_flags == 0x68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) dn_returned_conn_init(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * Control packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if ((cb->nsp_flags & 0x0c) == 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) switch (cb->nsp_flags & 0x70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) case 0x60:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) dn_nsp_conn_init(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) dn_nsp_conn_conf(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) case 0x30:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) dn_nsp_disc_init(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) dn_nsp_disc_conf(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) } else if (cb->nsp_flags == 0x24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * Special for connacks, 'cos they don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * ack data or ack otherdata info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) dn_nsp_conn_ack(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) int other = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /* both data and ack frames can kick a CC socket into RUN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if ((scp->state == DN_CC) && !sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) scp->state = DN_RUN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if ((cb->nsp_flags & 0x1c) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) other = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (cb->nsp_flags == 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) other = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * Read out ack data here, this applies equally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * to data, other data, link serivce and both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * ack data and ack otherdata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) dn_process_ack(sk, skb, other);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * If we've some sort of data here then call a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * suitable routine for dealing with it, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * the packet is an ack and can be discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if ((cb->nsp_flags & 0x0c) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (scp->state != DN_RUN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) goto free_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) switch (cb->nsp_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) case 0x10: /* LS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) dn_nsp_linkservice(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) case 0x30: /* OD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) dn_nsp_otherdata(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) dn_nsp_data(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) } else { /* Ack, chuck it out here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) free_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }