# #include "../h/param.h" #include "../h/pkts.h" #include "../h/net.h" inn_dispatch( rp ) struct rcvpkt *rp; { register struct inet_hdr *inp; register short ipprot; register char *pp; register struct dgm_hdr *dgp; register struct tcp_hdr *tcp; register struct netino *nip; inp = &rp->rp_inet; if ((ipprot = inp->ip_prot) == NULL) return(FALSE); switch(ipprot) { case TCPPROT: pp = inp; pp += ((inp->ip_ihlver & 017) << 2); tcp = pp; nip = tcp_match(ipprot, inp->ip_src, swab(tcp->tcp_sskt), swab(tcp->tcp_dskt)); break; case DGPROT: pp = inp; pp += ((inp->ip_ihlver & 017) << 2); dgp = pp; nip = inn_plmatch(ipprot, swab(dgp->dg_dskt)); break; default: nip = inn_pmatch(ipprot); break; } if (nip == NULL) { neterrt(EIPMATCH); return(FALSE); } rp->rp_inode = nip; return(TRUE); } /* inn_pmatch search net inode list * for protocol match w. incoming pkt */ struct netino *inn_pmatch(prot) register short prot; { register struct netino *nip; for (nip = neti_que.q_head; nip != NULL; nip = nip->nt_forw) if (prot == nip->nt_prot) break; return(nip); } /* inn_plmatch search net inodes * for protocol match w. incoming pkt. * Also try to match local skts, but * if can't, match w. net inode wh. * has NULL local skt. */ struct netino *inn_plmatch(prot, lskt) register short prot, lskt; { register struct netino *nip, *nipsv; nipsv = NULL; for (nip = neti_que.q_head; nip != NULL; nip = nip->nt_forw) if (prot == nip->nt_prot) { if (nip->nt_lskt == NULL) nipsv = nip; else if (lskt == nip->nt_lskt) { nipsv = nip; break; } } return(nipsv); } /* tcp_match search net inodes for * tcp protocol match w. incoming pkt. * Protocol and local skt must match * Foreign host/foreign skt might also * match and, if so, provide a better * match than only protocol and lskt * match */ struct netino *tcp_match(prot, fhost, fskt, lskt) register short prot; long fhost; short fskt, lskt; { register struct netino *nip, *nipsv; if (lskt == NULL) return(NULL); nipsv = NULL; for (nip = neti_que.q_head; nip != NULL; nip = nip->nt_forw) { if ((prot == nip->nt_prot) && (lskt == nip->nt_lskt)) { if (nip->nt_fhost.nt_lhost == NULL) nipsv = nip; else if ((fhost == nip->nt_fhost.nt_lhost) && (fskt == nip->nt_fskt)) { nipsv = nip; break; } } } return(nipsv); }