14790953fSMatthew Dillon /*
2*4408d548SBill Yuan * Copyright (c) 2014 - 2018 The DragonFly Project. All rights reserved.
34790953fSMatthew Dillon *
44790953fSMatthew Dillon * This code is derived from software contributed to The DragonFly Project
59187b359SBill Yuan * by Bill Yuan <bycn82@dragonflybsd.org>
64790953fSMatthew Dillon *
74790953fSMatthew Dillon * Redistribution and use in source and binary forms, with or without
84790953fSMatthew Dillon * modification, are permitted provided that the following conditions
94790953fSMatthew Dillon * are met:
104790953fSMatthew Dillon *
114790953fSMatthew Dillon * 1. Redistributions of source code must retain the above copyright
124790953fSMatthew Dillon * notice, this list of conditions and the following disclaimer.
134790953fSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
144790953fSMatthew Dillon * notice, this list of conditions and the following disclaimer in
154790953fSMatthew Dillon * the documentation and/or other materials provided with the
164790953fSMatthew Dillon * distribution.
174790953fSMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
184790953fSMatthew Dillon * contributors may be used to endorse or promote products derived
194790953fSMatthew Dillon * from this software without specific, prior written permission.
204790953fSMatthew Dillon *
214790953fSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
224790953fSMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
234790953fSMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
244790953fSMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
254790953fSMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
264790953fSMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
274790953fSMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
284790953fSMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
294790953fSMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
304790953fSMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
314790953fSMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324790953fSMatthew Dillon * SUCH DAMAGE.
334790953fSMatthew Dillon */
344790953fSMatthew Dillon
354790953fSMatthew Dillon #include <stdio.h>
364790953fSMatthew Dillon #include <stdlib.h>
374790953fSMatthew Dillon
384790953fSMatthew Dillon #include <net/if.h>
394790953fSMatthew Dillon #include <net/route.h>
404790953fSMatthew Dillon #include <net/pfil.h>
414790953fSMatthew Dillon #include <netinet/in.h>
424790953fSMatthew Dillon
4359ea0e34SBill Yuan #include <net/ipfw3/ip_fw3.h>
449187b359SBill Yuan #include "../../../sbin/ipfw3/ipfw3.h"
454790953fSMatthew Dillon #include "ipfw3_nat.h"
464790953fSMatthew Dillon
474790953fSMatthew Dillon
484790953fSMatthew Dillon void
parse_nat(ipfw_insn ** cmd,int * ac,char ** av[])494790953fSMatthew Dillon parse_nat(ipfw_insn **cmd, int *ac, char **av[])
504790953fSMatthew Dillon {
514790953fSMatthew Dillon NEXT_ARG1;
524790953fSMatthew Dillon (*cmd)->opcode = O_NAT_NAT;
534790953fSMatthew Dillon (*cmd)->module = MODULE_NAT_ID;
544790953fSMatthew Dillon (*cmd)->len = F_INSN_SIZE(ipfw_insn_nat);
554790953fSMatthew Dillon (*cmd)->arg1 = strtoul(**av, NULL, 10);
564790953fSMatthew Dillon ((ipfw_insn_nat *)(*cmd))->nat = NULL;
574790953fSMatthew Dillon NEXT_ARG1;
584790953fSMatthew Dillon }
594790953fSMatthew Dillon
604790953fSMatthew Dillon void
show_nat(ipfw_insn * cmd,int show_or)616ce8c93fSBill Yuan show_nat(ipfw_insn *cmd, int show_or)
624790953fSMatthew Dillon {
634790953fSMatthew Dillon printf(" nat %u", cmd->arg1);
644790953fSMatthew Dillon }
654790953fSMatthew Dillon
664790953fSMatthew Dillon void
load_module(register_func function,register_keyword keyword)674790953fSMatthew Dillon load_module(register_func function, register_keyword keyword)
684790953fSMatthew Dillon {
693b6ebdc3SBill Yuan keyword(MODULE_NAT_ID, O_NAT_NAT, "nat", ACTION);
704790953fSMatthew Dillon function(MODULE_NAT_ID, O_NAT_NAT,
714790953fSMatthew Dillon (parser_func)parse_nat, (shower_func)show_nat);
724790953fSMatthew Dillon }
73