Path: blob/main/sys/netpfil/ipfw/pmod/ip_fw_pmod.c
39536 views
/*-1* Copyright (c) 2017 Yandex LLC2* Copyright (c) 2017 Andrey V. Elsukov <[email protected]>3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/systm.h>29#include <sys/kernel.h>30#include <sys/lock.h>31#include <sys/malloc.h>32#include <sys/module.h>33#include <sys/rwlock.h>34#include <sys/socket.h>3536#include <net/if.h>37#include <net/vnet.h>3839#include <netinet/in.h>40#include <netinet/ip_var.h>41#include <netinet/ip_fw.h>4243#include <netpfil/ipfw/ip_fw_private.h>44#include <netpfil/ipfw/pmod/pmod.h>4546static int47vnet_ipfw_pmod_init(const void *arg __unused)48{49int error;5051error = tcpmod_init(&V_layer3_chain, IS_DEFAULT_VNET(curvnet));52return (error);53}5455static int56vnet_ipfw_pmod_uninit(const void *arg __unused)57{5859tcpmod_uninit(&V_layer3_chain, IS_DEFAULT_VNET(curvnet));60return (0);61}6263static int64ipfw_pmod_modevent(module_t mod, int type, void *unused)65{6667switch (type) {68case MOD_LOAD:69case MOD_UNLOAD:70break;71default:72return (EOPNOTSUPP);73}74return (0);75}7677static moduledata_t ipfw_pmod_mod = {78"ipfw_pmod",79ipfw_pmod_modevent,80081};8283/* Define startup order. */84#define IPFW_PMOD_SI_SUB_FIREWALL SI_SUB_PROTO_IFATTACHDOMAIN85#define IPFW_PMOD_MODEVENT_ORDER (SI_ORDER_ANY - 128) /* after ipfw */86#define IPFW_PMOD_MODULE_ORDER (IPFW_PMOD_MODEVENT_ORDER + 1)87#define IPFW_PMOD_VNET_ORDER (IPFW_PMOD_MODEVENT_ORDER + 2)8889DECLARE_MODULE(ipfw_pmod, ipfw_pmod_mod, IPFW_PMOD_SI_SUB_FIREWALL,90IPFW_PMOD_MODULE_ORDER);91MODULE_DEPEND(ipfw_pmod, ipfw, 3, 3, 3);92MODULE_VERSION(ipfw_pmod, 1);9394VNET_SYSINIT(vnet_ipfw_pmod_init, IPFW_PMOD_SI_SUB_FIREWALL,95IPFW_PMOD_VNET_ORDER, vnet_ipfw_pmod_init, NULL);96VNET_SYSUNINIT(vnet_ipfw_pmod_uninit, IPFW_PMOD_SI_SUB_FIREWALL,97IPFW_PMOD_VNET_ORDER, vnet_ipfw_pmod_uninit, NULL);9899100