mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-08 05:34:58 +02:00
condition: use unique symbol names and rewrite init function
Use an array of xt_match for the match vtable.
This commit is contained in:
@@ -73,9 +73,8 @@ static DECLARE_MUTEX(proc_lock);
|
|||||||
static LIST_HEAD(conditions_list);
|
static LIST_HEAD(conditions_list);
|
||||||
static struct proc_dir_entry *proc_net_condition = NULL;
|
static struct proc_dir_entry *proc_net_condition = NULL;
|
||||||
|
|
||||||
static int
|
static int condition_proc_read(char __user *buffer, char **start, off_t offset,
|
||||||
xt_condition_read_info(char __user *buffer, char **start, off_t offset,
|
int length, int *eof, void *data)
|
||||||
int length, int *eof, void *data)
|
|
||||||
{
|
{
|
||||||
const struct condition_variable *var = data;
|
const struct condition_variable *var = data;
|
||||||
|
|
||||||
@@ -87,10 +86,8 @@ xt_condition_read_info(char __user *buffer, char **start, off_t offset,
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int condition_proc_write(struct file *file, const char __user *buffer,
|
||||||
static int
|
unsigned long length, void *data)
|
||||||
xt_condition_write_info(struct file *file, const char __user *buffer,
|
|
||||||
unsigned long length, void *data)
|
|
||||||
{
|
{
|
||||||
struct condition_variable *var = data;
|
struct condition_variable *var = data;
|
||||||
char newval;
|
char newval;
|
||||||
@@ -196,8 +193,8 @@ condition_mt_check(const char *tablename, const void *entry,
|
|||||||
newvar->status_proc->owner = THIS_MODULE;
|
newvar->status_proc->owner = THIS_MODULE;
|
||||||
newvar->status_proc->data = newvar;
|
newvar->status_proc->data = newvar;
|
||||||
wmb();
|
wmb();
|
||||||
newvar->status_proc->read_proc = xt_condition_read_info;
|
newvar->status_proc->read_proc = condition_proc_read;
|
||||||
newvar->status_proc->write_proc = xt_condition_write_info;
|
newvar->status_proc->write_proc = condition_proc_write;
|
||||||
|
|
||||||
list_add_rcu(&newvar->list, &conditions_list);
|
list_add_rcu(&newvar->list, &conditions_list);
|
||||||
|
|
||||||
@@ -238,64 +235,53 @@ static void condition_mt_destroy(const struct xt_match *match, void *matchinfo)
|
|||||||
up(&proc_lock);
|
up(&proc_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xt_match condition_match = {
|
static struct xt_match condition_mt_reg[] __read_mostly = {
|
||||||
.name = "condition",
|
{
|
||||||
.family = PF_INET,
|
.name = "condition",
|
||||||
.matchsize = XT_ALIGN(sizeof(struct xt_condition_mtinfo)),
|
.revision = 0,
|
||||||
.match = condition_mt,
|
.family = PF_INET,
|
||||||
.checkentry = condition_mt_check,
|
.matchsize = XT_ALIGN(sizeof(struct xt_condition_mtinfo)),
|
||||||
.destroy = condition_mt_destroy,
|
.match = condition_mt,
|
||||||
.me = THIS_MODULE
|
.checkentry = condition_mt_check,
|
||||||
};
|
.destroy = condition_mt_destroy,
|
||||||
|
.me = THIS_MODULE,
|
||||||
static struct xt_match condition6_match = {
|
},
|
||||||
.name = "condition",
|
{
|
||||||
.family = PF_INET6,
|
.name = "condition",
|
||||||
.matchsize = XT_ALIGN(sizeof(struct xt_condition_mtinfo)),
|
.revision = 0,
|
||||||
.match = condition_mt,
|
.family = PF_INET6,
|
||||||
.checkentry = condition_mt_check,
|
.matchsize = XT_ALIGN(sizeof(struct xt_condition_mtinfo)),
|
||||||
.destroy = condition_mt_destroy,
|
.match = condition_mt,
|
||||||
.me = THIS_MODULE
|
.checkentry = condition_mt_check,
|
||||||
|
.destroy = condition_mt_destroy,
|
||||||
|
.me = THIS_MODULE,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *const dir_name = "nf_condition";
|
static const char *const dir_name = "nf_condition";
|
||||||
|
|
||||||
static int __init
|
static int __init condition_mt_init(void)
|
||||||
init(void)
|
|
||||||
{
|
{
|
||||||
int errorcode;
|
int ret;
|
||||||
|
|
||||||
proc_net_condition = proc_mkdir(dir_name, proc_net);
|
proc_net_condition = proc_mkdir(dir_name, proc_net);
|
||||||
if (proc_net_condition == NULL) {
|
if (proc_net_condition == NULL)
|
||||||
remove_proc_entry(dir_name, proc_net);
|
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
|
||||||
|
|
||||||
errorcode = xt_register_match(&condition_match);
|
ret = xt_register_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
||||||
if (errorcode) {
|
if (ret < 0) {
|
||||||
xt_unregister_match(&condition_match);
|
|
||||||
remove_proc_entry(dir_name, proc_net);
|
remove_proc_entry(dir_name, proc_net);
|
||||||
return errorcode;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
errorcode = xt_register_match(&condition6_match);
|
|
||||||
if (errorcode) {
|
|
||||||
xt_unregister_match(&condition6_match);
|
|
||||||
xt_unregister_match(&condition_match);
|
|
||||||
remove_proc_entry(dir_name, proc_net);
|
|
||||||
return errorcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit
|
static void __exit condition_mt_exit(void)
|
||||||
fini(void)
|
|
||||||
{
|
{
|
||||||
xt_unregister_match(&condition6_match);
|
xt_unregister_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
||||||
xt_unregister_match(&condition_match);
|
|
||||||
remove_proc_entry(dir_name, proc_net);
|
remove_proc_entry(dir_name, proc_net);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(init);
|
module_init(condition_mt_init);
|
||||||
module_exit(fini);
|
module_exit(condition_mt_exit);
|
||||||
|
Reference in New Issue
Block a user