Protect if_clone data with if_clone_mtx
To this end, carpattach needs to be delayed from RUMP_COMPONENT_NET to RUMP_COMPONENT_NET_IF on rump_server. Otherwise mutex_enter via carpattach for if_clone_mtx is called before mutex_init for it in ifinit1.
This commit is contained in:
parent
fd0caf00f0
commit
ac86ae25b9
30
sys/net/if.c
30
sys/net/if.c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if.c,v 1.371 2017/01/10 08:45:45 ozaki-r Exp $ */
|
||||
/* $NetBSD: if.c,v 1.372 2017/01/20 08:35:33 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -90,7 +90,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.371 2017/01/10 08:45:45 ozaki-r Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.372 2017/01/20 08:35:33 ozaki-r Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_inet.h"
|
||||
|
@ -1537,6 +1537,8 @@ if_clone_create(const char *name)
|
|||
struct ifnet *ifp;
|
||||
struct psref psref;
|
||||
|
||||
KASSERT(mutex_owned(&if_clone_mtx));
|
||||
|
||||
ifc = if_clone_lookup(name, &unit);
|
||||
if (ifc == NULL)
|
||||
return EINVAL;
|
||||
|
@ -1560,6 +1562,8 @@ if_clone_destroy(const char *name)
|
|||
struct ifnet *ifp;
|
||||
struct psref psref;
|
||||
|
||||
KASSERT(mutex_owned(&if_clone_mtx));
|
||||
|
||||
ifc = if_clone_lookup(name, NULL);
|
||||
if (ifc == NULL)
|
||||
return EINVAL;
|
||||
|
@ -1596,6 +1600,8 @@ if_clone_lookup(const char *name, int *unitp)
|
|||
char *dp, ifname[IFNAMSIZ + 3];
|
||||
int unit;
|
||||
|
||||
KASSERT(mutex_owned(&if_clone_mtx));
|
||||
|
||||
strcpy(ifname, "if_");
|
||||
/* separate interface name from unit */
|
||||
for (dp = ifname + 3, cp = name; cp - name < IFNAMSIZ &&
|
||||
|
@ -1641,8 +1647,10 @@ void
|
|||
if_clone_attach(struct if_clone *ifc)
|
||||
{
|
||||
|
||||
mutex_enter(&if_clone_mtx);
|
||||
LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
|
||||
if_cloners_count++;
|
||||
mutex_exit(&if_clone_mtx);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1652,6 +1660,7 @@ void
|
|||
if_clone_detach(struct if_clone *ifc)
|
||||
{
|
||||
|
||||
KASSERT(mutex_owned(&if_clone_mtx));
|
||||
LIST_REMOVE(ifc, ifc_list);
|
||||
if_cloners_count--;
|
||||
}
|
||||
|
@ -1666,14 +1675,17 @@ if_clone_list(int buf_count, char *buffer, int *total)
|
|||
struct if_clone *ifc;
|
||||
int count, error = 0;
|
||||
|
||||
mutex_enter(&if_clone_mtx);
|
||||
*total = if_cloners_count;
|
||||
if ((dst = buffer) == NULL) {
|
||||
/* Just asking how many there are. */
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (buf_count < 0)
|
||||
return EINVAL;
|
||||
if (buf_count < 0) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
count = (if_cloners_count < buf_count) ?
|
||||
if_cloners_count : buf_count;
|
||||
|
@ -1681,13 +1693,17 @@ if_clone_list(int buf_count, char *buffer, int *total)
|
|||
for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
|
||||
ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
|
||||
(void)strncpy(outbuf, ifc->ifc_name, sizeof(outbuf));
|
||||
if (outbuf[sizeof(outbuf) - 1] != '\0')
|
||||
return ENAMETOOLONG;
|
||||
if (outbuf[sizeof(outbuf) - 1] != '\0') {
|
||||
error = ENAMETOOLONG;
|
||||
goto out;
|
||||
}
|
||||
error = copyout(outbuf, dst, sizeof(outbuf));
|
||||
if (error != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_exit(&if_clone_mtx);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: netinet_component.c,v 1.7 2016/08/13 11:19:35 christos Exp $ */
|
||||
/* $NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
||||
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.7 2016/08/13 11:19:35 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/domain.h>
|
||||
|
@ -45,8 +45,6 @@ __KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.7 2016/08/13 11:19:35 christ
|
|||
#include <rump-sys/kern.h>
|
||||
#include <rump-sys/net.h>
|
||||
|
||||
int carpattach(int);
|
||||
|
||||
RUMP_COMPONENT(RUMP_COMPONENT_NET)
|
||||
{
|
||||
extern struct domain arpdomain, inetdomain;
|
||||
|
@ -54,11 +52,17 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET)
|
|||
domain_attach(&arpdomain);
|
||||
domain_attach(&inetdomain);
|
||||
|
||||
carpattach(1);
|
||||
|
||||
rump_netisr_register(NETISR_ARP, arpintr);
|
||||
}
|
||||
|
||||
int carpattach(int);
|
||||
|
||||
RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
|
||||
{
|
||||
|
||||
carpattach(1);
|
||||
}
|
||||
|
||||
RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG)
|
||||
{
|
||||
struct ifaliasreq ia;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: t_ifconfig.sh,v 1.14 2016/10/01 22:15:04 kre Exp $
|
||||
# $NetBSD: t_ifconfig.sh,v 1.15 2017/01/20 08:35:33 ozaki-r Exp $
|
||||
#
|
||||
# Copyright (c) 2015 The NetBSD Foundation, Inc.
|
||||
# All rights reserved.
|
||||
|
@ -181,7 +181,7 @@ ifconfig_options_body()
|
|||
|
||||
# ifconfig -C
|
||||
# -C shows all of the interface cloners available on the system
|
||||
atf_check -s exit:0 -o match:'shmif lo carp' rump.ifconfig -C
|
||||
atf_check -s exit:0 -o match:'shmif carp lo' rump.ifconfig -C
|
||||
|
||||
unset RUMP_SERVER
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue