-/* $OpenBSD: if_umb.c,v 1.50 2023/03/31 23:53:49 dlg Exp $ */
+/* $OpenBSD: if_umb.c,v 1.51 2023/04/18 22:01:23 mvs Exp $ */
/*
* Copyright (c) 2016 genua mbH
default_sin.sin_len = sizeof (default_sin);
memset(&info, 0, sizeof(info));
+ NET_LOCK();
info.rti_flags = RTF_GATEWAY /* maybe | RTF_STATIC */;
info.rti_ifa = ifa_ifwithaddr(sintosa(&ifra.ifra_addr),
ifp->if_rdomain);
info.rti_info[RTAX_NETMASK] = sintosa(&default_sin);
info.rti_info[RTAX_GATEWAY] = sintosa(&ifra.ifra_dstaddr);
- NET_LOCK();
rv = rtrequest(RTM_ADD, &info, 0, &rt, ifp->if_rdomain);
NET_UNLOCK();
if (rv) {
default_sin6.sin6_len = sizeof (default_sin6);
memset(&info, 0, sizeof(info));
+ NET_LOCK();
info.rti_flags = RTF_GATEWAY /* maybe | RTF_STATIC */;
info.rti_ifa = ifa_ifwithaddr(sin6tosa(&ifra.ifra_addr),
ifp->if_rdomain);
info.rti_info[RTAX_NETMASK] = sin6tosa(&default_sin6);
info.rti_info[RTAX_GATEWAY] = sin6tosa(&ifra.ifra_dstaddr);
- NET_LOCK();
rv = rtrequest(RTM_ADD, &info, 0, &rt, ifp->if_rdomain);
NET_UNLOCK();
if (rv) {
-/* $OpenBSD: if.c,v 1.689 2023/04/18 22:00:19 mvs Exp $ */
+/* $OpenBSD: if.c,v 1.690 2023/04/18 22:01:24 mvs Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
struct ifaddr *ifa;
u_int rdomain;
+ NET_ASSERT_LOCKED();
+
rdomain = rtable_l2(rtableid);
- KERNEL_LOCK();
TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
if (ifp->if_rdomain != rdomain)
continue;
continue;
if (equal(addr, ifa->ifa_addr)) {
- KERNEL_UNLOCK();
return (ifa);
}
}
}
- KERNEL_UNLOCK();
return (NULL);
}
struct ifnet *ifp;
struct ifaddr *ifa;
+ NET_ASSERT_LOCKED();
+
rdomain = rtable_l2(rdomain);
- KERNEL_LOCK();
TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
if (ifp->if_rdomain != rdomain)
continue;
addr->sa_family || ifa->ifa_dstaddr == NULL)
continue;
if (equal(addr, ifa->ifa_dstaddr)) {
- KERNEL_UNLOCK();
return (ifa);
}
}
}
}
- KERNEL_UNLOCK();
return (NULL);
}
void
ifa_add(struct ifnet *ifp, struct ifaddr *ifa)
{
+ NET_ASSERT_LOCKED_EXCLUSIVE();
TAILQ_INSERT_TAIL(&ifp->if_addrlist, ifa, ifa_list);
}
void
ifa_del(struct ifnet *ifp, struct ifaddr *ifa)
{
+ NET_ASSERT_LOCKED_EXCLUSIVE();
TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list);
}
-/* $OpenBSD: if_var.h,v 1.124 2023/04/18 22:00:19 mvs Exp $ */
+/* $OpenBSD: if_var.h,v 1.125 2023/04/18 22:01:24 mvs Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
struct sockaddr *ifa_netmask; /* used to determine subnet */
struct ifnet *ifa_ifp; /* back-pointer to interface */
- TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
+ TAILQ_ENTRY(ifaddr) ifa_list; /* [N] list of addresses for
+ interface */
u_int ifa_flags; /* interface flags, see below */
struct refcnt ifa_refcnt; /* number of `rt_ifa` references */
int ifa_metric; /* cost of going out this interface */
-/* $OpenBSD: rtsock.c,v 1.362 2023/04/18 09:56:54 mvs Exp $ */
+/* $OpenBSD: rtsock.c,v 1.363 2023/04/18 22:01:24 mvs Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
error = EINVAL;
goto fail;
}
- if ((error =
- rt_setsource(tableid, info.rti_info[RTAX_IFA])) != 0)
+ NET_LOCK();
+ error = rt_setsource(tableid, info.rti_info[RTAX_IFA]);
+ NET_UNLOCK();
+ if (error)
goto fail;
} else {
error = rtm_output(rtm, &rt, &info, prio, tableid);
rt_setsource(unsigned int rtableid, struct sockaddr *src)
{
struct ifaddr *ifa;
- int error;
/*
* If source address is 0.0.0.0 or ::
* use automatic source selection
return (EAFNOSUPPORT);
}
- KERNEL_LOCK();
/*
* Check if source address is assigned to an interface in the
* same rdomain
*/
- if ((ifa = ifa_ifwithaddr(src, rtableid)) == NULL) {
- KERNEL_UNLOCK();
+ if ((ifa = ifa_ifwithaddr(src, rtableid)) == NULL)
return (EINVAL);
- }
-
- error = rtable_setsource(rtableid, src->sa_family, ifa->ifa_addr);
- KERNEL_UNLOCK();
- return (error);
+ return rtable_setsource(rtableid, src->sa_family, ifa->ifa_addr);
}
/*