Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/ipt_NETFLOW.c b/ipt_NETFLOW.c
- index 6e30709..e1fa909 100644
- --- a/ipt_NETFLOW.c
- +++ b/ipt_NETFLOW.c
- @@ -40,6 +40,9 @@
- #include <net/ip6_fib.h>
- #include <net/dst.h>
- #include <linux/netfilter_ipv4/ip_tables.h>
- +#undef CONFIG_NF_NAT_NEEDED
- +#undef CONFIG_NF_CONNTRACK_MARK
- +
- #if defined(CONFIG_NF_NAT_NEEDED) || defined(CONFIG_NF_CONNTRACK_MARK)
- #include <linux/notifier.h>
- #include <net/netfilter/nf_conntrack.h>
- @@ -178,6 +181,7 @@ static unsigned long nat_events_stop = 0;
- #endif
- static struct kmem_cache *ipt_netflow_cachep __read_mostly; /* ipt_netflow memory */
- static atomic_t ipt_netflow_count = ATOMIC_INIT(0);
- +static atomic_t ipt_netflow_skip = ATOMIC_INIT(0);
- static long long pdu_packets = 0, pdu_traf = 0; /* how much accounted traffic in pdu */
- static unsigned int pdu_count = 0;
- @@ -185,6 +189,7 @@ static unsigned int pdu_seq = 0;
- static unsigned int pdu_data_records = 0;
- static unsigned int pdu_tpl_records = 0;
- static unsigned long pdu_ts_mod; /* ts(jiffies) of last flow */
- +static unsigned long jiffies_on_debug_dump; /* ts(jiffies) of last flow */
- static union {
- struct netflow5_pdu v5;
- struct netflow9_pdu v9;
- @@ -220,6 +225,9 @@ static long long min_prate = 0, min_brate = 0;
- static long long min5_prate = 0, min5_brate = 0;
- static unsigned int metric = 100, min15_metric = 100, min5_metric = 100, min_metric = 100; /* hash metrics */
- +static inline int active_needs_export(const struct ipt_netflow *nf, const long a_timeout);
- +static inline int active_needs_export_debug(const struct ipt_netflow *nf, const long a_timeout);
- +static inline u_int32_t hash_netflow(const struct ipt_netflow_tuple *tuple);
- static int set_hashsize(int new_size);
- static void destination_removeall(void);
- static int add_destinations(char *ptr);
- @@ -297,6 +305,57 @@ static inline void pause_scan_worker(void)
- #endif
- #ifdef CONFIG_PROC_FS
- +
- +
- +static void * nf_seq_debug_start(struct seq_file *seq, loff_t *pos)
- +{
- + struct ipt_netflow *nf;
- +
- + loff_t off = 0;
- + list_for_each_entry(nf, &ipt_netflow_list, list) {
- + if (*pos == off++) {
- + return nf;
- + }
- + }
- + return NULL;
- +}
- +
- +static void * nf_seq_debug_next(struct seq_file *seq, void *v, loff_t *pos)
- +{
- + struct list_head *n = ((struct ipt_netflow *)v)->list.next;
- + ++*pos;
- + return(n != &ipt_netflow_list) ?
- + list_entry(n, struct ipt_netflow, list) : NULL;
- +}
- +
- +static int nf_seq_debug_show(struct seq_file *seq, void *v)
- +{
- + const struct ipt_netflow *nf = v;
- + long i_timeout = inactive_timeout * HZ;
- + long a_timeout = active_timeout * HZ;
- +
- + int export = (((jiffies_on_debug_dump - nf->ts_last) >= i_timeout) ||
- + active_needs_export_debug(nf, a_timeout));
- +
- + unsigned int hash = hash_netflow(&nf->tuple);
- + char src_ip_port[32];
- + char dst_ip_port[32];
- + sprintf(src_ip_port,"%u.%u.%u.%u:%u", NIPQUAD(nf->tuple.src), ntohs(nf->tuple.s_port));
- + sprintf(dst_ip_port,"%u.%u.%u.%u:%u", NIPQUAD(nf->tuple.dst), ntohs(nf->tuple.d_port));
- +
- + seq_printf(seq,"i_ifc:%hd o_ifc:%hd src:%-21s dst:%-21s proto:%-2d tos:%-3d l3proto:%d needs_export:%d hash:%08x hash&mask:%02x\n",
- + nf->tuple.i_ifc, nf->o_ifc,
- + src_ip_port, dst_ip_port,
- + nf->tuple.protocol, nf->tuple.tos, nf->tuple.l3proto, export, hash, hash & LOCK_COUNT_MASK);
- + return 0;
- +}
- +
- +static void nf_seq_debug_stop(struct seq_file *seq, void *v)
- +{
- +
- +}
- +
- +
- /* procfs statistics /proc/net/stat/ipt_netflow */
- static int nf_seq_show(struct seq_file *seq, void *v)
- {
- @@ -485,6 +544,40 @@ static struct file_operations nf_seq_fops = {
- .llseek = seq_lseek,
- .release = single_release,
- };
- +
- +static struct seq_operations nf_seq_debug_ops = {
- + .start = nf_seq_debug_start,
- + .next = nf_seq_debug_next,
- + .stop = nf_seq_debug_stop,
- + .show = nf_seq_debug_show,
- +};
- +
- +static int nf_seq_debug_open(struct inode *inode, struct file *file)
- +{
- + atomic_inc(&ipt_netflow_skip);
- + pause_scan_worker();
- + spin_lock(&hlist_lock);
- + jiffies_on_debug_dump=jiffies;
- + return seq_open(file, &nf_seq_debug_ops);
- +}
- +
- +static int nf_seq_debug_release(struct inode *inode, struct file *file)
- +{
- + spin_unlock(&hlist_lock);
- + cont_scan_worker();
- + atomic_dec(&ipt_netflow_skip);
- + return seq_release(inode, file);
- +}
- +
- +static struct file_operations nf_seq_fops_debug = {
- + .owner = THIS_MODULE,
- + .open = nf_seq_debug_open,
- + .read = seq_read,
- + .llseek = seq_lseek,
- + .release = nf_seq_debug_release,
- +};
- +
- +
- #endif /* CONFIG_PROC_FS */
- #ifdef CONFIG_SYSCTL
- @@ -1987,6 +2080,18 @@ static inline int active_needs_export(const struct ipt_netflow *nf, const long a
- nf->nr_bytes >= FLOW_FULL_WATERMARK;
- }
- +static inline int active_needs_export_debug(const struct ipt_netflow *nf, const long a_timeout)
- +{
- + /* active too long, finishing, or having too much bytes */
- + return ((jiffies_on_debug_dump - nf->ts_first) > a_timeout) ||
- + (nf->tuple.protocol == IPPROTO_TCP &&
- + (nf->tcp_flags & TCP_FIN_RST) &&
- + (jiffies - nf->ts_last) > (1 * HZ)) ||
- + nf->nr_bytes >= FLOW_FULL_WATERMARK;
- +}
- +
- +
- +
- /* could be called with zero to flush cache and pdu */
- /* this function is guaranteed to be called non-concurrently */
- /* return -1 is trylockfailed, 0 if nothin gexported, >=1 if exported something */
- @@ -2445,6 +2550,11 @@ static unsigned int netflow_target(
- int options = 0;
- int tcpoptions = 0;
- + unsigned int skip = atomic_read(&ipt_netflow_skip);
- + if (skip > 0 ) {
- + return IPT_CONTINUE;
- + }
- +
- iph = skb_header_pointer(skb, 0, (likely(family == AF_INET))? sizeof(_iph.ip) : sizeof(_iph.ip6), &iph);
- if (unlikely(iph == NULL)) {
- NETFLOW_STAT_INC(truncated);
- @@ -2961,6 +3071,7 @@ static int __init ipt_netflow_init(void)
- {
- #ifdef CONFIG_PROC_FS
- struct proc_dir_entry *proc_stat;
- + struct proc_dir_entry *proc_stat_debug;
- #endif
- printk(KERN_INFO "ipt_NETFLOW version %s, srcversion %s\n",
- IPT_NETFLOW_VERSION, THIS_MODULE->srcversion);
- @@ -3003,8 +3114,10 @@ static int __init ipt_netflow_init(void)
- #ifdef CONFIG_PROC_FS
- #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
- proc_stat = create_proc_entry("ipt_netflow", S_IRUGO, INIT_NET(proc_net_stat));
- + proc_stat_debug = create_proc_entry("ipt_netflow_debug", S_IRUGO, INIT_NET(proc_net_stat));
- #else
- proc_stat = proc_create("ipt_netflow", S_IRUGO, INIT_NET(proc_net_stat), &nf_seq_fops);
- + proc_stat_debug = proc_create("ipt_netflow_debug", S_IRUGO, INIT_NET(proc_net_stat), &nf_seq_fops_debug);
- #endif
- if (!proc_stat) {
- printk(KERN_ERR "Unable to create /proc/net/stat/ipt_netflow entry\n");
- @@ -3012,9 +3125,11 @@ static int __init ipt_netflow_init(void)
- }
- #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
- proc_stat->proc_fops = &nf_seq_fops;
- + proc_stat_debug->proc_fops = &nf_seq_fops_debug;
- #endif
- #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
- proc_stat->owner = THIS_MODULE;
- + proc_stat_debug->owner = THIS_MODULE;
- #endif
- printk(KERN_INFO "netflow: registered: /proc/net/stat/ipt_netflow\n");
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement