From nobody Sat Jan 29 15:20:34 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 0A962198C60F; Sat, 29 Jan 2022 15:20:47 +0000 (UTC) (envelope-from zec@fer.hr) Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40079.outbound.protection.outlook.com [40.107.4.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "DigiCert Cloud Services CA-1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JmJ1T6hQnz3l89; Sat, 29 Jan 2022 15:20:45 +0000 (UTC) (envelope-from zec@fer.hr) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eeiC+CGZvSsU/ZhSZAIlv3NaP7E1ToAhT68QrSwmX6knhFMZFobyhmHzAcJ4S/fehsTjinViEUIQxyORCb+bywZBcW2yuBNLylClJIPCDkGRyyTZqcyEfZp4cS5rzRb44/FVP2K2GDlHxROS92DxGOkjA4bWLPHfIqVJUZjbg46PnA8GZI6pM1wHFMJPnEEooY/trSHGQNA9PYz7uUPrG4c+OYosqZ6MiHupWoq1SXMlLauFh1X3bbJdDiSvbX+80HEqgitDrKvquE6DEx7QGLszJVV30I9tcKR1qc+U+LjvhxTcsDuFbzDHKcGadVWP77U/nnvwh29hPG/J+zhb0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wvi8fRLG4Wl77DL8V/xLOUMHP6R/BkmvKHTx/b4H0t4=; b=bAHp2/5ZU6VLT6zCXdEXQ9KrLDfKN0t5v/QVDgrNu5UdgM5Az3FCYpUJL1jTRshWsPerTJbY+grp8Nl/RF/PiwTb2PieGuNZGMqsimv6e/iZQyU7ok2bAgbZHOg5LfNPtGlA/0hjk+KArctUT3Rqtu03tb0IHEWXhwog2NeA+Y9F4Y2cK6QbGoUdXCRLINfHKMusPBgBOyj4WUXh+U8xzTECaJWcBlgJzhEW4mW1U1yt7ZSA1jXYMNhqatK2oGq0weDATkXpjg9Ea3s0NhUVYPtntl8utCV4uI0RiWMN5dg9bSg5Z96GRzufusdmkoTrCB/y12cJHXbVP3USLhweLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ferhr.onmicrosoft.com; s=selector2-ferhr-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wvi8fRLG4Wl77DL8V/xLOUMHP6R/BkmvKHTx/b4H0t4=; b=QHlzoUY+jMS5Ha1PS1XrUgoIrXfTISIF6rw2MsK61HzJ0nnaJvIIfiz2j0TJvO62pN48RSflf8cbJsSu4+8H4mFfSM0Tc+PaYPJALLZL72A3kOTihSIXK7WsxFTm+KZp/Vpb8ClBr5IR4jYplMGKVXzyoyHlcAg9TU1biE/xjFk= Received: from VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) by AM9PR08MB5937.eurprd08.prod.outlook.com (2603:10a6:20b:285::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.17; Sat, 29 Jan 2022 15:20:38 +0000 Received: from VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::f077:7274:ad5:303]) by VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::f077:7274:ad5:303%5]) with mapi id 15.20.4930.019; Sat, 29 Jan 2022 15:20:37 +0000 Date: Sat, 29 Jan 2022 16:20:34 +0100 From: Marko Zec To: Gleb Smirnoff Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: 91f44749c6fe - main - ifnet: make if_index global Message-ID: <20220129162034.6cda27df@x25> In-Reply-To: <202201270600.20R601qd059593@gitrepo.freebsd.org> References: <202201270600.20R601qd059593@gitrepo.freebsd.org> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; amd64-portbld-freebsd13.0) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: VI1PR09CA0079.eurprd09.prod.outlook.com (2603:10a6:802:29::23) To VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 54e521ec-84b6-4239-92a4-08d9e33ae6ca X-MS-TrafficTypeDiagnostic: AM9PR08MB5937:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bDfIm4s3YCzI/zzXMMrqy9RY2sMzitlRuOKD6y6p+2j1REg79oP7M026rCiYLR0YvIz7C32sdTuQ2iFiXtjPwCiRNKYuh6EgUAbxxOAQLbFMwc1IpXAosJ4QnD/gpDjAuFTlkcg47tkzIRSTPsOC7AjbkKay1ziQyqI+Tf5RbhPgnCFGK5abYDDBFrVb6qP7ihBB22H04i/oeSB3YkorOeq9+T6hxgtY3j5aSYW7MANxPaqQiEF6YzFGW3Wnc6SlZKXNLfAwTYfJnjOB1Nl42q6qf/PVVMf+sBbmRKBgGhMOQm/r/fDzcAyNtvc5KZD/+OLih7+yU+rd56J4XWd/727YRlHHpjGRsKS5IWgVypRMfCWLQ9pv8bwjaueQda9sGCIxj8OvpnW0u8DeAwVwAGwShDkAfZ8KW7myr4tAVhHQCKRQsEHRuOiEBosHYHoVnT//gZps7A6mIxFFEkhj544xLUPmF3l43ViXLuDsnufRIFnPlxVqvoLhThT6Z0rvv1dXWKBEh0vM9Pw+2F9QOfZ+9F7fPHycHfybmfzXIbI9t0HnlxmdbH9JDBn/AGH0kohRVYzIpnqAIfpHwBg6x57veTQBogwY8+Bz6N60AWuGBLX/nxMzzxQ6UbtgjF7LSHpIytw4WqQEzMjEaf1G1QkT0hLxZIhZKQXSvNn25rjK+yKJVx/9IxzqwHcetlaQKiklzjtFLIfLHMEjJ7R729vDjuP/bPOQqqbImUxryPMfGhlmw+XqrYc6psVx7ZUgIZrnpkMHLNMb1PWSc4VkUkjTrlsoGpe/pzCB0SLI52gJGZzosE1KySY8NgheD8XJ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4783.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(7916004)(366004)(9686003)(4326008)(8936002)(6512007)(38100700002)(8676002)(6486002)(508600001)(6916009)(316002)(786003)(38350700002)(966005)(52116002)(66946007)(26005)(6506007)(66556008)(66476007)(6666004)(450100002)(86362001)(186003)(33716001)(83380400001)(30864003)(5660300002)(1076003)(2906002)(21314003)(20210929001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?I9S7a3DMyMBoQB2j6haHYuIXkrIQ8eAoTB168GQhfiMx6Tro6YrBge5rZ7SH?= =?us-ascii?Q?JpjL9pCI2mmj7XyAwGY+EZ0dRwOgYdNqp2AdTQXuPSZQuIErq3ffndEONZq8?= =?us-ascii?Q?keyhM3d/pUlRvno1GIQFYMJpDYV6ch6sYFkuUMm283hpCBXXIozUZVGOI/f2?= =?us-ascii?Q?vTYC8LDyUhg77ldWC16el5m2YJLl/MPyOBXL6UPC8hpsJ8qt0naIdAVgKDGB?= =?us-ascii?Q?q2fuITL27khM/L6rmTGgpT4kKS+0x3FR/XbBXvEJhssoWSN6X2N4y+Z6QnIA?= =?us-ascii?Q?Y0bWKTa1zmm2BxuC+vcxDc0qLlcre7JtHGTWR73ljb5+t2eCZJvR80Ei7IS5?= =?us-ascii?Q?pMv/aziJe+iDCgkSiXLkNTeXBM1DLMMPV4+yUP7aroAMgtmlPZpTduIOwdom?= =?us-ascii?Q?aawjINz/fim1g8VyB/R2Ws+++ZYAmORO/ndrHyDTGF66gCgD46acpddizpSM?= =?us-ascii?Q?2HMh1HX/4hoATBBXP3u9f5XH2srh+d3+ro0REQOQvNGrJyZ5TOQkLhR00fsR?= =?us-ascii?Q?8oiMb3HXZtMXbwQEMDAkgfkwqaLHCzpdiTvPBvTQS7fPgURpHyOUjZ6ozXu0?= =?us-ascii?Q?TBUVUb6a0P3qdjhMG3OszMxLObKFJ1JnRKvi/tKjmkHl/FWyc5sRazvuLNNz?= =?us-ascii?Q?hWc0PMpAi/V+cvJs5vHrxW8uk7mZbDDbvT5zmXb85Ak+WGoKNcZ6kQVL7wIt?= =?us-ascii?Q?Ox3EnmziT+FsklTL0r4CEbtEho0NWrbQGLq4LbV5ksS39pPoYe1eOVHGK+sZ?= =?us-ascii?Q?iITJn/+If9XcLvCQMtwwz9UEeBCg3hYUAjNSGwsezEqGpiC0yHjW7HL9+4GQ?= =?us-ascii?Q?akm/a/7WlC8p8YTc6Q5wE6jWj09zTSwGTT1mCL3VIH1sGC6OFi1ajt7PM8tM?= =?us-ascii?Q?d3654gDxr/+70+glNupTJcW6g8bPTzGZj3Gh6lyvKscFFIEKL/rbc/aVxneZ?= =?us-ascii?Q?aSrmvr3n0+tIwof+0sZLflE6R94woWwWfnT1CLnIgK57ANw/iNpWu97PSPv7?= =?us-ascii?Q?Oy3hVeo+YJXgHyZz6mFe6Mf2/8gaFcEHVkq9mt5BigTk+o5yy4ZP5p7nJ9Vz?= =?us-ascii?Q?jzPN4NDVIUw+wYK5/MR+Jfa+drPagjh5D3Xd5qmw6V3kRaOEj/StzU6Zbvbp?= =?us-ascii?Q?i5V3CLBAQhjm6YHCgGAQWiBROeKB+wRi0HatPXLpZ2KlZLbBbqAmTVmHT8zx?= =?us-ascii?Q?oZ3DraIyY9WW7tBS/hmHJq+ZvPWVJE1xZyhOJUwg2MXOKb6lsipKa68hq54H?= =?us-ascii?Q?pIW0lt1INQ9VvoUHZYQcgAGQaB8Ywh3Rp2n1wtqofnFj99Zs3bXke6AVBYWJ?= =?us-ascii?Q?xOcqEEFY7iA/5sehu9WfhZlrLKoKNXQGmWAbKRbdPUVkQxzXzQ26FbhagMsj?= =?us-ascii?Q?ViafK2TyXxG4PtYMA/Bo5xIZZc4iHn7Mil7YQ7q1caT702iFOuW2d3HNuggL?= =?us-ascii?Q?EFZ3LkyRCUixSZpJXFyHSGiuSmVZFEO6aeep7O6HwvFBhy6bpwesBMsef77Z?= =?us-ascii?Q?J26t/3L9LLkbSIyLrVPr33pFd+tjQpBmllqLD7Tfw+GwQVGUajkdThCiFOEI?= =?us-ascii?Q?vNw5KutuhOYU+0g029U=3D?= X-OriginatorOrg: fer.hr X-MS-Exchange-CrossTenant-Network-Message-Id: 54e521ec-84b6-4239-92a4-08d9e33ae6ca X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4783.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2022 15:20:37.0998 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: ca71eddc-cc7b-4e5b-95bd-55b658e696be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: edIOAdBkheAK1fiwVcfrAQVVoPbqEwZCvaXJrzNJOewPC3CzPfgeDpH8CUWd7a2O X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB5937 X-Rspamd-Queue-Id: 4JmJ1T6hQnz3l89 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=ferhr.onmicrosoft.com header.s=selector2-ferhr-onmicrosoft-com header.b=QHlzoUY+; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=none; spf=pass (mx1.freebsd.org: domain of zec@fer.hr designates 40.107.4.79 as permitted sender) smtp.mailfrom=zec@fer.hr X-Spamd-Result: default: False [-4.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[ferhr.onmicrosoft.com:s=selector2-ferhr-onmicrosoft-com]; FREEFALL_USER(0.00)[zec]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:40.107.0.0/16]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[fer.hr]; NEURAL_HAM_LONG(-1.00)[-1.000]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[ferhr.onmicrosoft.com:+]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCVD_IN_DNSWL_NONE(0.00)[40.107.4.79:from]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:8075, ipnet:40.104.0.0/14, country:US]; MID_RHS_NOT_FQDN(0.50)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.107.4.79:from] X-ThisMailContainsUnwantedMimeParts: N On Thu, 27 Jan 2022 06:00:01 GMT Gleb Smirnoff wrote: > The branch main has been updated by glebius: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=91f44749c6feb50f39af8805dd803e860f0418f1 > > commit 91f44749c6feb50f39af8805dd803e860f0418f1 > Author: Gleb Smirnoff > AuthorDate: 2022-01-27 05:58:44 +0000 > Commit: Gleb Smirnoff > CommitDate: 2022-01-27 05:58:44 +0000 > > ifnet: make if_index global > > Now that ifindex is static to if.c we can unvirtualize it. For > lifetime of an ifnet its index never changes. To avoid leaking > foreign interfaces the net.link.generic.system.ifcount sysctl and the > ifnet_byindex() KPI filter their returned value on curvnet. Since > if_vmove() no longer changes the if_index, inline ifindex_alloc() and > ifindex_free() into if_alloc() and if_free() respectively. > > API wise the only change is that now minimum interface index can > be greater than 1. IMO this is a huge change in an API which has been stable like forever. Was this tested with a broader spectrum of userland consumers, such as FRR & alike? > The holes in interface indexes were always allowed. True, the holes were formally allowed but were never huge, and now they will be guaranteed with #vnets > 1. Again, that's not something 3rd party tools would expect. What could be the repercussions of ifindex globalization to 16-bit size of ifru_index in struct ifreq? What can prevent a vnet to inflate the global ifindex space, causing the linear scan in sysctl_ifcount() to become a global problem? Why do we now need to check wheter curvnet != NULL in ifnet_byindex(), i.e. are there callers to ifnet_byindex() where curvnet is not set? If so, that smells like a bug in the caller? Or, is it the other way around, that ifnet_byindex() is now intended to become a silent workaround for callers which lack curvnet context? If that is so, it is indeed becoming a major VNET KPI feature (though I'd call it a bug), and as such, it should have been clearly stated in both the commit message, and as a comment in the ifnet_byindex() code. Finally, the commit message does not reveal any clues what this change actually tries to accomplish. The claim "Now that ifindex is static to if.c we can unvirtualize it." tell us nothing about the true intent. Sorry for chiming in late, but my sentiment against this change is obvious... > Reviewed by: kp > Differential revision: https://reviews.freebsd.org/D33672 > --- > sys/net/if.c | 216 > ++++++++++++++++++++++++----------------------------------- 1 file > changed, 86 insertions(+), 130 deletions(-) > > diff --git a/sys/net/if.c b/sys/net/if.c > index 4622f978acd9..f148ae8c9c6d 100644 > --- a/sys/net/if.c > +++ b/sys/net/if.c > @@ -311,19 +311,30 @@ VNET_DEFINE(struct ifnethead, ifnet); /* > depend on static init XXX */ VNET_DEFINE(struct ifgrouphead, > ifg_head); > /* Table of ifnet by index. */ > -VNET_DEFINE_STATIC(int, if_index); > -#define V_if_index VNET(if_index) > -VNET_DEFINE_STATIC(int, if_indexlim) = 8; > -#define V_if_indexlim VNET(if_indexlim) > -VNET_DEFINE_STATIC(struct ifnet **, ifindex_table); > -#define V_ifindex_table VNET(ifindex_table) > +static int if_index; > +static int if_indexlim = 8; > +static struct ifnet **ifindex_table; > > SYSCTL_NODE(_net_link_generic, IFMIB_SYSTEM, system, > CTLFLAG_RW | CTLFLAG_MPSAFE, 0, > "Variables global to all interfaces"); > -SYSCTL_INT(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, > - CTLFLAG_VNET | CTLFLAG_RD, &VNET_NAME(if_index), 0, > - "Number of configured interfaces"); > +static int > +sysctl_ifcount(SYSCTL_HANDLER_ARGS) > +{ > + int rv = 0; > + > + IFNET_RLOCK(); > + for (int i = 1; i <= if_index; i++) > + if (ifindex_table[i] != NULL && > + ifindex_table[i]->if_vnet == curvnet) > + rv = i; > + IFNET_RUNLOCK(); > + > + return (sysctl_handle_int(oidp, &rv, 0, req)); > +} > +SYSCTL_PROC(_net_link_generic_system, IFMIB_IFCOUNT, ifcount, > + CTLTYPE_INT | CTLFLAG_VNET | CTLFLAG_RD, NULL, 0, > sysctl_ifcount, "I", > + "Maximum known interface index"); > > /* > * The global network interface list (V_ifnet) and related state > (such as @@ -352,13 +363,19 @@ MALLOC_DEFINE(M_IFMADDR, > "ether_multi", "link-level multicast address"); struct ifnet * > ifnet_byindex(u_int idx) > { > + struct ifnet *ifp; > > NET_EPOCH_ASSERT(); > > - if (__predict_false(idx > V_if_index)) > + if (__predict_false(idx > if_index)) > return (NULL); > > - return (ck_pr_load_ptr(&V_ifindex_table[idx])); > + ifp = ck_pr_load_ptr(&ifindex_table[idx]); > + > + if (curvnet != NULL && ifp != NULL && ifp->if_vnet != > curvnet) > + ifp = NULL; > + > + return (ifp); > } > > struct ifnet * > @@ -374,58 +391,6 @@ ifnet_byindex_ref(u_int idx) > return (ifp); > } > > -/* > - * Allocate an ifindex array entry. > - */ > -static void > -ifindex_alloc(struct ifnet *ifp) > -{ > - u_short idx; > - > - IFNET_WLOCK(); > - /* > - * Try to find an empty slot below V_if_index. If we fail, > take the > - * next slot. > - */ > - for (idx = 1; idx <= V_if_index; idx++) { > - if (V_ifindex_table[idx] == NULL) > - break; > - } > - > - /* Catch if_index overflow. */ > - if (idx >= V_if_indexlim) { > - struct ifnet **new, **old; > - int newlim; > - > - newlim = V_if_indexlim * 2; > - new = malloc(newlim * sizeof(*new), M_IFNET, > M_WAITOK | M_ZERO); > - memcpy(new, V_ifindex_table, V_if_indexlim * > sizeof(*new)); > - old = V_ifindex_table; > - ck_pr_store_ptr(&V_ifindex_table, new); > - V_if_indexlim = newlim; > - epoch_wait_preempt(net_epoch_preempt); > - free(old, M_IFNET); > - } > - if (idx > V_if_index) > - V_if_index = idx; > - > - ifp->if_index = idx; > - ck_pr_store_ptr(&V_ifindex_table[idx], ifp); > - IFNET_WUNLOCK(); > -} > - > -static void > -ifindex_free(u_short idx) > -{ > - > - IFNET_WLOCK_ASSERT(); > - > - ck_pr_store_ptr(&V_ifindex_table[idx], NULL); > - while (V_if_index > 0 && > - V_ifindex_table[V_if_index] == NULL) > - V_if_index--; > -} > - > struct ifaddr * > ifaddr_byindex(u_short idx) > { > @@ -448,33 +413,24 @@ ifaddr_byindex(u_short idx) > */ > > static void > -vnet_if_init(const void *unused __unused) > +if_init(void *arg __unused) > { > > - CK_STAILQ_INIT(&V_ifnet); > - CK_STAILQ_INIT(&V_ifg_head); > - V_ifindex_table = malloc(V_if_indexlim * > sizeof(*V_ifindex_table), > + ifindex_table = malloc(if_indexlim * sizeof(*ifindex_table), > M_IFNET, M_WAITOK | M_ZERO); > - vnet_if_clone_init(); > } > -VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, > vnet_if_init, > - NULL); > +SYSINIT(if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, if_init, NULL); > > -#ifdef VIMAGE > static void > -vnet_if_uninit(const void *unused __unused) > +vnet_if_init(const void *unused __unused) > { > > - VNET_ASSERT(CK_STAILQ_EMPTY(&V_ifnet), ("%s:%d tailq > &V_ifnet=%p " > - "not empty", __func__, __LINE__, &V_ifnet)); > - VNET_ASSERT(CK_STAILQ_EMPTY(&V_ifg_head), ("%s:%d tailq > &V_ifg_head=%p " > - "not empty", __func__, __LINE__, &V_ifg_head)); > - > - free((caddr_t)V_ifindex_table, M_IFNET); > + CK_STAILQ_INIT(&V_ifnet); > + CK_STAILQ_INIT(&V_ifg_head); > + vnet_if_clone_init(); > } > -VNET_SYSUNINIT(vnet_if_uninit, SI_SUB_INIT_IF, SI_ORDER_FIRST, > - vnet_if_uninit, NULL); > -#endif > +VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, > vnet_if_init, > + NULL); > > static void > if_link_ifnet(struct ifnet *ifp) > @@ -568,6 +524,7 @@ static struct ifnet * > if_alloc_domain(u_char type, int numa_domain) > { > struct ifnet *ifp; > + u_short idx; > > KASSERT(numa_domain <= IF_NODOM, ("numa_domain too large")); > if (numa_domain == IF_NODOM) > @@ -607,7 +564,37 @@ if_alloc_domain(u_char type, int numa_domain) > ifp->if_get_counter = if_get_counter_default; > ifp->if_pcp = IFNET_PCP_NONE; > > - ifindex_alloc(ifp); > + /* Allocate an ifindex array entry. */ > + IFNET_WLOCK(); > + /* > + * Try to find an empty slot below if_index. If we fail, > take the > + * next slot. > + */ > + for (idx = 1; idx <= if_index; idx++) { > + if (ifindex_table[idx] == NULL) > + break; > + } > + > + /* Catch if_index overflow. */ > + if (idx >= if_indexlim) { > + struct ifnet **new, **old; > + int newlim; > + > + newlim = if_indexlim * 2; > + new = malloc(newlim * sizeof(*new), M_IFNET, > M_WAITOK | M_ZERO); > + memcpy(new, ifindex_table, if_indexlim * > sizeof(*new)); > + old = ifindex_table; > + ck_pr_store_ptr(&ifindex_table, new); > + if_indexlim = newlim; > + epoch_wait_preempt(net_epoch_preempt); > + free(old, M_IFNET); > + } > + if (idx > if_index) > + if_index = idx; > + > + ifp->if_index = idx; > + ck_pr_store_ptr(&ifindex_table[idx], ifp); > + IFNET_WUNLOCK(); > > return (ifp); > } > @@ -677,23 +664,18 @@ if_free(struct ifnet *ifp) > * epoch and then dereferencing ifp while we peform > if_free(), > * and after if_free() finished, too. > * > - * The reason is the VIMAGE. For some reason it was designed > - * to require all sockets drained before destroying, but not > all > - * ifnets. A vnet destruction calls if_vmove() on ifnet, > which > - * causes ID change. But ID change and a possible > misidentification > - * of an ifnet later is a lesser problem, as it doesn't > crash kernel. > - * A worse problem is that removed interface may outlive the > vnet it > - * belongs too! The if_free_deferred() would see > ifp->if_vnet freed. > + * This early index freeing was important back when ifindex > was > + * virtualized and interface would outlive the vnet. > */ > - CURVNET_SET_QUIET(ifp->if_vnet); > IFNET_WLOCK(); > - MPASS(V_ifindex_table[ifp->if_index] == ifp); > - ifindex_free(ifp->if_index); > + MPASS(ifindex_table[ifp->if_index] == ifp); > + ck_pr_store_ptr(&ifindex_table[ifp->if_index], NULL); > + while (if_index > 0 && ifindex_table[if_index] == NULL) > + if_index--; > IFNET_WUNLOCK(); > > if (refcount_release(&ifp->if_refcount)) > NET_EPOCH_CALL(if_free_deferred, &ifp->if_epoch_ctx); > - CURVNET_RESTORE(); > } > > /* > @@ -837,7 +819,7 @@ if_attach_internal(struct ifnet *ifp, bool vmove) > struct sockaddr_dl *sdl; > struct ifaddr *ifa; > > - MPASS(V_ifindex_table[ifp->if_index] == ifp); > + MPASS(ifindex_table[ifp->if_index] == ifp); > > #ifdef VIMAGE > ifp->if_vnet = curvnet; > @@ -1287,17 +1269,6 @@ if_vmove(struct ifnet *ifp, struct vnet > *new_vnet) if (rc != 0) > return (rc); > > - /* > - * Unlink the ifnet from ifindex_table[] in current vnet, > and shrink > - * the if_index for that vnet if possible. > - * > - * NOTE: IFNET_WLOCK/IFNET_WUNLOCK() are assumed to be > unvirtualized, > - * or we'd lock on one vnet and unlock on another. > - */ > - IFNET_WLOCK(); > - ifindex_free(ifp->if_index); > - IFNET_WUNLOCK(); > - > /* > * Perform interface-specific reassignment tasks, if > provided by > * the driver. > @@ -1309,7 +1280,6 @@ if_vmove(struct ifnet *ifp, struct vnet > *new_vnet) > * Switch to the context of the target vnet. > */ > CURVNET_SET_QUIET(new_vnet); > - ifindex_alloc(ifp); > if_attach_internal(ifp, true); > > #ifdef DEV_BPF > @@ -1945,7 +1915,6 @@ ifa_ifwithnet(const struct sockaddr *addr, int > ignore_ptp, int fibnum) struct ifaddr *ifa_maybe = NULL; > u_int af = addr->sa_family; > const char *addr_data = addr->sa_data, *cplim; > - const struct sockaddr_dl *sdl; > > NET_EPOCH_ASSERT(); > /* > @@ -1953,14 +1922,9 @@ ifa_ifwithnet(const struct sockaddr *addr, int > ignore_ptp, int fibnum) > * so do that if we can. > */ > if (af == AF_LINK) { > - sdl = (const struct sockaddr_dl *)addr; > - if (sdl->sdl_index && sdl->sdl_index <= V_if_index) { > - ifp = ifnet_byindex(sdl->sdl_index); > - if (ifp == NULL) > - return (NULL); > - > - return (ifp->if_addr); > - } > + ifp = ifnet_byindex( > + ((const struct sockaddr_dl *)addr)->sdl_index); > + return (ifp ? ifp->if_addr : NULL); > } > > /* > @@ -4596,24 +4560,16 @@ DB_SHOW_COMMAND(ifnet, db_show_ifnet) > > DB_SHOW_ALL_COMMAND(ifnets, db_show_all_ifnets) > { > - VNET_ITERATOR_DECL(vnet_iter); > struct ifnet *ifp; > u_short idx; > > - VNET_FOREACH(vnet_iter) { > - CURVNET_SET_QUIET(vnet_iter); > -#ifdef VIMAGE > - db_printf("vnet=%p\n", curvnet); > -#endif > - for (idx = 1; idx <= V_if_index; idx++) { > - ifp = V_ifindex_table[idx]; > - if (ifp == NULL) > - continue; > - db_printf( "%20s ifp=%p\n", ifp->if_xname, > ifp); > - if (db_pager_quit) > - break; > - } > - CURVNET_RESTORE(); > + for (idx = 1; idx <= if_index; idx++) { > + ifp = ifindex_table[idx]; > + if (ifp == NULL) > + continue; > + db_printf( "%20s ifp=%p\n", ifp->if_xname, ifp); > + if (db_pager_quit) > + break; > } > } > #endif /* DDB */