summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorJP Abgrall <jpa@google.com>2012-05-04 14:26:57 -0700
committerJP Abgrall <jpa@google.com>2012-05-04 15:00:33 -0700
commitf109fa626b97c4c7d213bfcd5cdb557a4e87d0ec (patch)
treeccb7a47d9ce67fe4398b8db602833d6926baef0d /net
parent758aaf52f607604164e93feff93b725d491e44f7 (diff)
netfilter: xt_IDLETIMER: Use uevent instead of new netlink msg type
Send netlink message notifications using a uevent with subsystem=xt_idletimer INTERFACE=... STATE={active,inactive} instead of needing a new netlink message type. Revert the netlink.h change added by commit beb914e987cbbd368988d2b94a6661cb907c4d5a Change-Id: I6881936bf754f3367ff3c8f6c1e9661cec0357d4 Signed-off-by: JP Abgrall <jpa@google.com>
Diffstat (limited to 'net')
-rw-r--r--net/netfilter/xt_IDLETIMER.c66
1 files changed, 20 insertions, 46 deletions
diff --git a/net/netfilter/xt_IDLETIMER.c b/net/netfilter/xt_IDLETIMER.c
index a192f55e8494..43a16d0bb629 100644
--- a/net/netfilter/xt_IDLETIMER.c
+++ b/net/netfilter/xt_IDLETIMER.c
@@ -37,7 +37,6 @@
#include <linux/netfilter.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter/xt_IDLETIMER.h>
-#include <linux/netlink.h>
#include <linux/kdev_t.h>
#include <linux/kobject.h>
#include <linux/skbuff.h>
@@ -45,8 +44,6 @@
#include <linux/sysfs.h>
#include <net/net_namespace.h>
-static struct sock *nl_sk;
-
struct idletimer_tg_attr {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj,
@@ -71,44 +68,30 @@ static DEFINE_MUTEX(list_mutex);
static struct kobject *idletimer_tg_kobj;
-static void notify_netlink(const char *iface, struct idletimer_tg *timer)
+static void notify_netlink_uevent(const char *iface, struct idletimer_tg *timer)
{
- struct sk_buff *log_skb;
- size_t size;
- struct nlmsghdr *nlh;
- char str[NLMSG_MAX_SIZE];
- int event_type, res;
-
- size = NLMSG_SPACE(NLMSG_MAX_SIZE);
- size = max(size, (size_t)NLMSG_GOODSIZE);
- log_skb = alloc_skb(size, GFP_ATOMIC);
- if (!log_skb) {
- pr_err("xt_cannot alloc skb for logging\n");
+ char iface_msg[NLMSG_MAX_SIZE];
+ char state_msg[NLMSG_MAX_SIZE];
+ char *envp[] = { iface_msg, state_msg, NULL };
+ int res;
+
+ res = snprintf(iface_msg, NLMSG_MAX_SIZE, "INTERFACE=%s",
+ iface);
+ if (NLMSG_MAX_SIZE <= res) {
+ pr_err("message too long (%d)", res);
return;
}
-
- event_type = timer->active ? NL_EVENT_TYPE_ACTIVE
- : NL_EVENT_TYPE_INACTIVE;
- res = snprintf(str, NLMSG_MAX_SIZE, "%s %s\n", iface,
- timer->active ? "ACTIVE" : "INACTIVE");
- if (NLMSG_MAX_SIZE <= res)
- goto nlmsg_failure;
-
- /* NLMSG_PUT() uses "goto nlmsg_failure" */
- nlh = NLMSG_PUT(log_skb, /*pid*/0, /*seq*/0, event_type,
- /* Size of message */NLMSG_MAX_SIZE);
-
- strncpy(NLMSG_DATA(nlh), str, MAX_IDLETIMER_LABEL_SIZE);
-
- NETLINK_CB(log_skb).dst_group = 1;
- netlink_broadcast(nl_sk, log_skb, 0, 1, GFP_ATOMIC);
-
- pr_debug("putting nlmsg: %s", str);
+ res = snprintf(state_msg, NLMSG_MAX_SIZE, "STATE=%s",
+ timer->active ? "active" : "inactive");
+ if (NLMSG_MAX_SIZE <= res) {
+ pr_err("message too long (%d)", res);
+ return;
+ }
+ pr_debug("putting nlmsg: <%s> <%s>\n", iface_msg, state_msg);
+ kobject_uevent_env(idletimer_tg_kobj, KOBJ_CHANGE, envp);
return;
-nlmsg_failure: /* Used within NLMSG_PUT() */
- consume_skb(log_skb);
- pr_debug("Failed nlmsg_put\n");
+
}
static
@@ -160,7 +143,7 @@ static void idletimer_tg_work(struct work_struct *work)
sysfs_notify(idletimer_tg_kobj, NULL, timer->attr.attr.name);
if (timer->send_nl_msg)
- notify_netlink(timer->attr.attr.name, timer);
+ notify_netlink_uevent(timer->attr.attr.name, timer);
}
static void idletimer_tg_expired(unsigned long data)
@@ -370,15 +353,6 @@ static int __init idletimer_tg_init(void)
goto out_dev;
}
- nl_sk = netlink_kernel_create(&init_net,
- NETLINK_IDLETIMER, 1, NULL,
- NULL, THIS_MODULE);
-
- if (!nl_sk) {
- pr_err("Failed to create netlink socket\n");
- return -ENOMEM;
- }
-
return 0;
out_dev:
device_destroy(idletimer_tg_class, MKDEV(0, 0));