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 7, 2001 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/protosw.h 43.In sys/domain.h 44.Ft void 45.Fn net_add_domain "void *data" 46.Ft void 47.Fn pfctlinput "int cmd" "struct sockaddr *sa" 48.Ft void 49.Fn pfctlinput2 "int cmd" "struct sockaddr *sa" "void *ctlparam" 50.Ft struct protosw * 51.Fn pffindproto "int family" "int protocol" "int type" 52.Ft struct protosw * 53.Fn pffindtype "int family" "int type" 54.Ft void 55.Fn DOMAIN_SET "name" 56.Sh DESCRIPTION 57Network protocols installed in the system are maintained within what 58are called domains 59.Pq for example the inetdomain and localdomain . 60.Bd -literal 61 62struct domain { 63 int dom_family; /* AF_xxx */ 64 char *dom_name; 65 void (*dom_init) /* initialize domain data structures */ 66 __P((void)); 67 int (*dom_externalize) /* externalize access rights */ 68 __P((struct mbuf *, struct mbuf **)); 69 void (*dom_dispose) /* dispose of internalized rights */ 70 __P((struct mbuf *)); 71 struct protosw *dom_protosw, *dom_protoswNPROTOSW; 72 struct domain *dom_next; 73 int (*dom_rtattach) /* initialize routing table */ 74 __P((void **, int)); 75 int dom_rtoffset; /* an arg to rtattach, in bits */ 76 int dom_maxrtkey; /* for routing layer */ 77}; 78.Ed 79.Pp 80Each domain contains an array of protocol switch structures 81.Pq Vt struct protosw * , 82one for each socket type supported. 83.Bd -literal 84 85struct protosw { 86 short pr_type; /* socket type used for */ 87 struct domain *pr_domain; /* domain protocol a member of */ 88 short pr_protocol; /* protocol number */ 89 short pr_flags; /* see below */ 90/* protocol-protocol hooks */ 91 pr_input_t *pr_input; /* input to protocol (from below) */ 92 pr_output_t *pr_output; /* output to protocol (from above) */ 93 pr_ctlinput_t *pr_ctlinput; /* control input (from below) */ 94 pr_ctloutput_t *pr_ctloutput; /* control output (from above) */ 95/* user-protocol hook */ 96 pr_usrreq_t *pr_ousrreq; 97/* utility hooks */ 98 pr_init_t *pr_init; 99 pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */ 100 pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */ 101 pr_drain_t *pr_drain; /* flush any excess space possible */ 102 103 struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ 104 struct pfil_head pr_pfh; 105}; 106.Ed 107.Pp 108The following functions handle the registration of a new domain, 109lookups of specific protocols and protocol types within those domains, 110and handle control messages from the system. 111.Pp 112.Fn pfctlinput 113is called by the system whenever an event occurs that could affect every 114domain. 115Examples of those types of events are routing table changes, interface 116shutdowns or certain 117.Dv ICMP 118message types. 119When called, 120.Fn pfctlinput 121calls the protocol specific 122.Fn pr_ctlinput 123function for each protocol in that has defined one, in every domain. 124.Pp 125.Fn pfctlinput2 126provides that same functionality of 127.Fn pfctlinput , 128but with a few additional checks and a new 129.Vt void * 130argument that is passed directly to the protocols 131.Fn pr_ctlinput 132function. 133Unlike 134.Fn pfctlinput , 135.Fn pfctlinput2 136verifies that 137.Fa sa 138is not 139.Dv NULL , 140and that only the protocol families that are the same as 141.Fa sa 142have their 143.Fn pr_ctlinput 144function called. 145.Pp 146.Fn net_add_domain 147adds a new protocol domain to the system. 148The argument 149.Fa data 150is cast directly to 151.Vt struct domain * 152within the function, but is declared 153.Vt void * 154in order to prevent compiler warnings when new domains are registered with 155.Fn SYSINIT . 156In most cases 157.Fn net_add_domain 158is not called directly, instead 159.Fn DOMAIN_SET 160is used. 161.Pp 162If the new domain has defined an initialization routine it is called by 163.Fn net_add_domain ; 164as well, each of the protocols within the domain that have defined an 165initialization routine will have theirs called. 166.Pp 167Once a domain is added it cannot be unloaded. This is because there is 168no reference counting system in place to determine if there are any 169active references from sockets within that domain. 170.Pp 171.Fn pffindtype 172and 173.Fn pffindproto 174lookup a protocol by its number or by its type. 175In most cases if the protocol or type cannot be found 176.Dv NULL 177is returned, but 178.Fn pffindproto 179may return the default if the requested type is 180.Dv SOCK_RAW , 181a protocol switch type of 182.Dv SOCK_RAW 183is found, and the domain has a default raw protocol. 184.Pp 185Both functions are called by 186.Fn socreate 187in order to resolve the protocol for the socket currently being created. 188.Pp 189.Fn DOMAIN_SET 190is a macro that simplifies the registration of a domain via SYSINIT. 191The code resulting from the macro expects there to be a domain structure 192named 193.Vt namedomain 194where name is the argument 195.Fa name . 196.Bd -literal 197 198 struct domain localdomain = 199 { AF_LOCAL, "local", unp_init, unp_externalize, unp_dispose, 200 localsw, &localsw[sizeof(localsw)/sizeof(localsw[0])] }; 201 202 DOMAIN_SET(local); 203 204.Ed 205.Sh RETURN VALUES 206Both 207.Fn pffindtype 208and 209.Fn pffindproto 210return a 211.Vt struct protosw * 212for the protocol requested. 213If the protocol or socket type is not found 214.Dv NULL 215is returned. 216In the case of 217.Fn pffindproto 218the default protocol may be returned for 219.Dv SOCK_RAW 220types if the domain has a default raw protocol. 221.Sh SEE ALSO 222.Xr socket 2 223.Sh AUTHORS 224This man page was written by 225.An Chad David Aq davidc@acns.ab.ca . 226