From patchwork Sun Mar 4 08:56:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1557 Return-Path: Received: from nm22-vm7.bullet.mail.ukl.yahoo.com (nm22-vm7.bullet.mail.ukl.yahoo.com [217.12.10.73]) by open-mesh.org (Postfix) with SMTP id EDCA46007A8 for ; Sun, 4 Mar 2012 09:56:51 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.183] by nm22.bullet.mail.ukl.yahoo.com with NNFMP; 04 Mar 2012 08:56:51 -0000 Received: from [77.238.184.61] by tm14.bullet.mail.ukl.yahoo.com with NNFMP; 04 Mar 2012 08:56:51 -0000 Received: from [127.0.0.1] by smtp130.mail.ukl.yahoo.com with NNFMP; 04 Mar 2012 08:56:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1330851411; bh=BecE4DdzsmmbVudNtPOlc+9+2FoAvhc3OKH2nhdgzlE=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=l57mVLwnxTQNXeZqZmRa1AXlVOUsaLjolexKy7heCPvGoPpN5Rr3Vk11Y2N6J8YRLJgHeAHD2L1WknjZGmlBp6owDrR4gHSXvG/6QNuPCoBMd3Pi6CUJhfMx0DTnm1lcJcJZriI2Uqr1PvCZMfIKIoFoYP3Ipt41PnJdTh0cKns= X-Yahoo-Newman-Id: 271910.32519.bm@smtp130.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: H6Bt1eMVM1nyA3Ruo.Y2n7lv.REGd1G0dO53wf_syelG8vI Tsp8TAkg6sw7lIGjY34Hpx3LKQmvapS.3Rl_l_LBy.ebfSFe6zNK51fH3EJd likKVUSQ2yPItIq5uT4f_Fx4sRCYPnTuDfCCJHfESjLTyQZEU3O4izZczTOX 0zjUrUQD9Sj.9oZRHhlbY72.2nC4WJw.qGeGDFdMqXlVEAjVhVUgNsqXDZlC hkpeltJOtSgwYMNNaRQzhsNHys_zw_boTxHv_1khPhiuca_2NkYWD7pU7ytd AypDHxkEnEMWGnjWasyVfrpHHBTLR79ymcsy2NLqsb3QHKGbAzpNUawk_.QI y4Qaksi2BZRRAcYDx03dLVrnyt1VyHBSctIeg31L6rtTkPAcf7MHndXpBczI XtPVu X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@119.236.110.45 with plain) by smtp130.mail.ukl.yahoo.com with SMTP; 04 Mar 2012 08:56:48 +0000 GMT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 4 Mar 2012 16:56:25 +0800 Message-Id: <1330851385-3457-1-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1330587321-12177-3-git-send-email-lindner_marek@yahoo.de> References: <1330587321-12177-3-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCHv2 3/6] batman-adv: register batman ogm receive function during protocol init X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Mar 2012 08:56:52 -0000 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 Acked-by: Simon Wunderlich --- bat_iv_ogm.c | 31 +++++++++++++++++++++++++++---- main.c | 5 +---- routing.c | 22 ++++++++++------------ routing.h | 4 +++- types.h | 3 --- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c index aba0204..784fcef 100644 --- a/bat_iv_ogm.c +++ b/bat_iv_ogm.c @@ -1166,13 +1166,18 @@ out: orig_node_free_ref(orig_node); } -static void bat_iv_ogm_receive(struct hard_iface *if_incoming, - struct sk_buff *skb) +static int bat_iv_ogm_receive(struct sk_buff *skb, + struct hard_iface *if_incoming) { struct batman_ogm_packet *batman_ogm_packet; struct ethhdr *ethhdr; int buff_pos = 0, packet_len; unsigned char *tt_buff, *packet_buff; + bool ret; + + ret = check_management_packet(skb, if_incoming, BATMAN_OGM_HLEN); + if (!ret) + return NET_RX_DROP; packet_len = skb_headlen(skb); ethhdr = (struct ethhdr *)skb_mac_header(skb); @@ -1198,6 +1203,9 @@ static void bat_iv_ogm_receive(struct hard_iface *if_incoming, (packet_buff + buff_pos); } while (bat_iv_ogm_aggr_packet(buff_pos, packet_len, batman_ogm_packet->tt_num_changes)); + + kfree_skb(skb); + return NET_RX_SUCCESS; } static struct bat_algo_ops batman_iv __read_mostly = { @@ -1208,10 +1216,25 @@ static struct bat_algo_ops batman_iv __read_mostly = { .bat_ogm_update_mac = bat_iv_ogm_update_mac, .bat_ogm_schedule = bat_iv_ogm_schedule, .bat_ogm_emit = bat_iv_ogm_emit, - .bat_ogm_receive = bat_iv_ogm_receive, }; int __init bat_iv_init(void) { - return bat_algo_register(&batman_iv); + int ret; + + /* batman originator packet */ + ret = recv_handler_register(BAT_IV_OGM, bat_iv_ogm_receive); + if (ret < 0) + goto out; + + ret = bat_algo_register(&batman_iv); + if (ret < 0) + goto handler_unregister; + + goto out; + +handler_unregister: + recv_handler_unregister(BAT_IV_OGM); +out: + return ret; } diff --git a/main.c b/main.c index 0d0cd48..8c3ff21 100644 --- a/main.c +++ b/main.c @@ -263,8 +263,6 @@ static void recv_handler_init(void) for (i = 0; i < ARRAY_SIZE(recv_packet_handler); i++) recv_packet_handler[i] = recv_unhandled_packet; - /* batman originator packet */ - recv_packet_handler[BAT_IV_OGM] = recv_bat_ogm_packet; /* batman icmp packet */ recv_packet_handler[BAT_ICMP] = recv_icmp_packet; /* unicast packet */ @@ -331,8 +329,7 @@ int bat_algo_register(struct bat_algo_ops *bat_algo_ops) !bat_algo_ops->bat_primary_iface_set || !bat_algo_ops->bat_ogm_update_mac || !bat_algo_ops->bat_ogm_schedule || - !bat_algo_ops->bat_ogm_emit || - !bat_algo_ops->bat_ogm_receive) { + !bat_algo_ops->bat_ogm_emit) { pr_info("Routing algo '%s' does not implement required ops\n", bat_algo_ops->name); goto out; diff --git a/routing.c b/routing.c index 0da9f5a..d83502a 100644 --- a/routing.c +++ b/routing.c @@ -248,37 +248,35 @@ int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff, return 0; } -int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) +bool check_management_packet(struct sk_buff *skb, + struct hard_iface *hard_iface, + int header_len) { - struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); struct ethhdr *ethhdr; /* drop packet if it has not necessary minimum size */ - if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_HLEN))) - return NET_RX_DROP; + if (unlikely(!pskb_may_pull(skb, header_len))) + return false; ethhdr = (struct ethhdr *)skb_mac_header(skb); /* packet with broadcast indication but unicast recipient */ if (!is_broadcast_ether_addr(ethhdr->h_dest)) - return NET_RX_DROP; + return false; /* packet with broadcast sender address */ if (is_broadcast_ether_addr(ethhdr->h_source)) - return NET_RX_DROP; + return false; /* create a copy of the skb, if needed, to modify it. */ if (skb_cow(skb, 0) < 0) - return NET_RX_DROP; + return false; /* keep skb linear */ if (skb_linearize(skb) < 0) - return NET_RX_DROP; - - bat_priv->bat_algo_ops->bat_ogm_receive(hard_iface, skb); + return false; - kfree_skb(skb); - return NET_RX_SUCCESS; + return true; } static int recv_my_icmp_packet(struct bat_priv *bat_priv, diff --git a/routing.h b/routing.h index 3d729cb..d6bbbeb 100644 --- a/routing.h +++ b/routing.h @@ -23,6 +23,9 @@ #define _NET_BATMAN_ADV_ROUTING_H_ void slide_own_bcast_window(struct hard_iface *hard_iface); +bool check_management_packet(struct sk_buff *skb, + struct hard_iface *hard_iface, + int header_len); void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node, struct neigh_node *neigh_node); int 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); int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if); int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if); int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if); -int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *recv_if); int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if); int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if); struct neigh_node *find_router(struct bat_priv *bat_priv, diff --git a/types.h b/types.h index 6a3cc88..51c59c2 100644 --- a/types.h +++ b/types.h @@ -408,9 +408,6 @@ struct bat_algo_ops { int tt_num_changes); /* send scheduled OGM */ void (*bat_ogm_emit)(struct forw_packet *forw_packet); - /* receive incoming OGM */ - void (*bat_ogm_receive)(struct hard_iface *if_incoming, - struct sk_buff *skb); }; struct dht_candidate {