batman-adv: Add bugfixes for 2017.0.1
[feed/routing.git] / batman-adv / patches / 0003-batman-adv-Initialize-gw-sel_class-via-batadv_algo.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Sat, 4 Mar 2017 15:48:50 +0100
3 Subject: [PATCH] batman-adv: Initialize gw sel_class via batadv_algo
4
5 The gateway selection class variable is shared between different algorithm
6 versions. But the interpretation of the content is algorithm specific. The
7 initialization is therefore also algorithm specific.
8
9 But this was implemented incorrectly and the initialization for BATMAN_V
10 always overwrote the value previously written for BATMAN_IV. This could
11 only be avoided when BATMAN_V was disabled during compile time.
12
13 Using a special batadv_algo hook for this initialization avoids this
14 problem.
15
16 Fixes: 80b2d47be2c7 ("batman-adv: B.A.T.M.A.N. V - implement GW selection logic")
17 Signed-off-by: Sven Eckelmann <sven@narfation.org>
18 ---
19 net/batman-adv/bat_iv_ogm.c | 11 +++++++++++
20 net/batman-adv/bat_v.c | 14 +++++++++++---
21 net/batman-adv/gateway_common.c | 5 +++++
22 net/batman-adv/soft-interface.c | 1 -
23 net/batman-adv/types.h | 2 ++
24 5 files changed, 29 insertions(+), 4 deletions(-)
25
26 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
27 index 7c3d994e..71343d0f 100644
28 --- a/net/batman-adv/bat_iv_ogm.c
29 +++ b/net/batman-adv/bat_iv_ogm.c
30 @@ -2477,6 +2477,16 @@ static void batadv_iv_iface_activate(struct batadv_hard_iface *hard_iface)
31 batadv_iv_ogm_schedule(hard_iface);
32 }
33
34 +/**
35 + * batadv_iv_init_sel_class - initialize GW selection class
36 + * @bat_priv: the bat priv with all the soft interface information
37 + */
38 +static void batadv_iv_init_sel_class(struct batadv_priv *bat_priv)
39 +{
40 + /* set default TQ difference threshold to 20 */
41 + atomic_set(&bat_priv->gw.sel_class, 20);
42 +}
43 +
44 static struct batadv_gw_node *
45 batadv_iv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
46 {
47 @@ -2823,6 +2833,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
48 .del_if = batadv_iv_ogm_orig_del_if,
49 },
50 .gw = {
51 + .init_sel_class = batadv_iv_init_sel_class,
52 .get_best_gw_node = batadv_iv_gw_get_best_gw_node,
53 .is_eligible = batadv_iv_gw_is_eligible,
54 #ifdef CONFIG_BATMAN_ADV_DEBUGFS
55 diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
56 index 0acd081d..a36c8e72 100644
57 --- a/net/batman-adv/bat_v.c
58 +++ b/net/batman-adv/bat_v.c
59 @@ -668,6 +668,16 @@ static bool batadv_v_neigh_is_sob(struct batadv_neigh_node *neigh1,
60 return ret;
61 }
62
63 +/**
64 + * batadv_v_init_sel_class - initialize GW selection class
65 + * @bat_priv: the bat priv with all the soft interface information
66 + */
67 +static void batadv_v_init_sel_class(struct batadv_priv *bat_priv)
68 +{
69 + /* set default throughput difference threshold to 5Mbps */
70 + atomic_set(&bat_priv->gw.sel_class, 50);
71 +}
72 +
73 static ssize_t batadv_v_store_sel_class(struct batadv_priv *bat_priv,
74 char *buff, size_t count)
75 {
76 @@ -1052,6 +1062,7 @@ static struct batadv_algo_ops batadv_batman_v __read_mostly = {
77 .dump = batadv_v_orig_dump,
78 },
79 .gw = {
80 + .init_sel_class = batadv_v_init_sel_class,
81 .store_sel_class = batadv_v_store_sel_class,
82 .show_sel_class = batadv_v_show_sel_class,
83 .get_best_gw_node = batadv_v_gw_get_best_gw_node,
84 @@ -1092,9 +1103,6 @@ int batadv_v_mesh_init(struct batadv_priv *bat_priv)
85 if (ret < 0)
86 return ret;
87
88 - /* set default throughput difference threshold to 5Mbps */
89 - atomic_set(&bat_priv->gw.sel_class, 50);
90 -
91 return 0;
92 }
93
94 diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
95 index 5db2e43e..33940c5c 100644
96 --- a/net/batman-adv/gateway_common.c
97 +++ b/net/batman-adv/gateway_common.c
98 @@ -253,6 +253,11 @@ static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
99 */
100 void batadv_gw_init(struct batadv_priv *bat_priv)
101 {
102 + if (bat_priv->algo_ops->gw.init_sel_class)
103 + bat_priv->algo_ops->gw.init_sel_class(bat_priv);
104 + else
105 + atomic_set(&bat_priv->gw.sel_class, 1);
106 +
107 batadv_tvlv_handler_register(bat_priv, batadv_gw_tvlv_ogm_handler_v1,
108 NULL, BATADV_TVLV_GW, 1,
109 BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
110 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
111 index 5d099b2e..d042c99a 100644
112 --- a/net/batman-adv/soft-interface.c
113 +++ b/net/batman-adv/soft-interface.c
114 @@ -819,7 +819,6 @@ static int batadv_softif_init_late(struct net_device *dev)
115 atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
116 #endif
117 atomic_set(&bat_priv->gw.mode, BATADV_GW_MODE_OFF);
118 - atomic_set(&bat_priv->gw.sel_class, 20);
119 atomic_set(&bat_priv->gw.bandwidth_down, 100);
120 atomic_set(&bat_priv->gw.bandwidth_up, 20);
121 atomic_set(&bat_priv->orig_interval, 1000);
122 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
123 index 66b25e41..246f21b4 100644
124 --- a/net/batman-adv/types.h
125 +++ b/net/batman-adv/types.h
126 @@ -1489,6 +1489,7 @@ struct batadv_algo_orig_ops {
127
128 /**
129 * struct batadv_algo_gw_ops - mesh algorithm callbacks (GW specific)
130 + * @init_sel_class: initialize GW selection class (optional)
131 * @store_sel_class: parse and stores a new GW selection class (optional)
132 * @show_sel_class: prints the current GW selection class (optional)
133 * @get_best_gw_node: select the best GW from the list of available nodes
134 @@ -1499,6 +1500,7 @@ struct batadv_algo_orig_ops {
135 * @dump: dump gateways to a netlink socket (optional)
136 */
137 struct batadv_algo_gw_ops {
138 + void (*init_sel_class)(struct batadv_priv *bat_priv);
139 ssize_t (*store_sel_class)(struct batadv_priv *bat_priv, char *buff,
140 size_t count);
141 ssize_t (*show_sel_class)(struct batadv_priv *bat_priv, char *buff);