Skip to content

Commit 5b8dddb

Browse files
Jon Maloydavem330
authored andcommitted
tipc: introduce group multicast messaging
The previously introduced message transport to all group members is based on the tipc multicast service, but is logically a broadcast service within the group, and that is what we call it. We now add functionality for sending messages to all group members having a certain identity. Correspondingly, we call this feature 'group multicast'. The service is using unicast when only one destination is found, otherwise it will use the bearer broadcast service to transfer the messages. In the latter case, the receiving members filter arriving messages by looking at the intended destination instance. If there is no match, the message will be dropped, while still being considered received and read as seen by the flow control mechanism. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ee106d7 commit 5b8dddb

3 files changed

Lines changed: 74 additions & 7 deletions

File tree

‎net/tipc/group.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,22 @@ void tipc_group_filter_msg(struct tipc_group *grp, struct sk_buff_head *inputq,
413413
if (!tipc_group_is_receiver(m))
414414
goto drop;
415415

416+
m->bc_rcv_nxt = msg_grp_bc_seqno(hdr) + 1;
417+
418+
/* Drop multicast here if not for this member */
419+
if (mtyp == TIPC_GRP_MCAST_MSG) {
420+
if (msg_nameinst(hdr) != grp->instance) {
421+
m->bc_rcv_nxt = msg_grp_bc_seqno(hdr) + 1;
422+
tipc_group_update_rcv_win(grp, msg_blocks(hdr),
423+
node, port, xmitq);
424+
kfree_skb(skb);
425+
return;
426+
}
427+
}
428+
416429
TIPC_SKB_CB(skb)->orig_member = m->instance;
417430
__skb_queue_tail(inputq, skb);
418431

419-
m->bc_rcv_nxt = msg_grp_bc_seqno(hdr) + 1;
420432
return;
421433
drop:
422434
kfree_skb(skb);

‎net/tipc/msg.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ struct plist;
6767
#define TIPC_DIRECT_MSG 3
6868
#define TIPC_GRP_MEMBER_EVT 4
6969
#define TIPC_GRP_BCAST_MSG 5
70-
#define TIPC_GRP_UCAST_MSG 6
70+
#define TIPC_GRP_MCAST_MSG 6
71+
#define TIPC_GRP_UCAST_MSG 7
7172

7273
/*
7374
* Internal message users
@@ -195,6 +196,11 @@ static inline u32 msg_size(struct tipc_msg *m)
195196
return msg_bits(m, 0, 0, 0x1ffff);
196197
}
197198

199+
static inline u32 msg_blocks(struct tipc_msg *m)
200+
{
201+
return (msg_size(m) / 1024) + 1;
202+
}
203+
198204
static inline u32 msg_data_sz(struct tipc_msg *m)
199205
{
200206
return msg_size(m) - msg_hdr_sz(m);
@@ -279,7 +285,8 @@ static inline u32 msg_mcast(struct tipc_msg *m)
279285
{
280286
int mtyp = msg_type(m);
281287

282-
return ((mtyp == TIPC_MCAST_MSG) || (mtyp == TIPC_GRP_BCAST_MSG));
288+
return ((mtyp == TIPC_MCAST_MSG) || (mtyp == TIPC_GRP_BCAST_MSG) ||
289+
(mtyp == TIPC_GRP_MCAST_MSG));
283290
}
284291

285292
static inline u32 msg_connected(struct tipc_msg *m)

‎net/tipc/socket.c‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,7 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m,
999999
static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m,
10001000
int dlen, long timeout)
10011001
{
1002+
DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
10021003
struct sock *sk = sock->sk;
10031004
struct net *net = sock_net(sk);
10041005
struct tipc_sock *tsk = tipc_sk(sk);
@@ -1021,11 +1022,16 @@ static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m,
10211022
return rc;
10221023

10231024
/* Complete message header */
1024-
msg_set_type(hdr, TIPC_GRP_BCAST_MSG);
1025+
if (dest) {
1026+
msg_set_type(hdr, TIPC_GRP_MCAST_MSG);
1027+
msg_set_nameinst(hdr, dest->addr.name.name.instance);
1028+
} else {
1029+
msg_set_type(hdr, TIPC_GRP_BCAST_MSG);
1030+
msg_set_nameinst(hdr, 0);
1031+
}
10251032
msg_set_hdr_sz(hdr, GROUP_H_SIZE);
10261033
msg_set_destport(hdr, 0);
10271034
msg_set_destnode(hdr, 0);
1028-
msg_set_nameinst(hdr, 0);
10291035
msg_set_grp_bc_seqno(hdr, tipc_group_bc_snd_nxt(grp));
10301036

10311037
/* Build message as chain of buffers */
@@ -1045,6 +1051,48 @@ static int tipc_send_group_bcast(struct socket *sock, struct msghdr *m,
10451051
return dlen;
10461052
}
10471053

1054+
/**
1055+
* tipc_send_group_mcast - send message to all members with given identity
1056+
* @sock: socket structure
1057+
* @m: message to send
1058+
* @dlen: total length of message data
1059+
* @timeout: timeout to wait for wakeup
1060+
*
1061+
* Called from function tipc_sendmsg(), which has done all sanity checks
1062+
* Returns the number of bytes sent on success, or errno
1063+
*/
1064+
static int tipc_send_group_mcast(struct socket *sock, struct msghdr *m,
1065+
int dlen, long timeout)
1066+
{
1067+
struct sock *sk = sock->sk;
1068+
DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
1069+
struct tipc_name_seq *seq = &dest->addr.nameseq;
1070+
struct tipc_sock *tsk = tipc_sk(sk);
1071+
struct tipc_group *grp = tsk->group;
1072+
struct net *net = sock_net(sk);
1073+
u32 domain, exclude, dstcnt;
1074+
struct list_head dsts;
1075+
1076+
INIT_LIST_HEAD(&dsts);
1077+
1078+
if (seq->lower != seq->upper)
1079+
return -ENOTSUPP;
1080+
1081+
domain = addr_domain(net, dest->scope);
1082+
exclude = tipc_group_exclude(grp);
1083+
if (!tipc_nametbl_lookup(net, seq->type, seq->lower, domain,
1084+
&dsts, &dstcnt, exclude, true))
1085+
return -EHOSTUNREACH;
1086+
1087+
if (dstcnt == 1) {
1088+
tipc_dest_pop(&dsts, &dest->addr.id.node, &dest->addr.id.ref);
1089+
return tipc_send_group_unicast(sock, m, dlen, timeout);
1090+
}
1091+
1092+
tipc_dest_list_purge(&dsts);
1093+
return tipc_send_group_bcast(sock, m, dlen, timeout);
1094+
}
1095+
10481096
/**
10491097
* tipc_sk_mcast_rcv - Deliver multicast messages to all destination sockets
10501098
* @arrvq: queue with arriving messages, to be cloned after destination lookup
@@ -1213,6 +1261,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
12131261
return tipc_send_group_anycast(sock, m, dlen, timeout);
12141262
if (dest->addrtype == TIPC_ADDR_ID)
12151263
return tipc_send_group_unicast(sock, m, dlen, timeout);
1264+
if (dest->addrtype == TIPC_ADDR_MCAST)
1265+
return tipc_send_group_mcast(sock, m, dlen, timeout);
12161266
return -EINVAL;
12171267
}
12181268

@@ -2022,8 +2072,6 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,
20222072

20232073
if (unlikely(!msg_isdata(hdr)))
20242074
tipc_sk_proto_rcv(sk, &inputq, xmitq);
2025-
else if (unlikely(msg_type(hdr) > TIPC_GRP_UCAST_MSG))
2026-
return kfree_skb(skb);
20272075

20282076
if (unlikely(grp))
20292077
tipc_group_filter_msg(grp, &inputq, xmitq);

0 commit comments

Comments
 (0)