gateway_client.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright (C) 2009-2011 B.A.T.M.A.N. contributors:
  3. *
  4. * Marek Lindner
  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_sysfs.h"
  23. #include "gateway_client.h"
  24. #include "gateway_common.h"
  25. #include "hard-interface.h"
  26. #include "originator.h"
  27. #include "routing.h"
  28. #include <linux/ip.h>
  29. #include <linux/ipv6.h>
  30. #include <linux/udp.h>
  31. #include <linux/if_vlan.h>
  32. /* This is the offset of the options field in a dhcp packet starting at
  33. * the beginning of the dhcp header */
  34. #define DHCP_OPTIONS_OFFSET 240
  35. #define DHCP_REQUEST 3
  36. static void gw_node_free_ref(struct gw_node *gw_node)
  37. {
  38. if (atomic_dec_and_test(&gw_node->refcount))
  39. kfree_rcu(gw_node, rcu);
  40. }
  41. static struct gw_node *gw_get_selected_gw_node(struct bat_priv *bat_priv)
  42. {
  43. struct gw_node *gw_node;
  44. rcu_read_lock();
  45. gw_node = rcu_dereference(bat_priv->curr_gw);
  46. if (!gw_node)
  47. goto out;
  48. if (!atomic_inc_not_zero(&gw_node->refcount))
  49. gw_node = NULL;
  50. out:
  51. rcu_read_unlock();
  52. return gw_node;
  53. }
  54. struct orig_node *gw_get_selected_orig(struct bat_priv *bat_priv)
  55. {
  56. struct gw_node *gw_node;
  57. struct orig_node *orig_node = NULL;
  58. gw_node = gw_get_selected_gw_node(bat_priv);
  59. if (!gw_node)
  60. goto out;
  61. rcu_read_lock();
  62. orig_node = gw_node->orig_node;
  63. if (!orig_node)
  64. goto unlock;
  65. if (!atomic_inc_not_zero(&orig_node->refcount))
  66. orig_node = NULL;
  67. unlock:
  68. rcu_read_unlock();
  69. out:
  70. if (gw_node)
  71. gw_node_free_ref(gw_node);
  72. return orig_node;
  73. }
  74. static void gw_select(struct bat_priv *bat_priv, struct gw_node *new_gw_node)
  75. {
  76. struct gw_node *curr_gw_node;
  77. spin_lock_bh(&bat_priv->gw_list_lock);
  78. if (new_gw_node && !atomic_inc_not_zero(&new_gw_node->refcount))
  79. new_gw_node = NULL;
  80. curr_gw_node = rcu_dereference_protected(bat_priv->curr_gw, 1);
  81. rcu_assign_pointer(bat_priv->curr_gw, new_gw_node);
  82. if (curr_gw_node)
  83. gw_node_free_ref(curr_gw_node);
  84. spin_unlock_bh(&bat_priv->gw_list_lock);
  85. }
  86. void gw_deselect(struct bat_priv *bat_priv)
  87. {
  88. atomic_set(&bat_priv->gw_reselect, 1);
  89. }
  90. static struct gw_node *gw_get_best_gw_node(struct bat_priv *bat_priv)
  91. {
  92. struct neigh_node *router;
  93. struct hlist_node *node;
  94. struct gw_node *gw_node, *curr_gw = NULL;
  95. uint32_t max_gw_factor = 0, tmp_gw_factor = 0;
  96. uint8_t max_tq = 0;
  97. int down, up;
  98. rcu_read_lock();
  99. hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) {
  100. if (gw_node->deleted)
  101. continue;
  102. router = orig_node_get_router(gw_node->orig_node);
  103. if (!router)
  104. continue;
  105. if (!atomic_inc_not_zero(&gw_node->refcount))
  106. goto next;
  107. switch (atomic_read(&bat_priv->gw_sel_class)) {
  108. case 1: /* fast connection */
  109. gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags,
  110. &down, &up);
  111. tmp_gw_factor = (router->tq_avg * router->tq_avg *
  112. down * 100 * 100) /
  113. (TQ_LOCAL_WINDOW_SIZE *
  114. TQ_LOCAL_WINDOW_SIZE * 64);
  115. if ((tmp_gw_factor > max_gw_factor) ||
  116. ((tmp_gw_factor == max_gw_factor) &&
  117. (router->tq_avg > max_tq))) {
  118. if (curr_gw)
  119. gw_node_free_ref(curr_gw);
  120. curr_gw = gw_node;
  121. atomic_inc(&curr_gw->refcount);
  122. }
  123. break;
  124. default: /**
  125. * 2: stable connection (use best statistic)
  126. * 3: fast-switch (use best statistic but change as
  127. * soon as a better gateway appears)
  128. * XX: late-switch (use best statistic but change as
  129. * soon as a better gateway appears which has
  130. * $routing_class more tq points)
  131. **/
  132. if (router->tq_avg > max_tq) {
  133. if (curr_gw)
  134. gw_node_free_ref(curr_gw);
  135. curr_gw = gw_node;
  136. atomic_inc(&curr_gw->refcount);
  137. }
  138. break;
  139. }
  140. if (router->tq_avg > max_tq)
  141. max_tq = router->tq_avg;
  142. if (tmp_gw_factor > max_gw_factor)
  143. max_gw_factor = tmp_gw_factor;
  144. gw_node_free_ref(gw_node);
  145. next:
  146. neigh_node_free_ref(router);
  147. }
  148. rcu_read_unlock();
  149. return curr_gw;
  150. }
  151. void gw_election(struct bat_priv *bat_priv)
  152. {
  153. struct gw_node *curr_gw = NULL, *next_gw = NULL;
  154. struct neigh_node *router = NULL;
  155. char gw_addr[18] = { '\0' };
  156. /**
  157. * The batman daemon checks here if we already passed a full originator
  158. * cycle in order to make sure we don't choose the first gateway we
  159. * hear about. This check is based on the daemon's uptime which we
  160. * don't have.
  161. **/
  162. if (atomic_read(&bat_priv->gw_mode) != GW_MODE_CLIENT)
  163. goto out;
  164. if (!atomic_dec_not_zero(&bat_priv->gw_reselect))
  165. goto out;
  166. curr_gw = gw_get_selected_gw_node(bat_priv);
  167. next_gw = gw_get_best_gw_node(bat_priv);
  168. if (curr_gw == next_gw)
  169. goto out;
  170. if (next_gw) {
  171. sprintf(gw_addr, "%pM", next_gw->orig_node->orig);
  172. router = orig_node_get_router(next_gw->orig_node);
  173. if (!router) {
  174. gw_deselect(bat_priv);
  175. goto out;
  176. }
  177. }
  178. if ((curr_gw) && (!next_gw)) {
  179. bat_dbg(DBG_BATMAN, bat_priv,
  180. "Removing selected gateway - no gateway in range\n");
  181. throw_uevent(bat_priv, UEV_GW, UEV_DEL, NULL);
  182. } else if ((!curr_gw) && (next_gw)) {
  183. bat_dbg(DBG_BATMAN, bat_priv,
  184. "Adding route to gateway %pM (gw_flags: %i, tq: %i)\n",
  185. next_gw->orig_node->orig,
  186. next_gw->orig_node->gw_flags,
  187. router->tq_avg);
  188. throw_uevent(bat_priv, UEV_GW, UEV_ADD, gw_addr);
  189. } else {
  190. bat_dbg(DBG_BATMAN, bat_priv,
  191. "Changing route to gateway %pM "
  192. "(gw_flags: %i, tq: %i)\n",
  193. next_gw->orig_node->orig,
  194. next_gw->orig_node->gw_flags,
  195. router->tq_avg);
  196. throw_uevent(bat_priv, UEV_GW, UEV_CHANGE, gw_addr);
  197. }
  198. gw_select(bat_priv, next_gw);
  199. out:
  200. if (curr_gw)
  201. gw_node_free_ref(curr_gw);
  202. if (next_gw)
  203. gw_node_free_ref(next_gw);
  204. if (router)
  205. neigh_node_free_ref(router);
  206. }
  207. void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node)
  208. {
  209. struct orig_node *curr_gw_orig;
  210. struct neigh_node *router_gw = NULL, *router_orig = NULL;
  211. uint8_t gw_tq_avg, orig_tq_avg;
  212. curr_gw_orig = gw_get_selected_orig(bat_priv);
  213. if (!curr_gw_orig)
  214. goto deselect;
  215. router_gw = orig_node_get_router(curr_gw_orig);
  216. if (!router_gw)
  217. goto deselect;
  218. /* this node already is the gateway */
  219. if (curr_gw_orig == orig_node)
  220. goto out;
  221. router_orig = orig_node_get_router(orig_node);
  222. if (!router_orig)
  223. goto out;
  224. gw_tq_avg = router_gw->tq_avg;
  225. orig_tq_avg = router_orig->tq_avg;
  226. /* the TQ value has to be better */
  227. if (orig_tq_avg < gw_tq_avg)
  228. goto out;
  229. /**
  230. * if the routing class is greater than 3 the value tells us how much
  231. * greater the TQ value of the new gateway must be
  232. **/
  233. if ((atomic_read(&bat_priv->gw_sel_class) > 3) &&
  234. (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_sel_class)))
  235. goto out;
  236. bat_dbg(DBG_BATMAN, bat_priv,
  237. "Restarting gateway selection: better gateway found (tq curr: "
  238. "%i, tq new: %i)\n",
  239. gw_tq_avg, orig_tq_avg);
  240. deselect:
  241. gw_deselect(bat_priv);
  242. out:
  243. if (curr_gw_orig)
  244. orig_node_free_ref(curr_gw_orig);
  245. if (router_gw)
  246. neigh_node_free_ref(router_gw);
  247. if (router_orig)
  248. neigh_node_free_ref(router_orig);
  249. return;
  250. }
  251. static void gw_node_add(struct bat_priv *bat_priv,
  252. struct orig_node *orig_node, uint8_t new_gwflags)
  253. {
  254. struct gw_node *gw_node;
  255. int down, up;
  256. gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
  257. if (!gw_node)
  258. return;
  259. INIT_HLIST_NODE(&gw_node->list);
  260. gw_node->orig_node = orig_node;
  261. atomic_set(&gw_node->refcount, 1);
  262. spin_lock_bh(&bat_priv->gw_list_lock);
  263. hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list);
  264. spin_unlock_bh(&bat_priv->gw_list_lock);
  265. gw_bandwidth_to_kbit(new_gwflags, &down, &up);
  266. bat_dbg(DBG_BATMAN, bat_priv,
  267. "Found new gateway %pM -> gw_class: %i - %i%s/%i%s\n",
  268. orig_node->orig, new_gwflags,
  269. (down > 2048 ? down / 1024 : down),
  270. (down > 2048 ? "MBit" : "KBit"),
  271. (up > 2048 ? up / 1024 : up),
  272. (up > 2048 ? "MBit" : "KBit"));
  273. }
  274. void gw_node_update(struct bat_priv *bat_priv,
  275. struct orig_node *orig_node, uint8_t new_gwflags)
  276. {
  277. struct hlist_node *node;
  278. struct gw_node *gw_node, *curr_gw;
  279. /**
  280. * Note: We don't need a NULL check here, since curr_gw never gets
  281. * dereferenced. If curr_gw is NULL we also should not exit as we may
  282. * have this gateway in our list (duplication check!) even though we
  283. * have no currently selected gateway.
  284. */
  285. curr_gw = gw_get_selected_gw_node(bat_priv);
  286. rcu_read_lock();
  287. hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) {
  288. if (gw_node->orig_node != orig_node)
  289. continue;
  290. bat_dbg(DBG_BATMAN, bat_priv,
  291. "Gateway class of originator %pM changed from "
  292. "%i to %i\n",
  293. orig_node->orig, gw_node->orig_node->gw_flags,
  294. new_gwflags);
  295. gw_node->deleted = 0;
  296. if (new_gwflags == NO_FLAGS) {
  297. gw_node->deleted = jiffies;
  298. bat_dbg(DBG_BATMAN, bat_priv,
  299. "Gateway %pM removed from gateway list\n",
  300. orig_node->orig);
  301. if (gw_node == curr_gw)
  302. goto deselect;
  303. }
  304. goto unlock;
  305. }
  306. if (new_gwflags == NO_FLAGS)
  307. goto unlock;
  308. gw_node_add(bat_priv, orig_node, new_gwflags);
  309. goto unlock;
  310. deselect:
  311. gw_deselect(bat_priv);
  312. unlock:
  313. rcu_read_unlock();
  314. if (curr_gw)
  315. gw_node_free_ref(curr_gw);
  316. }
  317. void gw_node_delete(struct bat_priv *bat_priv, struct orig_node *orig_node)
  318. {
  319. gw_node_update(bat_priv, orig_node, 0);
  320. }
  321. void gw_node_purge(struct bat_priv *bat_priv)
  322. {
  323. struct gw_node *gw_node, *curr_gw;
  324. struct hlist_node *node, *node_tmp;
  325. unsigned long timeout = 2 * PURGE_TIMEOUT * HZ;
  326. int do_deselect = 0;
  327. curr_gw = gw_get_selected_gw_node(bat_priv);
  328. spin_lock_bh(&bat_priv->gw_list_lock);
  329. hlist_for_each_entry_safe(gw_node, node, node_tmp,
  330. &bat_priv->gw_list, list) {
  331. if (((!gw_node->deleted) ||
  332. (time_before(jiffies, gw_node->deleted + timeout))) &&
  333. atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE)
  334. continue;
  335. if (curr_gw == gw_node)
  336. do_deselect = 1;
  337. hlist_del_rcu(&gw_node->list);
  338. gw_node_free_ref(gw_node);
  339. }
  340. spin_unlock_bh(&bat_priv->gw_list_lock);
  341. /* gw_deselect() needs to acquire the gw_list_lock */
  342. if (do_deselect)
  343. gw_deselect(bat_priv);
  344. if (curr_gw)
  345. gw_node_free_ref(curr_gw);
  346. }
  347. /**
  348. * fails if orig_node has no router
  349. */
  350. static int _write_buffer_text(struct bat_priv *bat_priv, struct seq_file *seq,
  351. const struct gw_node *gw_node)
  352. {
  353. struct gw_node *curr_gw;
  354. struct neigh_node *router;
  355. int down, up, ret = -1;
  356. gw_bandwidth_to_kbit(gw_node->orig_node->gw_flags, &down, &up);
  357. router = orig_node_get_router(gw_node->orig_node);
  358. if (!router)
  359. goto out;
  360. curr_gw = gw_get_selected_gw_node(bat_priv);
  361. ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n",
  362. (curr_gw == gw_node ? "=>" : " "),
  363. gw_node->orig_node->orig,
  364. router->tq_avg, router->addr,
  365. router->if_incoming->net_dev->name,
  366. gw_node->orig_node->gw_flags,
  367. (down > 2048 ? down / 1024 : down),
  368. (down > 2048 ? "MBit" : "KBit"),
  369. (up > 2048 ? up / 1024 : up),
  370. (up > 2048 ? "MBit" : "KBit"));
  371. neigh_node_free_ref(router);
  372. if (curr_gw)
  373. gw_node_free_ref(curr_gw);
  374. out:
  375. return ret;
  376. }
  377. int gw_client_seq_print_text(struct seq_file *seq, void *offset)
  378. {
  379. struct net_device *net_dev = (struct net_device *)seq->private;
  380. struct bat_priv *bat_priv = netdev_priv(net_dev);
  381. struct hard_iface *primary_if;
  382. struct gw_node *gw_node;
  383. struct hlist_node *node;
  384. int gw_count = 0, ret = 0;
  385. primary_if = primary_if_get_selected(bat_priv);
  386. if (!primary_if) {
  387. ret = seq_printf(seq, "BATMAN mesh %s disabled - please "
  388. "specify interfaces to enable it\n",
  389. net_dev->name);
  390. goto out;
  391. }
  392. if (primary_if->if_status != IF_ACTIVE) {
  393. ret = seq_printf(seq, "BATMAN mesh %s disabled - "
  394. "primary interface not active\n",
  395. net_dev->name);
  396. goto out;
  397. }
  398. seq_printf(seq, " %-12s (%s/%i) %17s [%10s]: gw_class ... "
  399. "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
  400. "Gateway", "#", TQ_MAX_VALUE, "Nexthop",
  401. "outgoingIF", SOURCE_VERSION, primary_if->net_dev->name,
  402. primary_if->net_dev->dev_addr, net_dev->name);
  403. rcu_read_lock();
  404. hlist_for_each_entry_rcu(gw_node, node, &bat_priv->gw_list, list) {
  405. if (gw_node->deleted)
  406. continue;
  407. /* fails if orig_node has no router */
  408. if (_write_buffer_text(bat_priv, seq, gw_node) < 0)
  409. continue;
  410. gw_count++;
  411. }
  412. rcu_read_unlock();
  413. if (gw_count == 0)
  414. seq_printf(seq, "No gateways in range ...\n");
  415. out:
  416. if (primary_if)
  417. hardif_free_ref(primary_if);
  418. return ret;
  419. }
  420. static bool is_type_dhcprequest(struct sk_buff *skb, int header_len)
  421. {
  422. int ret = false;
  423. unsigned char *p;
  424. int pkt_len;
  425. if (skb_linearize(skb) < 0)
  426. goto out;
  427. pkt_len = skb_headlen(skb);
  428. if (pkt_len < header_len + DHCP_OPTIONS_OFFSET + 1)
  429. goto out;
  430. p = skb->data + header_len + DHCP_OPTIONS_OFFSET;
  431. pkt_len -= header_len + DHCP_OPTIONS_OFFSET + 1;
  432. /* Access the dhcp option lists. Each entry is made up by:
  433. * - octect 1: option type
  434. * - octect 2: option data len (only if type != 255 and 0)
  435. * - octect 3: option data */
  436. while (*p != 255 && !ret) {
  437. /* p now points to the first octect: option type */
  438. if (*p == 53) {
  439. /* type 53 is the message type option.
  440. * Jump the len octect and go to the data octect */
  441. if (pkt_len < 2)
  442. goto out;
  443. p += 2;
  444. /* check if the message type is what we need */
  445. if (*p == DHCP_REQUEST)
  446. ret = true;
  447. break;
  448. } else if (*p == 0) {
  449. /* option type 0 (padding), just go forward */
  450. if (pkt_len < 1)
  451. goto out;
  452. pkt_len--;
  453. p++;
  454. } else {
  455. /* This is any other option. So we get the length... */
  456. if (pkt_len < 1)
  457. goto out;
  458. pkt_len--;
  459. p++;
  460. /* ...and then we jump over the data */
  461. if (pkt_len < *p)
  462. goto out;
  463. pkt_len -= *p;
  464. p += (*p);
  465. }
  466. }
  467. out:
  468. return ret;
  469. }
  470. int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb,
  471. struct orig_node *old_gw)
  472. {
  473. struct ethhdr *ethhdr;
  474. struct iphdr *iphdr;
  475. struct ipv6hdr *ipv6hdr;
  476. struct udphdr *udphdr;
  477. struct gw_node *curr_gw;
  478. struct neigh_node *neigh_curr = NULL, *neigh_old = NULL;
  479. unsigned int header_len = 0;
  480. int ret = 1;
  481. if (atomic_read(&bat_priv->gw_mode) == GW_MODE_OFF)
  482. return 0;
  483. /* check for ethernet header */
  484. if (!pskb_may_pull(skb, header_len + ETH_HLEN))
  485. return 0;
  486. ethhdr = (struct ethhdr *)skb->data;
  487. header_len += ETH_HLEN;
  488. /* check for initial vlan header */
  489. if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) {
  490. if (!pskb_may_pull(skb, header_len + VLAN_HLEN))
  491. return 0;
  492. ethhdr = (struct ethhdr *)(skb->data + VLAN_HLEN);
  493. header_len += VLAN_HLEN;
  494. }
  495. /* check for ip header */
  496. switch (ntohs(ethhdr->h_proto)) {
  497. case ETH_P_IP:
  498. if (!pskb_may_pull(skb, header_len + sizeof(*iphdr)))
  499. return 0;
  500. iphdr = (struct iphdr *)(skb->data + header_len);
  501. header_len += iphdr->ihl * 4;
  502. /* check for udp header */
  503. if (iphdr->protocol != IPPROTO_UDP)
  504. return 0;
  505. break;
  506. case ETH_P_IPV6:
  507. if (!pskb_may_pull(skb, header_len + sizeof(*ipv6hdr)))
  508. return 0;
  509. ipv6hdr = (struct ipv6hdr *)(skb->data + header_len);
  510. header_len += sizeof(*ipv6hdr);
  511. /* check for udp header */
  512. if (ipv6hdr->nexthdr != IPPROTO_UDP)
  513. return 0;
  514. break;
  515. default:
  516. return 0;
  517. }
  518. if (!pskb_may_pull(skb, header_len + sizeof(*udphdr)))
  519. return 0;
  520. udphdr = (struct udphdr *)(skb->data + header_len);
  521. header_len += sizeof(*udphdr);
  522. /* check for bootp port */
  523. if ((ntohs(ethhdr->h_proto) == ETH_P_IP) &&
  524. (ntohs(udphdr->dest) != 67))
  525. return 0;
  526. if ((ntohs(ethhdr->h_proto) == ETH_P_IPV6) &&
  527. (ntohs(udphdr->dest) != 547))
  528. return 0;
  529. if (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER)
  530. return -1;
  531. curr_gw = gw_get_selected_gw_node(bat_priv);
  532. if (!curr_gw)
  533. return 0;
  534. /* If old_gw != NULL then this packet is unicast.
  535. * So, at this point we have to check the message type: if it is a
  536. * DHCPREQUEST we have to decide whether to drop it or not */
  537. if (old_gw && curr_gw->orig_node != old_gw) {
  538. if (is_type_dhcprequest(skb, header_len)) {
  539. /* If the dhcp packet has been sent to a different gw,
  540. * we have to evaluate whether the old gw is still
  541. * reliable enough */
  542. neigh_curr = find_router(bat_priv, curr_gw->orig_node,
  543. NULL);
  544. neigh_old = find_router(bat_priv, old_gw, NULL);
  545. if (!neigh_curr || !neigh_old)
  546. goto free_neigh;
  547. if (neigh_curr->tq_avg - neigh_old->tq_avg <
  548. GW_THRESHOLD)
  549. ret = -1;
  550. }
  551. }
  552. free_neigh:
  553. if (neigh_old)
  554. neigh_node_free_ref(neigh_old);
  555. if (neigh_curr)
  556. neigh_node_free_ref(neigh_curr);
  557. if (curr_gw)
  558. gw_node_free_ref(curr_gw);
  559. return ret;
  560. }