Commit c67893d1 authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Antonio Quartulli

batman-adv: Reduce accumulated length of simple statements

Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarAntonio Quartulli <ordex@autistici.org>
parent bbb1f90e
...@@ -166,13 +166,15 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, ...@@ -166,13 +166,15 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
int16_t buff_pos; int16_t buff_pos;
struct batadv_ogm_packet *batadv_ogm_packet; struct batadv_ogm_packet *batadv_ogm_packet;
struct sk_buff *skb; struct sk_buff *skb;
uint8_t *packet_pos;
if (hard_iface->if_status != BATADV_IF_ACTIVE) if (hard_iface->if_status != BATADV_IF_ACTIVE)
return; return;
packet_num = 0; packet_num = 0;
buff_pos = 0; buff_pos = 0;
batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data; packet_pos = forw_packet->skb->data;
batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
/* adjust all flags and log packets */ /* adjust all flags and log packets */
while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
...@@ -187,9 +189,11 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, ...@@ -187,9 +189,11 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
else else
batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ? if (packet_num > 0 || !forw_packet->own)
"Sending own" : fwd_str = "Forwarding";
"Forwarding")); else
fwd_str = "Sending own";
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n", "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
fwd_str, (packet_num > 0 ? "aggregated " : ""), fwd_str, (packet_num > 0 ? "aggregated " : ""),
...@@ -204,8 +208,8 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, ...@@ -204,8 +208,8 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
buff_pos += BATADV_OGM_HLEN; buff_pos += BATADV_OGM_HLEN;
buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes); buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes);
packet_num++; packet_num++;
batadv_ogm_packet = (struct batadv_ogm_packet *) packet_pos = forw_packet->skb->data + buff_pos;
(forw_packet->skb->data + buff_pos); batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
} }
/* create clone because function is called more than once */ /* create clone because function is called more than once */
...@@ -227,9 +231,10 @@ static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet) ...@@ -227,9 +231,10 @@ static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet)
struct batadv_hard_iface *primary_if = NULL; struct batadv_hard_iface *primary_if = NULL;
struct batadv_ogm_packet *batadv_ogm_packet; struct batadv_ogm_packet *batadv_ogm_packet;
unsigned char directlink; unsigned char directlink;
uint8_t *packet_pos;
batadv_ogm_packet = (struct batadv_ogm_packet *) packet_pos = forw_packet->skb->data;
(forw_packet->skb->data); batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
directlink = (batadv_ogm_packet->flags & BATADV_DIRECTLINK ? 1 : 0); directlink = (batadv_ogm_packet->flags & BATADV_DIRECTLINK ? 1 : 0);
if (!forw_packet->if_incoming) { if (!forw_packet->if_incoming) {
...@@ -839,8 +844,10 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, ...@@ -839,8 +844,10 @@ static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
spin_unlock_bh(&orig_node->ogm_cnt_lock); spin_unlock_bh(&orig_node->ogm_cnt_lock);
/* pay attention to not get a value bigger than 100 % */ /* pay attention to not get a value bigger than 100 % */
total_count = (orig_eq_count > neigh_rq_count ? if (orig_eq_count > neigh_rq_count)
neigh_rq_count : orig_eq_count); total_count = neigh_rq_count;
else
total_count = orig_eq_count;
/* if we have too few packets (too less data) we set tq_own to zero /* if we have too few packets (too less data) we set tq_own to zero
* if we receive too few packets it is not considered bidirectional * if we receive too few packets it is not considered bidirectional
...@@ -1168,9 +1175,12 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, ...@@ -1168,9 +1175,12 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
/* if sender is a direct neighbor the sender mac equals /* if sender is a direct neighbor the sender mac equals
* originator mac * originator mac
*/ */
orig_neigh_node = (is_single_hop_neigh ? if (is_single_hop_neigh)
orig_node : orig_neigh_node = orig_node;
batadv_get_orig_node(bat_priv, ethhdr->h_source)); else
orig_neigh_node = batadv_get_orig_node(bat_priv,
ethhdr->h_source);
if (!orig_neigh_node) if (!orig_neigh_node)
goto out; goto out;
...@@ -1256,6 +1266,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, ...@@ -1256,6 +1266,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
int buff_pos = 0, packet_len; int buff_pos = 0, packet_len;
unsigned char *tt_buff, *packet_buff; unsigned char *tt_buff, *packet_buff;
bool ret; bool ret;
uint8_t *packet_pos;
ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN); ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
if (!ret) if (!ret)
...@@ -1286,8 +1297,8 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, ...@@ -1286,8 +1297,8 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
buff_pos += BATADV_OGM_HLEN; buff_pos += BATADV_OGM_HLEN;
buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes); buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes);
batadv_ogm_packet = (struct batadv_ogm_packet *) packet_pos = packet_buff + buff_pos;
(packet_buff + buff_pos); batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
} while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len, } while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len,
batadv_ogm_packet->tt_num_changes)); batadv_ogm_packet->tt_num_changes));
......
...@@ -1345,8 +1345,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb, ...@@ -1345,8 +1345,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
if (!pskb_may_pull(skb, hdr_size + sizeof(struct vlan_ethhdr))) if (!pskb_may_pull(skb, hdr_size + sizeof(struct vlan_ethhdr)))
return 0; return 0;
vhdr = (struct vlan_ethhdr *)(((uint8_t *)skb->data) + vhdr = (struct vlan_ethhdr *)(skb->data + hdr_size);
hdr_size);
vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
} }
......
...@@ -117,10 +117,15 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -117,10 +117,15 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
struct hlist_node *node; struct hlist_node *node;
struct batadv_gw_node *gw_node, *curr_gw = NULL; struct batadv_gw_node *gw_node, *curr_gw = NULL;
uint32_t max_gw_factor = 0, tmp_gw_factor = 0; uint32_t max_gw_factor = 0, tmp_gw_factor = 0;
uint32_t gw_divisor;
uint8_t max_tq = 0; uint8_t max_tq = 0;
int down, up; int down, up;
uint8_t tq_avg;
struct batadv_orig_node *orig_node; struct batadv_orig_node *orig_node;
gw_divisor = BATADV_TQ_LOCAL_WINDOW_SIZE * BATADV_TQ_LOCAL_WINDOW_SIZE;
gw_divisor *= 64;
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw.list, list) { hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw.list, list) {
if (gw_node->deleted) if (gw_node->deleted)
...@@ -134,19 +139,19 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -134,19 +139,19 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
if (!atomic_inc_not_zero(&gw_node->refcount)) if (!atomic_inc_not_zero(&gw_node->refcount))
goto next; goto next;
tq_avg = router->tq_avg;
switch (atomic_read(&bat_priv->gw_sel_class)) { switch (atomic_read(&bat_priv->gw_sel_class)) {
case 1: /* fast connection */ case 1: /* fast connection */
batadv_gw_bandwidth_to_kbit(orig_node->gw_flags, batadv_gw_bandwidth_to_kbit(orig_node->gw_flags,
&down, &up); &down, &up);
tmp_gw_factor = (router->tq_avg * router->tq_avg * tmp_gw_factor = tq_avg * tq_avg * down * 100 * 100;
down * 100 * 100) / tmp_gw_factor /= gw_divisor;
(BATADV_TQ_LOCAL_WINDOW_SIZE *
BATADV_TQ_LOCAL_WINDOW_SIZE * 64);
if ((tmp_gw_factor > max_gw_factor) || if ((tmp_gw_factor > max_gw_factor) ||
((tmp_gw_factor == max_gw_factor) && ((tmp_gw_factor == max_gw_factor) &&
(router->tq_avg > max_tq))) { (tq_avg > max_tq))) {
if (curr_gw) if (curr_gw)
batadv_gw_node_free_ref(curr_gw); batadv_gw_node_free_ref(curr_gw);
curr_gw = gw_node; curr_gw = gw_node;
...@@ -161,7 +166,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -161,7 +166,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
* soon as a better gateway appears which has * soon as a better gateway appears which has
* $routing_class more tq points) * $routing_class more tq points)
*/ */
if (router->tq_avg > max_tq) { if (tq_avg > max_tq) {
if (curr_gw) if (curr_gw)
batadv_gw_node_free_ref(curr_gw); batadv_gw_node_free_ref(curr_gw);
curr_gw = gw_node; curr_gw = gw_node;
...@@ -170,8 +175,8 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -170,8 +175,8 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
break; break;
} }
if (router->tq_avg > max_tq) if (tq_avg > max_tq)
max_tq = router->tq_avg; max_tq = tq_avg;
if (tmp_gw_factor > max_gw_factor) if (tmp_gw_factor > max_gw_factor)
max_gw_factor = tmp_gw_factor; max_gw_factor = tmp_gw_factor;
......
...@@ -981,8 +981,7 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv, ...@@ -981,8 +981,7 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
} else { } else {
memcpy(unicast_packet->dest, orig_node->orig, memcpy(unicast_packet->dest, orig_node->orig,
ETH_ALEN); ETH_ALEN);
curr_ttvn = (uint8_t) curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
atomic_read(&orig_node->last_ttvn);
batadv_orig_node_free_ref(orig_node); batadv_orig_node_free_ref(orig_node);
} }
......
...@@ -1559,6 +1559,7 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv, ...@@ -1559,6 +1559,7 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv,
uint16_t tt_len, tt_tot; uint16_t tt_len, tt_tot;
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
struct batadv_tt_query_packet *tt_response; struct batadv_tt_query_packet *tt_response;
uint8_t *packet_pos;
size_t len; size_t len;
batadv_dbg(BATADV_DBG_TT, bat_priv, batadv_dbg(BATADV_DBG_TT, bat_priv,
...@@ -1612,8 +1613,8 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv, ...@@ -1612,8 +1613,8 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv,
goto unlock; goto unlock;
skb_reserve(skb, ETH_HLEN); skb_reserve(skb, ETH_HLEN);
tt_response = (struct batadv_tt_query_packet *)skb_put(skb, packet_pos = skb_put(skb, len);
len); tt_response = (struct batadv_tt_query_packet *)packet_pos;
tt_response->ttvn = req_ttvn; tt_response->ttvn = req_ttvn;
tt_response->tt_data = htons(tt_tot); tt_response->tt_data = htons(tt_tot);
...@@ -1692,6 +1693,7 @@ batadv_send_my_tt_response(struct batadv_priv *bat_priv, ...@@ -1692,6 +1693,7 @@ batadv_send_my_tt_response(struct batadv_priv *bat_priv,
uint16_t tt_len, tt_tot; uint16_t tt_len, tt_tot;
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
struct batadv_tt_query_packet *tt_response; struct batadv_tt_query_packet *tt_response;
uint8_t *packet_pos;
size_t len; size_t len;
batadv_dbg(BATADV_DBG_TT, bat_priv, batadv_dbg(BATADV_DBG_TT, bat_priv,
...@@ -1738,8 +1740,8 @@ batadv_send_my_tt_response(struct batadv_priv *bat_priv, ...@@ -1738,8 +1740,8 @@ batadv_send_my_tt_response(struct batadv_priv *bat_priv,
goto unlock; goto unlock;
skb_reserve(skb, ETH_HLEN); skb_reserve(skb, ETH_HLEN);
tt_response = (struct batadv_tt_query_packet *)skb_put(skb, packet_pos = skb_put(skb, len);
len); tt_response = (struct batadv_tt_query_packet *)packet_pos;
tt_response->ttvn = req_ttvn; tt_response->ttvn = req_ttvn;
tt_response->tt_data = htons(tt_tot); tt_response->tt_data = htons(tt_tot);
......
...@@ -39,6 +39,7 @@ batadv_frag_merge_packet(struct list_head *head, ...@@ -39,6 +39,7 @@ batadv_frag_merge_packet(struct list_head *head,
struct batadv_unicast_packet *unicast_packet; struct batadv_unicast_packet *unicast_packet;
int hdr_len = sizeof(*unicast_packet); int hdr_len = sizeof(*unicast_packet);
int uni_diff = sizeof(*up) - hdr_len; int uni_diff = sizeof(*up) - hdr_len;
uint8_t *packet_pos;
up = (struct batadv_unicast_frag_packet *)skb->data; up = (struct batadv_unicast_frag_packet *)skb->data;
/* set skb to the first part and tmp_skb to the second part */ /* set skb to the first part and tmp_skb to the second part */
...@@ -65,8 +66,8 @@ batadv_frag_merge_packet(struct list_head *head, ...@@ -65,8 +66,8 @@ batadv_frag_merge_packet(struct list_head *head,
kfree_skb(tmp_skb); kfree_skb(tmp_skb);
memmove(skb->data + uni_diff, skb->data, hdr_len); memmove(skb->data + uni_diff, skb->data, hdr_len);
unicast_packet = (struct batadv_unicast_packet *)skb_pull(skb, packet_pos = skb_pull(skb, uni_diff);
uni_diff); unicast_packet = (struct batadv_unicast_packet *)packet_pos;
unicast_packet->header.packet_type = BATADV_UNICAST; unicast_packet->header.packet_type = BATADV_UNICAST;
return skb; return skb;
......
...@@ -578,6 +578,7 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv) ...@@ -578,6 +578,7 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv)
struct batadv_vis_packet *packet; struct batadv_vis_packet *packet;
struct batadv_vis_info_entry *entry; struct batadv_vis_info_entry *entry;
struct batadv_tt_common_entry *tt_common_entry; struct batadv_tt_common_entry *tt_common_entry;
uint8_t *packet_pos;
int best_tq = -1; int best_tq = -1;
uint32_t i; uint32_t i;
...@@ -618,8 +619,8 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv) ...@@ -618,8 +619,8 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv)
goto next; goto next;
/* fill one entry into buffer. */ /* fill one entry into buffer. */
entry = (struct batadv_vis_info_entry *) packet_pos = skb_put(info->skb_packet, sizeof(*entry));
skb_put(info->skb_packet, sizeof(*entry)); entry = (struct batadv_vis_info_entry *)packet_pos;
memcpy(entry->src, memcpy(entry->src,
router->if_incoming->net_dev->dev_addr, router->if_incoming->net_dev->dev_addr,
ETH_ALEN); ETH_ALEN);
...@@ -644,9 +645,8 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv) ...@@ -644,9 +645,8 @@ static int batadv_generate_vis_packet(struct batadv_priv *bat_priv)
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(tt_common_entry, node, head, hlist_for_each_entry_rcu(tt_common_entry, node, head,
hash_entry) { hash_entry) {
entry = (struct batadv_vis_info_entry *) packet_pos = skb_put(info->skb_packet, sizeof(*entry));
skb_put(info->skb_packet, entry = (struct batadv_vis_info_entry *)packet_pos;
sizeof(*entry));
memset(entry->src, 0, ETH_ALEN); memset(entry->src, 0, ETH_ALEN);
memcpy(entry->dest, tt_common_entry->addr, ETH_ALEN); memcpy(entry->dest, tt_common_entry->addr, ETH_ALEN);
entry->quality = 0; /* 0 means TT */ entry->quality = 0; /* 0 means TT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment