bat_iv_ogm.c 35 KB

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