#include "bat_algo.h"
#include "netlink.h"
char batadv_routing_algo[20] = "BATMAN_IV";
static struct hlist_head batadv_algo_list;
/**
* batadv_algo_init - Initialize batman-adv algorithm management data structures
*/
void batadv_algo_init(void)
{
INIT_HLIST_HEAD(&batadv_algo_list);
}
static struct batadv_algo_ops *batadv_algo_get(char *name)
{
struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
if (strcmp(bat_algo_ops_tmp->name, name) != 0)
continue;
bat_algo_ops = bat_algo_ops_tmp;
break;
}
return bat_algo_ops;
}
int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
{
struct batadv_algo_ops *bat_algo_ops_tmp;
bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
if (bat_algo_ops_tmp) {
pr_info("Trying to register already registered routing algorithm: %s\n",
bat_algo_ops->name);
return -EEXIST;
}
/* all algorithms must implement all ops (for now) */
if (!bat_algo_ops->iface.enable ||
!bat_algo_ops->iface.disable ||
!bat_algo_ops->iface.update_mac ||
!bat_algo_ops->iface.primary_set ||
!bat_algo_ops->neigh.cmp ||
!bat_algo_ops->neigh.is_similar_or_better) {
pr_info("Routing algo '%s' does not implement required ops\n",
bat_algo_ops->name);
return -EINVAL;
}
INIT_HLIST_NODE(&bat_algo_ops->list);
hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
return 0;
}
int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
{
struct batadv_algo_ops *bat_algo_ops;
bat_algo_ops = batadv_algo_get(name);
if (!bat_algo_ops)
return -EINVAL;
bat_priv->algo_ops = bat_algo_ops;
return 0;
}
#ifdef CONFIG_BATMAN_ADV_DEBUGFS
int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
{
struct batadv_algo_ops *bat_algo_ops;
seq_puts(seq, "Available routing algorithms:\n");
hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
seq_printf(seq, " * %s\n", bat_algo_ops->name);
}
return 0;
}
#endif
static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
{
struct batadv_algo_ops *bat_algo_ops;
char *algo_name = (char *)val;
size_t name_len = strlen(algo_name);
if (name_len > 0 && algo_name[name_len - 1] == '\n')
algo_name[name_len - 1] = '\0';
bat_algo_ops = batadv_algo_get(algo_name);
if (!bat_algo_ops) {
pr_err("Routing algorithm '%s' is not supported\n", algo_name);
return -EINVAL;
}
return param_set_copystring(algo_name, kp);
}
static const struct kernel_param_ops batadv_param_ops_ra = {
.set = batadv_param_set_ra,
.get = param_get_string,
};
static struct kparam_string batadv_param_string_ra = {
.maxlen = sizeof(batadv_routing_algo),
.string = batadv_routing_algo,
};
module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
0644);
/**
* batadv_algo_dump_entry - fill in information about one supported routing
* algorithm
* @msg: netlink message to be sent back
* @portid: Port to reply to
* @seq: Sequence number of message
* @bat_algo_ops: Algorithm to be dumped
*
* Return: Error number, or 0 on success
*/
static int batadv_algo_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_algo_ops *bat_algo_ops)
{
void *hdr;
hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
NLM_F_MULTI, BATADV_CMD_GET_ROUTING_ALGOS);
if (!hdr)
return -EMSGSIZE;
if (nla_put_string(msg, BATADV_ATTR_ALGO_NAME, bat_algo_ops->name))
goto nla_put_failure;
genlmsg_end(msg, hdr);
return 0;
nla_put_failure:
genlmsg_cancel(msg, hdr);
return -EMSGSIZE;
}
/**
* batadv_algo_dump - fill in information about supported routing
* algorithms
* @msg: netlink message to be sent back
* @cb: Parameters to the netlink request
*
* Return: Length of reply message.
*/
int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
int portid = NETLINK_CB(cb->skb).portid;
struct batadv_algo_ops *bat_algo_ops;
int skip = cb->args[0];
int i = 0;
hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
if (i++ < skip)
continue;
if (batadv_algo_dump_entry(msg, portid, cb->nlh->nlmsg_seq,
bat_algo_ops)) {
i--;
break;
}
}
cb->args[0] = i;
return msg->len;
}
cd0bd66c'>patch)
tree | 74e3a6b53f5fad9f7848ab1b9f6921b7012940a4 /include/net/9p/transport.h |
parent | 0263d4ebd94b36280608e296cba39b924b6e832b (diff) |
---|
parent | aab45453ff5c77200c6da4ac909f7a4392aed17e (diff) |
Merge branch 'akpm' (patches from Andrew)
Merge fixes from Andrew Morton:
"26 fixes"
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (26 commits)
MAINTAINERS: add Dan Streetman to zbud maintainers
MAINTAINERS: add Dan Streetman to zswap maintainers
mm: do not export ioremap_page_range symbol for external module
mn10300: fix build error of missing fpu_save()
romfs: use different way to generate fsid for BLOCK or MTD
frv: add missing atomic64 operations
mm, page_alloc: fix premature OOM when racing with cpuset mems update
mm, page_alloc: move cpuset seqcount checking to slowpath
mm, page_alloc: fix fast-path race with cpuset update or removal
mm, page_alloc: fix check for NULL preferred_zone
kernel/panic.c: add missing \n
fbdev: color map copying bounds checking
frv: add atomic64_add_unless()
mm/mempolicy.c: do not put mempolicy before using its nodemask
radix-tree: fix private list warnings
Documentation/filesystems/proc.txt: add VmPin
mm, memcg: do not retry precharge charges
proc: add a schedule point in proc_pid_readdir()
mm: alloc_contig: re-allow CMA to compact FS pages
mm/slub.c: trace free objects at KERN_INFO
...