netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
iptables.c File Reference
#include <getopt.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
#include <limits.h>
#include <unistd.h>
#include <iptables.h>
#include <xtables.h>
#include <fcntl.h>
#include "xshared.h"
Include dependency graph for iptables.c:

Macros

#define TRUE   1
 
#define FALSE   0
 
#define CMD_NONE   0x0000U
 
#define CMD_INSERT   0x0001U
 
#define CMD_DELETE   0x0002U
 
#define CMD_DELETE_NUM   0x0004U
 
#define CMD_REPLACE   0x0008U
 
#define CMD_APPEND   0x0010U
 
#define CMD_LIST   0x0020U
 
#define CMD_FLUSH   0x0040U
 
#define CMD_ZERO   0x0080U
 
#define CMD_NEW_CHAIN   0x0100U
 
#define CMD_DELETE_CHAIN   0x0200U
 
#define CMD_SET_POLICY   0x0400U
 
#define CMD_RENAME_CHAIN   0x0800U
 
#define CMD_LIST_RULES   0x1000U
 
#define CMD_ZERO_NUM   0x2000U
 
#define CMD_CHECK   0x4000U
 
#define NUMBER_OF_CMD   16
 
#define OPT_FRAGMENT   0x00800U
 
#define NUMBER_OF_OPT   ARRAY_SIZE(optflags)
 
#define opts   iptables_globals.opts
 
#define prog_name   iptables_globals.program_name
 
#define prog_vers   iptables_globals.program_version
 
#define IP_PARTS_NATIVE(n)
 
#define IP_PARTS(n)   IP_PARTS_NATIVE(ntohl(n))
 

Functions

void iptables_exit_error (enum xtables_exittype status, const char *msg,...) __attribute__((noreturn
 
void format (printf, 2, 3)))
 
int for_each_chain4 (int(*fn)(const xt_chainlabel, int, struct xtc_handle *), int verbose, int builtinstoo, struct xtc_handle *handle)
 
int flush_entries4 (const xt_chainlabel chain, int verbose, struct xtc_handle *handle)
 
int delete_chain4 (const xt_chainlabel chain, int verbose, struct xtc_handle *handle)
 
void print_rule4 (const struct ipt_entry *e, struct xtc_handle *h, const char *chain, int counters)
 
int do_command4 (int argc, char *argv[], char **table, struct xtc_handle **handle, bool restore)
 

Variables

struct xtables_globals iptables_globals
 

Macro Definition Documentation

#define CMD_APPEND   0x0010U

Referenced by do_command4().

#define CMD_CHECK   0x4000U

Referenced by do_command4().

#define CMD_DELETE   0x0002U

Referenced by do_command4().

#define CMD_DELETE_CHAIN   0x0200U

Referenced by do_command4().

#define CMD_DELETE_NUM   0x0004U

Referenced by do_command4().

#define CMD_FLUSH   0x0040U

Referenced by do_command4().

#define CMD_INSERT   0x0001U

Referenced by do_command4().

#define CMD_LIST   0x0020U

Referenced by do_command4().

#define CMD_LIST_RULES   0x1000U

Referenced by do_command4().

#define CMD_NEW_CHAIN   0x0100U

Referenced by do_command4().

#define CMD_NONE   0x0000U

Referenced by do_command4().

#define CMD_RENAME_CHAIN   0x0800U

Referenced by do_command4().

#define CMD_REPLACE   0x0008U

Referenced by do_command4().

#define CMD_SET_POLICY   0x0400U

Referenced by do_command4().

#define CMD_ZERO   0x0080U

Referenced by do_command4().

#define CMD_ZERO_NUM   0x2000U

Referenced by do_command4().

#define FALSE   0

Referenced by do_command4().

#define IP_PARTS (   n)    IP_PARTS_NATIVE(ntohl(n))
#define IP_PARTS_NATIVE (   n)
Value:
(unsigned int)((n)>>24)&0xFF, \
(unsigned int)((n)>>16)&0xFF, \
(unsigned int)((n)>>8)&0xFF, \
(unsigned int)((n)&0xFF)
#define NUMBER_OF_CMD   16
#define NUMBER_OF_OPT   ARRAY_SIZE(optflags)
#define OPT_FRAGMENT   0x00800U

Referenced by do_command4().

#define opts   iptables_globals.opts

Referenced by do_command4().

#define prog_name   iptables_globals.program_name

Referenced by do_command4(), and iptables_exit_error().

#define prog_vers   iptables_globals.program_version

Referenced by do_command4(), and iptables_exit_error().

#define TRUE   1

Referenced by do_command4().

Function Documentation

int delete_chain4 ( const xt_chainlabel  chain,
int  verbose,
struct xtc_handle handle 
)

References for_each_chain4(), and iptc_delete_chain().

Referenced by do_command4(), and iptables_restore_main().

Here is the call graph for this function:

Here is the caller graph for this function:

int do_command4 ( int  argc,
char *  argv[],
char **  table,
struct xtc_handle **  handle,
bool  restore 
)

References iptables_command_state::argv, xt_counters::bcnt, iptables_command_state::c, CMD_APPEND, CMD_CHECK, CMD_DELETE, CMD_DELETE_CHAIN, CMD_DELETE_NUM, CMD_FLUSH, CMD_INSERT, CMD_LIST, CMD_LIST_RULES, CMD_NEW_CHAIN, CMD_NONE, CMD_RENAME_CHAIN, CMD_REPLACE, CMD_SET_POLICY, CMD_ZERO, CMD_ZERO_NUM, command_default(), ipt_entry::counters, delete_chain4(), dump_entries(), exit_printhelp(), exit_tryhelp(), FALSE, ipt_ip::flags, flush_entries4(), iptables_command_state::fw, generic_opt_check(), ipt_ip::iniface, ipt_ip::iniface_mask, iptables_command_state::invert, ipt_ip::invflags, ipt_entry::ip, IPT_F_FRAG, IPT_F_GOTO, IPT_INV_DSTIP, IPT_INV_SRCIP, iptables_globals, iptc_create_chain(), iptc_delete_num_entry(), iptc_init(), iptc_is_chain(), iptc_rename_chain(), iptc_set_policy(), iptc_strerror(), iptc_zero_counter(), iptables_command_state::jumpto, line, xtables_match::m, xtables_rule_match::match, iptables_command_state::matches, xtables_match::mflags, xtables_match::next, xtables_target::next, xtables_rule_match::next, NULL, OPT_COUNTERS, OPT_DESTINATION, OPT_EXPANDED, OPT_FRAGMENT, OPT_JUMP, OPT_LINENUMBERS, OPT_NUMERIC, OPT_PROTOCOL, OPT_SOURCE, OPT_VERBOSE, OPT_VIANAMEIN, OPT_VIANAMEOUT, iptables_command_state::options, opts, xtables_globals::orig_opts, ipt_ip::outiface, ipt_ip::outiface_mask, PARAMETER_PROBLEM, xt_counters::pcnt, prog_name, prog_vers, ipt_ip::proto, iptables_command_state::protocol, RESOURCE_PROBLEM, size, xtables_target::t, xt_entry_target::target, iptables_command_state::target, xtables_target::tflags, TRUE, xtables_target::used, VERSION_PROBLEM, xs_init_target(), XT_INV_PROTO, xt_params, XT_STANDARD_TARGET, xtables_calloc(), xtables_error, xtables_find_match(), xtables_find_target(), xtables_free_opts(), xtables_ipparse_multiple(), xtables_load_ko(), xtables_lock(), xtables_matches, xtables_modprobe_program, xtables_option_mfcall(), xtables_option_tfcall(), xtables_parse_interface(), xtables_parse_protocol(), xtables_rule_matches_free(), xtables_targets, XTF_LOAD_MUST_SUCCEED, and XTF_TRY_LOAD.

Referenced by iptables_main(), and iptables_restore_main().

Here is the call graph for this function:

Here is the caller graph for this function:

int flush_entries4 ( const xt_chainlabel  chain,
int  verbose,
struct xtc_handle handle 
)

References for_each_chain4(), and iptc_flush_entries().

Referenced by do_command4(), and iptables_restore_main().

Here is the call graph for this function:

Here is the caller graph for this function:

int for_each_chain4 ( int(*)(const xt_chainlabel, int, struct xtc_handle *)  fn,
int  verbose,
int  builtinstoo,
struct xtc_handle handle 
)

References iptc_builtin(), iptc_first_chain(), iptc_next_chain(), and xtables_malloc().

Referenced by delete_chain4(), flush_entries4(), and iptables_restore_main().

Here is the call graph for this function:

Here is the caller graph for this function:

void format ( printf  ,
,
 
)
void iptables_exit_error ( enum xtables_exittype  status,
const char *  msg,
  ... 
)

References exit_tryhelp(), PARAMETER_PROBLEM, prog_name, prog_vers, VERSION_PROBLEM, and xtables_free_opts().

Here is the call graph for this function:

Variable Documentation

struct xtables_globals iptables_globals
Initial value:
= {
.option_offset = 0,
.program_version = IPTABLES_VERSION,
.orig_opts = original_opts,
.exit_err = iptables_exit_error,
}
int xtables_compatible_revision(const char *name, uint8_t revision, int opt)
Definition: xtables.c:742
void iptables_exit_error(enum xtables_exittype status, const char *msg,...) __attribute__((noreturn
Definition: iptables.c:269

Referenced by do_command4(), iptables_main(), iptables_restore_main(), and iptables_save_main().