-/* $OpenBSD: route.c,v 1.430 2024/02/07 23:52:20 bluhm Exp $ */
+/* $OpenBSD: route.c,v 1.431 2024/02/09 14:02:11 bluhm Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
#endif
}
-void
+int
route_cache(struct route *ro, struct in_addr addr, u_int rtableid)
{
u_long gen;
ro->ro_dst.sa_family == AF_INET &&
satosin(&ro->ro_dst)->sin_addr.s_addr == addr.s_addr) {
ipstat_inc(ips_rtcachehit);
- return;
+ return (0);
}
ipstat_inc(ips_rtcachemiss);
satosin(&ro->ro_dst)->sin_family = AF_INET;
satosin(&ro->ro_dst)->sin_len = sizeof(struct sockaddr_in);
satosin(&ro->ro_dst)->sin_addr = addr;
+
+ return (ESRCH);
}
#ifdef INET6
-void
+int
route6_cache(struct route_in6 *ro, const struct in6_addr *addr,
u_int rtableid)
{
ro->ro_dst.sin6_family == AF_INET6 &&
IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, addr)) {
ip6stat_inc(ip6s_rtcachehit);
- return;
+ return (0);
}
ip6stat_inc(ip6s_rtcachemiss);
ro->ro_dst.sin6_family = AF_INET6;
ro->ro_dst.sin6_len = sizeof(struct sockaddr_in6);
ro->ro_dst.sin6_addr = *addr;
+
+ return (ESRCH);
}
#endif
-/* $OpenBSD: in.h,v 1.146 2024/02/05 12:52:11 aoyama Exp $ */
+/* $OpenBSD: in.h,v 1.147 2024/02/09 14:02:11 bluhm Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
int in_nam2sin(const struct mbuf *, struct sockaddr_in **);
int in_sa2sin(struct sockaddr *, struct sockaddr_in **);
-void route_cache(struct route *, struct in_addr, u_int);
+int route_cache(struct route *, struct in_addr, u_int);
char *inet_ntoa(struct in_addr);
int inet_nat64(int, const void *, void *, const void *, u_int8_t);
-/* $OpenBSD: in_pcb.c,v 1.290 2024/02/07 23:40:40 bluhm Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.291 2024/02/09 14:02:11 bluhm Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
if (inp->inp_faddr.s_addr == INADDR_ANY)
return (NULL);
- route_cache(ro, inp->inp_faddr, inp->inp_rtableid);
- if (ro->ro_rt == NULL) {
+ if (route_cache(ro, inp->inp_faddr, inp->inp_rtableid)) {
ro->ro_rt = rtalloc_mpath(&ro->ro_dst,
&inp->inp_laddr.s_addr, ro->ro_tableid);
}
const struct in_addr *laddr = &inp->inp_laddr;
u_int rtableid = inp->inp_rtableid;
struct sockaddr *ip4_source = NULL;
-
- struct sockaddr_in *sin2;
struct in_ifaddr *ia = NULL;
/*
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
*/
- if (!rtisvalid(ro->ro_rt) || (ro->ro_tableid != rtableid) ||
- (satosin(&ro->ro_dst)->sin_addr.s_addr != sin->sin_addr.s_addr)) {
- rtfree(ro->ro_rt);
- ro->ro_rt = NULL;
- }
- if (ro->ro_rt == NULL) {
+ if (route_cache(ro, sin->sin_addr, rtableid)) {
/* No route yet, so try to acquire one */
- ro->ro_dst.sa_family = AF_INET;
- ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
- satosin(&ro->ro_dst)->sin_addr = sin->sin_addr;
- ro->ro_tableid = rtableid;
ro->ro_rt = rtalloc_mpath(&ro->ro_dst, NULL, ro->ro_tableid);
-
- /*
- * It is important to zero out the rest of the
- * struct sockaddr_in when mixing v6 & v4!
- */
- sin2 = satosin(&ro->ro_dst);
- memset(sin2->sin_zero, 0, sizeof(sin2->sin_zero));
}
/*
-/* $OpenBSD: in6.h,v 1.114 2024/02/07 23:40:40 bluhm Exp $ */
+/* $OpenBSD: in6.h,v 1.115 2024/02/09 14:02:12 bluhm Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
int in6_nam2sin6(const struct mbuf *, struct sockaddr_in6 **);
int in6_sa2sin6(struct sockaddr *, struct sockaddr_in6 **);
-void route6_cache(struct route_in6 *, const struct in6_addr *, u_int);
+int route6_cache(struct route_in6 *, const struct in6_addr *, u_int);
struct ip6_pktopts;
struct ip6_moptions;
-/* $OpenBSD: in6_pcb.c,v 1.135 2024/02/07 23:40:40 bluhm Exp $ */
+/* $OpenBSD: in6_pcb.c,v 1.136 2024/02/09 14:02:12 bluhm Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
return (NULL);
- route6_cache(ro, &inp->inp_faddr6, inp->inp_rtableid);
- if (ro->ro_rt == NULL) {
+ if (route6_cache(ro, &inp->inp_faddr6, inp->inp_rtableid)) {
ro->ro_rt = rtalloc_mpath(sin6tosa(&ro->ro_dst),
&inp->inp_laddr6.s6_addr32[0], ro->ro_tableid);
}
-/* $OpenBSD: in6_src.c,v 1.92 2024/02/07 23:40:40 bluhm Exp $ */
+/* $OpenBSD: in6_src.c,v 1.93 2024/02/09 14:02:12 bluhm Exp $ */
/* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */
/*
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
*/
- route6_cache(ro, dst, rtableid);
- if (ro->ro_rt == NULL) {
+ if (route6_cache(ro, dst, rtableid)) {
ro->ro_rt = rtalloc(sin6tosa(&ro->ro_dst),
RT_RESOLVE, ro->ro_tableid);
}
* a new one.
*/
if (ro) {
- route6_cache(ro, dst, rtableid);
- if (ro->ro_rt == NULL) {
+ if (route6_cache(ro, dst, rtableid)) {
/* No route yet, so try to acquire one */
ro->ro_rt = rtalloc_mpath(sin6tosa(&ro->ro_dst),
NULL, ro->ro_tableid);