Skip to content

Commit 078bec8

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: add new functions for multicast and broadcast distribution
We add a new broadcast link transmit function in bclink.c and a new receive function in socket.c. The purpose is to move the branching between external and internal destination down to the link layer, just as we have done with unicast in earlier commits. We also make use of the new link-independent fragmentation support that was introduced in an earlier commit series. This gives a shorter and simpler code path, and makes it possible to obtain copy-free buffer delivery to all node local destination sockets. The new transmission code is added in parallel with the existing one, and will be used by the socket multicast send function in the next commit in this series. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 25b660c commit 078bec8

6 files changed

Lines changed: 136 additions & 2 deletions

File tree

‎net/tipc/bcast.c‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/bcast.c: TIPC broadcast code
33
*
4-
* Copyright (c) 2004-2006, Ericsson AB
4+
* Copyright (c) 2004-2006, 2014, Ericsson AB
55
* Copyright (c) 2004, Intel Corporation.
66
* Copyright (c) 2005, 2010-2011, Wind River Systems
77
* All rights reserved.
@@ -38,6 +38,8 @@
3838
#include "core.h"
3939
#include "link.h"
4040
#include "port.h"
41+
#include "socket.h"
42+
#include "msg.h"
4143
#include "bcast.h"
4244
#include "name_distr.h"
4345

@@ -138,6 +140,11 @@ static void tipc_bclink_unlock(void)
138140
tipc_link_reset_all(node);
139141
}
140142

143+
uint tipc_bclink_get_mtu(void)
144+
{
145+
return MAX_PKT_DEFAULT_MCAST;
146+
}
147+
141148
void tipc_bclink_set_flags(unsigned int flags)
142149
{
143150
bclink->flags |= flags;
@@ -408,6 +415,52 @@ int tipc_bclink_xmit(struct sk_buff *buf)
408415
return res;
409416
}
410417

418+
/* tipc_bclink_xmit2 - broadcast buffer chain to all nodes in cluster
419+
* and to identified node local sockets
420+
* @buf: chain of buffers containing message
421+
* Consumes the buffer chain, except when returning -ELINKCONG
422+
* Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
423+
*/
424+
int tipc_bclink_xmit2(struct sk_buff *buf)
425+
{
426+
int rc = 0;
427+
int bc = 0;
428+
struct sk_buff *clbuf;
429+
430+
/* Prepare clone of message for local node */
431+
clbuf = tipc_msg_reassemble(buf);
432+
if (unlikely(!clbuf)) {
433+
kfree_skb_list(buf);
434+
return -EHOSTUNREACH;
435+
}
436+
437+
/* Broadcast to all other nodes */
438+
if (likely(bclink)) {
439+
tipc_bclink_lock();
440+
if (likely(bclink->bcast_nodes.count)) {
441+
rc = __tipc_link_xmit(bcl, buf);
442+
if (likely(!rc)) {
443+
bclink_set_last_sent();
444+
bcl->stats.queue_sz_counts++;
445+
bcl->stats.accu_queue_sz += bcl->out_queue_size;
446+
}
447+
bc = 1;
448+
}
449+
tipc_bclink_unlock();
450+
}
451+
452+
if (unlikely(!bc))
453+
kfree_skb_list(buf);
454+
455+
/* Deliver message clone */
456+
if (likely(!rc))
457+
tipc_sk_mcast_rcv(clbuf);
458+
else
459+
kfree_skb(clbuf);
460+
461+
return rc;
462+
}
463+
411464
/**
412465
* bclink_accept_pkt - accept an incoming, in-sequence broadcast packet
413466
*

‎net/tipc/bcast.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/bcast.h: Include file for TIPC broadcast code
33
*
4-
* Copyright (c) 2003-2006, Ericsson AB
4+
* Copyright (c) 2003-2006, 2014, Ericsson AB
55
* Copyright (c) 2005, 2010-2011, Wind River Systems
66
* All rights reserved.
77
*
@@ -98,5 +98,7 @@ int tipc_bclink_stats(char *stats_buf, const u32 buf_size);
9898
int tipc_bclink_reset_stats(void);
9999
int tipc_bclink_set_queue_limits(u32 limit);
100100
void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action);
101+
uint tipc_bclink_get_mtu(void);
102+
int tipc_bclink_xmit2(struct sk_buff *buf);
101103

102104
#endif

‎net/tipc/msg.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,38 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode)
417417
msg_set_destport(msg, dport);
418418
return TIPC_OK;
419419
}
420+
421+
/* tipc_msg_reassemble() - clone a buffer chain of fragments and
422+
* reassemble the clones into one message
423+
*/
424+
struct sk_buff *tipc_msg_reassemble(struct sk_buff *chain)
425+
{
426+
struct sk_buff *buf = chain;
427+
struct sk_buff *frag = buf;
428+
struct sk_buff *head = NULL;
429+
int hdr_sz;
430+
431+
/* Copy header if single buffer */
432+
if (!buf->next) {
433+
hdr_sz = skb_headroom(buf) + msg_hdr_sz(buf_msg(buf));
434+
return __pskb_copy(buf, hdr_sz, GFP_ATOMIC);
435+
}
436+
437+
/* Clone all fragments and reassemble */
438+
while (buf) {
439+
frag = skb_clone(buf, GFP_ATOMIC);
440+
if (!frag)
441+
goto error;
442+
frag->next = NULL;
443+
if (tipc_buf_append(&head, &frag))
444+
break;
445+
if (!head)
446+
goto error;
447+
buf = buf->next;
448+
}
449+
return frag;
450+
error:
451+
pr_warn("Failed do clone local mcast rcv buffer\n");
452+
kfree_skb(head);
453+
return NULL;
454+
}

‎net/tipc/msg.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,6 @@ bool tipc_msg_make_bundle(struct sk_buff **buf, u32 mtu, u32 dnode);
744744
int tipc_msg_build2(struct tipc_msg *mhdr, struct iovec const *iov,
745745
int offset, int dsz, int mtu , struct sk_buff **chain);
746746

747+
struct sk_buff *tipc_msg_reassemble(struct sk_buff *chain);
748+
747749
#endif

‎net/tipc/socket.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,46 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,
534534
return mask;
535535
}
536536

537+
/* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets
538+
*/
539+
void tipc_sk_mcast_rcv(struct sk_buff *buf)
540+
{
541+
struct tipc_msg *msg = buf_msg(buf);
542+
struct tipc_port_list dports = {0, NULL, };
543+
struct tipc_port_list *item;
544+
struct sk_buff *b;
545+
uint i, last, dst = 0;
546+
u32 scope = TIPC_CLUSTER_SCOPE;
547+
548+
if (in_own_node(msg_orignode(msg)))
549+
scope = TIPC_NODE_SCOPE;
550+
551+
/* Create destination port list: */
552+
tipc_nametbl_mc_translate(msg_nametype(msg),
553+
msg_namelower(msg),
554+
msg_nameupper(msg),
555+
scope,
556+
&dports);
557+
last = dports.count;
558+
if (!last) {
559+
kfree_skb(buf);
560+
return;
561+
}
562+
563+
for (item = &dports; item; item = item->next) {
564+
for (i = 0; i < PLSIZE && ++dst <= last; i++) {
565+
b = (dst != last) ? skb_clone(buf, GFP_ATOMIC) : buf;
566+
if (!b) {
567+
pr_warn("Failed do clone mcast rcv buffer\n");
568+
continue;
569+
}
570+
msg_set_destport(msg, item->ports[i]);
571+
tipc_sk_rcv(b);
572+
}
573+
}
574+
tipc_port_list_free(&dports);
575+
}
576+
537577
/**
538578
* tipc_sk_proto_rcv - receive a connection mng protocol message
539579
* @tsk: receiving socket

‎net/tipc/socket.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ static inline int tipc_sk_conn_cong(struct tipc_sock *tsk)
8585

8686
int tipc_sk_rcv(struct sk_buff *buf);
8787

88+
void tipc_sk_mcast_rcv(struct sk_buff *buf);
89+
8890
#endif

0 commit comments

Comments
 (0)