From fcc2c44a34911182dff36f19827110bcb12bde9b Mon Sep 17 00:00:00 2001 From: Alexander Bluhm Date: Wed, 31 Jan 2024 12:27:58 +0000 Subject: 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@ --- sys/netinet6/in6_pcb.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'sys/netinet6/in6_pcb.c') 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, -- cgit v1.2.3