Skip to contentSkip to conversation

Android netfilter patches (xt_IDLETIMER) [1/3]

PATCH dmitry pervushin 2 participants 2 messages Mar 25, 2013 – Mar 26, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Fix the case in which timer has expired and we refresh it without sending the notification

net/netfilter/xt_IDLETIMER.c +16 -2
index f407ebc1..3540c04 100644
@@ -168,14 +168,22 @@ static unsigned int idletimer_tg_target(struct sk_buff *skb,
 					 const struct xt_action_param *par)
 {
 	const struct idletimer_tg_info *info = par->targinfo;
+	unsigned long now = jiffies;
 
 	pr_debug("resetting timer %s, timeout period %u\n",
 		 info->label, info->timeout);
 
 	BUG_ON(!info->timer);
 
+	if (time_before(info->timer->timer.expires, now)) {
+		schedule_work(&info->timer->work);
+		pr_debug("Starting timer %s (Expired, Jiffies): %lu, %lu\n",
+			 info->label, info->timer->timer.expires, now);
+	}
+
+	/* TODO: Avoid modifying timers on each packet */
 	mod_timer(&info->timer->timer,
-		  msecs_to_jiffies(info->timeout * 1000) + jiffies);
+		  msecs_to_jiffies(info->timeout * 1000) + now);
 
 	return XT_CONTINUE;
 }
@@ -184,6 +192,7 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
 {
 	struct idletimer_tg_info *info = par->targinfo;
 	int ret;
+	unsigned long now = jiffies;
 
 	pr_debug("checkentry targinfo%s\n", info->label);
 
@@ -204,8 +213,13 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
 	info->timer = __idletimer_tg_find_by_label(info->label);
 	if (info->timer) {
 		info->timer->refcnt++;
+		if (time_before(info->timer->timer.expires, now)) {
+			schedule_work(&info->timer->work);
+			pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
+				info->timer->timer.expires, now);
+		}
 		mod_timer(&info->timer->timer,
-			  msecs_to_jiffies(info->timeout * 1000) + jiffies);
+			  msecs_to_jiffies(info->timeout * 1000) + now);
 
 		pr_debug("increased refcnt of timer %s to %u\n",
 			 info->label, info->timer->refcnt);
#1 lore raw

Hi Dmitry,

Quoted 18 lines · dmitry pervushin

Fix the case in which timer has expired and we refresh it without sending the notification

net/netfilter/xt_IDLETIMER.c +1 -0
index f407ebc1..3540c04 100644
@@ -168,14 +168,22 @@ static unsigned int idletimer_tg_target(struct sk_buff *skb,
 					 const struct xt_action_param *par)
 {
 	const struct idletimer_tg_info *info = par->targinfo;
+	unsigned long now = jiffies;
 

net/netfilter/xt_IDLETIMER.c static unsigned int idletimer_tg_target(struct sk_buff *skb, · line 182

Quoted 10 lines
net/netfilter/xt_IDLETIMER.c +5 -0
 	pr_debug("resetting timer %s, timeout period %u\n",
 		 info->label, info->timeout);
 
 	BUG_ON(!info->timer);
 
+	if (time_before(info->timer->timer.expires, now)) {
+		schedule_work(&info->timer->work);
+		pr_debug("Starting timer %s (Expired, Jiffies): %lu, %lu\n",
+			 info->label, info->timer->timer.expires, now);
+	}

Hm, this seems to me like a new feature. With this change, IDLETIMER is sending notifications once the timer becomes active again.

net/netfilter/xt_IDLETIMER.c static unsigned int idletimer_tg_target(struct sk_buff *skb, · line 184

Quoted 2 lines
net/netfilter/xt_IDLETIMER.c +2 -0
+
+	/* TODO: Avoid modifying timers on each packet */

Regarding this TODO, you can adapt this code snippet for this:

unsigned long newtime = jiffies + extra_jiffies;

/* Only update the timeout if the new timeout is at
* least HZ jiffies from the old timeout. Need del_timer
* for race avoidance (may already be dying). */
if (newtime - ct->timeout.expires >= HZ)

        mod_timer_pending(&ct->timeout, newtime);

We're using it in nf_conntrack.

This should come in a separate patch.

Quoted 29 lines
net/netfilter/xt_IDLETIMER.c +8 -2
 	mod_timer(&info->timer->timer,
-		  msecs_to_jiffies(info->timeout * 1000) + jiffies);
+		  msecs_to_jiffies(info->timeout * 1000) + now);
 
 	return XT_CONTINUE;
 }
@@ -184,6 +192,7 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
 {
 	struct idletimer_tg_info *info = par->targinfo;
 	int ret;
+	unsigned long now = jiffies;
 
 	pr_debug("checkentry targinfo%s\n", info->label);
 
@@ -204,8 +213,13 @@ static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
 	info->timer = __idletimer_tg_find_by_label(info->label);
 	if (info->timer) {
 		info->timer->refcnt++;
+		if (time_before(info->timer->timer.expires, now)) {
+			schedule_work(&info->timer->work);
+			pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
+				info->timer->timer.expires, now);
+		}
 		mod_timer(&info->timer->timer,
-			  msecs_to_jiffies(info->timeout * 1000) + jiffies);
+			  msecs_to_jiffies(info->timeout * 1000) + now);
 
 		pr_debug("increased refcnt of timer %s to %u\n",
 			 info->label, info->timer->refcnt);