-/* $OpenBSD: uipc_socket2.c,v 1.108 2021/04/26 08:21:35 claudio Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.109 2021/05/01 16:13:13 mvs Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
so = pool_get(&socket_pool, PR_NOWAIT|PR_ZERO);
if (so == NULL)
return (NULL);
+ rw_init(&so->so_lock, "solock");
so->so_type = head->so_type;
so->so_options = head->so_options &~ SO_ACCEPTCONN;
so->so_linger = head->so_linger;
rw_enter_write(&unp_lock);
break;
case PF_ROUTE:
+ rw_enter_write(&so->so_lock);
+ break;
case PF_KEY:
default:
KERNEL_LOCK();
rw_exit_write(&unp_lock);
break;
case PF_ROUTE:
+ rw_exit_write(&so->so_lock);
+ break;
case PF_KEY:
default:
KERNEL_UNLOCK();
rw_assert_wrlock(&unp_lock);
break;
case PF_ROUTE:
+ rw_assert_wrlock(&so->so_lock);
+ break;
case PF_KEY:
default:
KERNEL_ASSERT_LOCKED();
ret = rwsleep_nsec(ident, &unp_lock, prio, wmesg, nsecs);
break;
case PF_ROUTE:
+ ret = rwsleep_nsec(ident, &so->so_lock, prio, wmesg, nsecs);
+ break;
case PF_KEY:
default:
ret = tsleep_nsec(ident, prio, wmesg, nsecs);
-/* $OpenBSD: rtsock.c,v 1.311 2021/04/26 08:21:36 claudio Exp $ */
+/* $OpenBSD: rtsock.c,v 1.312 2021/05/01 16:13:13 mvs Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
/*
* Locks used to protect struct members
* I immutable after creation
- * sK solock (kernel lock)
+ * s solock
*/
struct rtpcb {
struct socket *rop_socket; /* [I] */
SRPL_ENTRY(rtpcb) rop_list;
struct refcnt rop_refcnt;
struct timeout rop_timeout;
- unsigned int rop_msgfilter; /* [sK] */
- unsigned int rop_flagfilter; /* [sK] */
- unsigned int rop_flags; /* [sK] */
- u_int rop_rtableid; /* [sK] */
+ unsigned int rop_msgfilter; /* [s] */
+ unsigned int rop_flagfilter; /* [s] */
+ unsigned int rop_flags; /* [s] */
+ u_int rop_rtableid; /* [s] */
unsigned short rop_proto; /* [I] */
- u_char rop_priority; /* [sK] */
+ u_char rop_priority; /* [s] */
};
#define sotortpcb(so) ((struct rtpcb *)(so)->so_pcb)
rw_init(&rtptable.rtp_lk, "rtsock");
SRPL_INIT(&rtptable.rtp_list);
pool_init(&rtpcb_pool, sizeof(struct rtpcb), 0,
- IPL_NONE, PR_WAITOK, "rtpcb", NULL);
+ IPL_SOFTNET, PR_WAITOK, "rtpcb", NULL);
}
void
rop = pool_get(&rtpcb_pool, PR_WAITOK|PR_ZERO);
so->so_pcb = rop;
/* Init the timeout structure */
- timeout_set(&rop->rop_timeout, rtm_senddesync_timer, so);
+ timeout_set_flags(&rop->rop_timeout, rtm_senddesync_timer, so,
+ TIMEOUT_PROC);
refcnt_init(&rop->rop_refcnt);
rop->rop_socket = so;
rop_list);
rw_exit(&rtptable.rtp_lk);
+ sounlock(so, SL_LOCKED);
+
/* wait for all references to drop */
refcnt_finalize(&rop->rop_refcnt, "rtsockrefs");
+ solock(so);
+
so->so_pcb = NULL;
KASSERT((so->so_state & SS_NOFDREF) == 0);
pool_put(&rtpcb_pool, rop);
struct rtentry *rt = NULL;
struct rt_addrinfo info;
struct ifnet *ifp;
- int len, seq, error = 0;
+ int len, seq, useloopback, error = 0;
u_int tableid;
u_int8_t prio;
u_char vers, type;
return (ENOBUFS);
if ((m->m_flags & M_PKTHDR) == 0)
panic("route_output");
+
+ useloopback = so->so_options & SO_USELOOPBACK;
+
+ /*
+ * The socket can't be closed concurrently because the file
+ * descriptor reference is still held.
+ */
+
+ sounlock(so, SL_LOCKED);
+
len = m->m_pkthdr.len;
if (len < offsetof(struct rt_msghdr, rtm_hdrlen) + 1 ||
len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
/*
* Check to see if we don't want our own messages.
*/
- if (!(so->so_options & SO_USELOOPBACK)) {
- if (rtptable.rtp_count <= 1) {
+ if (!useloopback) {
+ if (rtptable.rtp_count == 0) {
/* no other listener and no loopback of messages */
-fail:
- free(rtm, M_RTABLE, len);
- m_freem(m);
- return (error);
+ goto fail;
}
}
if (m_copyback(m, 0, len, rtm, M_NOWAIT)) {
if (m)
route_input(m, so, info.rti_info[RTAX_DST] ?
info.rti_info[RTAX_DST]->sa_family : AF_UNSPEC);
+ solock(so);
+
+ return (error);
+fail:
+ free(rtm, M_RTABLE, len);
+ m_freem(m);
+ solock(so);
return (error);
}