All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] idletimer extension :  Add alarm timer option
@ 2020-04-15  7:24 Manoj Basapathi
  2020-04-15  7:59 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Manoj Basapathi @ 2020-04-15  7:24 UTC (permalink / raw)
  To: netfilter-devel
  Cc: coreteam, pablo, sharathv, ssaha, vidulak, manojbm, subashab,
	Manoj Basapathi, Sauvik Saha

Introduce "--alarm" option for idletimer rule.
If it is present, hardidle-timer is used, else default timer.
The default idletimer starts a deferrable timer or in other
words the timer will cease to run when cpu is in suspended
state. This change introduces the option to start a
non-deferrable or alarm timer which will continue to run even
when the cpu is in suspended state.

Signed-off-by: Manoj Basapathi <manojbm@codeaurora.org>
Signed-off-by: Sauvik Saha <ssaha@codeaurora.org>
---
 extensions/libxt_IDLETIMER.c           | 99 ++++++++++++++++++++++----
 include/linux/netfilter/xt_IDLETIMER.h | 11 +++
 2 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/extensions/libxt_IDLETIMER.c b/extensions/libxt_IDLETIMER.c
index 21004a4b..68b223f4 100644
--- a/extensions/libxt_IDLETIMER.c
+++ b/extensions/libxt_IDLETIMER.c
@@ -27,6 +27,7 @@
 enum {
 	O_TIMEOUT = 0,
 	O_LABEL,
+	O_ALARM,
 };
 
 #define s struct idletimer_tg_info
@@ -39,6 +40,17 @@ static const struct xt_option_entry idletimer_tg_opts[] = {
 };
 #undef s
 
+#define s struct idletimer_tg_info_v1
+static const struct xt_option_entry idletimer_tg_opts_v1[] = {
+	{.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32,
+	 .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)},
+	{.name = "label", .id = O_LABEL, .type = XTTYPE_STRING,
+	 .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)},
+	{.name = "alarm", .id = O_ALARM, .type = XTTYPE_NONE},
+	XTOPT_TABLEEND,
+};
+#undef s
+
 static void idletimer_tg_help(void)
 {
 	printf(
@@ -48,6 +60,16 @@ static void idletimer_tg_help(void)
 "\n");
 }
 
+static void idletimer_tg_help_v1(void)
+{
+	printf(
+"IDLETIMER target options:\n"
+" --timeout time	Timeout until the notification is sent (in seconds)\n"
+" --label string	Unique rule identifier\n"
+" --alarm none	    Use alarm instead of default timer\n"
+"\n");
+}
+
 static void idletimer_tg_print(const void *ip,
 			       const struct xt_entry_target *target,
 			       int numeric)
@@ -59,6 +81,20 @@ static void idletimer_tg_print(const void *ip,
 	printf(" label:%s", info->label);
 }
 
+static void idletimer_tg_print_v1(const void *ip,
+			       const struct xt_entry_target *target,
+			       int numeric)
+{
+	struct idletimer_tg_info_v1 *info =
+		(struct idletimer_tg_info_v1 *) target->data;
+
+	printf(" timeout:%u", info->timeout);
+	printf(" label:%s", info->label);
+	if (info->timer_type == XT_IDLETIMER_ALARM)
+		printf(" alarm");
+}
+
+
 static void idletimer_tg_save(const void *ip,
 			      const struct xt_entry_target *target)
 {
@@ -69,21 +105,58 @@ static void idletimer_tg_save(const void *ip,
 	printf(" --label %s", info->label);
 }
 
-static struct xtables_target idletimer_tg_reg = {
-	.family	       = NFPROTO_UNSPEC,
-	.name	       = "IDLETIMER",
-	.version       = XTABLES_VERSION,
-	.revision      = 0,
-	.size	       = XT_ALIGN(sizeof(struct idletimer_tg_info)),
-	.userspacesize = offsetof(struct idletimer_tg_info, timer),
-	.help	       = idletimer_tg_help,
-	.x6_parse      = xtables_option_parse,
-	.print	       = idletimer_tg_print,
-	.save	       = idletimer_tg_save,
-	.x6_options    = idletimer_tg_opts,
+static void idletimer_tg_save_v1(const void *ip,
+			      const struct xt_entry_target *target)
+{
+	struct idletimer_tg_info_v1 *info =
+		(struct idletimer_tg_info_v1 *) target->data;
+
+	printf(" --timeout %u", info->timeout);
+	printf(" --label %s", info->label);
+	if (info->timer_type == XT_IDLETIMER_ALARM)
+		printf(" --alarm");
+}
+
+static void idletimer_tg_parse_v1(struct xt_option_call *cb)
+{
+	struct idletimer_tg_info_v1 *info = cb->data;
+
+	xtables_option_parse(cb);
+	if (cb->entry->id == O_ALARM)
+		info->timer_type = XT_IDLETIMER_ALARM;
+}
+
+static struct xtables_target idletimer_tg_reg[] = {
+	{
+		.family	       = NFPROTO_UNSPEC,
+		.name	       = "IDLETIMER",
+		.version       = XTABLES_VERSION,
+		.revision      = 0,
+		.size	       = XT_ALIGN(sizeof(struct idletimer_tg_info)),
+		.userspacesize = offsetof(struct idletimer_tg_info, timer),
+		.help	       = idletimer_tg_help,
+		.x6_parse      = xtables_option_parse,
+		.print	       = idletimer_tg_print,
+		.save	       = idletimer_tg_save,
+		.x6_options    = idletimer_tg_opts,
+	},
+	{
+		.family	       = NFPROTO_UNSPEC,
+		.name	       = "IDLETIMER",
+		.version       = XTABLES_VERSION,
+		.revision      = 1,
+		.size	       = XT_ALIGN(sizeof(struct idletimer_tg_info_v1)),
+		.userspacesize = offsetof(struct idletimer_tg_info_v1, timer),
+		.help	       = idletimer_tg_help_v1,
+		.x6_parse      = idletimer_tg_parse_v1,
+		.print	       = idletimer_tg_print_v1,
+		.save	       = idletimer_tg_save_v1,
+		.x6_options    = idletimer_tg_opts_v1,
+	},
+
 };
 
 void _init(void)
 {
-	xtables_register_target(&idletimer_tg_reg);
+	xtables_register_targets(idletimer_tg_reg, ARRAY_SIZE(idletimer_tg_reg));
 }
diff --git a/include/linux/netfilter/xt_IDLETIMER.h b/include/linux/netfilter/xt_IDLETIMER.h
index 208ae938..434e6506 100644
--- a/include/linux/netfilter/xt_IDLETIMER.h
+++ b/include/linux/netfilter/xt_IDLETIMER.h
@@ -32,6 +32,7 @@
 #include <linux/types.h>
 
 #define MAX_IDLETIMER_LABEL_SIZE 28
+#define XT_IDLETIMER_ALARM 0x01
 
 struct idletimer_tg_info {
 	__u32 timeout;
@@ -42,4 +43,14 @@ struct idletimer_tg_info {
 	struct idletimer_tg *timer __attribute__((aligned(8)));
 };
 
+struct idletimer_tg_info_v1 {
+	__u32 timeout;
+
+	char label[MAX_IDLETIMER_LABEL_SIZE];
+
+	__u8 timer_type;
+
+	/* for kernel module internal use only */
+	struct idletimer_tg *timer __attribute__((aligned(8)));
+};
 #endif
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] idletimer extension :  Add alarm timer option
  2020-04-15  7:24 [PATCH] idletimer extension : Add alarm timer option Manoj Basapathi
@ 2020-04-15  7:59 ` Pablo Neira Ayuso
  2020-04-15  8:38   ` manojbm
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-15  7:59 UTC (permalink / raw)
  To: Manoj Basapathi
  Cc: netfilter-devel, coreteam, sharathv, ssaha, vidulak, manojbm,
	subashab, Sauvik Saha

Hi Manoj

On Wed, Apr 15, 2020 at 12:54:11PM +0530, Manoj Basapathi wrote:
> Introduce "--alarm" option for idletimer rule.
> If it is present, hardidle-timer is used, else default timer.
> The default idletimer starts a deferrable timer or in other
> words the timer will cease to run when cpu is in suspended
> state. This change introduces the option to start a
> non-deferrable or alarm timer which will continue to run even
> when the cpu is in suspended state.

Would you include the recent update from Maciej:

        iptables: open eBPF programs in read only mode

in v2.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] idletimer extension :  Add alarm timer option
  2020-04-15  7:59 ` Pablo Neira Ayuso
@ 2020-04-15  8:38   ` manojbm
  2020-04-15  9:33     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: manojbm @ 2020-04-15  8:38 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: netfilter-devel, coreteam, sharathv, ssaha, vidulak, manojbm,
	subashab, Sauvik Saha

On 2020-04-15 13:29, Pablo Neira Ayuso wrote:
> Hi Manoj
> 
> On Wed, Apr 15, 2020 at 12:54:11PM +0530, Manoj Basapathi wrote:
>> Introduce "--alarm" option for idletimer rule.
>> If it is present, hardidle-timer is used, else default timer.
>> The default idletimer starts a deferrable timer or in other
>> words the timer will cease to run when cpu is in suspended
>> state. This change introduces the option to start a
>> non-deferrable or alarm timer which will continue to run even
>> when the cpu is in suspended state.
> 
> Would you include the recent update from Maciej:
> 
>         iptables: open eBPF programs in read only mode
> 
> in v2.
> 
> Thanks.

Hi Pablo,

IDLETIMER is not using bpf_obj_get function.
Can you please give me more details on how to include Maciej commit 
here.

Thanks,
Manoj

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] idletimer extension :  Add alarm timer option
  2020-04-15  8:38   ` manojbm
@ 2020-04-15  9:33     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-04-15  9:33 UTC (permalink / raw)
  To: manojbm
  Cc: netfilter-devel, coreteam, sharathv, ssaha, vidulak, manojbm,
	subashab, Sauvik Saha

On Wed, Apr 15, 2020 at 02:08:53PM +0530, manojbm@codeaurora.org wrote:
[...]
> Can you please give me more details on how to include Maciej commit here.

Wrong commit, sorry:

commit bc9fe6143de5df8fb36cf1532b48fecf35868571
Author: Maciej Żenczykowski <maze@google.com>
Date:   Tue Mar 31 09:35:59 2020 -0700

    netfilter: xt_IDLETIMER: target v1 - match Android layout

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-15  9:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15  7:24 [PATCH] idletimer extension : Add alarm timer option Manoj Basapathi
2020-04-15  7:59 ` Pablo Neira Ayuso
2020-04-15  8:38   ` manojbm
2020-04-15  9:33     ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.