From patchwork Sat Dec 10 17:15:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1496 Return-Path: Received: from nm23-vm3.bullet.mail.ukl.yahoo.com (nm23-vm3.bullet.mail.ukl.yahoo.com [217.146.177.142]) by open-mesh.org (Postfix) with SMTP id D48BF600746 for ; Sat, 10 Dec 2011 18:17:21 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.181] by nm23.bullet.mail.ukl.yahoo.com with NNFMP; 10 Dec 2011 17:17:21 -0000 Received: from [77.238.184.66] by tm12.bullet.mail.ukl.yahoo.com with NNFMP; 10 Dec 2011 17:17:21 -0000 Received: from [127.0.0.1] by smtp135.mail.ukl.yahoo.com with NNFMP; 10 Dec 2011 17:17:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1323537441; bh=xRU1rMlrNpQY7w24qf4R7MxKyXYCbrKp4B65dQy6Xiw=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=3pAjhch6gPhBLRxTUN8aETO3Sab/kVlmC0OcUrOFRf89z625KQ9EyBFQe9rzDYKKZceuJoAhGglbVxiBxbHFIJpGoPTNYt4RwJG+uw7xHHl3RoDyf9cQtWcFmpTLYxyzrC2wzbi98homDayYW980W7b/kaBb8w0xq7oBzLKBAAA= X-Yahoo-Newman-Id: 389905.67973.bm@smtp135.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: HQ6oYMgVM1nAAEuajM2hh2yj_npeqHiMqzIse9QyKFKDLgI cOwQaDhEibODqwpdd3jtYsKh_N6Wot_mZEpZ.3RUM3_ESXRyZEWMdnqJPkrq MBRQKfLN6GunBZJfSgKzdJDAba_nI3IFs.K4UhuN.M6QGGNCrioKyZ9t8Vit nUm1zxfLFNMjD0kUG1jfNFHCah_YarpnouC_PuHNdc1XzT1oajSTPX39MRlr sfyfesfXrho.iOBpsFSYgHVDVBnyLOhLOezLR1TqHWwPBq3jI5o_F6.VLSfV kXlwPFaSXVXKTGO9ET7w_KPAr7Xlebl3UIDD1kR22pT6RnueB96ps2l2Oq5A R7aV6_YG1vOa056tk.bAuTOwIao2lWTPGrz2DbJMgJAkUMTc- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@210.177.7.38 with plain) by smtp135.mail.ukl.yahoo.com with SMTP; 10 Dec 2011 17:17:15 +0000 GMT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 11 Dec 2011 01:15:56 +0800 Message-Id: <1323537357-9116-4-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323537357-9116-1-git-send-email-lindner_marek@yahoo.de> References: <1323537357-9116-1-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCHv2 3/4] batman-adv: allowing changing the routing algorithm via module parameter X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Dec 2011 17:17:27 -0000 Signed-off-by: Marek Lindner --- 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, ¶m_ops_ra, &__param_string_ra, 0644); module_init(batman_init); module_exit(batman_exit);