aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/routing.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2011-01-19 15:01:42 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 06:49:59 -0500
commit16b1aba849eeb45d51a5de731cf103143439ffe1 (patch)
tree2bbda8638bd925014e8d6025d704cb2860d28606 /net/batman-adv/routing.c
parentfb778ea173fcd58b8fc3d75c674f07fab187b55f (diff)
batman-adv: protect originator nodes with reference counters
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/routing.c')
-rw-r--r--net/batman-adv/routing.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 32ae04e26a05..1c31a0e9f90a 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -311,6 +311,8 @@ static void update_orig(struct bat_priv *bat_priv,
311 311
312 neigh_node = create_neighbor(orig_node, orig_tmp, 312 neigh_node = create_neighbor(orig_node, orig_tmp,
313 ethhdr->h_source, if_incoming); 313 ethhdr->h_source, if_incoming);
314
315 kref_put(&orig_tmp->refcount, orig_node_free_ref);
314 if (!neigh_node) 316 if (!neigh_node)
315 goto unlock; 317 goto unlock;
316 } else 318 } else
@@ -438,7 +440,7 @@ static char count_real_packets(struct ethhdr *ethhdr,
438 /* signalize caller that the packet is to be dropped. */ 440 /* signalize caller that the packet is to be dropped. */
439 if (window_protected(bat_priv, seq_diff, 441 if (window_protected(bat_priv, seq_diff,
440 &orig_node->batman_seqno_reset)) 442 &orig_node->batman_seqno_reset))
441 return -1; 443 goto err;
442 444
443 rcu_read_lock(); 445 rcu_read_lock();
444 hlist_for_each_entry_rcu(tmp_neigh_node, node, 446 hlist_for_each_entry_rcu(tmp_neigh_node, node,
@@ -471,7 +473,12 @@ static char count_real_packets(struct ethhdr *ethhdr,
471 orig_node->last_real_seqno = batman_packet->seqno; 473 orig_node->last_real_seqno = batman_packet->seqno;
472 } 474 }
473 475
476 kref_put(&orig_node->refcount, orig_node_free_ref);
474 return is_duplicate; 477 return is_duplicate;
478
479err:
480 kref_put(&orig_node->refcount, orig_node_free_ref);
481 return -1;
475} 482}
476 483
477/* copy primary address for bonding */ 484/* copy primary address for bonding */
@@ -686,7 +693,6 @@ void receive_bat_packet(struct ethhdr *ethhdr,
686 int offset; 693 int offset;
687 694
688 orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source); 695 orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source);
689
690 if (!orig_neigh_node) 696 if (!orig_neigh_node)
691 return; 697 return;
692 698
@@ -707,6 +713,7 @@ void receive_bat_packet(struct ethhdr *ethhdr,
707 713
708 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: " 714 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
709 "originator packet from myself (via neighbor)\n"); 715 "originator packet from myself (via neighbor)\n");
716 kref_put(&orig_neigh_node->refcount, orig_node_free_ref);
710 return; 717 return;
711 } 718 }
712 719
@@ -727,13 +734,13 @@ void receive_bat_packet(struct ethhdr *ethhdr,
727 bat_dbg(DBG_BATMAN, bat_priv, 734 bat_dbg(DBG_BATMAN, bat_priv,
728 "Drop packet: packet within seqno protection time " 735 "Drop packet: packet within seqno protection time "
729 "(sender: %pM)\n", ethhdr->h_source); 736 "(sender: %pM)\n", ethhdr->h_source);
730 return; 737 goto out;
731 } 738 }
732 739
733 if (batman_packet->tq == 0) { 740 if (batman_packet->tq == 0) {
734 bat_dbg(DBG_BATMAN, bat_priv, 741 bat_dbg(DBG_BATMAN, bat_priv,
735 "Drop packet: originator packet with tq equal 0\n"); 742 "Drop packet: originator packet with tq equal 0\n");
736 return; 743 goto out;
737 } 744 }
738 745
739 /* avoid temporary routing loops */ 746 /* avoid temporary routing loops */
@@ -747,7 +754,7 @@ void receive_bat_packet(struct ethhdr *ethhdr,
747 bat_dbg(DBG_BATMAN, bat_priv, 754 bat_dbg(DBG_BATMAN, bat_priv,
748 "Drop packet: ignoring all rebroadcast packets that " 755 "Drop packet: ignoring all rebroadcast packets that "
749 "may make me loop (sender: %pM)\n", ethhdr->h_source); 756 "may make me loop (sender: %pM)\n", ethhdr->h_source);
750 return; 757 goto out;
751 } 758 }
752 759
753 /* if sender is a direct neighbor the sender mac equals 760 /* if sender is a direct neighbor the sender mac equals
@@ -756,14 +763,14 @@ void receive_bat_packet(struct ethhdr *ethhdr,
756 orig_node : 763 orig_node :
757 get_orig_node(bat_priv, ethhdr->h_source)); 764 get_orig_node(bat_priv, ethhdr->h_source));
758 if (!orig_neigh_node) 765 if (!orig_neigh_node)
759 return; 766 goto out_neigh;
760 767
761 /* drop packet if sender is not a direct neighbor and if we 768 /* drop packet if sender is not a direct neighbor and if we
762 * don't route towards it */ 769 * don't route towards it */
763 if (!is_single_hop_neigh && (!orig_neigh_node->router)) { 770 if (!is_single_hop_neigh && (!orig_neigh_node->router)) {
764 bat_dbg(DBG_BATMAN, bat_priv, 771 bat_dbg(DBG_BATMAN, bat_priv,
765 "Drop packet: OGM via unknown neighbor!\n"); 772 "Drop packet: OGM via unknown neighbor!\n");
766 return; 773 goto out_neigh;
767 } 774 }
768 775
769 is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node, 776 is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node,
@@ -790,26 +797,32 @@ void receive_bat_packet(struct ethhdr *ethhdr,
790 797
791 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: " 798 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
792 "rebroadcast neighbor packet with direct link flag\n"); 799 "rebroadcast neighbor packet with direct link flag\n");
793 return; 800 goto out_neigh;
794 } 801 }
795 802
796 /* multihop originator */ 803 /* multihop originator */
797 if (!is_bidirectional) { 804 if (!is_bidirectional) {
798 bat_dbg(DBG_BATMAN, bat_priv, 805 bat_dbg(DBG_BATMAN, bat_priv,
799 "Drop packet: not received via bidirectional link\n"); 806 "Drop packet: not received via bidirectional link\n");
800 return; 807 goto out_neigh;
801 } 808 }
802 809
803 if (is_duplicate) { 810 if (is_duplicate) {
804 bat_dbg(DBG_BATMAN, bat_priv, 811 bat_dbg(DBG_BATMAN, bat_priv,
805 "Drop packet: duplicate packet received\n"); 812 "Drop packet: duplicate packet received\n");
806 return; 813 goto out_neigh;
807 } 814 }
808 815
809 bat_dbg(DBG_BATMAN, bat_priv, 816 bat_dbg(DBG_BATMAN, bat_priv,
810 "Forwarding packet: rebroadcast originator packet\n"); 817 "Forwarding packet: rebroadcast originator packet\n");
811 schedule_forward_packet(orig_node, ethhdr, batman_packet, 818 schedule_forward_packet(orig_node, ethhdr, batman_packet,
812 0, hna_buff_len, if_incoming); 819 0, hna_buff_len, if_incoming);
820
821out_neigh:
822 if (!is_single_hop_neigh)
823 kref_put(&orig_neigh_node->refcount, orig_node_free_ref);
824out:
825 kref_put(&orig_node->refcount, orig_node_free_ref);
813} 826}
814 827
815int recv_bat_packet(struct sk_buff *skb, struct batman_if *batman_if) 828int recv_bat_packet(struct sk_buff *skb, struct batman_if *batman_if)