2001-12-07 20:58:07 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice(s), this list of conditions and the following disclaimer as
|
|
|
|
.\" the first lines of this file unmodified other than the possible
|
|
|
|
.\" addition of one or more copyright notices.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice(s), this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
|
|
|
|
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
.\" DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2012-12-07 02:29:32 +00:00
|
|
|
.Dd December 7, 2012
|
2001-12-07 20:58:07 +00:00
|
|
|
.Dt DOMAIN 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2012-02-23 17:47:19 +00:00
|
|
|
.Nm domain_add ,
|
2001-12-07 20:58:07 +00:00
|
|
|
.Nm pfctlinput ,
|
|
|
|
.Nm pfctlinput2 ,
|
2012-12-07 02:29:32 +00:00
|
|
|
.Nm pffinddomain ,
|
2001-12-07 20:58:07 +00:00
|
|
|
.Nm pffindproto ,
|
|
|
|
.Nm pffindtype ,
|
|
|
|
.Nm DOMAIN_SET
|
|
|
|
.Nd "network domain management"
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/param.h
|
2001-12-26 23:14:04 +00:00
|
|
|
.In sys/kernel.h
|
2001-12-07 20:58:07 +00:00
|
|
|
.In sys/protosw.h
|
|
|
|
.In sys/domain.h
|
|
|
|
.Ft void
|
2012-02-23 17:47:19 +00:00
|
|
|
.Fn domain_add "void *data"
|
2001-12-07 20:58:07 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn pfctlinput "int cmd" "struct sockaddr *sa"
|
|
|
|
.Ft void
|
|
|
|
.Fn pfctlinput2 "int cmd" "struct sockaddr *sa" "void *ctlparam"
|
2012-12-07 02:29:32 +00:00
|
|
|
.Ft struct domain *
|
|
|
|
.Fn pffinddomain "int family"
|
2001-12-07 20:58:07 +00:00
|
|
|
.Ft struct protosw *
|
|
|
|
.Fn pffindproto "int family" "int protocol" "int type"
|
|
|
|
.Ft struct protosw *
|
|
|
|
.Fn pffindtype "int family" "int type"
|
|
|
|
.Ft void
|
|
|
|
.Fn DOMAIN_SET "name"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
Network protocols installed in the system are maintained within what
|
|
|
|
are called domains
|
2002-01-10 17:47:38 +00:00
|
|
|
(for example the
|
|
|
|
.Va inetdomain
|
|
|
|
and
|
|
|
|
.Va localdomain ) .
|
2001-12-07 20:58:07 +00:00
|
|
|
.Bd -literal
|
|
|
|
struct domain {
|
2002-01-10 17:47:38 +00:00
|
|
|
int dom_family; /* AF_xxx */
|
|
|
|
char *dom_name;
|
|
|
|
void (*dom_init) /* initialize domain data structures */
|
2002-10-10 00:32:55 +00:00
|
|
|
(void);
|
2012-11-05 09:45:37 +00:00
|
|
|
void (*dom_destroy) /* cleanup structures / state */
|
|
|
|
(void);
|
2002-01-10 17:47:38 +00:00
|
|
|
int (*dom_externalize) /* externalize access rights */
|
2002-10-10 00:32:55 +00:00
|
|
|
(struct mbuf *, struct mbuf **);
|
2002-01-10 17:47:38 +00:00
|
|
|
void (*dom_dispose) /* dispose of internalized rights */
|
2002-10-10 00:32:55 +00:00
|
|
|
(struct mbuf *);
|
2002-01-10 17:47:38 +00:00
|
|
|
struct protosw *dom_protosw, *dom_protoswNPROTOSW;
|
|
|
|
struct domain *dom_next;
|
|
|
|
int (*dom_rtattach) /* initialize routing table */
|
2002-10-10 00:32:55 +00:00
|
|
|
(void **, int);
|
2012-11-05 09:45:37 +00:00
|
|
|
int (*dom_rtdetach) /* clean up routing table */
|
|
|
|
(void **, int);
|
2002-01-10 17:47:38 +00:00
|
|
|
int dom_rtoffset; /* an arg to rtattach, in bits */
|
|
|
|
int dom_maxrtkey; /* for routing layer */
|
2012-11-05 09:45:37 +00:00
|
|
|
void *(*dom_ifattach)(struct ifnet *);
|
|
|
|
void (*dom_ifdetach)(struct ifnet *, void *);
|
|
|
|
/* af-dependent data on ifnet */
|
2001-12-07 20:58:07 +00:00
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Each domain contains an array of protocol switch structures
|
2002-01-10 17:47:38 +00:00
|
|
|
.Pq Vt "struct protosw *" ,
|
2001-12-07 20:58:07 +00:00
|
|
|
one for each socket type supported.
|
|
|
|
.Bd -literal
|
|
|
|
struct protosw {
|
2002-01-10 17:47:38 +00:00
|
|
|
short pr_type; /* socket type used for */
|
|
|
|
struct domain *pr_domain; /* domain protocol a member of */
|
|
|
|
short pr_protocol; /* protocol number */
|
|
|
|
short pr_flags; /* see below */
|
2001-12-07 20:58:07 +00:00
|
|
|
/* protocol-protocol hooks */
|
2002-01-10 17:47:38 +00:00
|
|
|
pr_input_t *pr_input; /* input to protocol (from below) */
|
|
|
|
pr_output_t *pr_output; /* output to protocol (from above) */
|
|
|
|
pr_ctlinput_t *pr_ctlinput; /* control input (from below) */
|
|
|
|
pr_ctloutput_t *pr_ctloutput; /* control output (from above) */
|
2001-12-07 20:58:07 +00:00
|
|
|
/* utility hooks */
|
2002-01-10 17:47:38 +00:00
|
|
|
pr_init_t *pr_init;
|
2012-11-05 09:45:37 +00:00
|
|
|
pr_destroy_t *pr_destroy;
|
2002-01-10 17:47:38 +00:00
|
|
|
pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */
|
|
|
|
pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */
|
|
|
|
pr_drain_t *pr_drain; /* flush any excess space possible */
|
2001-12-07 20:58:07 +00:00
|
|
|
|
2002-01-10 17:47:38 +00:00
|
|
|
struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */
|
2001-12-07 20:58:07 +00:00
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The following functions handle the registration of a new domain,
|
|
|
|
lookups of specific protocols and protocol types within those domains,
|
|
|
|
and handle control messages from the system.
|
|
|
|
.Pp
|
|
|
|
.Fn pfctlinput
|
|
|
|
is called by the system whenever an event occurs that could affect every
|
|
|
|
domain.
|
|
|
|
Examples of those types of events are routing table changes, interface
|
|
|
|
shutdowns or certain
|
2002-01-10 17:47:38 +00:00
|
|
|
.Tn ICMP
|
2001-12-07 20:58:07 +00:00
|
|
|
message types.
|
|
|
|
When called,
|
|
|
|
.Fn pfctlinput
|
|
|
|
calls the protocol specific
|
|
|
|
.Fn pr_ctlinput
|
|
|
|
function for each protocol in that has defined one, in every domain.
|
|
|
|
.Pp
|
|
|
|
.Fn pfctlinput2
|
|
|
|
provides that same functionality of
|
|
|
|
.Fn pfctlinput ,
|
|
|
|
but with a few additional checks and a new
|
2002-01-10 17:47:38 +00:00
|
|
|
.Vt "void *"
|
|
|
|
argument that is passed directly to the protocol's
|
2001-12-07 20:58:07 +00:00
|
|
|
.Fn pr_ctlinput
|
|
|
|
function.
|
|
|
|
Unlike
|
|
|
|
.Fn pfctlinput ,
|
|
|
|
.Fn pfctlinput2
|
|
|
|
verifies that
|
|
|
|
.Fa sa
|
|
|
|
is not
|
|
|
|
.Dv NULL ,
|
|
|
|
and that only the protocol families that are the same as
|
|
|
|
.Fa sa
|
|
|
|
have their
|
|
|
|
.Fn pr_ctlinput
|
|
|
|
function called.
|
|
|
|
.Pp
|
2012-02-23 17:47:19 +00:00
|
|
|
.Fn domain_add
|
2001-12-07 20:58:07 +00:00
|
|
|
adds a new protocol domain to the system.
|
|
|
|
The argument
|
|
|
|
.Fa data
|
|
|
|
is cast directly to
|
2002-01-10 17:47:38 +00:00
|
|
|
.Vt "struct domain *"
|
2001-12-07 20:58:07 +00:00
|
|
|
within the function, but is declared
|
2002-01-10 17:47:38 +00:00
|
|
|
.Vt "void *"
|
2001-12-07 20:58:07 +00:00
|
|
|
in order to prevent compiler warnings when new domains are registered with
|
|
|
|
.Fn SYSINIT .
|
|
|
|
In most cases
|
2012-02-23 17:47:19 +00:00
|
|
|
.Fn domain_add
|
2001-12-07 20:58:07 +00:00
|
|
|
is not called directly, instead
|
|
|
|
.Fn DOMAIN_SET
|
|
|
|
is used.
|
|
|
|
.Pp
|
2002-01-10 17:47:38 +00:00
|
|
|
If the new domain has defined an initialization routine, it is called by
|
2012-02-23 17:47:19 +00:00
|
|
|
.Fn domain_add ;
|
2001-12-07 20:58:07 +00:00
|
|
|
as well, each of the protocols within the domain that have defined an
|
|
|
|
initialization routine will have theirs called.
|
|
|
|
.Pp
|
2002-01-10 17:47:38 +00:00
|
|
|
Once a domain is added it cannot be unloaded.
|
|
|
|
This is because there is
|
2001-12-07 20:58:07 +00:00
|
|
|
no reference counting system in place to determine if there are any
|
|
|
|
active references from sockets within that domain.
|
|
|
|
.Pp
|
2012-12-07 02:29:32 +00:00
|
|
|
.Fn pffinddomain
|
|
|
|
finds a domain by family.
|
|
|
|
If the domain cannot be found,
|
|
|
|
.Dv NULL
|
|
|
|
is returned.
|
|
|
|
.Pp
|
2001-12-07 20:58:07 +00:00
|
|
|
.Fn pffindtype
|
|
|
|
and
|
|
|
|
.Fn pffindproto
|
2002-01-10 17:47:38 +00:00
|
|
|
look up a protocol by its number or by its type.
|
|
|
|
In most cases, if the protocol or type cannot be found,
|
2001-12-07 20:58:07 +00:00
|
|
|
.Dv NULL
|
|
|
|
is returned, but
|
|
|
|
.Fn pffindproto
|
|
|
|
may return the default if the requested type is
|
|
|
|
.Dv SOCK_RAW ,
|
|
|
|
a protocol switch type of
|
|
|
|
.Dv SOCK_RAW
|
|
|
|
is found, and the domain has a default raw protocol.
|
|
|
|
.Pp
|
|
|
|
Both functions are called by
|
|
|
|
.Fn socreate
|
|
|
|
in order to resolve the protocol for the socket currently being created.
|
|
|
|
.Pp
|
|
|
|
.Fn DOMAIN_SET
|
2002-01-10 17:47:38 +00:00
|
|
|
is a macro that simplifies the registration of a domain via
|
|
|
|
.Fn SYSINIT .
|
2001-12-07 20:58:07 +00:00
|
|
|
The code resulting from the macro expects there to be a domain structure
|
|
|
|
named
|
2002-01-10 17:47:38 +00:00
|
|
|
.Dq Fa name Ns Li domain
|
|
|
|
where
|
|
|
|
.Fa name
|
|
|
|
is the argument to
|
|
|
|
.Fn DOMAIN_SET :
|
2001-12-07 20:58:07 +00:00
|
|
|
.Bd -literal
|
2002-01-10 17:47:38 +00:00
|
|
|
struct domain localdomain =
|
|
|
|
{ AF_LOCAL, "local", unp_init, unp_externalize, unp_dispose,
|
|
|
|
localsw, &localsw[sizeof(localsw)/sizeof(localsw[0])] };
|
2001-12-07 20:58:07 +00:00
|
|
|
|
2002-01-10 17:47:38 +00:00
|
|
|
DOMAIN_SET(local);
|
2001-12-07 20:58:07 +00:00
|
|
|
.Ed
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
Both
|
|
|
|
.Fn pffindtype
|
|
|
|
and
|
|
|
|
.Fn pffindproto
|
|
|
|
return a
|
2002-01-10 17:47:38 +00:00
|
|
|
.Vt "struct protosw *"
|
2001-12-07 20:58:07 +00:00
|
|
|
for the protocol requested.
|
2002-01-10 17:47:38 +00:00
|
|
|
If the protocol or socket type is not found,
|
2001-12-07 20:58:07 +00:00
|
|
|
.Dv NULL
|
|
|
|
is returned.
|
|
|
|
In the case of
|
2002-01-10 17:47:38 +00:00
|
|
|
.Fn pffindproto ,
|
2001-12-07 20:58:07 +00:00
|
|
|
the default protocol may be returned for
|
|
|
|
.Dv SOCK_RAW
|
|
|
|
types if the domain has a default raw protocol.
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr socket 2
|
|
|
|
.Sh AUTHORS
|
2005-06-28 20:15:19 +00:00
|
|
|
This manual page was written by
|
2001-12-07 20:58:07 +00:00
|
|
|
.An Chad David Aq davidc@acns.ab.ca .
|