b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Marek Lindner <lindner_marek@yahoo.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Marek Lindner <lindner_marek@yahoo.de>
Subject: [B.A.T.M.A.N.] [PATCHv2 3/4] batman-adv: allowing changing the routing algorithm via module parameter
Date: Sun, 11 Dec 2011 01:15:56 +0800	[thread overview]
Message-ID: <1323537357-9116-4-git-send-email-lindner_marek@yahoo.de> (raw)
In-Reply-To: <1323537357-9116-1-git-send-email-lindner_marek@yahoo.de>

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 compat.h |   28 ++++++++++++++++++++++++++++
 main.c   |   24 ++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/compat.h b/compat.h
index 194e70e..3733f68 100644
--- a/compat.h
+++ b/compat.h
@@ -61,6 +61,34 @@
 #define __rcu
 #define IFF_BRIDGE_PORT  0 || (hard_iface->net_dev->br_port ? 1 : 0)
 
+struct kernel_param_ops {
+	/* Returns 0, or -errno.  arg is in kp->arg. */
+	int (*set)(const char *val, const struct kernel_param *kp);
+	/* Returns length written or -errno.  Buffer is 4k (ie. be short!) */
+	int (*get)(char *buffer, struct kernel_param *kp);
+	/* Optional function to free kp->arg when module unloaded. */
+	void (*free)(void *arg);
+};
+
+#define module_param_cb(name, ops, arg, perm)				\
+	static int __compat_set_param_##name(const char *val,		\
+					     struct kernel_param *kp)	\
+				{ return (ops)->set(val, kp); }		\
+	static int __compat_get_param_##name(char *buffer,		\
+					     struct kernel_param *kp)	\
+				{ return (ops)->get(buffer, kp); }	\
+	__module_param_call(MODULE_PARAM_PREFIX, name,			\
+			    __compat_set_param_##name,			\
+			    __compat_get_param_##name, arg,		\
+			    __same_type((arg), bool *), perm)
+
+static inline int __param_set_copystring(const char *val,
+					 const struct kernel_param *kp)
+{
+	return param_set_copystring(val, (struct kernel_param *)kp);
+}
+#define param_set_copystring __param_set_copystring
+
 #endif /* < KERNEL_VERSION(2, 6, 36) */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39)
diff --git a/main.c b/main.c
index bcc2bdd..8ae497b 100644
--- a/main.c
+++ b/main.c
@@ -256,6 +256,30 @@ int bat_algo_seq_print_text(struct seq_file *seq, void *offset)
 	return 0;
 }
 
+static int param_set_ra(const char *val, const struct kernel_param *kp)
+{
+	struct bat_algo_ops *bat_algo_ops;
+
+	bat_algo_ops = bat_algo_get((char *)val);
+	if (!bat_algo_ops) {
+		pr_err("Routing algorithm '%s' is not supported\n", val);
+		return -EINVAL;
+	}
+
+	return param_set_copystring(val, kp);
+}
+
+static const struct kernel_param_ops param_ops_ra = {
+	.set = param_set_ra,
+	.get = param_get_string,
+};
+
+static struct kparam_string __param_string_ra = {
+	.maxlen = sizeof(bat_routing_algo),
+	.string = bat_routing_algo,
+};
+
+module_param_cb(routing_algo, &param_ops_ra, &__param_string_ra, 0644);
 module_init(batman_init);
 module_exit(batman_exit);
 
-- 
1.7.5.4


  parent reply	other threads:[~2011-12-10 17:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-10 17:15 [B.A.T.M.A.N.] switch routing algorithm at runtime (v2) Marek Lindner
2011-12-10 17:15 ` [B.A.T.M.A.N.] [PATCHv2 1/4] batman-adv: add infrastructure to change routing algorithm at runtime Marek Lindner
2011-12-22 12:20   ` Marek Lindner
2011-12-10 17:15 ` [B.A.T.M.A.N.] [PATCHv2 2/4] batman-adv: convert batman iv algorithm to use dynamic infrastructure Marek Lindner
2011-12-22 12:23   ` Marek Lindner
2011-12-10 17:15 ` Marek Lindner [this message]
2011-12-22 12:24   ` [B.A.T.M.A.N.] [PATCHv2 3/4] batman-adv: allowing changing the routing algorithm via module parameter Marek Lindner
2011-12-10 17:15 ` [B.A.T.M.A.N.] [PATCHv2 4/4] batman-adv: export used routing algorithm via sysfs Marek Lindner
2011-12-22 12:25   ` 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=1323537357-9116-4-git-send-email-lindner_marek@yahoo.de \
    --to=lindner_marek@yahoo.de \
    --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).