ipx_pcb.c (25345) | ipx_pcb.c (25652) |
---|---|
1/* 2 * Copyright (c) 1995, Mike Mitchell 3 * Copyright (c) 1984, 1985, 1986, 1987, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 19 unchanged lines hidden (view full) --- 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)ipx_pcb.c 35 * | 1/* 2 * Copyright (c) 1995, Mike Mitchell 3 * Copyright (c) 1984, 1985, 1986, 1987, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 19 unchanged lines hidden (view full) --- 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)ipx_pcb.c 35 * |
36 * $Id: ipx_pcb.c,v 1.7 1997/02/22 09:41:56 peter Exp $ | 36 * $Id: ipx_pcb.c,v 1.8 1997/05/01 06:21:29 jhay Exp $ |
37 */ 38 39#include <sys/param.h> 40#include <sys/queue.h> 41#include <sys/systm.h> 42#include <sys/mbuf.h> 43#include <sys/proc.h> 44#include <sys/protosw.h> 45#include <sys/errno.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48 49#include <net/if.h> 50#include <net/route.h> 51 52#include <netipx/ipx.h> 53#include <netipx/ipx_if.h> 54#include <netipx/ipx_pcb.h> | 37 */ 38 39#include <sys/param.h> 40#include <sys/queue.h> 41#include <sys/systm.h> 42#include <sys/mbuf.h> 43#include <sys/proc.h> 44#include <sys/protosw.h> 45#include <sys/errno.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48 49#include <net/if.h> 50#include <net/route.h> 51 52#include <netipx/ipx.h> 53#include <netipx/ipx_if.h> 54#include <netipx/ipx_pcb.h> |
55#include <netipx/ipx_var.h> |
|
55 56struct ipx_addr zeroipx_addr; 57 58int 59ipx_pcballoc(so, head, p) 60 struct socket *so; 61 struct ipxpcb *head; 62 struct proc *p; --- 17 unchanged lines hidden (view full) --- 80 struct mbuf *nam; 81 struct proc *p; 82{ 83 register struct sockaddr_ipx *sipx; 84 u_short lport = 0; 85 86 if (ipxp->ipxp_lport || !ipx_nullhost(ipxp->ipxp_laddr)) 87 return (EINVAL); | 56 57struct ipx_addr zeroipx_addr; 58 59int 60ipx_pcballoc(so, head, p) 61 struct socket *so; 62 struct ipxpcb *head; 63 struct proc *p; --- 17 unchanged lines hidden (view full) --- 81 struct mbuf *nam; 82 struct proc *p; 83{ 84 register struct sockaddr_ipx *sipx; 85 u_short lport = 0; 86 87 if (ipxp->ipxp_lport || !ipx_nullhost(ipxp->ipxp_laddr)) 88 return (EINVAL); |
88 if (nam == 0) | 89 if (nam == NULL) |
89 goto noname; 90 sipx = mtod(nam, struct sockaddr_ipx *); | 90 goto noname; 91 sipx = mtod(nam, struct sockaddr_ipx *); |
91 if (nam->m_len != sizeof (*sipx)) | 92 if (nam->m_len != sizeof(*sipx)) |
92 return (EINVAL); 93 if (!ipx_nullhost(sipx->sipx_addr)) { 94 int tport = sipx->sipx_port; 95 96 sipx->sipx_port = 0; /* yech... */ 97 if (ifa_ifwithaddr((struct sockaddr *)sipx) == 0) 98 return (EADDRNOTAVAIL); 99 sipx->sipx_port = tport; 100 } 101 lport = sipx->sipx_port; 102 if (lport) { 103 u_short aport = ntohs(lport); 104 int error; 105 | 93 return (EINVAL); 94 if (!ipx_nullhost(sipx->sipx_addr)) { 95 int tport = sipx->sipx_port; 96 97 sipx->sipx_port = 0; /* yech... */ 98 if (ifa_ifwithaddr((struct sockaddr *)sipx) == 0) 99 return (EADDRNOTAVAIL); 100 sipx->sipx_port = tport; 101 } 102 lport = sipx->sipx_port; 103 if (lport) { 104 u_short aport = ntohs(lport); 105 int error; 106 |
106 if (aport < IPXPORT_MAX && 107 p && (error = suser(p->p_ucred, &p->p_acflag)) != 0) | 107 if (aport < IPXPORT_RESERVED && 108 p != NULL && (error = suser(p->p_ucred, &p->p_acflag)) != 0) |
108 return (error); 109 if (ipx_pcblookup(&zeroipx_addr, lport, 0)) 110 return (EADDRINUSE); 111 } 112 ipxp->ipxp_laddr = sipx->sipx_addr; 113noname: 114 if (lport == 0) 115 do { | 109 return (error); 110 if (ipx_pcblookup(&zeroipx_addr, lport, 0)) 111 return (EADDRINUSE); 112 } 113 ipxp->ipxp_laddr = sipx->sipx_addr; 114noname: 115 if (lport == 0) 116 do { |
116 if (ipxpcb.ipxp_lport++ < IPXPORT_MAX) 117 ipxpcb.ipxp_lport = IPXPORT_MAX; | 117 ipxpcb.ipxp_lport++; 118 if ((ipxpcb.ipxp_lport < IPXPORT_RESERVED) || 119 (ipxpcb.ipxp_lport >= IPXPORT_WELLKNOWN)) 120 ipxpcb.ipxp_lport = IPXPORT_RESERVED; |
118 lport = htons(ipxpcb.ipxp_lport); 119 } while (ipx_pcblookup(&zeroipx_addr, lport, 0)); 120 ipxp->ipxp_lport = lport; 121 return (0); 122} 123 124/* 125 * Connect from a socket to a specified address. --- 8 unchanged lines hidden (view full) --- 134 struct proc *p; 135{ 136 struct ipx_ifaddr *ia; 137 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 138 register struct ipx_addr *dst; 139 register struct route *ro; 140 struct ifnet *ifp; 141 | 121 lport = htons(ipxpcb.ipxp_lport); 122 } while (ipx_pcblookup(&zeroipx_addr, lport, 0)); 123 ipxp->ipxp_lport = lport; 124 return (0); 125} 126 127/* 128 * Connect from a socket to a specified address. --- 8 unchanged lines hidden (view full) --- 137 struct proc *p; 138{ 139 struct ipx_ifaddr *ia; 140 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 141 register struct ipx_addr *dst; 142 register struct route *ro; 143 struct ifnet *ifp; 144 |
142 if (nam->m_len != sizeof (*sipx)) | 145 ia = NULL; 146 147 if (nam->m_len != sizeof(*sipx)) |
143 return (EINVAL); 144 if (sipx->sipx_family != AF_IPX) 145 return (EAFNOSUPPORT); | 148 return (EINVAL); 149 if (sipx->sipx_family != AF_IPX) 150 return (EAFNOSUPPORT); |
146 if (sipx->sipx_port==0 || ipx_nullhost(sipx->sipx_addr)) | 151 if (sipx->sipx_port == 0 || ipx_nullhost(sipx->sipx_addr)) |
147 return (EADDRNOTAVAIL); 148 /* 149 * If we haven't bound which network number to use as ours, 150 * we will use the number of the outgoing interface. 151 * This depends on having done a routing lookup, which 152 * we will probably have to do anyway, so we might 153 * as well do it now. On the other hand if we are 154 * sending to multiple destinations we may have already --- 4 unchanged lines hidden (view full) --- 159 */ 160 ro = &ipxp->ipxp_route; 161 dst = &satoipx_addr(ro->ro_dst); 162 if (ipxp->ipxp_socket->so_options & SO_DONTROUTE) 163 goto flush; 164 if (!ipx_neteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) 165 goto flush; 166 if (!ipx_hosteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) { | 152 return (EADDRNOTAVAIL); 153 /* 154 * If we haven't bound which network number to use as ours, 155 * we will use the number of the outgoing interface. 156 * This depends on having done a routing lookup, which 157 * we will probably have to do anyway, so we might 158 * as well do it now. On the other hand if we are 159 * sending to multiple destinations we may have already --- 4 unchanged lines hidden (view full) --- 164 */ 165 ro = &ipxp->ipxp_route; 166 dst = &satoipx_addr(ro->ro_dst); 167 if (ipxp->ipxp_socket->so_options & SO_DONTROUTE) 168 goto flush; 169 if (!ipx_neteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) 170 goto flush; 171 if (!ipx_hosteq(ipxp->ipxp_lastdst, sipx->sipx_addr)) { |
167 if (ro->ro_rt && ! (ro->ro_rt->rt_flags & RTF_HOST)) { | 172 if (ro->ro_rt != NULL && !(ro->ro_rt->rt_flags & RTF_HOST)) { |
168 /* can patch route to avoid rtalloc */ 169 *dst = sipx->sipx_addr; 170 } else { 171 flush: | 173 /* can patch route to avoid rtalloc */ 174 *dst = sipx->sipx_addr; 175 } else { 176 flush: |
172 if (ro->ro_rt) | 177 if (ro->ro_rt != NULL) |
173 RTFREE(ro->ro_rt); | 178 RTFREE(ro->ro_rt); |
174 ro->ro_rt = (struct rtentry *)0; | 179 ro->ro_rt = NULL; |
175 ipxp->ipxp_laddr.x_net = ipx_zeronet; 176 } 177 }/* else cached route is ok; do nothing */ 178 ipxp->ipxp_lastdst = sipx->sipx_addr; 179 if ((ipxp->ipxp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/ | 180 ipxp->ipxp_laddr.x_net = ipx_zeronet; 181 } 182 }/* else cached route is ok; do nothing */ 183 ipxp->ipxp_lastdst = sipx->sipx_addr; 184 if ((ipxp->ipxp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/ |
180 (ro->ro_rt == (struct rtentry *)0 || 181 ro->ro_rt->rt_ifp == (struct ifnet *)0)) { | 185 (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL)) { |
182 /* No route yet, so try to acquire one */ 183 ro->ro_dst.sa_family = AF_IPX; 184 ro->ro_dst.sa_len = sizeof(ro->ro_dst); 185 *dst = sipx->sipx_addr; 186 dst->x_port = 0; 187 rtalloc(ro); 188 } 189 if (ipx_neteqnn(ipxp->ipxp_laddr.x_net, ipx_zeronet)) { 190 /* 191 * If route is known or can be allocated now, 192 * our src addr is taken from the i/f, else punt. 193 */ 194 | 186 /* No route yet, so try to acquire one */ 187 ro->ro_dst.sa_family = AF_IPX; 188 ro->ro_dst.sa_len = sizeof(ro->ro_dst); 189 *dst = sipx->sipx_addr; 190 dst->x_port = 0; 191 rtalloc(ro); 192 } 193 if (ipx_neteqnn(ipxp->ipxp_laddr.x_net, ipx_zeronet)) { 194 /* 195 * If route is known or can be allocated now, 196 * our src addr is taken from the i/f, else punt. 197 */ 198 |
195 ia = (struct ipx_ifaddr *)0; | |
196 /* 197 * If we found a route, use the address 198 * corresponding to the outgoing interface 199 */ | 199 /* 200 * If we found a route, use the address 201 * corresponding to the outgoing interface 202 */ |
200 if (ro->ro_rt && (ifp = ro->ro_rt->rt_ifp)) 201 for (ia = ipx_ifaddr; ia; ia = ia->ia_next) | 203 if (ro->ro_rt != NULL && (ifp = ro->ro_rt->rt_ifp) != NULL) 204 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next) |
202 if (ia->ia_ifp == ifp) 203 break; | 205 if (ia->ia_ifp == ifp) 206 break; |
204 if (ia == 0) { | 207 if (ia == NULL) { |
205 u_short fport = sipx->sipx_addr.x_port; 206 sipx->sipx_addr.x_port = 0; 207 ia = (struct ipx_ifaddr *) 208 ifa_ifwithdstaddr((struct sockaddr *)sipx); 209 sipx->sipx_addr.x_port = fport; | 208 u_short fport = sipx->sipx_addr.x_port; 209 sipx->sipx_addr.x_port = 0; 210 ia = (struct ipx_ifaddr *) 211 ifa_ifwithdstaddr((struct sockaddr *)sipx); 212 sipx->sipx_addr.x_port = fport; |
210 if (ia == 0) | 213 if (ia == NULL) |
211 ia = ipx_iaonnetof(&sipx->sipx_addr); | 214 ia = ipx_iaonnetof(&sipx->sipx_addr); |
212 if (ia == 0) | 215 if (ia == NULL) |
213 ia = ipx_ifaddr; | 216 ia = ipx_ifaddr; |
214 if (ia == 0) | 217 if (ia == NULL) |
215 return (EADDRNOTAVAIL); 216 } 217 ipxp->ipxp_laddr.x_net = satoipx_addr(ia->ia_addr).x_net; 218 } | 218 return (EADDRNOTAVAIL); 219 } 220 ipxp->ipxp_laddr.x_net = satoipx_addr(ia->ia_addr).x_net; 221 } |
219 if (ipx_pcblookup(&sipx->sipx_addr, ipxp->ipxp_lport, 0)) 220 return (EADDRINUSE); | |
221 if (ipx_nullhost(ipxp->ipxp_laddr)) { | 222 if (ipx_nullhost(ipxp->ipxp_laddr)) { |
222 if (ipxp->ipxp_lport == 0) 223 (void) ipx_pcbbind(ipxp, (struct mbuf *)0, p); 224 ipxp->ipxp_laddr.x_host = ipx_thishost; | 223 /* 224 * If route is known or can be allocated now, 225 * our src addr is taken from the i/f, else punt. 226 */ 227 228 /* 229 * If we found a route, use the address 230 * corresponding to the outgoing interface 231 */ 232 if (ro->ro_rt != NULL && (ifp = ro->ro_rt->rt_ifp) != NULL) 233 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next) 234 if (ia->ia_ifp == ifp) 235 break; 236 if (ia == NULL) { 237 u_short fport = sipx->sipx_addr.x_port; 238 sipx->sipx_addr.x_port = 0; 239 ia = (struct ipx_ifaddr *) 240 ifa_ifwithdstaddr((struct sockaddr *)sipx); 241 sipx->sipx_addr.x_port = fport; 242 if (ia == NULL) 243 ia = ipx_iaonnetof(&sipx->sipx_addr); 244 if (ia == NULL) 245 ia = ipx_ifaddr; 246 if (ia == NULL) 247 return (EADDRNOTAVAIL); 248 } 249 ipxp->ipxp_laddr.x_host = satoipx_addr(ia->ia_addr).x_host; |
225 } | 250 } |
251 if (ipx_pcblookup(&sipx->sipx_addr, ipxp->ipxp_lport, 0)) 252 return (EADDRINUSE); 253 if (ipxp->ipxp_lport == 0) 254 ipx_pcbbind(ipxp, (struct mbuf *)NULL, p); 255 256 /* XXX just leave it zero if we can't find a route */ 257 |
|
226 ipxp->ipxp_faddr = sipx->sipx_addr; 227 /* Includes ipxp->ipxp_fport = sipx->sipx_port; */ 228 return (0); 229} 230 231void 232ipx_pcbdisconnect(ipxp) 233 struct ipxpcb *ipxp; --- 7 unchanged lines hidden (view full) --- 241void 242ipx_pcbdetach(ipxp) 243 struct ipxpcb *ipxp; 244{ 245 struct socket *so = ipxp->ipxp_socket; 246 247 so->so_pcb = 0; 248 sofree(so); | 258 ipxp->ipxp_faddr = sipx->sipx_addr; 259 /* Includes ipxp->ipxp_fport = sipx->sipx_port; */ 260 return (0); 261} 262 263void 264ipx_pcbdisconnect(ipxp) 265 struct ipxpcb *ipxp; --- 7 unchanged lines hidden (view full) --- 273void 274ipx_pcbdetach(ipxp) 275 struct ipxpcb *ipxp; 276{ 277 struct socket *so = ipxp->ipxp_socket; 278 279 so->so_pcb = 0; 280 sofree(so); |
249 if (ipxp->ipxp_route.ro_rt) | 281 if (ipxp->ipxp_route.ro_rt != NULL) |
250 rtfree(ipxp->ipxp_route.ro_rt); 251 remque(ipxp); | 282 rtfree(ipxp->ipxp_route.ro_rt); 283 remque(ipxp); |
252 (void) m_free(dtom(ipxp)); | 284 m_free(dtom(ipxp)); |
253} 254 255void 256ipx_setsockaddr(ipxp, nam) 257 register struct ipxpcb *ipxp; 258 struct mbuf *nam; 259{ 260 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 261 | 285} 286 287void 288ipx_setsockaddr(ipxp, nam) 289 register struct ipxpcb *ipxp; 290 struct mbuf *nam; 291{ 292 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 293 |
262 nam->m_len = sizeof (*sipx); | 294 nam->m_len = sizeof(*sipx); |
263 sipx = mtod(nam, struct sockaddr_ipx *); | 295 sipx = mtod(nam, struct sockaddr_ipx *); |
264 bzero((caddr_t)sipx, sizeof (*sipx)); | 296 bzero((caddr_t)sipx, sizeof(*sipx)); |
265 sipx->sipx_len = sizeof(*sipx); 266 sipx->sipx_family = AF_IPX; 267 sipx->sipx_addr = ipxp->ipxp_laddr; 268} 269 270void 271ipx_setpeeraddr(ipxp, nam) 272 register struct ipxpcb *ipxp; 273 struct mbuf *nam; 274{ 275 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 276 | 297 sipx->sipx_len = sizeof(*sipx); 298 sipx->sipx_family = AF_IPX; 299 sipx->sipx_addr = ipxp->ipxp_laddr; 300} 301 302void 303ipx_setpeeraddr(ipxp, nam) 304 register struct ipxpcb *ipxp; 305 struct mbuf *nam; 306{ 307 register struct sockaddr_ipx *sipx = mtod(nam, struct sockaddr_ipx *); 308 |
277 nam->m_len = sizeof (*sipx); | 309 nam->m_len = sizeof(*sipx); |
278 sipx = mtod(nam, struct sockaddr_ipx *); | 310 sipx = mtod(nam, struct sockaddr_ipx *); |
279 bzero((caddr_t)sipx, sizeof (*sipx)); | 311 bzero((caddr_t)sipx, sizeof(*sipx)); |
280 sipx->sipx_len = sizeof(*sipx); 281 sipx->sipx_family = AF_IPX; 282 sipx->sipx_addr = ipxp->ipxp_faddr; 283} 284 285/* 286 * Pass some notification to all connections of a protocol 287 * associated with address dst. Call the --- 32 unchanged lines hidden (view full) --- 320#ifdef notdef 321/* 322 * After a routing change, flush old routing 323 * and allocate a (hopefully) better one. 324 */ 325ipx_rtchange(ipxp) 326 struct ipxpcb *ipxp; 327{ | 312 sipx->sipx_len = sizeof(*sipx); 313 sipx->sipx_family = AF_IPX; 314 sipx->sipx_addr = ipxp->ipxp_faddr; 315} 316 317/* 318 * Pass some notification to all connections of a protocol 319 * associated with address dst. Call the --- 32 unchanged lines hidden (view full) --- 352#ifdef notdef 353/* 354 * After a routing change, flush old routing 355 * and allocate a (hopefully) better one. 356 */ 357ipx_rtchange(ipxp) 358 struct ipxpcb *ipxp; 359{ |
328 if (ipxp->ipxp_route.ro_rt) { | 360 if (ipxp->ipxp_route.ro_rt != NULL) { |
329 rtfree(ipxp->ipxp_route.ro_rt); | 361 rtfree(ipxp->ipxp_route.ro_rt); |
330 ipxp->ipxp_route.ro_rt = 0; | 362 ipxp->ipxp_route.ro_rt = NULL; |
331 /* 332 * A new route can be allocated the next time 333 * output is attempted. 334 */ 335 } 336 /* SHOULD NOTIFY HIGHER-LEVEL PROTOCOLS */ 337} 338#endif --- 25 unchanged lines hidden (view full) --- 364 if (ipxp->ipxp_fport != fport) { 365 if (ipxp->ipxp_fport != 0) 366 continue; 367 else 368 wildcard++; 369 } 370 } 371 } | 363 /* 364 * A new route can be allocated the next time 365 * output is attempted. 366 */ 367 } 368 /* SHOULD NOTIFY HIGHER-LEVEL PROTOCOLS */ 369} 370#endif --- 25 unchanged lines hidden (view full) --- 396 if (ipxp->ipxp_fport != fport) { 397 if (ipxp->ipxp_fport != 0) 398 continue; 399 else 400 wildcard++; 401 } 402 } 403 } |
372 if (wildcard && wildp==0) | 404 if (wildcard && wildp == 0) |
373 continue; 374 if (wildcard < matchwild) { 375 match = ipxp; 376 matchwild = wildcard; 377 if (wildcard == 0) 378 break; 379 } 380 } 381 return (match); 382} | 405 continue; 406 if (wildcard < matchwild) { 407 match = ipxp; 408 matchwild = wildcard; 409 if (wildcard == 0) 410 break; 411 } 412 } 413 return (match); 414} |