The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
libiptc.c File Reference
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/version.h>
#include "linux_list.h"
Include dependency graph for libiptc.c:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  counter_map
 
struct  rule_head
 
struct  chain_head
 
struct  iptcb_chain_start
 
struct  iptcb_chain_foot
 
struct  iptcb_chain_error
 

Macros

#define DEBUGP(x, args...)
 
#define DEBUGP_C(x, args...)
 
#define IPT_LIB_DIR   "/usr/local/lib/iptables"
 
#define CHECK(h)
 
#define IPTCB_CHAIN_START_SIZE
 
#define IPTCB_CHAIN_FOOT_SIZE
 
#define IPTCB_CHAIN_ERROR_SIZE
 

Enumerations

enum  iptcc_rule_type { IPTCC_R_STANDARD, IPTCC_R_MODULE, IPTCC_R_FALLTHROUGH, IPTCC_R_JUMP }
 

Functions

static struct chain_headiptcc_alloc_chain_head (const char *name, int hooknum)
 
static struct rule_headiptcc_alloc_rule (struct chain_head *c, unsigned int size)
 
static void set_changed (TC_HANDLE_T h)
 
static int iptcb_get_number (const STRUCT_ENTRY *i, const STRUCT_ENTRY *seek, unsigned int *pos)
 
static int iptcb_get_entry_n (STRUCT_ENTRY *i, unsigned int number, unsigned int *pos, STRUCT_ENTRY **pe)
 
static STRUCT_ENTRYiptcb_get_entry (TC_HANDLE_T h, unsigned int offset)
 
static unsigned int iptcb_entry2index (const TC_HANDLE_T h, const STRUCT_ENTRY *seek)
 
static STRUCT_ENTRYiptcb_offset2entry (TC_HANDLE_T h, unsigned int offset)
 
static unsigned long iptcb_entry2offset (const TC_HANDLE_T h, const STRUCT_ENTRY *e)
 
static unsigned int iptcb_offset2index (const TC_HANDLE_T h, unsigned int offset)
 
static unsigned int iptcb_ent_is_hook_entry (STRUCT_ENTRY *e, TC_HANDLE_T h)
 
static unsigned int iptcc_is_builtin (struct chain_head *c)
 
static struct rule_headiptcc_get_rule_num (struct chain_head *c, unsigned int rulenum)
 
static struct rule_headiptcc_get_rule_num_reverse (struct chain_head *c, unsigned int rulenum)
 
static struct chain_headiptcc_find_chain_by_offset (TC_HANDLE_T handle, unsigned int offset)
 
static struct chain_headiptcc_find_label (const char *name, TC_HANDLE_T handle)
 
static void iptcc_delete_rule (struct rule_head *r)
 
static int __iptcc_p_del_policy (TC_HANDLE_T h, unsigned int num)
 
static void iptc_insert_chain (TC_HANDLE_T h, struct chain_head *c)
 
static void __iptcc_p_add_chain (TC_HANDLE_T h, struct chain_head *c, unsigned int offset, unsigned int *num)
 
static int cache_add_entry (STRUCT_ENTRY *e, TC_HANDLE_T h, STRUCT_ENTRY **prev, unsigned int *num)
 
static int parse_table (TC_HANDLE_T h)
 
static int iptcc_compile_rule (TC_HANDLE_T h, STRUCT_REPLACE *repl, struct rule_head *r)
 
static int iptcc_compile_chain (TC_HANDLE_T h, STRUCT_REPLACE *repl, struct chain_head *c)
 
static int iptcc_compile_chain_offsets (TC_HANDLE_T h, struct chain_head *c, unsigned int *offset, unsigned int *num)
 
static int iptcc_compile_table_prep (TC_HANDLE_T h, unsigned int *size)
 
static int iptcc_compile_table (TC_HANDLE_T h, STRUCT_REPLACE *repl)
 
static TC_HANDLE_T alloc_handle (const char *tablename, unsigned int size, unsigned int num_rules)
 
TC_HANDLE_T TC_INIT (const char *tablename)
 
void TC_FREE (TC_HANDLE_T *h)
 
static int print_match (const STRUCT_ENTRY_MATCH *m)
 
void TC_DUMP_ENTRIES (const TC_HANDLE_T handle)
 
int TC_IS_CHAIN (const char *chain, const TC_HANDLE_T handle)
 
static void iptcc_chain_iterator_advance (TC_HANDLE_T handle)
 
const char * TC_FIRST_CHAIN (TC_HANDLE_T *handle)
 
const char * TC_NEXT_CHAIN (TC_HANDLE_T *handle)
 
const STRUCT_ENTRYTC_FIRST_RULE (const char *chain, TC_HANDLE_T *handle)
 
const STRUCT_ENTRYTC_NEXT_RULE (const STRUCT_ENTRY *prev, TC_HANDLE_T *handle)
 
unsigned int TC_NUM_RULES (const char *chain, TC_HANDLE_T *handle)
 
const STRUCT_ENTRYTC_GET_RULE (const char *chain, unsigned int n, TC_HANDLE_T *handle)
 
const char * standard_target_map (int verdict)
 
const char * TC_GET_TARGET (const STRUCT_ENTRY *ce, TC_HANDLE_T *handle)
 
int TC_BUILTIN (const char *chain, const TC_HANDLE_T handle)
 
const char * TC_GET_POLICY (const char *chain, STRUCT_COUNTERS *counters, TC_HANDLE_T *handle)
 
static int iptcc_standard_map (struct rule_head *r, int verdict)
 
static int iptcc_map_target (const TC_HANDLE_T handle, struct rule_head *r)
 
int TC_INSERT_ENTRY (const IPT_CHAINLABEL chain, const STRUCT_ENTRY *e, unsigned int rulenum, TC_HANDLE_T *handle)
 
int TC_REPLACE_ENTRY (const IPT_CHAINLABEL chain, const STRUCT_ENTRY *e, unsigned int rulenum, TC_HANDLE_T *handle)
 
int TC_APPEND_ENTRY (const IPT_CHAINLABEL chain, const STRUCT_ENTRY *e, TC_HANDLE_T *handle)
 
static int match_different (const STRUCT_ENTRY_MATCH *a, const unsigned char *a_elems, const unsigned char *b_elems, unsigned char **maskptr)
 
static int target_same (struct rule_head *a, struct rule_head *b, const unsigned char *mask)
 
static unsigned char * is_same (const STRUCT_ENTRY *a, const STRUCT_ENTRY *b, unsigned char *matchmask)
 
int TC_DELETE_ENTRY (const IPT_CHAINLABEL chain, const STRUCT_ENTRY *origfw, unsigned char *matchmask, TC_HANDLE_T *handle)
 
int TC_DELETE_NUM_ENTRY (const IPT_CHAINLABEL chain, unsigned int rulenum, TC_HANDLE_T *handle)
 
const char * TC_CHECK_PACKET (const IPT_CHAINLABEL chain, STRUCT_ENTRY *entry, TC_HANDLE_T *handle)
 
int TC_FLUSH_ENTRIES (const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 
int TC_ZERO_ENTRIES (const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 
STRUCT_COUNTERSTC_READ_COUNTER (const IPT_CHAINLABEL chain, unsigned int rulenum, TC_HANDLE_T *handle)
 
int TC_ZERO_COUNTER (const IPT_CHAINLABEL chain, unsigned int rulenum, TC_HANDLE_T *handle)
 
int TC_SET_COUNTER (const IPT_CHAINLABEL chain, unsigned int rulenum, STRUCT_COUNTERS *counters, TC_HANDLE_T *handle)
 
int TC_CREATE_CHAIN (const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 
int TC_GET_REFERENCES (unsigned int *ref, const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 
int TC_DELETE_CHAIN (const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 
int TC_RENAME_CHAIN (const IPT_CHAINLABEL oldname, const IPT_CHAINLABEL newname, TC_HANDLE_T *handle)
 
int TC_SET_POLICY (const IPT_CHAINLABEL chain, const IPT_CHAINLABEL policy, STRUCT_COUNTERS *counters, TC_HANDLE_T *handle)
 
static void subtract_counters (STRUCT_COUNTERS *answer, const STRUCT_COUNTERS *a, const STRUCT_COUNTERS *b)
 
static void counters_nomap (STRUCT_COUNTERS_INFO *newcounters, unsigned int index)
 
static void counters_normal_map (STRUCT_COUNTERS_INFO *newcounters, STRUCT_REPLACE *repl, unsigned int index, unsigned int mappos)
 
static void counters_map_zeroed (STRUCT_COUNTERS_INFO *newcounters, STRUCT_REPLACE *repl, unsigned int index, unsigned int mappos, STRUCT_COUNTERS *counters)
 
static void counters_map_set (STRUCT_COUNTERS_INFO *newcounters, unsigned int index, STRUCT_COUNTERS *counters)
 
int TC_COMMIT (TC_HANDLE_T *handle)
 
int TC_GET_RAW_SOCKET ()
 
const char * TC_STRERROR (int err)
 

Variables

static int sockfd = -1
 
static int sockfd_use = 0
 
static void * iptc_fn = NULL
 
static const char * hooknames []
 
 STRUCT_TC_HANDLE
 
struct list_head chains
 
struct chain_headchain_iterator_cur
 
struct rule_headrule_iterator_cur
 
STRUCT_GETINFO info
 
STRUCT_GET_ENTRIESentries
 

Macro Definition Documentation

#define CHECK (   h)
#define DEBUGP (   x,
  args... 
)
#define DEBUGP_C (   x,
  args... 
)
#define IPT_LIB_DIR   "/usr/local/lib/iptables"
#define IPTCB_CHAIN_ERROR_SIZE
Value:
(sizeof(STRUCT_ENTRY) + \
ALIGN(sizeof(struct ipt_error_target)))
#define STRUCT_ENTRY
Definition: libip4tc.c:44
#define ALIGN
Definition: libip4tc.c:113
#define IPTCB_CHAIN_FOOT_SIZE
Value:
(sizeof(STRUCT_ENTRY) + \
#define STRUCT_ENTRY
Definition: libip4tc.c:44
#define ALIGN
Definition: libip4tc.c:113
#define STRUCT_STANDARD_TARGET
Definition: libip4tc.c:50
#define IPTCB_CHAIN_START_SIZE
Value:
(sizeof(STRUCT_ENTRY) + \
ALIGN(sizeof(struct ipt_error_target)))
#define STRUCT_ENTRY
Definition: libip4tc.c:44
#define ALIGN
Definition: libip4tc.c:113

Enumeration Type Documentation

Enumerator
IPTCC_R_STANDARD 
IPTCC_R_MODULE 
IPTCC_R_FALLTHROUGH 
IPTCC_R_JUMP 

Function Documentation

static void __iptcc_p_add_chain ( TC_HANDLE_T  h,
struct chain_head c,
unsigned int  offset,
unsigned int *  num 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int __iptcc_p_del_policy ( TC_HANDLE_T  h,
unsigned int  num 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static TC_HANDLE_T alloc_handle ( const char *  tablename,
unsigned int  size,
unsigned int  num_rules 
)
static

Here is the caller graph for this function:

static int cache_add_entry ( STRUCT_ENTRY e,
TC_HANDLE_T  h,
STRUCT_ENTRY **  prev,
unsigned int *  num 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void counters_map_set ( STRUCT_COUNTERS_INFO newcounters,
unsigned int  index,
STRUCT_COUNTERS counters 
)
static

Here is the caller graph for this function:

static void counters_map_zeroed ( STRUCT_COUNTERS_INFO newcounters,
STRUCT_REPLACE repl,
unsigned int  index,
unsigned int  mappos,
STRUCT_COUNTERS counters 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void counters_nomap ( STRUCT_COUNTERS_INFO newcounters,
unsigned int  index 
)
static

Here is the caller graph for this function:

static void counters_normal_map ( STRUCT_COUNTERS_INFO newcounters,
STRUCT_REPLACE repl,
unsigned int  index,
unsigned int  mappos 
)
static

Here is the caller graph for this function:

static void iptc_insert_chain ( TC_HANDLE_T  h,
struct chain_head c 
)
inlinestatic

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned int iptcb_ent_is_hook_entry ( STRUCT_ENTRY e,
TC_HANDLE_T  h 
)
inlinestatic

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned int iptcb_entry2index ( const TC_HANDLE_T  h,
const STRUCT_ENTRY seek 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned long iptcb_entry2offset ( const TC_HANDLE_T  h,
const STRUCT_ENTRY e 
)
inlinestatic

Here is the caller graph for this function:

static STRUCT_ENTRY* iptcb_get_entry ( TC_HANDLE_T  h,
unsigned int  offset 
)
inlinestatic

Here is the caller graph for this function:

static int iptcb_get_entry_n ( STRUCT_ENTRY i,
unsigned int  number,
unsigned int *  pos,
STRUCT_ENTRY **  pe 
)
inlinestatic
static int iptcb_get_number ( const STRUCT_ENTRY i,
const STRUCT_ENTRY seek,
unsigned int *  pos 
)
inlinestatic

Here is the caller graph for this function:

static STRUCT_ENTRY* iptcb_offset2entry ( TC_HANDLE_T  h,
unsigned int  offset 
)
inlinestatic

Here is the caller graph for this function:

static unsigned int iptcb_offset2index ( const TC_HANDLE_T  h,
unsigned int  offset 
)
inlinestatic

Here is the call graph for this function:

static struct chain_head* iptcc_alloc_chain_head ( const char *  name,
int  hooknum 
)
static

Here is the caller graph for this function:

static struct rule_head* iptcc_alloc_rule ( struct chain_head c,
unsigned int  size 
)
static

Here is the caller graph for this function:

static void iptcc_chain_iterator_advance ( TC_HANDLE_T  handle)
static

Here is the caller graph for this function:

static int iptcc_compile_chain ( TC_HANDLE_T  h,
STRUCT_REPLACE repl,
struct chain_head c 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int iptcc_compile_chain_offsets ( TC_HANDLE_T  h,
struct chain_head c,
unsigned int *  offset,
unsigned int *  num 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int iptcc_compile_rule ( TC_HANDLE_T  h,
STRUCT_REPLACE repl,
struct rule_head r 
)
inlinestatic

Here is the caller graph for this function:

static int iptcc_compile_table ( TC_HANDLE_T  h,
STRUCT_REPLACE repl 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int iptcc_compile_table_prep ( TC_HANDLE_T  h,
unsigned int *  size 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static void iptcc_delete_rule ( struct rule_head r)
static

Here is the caller graph for this function:

static struct chain_head* iptcc_find_chain_by_offset ( TC_HANDLE_T  handle,
unsigned int  offset 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static struct chain_head* iptcc_find_label ( const char *  name,
TC_HANDLE_T  handle 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static struct rule_head* iptcc_get_rule_num ( struct chain_head c,
unsigned int  rulenum 
)
static

Here is the caller graph for this function:

static struct rule_head* iptcc_get_rule_num_reverse ( struct chain_head c,
unsigned int  rulenum 
)
static

Here is the caller graph for this function:

static unsigned int iptcc_is_builtin ( struct chain_head c)
static

Here is the caller graph for this function:

static int iptcc_map_target ( const TC_HANDLE_T  handle,
struct rule_head r 
)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int iptcc_standard_map ( struct rule_head r,
int  verdict 
)
static

Here is the caller graph for this function:

static unsigned char* is_same ( const STRUCT_ENTRY a,
const STRUCT_ENTRY b,
unsigned char *  matchmask 
)
static

Here is the caller graph for this function:

static int match_different ( const STRUCT_ENTRY_MATCH a,
const unsigned char *  a_elems,
const unsigned char *  b_elems,
unsigned char **  maskptr 
)
inlinestatic

Here is the caller graph for this function:

static int parse_table ( TC_HANDLE_T  h)
static

Here is the call graph for this function:

Here is the caller graph for this function:

static int print_match ( const STRUCT_ENTRY_MATCH m)
inlinestatic
static void set_changed ( TC_HANDLE_T  h)
static

Here is the caller graph for this function:

const char* standard_target_map ( int  verdict)

Here is the caller graph for this function:

static void subtract_counters ( STRUCT_COUNTERS answer,
const STRUCT_COUNTERS a,
const STRUCT_COUNTERS b 
)
static

Here is the caller graph for this function:

static int target_same ( struct rule_head a,
struct rule_head b,
const unsigned char *  mask 
)
inlinestatic

Here is the caller graph for this function:

int TC_APPEND_ENTRY ( const IPT_CHAINLABEL  chain,
const STRUCT_ENTRY e,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

int TC_BUILTIN ( const char *  chain,
const TC_HANDLE_T  handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

const char* TC_CHECK_PACKET ( const IPT_CHAINLABEL  chain,
STRUCT_ENTRY entry,
TC_HANDLE_T handle 
)

Here is the caller graph for this function:

int TC_COMMIT ( TC_HANDLE_T handle)

Here is the call graph for this function:

int TC_CREATE_CHAIN ( const IPT_CHAINLABEL  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_DELETE_CHAIN ( const IPT_CHAINLABEL  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_DELETE_ENTRY ( const IPT_CHAINLABEL  chain,
const STRUCT_ENTRY origfw,
unsigned char *  matchmask,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_DELETE_NUM_ENTRY ( const IPT_CHAINLABEL  chain,
unsigned int  rulenum,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void TC_DUMP_ENTRIES ( const TC_HANDLE_T  handle)

Here is the caller graph for this function:

const char* TC_FIRST_CHAIN ( TC_HANDLE_T handle)

Here is the call graph for this function:

const STRUCT_ENTRY* TC_FIRST_RULE ( const char *  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

int TC_FLUSH_ENTRIES ( const IPT_CHAINLABEL  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

void TC_FREE ( TC_HANDLE_T h)

Here is the caller graph for this function:

const char* TC_GET_POLICY ( const char *  chain,
STRUCT_COUNTERS counters,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

int TC_GET_RAW_SOCKET ( )
int TC_GET_REFERENCES ( unsigned int *  ref,
const IPT_CHAINLABEL  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

const STRUCT_ENTRY* TC_GET_RULE ( const char *  chain,
unsigned int  n,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

const char* TC_GET_TARGET ( const STRUCT_ENTRY ce,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

TC_HANDLE_T TC_INIT ( const char *  tablename)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_INSERT_ENTRY ( const IPT_CHAINLABEL  chain,
const STRUCT_ENTRY e,
unsigned int  rulenum,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_IS_CHAIN ( const char *  chain,
const TC_HANDLE_T  handle 
)

Here is the call graph for this function:

const char* TC_NEXT_CHAIN ( TC_HANDLE_T handle)

Here is the call graph for this function:

const STRUCT_ENTRY* TC_NEXT_RULE ( const STRUCT_ENTRY prev,
TC_HANDLE_T handle 
)
unsigned int TC_NUM_RULES ( const char *  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

STRUCT_COUNTERS* TC_READ_COUNTER ( const IPT_CHAINLABEL  chain,
unsigned int  rulenum,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_RENAME_CHAIN ( const IPT_CHAINLABEL  oldname,
const IPT_CHAINLABEL  newname,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

int TC_REPLACE_ENTRY ( const IPT_CHAINLABEL  chain,
const STRUCT_ENTRY e,
unsigned int  rulenum,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_SET_COUNTER ( const IPT_CHAINLABEL  chain,
unsigned int  rulenum,
STRUCT_COUNTERS counters,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

int TC_SET_POLICY ( const IPT_CHAINLABEL  chain,
const IPT_CHAINLABEL  policy,
STRUCT_COUNTERS counters,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

const char* TC_STRERROR ( int  err)

Here is the call graph for this function:

int TC_ZERO_COUNTER ( const IPT_CHAINLABEL  chain,
unsigned int  rulenum,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int TC_ZERO_ENTRIES ( const IPT_CHAINLABEL  chain,
TC_HANDLE_T handle 
)

Here is the call graph for this function:

Variable Documentation

struct chain_head* chain_iterator_cur
struct list_head chains
const char* hooknames[]
static
Initial value:
= { [HOOK_PRE_ROUTING] "PREROUTING",
[HOOK_LOCAL_IN] "INPUT",
[HOOK_FORWARD] "FORWARD",
[HOOK_LOCAL_OUT] "OUTPUT",
[HOOK_POST_ROUTING] "POSTROUTING",
}
#define HOOK_LOCAL_IN
Definition: libip4tc.c:35
#define HOOK_PRE_ROUTING
Definition: libip4tc.c:34
#define HOOK_FORWARD
Definition: libip4tc.c:36
#define HOOK_LOCAL_OUT
Definition: libip4tc.c:37
#define HOOK_POST_ROUTING
Definition: libip4tc.c:38
void* iptc_fn = NULL
static
struct rule_head* rule_iterator_cur
int sockfd = -1
static
int sockfd_use = 0
static
STRUCT_TC_HANDLE
Initial value:
{
int changed