[commits] r1755 - trunk/batman-adv

postmaster at open-mesh.org postmaster at open-mesh.org
Sun Aug 1 20:31:56 CEST 2010


Author: marek
Date: 2010-08-01 20:31:29 +0200 (Sun, 01 Aug 2010)
New Revision: 1755

Modified:
   trunk/batman-adv/hard-interface.c
   trunk/batman-adv/main.c
   trunk/batman-adv/types.h
Log:
batman-adv: register the batman-adv packet type per interface

Batman-adv globally registered the batman-adv packet type and installed
a hook to batman_skb_recv(). Each interface receiving a packet with
that type would end up in this function which then had to loop through
all batman-adv internal interface structures to find the its meta data.
The more interfaces a system had the longer the loops might take. Each
and every packet goes through this function making it a performance
critical loop.
This patch installs the hook for each activated interface. The called
batman_skb_recv() can distinguish these calls, therefore avoiding the
loop through the interface structures.

Signed-off-by: Marek Lindner <lindner_marek at yahoo.de>

Modified: trunk/batman-adv/hard-interface.c
===================================================================
--- trunk/batman-adv/hard-interface.c	2010-08-01 15:22:38 UTC (rev 1754)
+++ trunk/batman-adv/hard-interface.c	2010-08-01 18:31:29 UTC (rev 1755)
@@ -269,6 +269,11 @@
 	batman_if->if_status = IF_INACTIVE;
 	orig_hash_add_if(batman_if, bat_priv->num_ifaces);
 
+	batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
+	batman_if->batman_adv_ptype.func = batman_skb_recv;
+	batman_if->batman_adv_ptype.dev = batman_if->net_dev;
+	dev_add_pack(&batman_if->batman_adv_ptype);
+
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
 	bat_info(soft_device, "Adding interface: %s\n", batman_if->dev);
@@ -323,6 +328,8 @@
 		return;
 
 	bat_info(soft_device, "Removing interface: %s\n", batman_if->dev);
+	dev_remove_pack(&batman_if->batman_adv_ptype);
+
 	bat_priv->num_ifaces--;
 	orig_hash_del_if(batman_if, bat_priv->num_ifaces);
 
@@ -473,6 +480,7 @@
 	struct batman_if *batman_if;
 	int ret;
 
+	batman_if = container_of(ptype, struct batman_if, batman_adv_ptype);
 	skb = skb_share_check(skb, GFP_ATOMIC);
 
 	/* skb was released by skb_share_check() */
@@ -498,10 +506,6 @@
 				|| !skb_mac_header(skb)))
 		goto err_free;
 
-	batman_if = get_batman_if_by_netdev(skb->dev);
-	if (!batman_if)
-		goto err_free;
-
 	/* discard frames on not active interfaces */
 	if (batman_if->if_status != IF_ACTIVE)
 		goto err_free;

Modified: trunk/batman-adv/main.c
===================================================================
--- trunk/batman-adv/main.c	2010-08-01 15:22:38 UTC (rev 1754)
+++ trunk/batman-adv/main.c	2010-08-01 18:31:29 UTC (rev 1755)
@@ -51,11 +51,6 @@
 unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 atomic_t module_state;
 
-static struct packet_type batman_adv_packet_type __read_mostly = {
-	.type = __constant_htons(ETH_P_BATMAN),
-	.func = batman_skb_recv,
-};
-
 struct workqueue_struct *bat_event_workqueue;
 
 static int __init batman_init(void)
@@ -105,7 +100,6 @@
 		goto unreg_sysfs;
 
 	register_netdevice_notifier(&hard_if_notifier);
-	dev_add_pack(&batman_adv_packet_type);
 
 	pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
 		"loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
@@ -142,8 +136,6 @@
 		soft_device = NULL;
 	}
 
-	dev_remove_pack(&batman_adv_packet_type);
-
 	destroy_workqueue(bat_event_workqueue);
 	bat_event_workqueue = NULL;
 }
@@ -187,8 +179,6 @@
 
 	vis_quit();
 
-	/* TODO: unregister BATMAN pack */
-
 	gw_node_list_free();
 	originator_free();
 

Modified: trunk/batman-adv/types.h
===================================================================
--- trunk/batman-adv/types.h	2010-08-01 15:22:38 UTC (rev 1754)
+++ trunk/batman-adv/types.h	2010-08-01 18:31:29 UTC (rev 1755)
@@ -46,6 +46,7 @@
 	int packet_len;
 	struct kobject *hardif_obj;
 	struct rcu_head rcu;
+	struct packet_type batman_adv_ptype;
 };
 
 /**



More information about the commits mailing list