static int get_info(struct net *net, void __user *user, const int *len, int compat) (讀取表中信息)
該函數(shù)是用戶使用iptables命令操作表中規(guī)則時(shí),用于獲取表中信息的接口。它使用xt_find_table_lock()和xt_table_unlock()保證沒有其它人操作該表。
static int get_entries(struct net *net, struct ipt_get_entries __user *uptr, const int *len)(讀取表中規(guī)則)
該函數(shù)是用戶使用iptables命令操作表中規(guī)則時(shí),用于獲取表中規(guī)則的接口。它使用xt_find_table_lock()和xt_table_unlock()保證沒有其它人操作該表。
static int do_replace(struct net *net, const void __user *user, unsigned int len) (修改表中規(guī)則)
該函數(shù)是iptables為filter、nat、mangle模塊提供用于在對應(yīng)表中下規(guī)則的接口。它根據(jù)用戶傳遞過來的規(guī)則,構(gòu)建一個(gè)新的xt_table_info結(jié)構(gòu)和規(guī)則,并將它們與對應(yīng)表的xt_table->private相關(guān)聯(lián)。它通過xt_find_table_lock()和xt_table_unlock()保證當(dāng)前只有一個(gè)寫者在操作該表。通過local_bh_disable()和local_bh_enable()保證更換table->private指向新的xt_table_info結(jié)構(gòu)時(shí)不被打斷。通過get_counters()保證所有其它CPU都不再使用舊的xt_table_info結(jié)構(gòu),安全釋放舊的xt_table_info結(jié)構(gòu)。
static int translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0, const struct ipt_replace *repl)
根據(jù)ipt_replace結(jié)構(gòu)構(gòu)建一個(gè)xt_table_info結(jié)構(gòu),并做一些必要的檢查(鏈?zhǔn)欠癍h(huán)路等),同時(shí)將表中的規(guī)則與相應(yīng)的match和target相關(guān)聯(lián)。
struct xt_table_info *xt_replace_table(struct xt_table *table, unsigned int num_counters, struct xt_table_info *newinfo, int *error)
為newinfo調(diào)用xt_jumpstack_alloc(struct xt_table_info *i)初始化stack相關(guān)數(shù)據(jù),然后使table->private指向newinfo,并返回oldinfo。