The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
mark.h
Go to the documentation of this file.
1 #ifndef MARK_H
2 #define MARK_H
3 
4 #include <linux/version.h>
5 
6 //original inclusions
7 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 7, 0)
8 #if 0
9  #include "libiptc/libiptc.h"
10  #include <linux/netfilter_ipv4/ip_conntrack.h>
11  #include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
12  #include "libiptc/ipt_conntrack.h"
13  #include "libiptc/ipt_connmark.h"
14  #include "libiptc/ipt_CONNMARK.h"
15  #endif
16 
17  #if 1
18  #include "libiptc/libiptc.h"
19  #if 1
20  #include <linux/netfilter/nf_conntrack_common.h>
21  #endif
22  #if 0
23  #include <linux/netfilter_ipv4/ipt_conntrack_tuple.h>
24  #endif
25 #include "libiptc/ipt_conntrack.h"
26 #include "libiptc/ipt_connmark.h"
27 #include "libiptc/ipt_CONNMARK.h"
28  #endif
29 
30  /* 2010 fixes for debian package */
31  #if 0
32  #include "libiptc/libiptc.h"
33  #include <linux/netfilter/nf_conntrack_common.h>
34  #include <linux/netfilter_ipv4/ipt_conntrack.h>
35  #include <linux/netfilter_ipv4/ipt_connmark.h>
36  #include <linux/netfilter_ipv4/ipt_CONNMARK.h>
37  #endif
38 #endif
39 
40 #include "libiptc/libiptc.h"
41 #include <linux/netfilter/nf_conntrack_common.h>
42 #include "libiptc/ipt_conntrack.h"
43 #include "libiptc/ipt_connmark.h"
44 #include "libiptc/ipt_CONNMARK.h"
45 
46 #define MANGLE_TABLE "mangle"
47 #define FILTER_TABLE "filter"
48 #define NTK_MARK_CHAIN "ntk_mark_chain"
49 #define CHAIN_OUTPUT "OUTPUT"
50 #define CHAIN_POSTROUTING "POSTROUTING"
51 #define CHAIN_PREROUTING "PREROUTING"
52 #define CHAIN_POSTROUTING "POSTROUTING"
53 #define CHAIN_FORWARD "FORWARD"
54 
55 #define MOD_CONNTRACK "conntrack"
56 #define MOD_CONNMARK "CONNMARK"
57 #define MARK_TARGET "MARK"
58 
59 #define NTK_NET_STR "10.0.0.0"
60 #define NTK_NET_MASK_STR "255.0.0.0"
61 
62 #define IPT_ENTRY_SZ sizeof(struct ipt_entry)
63 #define IPT_ENTRY_MATCH_SZ sizeof(struct ipt_entry_match)
64 #define IPT_ENTRY_TARGET_SZ sizeof(struct ipt_entry_target)
65 #define IPT_CT_INFO_SZ sizeof(struct ipt_conntrack_info)
66 #define IPT_CM_TARGET_INFO_SZ sizeof(struct ipt_connmark_target_info)
67 
68 #define MATCH_SZ IPT_ENTRY_MATCH_SZ+IPT_CT_INFO_SZ
69 #define TARGET_SZ IPT_ENTRY_TARGET_SZ+IPT_CM_TARGET_INFO_SZ
70 
71 #define RESTORE_OUTPUT_RULE_SZ IPT_ENTRY_SZ+MATCH_SZ+TARGET_SZ
72 
73 #define OFFSET_MATCH IPT_ENTRY_SZ
74 #define OFFSET_MATCH_INFO OFFSET_MATCH+IPT_ENTRY_MATCH_SZ
75 #define OFFSET_TARGET OFFSET_MATCH_INFO+IPT_CT_INFO_SZ
76 #define OFFSET_TARGET_INFO OFFSET_TARGET+IPT_ENTRY_TARGET_SZ
77 
78 #define MARK_RULE_SZ IPT_ENTRY_SZ+TARGET_SZ
79 #define MAX_MARK_RULES 100
80 
81 #define NTK_FORWARD_RULE_SZ OFFSET_TARGET_INFO+4
82 
83 #define IGW_FILTER_RULE_SZ IPT_ENTRY_SZ+IPT_ENTRY_SZ+4
84 #define INET_MARK 25
85 
86 #define MAX_RULE_SZ RESTORE_OUTPUT_RULE_SZ
87 
88 //struct in_addr inet_dst,inet_dst_mask;
89 
90 typedef struct rule_store {
92  int sz;
93  char *chain;
94 } rule_store;
95 
96 /* Functions */
97 
98 int table_init(const char *table, iptc_handle_t *t);
99 int insert_rule(const char *rule,iptc_handle_t *t,const char *chain,int pos);
100 int append_rule(const char *rule,iptc_handle_t *t,const char *chain);
102 void restore_output_rule_init(char *rule);
103 void ntk_forward_rule_init(char *rule);
104 void mark_rule_init(char *rule,char *outiface,int outiface_num);
105 void igw_mark_rule_init(char *rule);
107 int store_rules();
108 int mark_init(int igw);
110 int create_mark_rules(int n);
112 int delete_first_rule(iptc_handle_t *t,const char *chain);
114 int delete_rule(rule_store *rule,iptc_handle_t *t);
115 int mark_close();
116 
117 #endif /* MARK_H */
Definition: mark.h:90
int ntk_mark_chain_init(iptc_handle_t *t)
Definition: mark.c:268
int commit_rules(iptc_handle_t *t)
Definition: mark.c:104
int append_rule(const char *rule, iptc_handle_t *t, const char *chain)
Definition: mark.c:88
int delete_ntk_forward_chain(iptc_handle_t *t)
Definition: mark.c:564
void igw_mark_rule_init(char *rule)
Definition: mark.c:243
int delete_first_rule(iptc_handle_t *t, const char *chain)
Definition: mark.c:586
int insert_rule(const char *rule, iptc_handle_t *t, const char *chain, int pos)
Definition: mark.c:72
struct iptc_handle * iptc_handle_t
Definition: libiptc.h:51
int table_init(const char *table, iptc_handle_t *t)
Definition: mark.c:55
int sz
Definition: mark.h:92
int store_rules()
Definition: mark.c:297
void ntk_forward_rule_init(char *rule)
Definition: mark.c:170
int delete_rule(rule_store *rule, iptc_handle_t *t)
Definition: mark.c:633
char * chain
Definition: mark.h:93
int count_ntk_mark_chain(iptc_handle_t *t)
Definition: mark.c:489
char e[sizeof(struct ipt_entry)+sizeof(struct ipt_entry_match)+sizeof(struct ipt_conntrack_info)+sizeof(struct ipt_entry_target)+sizeof(struct ipt_connmark_target_info)]
Definition: mark.h:91
struct rule_store rule_store
int create_mark_rules(int n)
Definition: mark.c:519
#define RESTORE_OUTPUT_RULE_SZ
Definition: mark.h:71
int mark_init(int igw)
Definition: mark.c:400
void restore_output_rule_init(char *rule)
Definition: mark.c:125
int mark_close()
Definition: mark.c:657
void mark_rule_init(char *rule, char *outiface, int outiface_num)
Definition: mark.c:209
int rule_position(rule_store *rule, iptc_handle_t *t)
Definition: mark.c:609