48 #include <linux/errno.h>
49 #include <linux/types.h>
50 #include <linux/socket.h>
52 #include <linux/kernel.h>
54 #include <linux/string.h>
56 #include <linux/net.h>
57 #include <linux/netdevice.h>
60 #include <linux/slab.h>
63 #include <linux/fcntl.h>
68 #include <linux/stat.h>
70 #include <linux/poll.h>
81 static void dn_log_martian(
struct sk_buff *
skb,
const char *
msg)
84 char *devname = skb->
dev ? skb->
dev->name :
"???";
86 net_info_ratelimited(
"DECnet: Martian packet (%s) dev=%s src=0x%04hx dst=0x%04hx srcport=0x%04hx dstport=0x%04hx\n",
100 static void dn_ack(
struct sock *
sk,
struct sk_buff *skb,
unsigned short ack)
103 unsigned short type = ((ack >> 12) & 0x0003);
136 static int dn_process_ack(
struct sock *sk,
struct sk_buff *skb,
int oth)
149 if ((ack & 0x4000) == 0) {
152 dn_ack(sk, skb, ack);
162 if ((ack & 0x4000) == 0) {
165 dn_ack(sk, skb, ack);
182 static inline int dn_check_idf(
unsigned char **pptr,
int *len,
unsigned char max,
unsigned char follow_on)
184 unsigned char *ptr = *pptr;
185 unsigned char flen = *ptr++;
190 if ((flen + follow_on) > *len)
208 { 0,
"CI: Truncated message" },
212 { 0,
"CI: Truncated at menuver" },
213 { 0,
"CI: Truncated before access or user data" },
225 static struct sock *dn_find_listener(
struct sk_buff *skb,
unsigned short *
reason)
231 unsigned char type = 0;
237 unsigned char menuver;
251 if (!pskb_may_pull(skb,
sizeof(*msg)))
304 if (dn_check_idf(&ptr, &len, 39, 1))
306 if (dn_check_idf(&ptr, &len, 39, 1))
308 if (dn_check_idf(&ptr, &len, 39, (menuver &
DN_MENUVER_USR) ? 1 : 0))
317 if (dn_check_idf(&ptr, &len, 16, 0))
326 dn_log_martian(skb, ci_err_table[
err].
text);
327 *reason = ci_err_table[
err].reason;
332 static void dn_nsp_conn_init(
struct sock *sk,
struct sk_buff *skb)
334 if (sk_acceptq_is_full(sk)) {
344 static void dn_nsp_conn_conf(
struct sock *sk,
struct sk_buff *skb)
347 struct dn_scp *scp = DN_SK(sk);
372 if ((dlen <= 16) && (dlen <= skb->len)) {
374 skb_copy_from_linear_data_offset(skb, 1,
387 static void dn_nsp_conn_ack(
struct sock *sk,
struct sk_buff *skb)
389 struct dn_scp *scp = DN_SK(sk);
399 static void dn_nsp_disc_init(
struct sock *sk,
struct sk_buff *skb)
401 struct dn_scp *scp = DN_SK(sk);
417 if ((dlen <= 16) && (dlen <= skb->len)) {
419 skb_copy_from_linear_data_offset(skb, 1, scp->
discdata_in.opt_data, dlen);
426 switch (scp->
state) {
467 static void dn_nsp_disc_conf(
struct sock *sk,
struct sk_buff *skb)
469 struct dn_scp *scp = DN_SK(sk);
479 switch (scp->
state) {
511 static void dn_nsp_linkservice(
struct sock *sk,
struct sk_buff *skb)
513 struct dn_scp *scp = DN_SK(sk);
514 unsigned short segnum;
515 unsigned char lsflags;
518 char *ptr = skb->
data;
526 lsflags = *(
unsigned char *)ptr++;
539 switch(lsflags & 0x04) {
541 switch(lsflags & 0x03) {
544 unsigned char p_fcval = -fcval;
549 }
else if (fcval > 0) {
570 if (wake_up && !sock_flag(sk,
SOCK_DEAD))
604 skb_set_owner_r(skb, sk);
613 static void dn_nsp_otherdata(
struct sock *sk,
struct sk_buff *skb)
615 struct dn_scp *scp = DN_SK(sk);
616 unsigned short segnum;
641 static void dn_nsp_data(
struct sock *sk,
struct sk_buff *skb)
646 struct dn_scp *scp = DN_SK(sk);
677 static void dn_returned_conn_init(
struct sock *sk,
struct sk_buff *skb)
679 struct dn_scp *scp = DN_SK(sk);
691 static int dn_nsp_no_socket(
struct sk_buff *skb,
unsigned short reason)
719 static int dn_nsp_rx_packet(
struct sk_buff *skb)
723 unsigned char *ptr = (
unsigned char *)skb->
data;
726 if (!pskb_may_pull(skb, 2))
729 skb_reset_transport_header(skb);
751 sk = dn_find_listener(skb, &reason);
756 if (!pskb_may_pull(skb, 3))
769 if (pskb_may_pull(skb, 5)) {
794 struct dn_scp *scp = DN_SK(sk);
810 return dn_nsp_no_socket(skb, reason);
830 struct dn_scp *scp = DN_SK(sk);
835 dn_returned_conn_init(sk, skb);
848 dn_nsp_conn_init(sk, skb);
851 dn_nsp_conn_conf(sk, skb);
854 dn_nsp_disc_init(sk, skb);
857 dn_nsp_disc_conf(sk, skb);
866 dn_nsp_conn_ack(sk, skb);
887 dn_process_ack(sk, skb, other);
901 dn_nsp_linkservice(sk, skb);
904 dn_nsp_otherdata(sk, skb);
907 dn_nsp_data(sk, skb);