extern int ipsec_bypass;
#endif
+extern u_long route_generation;
+
#define DBG_FNC_PCB_LOOKUP NETDBG_CODE(DBG_NETTCP, (6 << 8))
#define DBG_FNC_PCB_HLOOKUP NETDBG_CODE(DBG_NETTCP, ((6 << 8) | 1))
/*
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
+ * Note that we should check the address family of the cached
+ * destination, in case of sharing the cache with IPv6.
*/
ro = &inp->inp_route;
if (ro->ro_rt &&
- (satosin(&ro->ro_dst)->sin_addr.s_addr !=
+ (ro->ro_dst.sa_family != AF_INET ||
+ satosin(&ro->ro_dst)->sin_addr.s_addr !=
sin->sin_addr.s_addr ||
- inp->inp_socket->so_options & SO_DONTROUTE)) {
+ inp->inp_socket->so_options & SO_DONTROUTE ||
+ ro->ro_rt->generation_id != route_generation)) {
rtfree(ro->ro_rt);
ro->ro_rt = (struct rtentry *)0;
}
(ro->ro_rt == (struct rtentry *)0 ||
ro->ro_rt->rt_ifp == (struct ifnet *)0)) {
/* No route yet, so try to acquire one */
+ bzero(&ro->ro_dst, sizeof(struct sockaddr_in));
ro->ro_dst.sa_family = AF_INET;
ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
return (error);
}
inp->inp_laddr = ifaddr->sin_addr;
+ inp->inp_flags |= INP_INADDR_ANY;
}
inp->inp_faddr = sin->sin_addr;
inp->inp_fport = sin->sin_port;
rt->rt_gateway, rt_mask(rt),
rt->rt_flags, (struct rtentry **)0);
}
- else
+ else {
rtfree(rt);
+ inp->inp_route.ro_rt = 0;
+ }
}
ip_freemoptions(inp->inp_moptions);
inp->inp_vflag = 0;
LIST_REMOVE(inp, inp_hash);
LIST_REMOVE(inp, inp_portlist);
- if (LIST_FIRST(&phd->phd_pcblist) == NULL) {
+ if (phd != NULL && (LIST_FIRST(&phd->phd_pcblist) == NULL)) {
LIST_REMOVE(phd, phd_hash);
FREE(phd, M_PCB);
}