batman-adv: use more descriptive var names for is_similar_or_better

neigh1 and neigh2 is not really helpful when looking at a code which needs
to judge the metric similarity between a candidate and a reference. This
already caused an implementation error in the B.A.T.M.A.N. V bonding code.
Simply using "reference" and "candidate" for the neighbors is a lot more
descriptive and makes it easier to understand the code.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
This commit is contained in:
Sven Eckelmann 2026-08-06 20:54:55 +02:00
parent 7356a9232d
commit 776c26254d
No known key found for this signature in database
GPG Key ID: 4D0F772BD314F5CB
3 changed files with 40 additions and 39 deletions

View File

@ -2424,25 +2424,26 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
/**
* batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better
* than neigh2 from the metric prospective
* @neigh1: the first neighbor object of the comparison
* @if_outgoing1: outgoing interface for the first neighbor
* @neigh2: the second neighbor object of the comparison
* @if_outgoing2: outgoing interface for the second neighbor
* @candidate: the first neighbor object of the comparison
* @if_outgoing_cand: outgoing interface for the @candidate neighbor
* @reference: the second neighbor object of the comparison
* @if_outgoing_ref: outgoing interface for the @reference neighbor
*
* Return: true if the metric via neigh1 is equally good or better than
* the metric via neigh2, false otherwise.
* Return: true if the metric via @candidate is equally good or better than
* the metric via @reference, false otherwise.
*/
static bool
batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing1,
struct batadv_neigh_node *neigh2,
struct batadv_hard_iface *if_outgoing2)
batadv_iv_ogm_neigh_is_sob(struct batadv_neigh_node *candidate,
struct batadv_hard_iface *if_outgoing_cand,
struct batadv_neigh_node *reference,
struct batadv_hard_iface *if_outgoing_ref)
{
bool ret;
int diff;
ret = batadv_iv_ogm_neigh_diff(neigh1, if_outgoing1, neigh2,
if_outgoing2, &diff);
ret = batadv_iv_ogm_neigh_diff(candidate, if_outgoing_cand,
reference, if_outgoing_ref,
&diff);
if (!ret)
return false;

View File

@ -514,40 +514,40 @@ static int batadv_v_neigh_cmp(struct batadv_neigh_node *neigh1,
/**
* batadv_v_neigh_is_sob() - check whether two B.A.T.M.A.N. V neighbours have
* a similar or better throughput
* @neigh1: first neighbour to compare
* @if_outgoing1: outgoing interface to use for @neigh1
* @neigh2: second neighbour to compare
* @if_outgoing2: outgoing interface to use for @neigh2
* @candidate: the first neighbor object of the comparison
* @if_outgoing_cand: outgoing interface for the @candidate neighbor
* @reference: the second neighbor object of the comparison
* @if_outgoing_ref: outgoing interface for the @reference neighbor
*
* Return: true if the throughput of @neigh1 is more than 3/4 of the
* @neigh2 throughput
* Return: true if the throughput of @candidate is more than 3/4 of the
* @reference throughput
*/
static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing1,
struct batadv_neigh_node *neigh2,
struct batadv_hard_iface *if_outgoing2)
static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *candidate,
struct batadv_hard_iface *if_outgoing_cand,
struct batadv_neigh_node *reference,
struct batadv_hard_iface *if_outgoing_ref)
{
struct batadv_neigh_ifinfo *ifinfo1;
struct batadv_neigh_ifinfo *ifinfo2;
struct batadv_neigh_ifinfo *ifinfo_cand;
struct batadv_neigh_ifinfo *ifinfo_ref;
bool ret = false;
u32 threshold;
ifinfo1 = batadv_neigh_ifinfo_get(neigh1, if_outgoing1);
if (!ifinfo1)
ifinfo_cand = batadv_neigh_ifinfo_get(candidate, if_outgoing_cand);
if (!ifinfo_cand)
goto err_ifinfo1;
ifinfo2 = batadv_neigh_ifinfo_get(neigh2, if_outgoing2);
if (!ifinfo2)
ifinfo_ref = batadv_neigh_ifinfo_get(reference, if_outgoing_ref);
if (!ifinfo_ref)
goto err_ifinfo2;
threshold = ifinfo2->bat_v.throughput / 4;
threshold = ifinfo2->bat_v.throughput - threshold;
threshold = ifinfo_ref->bat_v.throughput / 4;
threshold = ifinfo_ref->bat_v.throughput - threshold;
ret = ifinfo1->bat_v.throughput > threshold;
ret = ifinfo_cand->bat_v.throughput > threshold;
batadv_neigh_ifinfo_put(ifinfo2);
batadv_neigh_ifinfo_put(ifinfo_ref);
err_ifinfo2:
batadv_neigh_ifinfo_put(ifinfo1);
batadv_neigh_ifinfo_put(ifinfo_cand);
err_ifinfo1:
return ret;
}

View File

@ -2087,14 +2087,14 @@ struct batadv_algo_neigh_ops {
struct batadv_hard_iface *if_outgoing2);
/**
* @is_similar_or_better: check if neigh1 is equally similar or better
* than neigh2 for their respective outgoing interface from the metric
* @is_similar_or_better: check if @candidate is equally similar or better
* than @reference for their respective outgoing interface from the metric
* prospective
*/
bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1,
struct batadv_hard_iface *if_outgoing1,
struct batadv_neigh_node *neigh2,
struct batadv_hard_iface *if_outgoing2);
bool (*is_similar_or_better)(struct batadv_neigh_node *candidate,
struct batadv_hard_iface *if_outgoing_cand,
struct batadv_neigh_node *reference,
struct batadv_hard_iface *if_outgoing_ref);
/** @dump: dump neighbors to a netlink socket (optional) */
void (*dump)(struct sk_buff *msg, struct netlink_callback *cb,