From f109fa626b97c4c7d213bfcd5cdb557a4e87d0ec Mon Sep 17 00:00:00 2001 From: JP Abgrall Date: Fri, 4 May 2012 14:26:57 -0700 Subject: [PATCH] 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 --- include/linux/netlink.h | 2 +- net/netfilter/xt_IDLETIMER.c | 66 +++++++++++------------------------- 2 files changed, 21 insertions(+), 47 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index f434363a3e6b..e8e9cc3d4281 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -25,7 +25,7 @@ #define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */ #define NETLINK_ECRYPTFS 19 #define NETLINK_RDMA 20 -#define NETLINK_IDLETIMER 21 + #define MAX_LINKS 32 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 #include #include -#include #include #include #include @@ -45,8 +44,6 @@ #include #include -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)); -- 2.34.1