73 batadv_ogm_packet = (
struct batadv_ogm_packet *)hard_iface->
packet_buff;
76 batadv_ogm_packet->
header.ttl = 2;
80 batadv_ogm_packet->
ttvn = 0;
96 struct batadv_ogm_packet *batadv_ogm_packet;
98 batadv_ogm_packet = (
struct batadv_ogm_packet *)hard_iface->
packet_buff;
108 struct batadv_ogm_packet *batadv_ogm_packet;
110 batadv_ogm_packet = (
struct batadv_ogm_packet *)hard_iface->
packet_buff;
117 batadv_iv_ogm_emit_send_time(
const struct batadv_priv *bat_priv)
128 static unsigned long batadv_iv_ogm_fwd_send_time(
void)
147 static int batadv_iv_ogm_aggr_packet(
int buff_pos,
int packet_len,
150 int next_buff_pos = 0;
155 return (next_buff_pos <= packet_len) &&
167 struct batadv_ogm_packet *batadv_ogm_packet;
176 packet_pos = forw_packet->
skb->data;
177 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_pos;
180 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->
packet_len,
192 if (packet_num > 0 || !forw_packet->
own)
193 fwd_str =
"Forwarding";
195 fwd_str =
"Sending own";
198 "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
199 fwd_str, (packet_num > 0 ?
"aggregated " :
""),
200 batadv_ogm_packet->
orig,
202 batadv_ogm_packet->
tq, batadv_ogm_packet->
header.ttl,
205 batadv_ogm_packet->
ttvn, hard_iface->
net_dev->name,
206 hard_iface->
net_dev->dev_addr);
211 packet_pos = forw_packet->
skb->data + buff_pos;
212 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_pos;
232 struct batadv_ogm_packet *batadv_ogm_packet;
233 unsigned char directlink;
236 packet_pos = forw_packet->
skb->data;
237 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_pos;
241 pr_err(
"Error - can't forward packet: incoming iface not specified\n");
246 bat_priv = netdev_priv(soft_iface);
251 primary_if = batadv_primary_if_get_selected(bat_priv);
258 if ((directlink && (batadv_ogm_packet->
header.ttl == 1)) ||
263 "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n",
264 (forw_packet->
own ?
"Sending own" :
"Forwarding"),
265 batadv_ogm_packet->
orig,
267 batadv_ogm_packet->
header.ttl,
286 batadv_iv_ogm_send_to_if(forw_packet, hard_iface);
292 batadv_hardif_free_ref(primary_if);
297 batadv_iv_ogm_can_aggregate(
const struct batadv_ogm_packet *new_bat_ogm_packet,
299 int packet_len,
unsigned long send_time,
304 struct batadv_ogm_packet *batadv_ogm_packet;
305 int aggregated_bytes = forw_packet->
packet_len + packet_len;
308 unsigned long aggregation_end_time;
310 batadv_ogm_packet = (
struct batadv_ogm_packet *)forw_packet->
skb->data;
311 aggregation_end_time = send_time;
332 primary_if = batadv_primary_if_get_selected(bat_priv);
341 (batadv_ogm_packet->
header.ttl != 1) &&
346 ((!forw_packet->
own) ||
356 (new_bat_ogm_packet->
header.ttl == 1) &&
373 batadv_hardif_free_ref(primary_if);
378 static void batadv_iv_ogm_aggregate_new(
const unsigned char *packet_buff,
379 int packet_len,
unsigned long send_time,
386 unsigned char *skb_buff;
387 unsigned int skb_size;
396 "batman packet queue full\n");
402 if (!forw_packet_aggr) {
414 forw_packet_aggr->
skb = dev_alloc_skb(skb_size);
415 if (!forw_packet_aggr->
skb) {
418 kfree(forw_packet_aggr);
421 skb_reserve(forw_packet_aggr->
skb, ETH_HLEN);
423 INIT_HLIST_NODE(&forw_packet_aggr->
list);
425 skb_buff =
skb_put(forw_packet_aggr->
skb, packet_len);
427 memcpy(skb_buff, packet_buff, packet_len);
429 forw_packet_aggr->
own = own_packet;
449 send_time - jiffies);
453 batadv_hardif_free_ref(if_incoming);
458 const unsigned char *packet_buff,
459 int packet_len,
bool direct_link)
461 unsigned char *skb_buff;
462 unsigned long new_direct_link_flag;
464 skb_buff =
skb_put(forw_packet_aggr->
skb, packet_len);
465 memcpy(skb_buff, packet_buff, packet_len);
476 static void batadv_iv_ogm_queue_add(
struct batadv_priv *bat_priv,
477 unsigned char *packet_buff,
480 int own_packet,
unsigned long send_time)
488 struct batadv_ogm_packet *batadv_ogm_packet;
490 unsigned long max_aggregation_jiffies;
492 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_buff;
502 if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet,
503 bat_priv, packet_len,
504 send_time, direct_link,
507 forw_packet_aggr = forw_packet_pos;
516 if (!forw_packet_aggr) {
525 send_time += max_aggregation_jiffies;
527 batadv_iv_ogm_aggregate_new(packet_buff, packet_len,
528 send_time, direct_link,
529 if_incoming, own_packet);
531 batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff,
532 packet_len, direct_link);
539 struct batadv_ogm_packet *batadv_ogm_packet,
540 bool is_single_hop_neigh,
541 bool is_from_best_next_hop,
547 if (batadv_ogm_packet->
header.ttl <= 1) {
552 if (!is_from_best_next_hop) {
559 if (is_single_hop_neigh)
567 batadv_ogm_packet->
header.ttl--;
571 batadv_ogm_packet->
tq = batadv_hop_penalty(batadv_ogm_packet->
tq,
575 "Forwarding packet: tq: %i, ttl: %i\n",
576 batadv_ogm_packet->
tq, batadv_ogm_packet->
header.ttl);
580 if (is_single_hop_neigh)
585 batadv_iv_ogm_queue_add(bat_priv, (
unsigned char *)batadv_ogm_packet,
587 if_incoming, 0, batadv_iv_ogm_fwd_send_time());
593 struct batadv_ogm_packet *batadv_ogm_packet;
595 int vis_server, tt_num_changes = 0;
600 primary_if = batadv_primary_if_get_selected(bat_priv);
602 if (hard_iface == primary_if)
608 batadv_ogm_packet = (
struct batadv_ogm_packet *)hard_iface->
packet_buff;
617 if (tt_num_changes >= 0)
625 if (hard_iface == primary_if &&
634 batadv_iv_ogm_queue_add(bat_priv, hard_iface->
packet_buff,
636 batadv_iv_ogm_emit_send_time(bat_priv));
639 batadv_hardif_free_ref(primary_if);
643 batadv_iv_ogm_orig_update(
struct batadv_priv *bat_priv,
645 const struct ethhdr *ethhdr,
646 const struct batadv_ogm_packet *batadv_ogm_packet,
648 const unsigned char *tt_buff,
661 "update_originator(): Searching and updating originator entry of received packet\n");
664 hlist_for_each_entry_rcu(tmp_neigh_node, node,
666 neigh_addr = tmp_neigh_node->addr;
667 if (batadv_compare_eth(neigh_addr, ethhdr->
h_source) &&
668 tmp_neigh_node->if_incoming == if_incoming &&
672 neigh_node = tmp_neigh_node;
679 spin_lock_bh(&tmp_neigh_node->lq_update_lock);
681 &tmp_neigh_node->tq_index, 0);
683 tmp_neigh_node->tq_avg = tq_avg;
684 spin_unlock_bh(&tmp_neigh_node->lq_update_lock);
694 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
697 batadv_ogm_packet->
seqno);
704 "Updating existing last-hop neighbor of originator\n");
714 batadv_ogm_packet->
tq);
729 if (router == neigh_node)
752 if (sum_orig >= sum_neigh)
763 (batadv_ogm_packet->
header.ttl > 2)) ||
767 batadv_ogm_packet->
ttvn,
795 struct batadv_ogm_packet *batadv_ogm_packet,
802 uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own;
803 unsigned int neigh_rq_inv_cube, neigh_rq_max_cube;
804 int tq_asym_penalty, inv_asym_penalty,
ret = 0;
805 unsigned int combined_tq;
809 hlist_for_each_entry_rcu(tmp_neigh_node, node,
812 if (!batadv_compare_eth(tmp_neigh_node->addr,
813 orig_neigh_node->
orig))
816 if (tmp_neigh_node->if_incoming != if_incoming)
822 neigh_node = tmp_neigh_node;
828 neigh_node = batadv_iv_ogm_neigh_new(if_incoming,
829 orig_neigh_node->
orig,
832 batadv_ogm_packet->
seqno);
838 if (orig_node == orig_neigh_node)
850 if (orig_eq_count > neigh_rq_count)
851 total_count = neigh_rq_count;
853 total_count = orig_eq_count;
874 neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv;
879 inv_asym_penalty /= neigh_rq_max_cube;
882 combined_tq = batadv_ogm_packet->
tq * tq_own * tq_asym_penalty;
884 batadv_ogm_packet->
tq = combined_tq;
887 "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n",
888 orig_node->
orig, orig_neigh_node->
orig, total_count,
889 neigh_rq_count, tq_own,
890 tq_asym_penalty, batadv_ogm_packet->
tq);
913 batadv_iv_ogm_update_seqnos(
const struct ethhdr *ethhdr,
914 const struct batadv_ogm_packet *batadv_ogm_packet,
921 int is_duplicate = 0;
924 int set_mark, ret = -1;
943 hlist_for_each_entry_rcu(tmp_neigh_node, node,
946 is_duplicate |= batadv_test_bit(tmp_neigh_node->real_bits,
950 neigh_addr = tmp_neigh_node->
addr;
951 if (batadv_compare_eth(neigh_addr, ethhdr->
h_source) &&
959 tmp_neigh_node->real_bits,
962 packet_count = bitmap_weight(tmp_neigh_node->real_bits,
963 BATADV_TQ_LOCAL_WINDOW_SIZE);
970 "updating last_seqno: old %u, new %u\n",
983 static void batadv_iv_ogm_process(
const struct ethhdr *ethhdr,
984 struct batadv_ogm_packet *batadv_ogm_packet,
985 const unsigned char *tt_buff,
993 int has_directlink_flag;
994 int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
995 int is_broadcast = 0, is_bidirect;
996 bool is_single_hop_neigh =
false;
997 bool is_from_best_next_hop =
false;
998 int is_duplicate, sameseq, simlar_ttl;
1021 has_directlink_flag = 1;
1023 has_directlink_flag = 0;
1025 if (batadv_compare_eth(ethhdr->
h_source, batadv_ogm_packet->
orig))
1026 is_single_hop_neigh =
true;
1029 "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, ttvn %u, crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
1031 if_incoming->
net_dev->dev_addr, batadv_ogm_packet->
orig,
1036 batadv_ogm_packet->
header.ttl,
1037 batadv_ogm_packet->
header.version, has_directlink_flag);
1047 if (batadv_compare_eth(ethhdr->
h_source,
1048 hard_iface->
net_dev->dev_addr))
1051 if (batadv_compare_eth(batadv_ogm_packet->
orig,
1052 hard_iface->
net_dev->dev_addr))
1055 if (batadv_compare_eth(batadv_ogm_packet->
prev_sender,
1056 hard_iface->
net_dev->dev_addr))
1059 if (is_broadcast_ether_addr(ethhdr->
h_source))
1066 "Drop packet: incompatible batman version (%i)\n",
1067 batadv_ogm_packet->
header.version);
1073 "Drop packet: received my own broadcast (sender: %pM)\n",
1080 "Drop packet: ignoring all packets with broadcast source addr (sender: %pM)\n",
1086 unsigned long *
word;
1094 if (!orig_neigh_node)
1101 if (has_directlink_flag &&
1102 batadv_compare_eth(if_incoming->
net_dev->dev_addr,
1103 batadv_ogm_packet->
orig)) {
1104 if_num = if_incoming->
if_num;
1109 bit_pos = if_incoming_seqno - 2;
1111 batadv_set_bit(word, bit_pos);
1113 *weight = bitmap_weight(word,
1114 BATADV_TQ_LOCAL_WINDOW_SIZE);
1119 "Drop packet: originator packet from myself (via neighbor)\n");
1124 if (is_my_oldorig) {
1126 "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n",
1133 "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n",
1142 is_duplicate = batadv_iv_ogm_update_seqnos(ethhdr, batadv_ogm_packet,
1145 if (is_duplicate == -1) {
1147 "Drop packet: packet within seqno protection time (sender: %pM)\n",
1152 if (batadv_ogm_packet->
tq == 0) {
1154 "Drop packet: originator packet with tq equal 0\n");
1162 if ((router && router->
tq_avg != 0) &&
1164 is_from_best_next_hop =
true;
1168 if (router && router_router &&
1169 (batadv_compare_eth(router->
addr, prev_sender)) &&
1170 !(batadv_compare_eth(batadv_ogm_packet->
orig, prev_sender)) &&
1171 (batadv_compare_eth(router->
addr, router_router->addr))) {
1173 "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n",
1181 if (is_single_hop_neigh)
1187 if (!orig_neigh_node)
1195 if (!is_single_hop_neigh && (!orig_neigh_router)) {
1197 "Drop packet: OGM via unknown neighbor!\n");
1201 is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node,
1202 batadv_ogm_packet, if_incoming);
1211 simlar_ttl = orig_node->
last_ttl - 3 <= batadv_ogm_packet->
header.ttl;
1212 if (is_bidirect && (!is_duplicate || (sameseq && simlar_ttl)))
1213 batadv_iv_ogm_orig_update(bat_priv, orig_node, ethhdr,
1214 batadv_ogm_packet, if_incoming,
1215 tt_buff, is_duplicate);
1218 if (is_single_hop_neigh) {
1221 batadv_iv_ogm_forward(orig_node, ethhdr, batadv_ogm_packet,
1222 is_single_hop_neigh,
1223 is_from_best_next_hop, if_incoming);
1226 "Forwarding packet: rebroadcast neighbor packet with direct link flag\n");
1233 "Drop packet: not received via bidirectional link\n");
1239 "Drop packet: duplicate packet received\n");
1244 "Forwarding packet: rebroadcast originator packet\n");
1245 batadv_iv_ogm_forward(orig_node, ethhdr, batadv_ogm_packet,
1246 is_single_hop_neigh, is_from_best_next_hop,
1250 if ((orig_neigh_node) && (!is_single_hop_neigh))
1257 if (orig_neigh_router)
1263 static int batadv_iv_ogm_receive(
struct sk_buff *skb,
1267 struct batadv_ogm_packet *batadv_ogm_packet;
1268 struct ethhdr *ethhdr;
1269 int buff_pos = 0, packet_len;
1270 unsigned char *tt_buff, *packet_buff;
1281 if (bat_priv->
bat_algo_ops->bat_ogm_emit != batadv_iv_ogm_emit)
1286 skb->
len + ETH_HLEN);
1288 packet_len = skb_headlen(skb);
1289 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
1290 packet_buff = skb->
data;
1291 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_buff;
1297 batadv_iv_ogm_process(ethhdr, batadv_ogm_packet, tt_buff,
1303 packet_pos = packet_buff + buff_pos;
1304 batadv_ogm_packet = (
struct batadv_ogm_packet *)packet_pos;
1305 }
while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len,
1313 .name =
"BATMAN_IV",
1314 .bat_iface_enable = batadv_iv_ogm_iface_enable,
1315 .bat_iface_disable = batadv_iv_ogm_iface_disable,
1316 .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac,
1317 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
1318 .bat_ogm_schedule = batadv_iv_ogm_schedule,
1319 .bat_ogm_emit = batadv_iv_ogm_emit,
1328 batadv_iv_ogm_receive);
1334 goto handler_unregister;