2 * Copyright (c) 2002-2003 Luigi Rizzo
3 * Copyright (c) 1996 Alex Nash, Paul Traina, Poul-Henning Kamp
4 * Copyright (c) 1994 Ugen J.S.Antsilevich
6 * Idea and grammar partially left from:
7 * Copyright (c) 1993 Daniel Boulet
9 * Redistribution and use in source forms, with and without modification,
10 * are permitted provided that this entire comment appears intact.
12 * Redistribution in binary form may occur without any restrictions.
13 * Obviously, it would be nice if you gave credit where credit is due
14 * but requiring it would be too onerous.
16 * This software is provided ``AS IS'' without any warranties of any kind.
18 * NEW command line interface for IP firewall facility
24 * Options that can be set on the command line.
25 * When reading commands from a file, a subset of the options can also
26 * be applied globally by specifying them before the file name.
27 * After that, each line can contain its own option that changes
29 * XXX The context is not restored after each line.
33 /* boolean options: */
34 int do_value_as_ip; /* show table value as IP */
35 int do_resolv; /* try to resolve all ip to names */
36 int do_time; /* Show time stamps */
37 int do_quiet; /* Be quiet in add and flush */
38 int do_pipe; /* this cmd refers to a pipe */
39 int do_nat; /* this cmd refers to a nat config */
40 int do_dynamic; /* display dynamic rules */
41 int do_expired; /* display expired dynamic rules */
42 int do_compact; /* show rules in compact mode */
43 int do_force; /* do not ask for confirmation */
44 int show_sets; /* display the set each rule belongs to */
45 int test_only; /* only check syntax */
46 int comment_only; /* only print action and comment */
47 int verbose; /* be verbose on some commands */
49 /* The options below can have multiple values. */
51 int do_sort; /* field to sort results (0 = no) */
52 /* valid fields are 1 and above */
54 int use_set; /* work with specified set number */
55 /* 0 means all sets, otherwise apply to set use_set - 1 */
59 extern struct cmdline_opts co;
62 * _s_x is a structure that stores a string <-> token pairs, used in
63 * various places in the parser. Entries are stored in arrays,
64 * with an entry with s=NULL as terminator.
65 * The search routines are match_token() and match_value().
66 * Often, an element with x=0 contains an error string.
115 TOK_DIVERTEDLOOPBACK,
191 * the following macro returns an error message if we run out of
194 #define NEED1(msg) {if (!ac) errx(EX_USAGE, msg);}
196 unsigned long long align_uint64(const uint64_t *pll);
198 /* memory allocation support */
199 void *safe_calloc(size_t number, size_t size);
200 void *safe_realloc(void *ptr, size_t size);
202 /* string comparison functions used for historical compatibility */
203 int _substrcmp(const char *str1, const char* str2);
204 int _substrcmp2(const char *str1, const char* str2, const char* str3);
206 /* utility functions */
207 int match_token(struct _s_x *table, char *string);
208 char const *match_value(struct _s_x *p, int value);
210 int do_cmd(int optname, void *optval, uintptr_t optlen);
213 void n2mask(struct in6_addr *mask, int n);
214 int contigmask(uint8_t *p, int len);
217 * Forward declarations to avoid include way too many headers.
218 * C does not allow duplicated typedefs, so we use the base struct
219 * that the typedef points to.
220 * Should the typedefs use a different type, the compiler will
221 * still detect the change when compiling the body of the
222 * functions involved, so we do not lose error checking.
225 struct _ipfw_insn_altq;
226 struct _ipfw_insn_u32;
227 struct _ipfw_insn_ip6;
228 struct _ipfw_insn_icmp6;
231 * The reserved set numer. This is a constant in ip_fw.h
232 * but we store it in a variable so other files do not depend
233 * in that header just for one constant.
235 extern int resvd_set_number;
237 /* first-level command handlers */
238 void ipfw_add(int ac, char *av[]);
239 void ipfw_show_nat(int ac, char **av);
240 void ipfw_config_pipe(int ac, char **av);
241 void ipfw_config_nat(int ac, char **av);
242 void ipfw_sets_handler(int ac, char *av[]);
243 void ipfw_table_handler(int ac, char *av[]);
244 void ipfw_sysctl_handler(int ac, char *av[], int which);
245 void ipfw_delete(int ac, char *av[]);
246 void ipfw_flush(int force);
247 void ipfw_zero(int ac, char *av[], int optname);
248 void ipfw_list(int ac, char *av[], int show_counters);
251 void altq_set_enabled(int enabled);
252 u_int32_t altq_name_to_qid(const char *name);
254 void print_altq_cmd(struct _ipfw_insn_altq *altqptr);
257 void ipfw_list_pipes(void *data, uint nbytes, int ac, char *av[]);
258 int ipfw_delete_pipe(int pipe_or_queue, int n);
261 void print_unreach6_code(uint16_t code);
262 void print_ip6(struct _ipfw_insn_ip6 *cmd, char const *s);
263 void print_flow6id(struct _ipfw_insn_u32 *cmd);
264 void print_icmp6types(struct _ipfw_insn_u32 *cmd);
265 void print_ext6hdr(struct _ipfw_insn *cmd );
267 struct _ipfw_insn *add_srcip6(struct _ipfw_insn *cmd, char *av);
268 struct _ipfw_insn *add_dstip6(struct _ipfw_insn *cmd, char *av);
270 void fill_flow6(struct _ipfw_insn_u32 *cmd, char *av );
271 void fill_unreach6_code(u_short *codep, char *str);
272 void fill_icmp6types(struct _ipfw_insn_icmp6 *cmd, char *av);
273 int fill_ext6hdr(struct _ipfw_insn *cmd, char *av);