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 160619 2006-07-24 15:20: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 * Before we do any setup, make sure to initialize the
202 * zone allocator we get struct sockets from.
203 */
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 mtx_lock(&dom_mtx);
233 KASSERT(domain_init_status == 1, ("domainfinalize called too late!"));
234 domain_init_status = 2;
235 mtx_unlock(&dom_mtx);
236
237 callout_reset(&pffast_callout, 1, pffasttimo, NULL);
238 callout_reset(&pfslow_callout, 1, pfslowtimo, NULL);
239}
240
241struct protosw *
242pffindtype(family, type)
243 int family;
244 int type;
245{
246 register struct domain *dp;
247 register struct protosw *pr;
248
249 for (dp = domains; dp; dp = dp->dom_next)
250 if (dp->dom_family == family)
251 goto found;
252 return (0);
253found:
254 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
255 if (pr->pr_type && pr->pr_type == type)
256 return (pr);
257 return (0);
258}
259
260struct protosw *
261pffindproto(family, protocol, type)
262 int family;
263 int protocol;
264 int type;
265{
266 register struct domain *dp;
267 register struct protosw *pr;
268 struct protosw *maybe = 0;
269
270 if (family == 0)
271 return (0);
272 for (dp = domains; dp; dp = dp->dom_next)
273 if (dp->dom_family == family)
274 goto found;
275 return (0);
--- 9 unchanged lines hidden (view full) ---
285 return (maybe);
286}
287
288/*
289 * The caller must make sure that the new protocol is fully set up and ready to
290 * accept requests before it is registered.
291 */
292int
293pf_proto_register(family, npr)
294 int family;
295 struct protosw *npr;
296{
297 struct domain *dp;
298 struct protosw *pr, *fpr;
299
300 /* Sanity checks. */
301 if (family == 0)
302 return (EPFNOSUPPORT);
303 if (npr->pr_type == 0)
--- 50 unchanged lines hidden (view full) ---
354 return (0);
355}
356
357/*
358 * The caller must make sure the protocol and its functions correctly shut down
359 * all sockets and release all locks and memory references.
360 */
361int
362pf_proto_unregister(family, protocol, type)
363 int family;
364 int protocol;
365 int type;
366{
367 struct domain *dp;
368 struct protosw *pr, *dpr;
369
370 /* Sanity checks. */
371 if (family == 0)
372 return (EPFNOSUPPORT);
373 if (protocol == 0)
--- 48 unchanged lines hidden (view full) ---
422
423 /* Job is done, not more protection required. */
424 mtx_unlock(&Giant);
425
426 return (0);
427}
428
429void
430pfctlinput(cmd, sa)
431 int cmd;
432 struct sockaddr *sa;
433{
434 register struct domain *dp;
435 register struct protosw *pr;
436
437 for (dp = domains; dp; dp = dp->dom_next)
438 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
439 if (pr->pr_ctlinput)
440 (*pr->pr_ctlinput)(cmd, sa, (void *)0);
441}
442
443void
444pfctlinput2(cmd, sa, ctlparam)
445 int cmd;
446 struct sockaddr *sa;
447 void *ctlparam;
448{
449 struct domain *dp;
450 struct protosw *pr;
451
452 if (!sa)
453 return;
454 for (dp = domains; dp; dp = dp->dom_next) {
455 /*
--- 6 unchanged lines hidden (view full) ---
462
463 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
464 if (pr->pr_ctlinput)
465 (*pr->pr_ctlinput)(cmd, sa, ctlparam);
466 }
467}
468
469static void
470pfslowtimo(arg)
471 void *arg;
472{
473 register struct domain *dp;
474 register 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_slowtimo)
481 (*pr->pr_slowtimo)();
482 callout_reset(&pfslow_callout, hz/2, pfslowtimo, NULL);
483}
484
485static void
486pffasttimo(arg)
487 void *arg;
488{
489 register struct domain *dp;
490 register struct protosw *pr;
491
492 NET_ASSERT_GIANT();
493
494 for (dp = domains; dp; dp = dp->dom_next)
495 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
496 if (pr->pr_fasttimo)
497 (*pr->pr_fasttimo)();
498 callout_reset(&pffast_callout, hz/5, pffasttimo, NULL);
499}
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 160619 2006-07-24 15:20: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 * Before we do any setup, make sure to initialize the
202 * zone allocator we get struct sockets from.
203 */
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 mtx_lock(&dom_mtx);
233 KASSERT(domain_init_status == 1, ("domainfinalize called too late!"));
234 domain_init_status = 2;
235 mtx_unlock(&dom_mtx);
236
237 callout_reset(&pffast_callout, 1, pffasttimo, NULL);
238 callout_reset(&pfslow_callout, 1, pfslowtimo, NULL);
239}
240
241struct protosw *
242pffindtype(family, type)
243 int family;
244 int type;
245{
246 register struct domain *dp;
247 register struct protosw *pr;
248
249 for (dp = domains; dp; dp = dp->dom_next)
250 if (dp->dom_family == family)
251 goto found;
252 return (0);
253found:
254 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
255 if (pr->pr_type && pr->pr_type == type)
256 return (pr);
257 return (0);
258}
259
260struct protosw *
261pffindproto(family, protocol, type)
262 int family;
263 int protocol;
264 int type;
265{
266 register struct domain *dp;
267 register struct protosw *pr;
268 struct protosw *maybe = 0;
269
270 if (family == 0)
271 return (0);
272 for (dp = domains; dp; dp = dp->dom_next)
273 if (dp->dom_family == family)
274 goto found;
275 return (0);
--- 9 unchanged lines hidden (view full) ---
285 return (maybe);
286}
287
288/*
289 * The caller must make sure that the new protocol is fully set up and ready to
290 * accept requests before it is registered.
291 */
292int
293pf_proto_register(family, npr)
294 int family;
295 struct protosw *npr;
296{
297 struct domain *dp;
298 struct protosw *pr, *fpr;
299
300 /* Sanity checks. */
301 if (family == 0)
302 return (EPFNOSUPPORT);
303 if (npr->pr_type == 0)
--- 50 unchanged lines hidden (view full) ---
354 return (0);
355}
356
357/*
358 * The caller must make sure the protocol and its functions correctly shut down
359 * all sockets and release all locks and memory references.
360 */
361int
362pf_proto_unregister(family, protocol, type)
363 int family;
364 int protocol;
365 int type;
366{
367 struct domain *dp;
368 struct protosw *pr, *dpr;
369
370 /* Sanity checks. */
371 if (family == 0)
372 return (EPFNOSUPPORT);
373 if (protocol == 0)
--- 48 unchanged lines hidden (view full) ---
422
423 /* Job is done, not more protection required. */
424 mtx_unlock(&Giant);
425
426 return (0);
427}
428
429void
430pfctlinput(cmd, sa)
431 int cmd;
432 struct sockaddr *sa;
433{
434 register struct domain *dp;
435 register struct protosw *pr;
436
437 for (dp = domains; dp; dp = dp->dom_next)
438 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
439 if (pr->pr_ctlinput)
440 (*pr->pr_ctlinput)(cmd, sa, (void *)0);
441}
442
443void
444pfctlinput2(cmd, sa, ctlparam)
445 int cmd;
446 struct sockaddr *sa;
447 void *ctlparam;
448{
449 struct domain *dp;
450 struct protosw *pr;
451
452 if (!sa)
453 return;
454 for (dp = domains; dp; dp = dp->dom_next) {
455 /*
--- 6 unchanged lines hidden (view full) ---
462
463 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
464 if (pr->pr_ctlinput)
465 (*pr->pr_ctlinput)(cmd, sa, ctlparam);
466 }
467}
468
469static void
470pfslowtimo(arg)
471 void *arg;
472{
473 register struct domain *dp;
474 register 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_slowtimo)
481 (*pr->pr_slowtimo)();
482 callout_reset(&pfslow_callout, hz/2, pfslowtimo, NULL);
483}
484
485static void
486pffasttimo(arg)
487 void *arg;
488{
489 register struct domain *dp;
490 register struct protosw *pr;
491
492 NET_ASSERT_GIANT();
493
494 for (dp = domains; dp; dp = dp->dom_next)
495 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
496 if (pr->pr_fasttimo)
497 (*pr->pr_fasttimo)();
498 callout_reset(&pffast_callout, hz/5, pffasttimo, NULL);
499}