* Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* @(#)ns_pcb.c 7.5 (Berkeley) 6/29/88
#include "../net/route.h"
struct ns_addr zerons_addr
;
register struct nspcb
*nsp
;
m
= m_getclr(M_DONTWAIT
, MT_PCB
);
nsp
= mtod(m
, struct nspcb
*);
so
->so_pcb
= (caddr_t
)nsp
;
register struct nspcb
*nsp
;
register struct sockaddr_ns
*sns
;
if(nsp
->nsp_lport
|| !ns_nullhost(nsp
->nsp_laddr
))
sns
= mtod(nam
, struct sockaddr_ns
*);
if (nam
->m_len
!= sizeof (*sns
))
if (!ns_nullhost(sns
->sns_addr
)) {
int tport
= sns
->sns_port
;
sns
->sns_port
= 0; /* yech... */
if (ifa_ifwithaddr((struct sockaddr
*)sns
) == 0)
u_short aport
= ntohs(lport
);
if (aport
< NSPORT_RESERVED
&& u
.u_uid
!= 0)
if (ns_pcblookup(&zerons_addr
, lport
, 0))
nsp
->nsp_laddr
= sns
->sns_addr
;
if (nspcb
.nsp_lport
++ < NSPORT_RESERVED
)
nspcb
.nsp_lport
= NSPORT_RESERVED
;
lport
= htons(nspcb
.nsp_lport
);
} while (ns_pcblookup(&zerons_addr
, lport
, 0));
* Connect from a socket to a specified address.
* Both address and port must be specified in argument sns.
* If don't have a local address for this socket yet,
register struct sockaddr_ns
*sns
= mtod(nam
, struct sockaddr_ns
*);
register struct ns_addr
*dst
;
if (nam
->m_len
!= sizeof (*sns
))
if (sns
->sns_family
!= AF_NS
)
if (sns
->sns_port
==0 || ns_nullhost(sns
->sns_addr
))
if (ns_nullhost(nsp
->nsp_laddr
)) {
register struct route
*ro
;
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
dst
= &satons_addr(ro
->ro_dst
);
ia
= (struct ns_ifaddr
*)0;
if ((!ns_neteq(nsp
->nsp_lastdst
, sns
->sns_addr
)) ||
((ifp
= ro
->ro_rt
->rt_ifp
) &&
(ifp
->if_flags
& IFF_POINTOPOINT
) &&
(!ns_hosteq(nsp
->nsp_lastdst
, sns
->sns_addr
))) ||
(nsp
->nsp_socket
->so_options
& SO_DONTROUTE
)) {
ro
->ro_rt
= (struct rtentry
*)0;
if ((nsp
->nsp_socket
->so_options
& SO_DONTROUTE
) == 0 && /*XXX*/
(ro
->ro_rt
== (struct rtentry
*)0 ||
ro
->ro_rt
->rt_ifp
== (struct ifnet
*)0)) {
/* No route yet, so try to acquire one */
ro
->ro_dst
.sa_family
= AF_NS
;
* If we found a route, use the address
* corresponding to the outgoing interface
if (ro
->ro_rt
&& (ifp
= ro
->ro_rt
->rt_ifp
))
for (ia
= ns_ifaddr
; ia
; ia
= ia
->ia_next
)
u_short fport
= sns
->sns_addr
.x_port
;
sns
->sns_addr
.x_port
= 0;
ia
= (struct ns_ifaddr
*)
ifa_ifwithdstaddr((struct sockaddr
*)sns
);
sns
->sns_addr
.x_port
= fport
;
ia
= ns_iaonnetof(&sns
->sns_addr
);
nsp
->nsp_laddr
.x_net
= satons_addr(ia
->ia_addr
).x_net
;
nsp
->nsp_lastdst
= sns
->sns_addr
;
if (ns_pcblookup(&sns
->sns_addr
, nsp
->nsp_lport
, 0))
if (ns_nullhost(nsp
->nsp_laddr
)) {
(void) ns_pcbbind(nsp
, (struct mbuf
*)0);
nsp
->nsp_laddr
.x_host
= ns_thishost
;
nsp
->nsp_faddr
= sns
->sns_addr
;
/* Includes nsp->nsp_fport = sns->sns_port; */
nsp
->nsp_faddr
= zerons_addr
;
if (nsp
->nsp_socket
->so_state
& SS_NOFDREF
)
struct socket
*so
= nsp
->nsp_socket
;
if (nsp
->nsp_route
.ro_rt
)
rtfree(nsp
->nsp_route
.ro_rt
);
(void) m_free(dtom(nsp
));
register struct nspcb
*nsp
;
register struct sockaddr_ns
*sns
= mtod(nam
, struct sockaddr_ns
*);
nam
->m_len
= sizeof (*sns
);
sns
= mtod(nam
, struct sockaddr_ns
*);
bzero((caddr_t
)sns
, sizeof (*sns
));
sns
->sns_addr
= nsp
->nsp_laddr
;
register struct nspcb
*nsp
;
register struct sockaddr_ns
*sns
= mtod(nam
, struct sockaddr_ns
*);
nam
->m_len
= sizeof (*sns
);
sns
= mtod(nam
, struct sockaddr_ns
*);
bzero((caddr_t
)sns
, sizeof (*sns
));
sns
->sns_addr
= nsp
->nsp_faddr
;
* Pass some notification to all connections of a protocol
* associated with address dst. Call the
* protocol specific routine to handle each connection.
* Also pass an extra paramter via the nspcb. (which may in fact
ns_pcbnotify(dst
, errno
, notify
, param
)
register struct ns_addr
*dst
;
register struct nspcb
*nsp
, *oinp
;
for (nsp
= (&nspcb
)->nsp_next
; nsp
!= (&nspcb
);) {
if (!ns_hosteq(*dst
,nsp
->nsp_faddr
)) {
if (nsp
->nsp_socket
== 0)
nsp
->nsp_socket
->so_error
= errno
;
oinp
->nsp_notify_param
= param
;
* After a routing change, flush old routing
* and allocate a (hopefully) better one.
if (nsp
->nsp_route
.ro_rt
) {
rtfree(nsp
->nsp_route
.ro_rt
);
nsp
->nsp_route
.ro_rt
= 0;
* A new route can be allocated the next time
/* SHOULD NOTIFY HIGHER-LEVEL PROTOCOLS */
ns_pcblookup(faddr
, lport
, wildp
)
register struct nspcb
*nsp
, *match
= 0;
int matchwild
= 3, wildcard
;
for (nsp
= (&nspcb
)->nsp_next
; nsp
!= (&nspcb
); nsp
= nsp
->nsp_next
) {
if (nsp
->nsp_lport
!= lport
)
if (ns_nullhost(nsp
->nsp_faddr
)) {
if (!ns_nullhost(*faddr
))
if (!ns_hosteq(nsp
->nsp_faddr
, *faddr
))
if( nsp
->nsp_fport
!= fport
) {
if (wildcard
&& wildp
==0)
if (wildcard
< matchwild
) {