Skip to content

Commit a609108

Browse files
committed
Module option to lock exporter to single cpu (exportcpu).
Also could be controlled at runtime via echo # > /sys/module/ipt_NETFLOW/parameters/exportcpu
1 parent 53de3f9 commit a609108

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ipt_NETFLOW.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ static int active_timeout = 30 * 60;
175175
module_param(active_timeout, int, 0644);
176176
MODULE_PARM_DESC(active_timeout, "active flows timeout in seconds");
177177

178+
static int exportcpu = -1;
179+
module_param(exportcpu, int, 0644);
180+
MODULE_PARM_DESC(exportcpu, "lock exporter to this cpu");
181+
178182
static int debug = 0;
179183
module_param(debug, int, 0644);
180184
MODULE_PARM_DESC(debug, "debug verbosity level");
@@ -185,7 +189,7 @@ MODULE_PARM_DESC(sndbuf, "udp socket SNDBUF size");
185189

186190
static int protocol = 5;
187191
module_param(protocol, int, 0444);
188-
MODULE_PARM_DESC(protocol, "netflow protocol version (5, 9, 10)");
192+
MODULE_PARM_DESC(protocol, "netflow protocol version (5, 9, 10=IPFIX)");
189193

190194
static unsigned int refresh_rate = 20;
191195
module_param(refresh_rate, uint, 0644);
@@ -213,7 +217,7 @@ static DEFINE_SPINLOCK(snmp_lock);
213217
#ifdef CONFIG_NF_NAT_NEEDED
214218
static int natevents = 0;
215219
module_param(natevents, int, 0444);
216-
MODULE_PARM_DESC(natevents, "send NAT Events");
220+
MODULE_PARM_DESC(natevents, "enable NAT Events");
217221
#endif
218222

219223
static int hashsize;
@@ -358,6 +362,8 @@ static DEFINE_MUTEX(worker_lock);
358362
static int worker_delay = HZ / 10;
359363
static inline void _schedule_scan_worker(const int status)
360364
{
365+
int cpu = exportcpu;
366+
361367
/* rudimentary congestion avoidance */
362368
if (status > 0)
363369
worker_delay -= status;
@@ -370,6 +376,17 @@ static inline void _schedule_scan_worker(const int status)
370376
worker_delay = scan_min;
371377
else if (worker_delay > scan_max)
372378
worker_delay = scan_max;
379+
380+
if (cpu >= 0) {
381+
if (cpu < NR_CPUS &&
382+
cpu_online(cpu)) {
383+
schedule_delayed_work_on(cpu, &netflow_work, worker_delay);
384+
return;
385+
}
386+
printk(KERN_WARNING "ipt_NETFLOW: can't schedule exporter on cpu %d. Disabling cpu lock.\n",
387+
cpu);
388+
exportcpu = -1;
389+
}
373390
schedule_delayed_work(&netflow_work, worker_delay);
374391
}
375392

0 commit comments

Comments
 (0)