b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: "B.A.T.M.A.N" <b.a.t.m.a.n@lists.open-mesh.org>
Subject: [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: add wrapper function to throw uevent in userspace
Date: Thu,  5 May 2011 09:13:07 +0200	[thread overview]
Message-ID: <1304579589-5222-2-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1304579589-5222-1-git-send-email-ordex@autistici.org>

Using throw_uevent() is now possible to trigger uevent signal that can
be recognised in userspace. Uevents will be triggered through the
/devices/virtual/net/{MESH_IFACE} kobject.

A triggered uevent has three properties:
- type: the event class. Who generates the event (only 'gw' is currently
  defined). Corresponds to the BATTYPE uevent variable.
- action: the associated action with the event ('add'/'change'/'del' are
  currently defined). Corresponds to the BAACTION uevent variable.
- data: any useful data for the userspace. Corresponds to the BATDATA
  uevent variable.

Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 bat_sysfs.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 bat_sysfs.h |    4 +++
 main.h      |   11 +++++++++
 3 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/bat_sysfs.c b/bat_sysfs.c
index 497a070..83c0980 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -32,6 +32,16 @@
 #define kobj_to_netdev(obj)	to_net_dev(to_dev(obj->parent))
 #define kobj_to_batpriv(obj)	netdev_priv(kobj_to_netdev(obj))
 
+static char *uev_action_str[] = {
+	"add",
+	"del",
+	"change"
+};
+
+static char *uev_type_str[] = {
+	"gw"
+};
+
 /* Use this, if you have customized show and store functions */
 #define BAT_ATTR(_name, _mode, _show, _store)	\
 struct bat_attribute bat_attr_##_name = {	\
@@ -594,3 +604,62 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
 	kobject_put(*hardif_obj);
 	*hardif_obj = NULL;
 }
+
+int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
+		 enum uev_action action, char *data)
+{
+	int ret = -1;
+	struct hard_iface *primary_if = NULL;
+	struct kobject *bat_kobj;
+	char *uevent_env[4] = { NULL, NULL, NULL, NULL };
+
+	primary_if = primary_if_get_selected(bat_priv);
+	if (!primary_if)
+		goto out;
+
+	bat_kobj = &primary_if->soft_iface->dev.kobj;
+
+	uevent_env[0] = kmalloc(strlen("BATTYPE=") +
+				strlen(uev_type_str[type]) + 1,
+				GFP_ATOMIC);
+	if (!uevent_env[0])
+		goto out;
+
+	sprintf(uevent_env[0], "BATTYPE=%s", uev_type_str[type]);
+
+	uevent_env[1] = kmalloc(strlen("BATACTION=") +
+				strlen(uev_action_str[action]) + 1,
+				GFP_ATOMIC);
+	if (!uevent_env[1])
+		goto out;
+
+	sprintf(uevent_env[1], "BATACTION=%s", uev_action_str[action]);
+
+	/* If the event is DEL, ignore the data field */
+	if (action == UEV_DEL)
+		goto throw;
+
+	uevent_env[2] = kmalloc(strlen("BATDATA=") +
+				strlen(data) + 1, GFP_ATOMIC);
+	if (!uevent_env[2])
+		goto out;
+
+	sprintf(uevent_env[2], "BATDATA=%s", data);
+
+throw:
+	ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
+out:
+	kfree(uevent_env[0]);
+	kfree(uevent_env[1]);
+	kfree(uevent_env[2]);
+
+	if (primary_if)
+		hardif_free_ref(primary_if);
+
+	if (ret)
+		bat_dbg(DBG_BATMAN, bat_priv, "Impossible to send "
+			"uevent for (%s,%s,%s) event\n",
+			uev_type_str[type], uev_action_str[action],
+			(action == UEV_DEL ? "NULL" : data));
+	return ret;
+}
diff --git a/bat_sysfs.h b/bat_sysfs.h
index 02f1fa7..2b1a1d0 100644
--- a/bat_sysfs.h
+++ b/bat_sysfs.h
@@ -26,6 +26,8 @@
 #define SYSFS_IF_MESH_SUBDIR "mesh"
 #define SYSFS_IF_BAT_SUBDIR "batman_adv"
 
+struct bat_priv;
+
 struct bat_attribute {
 	struct attribute attr;
 	ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
@@ -38,5 +40,7 @@ int sysfs_add_meshif(struct net_device *dev);
 void sysfs_del_meshif(struct net_device *dev);
 int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev);
 void sysfs_del_hardif(struct kobject **hardif_obj);
+int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
+		 enum uev_action action, char *data);
 
 #endif /* _NET_BATMAN_ADV_SYSFS_H_ */
diff --git a/main.h b/main.h
index 101d9dc..0dfb46e 100644
--- a/main.h
+++ b/main.h
@@ -78,6 +78,17 @@
 #define BCAST_QUEUE_LEN		256
 #define BATMAN_QUEUE_LEN	256
 
+
+enum uev_action {
+	UEV_ADD = 0,
+	UEV_DEL,
+	UEV_CHANGE
+};
+
+enum uev_type {
+	UEV_GW = 0
+};
+
 /*
  * Debug Messages
  */
-- 
1.7.3.4


  reply	other threads:[~2011-05-05  7:13 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-05  7:13 [B.A.T.M.A.N.] batman-adv: added uevent support for gw and gw propagation for clients Antonio Quartulli
2011-05-05  7:13 ` Antonio Quartulli [this message]
2011-05-05 13:34   ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: add wrapper function to throw uevent in userspace Andrew Lunn
2011-05-08 19:21     ` Antonio Quartulli
2011-05-08 20:11       ` Andrew Lunn
2011-05-08 20:13         ` Antonio Quartulli
2011-05-05  7:13 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: throw uevent in userspace on gateway add/change/del event Antonio Quartulli
2011-05-05  7:13 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: improved gateway tq-based selection Antonio Quartulli
2011-05-05 13:46   ` Andrew Lunn
2011-05-08 20:57     ` Antonio Quartulli
2011-05-09  9:52 ` [B.A.T.M.A.N.] [PATCHv2 1/3] batman-adv: add wrapper function to throw uevent in userspace Antonio Quartulli
2011-05-09  9:52 ` [B.A.T.M.A.N.] [PATCHv2 2/3] batman-adv: throw uevent in userspace on gateway add/change/del event Antonio Quartulli
2011-05-09  9:52 ` [B.A.T.M.A.N.] [PATCHv2 3/3] batman-adv: improved gateway tq-based selection Antonio Quartulli
2011-05-09 13:02 ` [B.A.T.M.A.N.] [PATCHv3 1/3] batman-adv: add wrapper function to throw uevent in userspace Antonio Quartulli
2011-05-10  5:08   ` Andrew Lunn
2011-05-10  6:29     ` Antonio Quartulli
2011-06-11 10:10       ` Marek Lindner
2011-06-11 12:45         ` Antonio Quartulli
2011-06-11 10:07   ` Marek Lindner
2011-05-09 13:02 ` [B.A.T.M.A.N.] [PATCHv3 2/3] batman-adv: throw uevent in userspace on gateway add/change/del event Antonio Quartulli
2011-06-11 10:15   ` [B.A.T.M.A.N.] [PATCHv4 " Marek Lindner
2011-06-11 10:21     ` [B.A.T.M.A.N.] [PATCHv5 " Marek Lindner
2011-06-12 10:09       ` Marek Lindner
2011-05-09 13:02 ` [B.A.T.M.A.N.] [PATCHv3 3/3] batman-adv: improved gateway tq-based selection Antonio Quartulli
2011-05-09 14:48   ` Andrew Lunn
2011-05-09 20:26     ` Antonio Quartulli
2011-05-09 20:30 ` [B.A.T.M.A.N.] [PATCHv4 " Antonio Quartulli
2011-05-09 21:15 ` [B.A.T.M.A.N.] [PATCHv5 " Antonio Quartulli
2011-06-11 10:25   ` [B.A.T.M.A.N.] [PATCHv6 " Marek Lindner
2011-06-12 10:11     ` Marek Lindner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304579589-5222-2-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).