aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2012-03-04 03:56:25 -0500
committerAntonio Quartulli <ordex@autistici.org>2012-05-11 04:08:11 -0400
commitc3e29312c8c27d403f91522711ce9a290c7571c9 (patch)
treea366ebef6e2d65ed5fdbec48e38fc3e630a9e367 /net/batman-adv
parentffa995e036bef734ea40cbbccda574d1df3a8a58 (diff)
batman-adv: register batman ogm receive function during protocol init
The B.A.T.M.A.N. IV OGM receive function still was hard-coded although it is a routing protocol specific function. This patch takes advantage of the dynamic packet handler registration to remove the hard-coded function calls. Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Acked-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Diffstat (limited to 'net/batman-adv')
-rw-r--r--net/batman-adv/bat_iv_ogm.c31
-rw-r--r--net/batman-adv/main.c5
-rw-r--r--net/batman-adv/routing.c22
-rw-r--r--net/batman-adv/routing.h4
-rw-r--r--net/batman-adv/types.h3
5 files changed, 41 insertions, 24 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index cd8f473c1bd0..e0aaf8c87d65 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1155,13 +1155,18 @@ out:
1155 orig_node_free_ref(orig_node); 1155 orig_node_free_ref(orig_node);
1156} 1156}
1157 1157
1158static void bat_iv_ogm_receive(struct hard_iface *if_incoming, 1158static int bat_iv_ogm_receive(struct sk_buff *skb,
1159 struct sk_buff *skb) 1159 struct hard_iface *if_incoming)
1160{ 1160{
1161 struct batman_ogm_packet *batman_ogm_packet; 1161 struct batman_ogm_packet *batman_ogm_packet;
1162 struct ethhdr *ethhdr; 1162 struct ethhdr *ethhdr;
1163 int buff_pos = 0, packet_len; 1163 int buff_pos = 0, packet_len;
1164 unsigned char *tt_buff, *packet_buff; 1164 unsigned char *tt_buff, *packet_buff;
1165 bool ret;
1166
1167 ret = check_management_packet(skb, if_incoming, BATMAN_OGM_HLEN);
1168 if (!ret)
1169 return NET_RX_DROP;
1165 1170
1166 packet_len = skb_headlen(skb); 1171 packet_len = skb_headlen(skb);
1167 ethhdr = (struct ethhdr *)skb_mac_header(skb); 1172 ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -1187,6 +1192,9 @@ static void bat_iv_ogm_receive(struct hard_iface *if_incoming,
1187 (packet_buff + buff_pos); 1192 (packet_buff + buff_pos);
1188 } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len, 1193 } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len,
1189 batman_ogm_packet->tt_num_changes)); 1194 batman_ogm_packet->tt_num_changes));
1195
1196 kfree_skb(skb);
1197 return NET_RX_SUCCESS;
1190} 1198}
1191 1199
1192static struct bat_algo_ops batman_iv __read_mostly = { 1200static struct bat_algo_ops batman_iv __read_mostly = {
@@ -1197,10 +1205,25 @@ static struct bat_algo_ops batman_iv __read_mostly = {
1197 .bat_ogm_update_mac = bat_iv_ogm_update_mac, 1205 .bat_ogm_update_mac = bat_iv_ogm_update_mac,
1198 .bat_ogm_schedule = bat_iv_ogm_schedule, 1206 .bat_ogm_schedule = bat_iv_ogm_schedule,
1199 .bat_ogm_emit = bat_iv_ogm_emit, 1207 .bat_ogm_emit = bat_iv_ogm_emit,
1200 .bat_ogm_receive = bat_iv_ogm_receive,
1201}; 1208};
1202 1209
1203int __init bat_iv_init(void) 1210int __init bat_iv_init(void)
1204{ 1211{
1205 return bat_algo_register(&batman_iv); 1212 int ret;
1213
1214 /* batman originator packet */
1215 ret = recv_handler_register(BAT_IV_OGM, bat_iv_ogm_receive);
1216 if (ret < 0)
1217 goto out;
1218
1219 ret = bat_algo_register(&batman_iv);
1220 if (ret < 0)
1221 goto handler_unregister;
1222
1223 goto out;
1224
1225handler_unregister:
1226 recv_handler_unregister(BAT_IV_OGM);
1227out:
1228 return ret;
1206} 1229}
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index d19b93575d56..f80c4474127c 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -266,8 +266,6 @@ static void recv_handler_init(void)
266 for (i = 0; i < ARRAY_SIZE(recv_packet_handler); i++) 266 for (i = 0; i < ARRAY_SIZE(recv_packet_handler); i++)
267 recv_packet_handler[i] = recv_unhandled_packet; 267 recv_packet_handler[i] = recv_unhandled_packet;
268 268
269 /* batman originator packet */
270 recv_packet_handler[BAT_IV_OGM] = recv_bat_ogm_packet;
271 /* batman icmp packet */ 269 /* batman icmp packet */
272 recv_packet_handler[BAT_ICMP] = recv_icmp_packet; 270 recv_packet_handler[BAT_ICMP] = recv_icmp_packet;
273 /* unicast packet */ 271 /* unicast packet */
@@ -334,8 +332,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
334 !bat_algo_ops->bat_primary_iface_set || 332 !bat_algo_ops->bat_primary_iface_set ||
335 !bat_algo_ops->bat_ogm_update_mac || 333 !bat_algo_ops->bat_ogm_update_mac ||
336 !bat_algo_ops->bat_ogm_schedule || 334 !bat_algo_ops->bat_ogm_schedule ||
337 !bat_algo_ops->bat_ogm_emit || 335 !bat_algo_ops->bat_ogm_emit) {
338 !bat_algo_ops->bat_ogm_receive) {
339 pr_info("Routing algo '%s' does not implement required ops\n", 336 pr_info("Routing algo '%s' does not implement required ops\n",
340 bat_algo_ops->name); 337 bat_algo_ops->name);
341 goto out; 338 goto out;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index ff560863bc74..7ed9d8f92916 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -248,37 +248,35 @@ int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff,
248 return 0; 248 return 0;
249} 249}
250 250
251int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) 251bool check_management_packet(struct sk_buff *skb,
252 struct hard_iface *hard_iface,
253 int header_len)
252{ 254{
253 struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
254 struct ethhdr *ethhdr; 255 struct ethhdr *ethhdr;
255 256
256 /* drop packet if it has not necessary minimum size */ 257 /* drop packet if it has not necessary minimum size */
257 if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_HLEN))) 258 if (unlikely(!pskb_may_pull(skb, header_len)))
258 return NET_RX_DROP; 259 return false;
259 260
260 ethhdr = (struct ethhdr *)skb_mac_header(skb); 261 ethhdr = (struct ethhdr *)skb_mac_header(skb);
261 262
262 /* packet with broadcast indication but unicast recipient */ 263 /* packet with broadcast indication but unicast recipient */
263 if (!is_broadcast_ether_addr(ethhdr->h_dest)) 264 if (!is_broadcast_ether_addr(ethhdr->h_dest))
264 return NET_RX_DROP; 265 return false;
265 266
266 /* packet with broadcast sender address */ 267 /* packet with broadcast sender address */
267 if (is_broadcast_ether_addr(ethhdr->h_source)) 268 if (is_broadcast_ether_addr(ethhdr->h_source))
268 return NET_RX_DROP; 269 return false;
269 270
270 /* create a copy of the skb, if needed, to modify it. */ 271 /* create a copy of the skb, if needed, to modify it. */
271 if (skb_cow(skb, 0) < 0) 272 if (skb_cow(skb, 0) < 0)
272 return NET_RX_DROP; 273 return false;
273 274
274 /* keep skb linear */ 275 /* keep skb linear */
275 if (skb_linearize(skb) < 0) 276 if (skb_linearize(skb) < 0)
276 return NET_RX_DROP; 277 return false;
277
278 bat_priv->bat_algo_ops->bat_ogm_receive(hard_iface, skb);
279 278
280 kfree_skb(skb); 279 return true;
281 return NET_RX_SUCCESS;
282} 280}
283 281
284static int recv_my_icmp_packet(struct bat_priv *bat_priv, 282static int recv_my_icmp_packet(struct bat_priv *bat_priv,
diff --git a/net/batman-adv/routing.h b/net/batman-adv/routing.h
index 3d729cb17113..d6bbbebb6567 100644
--- a/net/batman-adv/routing.h
+++ b/net/batman-adv/routing.h
@@ -23,6 +23,9 @@
23#define _NET_BATMAN_ADV_ROUTING_H_ 23#define _NET_BATMAN_ADV_ROUTING_H_
24 24
25void slide_own_bcast_window(struct hard_iface *hard_iface); 25void slide_own_bcast_window(struct hard_iface *hard_iface);
26bool check_management_packet(struct sk_buff *skb,
27 struct hard_iface *hard_iface,
28 int header_len);
26void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node, 29void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node,
27 struct neigh_node *neigh_node); 30 struct neigh_node *neigh_node);
28int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if); 31int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if);
@@ -30,7 +33,6 @@ int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
30int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if); 33int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if);
31int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if); 34int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
32int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if); 35int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if);
33int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *recv_if);
34int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if); 36int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if);
35int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if); 37int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if);
36struct neigh_node *find_router(struct bat_priv *bat_priv, 38struct neigh_node *find_router(struct bat_priv *bat_priv,
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 2f4848b776a7..50e1895a25c3 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -390,9 +390,6 @@ struct bat_algo_ops {
390 int tt_num_changes); 390 int tt_num_changes);
391 /* send scheduled OGM */ 391 /* send scheduled OGM */
392 void (*bat_ogm_emit)(struct forw_packet *forw_packet); 392 void (*bat_ogm_emit)(struct forw_packet *forw_packet);
393 /* receive incoming OGM */
394 void (*bat_ogm_receive)(struct hard_iface *if_incoming,
395 struct sk_buff *skb);
396}; 393};
397 394
398#endif /* _NET_BATMAN_ADV_TYPES_H_ */ 395#endif /* _NET_BATMAN_ADV_TYPES_H_ */