diff options
Diffstat (limited to 'sys/netiso/tp_inet.c')
-rw-r--r-- | sys/netiso/tp_inet.c | 465 |
1 files changed, 267 insertions, 198 deletions
diff --git a/sys/netiso/tp_inet.c b/sys/netiso/tp_inet.c index 943d2da72e0..60f53d36954 100644 --- a/sys/netiso/tp_inet.c +++ b/sys/netiso/tp_inet.c @@ -1,4 +1,5 @@ -/* $NetBSD: tp_inet.c,v 1.9 1995/08/12 23:59:48 mycroft Exp $ */ +/* $OpenBSD: tp_inet.c,v 1.2 1996/03/04 10:36:00 mickey Exp $ */ +/* $NetBSD: tp_inet.c,v 1.10 1996/02/13 22:11:02 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -40,13 +41,13 @@ All Rights Reserved -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in +both that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not be used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. +software without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL @@ -61,23 +62,19 @@ SOFTWARE. /* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison */ -/* - * Here is where you find the inet-dependent code. We've tried - * keep all net-level and (primarily) address-family-dependent stuff - * out of the tp source, and everthing here is reached indirectly - * through a switch table (struct nl_protosw *) tpcb->tp_nlproto - * (see tp_pcb.c). - * The routines here are: - * in_getsufx: gets transport suffix out of an inpcb structure. - * in_putsufx: put transport suffix into an inpcb structure. - * in_putnetaddr: put a whole net addr into an inpcb. - * in_getnetaddr: get a whole net addr from an inpcb. - * in_cmpnetaddr: compare a whole net addr from an isopcb. - * in_recycle_suffix: clear suffix for reuse in inpcb - * tpip_mtu: figure out what size tpdu to use - * tpip_input: take a pkt from ip, strip off its ip header, give to tp - * tpip_output_dg: package a pkt for ip given 2 addresses & some data - * tpip_output: package a pkt for ip given an inpcb & some data +/* + * Here is where you find the inet-dependent code. We've tried keep all + * net-level and (primarily) address-family-dependent stuff out of the tp + * source, and everthing here is reached indirectly through a switch table + * (struct nl_protosw *) tpcb->tp_nlproto (see tp_pcb.c). The routines here + * are: in_getsufx: gets transport suffix out of an inpcb structure. + * in_putsufx: put transport suffix into an inpcb structure. in_putnetaddr: + * put a whole net addr into an inpcb. in_getnetaddr: get a whole net addr + * from an inpcb. in_cmpnetaddr: compare a whole net addr from an isopcb. + * in_recycle_suffix: clear suffix for reuse in inpcb tpip_mtu: figure out + * what size tpdu to use tpip_input: take a pkt from ip, strip off its ip + * header, give to tp tpip_output_dg: package a pkt for ip given 2 addresses + * & some data tpip_output: package a pkt for ip given an inpcb & some data */ #ifdef INET @@ -88,6 +85,7 @@ SOFTWARE. #include <sys/mbuf.h> #include <sys/errno.h> #include <sys/time.h> +#include <sys/systm.h> #include <net/if.h> @@ -99,17 +97,20 @@ SOFTWARE. #include <netiso/tp_trace.h> #include <netiso/tp_stat.h> #include <netiso/tp_tpdu.h> +#include <netiso/tp_var.h> #include <netinet/in_var.h> #ifndef ISO #include <netiso/iso_chksum.c> #endif -/* - * NAME: in_getsufx() +#include <machine/stdarg.h> - * CALLED FROM: pr_usrreq() on PRU_BIND, - * PRU_CONNECT, PRU_ACCEPT, and PRU_PEERADDR +/* + * NAME: in_getsufx() + * + * CALLED FROM: pr_usrreq() on PRU_BIND, + * PRU_CONNECT, PRU_ACCEPT, and PRU_PEERADDR * * FUNCTION, ARGUMENTS, and RETURN VALUE: * Get a transport suffix from an inpcb structure (inp). @@ -118,78 +119,83 @@ SOFTWARE. * RETURNS: internet port / transport suffix * (CAST TO AN INT) * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ -in_getsufx(inp, lenp, data_out, which) - struct inpcb *inp; - u_short *lenp; - caddr_t data_out; - int which; +void +in_getsufx(v, lenp, data_out, which) + void *v; + u_short *lenp; + caddr_t data_out; + int which; { + struct inpcb *inp = v; *lenp = sizeof(u_short); switch (which) { case TP_LOCAL: - *(u_short *)data_out = inp->inp_lport; + *(u_short *) data_out = inp->inp_lport; return; case TP_FOREIGN: - *(u_short *)data_out = inp->inp_fport; + *(u_short *) data_out = inp->inp_fport; } } /* - * NAME: in_putsufx() + * NAME: in_putsufx() * - * CALLED FROM: tp_newsocket(); i.e., when a connection + * CALLED FROM: tp_newsocket(); i.e., when a connection * is being established by an incoming CR_TPDU. * * FUNCTION, ARGUMENTS: * Put a transport suffix (found in name) into an inpcb structure (inp). * The argument (which) takes the value TP_LOCAL or TP_FOREIGN. * - * RETURNS: Nada + * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ -/*ARGSUSED*/ +/* ARGSUSED */ void -in_putsufx(inp, sufxloc, sufxlen, which) - struct inpcb *inp; - caddr_t sufxloc; - int which; +in_putsufx(v, sufxloc, sufxlen, which) + void *v; + caddr_t sufxloc; + int sufxlen; + int which; { + struct inpcb *inp = v; if (which == TP_FOREIGN) { - bcopy(sufxloc, (caddr_t)&inp->inp_fport, sizeof(inp->inp_fport)); + bcopy(sufxloc, (caddr_t) & inp->inp_fport, sizeof(inp->inp_fport)); } } /* - * NAME: in_recycle_tsuffix() + * NAME: in_recycle_tsuffix() * * CALLED FROM: tp.trans whenever we go into REFWAIT state. * * FUNCTION and ARGUMENT: - * Called when a ref is frozen, to allow the suffix to be reused. - * (inp) is the net level pcb. + * Called when a ref is frozen, to allow the suffix to be reused. + * (inp) is the net level pcb. * * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: This really shouldn't have to be done in a NET level pcb + * NOTES: This really shouldn't have to be done in a NET level pcb * but... for the internet world that just the way it is done in BSD... * The alternative is to have the port unusable until the reference * timer goes off. */ void -in_recycle_tsuffix(inp) - struct inpcb *inp; +in_recycle_tsuffix(v) + void *v; { + struct inpcb *inp = v; inp->inp_fport = inp->inp_lport = 0; } @@ -207,33 +213,35 @@ in_recycle_tsuffix(inp) * * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: - */ + * NOTES: + */ void -in_putnetaddr(inp, name, which) - register struct inpcb *inp; - struct sockaddr_in *name; - int which; +in_putnetaddr(v, nm, which) + register void *v; + struct sockaddr *nm; + int which; { + register struct inpcb *inp = v; + struct sockaddr_in *name = (struct sockaddr_in *) nm; switch (which) { case TP_LOCAL: - bcopy((caddr_t)&name->sin_addr, - (caddr_t)&inp->inp_laddr, sizeof(struct in_addr)); - /* won't work if the dst address (name) is INADDR_ANY */ + bcopy((caddr_t) & name->sin_addr, + (caddr_t) & inp->inp_laddr, sizeof(struct in_addr)); + /* won't work if the dst address (name) is INADDR_ANY */ break; case TP_FOREIGN: - if( name != (struct sockaddr_in *)0 ) { - bcopy((caddr_t)&name->sin_addr, - (caddr_t)&inp->inp_faddr, sizeof(struct in_addr)); + if (name != (struct sockaddr_in *) 0) { + bcopy((caddr_t) & name->sin_addr, + (caddr_t) & inp->inp_faddr, sizeof(struct in_addr)); } } } /* - * NAME: in_putnetaddr() + * NAME: in_cmpnetaddr() * * CALLED FROM: * tp_input() when a connection is being established by an @@ -246,15 +254,18 @@ in_putnetaddr(inp, name, which) * * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: - */ -in_cmpnetaddr(inp, name, which) - register struct inpcb *inp; - register struct sockaddr_in *name; - int which; + * NOTES: + */ +int +in_cmpnetaddr(v, nm, which) + register void *v; + register struct sockaddr *nm; + int which; { + register struct inpcb *inp = v; + struct sockaddr_in *name = (struct sockaddr_in *) nm; if (which == TP_LOCAL) { if (name->sin_port && name->sin_port != inp->inp_lport) return 0; @@ -277,19 +288,20 @@ in_cmpnetaddr(inp, name, which) * * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: - */ + * NOTES: + */ void -in_getnetaddr( inp, name, which) +in_getnetaddr(v, name, which) + void *v; register struct mbuf *name; - struct inpcb *inp; - int which; + int which; { + struct inpcb *inp = v; register struct sockaddr_in *sin = mtod(name, struct sockaddr_in *); - bzero((caddr_t)sin, sizeof(*sin)); + bzero((caddr_t) sin, sizeof(*sin)); switch (which) { case TP_LOCAL: sin->sin_addr = inp->inp_laddr; @@ -302,7 +314,7 @@ in_getnetaddr( inp, name, which) default: return; } - name->m_len = sin->sin_len = sizeof (*sin); + name->m_len = sin->sin_len = sizeof(*sin); sin->sin_family = AF_INET; } @@ -318,24 +330,27 @@ in_getnetaddr( inp, name, which) * It appears that setting a double pointer to the rtentry associated with * the destination, and returning the header size for the network protocol * suffices. - * + * * SIDE EFFECTS: * Sets tp_routep pointer in pcb. * * NOTES: */ - -tpip_mtu(tpcb) -register struct tp_pcb *tpcb; +int +tpip_mtu(v) + void *v; { - struct inpcb *inp = (struct inpcb *)tpcb->tp_npcb; + register struct tp_pcb *tpcb = v; + struct inpcb *inp = (struct inpcb *) tpcb->tp_npcb; - IFDEBUG(D_CONN) +#ifdef ARGO_DEBUG + if (argo_debug[D_CONN]) { printf("tpip_mtu(tpcb)\n", tpcb); printf("tpip_mtu routing to addr 0x%x\n", inp->inp_faddr.s_addr); - ENDDEBUG + } +#endif tpcb->tp_routep = &(inp->inp_route.ro_rt); - return (sizeof (struct ip)); + return (sizeof(struct ip)); } @@ -350,23 +365,36 @@ register struct tp_pcb *tpcb; * of the fields. * inp is the inpcb structure; datalen is the length of the data in the * mbuf string m0. - * RETURNS: + * RETURNS: * whatever (E*) is returned form the net layer output routine. * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ int -tpip_output(inp, m0, datalen, nochksum) - struct inpcb *inp; - struct mbuf *m0; - int datalen; - int nochksum; +#if __STDC__ +tpip_output(struct mbuf *m0, ...) +#else +tpip_output(m0, va_alist) + struct mbuf *m0; + va_dcl +#endif { - return tpip_output_dg( &inp->inp_laddr, &inp->inp_faddr, m0, datalen, - &inp->inp_route, nochksum); + int datalen; + struct inpcb *inp; + int nochksum; + va_list ap; + + va_start(ap, m0); + datalen = va_arg(ap, int); + inp = va_arg(ap, struct inpcb *); + nochksum = va_arg(ap, int); + va_end(ap); + + return tpip_output_dg(m0, datalen, &inp->inp_laddr, &inp->inp_faddr, + &inp->inp_route, nochksum); } /* @@ -379,30 +407,46 @@ tpip_output(inp, m0, datalen, nochksum) * instead of a pcb. It's used by the tp_error_emit, when we * don't have an in_pcb with which to call the normal output rtn. * - * RETURNS: ENOBUFS or whatever (E*) is + * RETURNS: ENOBUFS or whatever (E*) is * returned form the net layer output routine. * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ -/*ARGSUSED*/ +/* ARGSUSED */ int -tpip_output_dg(laddr, faddr, m0, datalen, ro, nochksum) - struct in_addr *laddr, *faddr; - struct mbuf *m0; - int datalen; - struct route *ro; - int nochksum; +#if __STDC__ +tpip_output_dg(struct mbuf *m0, ...) +#else +tpip_output_dg(m0, va_alist) + struct mbuf *m0; + va_dcl +#endif { - register struct mbuf *m; + int datalen; + struct in_addr *laddr, *faddr; + struct route *ro; + int nochksum; + register struct mbuf *m; register struct ip *ip; - int error; + int error; + va_list ap; - IFDEBUG(D_EMIT) + va_start(ap, m0); + datalen = va_arg(ap, int); + laddr = va_arg(ap, struct in_addr *); + faddr = va_arg(ap, struct in_addr *); + ro = va_arg(ap, struct route *); + nochksum = va_arg(ap, int); + va_end(ap); + +#ifdef ARGO_DEBUG + if (argo_debug[D_EMIT]) { printf("tpip_output_dg datalen 0x%x m0 0x%x\n", datalen, m0); - ENDDEBUG + } +#endif MGETHDR(m, M_DONTWAIT, TPMT_IPHDR); @@ -415,28 +459,33 @@ tpip_output_dg(laddr, faddr, m0, datalen, ro, nochksum) m->m_len = sizeof(struct ip); ip = mtod(m, struct ip *); - bzero((caddr_t)ip, sizeof *ip); + bzero((caddr_t) ip, sizeof *ip); ip->ip_p = IPPROTO_TP; m->m_pkthdr.len = ip->ip_len = sizeof(struct ip) + datalen; - ip->ip_ttl = MAXTTL; - /* don't know why you need to set ttl; - * overlay doesn't even make this available - */ + ip->ip_ttl = MAXTTL; + /* + * don't know why you need to set ttl; overlay doesn't even make this + * available + */ ip->ip_src = *laddr; ip->ip_dst = *faddr; IncStat(ts_tpdu_sent); - IFDEBUG(D_EMIT) +#ifdef ARGO_DEBUG + if (argo_debug[D_EMIT]) { dump_mbuf(m, "tpip_output_dg before ip_output\n"); - ENDDEBUG + } +#endif - error = ip_output(m, (struct mbuf *)0, ro, IP_ALLOWBROADCAST, NULL); + error = ip_output(m, (struct mbuf *) 0, ro, IP_ALLOWBROADCAST, NULL); - IFDEBUG(D_EMIT) +#ifdef ARGO_DEBUG + if (argo_debug[D_EMIT]) { printf("tpip_output_dg after ip_output\n"); - ENDDEBUG + } +#endif return error; @@ -455,20 +504,30 @@ bad: * FUNCTION and ARGUMENTS: * Take a packet (m) from ip, strip off the ip header and give it to tp * - * RETURNS: No return value. - * + * RETURNS: No return value. + * * SIDE EFFECTS: * * NOTES: */ void -tpip_input(m, iplen) - struct mbuf *m; - int iplen; +#if __STDC__ +tpip_input(struct mbuf *m, ...) +#else +tpip_input(m, va_alist) + struct mbuf *m; + va_dcl +#endif { - struct sockaddr_in src, dst; - register struct ip *ip; - int s = splsoftnet(), hdrlen; + int iplen; + struct sockaddr_in src, dst; + register struct ip *ip; + int s = splsoftnet(), hdrlen; + va_list ap; + + va_start(ap, m); + iplen = va_arg(ap, int); + va_end(ap); IncStat(ts_pkt_rcvd); @@ -482,10 +541,10 @@ tpip_input(m, iplen) */ - if((m = m_pullup(m, iplen + 1)) == MNULL) + if ((m = m_pullup(m, iplen + 1)) == MNULL) goto discard; CHANGE_MTYPE(m, TPMT_DATA); - + /* * Now pull up the whole tp header: * Unfortunately, there may be IP options to skip past so we @@ -493,23 +552,27 @@ tpip_input(m, iplen) */ hdrlen = iplen + 1 + mtod(m, u_char *)[iplen]; - if( m->m_len < hdrlen ) { - if((m = m_pullup(m, hdrlen)) == MNULL){ - IFDEBUG(D_TPINPUT) + if (m->m_len < hdrlen) { + if ((m = m_pullup(m, hdrlen)) == MNULL) { +#ifdef ARGO_DEBUG + if (argo_debug[D_TPINPUT]) { printf("tp_input, pullup 2!\n"); - ENDDEBUG + } +#endif goto discard; } } - /* - * cannot use tp_inputprep() here 'cause you don't - * have quite the same situation + /* + * cannot use tp_inputprep() here 'cause you don't have quite the + * same situation */ - IFDEBUG(D_TPINPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_TPINPUT]) { dump_mbuf(m, "after tpip_input both pullups"); - ENDDEBUG - /* + } +#endif + /* * m_pullup may have returned a different mbuf */ ip = mtod(m, struct ip *); @@ -521,24 +584,28 @@ tpip_input(m, iplen) m->m_len -= iplen; m->m_data += iplen; - src.sin_addr = *(struct in_addr *)&(ip->ip_src); - src.sin_family = AF_INET; - src.sin_len = sizeof(src); - dst.sin_addr = *(struct in_addr *)&(ip->ip_dst); - dst.sin_family = AF_INET; - dst.sin_len = sizeof(dst); + src.sin_addr = *(struct in_addr *) & (ip->ip_src); + src.sin_family = AF_INET; + src.sin_len = sizeof(src); + dst.sin_addr = *(struct in_addr *) & (ip->ip_dst); + dst.sin_family = AF_INET; + dst.sin_len = sizeof(dst); tp_input(m, sintosa(&src), sintosa(&dst), 0, tpip_output_dg, 0); return; discard: - IFDEBUG(D_TPINPUT) +#ifdef ARGO_DEBUG + if (argo_debug[D_TPINPUT]) { printf("tpip_input DISCARD\n"); - ENDDEBUG - IFTRACE(D_TPINPUT) - tptrace(TPPTmisc, "tpip_input DISCARD m", m,0,0,0); - ENDTRACE - m_freem(m); + } +#endif +#ifdef TPPT + if (tp_traceflags[D_TPINPUT]) { + tptrace(TPPTmisc, "tpip_input DISCARD m", m, 0, 0, 0); + } +#endif + m_freem(m); IncStat(ts_recv_drop); splx(s); } @@ -547,7 +614,6 @@ discard: #include <sys/protosw.h> #include <netinet/ip_icmp.h> -extern void tp_quench(); /* * NAME: tpin_quench() * @@ -557,16 +623,17 @@ extern void tp_quench(); * * RETURNS: Nada * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ void -tpin_quench(inp) - struct inpcb *inp; +tpin_quench(inp, dummy) + struct inpcb *inp; + int dummy; { - tp_quench((struct tp_pcb *)inp->inp_socket->so_pcb, PRC_QUENCH); + tp_quench((struct inpcb *) inp->inp_socket->so_pcb, PRC_QUENCH); } /* @@ -580,48 +647,48 @@ tpin_quench(inp) * It either returns an error status to the user or * causes all connections on this address to be aborted * by calling the appropriate xx_notify() routine. - * (cmd) is the type of ICMP error. + * (cmd) is the type of ICMP error. * (sa) the address of the sender * * RETURNS: Nothing * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ -void -tpip_ctlinput(cmd, sin) - int cmd; - struct sockaddr_in *sin; +void * +tpip_ctlinput(cmd, sa, dummy) + int cmd; + struct sockaddr *sa; + void *dummy; { - extern int inetctlerrmap[]; - void (*notify) __P((struct inpcb *, int)); - void tp_quench __P((struct inpcb *, int)); - void tpin_abort __P((struct inpcb *, int)); - int errno; + struct sockaddr_in *sin = (struct sockaddr_in *) sa; + extern int inetctlerrmap[]; + void (*notify) __P((struct inpcb *, int)); + int errno; if (cmd < 0 || cmd >= PRC_NCMDS) - return; + return NULL; if (sin->sin_family != AF_INET && sin->sin_family != AF_IMPLINK) - return; + return NULL; if (sin->sin_addr.s_addr == INADDR_ANY) - return; + return NULL; errno = inetctlerrmap[cmd]; switch (cmd) { - case PRC_QUENCH: - notify = tp_quench; - break; + case PRC_QUENCH: + notify = tp_quench; + break; - case PRC_ROUTEDEAD: - case PRC_HOSTUNREACH: - case PRC_UNREACH_NET: - case PRC_IFDOWN: - case PRC_HOSTDEAD: - notify = in_rtchange; - break; + case PRC_ROUTEDEAD: + case PRC_HOSTUNREACH: + case PRC_UNREACH_NET: + case PRC_IFDOWN: + case PRC_HOSTDEAD: + notify = in_rtchange; + break; - default: + default: /* case PRC_MSGSIZE: case PRC_UNREACH_HOST: @@ -637,10 +704,11 @@ tpip_ctlinput(cmd, sin) case PRC_TIMXCEED_REASS: case PRC_PARAMPROB: */ - notify = tpin_abort; - break; + notify = tpin_abort; + break; } in_pcbnotifyall(&tp_inpcb, sintosa(sin), errno, notify); + return NULL; } /* @@ -657,28 +725,29 @@ tpip_ctlinput(cmd, sin) * * RETURNS: Nothing * - * SIDE EFFECTS: + * SIDE EFFECTS: * - * NOTES: + * NOTES: */ void tpin_abort(inp, n) - struct inpcb *inp; - int n; + struct inpcb *inp; + int n; { struct tp_event e; e.ev_number = ER_TPDU; - e.ATTR(ER_TPDU).e_reason = ENETRESET; - tp_driver((struct tp_pcb *)inp->inp_ppcb, &e); + e.TPDU_ATTR(ER).e_reason = ENETRESET; + tp_driver((struct tp_pcb *) inp->inp_ppcb, &e); } #ifdef ARGO_DEBUG +void dump_inaddr(addr) register struct sockaddr_in *addr; { printf("INET: port 0x%x; addr 0x%x\n", addr->sin_port, addr->sin_addr); } -#endif /* ARGO_DEBUG */ -#endif /* INET */ +#endif /* ARGO_DEBUG */ +#endif /* INET */ |