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