1aed810cbSSepherosa Ziehau /*
2aed810cbSSepherosa Ziehau * Copyright (c) 2008 The DragonFly Project. All rights reserved.
3aed810cbSSepherosa Ziehau *
4aed810cbSSepherosa Ziehau * This code is derived from software contributed to The DragonFly Project
5aed810cbSSepherosa Ziehau * by Sepherosa Ziehau <sepherosa@gmail.com>
6aed810cbSSepherosa Ziehau *
7aed810cbSSepherosa Ziehau * Redistribution and use in source and binary forms, with or without
8aed810cbSSepherosa Ziehau * modification, are permitted provided that the following conditions
9aed810cbSSepherosa Ziehau * are met:
10aed810cbSSepherosa Ziehau *
11aed810cbSSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright
12aed810cbSSepherosa Ziehau * notice, this list of conditions and the following disclaimer.
13aed810cbSSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright
14aed810cbSSepherosa Ziehau * notice, this list of conditions and the following disclaimer in
15aed810cbSSepherosa Ziehau * the documentation and/or other materials provided with the
16aed810cbSSepherosa Ziehau * distribution.
17aed810cbSSepherosa Ziehau * 3. Neither the name of The DragonFly Project nor the names of its
18aed810cbSSepherosa Ziehau * contributors may be used to endorse or promote products derived
19aed810cbSSepherosa Ziehau * from this software without specific, prior written permission.
20aed810cbSSepherosa Ziehau *
21aed810cbSSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22aed810cbSSepherosa Ziehau * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23aed810cbSSepherosa Ziehau * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24aed810cbSSepherosa Ziehau * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25aed810cbSSepherosa Ziehau * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26aed810cbSSepherosa Ziehau * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27aed810cbSSepherosa Ziehau * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28aed810cbSSepherosa Ziehau * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29aed810cbSSepherosa Ziehau * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30aed810cbSSepherosa Ziehau * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31aed810cbSSepherosa Ziehau * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32aed810cbSSepherosa Ziehau * SUCH DAMAGE.
33aed810cbSSepherosa Ziehau *
3481a24a55SSepherosa Ziehau * $DragonFly: src/sys/net/ipfw/ip_fw2_glue.c,v 1.3 2008/09/13 10:23:39 sephe Exp $
35aed810cbSSepherosa Ziehau */
36aed810cbSSepherosa Ziehau
37aed810cbSSepherosa Ziehau #include <sys/param.h>
38aed810cbSSepherosa Ziehau #include <sys/socketvar.h>
39aed810cbSSepherosa Ziehau
40aed810cbSSepherosa Ziehau #include <net/if.h>
41*b0e7fb3eSSepherosa Ziehau #include <net/netisr2.h>
42aed810cbSSepherosa Ziehau
43aed810cbSSepherosa Ziehau #include <netinet/in.h>
44aed810cbSSepherosa Ziehau
45aed810cbSSepherosa Ziehau #include <net/ipfw/ip_fw2.h>
46aed810cbSSepherosa Ziehau
4781a24a55SSepherosa Ziehau ip_fw_chk_t *ip_fw_chk_ptr;
4881a24a55SSepherosa Ziehau ip_fw_dn_io_t *ip_fw_dn_io_ptr;
49*b0e7fb3eSSepherosa Ziehau ip_fw_ctl_t *ip_fw_ctl_ptr;
5081a24a55SSepherosa Ziehau int ip_fw_loaded;
5181a24a55SSepherosa Ziehau int fw_enable = 1;
5281a24a55SSepherosa Ziehau int fw_one_pass = 1;
5381a24a55SSepherosa Ziehau
54aed810cbSSepherosa Ziehau int
ip_fw_sockopt(struct sockopt * sopt)55aed810cbSSepherosa Ziehau ip_fw_sockopt(struct sockopt *sopt)
56aed810cbSSepherosa Ziehau {
57*b0e7fb3eSSepherosa Ziehau int error;
58*b0e7fb3eSSepherosa Ziehau
59*b0e7fb3eSSepherosa Ziehau ASSERT_NETISR0;
60aed810cbSSepherosa Ziehau
61aed810cbSSepherosa Ziehau /*
62aed810cbSSepherosa Ziehau * Disallow modifications in really-really secure mode, but still allow
63aed810cbSSepherosa Ziehau * the logging counters to be reset.
64aed810cbSSepherosa Ziehau */
65aed810cbSSepherosa Ziehau if (sopt->sopt_name == IP_FW_ADD ||
66aed810cbSSepherosa Ziehau (sopt->sopt_dir == SOPT_SET && sopt->sopt_name != IP_FW_RESETLOG)) {
67aed810cbSSepherosa Ziehau if (securelevel >= 3)
68aed810cbSSepherosa Ziehau return EPERM;
69aed810cbSSepherosa Ziehau }
70aed810cbSSepherosa Ziehau if (IPFW_LOADED)
71aed810cbSSepherosa Ziehau error = ip_fw_ctl_ptr(sopt);
72aed810cbSSepherosa Ziehau else
73aed810cbSSepherosa Ziehau error = ENOPROTOOPT;
74*b0e7fb3eSSepherosa Ziehau return (error);
75aed810cbSSepherosa Ziehau }
76