ip(6)tables enhancement: add new /proc/net files
Subsystems (2)
PATCH 1/1 ip(6)tables enhancement: add new /proc/net files
Hi Dave!
Here is a patch that adds some more ip(6)tables-related files to /proc/net. The idea is for applications to find out which target and match modules are loaded in the kernel.
net/ipv4/netfilter/ip_tables.c +60 -9
@@ -1698,14 +1698,15 @@ = { {NULL ,NULL },"icmp" , &icmp_match, &icmp_checkentry,NULL }; #ifdef CONFIG_PROC_FS -static inline int print_name(const struct ipt_table *t, +static inline int print_name(const char *i, off_t start_offset, char *buffer, int length, off_t *pos, unsigned int *count) { if ((*count)++ >= start_offset) { unsigned int namelen; - namelen = sprintf(buffer + *pos, "%s\n", t->name); + namelen = sprintf(buffer + *pos, "%s\n", + i + sizeof(struct list_head)); if (*pos + namelen > length) { /* Stop iterating */ return 1;
@@ -1723,7 +1724,7 @@if (down_interruptible (&ipt_mutex) !=0 )return 0 ; - LIST_FIND(&ipt_tables, print_name, struct ipt_table *, + LIST_FIND(&ipt_tables, print_name, void *, offset, buffer, length, &pos, &count);up (&ipt_mutex);
@@ -1732,6 +1733,46 @@ *start=(char *)((unsigned long )count-offset);return pos; } + +static int ipt_get_targets (char *buffer,char **start,off_t offset,int length) +{ +off_t pos =0 ; +unsigned int count =0 ; + +if (down_interruptible (&ipt_mutex) !=0 ) +return 0 ; + + LIST_FIND(&ipt_target, print_name, void *, + offset, buffer, length, &pos, &count); + +up (&ipt_mutex); + + *start = (char *)((unsigned long )count - offset); +return pos; +} + +static int ipt_get_matches (char *buffer,char **start,off_t offset,int length) +{ +off_t pos =0 ; +unsigned int count =0 ; + +if (down_interruptible (&ipt_mutex) !=0 ) +return 0 ; + + LIST_FIND(&ipt_match, print_name, void *, + offset, buffer, length, &pos, &count); + +up (&ipt_mutex); + + *start = (char *)((unsigned long )count - offset); +return pos; +} + +static struct {char *name;get_info_t *get_info; } ipt_proc_entry[] = +{ {"ip_tables_names" , ipt_get_tables }, + {"ip_tables_targets" , ipt_get_targets }, + {"ip_tables_matches" , ipt_get_matches }, + {NULL ,NULL } };#endif /*CONFIG_PROC_FS*/ static int __init init (void )
@@ -1757,13 +1798,19 @@#ifdef CONFIG_PROC_FS {struct proc_dir_entry *proc; +int i; - proc =proc_net_create ("ip_tables_names" ,0 , ipt_get_tables); -if (!proc) { -nf_unregister_sockopt (&ipt_sockopts); -return -ENOMEM ; +for (i =0 ; ipt_proc_entry[i].name; i++) { + proc =proc_net_create (ipt_proc_entry[i].name,0 , + ipt_proc_entry[i].get_info); +if (!proc) { +while (--i >=0 ) +proc_net_remove (ipt_proc_entry[i].name); +nf_unregister_sockopt (&ipt_sockopts); +return -ENOMEM ; + } + proc->owner =THIS_MODULE ; } - proc->owner =THIS_MODULE ; }#endif
@@ -1775,7 +1822,11 @@ {nf_unregister_sockopt (&ipt_sockopts);#ifdef CONFIG_PROC_FS -proc_net_remove ("ip_tables_names" ); + { +int i; +for (i =0 ; ipt_proc_entry[i].name; i++) +proc_net_remove (ipt_proc_entry[i].name); + }#endif }
net/ipv6/netfilter/ip6_tables.c +61 -10
108 lines not on this page · raw message
Please apply, thanks.
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie