New netfilter target to trigger LED devices
Subsystems (3)
PATCH v2 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/
---
Here's the kernel module. I haven't removed the /*noconst*/ as queried by Alexey Dobriyan, as my justification for having it seems to have been accepted.
Changes since the last post:
- Fixed variadic-size types in xt_led_info
- Made use of KBUILD_MODNAME
- Added --led-always-blink since Jan suggested the commented out code could be a feature :-)
- Added KERN_ levels to all printk()s
- Coding style fixes
- xt_led_info moved to the shared .h file
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 +12 -0
@@ -0,0 +1,12 @@ +#ifndef _XT_LED_H +#define _XT_LED_H + +struct xt_led_info { +char id[26 ];/* Unique ID for this trigger in the LED class */ +__u32 delay;/* Delay until LED is switched off after trigger */ +__u8 always_blink;/* Blink even if the LED is already on */ + +void *internal_data;/* Kernel data used in the module */ +}; + +#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 +191 -0
191 lines not on this page · raw message
Quoted 7 lines · Adam Nielsen
+/*
+ * Known issues:
+ *
+ * - It's possible to add multiple led triggers with the same name (as
+ * set with --led-trigger-id)
+ *
+ */
So fix this?
net/netfilter/xt_LED.c line 103
Quoted 4 lines
net/netfilter/xt_LED.c +4
-0+/* If the timer has expired while we're changing the state, then don't +interfere. We also don't want to twiddle with anything after the +mutex is unlocked, because by then a new timeout will have been +set. */
Not that it is overly important, but the comment style generally seems to be (for multilines)
m{^(\s+)/\*\n(\1 \* \w+\n)+\1 \*/\n}
Quoted 9 lines
Quoted 7 lines
+/*
+ * Known issues:
+ *
+ * - It's possible to add multiple led triggers with the same name (as
+ * set with --led-trigger-id)
+ *
+ */So fix this?
I don't know how :-( Since the LED hardware class doesn't (to my knowledge) allow you to get a list of available LED triggers on the system, I'd have to have some sort of global list that I append to every time a trigger is created. Given the likelihood of this happening (and the fact that it mostly works having two triggers with the same name, it just looks bad) I didn't think it was important enough for the additional code.
If this functionality is added to the LED class then I will happily update my code to make use of it.
Quoted 3 lines
Not that it is overly important, but the comment style generally seems to be (for multilines)
m{^(\s+)/\*\n(\1 \* \w+\n)+\1 \*/\n}
Will fix in the next revision. I'm hoping to hear back from the "LED people" before posting again as per Patrick's comment.
Cheers,
Adam.
Quoted 8 lines · Adam Nielsen
Quoted 8 lines
Quoted 7 lines
+/*
+ * Known issues:
+ *
+ * - It's possible to add multiple led triggers with the same name (as
+ * set with --led-trigger-id)
+ *
+ */
Quoted 4 lines
Quoted 1 line
So fix this?
I don't know how :-( Since the LED hardware class doesn't (to my knowledge) allow you to get a list of available LED triggers on the system,
But it may allow you to *test* the presence using something like
checkentry() {
...
char buf[];
strcpy(buf,"netfilter-");
strcat(buf,name);
if (led_get(buf) != NULL) {
printk(KERN_WARNING "That thing already exists\n");
return false;
}
...
}No? In that case, you could keep a list of names withint he module itself:
struct name_entry {
struct list_head list;
char *name;
}
struct list_head known_names;
checkentry() {
char buf[];
...
list_for_each_entry(i, known_names, list)
if (strcmp(buf, i->name) == 0) {
printk("that already exists\n");
return false;
}
...
i = kmalloc(*i, GFP_KERNEL);
i->name = strdup(buf);
list_add(&known_names, &i->list);
}something like that..
Quoted 5 lines
I'd have to
have some sort of global list that I append to every time a trigger is created. Given the likelihood of this happening (and the fact that it mostly works having two triggers with the same name, it just looks bad) I didn't think it was important enough for the additional code.
I will let others judge that ;-)
Quoted 2 lines
If this functionality is added to the LED class then I will happily update my code to make use of it.
Yeah it would be best if the led class provided something. (preferably a btree/hashlookup)