xref: /freebsd/share/man/man9/domain.9 (revision 7a0a89d2cb29ee2c383600fa59e42d714a6dcbcb)
1.\"
2.\" Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice(s), this list of conditions and the following disclaimer as
9.\"    the first lines of this file unmodified other than the possible
10.\"    addition of one or more copyright notices.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice(s), this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25.\" DAMAGE.
26.\"
27.\" $FreeBSD$
28.\"
29.Dd December 23, 2008
30.Dt DOMAIN 9
31.Os
32.Sh NAME
33.Nm net_add_domain ,
34.Nm pfctlinput ,
35.Nm pfctlinput2 ,
36.Nm pffindproto ,
37.Nm pffindtype ,
38.Nm DOMAIN_SET
39.Nd "network domain management"
40.Sh SYNOPSIS
41.In sys/param.h
42.In sys/kernel.h
43.In sys/protosw.h
44.In sys/domain.h
45.Ft void
46.Fn net_add_domain "void *data"
47.Ft void
48.Fn pfctlinput "int cmd" "struct sockaddr *sa"
49.Ft void
50.Fn pfctlinput2 "int cmd" "struct sockaddr *sa" "void *ctlparam"
51.Ft struct protosw *
52.Fn pffindproto "int family" "int protocol" "int type"
53.Ft struct protosw *
54.Fn pffindtype "int family" "int type"
55.Ft void
56.Fn DOMAIN_SET "name"
57.Sh DESCRIPTION
58Network protocols installed in the system are maintained within what
59are called domains
60(for example the
61.Va inetdomain
62and
63.Va localdomain ) .
64.Bd -literal
65struct domain {
66	int	dom_family;		/* AF_xxx */
67	char	*dom_name;
68	void	(*dom_init)		/* initialize domain data structures */
69		(void);
70	int	(*dom_externalize)	/* externalize access rights */
71		(struct mbuf *, struct mbuf **);
72	void	(*dom_dispose)		/* dispose of internalized rights */
73		(struct mbuf *);
74	struct	protosw *dom_protosw, *dom_protoswNPROTOSW;
75	struct	domain *dom_next;
76	int	(*dom_rtattach)		/* initialize routing table */
77		(void **, int);
78	int	dom_rtoffset;		/* an arg to rtattach, in bits */
79	int	dom_maxrtkey;		/* for routing layer */
80};
81.Ed
82.Pp
83Each domain contains an array of protocol switch structures
84.Pq Vt "struct protosw *" ,
85one for each socket type supported.
86.Bd -literal
87struct protosw {
88	short	pr_type;		/* socket type used for */
89	struct	domain *pr_domain;	/* domain protocol a member of */
90	short	pr_protocol;		/* protocol number */
91	short	pr_flags;		/* see below */
92/* protocol-protocol hooks */
93	pr_input_t *pr_input;		/* input to protocol (from below) */
94	pr_output_t *pr_output;		/* output to protocol (from above) */
95	pr_ctlinput_t *pr_ctlinput;	/* control input (from below) */
96	pr_ctloutput_t *pr_ctloutput;	/* control output (from above) */
97/* user-protocol hook */
98	pr_usrreq_t	*pr_ousrreq;
99/* utility hooks */
100	pr_init_t *pr_init;
101	pr_fasttimo_t *pr_fasttimo;	/* fast timeout (200ms) */
102	pr_slowtimo_t *pr_slowtimo;	/* slow timeout (500ms) */
103	pr_drain_t *pr_drain;		/* flush any excess space possible */
104
105	struct	pr_usrreqs *pr_usrreqs;	/* supersedes pr_usrreq() */
106};
107.Ed
108.Pp
109The following functions handle the registration of a new domain,
110lookups of specific protocols and protocol types within those domains,
111and handle control messages from the system.
112.Pp
113.Fn pfctlinput
114is called by the system whenever an event occurs that could affect every
115domain.
116Examples of those types of events are routing table changes, interface
117shutdowns or certain
118.Tn ICMP
119message types.
120When called,
121.Fn pfctlinput
122calls the protocol specific
123.Fn pr_ctlinput
124function for each protocol in that has defined one, in every domain.
125.Pp
126.Fn pfctlinput2
127provides that same functionality of
128.Fn pfctlinput ,
129but with a few additional checks and a new
130.Vt "void *"
131argument that is passed directly to the protocol's
132.Fn pr_ctlinput
133function.
134Unlike
135.Fn pfctlinput ,
136.Fn pfctlinput2
137verifies that
138.Fa sa
139is not
140.Dv NULL ,
141and that only the protocol families that are the same as
142.Fa sa
143have their
144.Fn pr_ctlinput
145function called.
146.Pp
147.Fn net_add_domain
148adds a new protocol domain to the system.
149The argument
150.Fa data
151is cast directly to
152.Vt "struct domain *"
153within the function, but is declared
154.Vt "void *"
155in order to prevent compiler warnings when new domains are registered with
156.Fn SYSINIT .
157In most cases
158.Fn net_add_domain
159is not called directly, instead
160.Fn DOMAIN_SET
161is used.
162.Pp
163If the new domain has defined an initialization routine, it is called by
164.Fn net_add_domain ;
165as well, each of the protocols within the domain that have defined an
166initialization routine will have theirs called.
167.Pp
168Once a domain is added it cannot be unloaded.
169This is because there is
170no reference counting system in place to determine if there are any
171active references from sockets within that domain.
172.Pp
173.Fn pffindtype
174and
175.Fn pffindproto
176look up a protocol by its number or by its type.
177In most cases, if the protocol or type cannot be found,
178.Dv NULL
179is returned, but
180.Fn pffindproto
181may return the default if the requested type is
182.Dv SOCK_RAW ,
183a protocol switch type of
184.Dv SOCK_RAW
185is found, and the domain has a default raw protocol.
186.Pp
187Both functions are called by
188.Fn socreate
189in order to resolve the protocol for the socket currently being created.
190.Pp
191.Fn DOMAIN_SET
192is a macro that simplifies the registration of a domain via
193.Fn SYSINIT .
194The code resulting from the macro expects there to be a domain structure
195named
196.Dq Fa name Ns Li domain
197where
198.Fa name
199is the argument to
200.Fn DOMAIN_SET :
201.Bd -literal
202struct domain localdomain =
203{ AF_LOCAL, "local", unp_init, unp_externalize, unp_dispose,
204  localsw, &localsw[sizeof(localsw)/sizeof(localsw[0])] };
205
206DOMAIN_SET(local);
207.Ed
208.Sh RETURN VALUES
209Both
210.Fn pffindtype
211and
212.Fn pffindproto
213return a
214.Vt "struct protosw *"
215for the protocol requested.
216If the protocol or socket type is not found,
217.Dv NULL
218is returned.
219In the case of
220.Fn pffindproto ,
221the default protocol may be returned for
222.Dv SOCK_RAW
223types if the domain has a default raw protocol.
224.Sh SEE ALSO
225.Xr socket 2
226.Sh AUTHORS
227This manual page was written by
228.An Chad David Aq davidc@acns.ab.ca .
229