Skip to contentSkip to conversation

New netfilter target to trigger LED devices

PATCH Superseded Adam Nielsen 2 participants 3 messages Feb 11, 2009

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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 matching kernel module.

drivers/leds/Kconfig +3 -0
diff -urN linux-2.6.28.3-orig/drivers/leds/Kconfig linux-2.6.28.3/drivers/leds/Kconfig
@@ -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
diff -urN linux-2.6.28.3-orig/include/linux/netfilter/Kbuild linux-2.6.28.3/include/linux/netfilter/Kbuild
@@ -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
diff -urN linux-2.6.28.3-orig/include/linux/netfilter/xt_LED.h linux-2.6.28.3/include/linux/netfilter/xt_LED.h
@@ -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
diff -urN linux-2.6.28.3-orig/net/netfilter/Kconfig linux-2.6.28.3/net/netfilter/Kconfig
@@ -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
diff -urN linux-2.6.28.3-orig/net/netfilter/Makefile linux-2.6.28.3/net/netfilter/Makefile
@@ -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

#1 lore raw

include/linux/netfilter/xt_LED.h line 9

Quoted 6 lines · Adam Nielsen
include/linux/netfilter/xt_LED.h +6 -0
+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 */

I wonder. We talked about alignment and padding, but it seemed to not have helped :)

This really needs

	void *internal_data __attribute__((aligned(8)))

And because 26+4+1 = 31, you can make that id[27] to fill-it-up.

Otherwise pretty clean.

#2 lore raw
Quoted 2 lines

I wonder. We talked about alignment and padding, but it seemed to not have helped :)

Aaagh! I forgot to go back and fix that up :-( Sorry about that. New version coming soon.

Thanks,
Adam.