aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorBob Copeland <me@bobcopeland.com>2016-02-28 20:03:58 -0500
committerJohannes Berg <johannes.berg@intel.com>2016-04-05 04:56:31 -0400
commitb15dc38b9817729d3d4962f8c84bbda0eccb3532 (patch)
tree91d72e34e592d68ac06f77c87086fc2a798d7d4f /net/mac80211
parent443954815b63b36f09623d74170520e6554f5fac (diff)
mac80211: mesh: factor out common mesh path allocation code
Remove duplicate code to allocate and initialize a mesh path or mesh proxy path. Signed-off-by: Bob Copeland <me@bobcopeland.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/mesh_pathtbl.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index fc3cc350df8c..4794240e8f94 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -501,6 +501,31 @@ int mesh_gate_num(struct ieee80211_sub_if_data *sdata)
501 return sdata->u.mesh.num_gates; 501 return sdata->u.mesh.num_gates;
502} 502}
503 503
504static
505struct mesh_path *mesh_path_new(struct ieee80211_sub_if_data *sdata,
506 const u8 *dst, gfp_t gfp_flags)
507{
508 struct mesh_path *new_mpath;
509
510 new_mpath = kzalloc(sizeof(struct mesh_path), gfp_flags);
511 if (!new_mpath)
512 return NULL;
513
514 memcpy(new_mpath->dst, dst, ETH_ALEN);
515 eth_broadcast_addr(new_mpath->rann_snd_addr);
516 new_mpath->is_root = false;
517 new_mpath->sdata = sdata;
518 new_mpath->flags = 0;
519 skb_queue_head_init(&new_mpath->frame_queue);
520 new_mpath->timer.data = (unsigned long) new_mpath;
521 new_mpath->timer.function = mesh_path_timer;
522 new_mpath->exp_time = jiffies;
523 spin_lock_init(&new_mpath->state_lock);
524 init_timer(&new_mpath->timer);
525
526 return new_mpath;
527}
528
504/** 529/**
505 * mesh_path_add - allocate and add a new path to the mesh path table 530 * mesh_path_add - allocate and add a new path to the mesh path table
506 * @dst: destination address of the path (ETH_ALEN length) 531 * @dst: destination address of the path (ETH_ALEN length)
@@ -548,7 +573,7 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
548 } 573 }
549 574
550 err = -ENOMEM; 575 err = -ENOMEM;
551 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC); 576 new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
552 if (!new_mpath) 577 if (!new_mpath)
553 goto err_path_alloc; 578 goto err_path_alloc;
554 579
@@ -556,19 +581,7 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
556 if (!new_node) 581 if (!new_node)
557 goto err_node_alloc; 582 goto err_node_alloc;
558 583
559 memcpy(new_mpath->dst, dst, ETH_ALEN);
560 eth_broadcast_addr(new_mpath->rann_snd_addr);
561 new_mpath->is_root = false;
562 new_mpath->sdata = sdata;
563 new_mpath->flags = 0;
564 skb_queue_head_init(&new_mpath->frame_queue);
565 new_node->mpath = new_mpath; 584 new_node->mpath = new_mpath;
566 new_mpath->timer.data = (unsigned long) new_mpath;
567 new_mpath->timer.function = mesh_path_timer;
568 new_mpath->exp_time = jiffies;
569 spin_lock_init(&new_mpath->state_lock);
570 init_timer(&new_mpath->timer);
571
572 hlist_add_head_rcu(&new_node->list, bucket); 585 hlist_add_head_rcu(&new_node->list, bucket);
573 if (atomic_inc_return(&tbl->entries) >= 586 if (atomic_inc_return(&tbl->entries) >=
574 MEAN_CHAIN_LEN * (tbl->hash_mask + 1)) 587 MEAN_CHAIN_LEN * (tbl->hash_mask + 1))
@@ -664,7 +677,7 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
664 return -ENOTSUPP; 677 return -ENOTSUPP;
665 678
666 err = -ENOMEM; 679 err = -ENOMEM;
667 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC); 680 new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
668 if (!new_mpath) 681 if (!new_mpath)
669 goto err_path_alloc; 682 goto err_path_alloc;
670 683
@@ -672,17 +685,9 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
672 if (!new_node) 685 if (!new_node)
673 goto err_node_alloc; 686 goto err_node_alloc;
674 687
675 read_lock_bh(&sdata->u.mesh.pathtbl_resize_lock);
676 memcpy(new_mpath->dst, dst, ETH_ALEN);
677 memcpy(new_mpath->mpp, mpp, ETH_ALEN); 688 memcpy(new_mpath->mpp, mpp, ETH_ALEN);
678 new_mpath->sdata = sdata;
679 new_mpath->flags = 0;
680 skb_queue_head_init(&new_mpath->frame_queue);
681 new_node->mpath = new_mpath; 689 new_node->mpath = new_mpath;
682 init_timer(&new_mpath->timer); 690 read_lock_bh(&sdata->u.mesh.pathtbl_resize_lock);
683 new_mpath->exp_time = jiffies;
684 spin_lock_init(&new_mpath->state_lock);
685
686 tbl = resize_dereference_mpp_paths(sdata); 691 tbl = resize_dereference_mpp_paths(sdata);
687 692
688 hash_idx = mesh_table_hash(dst, tbl); 693 hash_idx = mesh_table_hash(dst, tbl);