summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBart De Schuymer <bdschuym@pandora.be>2004-01-14 20:05:27 +0000
committerBart De Schuymer <bdschuym@pandora.be>2004-01-14 20:05:27 +0000
commit8339ff1d7d8694153e2daac032c0999fbf04aad9 (patch)
tree48d3400eb6d6ea2fc08c0680e328947a986f1b7d /include
parent464e7d9b2e853441282addc7484e5eee7d825514 (diff)
Make ebtables library functions
Diffstat (limited to 'include')
-rw-r--r--include/ebtables_u.h155
1 files changed, 117 insertions, 38 deletions
diff --git a/include/ebtables_u.h b/include/ebtables_u.h
index 914a0f9..77d1e50 100644
--- a/include/ebtables_u.h
+++ b/include/ebtables_u.h
@@ -30,6 +30,7 @@
#define EBT_MIN_ALIGN (__alignof__(struct ebt_entry_target))
#endif
#define EBT_ALIGN(s) (((s) + (EBT_MIN_ALIGN-1)) & ~(EBT_MIN_ALIGN-1))
+#define ERRORMSG_MAXLEN 128
struct ebt_u_entries
{
@@ -51,6 +52,13 @@ struct ebt_u_chain_list
char *kernel_start;
};
+struct ebt_cntchanges;
+struct ebt_cntchanges
+{
+ unsigned short type;
+ struct ebt_cntchanges *next;
+};
+
struct ebt_u_replace
{
char name[EBT_TABLE_MAXNAMELEN];
@@ -72,20 +80,20 @@ struct ebt_u_replace
/* we stick the specified command (e.g. -A) in here */
char command;
/*
- * here we stick the hook to do our thing on (can be -1 if unspecified)
+ * here we stick the chain to do our thing on (can be -1 if unspecified)
*/
- int selected_hook;
+ int selected_chain;
/* used for the atomic option */
char *filename;
/* tells what happened to the old rules */
- unsigned short *counterchanges;
+ struct ebt_cntchanges *counterchanges;
};
struct ebt_u_table
{
char name[EBT_TABLE_MAXNAMELEN];
void (*check)(struct ebt_u_replace *repl);
- void (*help)(char **);
+ void (*help)(const char **);
struct ebt_u_table *next;
};
@@ -118,6 +126,8 @@ struct ebt_u_entry
struct ebt_u_watcher_list *w_list;
struct ebt_entry_target *t;
struct ebt_u_entry *next;
+ /* needed f.e. to find out the name of the udc when listing -j */
+ struct ebt_u_replace *replace;
};
struct ebt_u_match
@@ -147,6 +157,7 @@ struct ebt_u_match
/*
* if used == 1 we no longer have to add it to
* the match chain of the new entry
+ * be sure to put it back on 0 when finished
*/
unsigned int used;
struct ebt_u_match *next;
@@ -200,60 +211,128 @@ struct ebt_u_target
struct ebt_u_target *next;
};
-void register_table(struct ebt_u_table *);
-void register_match(struct ebt_u_match *);
-void register_watcher(struct ebt_u_watcher *);
-void register_target(struct ebt_u_target *t);
-int get_table(struct ebt_u_replace *repl);
-struct ebt_u_target *find_target(const char *name);
-struct ebt_u_match *find_match(const char *name);
-struct ebt_u_watcher *find_watcher(const char *name);
-struct ebt_u_table *find_table(char *name);
-void deliver_counters(struct ebt_u_replace *repl);
-void deliver_table(struct ebt_u_replace *repl);
-void check_option(unsigned int *flags, unsigned int mask);
-int check_inverse(const char option[]);
-void print_mac(const char *mac);
-void print_mac_and_mask(const char *mac, const char *mask);
+/* libebtc.c */
+
+extern struct ebt_u_table *ebt_tables;
+extern struct ebt_u_match *ebt_matches;
+extern struct ebt_u_watcher *ebt_watchers;
+extern struct ebt_u_target *ebt_targets;
+
+void ebt_register_table(struct ebt_u_table *);
+void ebt_register_match(struct ebt_u_match *);
+void ebt_register_watcher(struct ebt_u_watcher *);
+void ebt_register_target(struct ebt_u_target *t);
+void ebt_get_kernel_table(struct ebt_u_replace *replace,
+ struct ebt_u_table *table);
+struct ebt_u_target *ebt_find_target(const char *name);
+struct ebt_u_match *ebt_find_match(const char *name);
+struct ebt_u_watcher *ebt_find_watcher(const char *name);
+struct ebt_u_table *ebt_find_table(const char *name);
int ebtables_insmod(const char *modname);
+void ebt_list_extensions();
+void ebt_initialize_entry(struct ebt_u_entry *e);
+void ebt_free_u_entry(struct ebt_u_entry *e);
+struct ebt_u_entries *ebt_name_to_chain(const struct ebt_u_replace *replace,
+ const char* arg);
+struct ebt_u_entries *ebt_nr_to_chain(const struct ebt_u_replace *replace,
+ int nr);
+struct ebt_u_entries *ebt_to_chain(const struct ebt_u_replace *replace);
+struct ebt_u_entries *ebt_name_to_chain(const struct ebt_u_replace *replace,
+ const char* arg);
+int ebt_get_chainnr(const struct ebt_u_replace *replace, const char* arg);
+/**/
+void ebt_change_policy(struct ebt_u_replace *replace, int policy);
+void ebt_flush_chains(struct ebt_u_replace *replace);
+int ebt_check_rule_exists(struct ebt_u_replace *replace,
+ struct ebt_u_entry *new_entry);
+void ebt_add_rule(struct ebt_u_replace *replace, struct ebt_u_entry *new_entry,
+ int rule_nr);
+void ebt_delete_rule(struct ebt_u_replace *replace,
+ struct ebt_u_entry *new_entry, int begin, int end);
+void ebt_zero_counters(struct ebt_u_replace *replace);
+void ebt_new_chain(struct ebt_u_replace *replace, const char *name, int policy);
+void ebt_delete_chain(struct ebt_u_replace *replace);
+void ebt_rename_chain(struct ebt_u_replace *replace, const char *name);
+/**/
+void ebt_do_final_checks(struct ebt_u_replace *replace, struct ebt_u_entry *e,
+ struct ebt_u_entries *entries);
+int ebt_check_for_references(struct ebt_u_replace *replace);
+int ebt_check_for_references2(struct ebt_u_replace *replace, int chain_nr);
+void ebt_check_for_loops(struct ebt_u_replace *replace);
+void ebt_add_match(struct ebt_u_entry *new_entry, struct ebt_u_match *m);
+void ebt_add_watcher(struct ebt_u_entry *new_entry, struct ebt_u_watcher *w);
+void ebt_iterate_matches(void (*f)(struct ebt_u_match *));
+void ebt_iterate_watchers(void (*f)(struct ebt_u_watcher *));
+void ebt_iterate_targets(void (*f)(struct ebt_u_target *));
void __print_bug(char *file, int line, char *format, ...);
+void __print_error(char *format, ...);
+
+/* communication.c */
+
+int ebt_get_table(struct ebt_u_replace *repl);
+void ebt_deliver_counters(struct ebt_u_replace *repl);
+void ebt_deliver_table(struct ebt_u_replace *repl);
+
+/* useful_functions.c */
+
+extern int ebt_invert;
+void ebt_check_option(unsigned int *flags, unsigned int mask);
+int ebt_check_inverse(const char option[]);
+void ebt_print_mac(const char *mac);
+void ebt_print_mac_and_mask(const char *mac, const char *mask);
+int ebt_get_mac_and_mask(char *from, char *to, char *mask);
+void ebt_parse_ip_address(char *address, uint32_t *addr, uint32_t *msk);
+char *ebt_mask_to_dotted(uint32_t mask);
+
+struct ethertypeent *parseethertypebynumber(int type);
+
#define print_bug(format, args...) \
__print_bug(__FILE__, __LINE__, format, ##args)
-#define print_error(format,args...) {printf(format,##args);\
- printf(".\n");exit(-1);}
+#define print_error(format,args...) __print_error(format, ##args);
#define print_memory() {printf("Ebtables: " __FILE__ \
" %s %d :Out of memory.\n", __FUNCTION__, __LINE__); exit(-1);}
/* used for keeping the rule counters right during rule adds or deletes */
-#define CNT_NORM 0
-#define CNT_DEL 1
-#define CNT_ADD 2
-#define CNT_END 3
-#define CNT_ZERO 4
+#define CNT_NORM 0
+#define CNT_DEL 1
+#define CNT_ADD 2
+#define CNT_OWRITE 3
+#define CNT_ZERO 4
+
+extern const char *ebt_hooknames[NF_BR_NUMHOOKS];
+extern const char *ebt_standard_targets[NUM_STANDARD_TARGETS];
+extern char ebt_errormsg[ERRORMSG_MAXLEN];
+extern char *ebt_modprobe;
+extern int ebt_silent;
+extern int ebt_printstyle_mac;
-extern char *standard_targets[NUM_STANDARD_TARGETS];
/*
* Transforms a target string into the right integer,
* returns 0 on success.
*/
-#define FILL_TARGET(_str, _pos) ({ \
- int _i, _ret = 0; \
- for (_i = 0; _i < NUM_STANDARD_TARGETS; _i++) \
- if (!strcmp(_str, standard_targets[_i])) {\
- _pos = -_i - 1; \
- break; \
- } \
- if (_i == NUM_STANDARD_TARGETS) \
- _ret = 1; \
- _ret; \
+#define FILL_TARGET(_str, _pos) ({ \
+ int _i, _ret = 0; \
+ for (_i = 0; _i < NUM_STANDARD_TARGETS; _i++) \
+ if (!strcmp(_str, ebt_standard_targets[_i])) {\
+ _pos = -_i - 1; \
+ break; \
+ } \
+ if (_i == NUM_STANDARD_TARGETS) \
+ _ret = 1; \
+ _ret; \
})
/* Transforms the target value to an index into standard_targets[] */
#define TARGET_INDEX(_value) (-_value - 1)
/* Returns a target string corresponding to the value */
-#define TARGET_NAME(_value) (standard_targets[TARGET_INDEX(_value)])
+#define TARGET_NAME(_value) (ebt_standard_targets[TARGET_INDEX(_value)])
/* True if the hook mask denotes that the rule is in a base chain */
#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
/* Clear the bit in the hook_mask that tells if the rule is on a base chain */
#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
+#define PRINT_VERSION printf(PROGNAME" v"PROGVERSION" ("PROGDATE")\n")
+#ifndef PROC_SYS_MODPROBE
+#define PROC_SYS_MODPROBE "/proc/sys/kernel/modprobe"
+#endif
+#define ATOMIC_ENV_VARIABLE "EBTABLES_ATOMIC_FILE"
#endif /* EBTABLES_U_H */