1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
.\"
.\" 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$
.\"
.Dd November 6, 2014
.Dt DOMAIN 9
.Os
.Sh NAME
.Nm domain_add ,
.Nm pfctlinput ,
.Nm pfctlinput2 ,
.Nm pffinddomain ,
.Nm pffindproto ,
.Nm pffindtype ,
.Nm DOMAIN_SET
.Nd "network domain management"
.Sh SYNOPSIS
.In sys/param.h
.In sys/kernel.h
.In sys/protosw.h
.In sys/domain.h
.Ft void
.Fn domain_add "void *data"
.Ft void
.Fn pfctlinput "int cmd" "struct sockaddr *sa"
.Ft void
.Fn pfctlinput2 "int cmd" "struct sockaddr *sa" "void *ctlparam"
.Ft struct domain *
.Fn pffinddomain "int family"
.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
(for example the
.Va inetdomain
and
.Va localdomain ) .
.Bd -literal
struct domain {
int dom_family; /* AF_xxx */
char *dom_name;
void (*dom_init) /* initialize domain data structures */
(void);
void (*dom_destroy) /* cleanup structures / state */
(void);
int (*dom_externalize) /* externalize access rights */
(struct mbuf *, struct mbuf **);
void (*dom_dispose) /* dispose of internalized rights */
(struct mbuf *);
struct protosw *dom_protosw, *dom_protoswNPROTOSW;
struct domain *dom_next;
int (*dom_rtattach) /* initialize routing table */
(void **, int);
int (*dom_rtdetach) /* clean up routing table */
(void **, int);
void *(*dom_ifattach)(struct ifnet *);
void (*dom_ifdetach)(struct ifnet *, void *);
int (*dom_ifmtu)(struct ifnet *);
/* af-dependent data on ifnet */
};
.Ed
.Pp
Each domain contains an array of protocol switch structures
.Pq Vt "struct protosw *" ,
one for each socket type supported.
.Bd -literal
struct protosw {
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 */
/* protocol-protocol hooks */
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) */
/* utility hooks */
pr_init_t *pr_init;
pr_destroy_t *pr_destroy;
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 */
struct pr_usrreqs *pr_usrreqs; /* user-protocol hook */
};
.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
.Tn ICMP
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
.Vt "void *"
argument that is passed directly to the protocol's
.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
.Fn domain_add
adds a new protocol domain to the system.
The argument
.Fa data
is cast directly to
.Vt "struct domain *"
within the function, but is declared
.Vt "void *"
in order to prevent compiler warnings when new domains are registered with
.Fn SYSINIT .
In most cases
.Fn domain_add
is not called directly, instead
.Fn DOMAIN_SET
is used.
.Pp
If the new domain has defined an initialization routine, it is called by
.Fn domain_add ;
as well, each of the protocols within the domain that have defined an
initialization routine will have theirs called.
.Pp
Once a domain is added it cannot be unloaded.
This is because there is
no reference counting system in place to determine if there are any
active references from sockets within that domain.
.Pp
.Fn pffinddomain
finds a domain by family.
If the domain cannot be found,
.Dv NULL
is returned.
.Pp
.Fn pffindtype
and
.Fn pffindproto
look up a protocol by its number or by its type.
In most cases, if the protocol or type cannot be found,
.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
is a macro that simplifies the registration of a domain via
.Fn SYSINIT .
The code resulting from the macro expects there to be a domain structure
named
.Dq Fa name Ns Li domain
where
.Fa name
is the argument to
.Fn DOMAIN_SET :
.Bd -literal
struct domain localdomain =
{ AF_LOCAL, "local", unp_init, unp_externalize, unp_dispose,
localsw, &localsw[sizeof(localsw)/sizeof(localsw[0])] };
DOMAIN_SET(local);
.Ed
.Sh RETURN VALUES
Both
.Fn pffindtype
and
.Fn pffindproto
return a
.Vt "struct protosw *"
for the protocol requested.
If the protocol or socket type is not found,
.Dv NULL
is returned.
In the case of
.Fn pffindproto ,
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
This manual page was written by
.An Chad David Aq Mt davidc@acns.ab.ca .
|