[BACK]Return to if_get.9 CVS log [TXT][DIR] Up to [local] / src / share / man / man9

File: [local] / src / share / man / man9 / if_get.9 (download)

Revision 1.3, Mon Jan 18 09:55:43 2021 UTC (3 years, 4 months ago) by mvs
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, HEAD
Changes since 1.2: +19 -1 lines

Introduce new function if_unit(9). This function returns a pointer the
interface descriptor corresponding to the unique name. This descriptor
is guaranteed to be valid until if_put(9) is called on the returned
pointer. if_unit(9) should replace already existent ifunit() which
returns descriptor not safe for dereference when context was switched.
This allow us to avoid some use-after-free issues in ioctl(2) path.
Also this unifies interface descriptor usage.

ok claudio@ sashan@

.\" $OpenBSD: if_get.9,v 1.3 2021/01/18 09:55:43 mvs Exp $
.\"
.\" Copyright (c) 2015 Martin Pieuchot
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: January 18 2021 $
.Dt IF_GET 9
.Os
.Sh NAME
.Nm if_get ,
.Nm if_unit ,
.Nm if_put
.Nd get an interface pointer from an interface index
.Sh SYNOPSIS
.In net/if.h
.Ft struct ifnet *
.Fn if_get "unsigned int ifidx"
.Ft struct ifnet *
.Fn if_unit "const char *name"
.Ft void
.Fn if_put "struct ifnet *ifp"
.Sh DESCRIPTION
The
.Fn if_get
function returns a pointer to the interface descriptor corresponding to the
unique index
.Fa ifidx .
This descriptor is guaranteed to be valid until
.Fn if_put
is called on the returned pointer.
.Pp
The index value
.Dv 0
is never associated with an interface descriptor and can be used to determine if
an interface index is valid or not.
.Pp
The
.Fn if_unit
function returns a pointer to the interface descriptor corresponding to the
unique name
.Fa name .
This descriptor is guaranteed to be valid until
.Fn if_put
is called on the returned pointer.
.Pp
The
.Fn if_put
function releases a reference on the interface descriptor pointed by
.Fa ifp .
If
.Fa ifp
is a
.Dv NULL
pointer, no action occurs.
.Sh CONTEXT
.Fn if_get ,
.Fn if_unit
and
.Fn if_put
can be called during autoconf, from process context, or from interrupt context.
.Sh RETURN VALUES
.Fn if_get
returns a pointer to an interface descriptor if the index is valid, otherwise
.Dv NULL .
.Pp
.Fn if_unit
returns a pointer to an interface descriptor if the interface with present
name exists, otherwise
.Dv NULL .