tipc: let neighbor discoverer tranmsit consumable buffers
authorJon Paul Maloy <jon.maloy@ericsson.com>
Thu, 22 Oct 2015 12:51:44 +0000 (08:51 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sat, 24 Oct 2015 13:56:44 +0000 (06:56 -0700)
The neighbor discovery function currently uses the function
tipc_bearer_send() for transmitting packets, assuming that the
sent buffers are not consumed by the called function.

We want to change this, in order to avoid unnecessary buffer cloning
elswhere in the code.

This commit introduces a new function tipc_bearer_skb() which consumes
the sent buffers, and let the discoverer functions use this new call
instead. The discoverer does now itself perform the cloning when
that is necessary.

Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tipc/bearer.c
net/tipc/bearer.h
net/tipc/discover.c
net/tipc/link.c

index b39f631fd6d7c4ceb251af7e6109da4c1ecee545..11333916279f29abc2795546cadd95ce95e52639 100644 (file)
@@ -477,6 +477,24 @@ int tipc_bearer_mtu(struct net *net, u32 bearer_id)
        return mtu;
 }
 
+/* tipc_bearer_xmit_skb - sends buffer to destination over bearer
+ */
+void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
+                         struct sk_buff *skb,
+                         struct tipc_media_addr *dest)
+{
+       struct tipc_net *tn = tipc_net(net);
+       struct tipc_bearer *b;
+
+       rcu_read_lock();
+       b = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
+       if (likely(b))
+               b->media->send_msg(net, skb, b, dest);
+       rcu_read_unlock();
+       /* Until we remove cloning in tipc_l2_send_msg(): */
+       kfree_skb(skb);
+}
+
 /* tipc_bearer_xmit() -send buffer to destination over bearer
  */
 void tipc_bearer_xmit(struct net *net, u32 bearer_id,
index 2ba8a7e274a5e85dd1241f80d10c81bed565e9c2..5a600e1b197fa2883dcfeffb6b355d3a8cd94efa 100644 (file)
@@ -219,6 +219,9 @@ void tipc_bearer_stop(struct net *net);
 void tipc_bearer_send(struct net *net, u32 bearer_id, struct sk_buff *buf,
                      struct tipc_media_addr *dest);
 int tipc_bearer_mtu(struct net *net, u32 bearer_id);
+void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
+                         struct sk_buff *skb,
+                         struct tipc_media_addr *dest);
 void tipc_bearer_xmit(struct net *net, u32 bearer_id,
                      struct sk_buff_head *xmitq,
                      struct tipc_media_addr *dst);
index 6cd36f93aeb446ea3793476a8777499b1ce0255f..afe8c47c4085c7e01e6e8bfb3d9ed1e4f13eaa20 100644 (file)
@@ -167,11 +167,10 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb,
        /* Send response, if necessary */
        if (respond && (mtyp == DSC_REQ_MSG)) {
                rskb = tipc_buf_acquire(MAX_H_SIZE);
-               if (rskb) {
-                       tipc_disc_init_msg(net, rskb, DSC_RESP_MSG, bearer);
-                       tipc_bearer_send(net, bearer->identity, rskb, &maddr);
-                       kfree_skb(rskb);
-               }
+               if (!rskb)
+                       return;
+               tipc_disc_init_msg(net, rskb, DSC_RESP_MSG, bearer);
+               tipc_bearer_xmit_skb(net, bearer->identity, rskb, &maddr);
        }
 }
 
@@ -225,6 +224,7 @@ void tipc_disc_remove_dest(struct tipc_link_req *req)
 static void disc_timeout(unsigned long data)
 {
        struct tipc_link_req *req = (struct tipc_link_req *)data;
+       struct sk_buff *skb;
        int max_delay;
 
        spin_lock_bh(&req->lock);
@@ -242,9 +242,9 @@ static void disc_timeout(unsigned long data)
         * hold at fast polling rate if don't have any associated nodes,
         * otherwise hold at slow polling rate
         */
-       tipc_bearer_send(req->net, req->bearer_id, req->buf, &req->dest);
-
-
+       skb = skb_clone(req->buf, GFP_ATOMIC);
+       if (skb)
+               tipc_bearer_xmit_skb(req->net, req->bearer_id, skb, &req->dest);
        req->timer_intv *= 2;
        if (req->num_nodes)
                max_delay = TIPC_LINK_REQ_SLOW;
@@ -271,6 +271,7 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr,
                     struct tipc_media_addr *dest)
 {
        struct tipc_link_req *req;
+       struct sk_buff *skb;
 
        req = kmalloc(sizeof(*req), GFP_ATOMIC);
        if (!req)
@@ -292,7 +293,9 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr,
        setup_timer(&req->timer, disc_timeout, (unsigned long)req);
        mod_timer(&req->timer, jiffies + req->timer_intv);
        b_ptr->link_req = req;
-       tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest);
+       skb = skb_clone(req->buf, GFP_ATOMIC);
+       if (skb)
+               tipc_bearer_xmit_skb(net, req->bearer_id, skb, &req->dest);
        return 0;
 }
 
@@ -316,6 +319,7 @@ void tipc_disc_delete(struct tipc_link_req *req)
 void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr)
 {
        struct tipc_link_req *req = b_ptr->link_req;
+       struct sk_buff *skb;
 
        spin_lock_bh(&req->lock);
        tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr);
@@ -325,6 +329,8 @@ void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr)
        req->num_nodes = 0;
        req->timer_intv = TIPC_LINK_REQ_INIT;
        mod_timer(&req->timer, jiffies + req->timer_intv);
-       tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest);
+       skb = skb_clone(req->buf, GFP_ATOMIC);
+       if (skb)
+               tipc_bearer_xmit_skb(net, req->bearer_id, skb, &req->dest);
        spin_unlock_bh(&req->lock);
 }
index 3b98f8e706267b60c9c287606c9c572025bdf15f..7d3b6e7d852ac3ee7759561808ea8d42cda7e468 100644 (file)
@@ -1300,9 +1300,8 @@ void tipc_link_proto_xmit(struct tipc_link *l, u32 msg_typ, int probe_msg,
        skb = __skb_dequeue(&xmitq);
        if (!skb)
                return;
-       tipc_bearer_send(l->owner->net, l->bearer_id, skb, l->media_addr);
+       tipc_bearer_xmit_skb(l->owner->net, l->bearer_id, skb, l->media_addr);
        l->rcv_unacked = 0;
-       kfree_skb(skb);
 }
 
 static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,