1 /* tcp_subr.c 4.1 81/11/24 */ 2 3 #include "../h/param.h" 4 #include "../h/systm.h" 5 #include "../h/mbuf.h" 6 #include "../h/socket.h" 7 #include "../h/socketvar.h" 8 #include "../h/protosw.h" 9 #include "../net/inet.h" 10 #include "../net/inet_pcb.h" 11 #include "../net/inet_systm.h" 12 #include "../net/if.h" 13 #include "../net/imp.h" 14 #include "../net/ip.h" 15 #include "../net/ip_var.h" 16 #include "../net/tcp.h" 17 #define TCPFSTAB 18 #include "../net/tcp_fsm.h" 19 #include "../net/tcp_var.h" 20 #include "/usr/include/errno.h" 21 22 /* 23 * Tcp initialization 24 */ 25 tcp_init() 26 { 27 28 tcp_iss = 1; /* wrong */ 29 tcb.inp_next = tcb.inp_prev = &tcb; 30 } 31 32 /* 33 * Create template to be used to send tcp packets on a connection. 34 * Call after host entry created, allocates an mbuf and fills 35 * in a skeletal tcp/ip header, minimizing the amount of work 36 * necessary when the connection is used. 37 */ 38 struct tcpiphdr * 39 tcp_template(tp) 40 struct tcpcb *tp; 41 { 42 register struct inpcb *inp = tp->t_inpcb; 43 register struct mbuf *m; 44 register struct tcpiphdr *n; 45 46 COUNT(TCP_TEMPLATE); 47 m = m_get(1); 48 if (m == 0) 49 return (0); 50 m->m_off = MMAXOFF - sizeof (struct tcpiphdr); 51 m->m_len = sizeof (struct tcpiphdr); 52 n = mtod(m, struct tcpiphdr *); 53 n->ti_next = n->ti_prev = 0; 54 n->ti_x1 = 0; 55 n->ti_pr = IPPROTO_TCP; 56 n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip)); 57 n->ti_src = inp->inp_laddr; 58 n->ti_dst = inp->inp_faddr; 59 n->ti_sport = inp->inp_lport; 60 n->ti_dport = inp->inp_fport; 61 n->ti_seq = 0; 62 n->ti_ackno = 0; 63 n->ti_x2 = 0; 64 n->ti_off = 5; 65 n->ti_flags = 0; 66 n->ti_win = 0; 67 n->ti_sum = 0; 68 n->ti_urp = 0; 69 return (n); 70 } 71 72 /* 73 * Reflect a control message back to sender of tcp segment ti, 74 * with ack, seq and flags fields as specified by parameters. 75 */ 76 tcp_reflect(ti, ack, seq, flags) 77 register struct tcpiphdr *ti; 78 tcpseq_t ack, seq; 79 int flags; 80 { 81 82 m_freem(m->m_next); 83 m->m_next = 0; 84 m->m_len = sizeof(struct tcpiphdr); 85 #define xchg(a,b) j=a; a=b; b=j 86 xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr); 87 xchg(ti->ti_dport, ti->ti_sport); 88 #undef xchg 89 ti->ti_ack = htonl(ack); 90 ti->ti_seq = htonl(seq); 91 ti->ti_flags = flags; 92 93 ti->ti_len = htons(sizeof (struct tcphdr)); 94 ti->ti_off = 5; 95 ti->ti_sum = inet_cksum(m, sizeof(struct tcpiphdr)); 96 ((struct ip *)ti)->ip_len = sizeof(struct tcpiphdr); 97 ((struct ip *)ti)->ip_ttl = MAXTTL; 98 ip_output(m); 99 } 100