bat_iv_ogm.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. /*
  2. * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner, Simon Wunderlich
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of version 2 of the GNU General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA
  19. *
  20. */
  21. #include "main.h"
  22. #include "bat_ogm.h"
  23. #include "translation-table.h"
  24. #include "ring_buffer.h"
  25. #include "originator.h"
  26. #include "routing.h"
  27. #include "gateway_common.h"
  28. #include "gateway_client.h"
  29. #include "hard-interface.h"
  30. #include "send.h"
  31. void bat_ogm_init(struct hard_iface *hard_iface)
  32. {
  33. struct batman_ogm_packet *batman_ogm_packet;
  34. hard_iface->packet_len = BATMAN_OGM_LEN;
  35. hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
  36. batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
  37. batman_ogm_packet->packet_type = BAT_OGM;
  38. batman_ogm_packet->version = COMPAT_VERSION;
  39. batman_ogm_packet->flags = NO_FLAGS;
  40. batman_ogm_packet->ttl = 2;
  41. batman_ogm_packet->tq = TQ_MAX_VALUE;
  42. batman_ogm_packet->tt_num_changes = 0;
  43. batman_ogm_packet->ttvn = 0;
  44. }
  45. void bat_ogm_init_primary(struct hard_iface *hard_iface)
  46. {
  47. struct batman_ogm_packet *batman_ogm_packet;
  48. batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
  49. batman_ogm_packet->flags = PRIMARIES_FIRST_HOP;
  50. batman_ogm_packet->ttl = TTL;
  51. }
  52. void bat_ogm_update_mac(struct hard_iface *hard_iface)
  53. {
  54. struct batman_ogm_packet *batman_ogm_packet;
  55. batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
  56. memcpy(batman_ogm_packet->orig,
  57. hard_iface->net_dev->dev_addr, ETH_ALEN);
  58. memcpy(batman_ogm_packet->prev_sender,
  59. hard_iface->net_dev->dev_addr, ETH_ALEN);
  60. }
  61. /* when do we schedule our own ogm to be sent */
  62. static unsigned long bat_ogm_emit_send_time(const struct bat_priv *bat_priv)
  63. {
  64. return jiffies + msecs_to_jiffies(
  65. atomic_read(&bat_priv->orig_interval) -
  66. JITTER + (random32() % 2*JITTER));
  67. }
  68. /* when do we schedule a ogm packet to be sent */
  69. static unsigned long bat_ogm_fwd_send_time(void)
  70. {
  71. return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
  72. }
  73. /* apply hop penalty for a normal link */
  74. static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv)
  75. {
  76. int hop_penalty = atomic_read(&bat_priv->hop_penalty);
  77. return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
  78. }
  79. /* is there another aggregated packet here? */
  80. static int bat_ogm_aggr_packet(int buff_pos, int packet_len,
  81. int tt_num_changes)
  82. {
  83. int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);
  84. return (next_buff_pos <= packet_len) &&
  85. (next_buff_pos <= MAX_AGGREGATION_BYTES);
  86. }
  87. /* send a batman ogm to a given interface */
  88. static void bat_ogm_send_to_if(struct forw_packet *forw_packet,
  89. struct hard_iface *hard_iface)
  90. {
  91. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  92. char *fwd_str;
  93. uint8_t packet_num;
  94. int16_t buff_pos;
  95. struct batman_ogm_packet *batman_ogm_packet;
  96. struct sk_buff *skb;
  97. if (hard_iface->if_status != IF_ACTIVE)
  98. return;
  99. packet_num = 0;
  100. buff_pos = 0;
  101. batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
  102. /* adjust all flags and log packets */
  103. while (bat_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
  104. batman_ogm_packet->tt_num_changes)) {
  105. /* we might have aggregated direct link packets with an
  106. * ordinary base packet */
  107. if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
  108. (forw_packet->if_incoming == hard_iface))
  109. batman_ogm_packet->flags |= DIRECTLINK;
  110. else
  111. batman_ogm_packet->flags &= ~DIRECTLINK;
  112. fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
  113. "Sending own" :
  114. "Forwarding"));
  115. bat_dbg(DBG_BATMAN, bat_priv,
  116. "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d,"
  117. " IDF %s, ttvn %d) on interface %s [%pM]\n",
  118. fwd_str, (packet_num > 0 ? "aggregated " : ""),
  119. batman_ogm_packet->orig,
  120. ntohl(batman_ogm_packet->seqno),
  121. batman_ogm_packet->tq, batman_ogm_packet->ttl,
  122. (batman_ogm_packet->flags & DIRECTLINK ?
  123. "on" : "off"),
  124. batman_ogm_packet->ttvn, hard_iface->net_dev->name,
  125. hard_iface->net_dev->dev_addr);
  126. buff_pos += BATMAN_OGM_LEN +
  127. tt_len(batman_ogm_packet->tt_num_changes);
  128. packet_num++;
  129. batman_ogm_packet = (struct batman_ogm_packet *)
  130. (forw_packet->skb->data + buff_pos);
  131. }
  132. /* create clone because function is called more than once */
  133. skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
  134. if (skb)
  135. send_skb_packet(skb, hard_iface, broadcast_addr);
  136. }
  137. /* send a batman ogm packet */
  138. void bat_ogm_emit(struct forw_packet *forw_packet)
  139. {
  140. struct hard_iface *hard_iface;
  141. struct net_device *soft_iface;
  142. struct bat_priv *bat_priv;
  143. struct hard_iface *primary_if = NULL;
  144. struct batman_ogm_packet *batman_ogm_packet;
  145. unsigned char directlink;
  146. batman_ogm_packet = (struct batman_ogm_packet *)
  147. (forw_packet->skb->data);
  148. directlink = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
  149. if (!forw_packet->if_incoming) {
  150. pr_err("Error - can't forward packet: incoming iface not "
  151. "specified\n");
  152. goto out;
  153. }
  154. soft_iface = forw_packet->if_incoming->soft_iface;
  155. bat_priv = netdev_priv(soft_iface);
  156. if (forw_packet->if_incoming->if_status != IF_ACTIVE)
  157. goto out;
  158. primary_if = primary_if_get_selected(bat_priv);
  159. if (!primary_if)
  160. goto out;
  161. /* multihomed peer assumed */
  162. /* non-primary OGMs are only broadcasted on their interface */
  163. if ((directlink && (batman_ogm_packet->ttl == 1)) ||
  164. (forw_packet->own && (forw_packet->if_incoming != primary_if))) {
  165. /* FIXME: what about aggregated packets ? */
  166. bat_dbg(DBG_BATMAN, bat_priv,
  167. "%s packet (originator %pM, seqno %d, TTL %d) "
  168. "on interface %s [%pM]\n",
  169. (forw_packet->own ? "Sending own" : "Forwarding"),
  170. batman_ogm_packet->orig,
  171. ntohl(batman_ogm_packet->seqno),
  172. batman_ogm_packet->ttl,
  173. forw_packet->if_incoming->net_dev->name,
  174. forw_packet->if_incoming->net_dev->dev_addr);
  175. /* skb is only used once and than forw_packet is free'd */
  176. send_skb_packet(forw_packet->skb, forw_packet->if_incoming,
  177. broadcast_addr);
  178. forw_packet->skb = NULL;
  179. goto out;
  180. }
  181. /* broadcast on every interface */
  182. rcu_read_lock();
  183. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  184. if (hard_iface->soft_iface != soft_iface)
  185. continue;
  186. bat_ogm_send_to_if(forw_packet, hard_iface);
  187. }
  188. rcu_read_unlock();
  189. out:
  190. if (primary_if)
  191. hardif_free_ref(primary_if);
  192. }
  193. /* return true if new_packet can be aggregated with forw_packet */
  194. static bool bat_ogm_can_aggregate(const struct batman_ogm_packet
  195. *new_batman_ogm_packet,
  196. struct bat_priv *bat_priv,
  197. int packet_len, unsigned long send_time,
  198. bool directlink,
  199. const struct hard_iface *if_incoming,
  200. const struct forw_packet *forw_packet)
  201. {
  202. struct batman_ogm_packet *batman_ogm_packet;
  203. int aggregated_bytes = forw_packet->packet_len + packet_len;
  204. struct hard_iface *primary_if = NULL;
  205. bool res = false;
  206. batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data;
  207. /**
  208. * we can aggregate the current packet to this aggregated packet
  209. * if:
  210. *
  211. * - the send time is within our MAX_AGGREGATION_MS time
  212. * - the resulting packet wont be bigger than
  213. * MAX_AGGREGATION_BYTES
  214. */
  215. if (time_before(send_time, forw_packet->send_time) &&
  216. time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS),
  217. forw_packet->send_time) &&
  218. (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
  219. /**
  220. * check aggregation compatibility
  221. * -> direct link packets are broadcasted on
  222. * their interface only
  223. * -> aggregate packet if the current packet is
  224. * a "global" packet as well as the base
  225. * packet
  226. */
  227. primary_if = primary_if_get_selected(bat_priv);
  228. if (!primary_if)
  229. goto out;
  230. /* packets without direct link flag and high TTL
  231. * are flooded through the net */
  232. if ((!directlink) &&
  233. (!(batman_ogm_packet->flags & DIRECTLINK)) &&
  234. (batman_ogm_packet->ttl != 1) &&
  235. /* own packets originating non-primary
  236. * interfaces leave only that interface */
  237. ((!forw_packet->own) ||
  238. (forw_packet->if_incoming == primary_if))) {
  239. res = true;
  240. goto out;
  241. }
  242. /* if the incoming packet is sent via this one
  243. * interface only - we still can aggregate */
  244. if ((directlink) &&
  245. (new_batman_ogm_packet->ttl == 1) &&
  246. (forw_packet->if_incoming == if_incoming) &&
  247. /* packets from direct neighbors or
  248. * own secondary interface packets
  249. * (= secondary interface packets in general) */
  250. (batman_ogm_packet->flags & DIRECTLINK ||
  251. (forw_packet->own &&
  252. forw_packet->if_incoming != primary_if))) {
  253. res = true;
  254. goto out;
  255. }
  256. }
  257. out:
  258. if (primary_if)
  259. hardif_free_ref(primary_if);
  260. return res;
  261. }
  262. /* create a new aggregated packet and add this packet to it */
  263. static void bat_ogm_aggregate_new(const unsigned char *packet_buff,
  264. int packet_len, unsigned long send_time,
  265. bool direct_link,
  266. struct hard_iface *if_incoming,
  267. int own_packet)
  268. {
  269. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  270. struct forw_packet *forw_packet_aggr;
  271. unsigned char *skb_buff;
  272. if (!atomic_inc_not_zero(&if_incoming->refcount))
  273. return;
  274. /* own packet should always be scheduled */
  275. if (!own_packet) {
  276. if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
  277. bat_dbg(DBG_BATMAN, bat_priv,
  278. "batman packet queue full\n");
  279. goto out;
  280. }
  281. }
  282. forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC);
  283. if (!forw_packet_aggr) {
  284. if (!own_packet)
  285. atomic_inc(&bat_priv->batman_queue_left);
  286. goto out;
  287. }
  288. if ((atomic_read(&bat_priv->aggregated_ogms)) &&
  289. (packet_len < MAX_AGGREGATION_BYTES))
  290. forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
  291. sizeof(struct ethhdr));
  292. else
  293. forw_packet_aggr->skb = dev_alloc_skb(packet_len +
  294. sizeof(struct ethhdr));
  295. if (!forw_packet_aggr->skb) {
  296. if (!own_packet)
  297. atomic_inc(&bat_priv->batman_queue_left);
  298. kfree(forw_packet_aggr);
  299. goto out;
  300. }
  301. skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr));
  302. INIT_HLIST_NODE(&forw_packet_aggr->list);
  303. skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
  304. forw_packet_aggr->packet_len = packet_len;
  305. memcpy(skb_buff, packet_buff, packet_len);
  306. forw_packet_aggr->own = own_packet;
  307. forw_packet_aggr->if_incoming = if_incoming;
  308. forw_packet_aggr->num_packets = 0;
  309. forw_packet_aggr->direct_link_flags = NO_FLAGS;
  310. forw_packet_aggr->send_time = send_time;
  311. /* save packet direct link flag status */
  312. if (direct_link)
  313. forw_packet_aggr->direct_link_flags |= 1;
  314. /* add new packet to packet list */
  315. spin_lock_bh(&bat_priv->forw_bat_list_lock);
  316. hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
  317. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  318. /* start timer for this packet */
  319. INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
  320. send_outstanding_bat_ogm_packet);
  321. queue_delayed_work(bat_event_workqueue,
  322. &forw_packet_aggr->delayed_work,
  323. send_time - jiffies);
  324. return;
  325. out:
  326. hardif_free_ref(if_incoming);
  327. }
  328. /* aggregate a new packet into the existing ogm packet */
  329. static void bat_ogm_aggregate(struct forw_packet *forw_packet_aggr,
  330. const unsigned char *packet_buff,
  331. int packet_len, bool direct_link)
  332. {
  333. unsigned char *skb_buff;
  334. skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
  335. memcpy(skb_buff, packet_buff, packet_len);
  336. forw_packet_aggr->packet_len += packet_len;
  337. forw_packet_aggr->num_packets++;
  338. /* save packet direct link flag status */
  339. if (direct_link)
  340. forw_packet_aggr->direct_link_flags |=
  341. (1 << forw_packet_aggr->num_packets);
  342. }
  343. static void bat_ogm_queue_add(struct bat_priv *bat_priv,
  344. unsigned char *packet_buff,
  345. int packet_len, struct hard_iface *if_incoming,
  346. int own_packet, unsigned long send_time)
  347. {
  348. /**
  349. * _aggr -> pointer to the packet we want to aggregate with
  350. * _pos -> pointer to the position in the queue
  351. */
  352. struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
  353. struct hlist_node *tmp_node;
  354. struct batman_ogm_packet *batman_ogm_packet;
  355. bool direct_link;
  356. batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
  357. direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0;
  358. /* find position for the packet in the forward queue */
  359. spin_lock_bh(&bat_priv->forw_bat_list_lock);
  360. /* own packets are not to be aggregated */
  361. if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) {
  362. hlist_for_each_entry(forw_packet_pos, tmp_node,
  363. &bat_priv->forw_bat_list, list) {
  364. if (bat_ogm_can_aggregate(batman_ogm_packet,
  365. bat_priv, packet_len,
  366. send_time, direct_link,
  367. if_incoming,
  368. forw_packet_pos)) {
  369. forw_packet_aggr = forw_packet_pos;
  370. break;
  371. }
  372. }
  373. }
  374. /* nothing to aggregate with - either aggregation disabled or no
  375. * suitable aggregation packet found */
  376. if (!forw_packet_aggr) {
  377. /* the following section can run without the lock */
  378. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  379. /**
  380. * if we could not aggregate this packet with one of the others
  381. * we hold it back for a while, so that it might be aggregated
  382. * later on
  383. */
  384. if ((!own_packet) &&
  385. (atomic_read(&bat_priv->aggregated_ogms)))
  386. send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
  387. bat_ogm_aggregate_new(packet_buff, packet_len,
  388. send_time, direct_link,
  389. if_incoming, own_packet);
  390. } else {
  391. bat_ogm_aggregate(forw_packet_aggr, packet_buff, packet_len,
  392. direct_link);
  393. spin_unlock_bh(&bat_priv->forw_bat_list_lock);
  394. }
  395. }
  396. static void bat_ogm_forward(struct orig_node *orig_node,
  397. const struct ethhdr *ethhdr,
  398. struct batman_ogm_packet *batman_ogm_packet,
  399. int directlink, struct hard_iface *if_incoming)
  400. {
  401. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  402. struct neigh_node *router;
  403. uint8_t in_tq, in_ttl, tq_avg = 0;
  404. uint8_t tt_num_changes;
  405. if (batman_ogm_packet->ttl <= 1) {
  406. bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
  407. return;
  408. }
  409. router = orig_node_get_router(orig_node);
  410. in_tq = batman_ogm_packet->tq;
  411. in_ttl = batman_ogm_packet->ttl;
  412. tt_num_changes = batman_ogm_packet->tt_num_changes;
  413. batman_ogm_packet->ttl--;
  414. memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
  415. /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast
  416. * of our best tq value */
  417. if (router && router->tq_avg != 0) {
  418. /* rebroadcast ogm of best ranking neighbor as is */
  419. if (!compare_eth(router->addr, ethhdr->h_source)) {
  420. batman_ogm_packet->tq = router->tq_avg;
  421. if (router->last_ttl)
  422. batman_ogm_packet->ttl = router->last_ttl - 1;
  423. }
  424. tq_avg = router->tq_avg;
  425. }
  426. if (router)
  427. neigh_node_free_ref(router);
  428. /* apply hop penalty */
  429. batman_ogm_packet->tq = hop_penalty(batman_ogm_packet->tq, bat_priv);
  430. bat_dbg(DBG_BATMAN, bat_priv,
  431. "Forwarding packet: tq_orig: %i, tq_avg: %i, "
  432. "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n",
  433. in_tq, tq_avg, batman_ogm_packet->tq, in_ttl - 1,
  434. batman_ogm_packet->ttl);
  435. batman_ogm_packet->seqno = htonl(batman_ogm_packet->seqno);
  436. batman_ogm_packet->tt_crc = htons(batman_ogm_packet->tt_crc);
  437. /* switch of primaries first hop flag when forwarding */
  438. batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP;
  439. if (directlink)
  440. batman_ogm_packet->flags |= DIRECTLINK;
  441. else
  442. batman_ogm_packet->flags &= ~DIRECTLINK;
  443. bat_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet,
  444. BATMAN_OGM_LEN + tt_len(tt_num_changes),
  445. if_incoming, 0, bat_ogm_fwd_send_time());
  446. }
  447. void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
  448. {
  449. struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
  450. struct batman_ogm_packet *batman_ogm_packet;
  451. struct hard_iface *primary_if;
  452. int vis_server;
  453. vis_server = atomic_read(&bat_priv->vis_mode);
  454. primary_if = primary_if_get_selected(bat_priv);
  455. batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
  456. /* change sequence number to network order */
  457. batman_ogm_packet->seqno =
  458. htonl((uint32_t)atomic_read(&hard_iface->seqno));
  459. batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
  460. batman_ogm_packet->tt_crc = htons((uint16_t)
  461. atomic_read(&bat_priv->tt_crc));
  462. if (tt_num_changes >= 0)
  463. batman_ogm_packet->tt_num_changes = tt_num_changes;
  464. if (vis_server == VIS_TYPE_SERVER_SYNC)
  465. batman_ogm_packet->flags |= VIS_SERVER;
  466. else
  467. batman_ogm_packet->flags &= ~VIS_SERVER;
  468. if ((hard_iface == primary_if) &&
  469. (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER))
  470. batman_ogm_packet->gw_flags =
  471. (uint8_t)atomic_read(&bat_priv->gw_bandwidth);
  472. else
  473. batman_ogm_packet->gw_flags = NO_FLAGS;
  474. atomic_inc(&hard_iface->seqno);
  475. slide_own_bcast_window(hard_iface);
  476. bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
  477. hard_iface->packet_len, hard_iface, 1,
  478. bat_ogm_emit_send_time(bat_priv));
  479. if (primary_if)
  480. hardif_free_ref(primary_if);
  481. }
  482. static void bat_ogm_orig_update(struct bat_priv *bat_priv,
  483. struct orig_node *orig_node,
  484. const struct ethhdr *ethhdr,
  485. const struct batman_ogm_packet
  486. *batman_ogm_packet,
  487. struct hard_iface *if_incoming,
  488. const unsigned char *tt_buff, int is_duplicate)
  489. {
  490. struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
  491. struct neigh_node *router = NULL;
  492. struct orig_node *orig_node_tmp;
  493. struct hlist_node *node;
  494. uint8_t bcast_own_sum_orig, bcast_own_sum_neigh;
  495. bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): "
  496. "Searching and updating originator entry of received packet\n");
  497. rcu_read_lock();
  498. hlist_for_each_entry_rcu(tmp_neigh_node, node,
  499. &orig_node->neigh_list, list) {
  500. if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
  501. (tmp_neigh_node->if_incoming == if_incoming) &&
  502. atomic_inc_not_zero(&tmp_neigh_node->refcount)) {
  503. if (neigh_node)
  504. neigh_node_free_ref(neigh_node);
  505. neigh_node = tmp_neigh_node;
  506. continue;
  507. }
  508. if (is_duplicate)
  509. continue;
  510. spin_lock_bh(&tmp_neigh_node->tq_lock);
  511. ring_buffer_set(tmp_neigh_node->tq_recv,
  512. &tmp_neigh_node->tq_index, 0);
  513. tmp_neigh_node->tq_avg =
  514. ring_buffer_avg(tmp_neigh_node->tq_recv);
  515. spin_unlock_bh(&tmp_neigh_node->tq_lock);
  516. }
  517. if (!neigh_node) {
  518. struct orig_node *orig_tmp;
  519. orig_tmp = get_orig_node(bat_priv, ethhdr->h_source);
  520. if (!orig_tmp)
  521. goto unlock;
  522. neigh_node = create_neighbor(orig_node, orig_tmp,
  523. ethhdr->h_source, if_incoming);
  524. orig_node_free_ref(orig_tmp);
  525. if (!neigh_node)
  526. goto unlock;
  527. } else
  528. bat_dbg(DBG_BATMAN, bat_priv,
  529. "Updating existing last-hop neighbor of originator\n");
  530. rcu_read_unlock();
  531. orig_node->flags = batman_ogm_packet->flags;
  532. neigh_node->last_valid = jiffies;
  533. spin_lock_bh(&neigh_node->tq_lock);
  534. ring_buffer_set(neigh_node->tq_recv,
  535. &neigh_node->tq_index,
  536. batman_ogm_packet->tq);
  537. neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
  538. spin_unlock_bh(&neigh_node->tq_lock);
  539. if (!is_duplicate) {
  540. orig_node->last_ttl = batman_ogm_packet->ttl;
  541. neigh_node->last_ttl = batman_ogm_packet->ttl;
  542. }
  543. bonding_candidate_add(orig_node, neigh_node);
  544. /* if this neighbor already is our next hop there is nothing
  545. * to change */
  546. router = orig_node_get_router(orig_node);
  547. if (router == neigh_node)
  548. goto update_tt;
  549. /* if this neighbor does not offer a better TQ we won't consider it */
  550. if (router && (router->tq_avg > neigh_node->tq_avg))
  551. goto update_tt;
  552. /* if the TQ is the same and the link not more symmetric we
  553. * won't consider it either */
  554. if (router && (neigh_node->tq_avg == router->tq_avg)) {
  555. orig_node_tmp = router->orig_node;
  556. spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
  557. bcast_own_sum_orig =
  558. orig_node_tmp->bcast_own_sum[if_incoming->if_num];
  559. spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
  560. orig_node_tmp = neigh_node->orig_node;
  561. spin_lock_bh(&orig_node_tmp->ogm_cnt_lock);
  562. bcast_own_sum_neigh =
  563. orig_node_tmp->bcast_own_sum[if_incoming->if_num];
  564. spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);
  565. if (bcast_own_sum_orig >= bcast_own_sum_neigh)
  566. goto update_tt;
  567. }
  568. update_route(bat_priv, orig_node, neigh_node);
  569. update_tt:
  570. /* I have to check for transtable changes only if the OGM has been
  571. * sent through a primary interface */
  572. if (((batman_ogm_packet->orig != ethhdr->h_source) &&
  573. (batman_ogm_packet->ttl > 2)) ||
  574. (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
  575. tt_update_orig(bat_priv, orig_node, tt_buff,
  576. batman_ogm_packet->tt_num_changes,
  577. batman_ogm_packet->ttvn,
  578. batman_ogm_packet->tt_crc);
  579. if (orig_node->gw_flags != batman_ogm_packet->gw_flags)
  580. gw_node_update(bat_priv, orig_node,
  581. batman_ogm_packet->gw_flags);
  582. orig_node->gw_flags = batman_ogm_packet->gw_flags;
  583. /* restart gateway selection if fast or late switching was enabled */
  584. if ((orig_node->gw_flags) &&
  585. (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) &&
  586. (atomic_read(&bat_priv->gw_sel_class) > 2))
  587. gw_check_election(bat_priv, orig_node);
  588. goto out;
  589. unlock:
  590. rcu_read_unlock();
  591. out:
  592. if (neigh_node)
  593. neigh_node_free_ref(neigh_node);
  594. if (router)
  595. neigh_node_free_ref(router);
  596. }
  597. static int bat_ogm_calc_tq(struct orig_node *orig_node,
  598. struct orig_node *orig_neigh_node,
  599. struct batman_ogm_packet *batman_ogm_packet,
  600. struct hard_iface *if_incoming)
  601. {
  602. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  603. struct neigh_node *neigh_node = NULL, *tmp_neigh_node;
  604. struct hlist_node *node;
  605. uint8_t total_count;
  606. uint8_t orig_eq_count, neigh_rq_count, tq_own;
  607. int tq_asym_penalty, ret = 0;
  608. /* find corresponding one hop neighbor */
  609. rcu_read_lock();
  610. hlist_for_each_entry_rcu(tmp_neigh_node, node,
  611. &orig_neigh_node->neigh_list, list) {
  612. if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig))
  613. continue;
  614. if (tmp_neigh_node->if_incoming != if_incoming)
  615. continue;
  616. if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
  617. continue;
  618. neigh_node = tmp_neigh_node;
  619. break;
  620. }
  621. rcu_read_unlock();
  622. if (!neigh_node)
  623. neigh_node = create_neighbor(orig_neigh_node,
  624. orig_neigh_node,
  625. orig_neigh_node->orig,
  626. if_incoming);
  627. if (!neigh_node)
  628. goto out;
  629. /* if orig_node is direct neighbor update neigh_node last_valid */
  630. if (orig_node == orig_neigh_node)
  631. neigh_node->last_valid = jiffies;
  632. orig_node->last_valid = jiffies;
  633. /* find packet count of corresponding one hop neighbor */
  634. spin_lock_bh(&orig_node->ogm_cnt_lock);
  635. orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num];
  636. neigh_rq_count = neigh_node->real_packet_count;
  637. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  638. /* pay attention to not get a value bigger than 100 % */
  639. total_count = (orig_eq_count > neigh_rq_count ?
  640. neigh_rq_count : orig_eq_count);
  641. /* if we have too few packets (too less data) we set tq_own to zero */
  642. /* if we receive too few packets it is not considered bidirectional */
  643. if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
  644. (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
  645. tq_own = 0;
  646. else
  647. /* neigh_node->real_packet_count is never zero as we
  648. * only purge old information when getting new
  649. * information */
  650. tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count;
  651. /*
  652. * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
  653. * affect the nearly-symmetric links only a little, but
  654. * punishes asymmetric links more. This will give a value
  655. * between 0 and TQ_MAX_VALUE
  656. */
  657. tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE *
  658. (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
  659. (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) *
  660. (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) /
  661. (TQ_LOCAL_WINDOW_SIZE *
  662. TQ_LOCAL_WINDOW_SIZE *
  663. TQ_LOCAL_WINDOW_SIZE);
  664. batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own
  665. * tq_asym_penalty) /
  666. (TQ_MAX_VALUE * TQ_MAX_VALUE));
  667. bat_dbg(DBG_BATMAN, bat_priv,
  668. "bidirectional: "
  669. "orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
  670. "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
  671. "total tq: %3i\n",
  672. orig_node->orig, orig_neigh_node->orig, total_count,
  673. neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq);
  674. /* if link has the minimum required transmission quality
  675. * consider it bidirectional */
  676. if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
  677. ret = 1;
  678. out:
  679. if (neigh_node)
  680. neigh_node_free_ref(neigh_node);
  681. return ret;
  682. }
  683. /* processes a batman packet for all interfaces, adjusts the sequence number and
  684. * finds out whether it is a duplicate.
  685. * returns:
  686. * 1 the packet is a duplicate
  687. * 0 the packet has not yet been received
  688. * -1 the packet is old and has been received while the seqno window
  689. * was protected. Caller should drop it.
  690. */
  691. static int bat_ogm_update_seqnos(const struct ethhdr *ethhdr,
  692. const struct batman_ogm_packet
  693. *batman_ogm_packet,
  694. const struct hard_iface *if_incoming)
  695. {
  696. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  697. struct orig_node *orig_node;
  698. struct neigh_node *tmp_neigh_node;
  699. struct hlist_node *node;
  700. int is_duplicate = 0;
  701. int32_t seq_diff;
  702. int need_update = 0;
  703. int set_mark, ret = -1;
  704. orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
  705. if (!orig_node)
  706. return 0;
  707. spin_lock_bh(&orig_node->ogm_cnt_lock);
  708. seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno;
  709. /* signalize caller that the packet is to be dropped. */
  710. if (window_protected(bat_priv, seq_diff,
  711. &orig_node->batman_seqno_reset))
  712. goto out;
  713. rcu_read_lock();
  714. hlist_for_each_entry_rcu(tmp_neigh_node, node,
  715. &orig_node->neigh_list, list) {
  716. is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
  717. orig_node->last_real_seqno,
  718. batman_ogm_packet->seqno);
  719. if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) &&
  720. (tmp_neigh_node->if_incoming == if_incoming))
  721. set_mark = 1;
  722. else
  723. set_mark = 0;
  724. /* if the window moved, set the update flag. */
  725. need_update |= bit_get_packet(bat_priv,
  726. tmp_neigh_node->real_bits,
  727. seq_diff, set_mark);
  728. tmp_neigh_node->real_packet_count =
  729. bit_packet_count(tmp_neigh_node->real_bits);
  730. }
  731. rcu_read_unlock();
  732. if (need_update) {
  733. bat_dbg(DBG_BATMAN, bat_priv,
  734. "updating last_seqno: old %d, new %d\n",
  735. orig_node->last_real_seqno, batman_ogm_packet->seqno);
  736. orig_node->last_real_seqno = batman_ogm_packet->seqno;
  737. }
  738. ret = is_duplicate;
  739. out:
  740. spin_unlock_bh(&orig_node->ogm_cnt_lock);
  741. orig_node_free_ref(orig_node);
  742. return ret;
  743. }
  744. static void bat_ogm_process(const struct ethhdr *ethhdr,
  745. struct batman_ogm_packet *batman_ogm_packet,
  746. const unsigned char *tt_buff,
  747. struct hard_iface *if_incoming)
  748. {
  749. struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
  750. struct hard_iface *hard_iface;
  751. struct orig_node *orig_neigh_node, *orig_node;
  752. struct neigh_node *router = NULL, *router_router = NULL;
  753. struct neigh_node *orig_neigh_router = NULL;
  754. int has_directlink_flag;
  755. int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
  756. int is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
  757. int is_duplicate;
  758. uint32_t if_incoming_seqno;
  759. /* Silently drop when the batman packet is actually not a
  760. * correct packet.
  761. *
  762. * This might happen if a packet is padded (e.g. Ethernet has a
  763. * minimum frame length of 64 byte) and the aggregation interprets
  764. * it as an additional length.
  765. *
  766. * TODO: A more sane solution would be to have a bit in the
  767. * batman_ogm_packet to detect whether the packet is the last
  768. * packet in an aggregation. Here we expect that the padding
  769. * is always zero (or not 0x01)
  770. */
  771. if (batman_ogm_packet->packet_type != BAT_OGM)
  772. return;
  773. /* could be changed by schedule_own_packet() */
  774. if_incoming_seqno = atomic_read(&if_incoming->seqno);
  775. has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
  776. is_single_hop_neigh = (compare_eth(ethhdr->h_source,
  777. batman_ogm_packet->orig) ? 1 : 0);
  778. bat_dbg(DBG_BATMAN, bat_priv,
  779. "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
  780. "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, "
  781. "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n",
  782. ethhdr->h_source, if_incoming->net_dev->name,
  783. if_incoming->net_dev->dev_addr, batman_ogm_packet->orig,
  784. batman_ogm_packet->prev_sender, batman_ogm_packet->seqno,
  785. batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc,
  786. batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq,
  787. batman_ogm_packet->ttl, batman_ogm_packet->version,
  788. has_directlink_flag);
  789. rcu_read_lock();
  790. list_for_each_entry_rcu(hard_iface, &hardif_list, list) {
  791. if (hard_iface->if_status != IF_ACTIVE)
  792. continue;
  793. if (hard_iface->soft_iface != if_incoming->soft_iface)
  794. continue;
  795. if (compare_eth(ethhdr->h_source,
  796. hard_iface->net_dev->dev_addr))
  797. is_my_addr = 1;
  798. if (compare_eth(batman_ogm_packet->orig,
  799. hard_iface->net_dev->dev_addr))
  800. is_my_orig = 1;
  801. if (compare_eth(batman_ogm_packet->prev_sender,
  802. hard_iface->net_dev->dev_addr))
  803. is_my_oldorig = 1;
  804. if (is_broadcast_ether_addr(ethhdr->h_source))
  805. is_broadcast = 1;
  806. }
  807. rcu_read_unlock();
  808. if (batman_ogm_packet->version != COMPAT_VERSION) {
  809. bat_dbg(DBG_BATMAN, bat_priv,
  810. "Drop packet: incompatible batman version (%i)\n",
  811. batman_ogm_packet->version);
  812. return;
  813. }
  814. if (is_my_addr) {
  815. bat_dbg(DBG_BATMAN, bat_priv,
  816. "Drop packet: received my own broadcast (sender: %pM"
  817. ")\n",
  818. ethhdr->h_source);
  819. return;
  820. }
  821. if (is_broadcast) {
  822. bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
  823. "ignoring all packets with broadcast source addr (sender: %pM"
  824. ")\n", ethhdr->h_source);
  825. return;
  826. }
  827. if (is_my_orig) {
  828. unsigned long *word;
  829. int offset;
  830. orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source);
  831. if (!orig_neigh_node)
  832. return;
  833. /* neighbor has to indicate direct link and it has to
  834. * come via the corresponding interface */
  835. /* save packet seqno for bidirectional check */
  836. if (has_directlink_flag &&
  837. compare_eth(if_incoming->net_dev->dev_addr,
  838. batman_ogm_packet->orig)) {
  839. offset = if_incoming->if_num * NUM_WORDS;
  840. spin_lock_bh(&orig_neigh_node->ogm_cnt_lock);
  841. word = &(orig_neigh_node->bcast_own[offset]);
  842. bit_mark(word,
  843. if_incoming_seqno -
  844. batman_ogm_packet->seqno - 2);
  845. orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
  846. bit_packet_count(word);
  847. spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock);
  848. }
  849. bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
  850. "originator packet from myself (via neighbor)\n");
  851. orig_node_free_ref(orig_neigh_node);
  852. return;
  853. }
  854. if (is_my_oldorig) {
  855. bat_dbg(DBG_BATMAN, bat_priv,
  856. "Drop packet: ignoring all rebroadcast echos (sender: "
  857. "%pM)\n", ethhdr->h_source);
  858. return;
  859. }
  860. orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig);
  861. if (!orig_node)
  862. return;
  863. is_duplicate = bat_ogm_update_seqnos(ethhdr, batman_ogm_packet,
  864. if_incoming);
  865. if (is_duplicate == -1) {
  866. bat_dbg(DBG_BATMAN, bat_priv,
  867. "Drop packet: packet within seqno protection time "
  868. "(sender: %pM)\n", ethhdr->h_source);
  869. goto out;
  870. }
  871. if (batman_ogm_packet->tq == 0) {
  872. bat_dbg(DBG_BATMAN, bat_priv,
  873. "Drop packet: originator packet with tq equal 0\n");
  874. goto out;
  875. }
  876. router = orig_node_get_router(orig_node);
  877. if (router)
  878. router_router = orig_node_get_router(router->orig_node);
  879. /* avoid temporary routing loops */
  880. if (router && router_router &&
  881. (compare_eth(router->addr, batman_ogm_packet->prev_sender)) &&
  882. !(compare_eth(batman_ogm_packet->orig,
  883. batman_ogm_packet->prev_sender)) &&
  884. (compare_eth(router->addr, router_router->addr))) {
  885. bat_dbg(DBG_BATMAN, bat_priv,
  886. "Drop packet: ignoring all rebroadcast packets that "
  887. "may make me loop (sender: %pM)\n", ethhdr->h_source);
  888. goto out;
  889. }
  890. /* if sender is a direct neighbor the sender mac equals
  891. * originator mac */
  892. orig_neigh_node = (is_single_hop_neigh ?
  893. orig_node :
  894. get_orig_node(bat_priv, ethhdr->h_source));
  895. if (!orig_neigh_node)
  896. goto out;
  897. orig_neigh_router = orig_node_get_router(orig_neigh_node);
  898. /* drop packet if sender is not a direct neighbor and if we
  899. * don't route towards it */
  900. if (!is_single_hop_neigh && (!orig_neigh_router)) {
  901. bat_dbg(DBG_BATMAN, bat_priv,
  902. "Drop packet: OGM via unknown neighbor!\n");
  903. goto out_neigh;
  904. }
  905. is_bidirectional = bat_ogm_calc_tq(orig_node, orig_neigh_node,
  906. batman_ogm_packet, if_incoming);
  907. bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet);
  908. /* update ranking if it is not a duplicate or has the same
  909. * seqno and similar ttl as the non-duplicate */
  910. if (is_bidirectional &&
  911. (!is_duplicate ||
  912. ((orig_node->last_real_seqno == batman_ogm_packet->seqno) &&
  913. (orig_node->last_ttl - 3 <= batman_ogm_packet->ttl))))
  914. bat_ogm_orig_update(bat_priv, orig_node, ethhdr,
  915. batman_ogm_packet, if_incoming,
  916. tt_buff, is_duplicate);
  917. /* is single hop (direct) neighbor */
  918. if (is_single_hop_neigh) {
  919. /* mark direct link on incoming interface */
  920. bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet,
  921. 1, if_incoming);
  922. bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
  923. "rebroadcast neighbor packet with direct link flag\n");
  924. goto out_neigh;
  925. }
  926. /* multihop originator */
  927. if (!is_bidirectional) {
  928. bat_dbg(DBG_BATMAN, bat_priv,
  929. "Drop packet: not received via bidirectional link\n");
  930. goto out_neigh;
  931. }
  932. if (is_duplicate) {
  933. bat_dbg(DBG_BATMAN, bat_priv,
  934. "Drop packet: duplicate packet received\n");
  935. goto out_neigh;
  936. }
  937. bat_dbg(DBG_BATMAN, bat_priv,
  938. "Forwarding packet: rebroadcast originator packet\n");
  939. bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 0, if_incoming);
  940. out_neigh:
  941. if ((orig_neigh_node) && (!is_single_hop_neigh))
  942. orig_node_free_ref(orig_neigh_node);
  943. out:
  944. if (router)
  945. neigh_node_free_ref(router);
  946. if (router_router)
  947. neigh_node_free_ref(router_router);
  948. if (orig_neigh_router)
  949. neigh_node_free_ref(orig_neigh_router);
  950. orig_node_free_ref(orig_node);
  951. }
  952. void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff,
  953. int packet_len, struct hard_iface *if_incoming)
  954. {
  955. struct batman_ogm_packet *batman_ogm_packet;
  956. int buff_pos = 0;
  957. unsigned char *tt_buff;
  958. batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
  959. /* unpack the aggregated packets and process them one by one */
  960. do {
  961. /* network to host order for our 32bit seqno and the
  962. orig_interval */
  963. batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno);
  964. batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc);
  965. tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;
  966. bat_ogm_process(ethhdr, batman_ogm_packet,
  967. tt_buff, if_incoming);
  968. buff_pos += BATMAN_OGM_LEN +
  969. tt_len(batman_ogm_packet->tt_num_changes);
  970. batman_ogm_packet = (struct batman_ogm_packet *)
  971. (packet_buff + buff_pos);
  972. } while (bat_ogm_aggr_packet(buff_pos, packet_len,
  973. batman_ogm_packet->tt_num_changes));
  974. }