The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/hhook.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org>
    3  * Copyright (c) 2010 The FreeBSD Foundation
    4  * All rights reserved.
    5  *
    6  * This software was developed by Lawrence Stewart while studying at the Centre
    7  * for Advanced Internet Architectures, Swinburne University of Technology, made
    8  * possible in part by grants from the FreeBSD Foundation and Cisco University
    9  * Research Program Fund at Community Foundation Silicon Valley.
   10  *
   11  * Portions of this software were developed at the Centre for Advanced
   12  * Internet Architectures, Swinburne University of Technology, Melbourne,
   13  * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation.
   14  *
   15  * Redistribution and use in source and binary forms, with or without
   16  * modification, are permitted provided that the following conditions
   17  * are met:
   18  * 1. Redistributions of source code must retain the above copyright
   19  *    notice, this list of conditions and the following disclaimer.
   20  * 2. Redistributions in binary form must reproduce the above copyright
   21  *    notice, this list of conditions and the following disclaimer in the
   22  *    documentation and/or other materials provided with the distribution.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   34  * SUCH DAMAGE.
   35  *
   36  * $FreeBSD: releng/9.0/sys/sys/hhook.h 220560 2011-04-12 08:13:18Z lstewart $
   37  */
   38 
   39 /*
   40  * A KPI modelled on the pfil framework for instantiating helper hook points
   41  * within the kernel for use by Khelp modules. Originally released as part of
   42  * the NewTCP research project at Swinburne University of Technology's Centre
   43  * for Advanced Internet Architectures, Melbourne, Australia, which was made
   44  * possible in part by a grant from the Cisco University Research Program Fund
   45  * at Community Foundation Silicon Valley. More details are available at:
   46  *   http://caia.swin.edu.au/urp/newtcp/
   47  */
   48 
   49 #ifndef _SYS_HHOOK_H_
   50 #define _SYS_HHOOK_H_
   51 
   52 /* XXXLAS: Is there a way around this? */
   53 #include <sys/lock.h>
   54 #include <sys/rmlock.h>
   55 
   56 /* hhook_head flags. */
   57 #define HHH_ISINVNET            0x00000001 /* Is the hook point in a vnet? */
   58 
   59 /* Flags common to  all register functions. */
   60 #define HHOOK_WAITOK            0x00000001 /* Sleeping allowed. */
   61 #define HHOOK_NOWAIT            0x00000002 /* Sleeping disallowed. */
   62 /* Flags only relevant to hhook_head_register() and hhook_head_is_virtual(). */
   63 #define HHOOK_HEADISINVNET      0x00000100 /* Public proxy for HHH_ISINVNET. */
   64 
   65 /* Helper hook types. */
   66 #define HHOOK_TYPE_TCP          1
   67 
   68 struct helper;
   69 struct osd;
   70 
   71 /* Signature for helper hook functions. */
   72 typedef int (*hhook_func_t)(int32_t hhook_type, int32_t hhook_id, void *udata,
   73     void *ctx_data, void *hdata, struct osd *hosd);
   74 
   75 /*
   76  * Information required to add/remove a helper hook function to/from a helper
   77  * hook point.
   78  */
   79 struct hookinfo {
   80         hhook_func_t    hook_func;
   81         struct helper   *hook_helper;
   82         void            *hook_udata;
   83         int32_t         hook_id;
   84         int32_t         hook_type;
   85 };
   86 
   87 /*
   88  * Ideally this would be private but we need access to the hhh_nhooks member
   89  * variable in order to make the HHOOKS_RUN_IF() macro low impact.
   90  */
   91 struct hhook_head {
   92         STAILQ_HEAD(hhook_list, hhook)  hhh_hooks;
   93         struct rmlock                   hhh_lock;
   94         int32_t                         hhh_id;
   95         int32_t                         hhh_nhooks;
   96         int32_t                         hhh_type;
   97         uint32_t                        hhh_flags;
   98         volatile uint32_t               hhh_refcount;
   99         LIST_ENTRY(hhook_head)          hhh_next;
  100 };
  101 
  102 /* Public KPI functions. */
  103 void    hhook_run_hooks(struct hhook_head *hhh, void *ctx_data, struct osd *hosd);
  104 
  105 int     hhook_add_hook(struct hhook_head *hhh, struct hookinfo *hki,
  106     uint32_t flags);
  107 
  108 int     hhook_add_hook_lookup(struct hookinfo *hki, uint32_t flags);
  109 
  110 int     hhook_remove_hook(struct hhook_head *hhh, struct hookinfo *hki);
  111 
  112 int     hhook_remove_hook_lookup(struct hookinfo *hki);
  113 
  114 int     hhook_head_register(int32_t hhook_type, int32_t hhook_id,
  115     struct hhook_head **hhh, uint32_t flags);
  116 
  117 int     hhook_head_deregister(struct hhook_head *hhh);
  118 
  119 int     hhook_head_deregister_lookup(int32_t hhook_type, int32_t hhook_id);
  120 
  121 struct hhook_head * hhook_head_get(int32_t hhook_type, int32_t hhook_id);
  122 
  123 void    hhook_head_release(struct hhook_head *hhh);
  124 
  125 uint32_t hhook_head_is_virtualised(struct hhook_head *hhh);
  126 
  127 uint32_t hhook_head_is_virtualised_lookup(int32_t hook_type, int32_t hook_id);
  128 
  129 /*
  130  * A wrapper around hhook_run_hooks() that only calls the function if at least
  131  * one helper hook function is registered for the specified helper hook point.
  132  */
  133 #define HHOOKS_RUN_IF(hhh, ctx_data, hosd) do {                         \
  134         if (hhh != NULL && hhh->hhh_nhooks > 0)                         \
  135                 hhook_run_hooks(hhh, ctx_data, hosd);                   \
  136 } while (0)
  137 
  138 /*
  139  * WARNING: This macro should only be used in code paths that execute
  140  * infrequently, otherwise the refcounting overhead would be excessive.
  141  *
  142  * A similar wrapper to HHOOKS_RUN_IF() for situations where the caller prefers
  143  * not to lookup and store the appropriate hhook_head pointer themselves.
  144  */
  145 #define HHOOKS_RUN_LOOKUP_IF(hhook_type, hhook_id, ctx_data, hosd) do { \
  146         struct hhook_head *_hhh;                                        \
  147                                                                         \
  148         _hhh = hhook_head_get(hhook_type, hhook_id);                    \
  149         if (_hhh != NULL) {                                             \
  150                 if (_hhh->hhh_nhooks > 0)                               \
  151                         hhook_run_hooks(_hhh, ctx_data, hosd);          \
  152                 hhook_head_release(_hhh);                               \
  153         }                                                               \
  154 } while (0)
  155 
  156 #endif /* _SYS_HHOOK_H_ */

Cache object: e81b4ff9c1ab58dec46f63ecc1572cf0


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.