net/batman-adv/routing.c
Source file repositories/reference/linux-study-clean/net/batman-adv/routing.c
File Facts
- System
- Linux kernel
- Corpus path
net/batman-adv/routing.c- Extension
.c- Size
- 38967 bytes
- Lines
- 1336
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
routing.hmain.hlinux/atomic.hlinux/byteorder/generic.hlinux/compiler.hlinux/errno.hlinux/etherdevice.hlinux/if_ether.hlinux/jiffies.hlinux/kref.hlinux/netdevice.hlinux/printk.hlinux/rculist.hlinux/rcupdate.hlinux/skbuff.hlinux/spinlock.hlinux/stddef.huapi/linux/batadv_packet.hbitarray.hbridge_loop_avoidance.hdistributed-arp-table.hfragmentation.hhard-interface.hlog.hmesh-interface.horiginator.hsend.htp_meter.htranslation-table.htvlv.h
Detected Declarations
function _batadv_update_routefunction batadv_update_routefunction batadv_window_protectedfunction batadv_check_management_packetfunction batadv_recv_my_icmp_packetfunction batadv_recv_icmp_ttl_exceededfunction batadv_recv_icmp_packetfunction batadv_check_unicast_packetfunction batadv_last_bonding_getfunction batadv_last_bonding_replacefunction batadv_find_routerfunction hlist_for_each_entry_rcufunction batadv_route_unicast_packetfunction batadv_reroute_unicast_packetfunction batadv_check_unicast_ttvnfunction batadv_recv_unhandled_unicast_packetfunction batadv_recv_unicast_packetfunction batadv_recv_unicast_tvlvfunction batadv_recv_frag_packetfunction batadv_frag_skb_fwdfunction batadv_recv_bcast_packetfunction batadv_recv_mcast_packet
Annotated Snippet
if (!kref_get_unless_zero(&cand_router->refcount)) {
cand_router = NULL;
goto next;
}
/* alternative candidate should be good enough to be
* considered
*/
if (!bao->neigh.is_similar_or_better(cand_router,
cand->if_outgoing, router,
recv_if))
goto next;
/* don't use the same router twice */
if (last_cand_router == cand_router)
goto next;
/* mark the first possible candidate */
if (!first_candidate) {
kref_get(&cand_router->refcount);
kref_get(&cand->refcount);
first_candidate = cand;
first_candidate_router = cand_router;
}
/* check if the loop has already passed the previously selected
* candidate ... this function should select the next candidate
* AFTER the previously used bonding candidate.
*/
if (!last_candidate || last_candidate_found) {
next_candidate = cand;
next_candidate_router = cand_router;
break;
}
if (last_candidate == cand)
last_candidate_found = true;
next:
/* free references */
if (cand_router) {
batadv_neigh_node_put(cand_router);
cand_router = NULL;
}
batadv_orig_ifinfo_put(cand);
}
rcu_read_unlock();
/* After finding candidates, handle the three cases:
* 1) there is a next candidate, use that
* 2) there is no next candidate, use the first of the list
* 3) there is no candidate at all, return the default router
*/
if (next_candidate) {
batadv_neigh_node_put(router);
kref_get(&next_candidate_router->refcount);
router = next_candidate_router;
batadv_last_bonding_replace(orig_node, next_candidate);
} else if (first_candidate) {
batadv_neigh_node_put(router);
kref_get(&first_candidate_router->refcount);
router = first_candidate_router;
batadv_last_bonding_replace(orig_node, first_candidate);
} else {
batadv_last_bonding_replace(orig_node, NULL);
}
/* cleanup of candidates */
if (first_candidate) {
batadv_neigh_node_put(first_candidate_router);
batadv_orig_ifinfo_put(first_candidate);
}
if (next_candidate) {
batadv_neigh_node_put(next_candidate_router);
batadv_orig_ifinfo_put(next_candidate);
}
batadv_orig_ifinfo_put(last_candidate);
return router;
}
static int batadv_route_unicast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
struct batadv_priv *bat_priv = netdev_priv(recv_if->mesh_iface);
struct batadv_orig_node *orig_node = NULL;
struct batadv_unicast_packet *unicast_packet;
Annotation
- Immediate include surface: `routing.h`, `main.h`, `linux/atomic.h`, `linux/byteorder/generic.h`, `linux/compiler.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/if_ether.h`.
- Detected declarations: `function _batadv_update_route`, `function batadv_update_route`, `function batadv_window_protected`, `function batadv_check_management_packet`, `function batadv_recv_my_icmp_packet`, `function batadv_recv_icmp_ttl_exceeded`, `function batadv_recv_icmp_packet`, `function batadv_check_unicast_packet`, `function batadv_last_bonding_get`, `function batadv_last_bonding_replace`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.