summaryrefslogtreecommitdiff
path: root/sys/netinet6/in6_pcb.c
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2024-01-31 12:27:58 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2024-01-31 12:27:58 +0000
commitfcc2c44a34911182dff36f19827110bcb12bde9b (patch)
tree7008c5d5906265e7a400820e7982d8690be76b2c /sys/netinet6/in6_pcb.c
parent44b0ccfcc5b078064f76743c000bdd3d1112727b (diff)
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@
Diffstat (limited to 'sys/netinet6/in6_pcb.c')
-rw-r--r--sys/netinet6/in6_pcb.c31
1 files changed, 30 insertions, 1 deletions
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,