diff -r 58347fad0298 sys/modules/khelp/Makefile --- a/sys/modules/khelp/Makefile Fri Dec 10 11:48:19 2010 +1100 +++ b/sys/modules/khelp/Makefile Fri Dec 10 11:48:35 2010 +1100 @@ -1,5 +1,7 @@ # $FreeBSD$ -SUBDIR= h_ertt +SUBDIR= h_ertt \ + h_test1 \ + h_test2 .include diff -r 58347fad0298 sys/modules/khelp/h_test1/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/modules/khelp/h_test1/Makefile Fri Dec 10 11:48:35 2010 +1100 @@ -0,0 +1,9 @@ +# $FreeBSD$ + +.include + +.PATH: ${.CURDIR}/../../../netinet +KMOD= h_test1 +SRCS= h_test1.c + +.include diff -r 58347fad0298 sys/modules/khelp/h_test2/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/modules/khelp/h_test2/Makefile Fri Dec 10 11:48:35 2010 +1100 @@ -0,0 +1,9 @@ +# $FreeBSD$ + +.include + +.PATH: ${.CURDIR}/../../../netinet +KMOD= h_test2 +SRCS= h_test2.c + +.include diff -r 58347fad0298 sys/netinet/h_test1.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/netinet/h_test1.c Fri Dec 10 11:48:35 2010 +1100 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, Melbourne, Australia by + * Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +static int test1_mod_init(void); +static int test1_mod_destroy(void); + +struct test1 { + uint32_t est_in_count; + uint32_t est_out_count; +}; + +struct helper test1_helper = { + .mod_init = test1_mod_init, + .mod_destroy = test1_mod_destroy, + .h_flags = HELPER_NEEDS_OSD, + .h_classes = HELPER_CLASS_TCP +}; + +static void +test1_hook(int hhook_type, int hhook_id, void *udata, + void *ctx_data, void *hdata, struct osd *hosd) +{ + struct test1 *data; + + data = hdata; + + if (hhook_id == HHOOK_TCP_EST_IN) + data->est_in_count++; + else if (hhook_id == HHOOK_TCP_EST_OUT) + data->est_out_count++; +} + +static int +test1_mod_init(void) +{ + int ret; + + ret = hhook_add_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, + &test1_helper, &test1_hook, NULL, HHOOK_WAITOK); + if (ret) + return (ret); + + return hhook_add_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_OUT, + &test1_helper, &test1_hook, NULL, HHOOK_WAITOK); +} + +static int +test1_mod_destroy(void) +{ + int ret; + + ret = hhook_remove_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, + &test1_hook, NULL); + ret += hhook_remove_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_OUT, + &test1_hook, NULL); + + return (ret); +} + + +DECLARE_HELPER_UMA(test1, &test1_helper, 1, sizeof(struct test1), NULL, NULL); diff -r 58347fad0298 sys/netinet/h_test2.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sys/netinet/h_test2.c Fri Dec 10 11:48:35 2010 +1100 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, Melbourne, Australia by + * Lawrence Stewart under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +static int test2_mod_init(void); +static int test2_mod_destroy(void); + +struct test2 { + uint32_t est_in_count; + uint32_t est_out_count; +}; + +struct helper test2_helper = { + .mod_init = test2_mod_init, + .mod_destroy = test2_mod_destroy, + .h_flags = HELPER_NEEDS_OSD, + .h_classes = HELPER_CLASS_TCP +}; + +static void +test2_hook(int hhook_type, int hhook_id, void *udata, + void *ctx_data, void *hdata, struct osd *hosd) +{ + struct test2 *data; + + data = hdata; + + if (hhook_id == HHOOK_TCP_EST_IN) + data->est_in_count++; + else if (hhook_id == HHOOK_TCP_EST_OUT) + data->est_out_count++; +} + +static int +test2_mod_init(void) +{ + int ret; + + ret = hhook_add_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, + &test2_helper, &test2_hook, NULL, HHOOK_WAITOK); + if (ret) + return (ret); + + return hhook_add_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_OUT, + &test2_helper, &test2_hook, NULL, HHOOK_WAITOK); +} + +static int +test2_mod_destroy(void) +{ + int ret; + + ret = hhook_remove_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_IN, + &test2_hook, NULL); + ret += hhook_remove_hook_lookup(HHOOK_TYPE_TCP, HHOOK_TCP_EST_OUT, + &test2_hook, NULL); + + return (ret); +} + + +DECLARE_HELPER_UMA(test2, &test2_helper, 1, sizeof(struct test2), NULL, NULL);