# #include "util.h" #include "pkts.h" #include "buf.h" #include /* inet_init store away constant inet info in tcb and tcb send pkt. Compute max tcp segment (data) size we will accept. */ inet_init(ptcb, fhost) struct tcb *ptcb; long fhost; { register struct inet_hdr *inp; register struct tcp_phdr *phd; struct maxdata { long md_fhost; short md_maxfrag; } maxdata; register struct maxdata *mdp; inp = &ptcb->t_inet; inp->ip_ihlver = IP_VERHL; inp->ip_tsrv = IP_TSRV; inp->ip_frag = 0; inp->ip_time = IP_TIME; inp->ip_prot = TCPPROT; inp->ip_src = mymach; inp->ip_dest = fhost; phd = &ptcb->t_phdr; phd->pt_src = mymach; phd->pt_dest = fhost; phd->pt_zero = 0; phd->pt_prot = TCPPROT; mdp = &maxdata; mdp->md_fhost = fhost; mdp->md_maxfrag = 0; ioctl(net, NIONWRITE, mdp); mdp->md_maxfrag -= (IPHSIZ + TCPHSIZ); ptcb->t_maxdata = (mdp->md_maxfrag < MAXDATA) ? mdp->md_maxfrag:MAXDATA; ptcb->t_maxsdata = ptcb->t_maxdata; if (ptcb->t_maxdata < 5) { logerr("inet_init data size too small %d fhost %X\n", ptcb->t_maxdata, fhost); return(FALSE); } return(TRUE); } ch_inet(ptcb, ppkt) struct tcb *ptcb; register struct rcvpkt *ppkt; { register struct inet_hdr *inp; inp = &ppkt->rp_inet; if ( (((inp->ip_ihlver & 017) << 2) > ppkt->rp_len) || (inp->ip_len < IPHSIZ) || (inp->ip_len > ppkt->rp_len) ) { logerr("ch_inet bad rcvpkt or inet length %d %d\n", ppkt->rp_len, inp->ip_len); return(FALSE); } if ((inp->ip_prot != TCPPROT) || (inp->ip_src != ptcb->t_inet.ip_dest) || (inp->ip_dest != mymach)) { logerr("ch_inet bad protocol, src host,or dest host %d %X %X\n", inp->ip_prot, inp->ip_src, inp->ip_dest); return(FALSE); } return(TRUE); } ch_security(ptcb, inp) struct tcb *ptcb; register struct inet_hdr *inp; { register char *ipo, *ipoe; short *security, *compart; short iphlen; if ((inp->ip_tsrv & 0340) != 0) { logerr("ch_security bad precedence fhost %X\n", inp->ip_src); return(FALSE); } iphlen = (inp->ip_ihlver & 017) << 2; if (iphlen <= IPHSIZ) return(TRUE); ipo = (char *) inp + IPHSIZ; ipoe = (char *) inp + iphlen; while (ipo < ipoe) { switch(*ipo) { case 0: return(TRUE); case 1: ipo++; break; default: if (*ipo == IPOPT_SECURITY) { security = ipo + 2; compart = ipo + 4; if (*security || *compart) { logerr("ch_security bad security fhost %X\n", inp->ip_src); return(FALSE); } return(TRUE); } ipo += (*(ipo + 1)); break; } } return(TRUE); }