net/batman-adv/bat_algo.c
Source file repositories/reference/linux-study-clean/net/batman-adv/bat_algo.c
File Facts
- System
- Linux kernel
- Corpus path
net/batman-adv/bat_algo.c- Extension
.c- Size
- 5371 bytes
- Lines
- 211
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
main.hlinux/errno.hlinux/list.hlinux/moduleparam.hlinux/netlink.hlinux/printk.hlinux/skbuff.hlinux/stddef.hlinux/string.hlinux/types.hnet/genetlink.hnet/netlink.huapi/linux/batman_adv.hbat_algo.hnetlink.h
Detected Declarations
function batadv_algo_initfunction batadv_algo_getfunction hlist_for_each_entryfunction batadv_algo_registerfunction batadv_algo_selectfunction batadv_param_set_rafunction batadv_algo_dump_entryfunction batadv_algo_dumpfunction hlist_for_each_entry
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) B.A.T.M.A.N. contributors:
*
* Marek Lindner, Simon Wunderlich
*/
#include "main.h"
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/moduleparam.h>
#include <linux/netlink.h>
#include <linux/printk.h>
#include <linux/skbuff.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/types.h>
#include <net/genetlink.h>
#include <net/netlink.h>
#include <uapi/linux/batman_adv.h>
#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);
}
/**
* batadv_algo_get() - Search for algorithm with specific name
* @name: algorithm name to find
*
* Return: Pointer to batadv_algo_ops on success, NULL otherwise
*/
struct batadv_algo_ops *batadv_algo_get(const 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;
}
/**
* batadv_algo_register() - Register callbacks for a mesh algorithm
* @bat_algo_ops: mesh algorithm callbacks to add
*
* Return: 0 on success or negative error number in case of failure
*/
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;
Annotation
- Immediate include surface: `main.h`, `linux/errno.h`, `linux/list.h`, `linux/moduleparam.h`, `linux/netlink.h`, `linux/printk.h`, `linux/skbuff.h`, `linux/stddef.h`.
- Detected declarations: `function batadv_algo_init`, `function batadv_algo_get`, `function hlist_for_each_entry`, `function batadv_algo_register`, `function batadv_algo_select`, `function batadv_param_set_ra`, `function batadv_algo_dump_entry`, `function batadv_algo_dump`, `function hlist_for_each_entry`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.