New netfilter target to trigger LED devices
Subsystems (3)
PATCH v4 2/2 New netfilter target to trigger LED devices
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in /sys/class/leds/
---
Kernel module. Proper structure packing this time.
drivers/leds/Kconfig +3 -0
@@ -217,4 +217,7 @@ This allows LEDs to be initialised in the ON state. If unsure, say Y. +comment "iptables trigger is under Netfilter config (LED target)" + depends on LEDS_TRIGGERS + endif # NEW_LEDS
include/linux/netfilter/Kbuild +1 -0
@@ -7,6 +7,7 @@ header-y += xt_CONNMARK.h header-y += xt_CONNSECMARK.h header-y += xt_DSCP.h +header-y += xt_LED.h header-y += xt_MARK.h header-y += xt_NFLOG.h header-y += xt_NFQUEUE.h
include/linux/netfilter/xt_LED.h +13 -0
@@ -0,0 +1,13 @@ +#ifndef _XT_LED_H +#define _XT_LED_H + +struct xt_led_info { +char id[27 ];/* Unique ID for this trigger in the LED class */ +__u8 always_blink;/* Blink even if the LED is already on */ +__u32 delay;/* Delay until LED is switched off after trigger */ + +/* Kernel data used in the module */ +void *internal_data __attribute__((aligned (8 ))); +}; + +#endif /* _XT_LED_H */
net/netfilter/Kconfig +24 -0
@@ -357,6 +357,30 @@ To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_LED + tristate '"LED" target support' + depends on LEDS_CLASS + depends on NETFILTER_ADVANCED + help + This option adds a `LED' target, which allows you to blink LEDs in + response to particular packets passing through your machine. + + This can be used to turn a spare LED into a network activity LED, + which only flashes in response to FTP transfers, for example. Or + you could have an LED which lights up for a minute or two every time + somebody connects to your machine via SSH. + + You will need support for the "led" class to make this work. + + To create an LED trigger for incoming SSH traffic: + iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000 + + Then attach the new trigger to an LED on your system: + echo netfilter-ssh > /sys/class/leds/<ledname>/trigger + + For more information on the LEDs available on your system, see + Documentation/leds-class.txt + config NETFILTER_XT_TARGET_MARK tristate '"MARK" target support' default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o +obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
net/netfilter/xt_LED.c +199 -0
199 lines not on this page · raw message
net/netfilter/xt_LED.c line 56
Quoted 13 lines · Adam Nielsen
net/netfilter/xt_LED.c +5
-0+static unsigned int +led_tg (struct sk_buff *skb,const struct xt_target_param *par) +{ +const struct xt_led_info *ledinfo = par->targinfo; + /*noconst*/struct xt_led_info_internal *ledinternal =
ledinfo->internal_data;net/netfilter/xt_LED.c +7
-0+ +/* +* Make sure the timer callback doesn't go switching the LED off while +* we're figuring out what to do +*/ +if (ledinfo->delay >0 ) { +mutex_lock (&ledinternal->led_changing_state);
You can't use a mutex here, this might be running in softirq context. Is locking necessary at all? Whats the worst that might happen? The LED might forget to blink once? :)
net/netfilter/xt_LED.c line 121
Quoted 10 lines
net/netfilter/xt_LED.c +10
-0+static bool led_tg_check (const struct xt_tgchk_param *par) +{ +/*noconst*/ struct xt_led_info *ledinfo = par->targinfo; +struct xt_led_info_internal *ledinternal; +int err; + +if (ledinfo->id[0 ] =='\0' ) { + printk(KERN_CRIT KBUILD_MODNAME ": No 'id' parameter given.\n"); +return false; + }
I guess KERN_ERR or default level is enough.
net/netfilter/xt_LED.c line 126
Quoted 5 lines
+ if (!(ledinternal = kzalloc(sizeof(struct
xt_led_info_internal),GFP_KERNEL))) {net/netfilter/xt_LED.c +3
-0+ printk(KERN_CRIT KBUILD_MODNAME ": out of memory\n"); +return false; + }
Please seperate assignments from comparisons.
net/netfilter/xt_LED.c line 132
Quoted 6 lines
net/netfilter/xt_LED.c +6
-0+ + ledinternal->netfilter_led_trigger.name = ledinfo->id; +mutex_init (&ledinternal->led_changing_state); + + printk(KERN_NOTICE KBUILD_MODNAME ": Adding led trigger \"%s\"\n", + ledinfo->id);
Too noisy, no printks except errors please.
Quoted 47 lines
net/netfilter/xt_LED.c +31
-0+ + err =led_trigger_register (&ledinternal->netfilter_led_trigger); +if (err) { + printk(KERN_CRIT KBUILD_MODNAME + ": led_trigger_register() failed\n"); +if (err == -EEXIST ) { + printk(KERN_CRIT KBUILD_MODNAME + ": Trigger name is already in use.\n"); + } + goto exit_alloc; + } + +/* See if we need to set up a timer */ +if (ledinfo->delay >0 ) +setup_timer (&ledinternal->timer, led_timeout_callback, + (unsigned long ) ledinfo); + + ledinfo->internal_data = ledinternal; + +return true; + +exit_alloc: +kfree (ledinternal); + +return false; +} + +static void led_tg_destroy (const struct xt_tgdtor_param *par) +{ +const struct xt_led_info *ledinfo = par->targinfo; + /*noconst*/struct xt_led_info_internal *ledinternal =
ledinfo->internal_data;net/netfilter/xt_LED.c +14
-0+ + printk(KERN_NOTICE KBUILD_MODNAME ": Removing led trigger \"%s\"\n", + ledinternal->netfilter_led_trigger.name); + +if (ledinfo->delay >0 ) +del_timer_sync (&ledinternal->timer); + +led_trigger_unregister (&ledinternal->netfilter_led_trigger); +kfree (ledinternal); +} + +static int __init led_tg_init (void ) +{ + printk(KERN_NOTICE KBUILD_MODNAME ": Registering LED netfilter
Quoted 1 line
target\n");
This is too noisy, please remove this.
Quoted 10 lines
net/netfilter/xt_LED.c +6
-0+return xt_register_target (&led_tg_reg); +} + +static void __exit led_tg_exit(void) +{ + printk(KERN_NOTICE KBUILD_MODNAME ": Unregistering LED netfiltertarget\n");
net/netfilter/xt_LED.c +2
-0+xt_unregister_target (&led_tg_reg); +}
PATCH v5 2/2 New netfilter target to trigger LED devices
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in /sys/class/leds/
---
Thanks for the feedback Patrick - here is the updated version with your suggestions:
- Mutexes removed - I concede that missing a blink here and there is acceptable :-)
- KERN_ERR used for non-critical errors, all KERN_NOTICEs removed
- Split assignment out from comparison in kzalloc()
Hope this one's okay!
drivers/leds/Kconfig +3 -0
@@ -217,4 +217,7 @@ This allows LEDs to be initialised in the ON state. If unsure, say Y. +comment "iptables trigger is under Netfilter config (LED target)" + depends on LEDS_TRIGGERS + endif # NEW_LEDS
include/linux/netfilter/Kbuild +1 -0
@@ -7,6 +7,7 @@ header-y += xt_CONNMARK.h header-y += xt_CONNSECMARK.h header-y += xt_DSCP.h +header-y += xt_LED.h header-y += xt_MARK.h header-y += xt_NFLOG.h header-y += xt_NFQUEUE.h
include/linux/netfilter/xt_LED.h +13 -0
@@ -0,0 +1,13 @@ +#ifndef _XT_LED_H +#define _XT_LED_H + +struct xt_led_info { +char id[27 ];/* Unique ID for this trigger in the LED class */ +__u8 always_blink;/* Blink even if the LED is already on */ +__u32 delay;/* Delay until LED is switched off after trigger */ + +/* Kernel data used in the module */ +void *internal_data __attribute__((aligned (8 ))); +}; + +#endif /* _XT_LED_H */
net/netfilter/Kconfig +24 -0
@@ -357,6 +357,30 @@ To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_LED + tristate '"LED" target support' + depends on LEDS_CLASS + depends on NETFILTER_ADVANCED + help + This option adds a `LED' target, which allows you to blink LEDs in + response to particular packets passing through your machine. + + This can be used to turn a spare LED into a network activity LED, + which only flashes in response to FTP transfers, for example. Or + you could have an LED which lights up for a minute or two every time + somebody connects to your machine via SSH. + + You will need support for the "led" class to make this work. + + To create an LED trigger for incoming SSH traffic: + iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000 + + Then attach the new trigger to an LED on your system: + echo netfilter-ssh > /sys/class/leds/<ledname>/trigger + + For more information on the LEDs available on your system, see + Documentation/leds-class.txt + config NETFILTER_XT_TARGET_MARK tristate '"MARK" target support' default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o +obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
net/netfilter/xt_LED.c +162 -0
162 lines not on this page · raw message
Quoted 11 lines · Adam Nielsen
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in
/sys/class/leds/Signed-off-by Adam Nielsen <[email protected]>---
Thanks for the feedback Patrick - here is the updated version with your suggestions:
Quoted 6 lines
- Mutexes removed - I concede that missing a blink here and there is acceptable :-)
-KERN_ERRused for non-critical errors, allKERN_NOTICEsremoved
- Split assignment out from comparison inkzalloc()Hope this one's okay!
Apart from some minor cosmetic issues that I'm simply going to fix up when applying, it looks fine to me. If Richard is also ok with this I'll apply it.
Richard Purdie
Acked-byQuoted 17 lines · Patrick McHardy
Quoted 16 lines · Adam Nielsen
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in
/sys/class/leds/Signed-off-by Adam Nielsen <[email protected]>---
Thanks for the feedback Patrick - here is the updated version with your suggestions:
- Mutexes removed - I concede that missing a blink here and there is acceptable :-)
-KERN_ERRused for non-critical errors, allKERN_NOTICEsremoved
- Split assignment out from comparison inkzalloc()
Quoted 5 lines
Quoted 1 line
Hope this one's okay!
Apart from some minor cosmetic issues that I'm simply going to fix up when applying, it looks fine to me. If Richard is also ok with this I'll apply it.
Looks good to me.
Signature · 2 lines
Richard Purdie Intel Open Source Technology Centre
Quoted 18 lines · Richard Purdie
Quoted 17 lines · Patrick McHardy
Quoted 16 lines · Adam Nielsen
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in
/sys/class/leds/Signed-off-by Adam Nielsen <[email protected]>---
Thanks for the feedback Patrick - here is the updated version with your suggestions:
- Mutexes removed - I concede that missing a blink here and there is acceptable :-)
-KERN_ERRused for non-critical errors, allKERN_NOTICEsremoved
- Split assignment out from comparison inkzalloc()
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Hope this one's okay!
Apart from some minor cosmetic issues that I'm simply going to fix up when applying, it looks fine to me. If Richard is also ok with this I'll apply it.
Looks good to me.
Acked-by Richard Purdie <[email protected]>
Thanks Richard.
Adam, I wanted to apply this, but I get rejects for every single existing file. There appears to be some whitespace damage, please resend as attachment.
Adam Nielsen
Acked-by Richard PurdieQuoted 3 lines
Adam, I wanted to apply this, but I get rejects for every single existing file. There appears to be some whitespace damage, please resend as attachment.
Hmm, that's odd - Thunderbird must not like sending tabs - sorry about that!
I hope the attached files work better.
Cheers,
Adam.
Kernel module providing implementation of LED netfilter target. Each instance of the target appears as a led-trigger device, which can be associated with one or more LEDs in /sys/class/leds/
---
drivers/leds/Kconfig +3 -0
@@ -217,4 +217,7 @@ This allows LEDs to be initialised in the ON state. If unsure, say Y. +comment "iptables trigger is under Netfilter config (LED target)" + depends on LEDS_TRIGGERS + endif # NEW_LEDS
include/linux/netfilter/Kbuild +1 -0
@@ -7,6 +7,7 @@ header-y += xt_CONNMARK.h header-y += xt_CONNSECMARK.h header-y += xt_DSCP.h +header-y += xt_LED.h header-y += xt_MARK.h header-y += xt_NFLOG.h header-y += xt_NFQUEUE.h
include/linux/netfilter/xt_LED.h +13 -0
@@ -0,0 +1,13 @@ +#ifndef _XT_LED_H +#define _XT_LED_H + +struct xt_led_info { +char id[27 ];/* Unique ID for this trigger in the LED class */ +__u8 always_blink;/* Blink even if the LED is already on */ +__u32 delay;/* Delay until LED is switched off after trigger */ + +/* Kernel data used in the module */ +void *internal_data __attribute__((aligned (8 ))); +}; + +#endif /* _XT_LED_H */
net/netfilter/Kconfig +24 -0
@@ -357,6 +357,30 @@ To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_LED + tristate '"LED" target support' + depends on LEDS_CLASS + depends on NETFILTER_ADVANCED + help + This option adds a `LED' target, which allows you to blink LEDs in + response to particular packets passing through your machine. + + This can be used to turn a spare LED into a network activity LED, + which only flashes in response to FTP transfers, for example. Or + you could have an LED which lights up for a minute or two every time + somebody connects to your machine via SSH. + + You will need support for the "led" class to make this work. + + To create an LED trigger for incoming SSH traffic: + iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000 + + Then attach the new trigger to an LED on your system: + echo netfilter-ssh > /sys/class/leds/<ledname>/trigger + + For more information on the LEDs available on your system, see + Documentation/leds-class.txt + config NETFILTER_XT_TARGET_MARK tristate '"MARK" target support' default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o +obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
net/netfilter/xt_LED.c +162 -0
162 lines not on this page · raw message
Add a new "LED" target to iptables, which allows LEDs to blink in response to matching rules.
---
extensions/libxt_LED.c new file +158 -0
158 lines not on this page · raw message
extensions/libxt_LED.man new file +30 -0
@@ -0,0 +1,30 @@ +This creates an LED-trigger that can then be attached to system indicator +lights, to blink or illuminate them when certain packets pass through the +system. One example might be to light up an LED for a few minutes every time +an SSH connection is made to the local machine. The following options control +the trigger behaviour: +.TP +\fB--led-trigger-id\fP \fIname\fP +This is the name given to the LED trigger. The actual name of the trigger +will be prefixed with "netfilter-". +.TP +\fB--led-delay\fP \fIms\fP +This indicates how long (in milliseconds) the LED should be left illuminated +when a packet arrives before being switched off again. The default is 0 +(blink as fast as possible.) The special value \fIinf\fP can be given to +leave the LED on permanently once activated. (In this case the trigger will +need to be manually detached and reattached to the LED device to switch it +off again.) +.TP +\fB--led-always-blink\fP +Always make the LED blink on packet arrival, even if the LED is already on. +This allows notification of new packets even with long delay values (which +otherwise would result in a silent prolonging of the delay time.) +.TP +Example: +.TP +Create an LED trigger for incoming SSH traffic: +iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh +.TP +Then attach the new trigger to an LED: +echo netfilter-ssh > /sys/class/leds/<ledname>/trigger
include/linux/netfilter/xt_LED.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _XT_LED_H +#define _XT_LED_H + +struct xt_led_info { +char id[27 ];/* Unique ID for this trigger in the LED class */ +__u8 always_blink;/* Blink even if the LED is already on */ +__u32 delay;/* Delay until LED is switched off after trigger */ + +/* Kernel data used in the module */ +void *internal_data __attribute__((aligned (8 ))); +}; + +#endif /* _XT_LED_H */
Quoted 8 lines · Adam Nielsen
Quoted 3 lines
Adam, I wanted to apply this, but I get rejects for every single existing file. There appears to be some whitespace damage, please resend as attachment.
Hmm, that's odd - Thunderbird must not like sending tabs - sorry about that!
I hope the attached files work better.
It applies with some minor manual fixups (please diff against the nf-next tree at git.kernel.org). It doesn't compile though:
CC [M] net/netfilter/xt_LED.onet/netfilter/xt_LED.c:40: error: field 'netfilter_led_trigger' has incomplete type net/netfilter/xt_LED.c: In function 'led_timeout_callback':net/netfilter/xt_LED.c:77: warning: unused variable 'ledinternal' net/netfilter/xt_LED.c: In function 'led_tg_check':net/netfilter/xt_LED.c:101: error: implicit declaration of function 'led_trigger_register' net/netfilter/xt_LED.c: In function 'led_tg_destroy':net/netfilter/xt_LED.c:134: error: implicit declaration of function 'led_trigger_unregister'
Patrick McHardy
AppliedQuoted 8 lines · Adam Nielsen
Quoted 3 lines
Adam, I wanted to apply this, but I get rejects for every single existing file. There appears to be some whitespace damage, please resend as attachment.
Hmm, that's odd - Thunderbird must not like sending tabs - sorry about that!
I hope the attached files work better.
Applied, thanks. I've made some minor cosmetic changes, like removal of /* noconst */ annotations and fixing indentation in one spot.
You can look at the final commit at:
git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.git
Quoted 6 lines
Applied, thanks. I've made some minor cosmetic changes, like removal of /* noconst */ annotations and fixing indentation in one spot.
You can look at the final commit at:
git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.git
Thanks Patrick, looks fine. Did you fix the compile errors in your other post, or do you still want me to look at them? It looks like it was compiled with LED support disabled, which I thought the kernel should take care of (not allowing the file to be compiled if LED support was not present.)
Did the other companion patch (1/2, the one to netfilter) also get committed?
Without that the new kernel module won't ever be used.
Cheers,
Adam.
Quoted 8 lines · Adam Nielsen
Quoted 6 lines
Applied, thanks. I've made some minor cosmetic changes, like removal of /* noconst */ annotations and fixing indentation in one spot.
You can look at the final commit at:
git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6.gitThanks Patrick, looks fine. Did you fix the compile errors in your other post, or do you still want me to look at them? It looks like it was compiled with LED support disabled, which I thought the kernel should take care of (not allowing the file to be compiled if LED support was not present.)
I did enable LED support to be able to select it. Might be a mistake when rebuilding on my side though, the latest patch compiles cleanly.
Quoted 1 line
Did the other companion patch (1/2, the one to netfilter) also get committed? Without that the new kernel module won't ever be used.
That will get committed when the new -rc window starts so we don't include the userspace code in a release before the kernel part is released (and thus still can fix any mistakes that come up).