1/*- 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/kern/uipc_domain.c 169624 2007-05-16 20:41:08Z rwatson $"); |
34 35#include <sys/param.h> 36#include <sys/socket.h> 37#include <sys/protosw.h> 38#include <sys/domain.h> 39#include <sys/eventhandler.h> 40#include <sys/mbuf.h> 41#include <sys/kernel.h> --- 150 unchanged lines hidden (view full) --- 192 193 uma_zone_set_max(socket_zone, maxsockets); 194} 195 196/* ARGSUSED*/ 197static void 198domaininit(void *dummy) 199{ |
200 |
201 /* 202 * Before we do any setup, make sure to initialize the 203 * zone allocator we get struct sockets from. 204 */ |
205 socket_zone = uma_zcreate("socket", sizeof(struct socket), NULL, NULL, 206 NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); 207 uma_zone_set_max(socket_zone, maxsockets); 208 EVENTHANDLER_REGISTER(maxsockets_change, socket_zone_change, NULL, 209 EVENTHANDLER_PRI_FIRST); 210 211 if (max_linkhdr < 16) /* XXX */ 212 max_linkhdr = 16; --- 11 unchanged lines hidden (view full) --- 224 domain_init_status = 1; 225 mtx_unlock(&dom_mtx); 226} 227 228/* ARGSUSED*/ 229static void 230domainfinalize(void *dummy) 231{ |
232 |
233 mtx_lock(&dom_mtx); 234 KASSERT(domain_init_status == 1, ("domainfinalize called too late!")); 235 domain_init_status = 2; 236 mtx_unlock(&dom_mtx); 237 238 callout_reset(&pffast_callout, 1, pffasttimo, NULL); 239 callout_reset(&pfslow_callout, 1, pfslowtimo, NULL); 240} 241 242struct protosw * |
243pffindtype(int family, int type) |
244{ |
245 struct domain *dp; 246 struct protosw *pr; |
247 248 for (dp = domains; dp; dp = dp->dom_next) 249 if (dp->dom_family == family) 250 goto found; 251 return (0); 252found: 253 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 254 if (pr->pr_type && pr->pr_type == type) 255 return (pr); 256 return (0); 257} 258 259struct protosw * |
260pffindproto(int family, int protocol, int type) |
261{ |
262 struct domain *dp; 263 struct protosw *pr; |
264 struct protosw *maybe = 0; 265 266 if (family == 0) 267 return (0); 268 for (dp = domains; dp; dp = dp->dom_next) 269 if (dp->dom_family == family) 270 goto found; 271 return (0); --- 9 unchanged lines hidden (view full) --- 281 return (maybe); 282} 283 284/* 285 * The caller must make sure that the new protocol is fully set up and ready to 286 * accept requests before it is registered. 287 */ 288int |
289pf_proto_register(int family, struct protosw *npr) |
290{ 291 struct domain *dp; 292 struct protosw *pr, *fpr; 293 294 /* Sanity checks. */ 295 if (family == 0) 296 return (EPFNOSUPPORT); 297 if (npr->pr_type == 0) --- 50 unchanged lines hidden (view full) --- 348 return (0); 349} 350 351/* 352 * The caller must make sure the protocol and its functions correctly shut down 353 * all sockets and release all locks and memory references. 354 */ 355int |
356pf_proto_unregister(int family, int protocol, int type) |
357{ 358 struct domain *dp; 359 struct protosw *pr, *dpr; 360 361 /* Sanity checks. */ 362 if (family == 0) 363 return (EPFNOSUPPORT); 364 if (protocol == 0) --- 48 unchanged lines hidden (view full) --- 413 414 /* Job is done, not more protection required. */ 415 mtx_unlock(&Giant); 416 417 return (0); 418} 419 420void |
421pfctlinput(int cmd, struct sockaddr *sa) |
422{ |
423 struct domain *dp; 424 struct protosw *pr; |
425 426 for (dp = domains; dp; dp = dp->dom_next) 427 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 428 if (pr->pr_ctlinput) 429 (*pr->pr_ctlinput)(cmd, sa, (void *)0); 430} 431 432void |
433pfctlinput2(int cmd, struct sockaddr *sa, void *ctlparam) |
434{ 435 struct domain *dp; 436 struct protosw *pr; 437 438 if (!sa) 439 return; 440 for (dp = domains; dp; dp = dp->dom_next) { 441 /* --- 6 unchanged lines hidden (view full) --- 448 449 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 450 if (pr->pr_ctlinput) 451 (*pr->pr_ctlinput)(cmd, sa, ctlparam); 452 } 453} 454 455static void |
456pfslowtimo(void *arg) |
457{ |
458 struct domain *dp; 459 struct protosw *pr; |
460 461 NET_ASSERT_GIANT(); 462 463 for (dp = domains; dp; dp = dp->dom_next) 464 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 465 if (pr->pr_slowtimo) 466 (*pr->pr_slowtimo)(); 467 callout_reset(&pfslow_callout, hz/2, pfslowtimo, NULL); 468} 469 470static void |
471pffasttimo(void *arg) |
472{ |
473 struct domain *dp; 474 struct protosw *pr; |
475 476 NET_ASSERT_GIANT(); 477 478 for (dp = domains; dp; dp = dp->dom_next) 479 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 480 if (pr->pr_fasttimo) 481 (*pr->pr_fasttimo)(); 482 callout_reset(&pffast_callout, hz/5, pffasttimo, NULL); 483} |