From: bluhm Date: Wed, 31 Jan 2024 12:27:57 +0000 (+0000) Subject: Split in_pcbrtentry() and in6_pcbrtentry() based on INP_IPV6. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3dc61bc4bed21261969a6610a5769348be94854f;p=openbsd Split in_pcbrtentry() and in6_pcbrtentry() based on INP_IPV6. Splitting the IPv6 code into a separate function results in less #ifdef INET6. Also struct route_in6 *ro in in6_pcbrtentry() is of the correct type and in_pcbrtentry() does not rely on the fact that inp_route and inp_route6 are pointers to the same union. OK kn@ claudio@ --- diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 20a5c5c97fc..36ff7553a5b 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.287 2024/01/28 20:34:25 bluhm Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.288 2024/01/31 12:27:57 bluhm Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -909,6 +909,11 @@ in_pcbrtentry(struct inpcb *inp) { struct route *ro; +#ifdef INET6 + if (ISSET(inp->inp_flags, INP_IPV6)) + in6_pcbrtentry(inp); +#endif + ro = &inp->inp_route; /* check if route is still valid */ @@ -921,34 +926,16 @@ in_pcbrtentry(struct inpcb *inp) * No route yet, so try to acquire one. */ if (ro->ro_rt == NULL) { -#ifdef INET6 - memset(ro, 0, sizeof(struct route_in6)); -#else memset(ro, 0, sizeof(struct route)); -#endif -#ifdef INET6 - if (ISSET(inp->inp_flags, INP_IPV6)) { - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) - return (NULL); - ro->ro_dst.sa_family = AF_INET6; - ro->ro_dst.sa_len = sizeof(struct sockaddr_in6); - satosin6(&ro->ro_dst)->sin6_addr = inp->inp_faddr6; - ro->ro_tableid = inp->inp_rtableid; - ro->ro_rt = rtalloc_mpath(&ro->ro_dst, - &inp->inp_laddr6.s6_addr32[0], ro->ro_tableid); - } else -#endif /* INET6 */ - { - if (inp->inp_faddr.s_addr == INADDR_ANY) - return (NULL); - ro->ro_dst.sa_family = AF_INET; - ro->ro_dst.sa_len = sizeof(struct sockaddr_in); - satosin(&ro->ro_dst)->sin_addr = inp->inp_faddr; - ro->ro_tableid = inp->inp_rtableid; - ro->ro_rt = rtalloc_mpath(&ro->ro_dst, - &inp->inp_laddr.s_addr, ro->ro_tableid); - } + if (inp->inp_faddr.s_addr == INADDR_ANY) + return (NULL); + ro->ro_dst.sa_family = AF_INET; + ro->ro_dst.sa_len = sizeof(struct sockaddr_in); + satosin(&ro->ro_dst)->sin_addr = inp->inp_faddr; + ro->ro_tableid = inp->inp_rtableid; + ro->ro_rt = rtalloc_mpath(&ro->ro_dst, + &inp->inp_laddr.s_addr, ro->ro_tableid); } return (ro->ro_rt); } diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index a463d87dc4a..fd09f3696aa 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.149 2024/01/28 20:34:25 bluhm Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.150 2024/01/31 12:27:57 bluhm Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -367,6 +367,8 @@ struct rtentry * in_pcbrtentry(struct inpcb *); /* INET6 stuff */ +struct rtentry * + in6_pcbrtentry(struct inpcb *); void in6_pcbnotify(struct inpcbtable *, const struct sockaddr_in6 *, u_int, const struct sockaddr_in6 *, u_int, u_int, int, void *, void (*)(struct inpcb *, int)); diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 3561446e8eb..d447beb8329 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.133 2024/01/28 20:34:25 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.134 2024/01/31 12:27:57 bluhm Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -561,6 +561,35 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr_in6 *dst, rw_exit_write(&table->inpt_notify); } +struct rtentry * +in6_pcbrtentry(struct inpcb *inp) +{ + struct route_in6 *ro = &inp->inp_route6; + + /* check if route is still valid */ + if (!rtisvalid(ro->ro_rt)) { + rtfree(ro->ro_rt); + ro->ro_rt = NULL; + } + + /* + * No route yet, so try to acquire one. + */ + if (ro->ro_rt == NULL) { + memset(ro, 0, sizeof(struct route_in6)); + + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) + return (NULL); + ro->ro_dst.sin6_family = AF_INET6; + ro->ro_dst.sin6_len = sizeof(struct sockaddr_in6); + ro->ro_dst.sin6_addr = inp->inp_faddr6; + ro->ro_tableid = inp->inp_rtableid; + ro->ro_rt = rtalloc_mpath(sin6tosa(&ro->ro_dst), + &inp->inp_laddr6.s6_addr32[0], ro->ro_tableid); + } + return (ro->ro_rt); +} + struct inpcb * in6_pcbhash_lookup(struct inpcbtable *table, uint64_t hash, u_int rdomain, const struct in6_addr *faddr, u_short fport, diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 370f15fef40..f3da1972a94 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_output.c,v 1.283 2024/01/18 11:03:16 claudio Exp $ */ +/* $OpenBSD: ip6_output.c,v 1.284 2024/01/31 12:27:57 bluhm Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -1486,7 +1486,7 @@ do { \ if (!(so->so_state & SS_ISCONNECTED)) return (ENOTCONN); - rt = in_pcbrtentry(inp); + rt = in6_pcbrtentry(inp); if (!rtisvalid(rt)) return (EHOSTUNREACH);