@@ -817,6 +817,93 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
817817 return rc ? rc : dlen ;
818818}
819819
820+ /**
821+ * tipc_send_group_msg - send a message to a member in the group
822+ * @net: network namespace
823+ * @m: message to send
824+ * @mb: group member
825+ * @dnode: destination node
826+ * @dport: destination port
827+ * @dlen: total length of message data
828+ */
829+ static int tipc_send_group_msg (struct net * net , struct tipc_sock * tsk ,
830+ struct msghdr * m , struct tipc_member * mb ,
831+ u32 dnode , u32 dport , int dlen )
832+ {
833+ int blks = tsk_blocks (GROUP_H_SIZE + dlen );
834+ struct tipc_msg * hdr = & tsk -> phdr ;
835+ struct sk_buff_head pkts ;
836+ int mtu , rc ;
837+
838+ /* Complete message header */
839+ msg_set_type (hdr , TIPC_GRP_UCAST_MSG );
840+ msg_set_hdr_sz (hdr , GROUP_H_SIZE );
841+ msg_set_destport (hdr , dport );
842+ msg_set_destnode (hdr , dnode );
843+
844+ /* Build message as chain of buffers */
845+ skb_queue_head_init (& pkts );
846+ mtu = tipc_node_get_mtu (net , dnode , tsk -> portid );
847+ rc = tipc_msg_build (hdr , m , 0 , dlen , mtu , & pkts );
848+ if (unlikely (rc != dlen ))
849+ return rc ;
850+
851+ /* Send message */
852+ rc = tipc_node_xmit (net , & pkts , dnode , tsk -> portid );
853+ if (unlikely (rc == - ELINKCONG )) {
854+ tipc_dest_push (& tsk -> cong_links , dnode , 0 );
855+ tsk -> cong_link_cnt ++ ;
856+ }
857+
858+ /* Update send window and sequence number */
859+ tipc_group_update_member (mb , blks );
860+
861+ return dlen ;
862+ }
863+
864+ /**
865+ * tipc_send_group_unicast - send message to a member in the group
866+ * @sock: socket structure
867+ * @m: message to send
868+ * @dlen: total length of message data
869+ * @timeout: timeout to wait for wakeup
870+ *
871+ * Called from function tipc_sendmsg(), which has done all sanity checks
872+ * Returns the number of bytes sent on success, or errno
873+ */
874+ static int tipc_send_group_unicast (struct socket * sock , struct msghdr * m ,
875+ int dlen , long timeout )
876+ {
877+ struct sock * sk = sock -> sk ;
878+ DECLARE_SOCKADDR (struct sockaddr_tipc * , dest , m -> msg_name );
879+ int blks = tsk_blocks (GROUP_H_SIZE + dlen );
880+ struct tipc_sock * tsk = tipc_sk (sk );
881+ struct tipc_group * grp = tsk -> group ;
882+ struct net * net = sock_net (sk );
883+ struct tipc_member * mb = NULL ;
884+ u32 node , port ;
885+ int rc ;
886+
887+ node = dest -> addr .id .node ;
888+ port = dest -> addr .id .ref ;
889+ if (!port && !node )
890+ return - EHOSTUNREACH ;
891+
892+ /* Block or return if destination link or member is congested */
893+ rc = tipc_wait_for_cond (sock , & timeout ,
894+ !tipc_dest_find (& tsk -> cong_links , node , 0 ) &&
895+ !tipc_group_cong (grp , node , port , blks , & mb ));
896+ if (unlikely (rc ))
897+ return rc ;
898+
899+ if (unlikely (!mb ))
900+ return - EHOSTUNREACH ;
901+
902+ rc = tipc_send_group_msg (net , tsk , m , mb , node , port , dlen );
903+
904+ return rc ? rc : dlen ;
905+ }
906+
820907/**
821908 * tipc_send_group_bcast - send message to all members in communication group
822909 * @sk: socket structure
@@ -1030,21 +1117,27 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
10301117 if (unlikely (dlen > TIPC_MAX_USER_MSG_SIZE ))
10311118 return - EMSGSIZE ;
10321119
1033- if (unlikely (grp && !dest ))
1034- return tipc_send_group_bcast (sock , m , dlen , timeout );
1120+ if (likely (dest )) {
1121+ if (unlikely (m -> msg_namelen < sizeof (* dest )))
1122+ return - EINVAL ;
1123+ if (unlikely (dest -> family != AF_TIPC ))
1124+ return - EINVAL ;
1125+ }
1126+
1127+ if (grp ) {
1128+ if (!dest )
1129+ return tipc_send_group_bcast (sock , m , dlen , timeout );
1130+ if (dest -> addrtype == TIPC_ADDR_ID )
1131+ return tipc_send_group_unicast (sock , m , dlen , timeout );
1132+ return - EINVAL ;
1133+ }
10351134
10361135 if (unlikely (!dest )) {
10371136 dest = & tsk -> peer ;
10381137 if (!syn || dest -> family != AF_TIPC )
10391138 return - EDESTADDRREQ ;
10401139 }
10411140
1042- if (unlikely (m -> msg_namelen < sizeof (* dest )))
1043- return - EINVAL ;
1044-
1045- if (unlikely (dest -> family != AF_TIPC ))
1046- return - EINVAL ;
1047-
10481141 if (unlikely (syn )) {
10491142 if (sk -> sk_state == TIPC_LISTEN )
10501143 return - EPIPE ;
@@ -1077,7 +1170,6 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
10771170 msg_set_destport (hdr , dport );
10781171 if (unlikely (!dport && !dnode ))
10791172 return - EHOSTUNREACH ;
1080-
10811173 } else if (dest -> addrtype == TIPC_ADDR_ID ) {
10821174 dnode = dest -> addr .id .node ;
10831175 msg_set_type (hdr , TIPC_DIRECT_MSG );
@@ -1846,7 +1938,7 @@ static void tipc_sk_filter_rcv(struct sock *sk, struct sk_buff *skb,
18461938
18471939 if (unlikely (!msg_isdata (hdr )))
18481940 tipc_sk_proto_rcv (sk , & inputq , xmitq );
1849- else if (unlikely (msg_type (hdr ) > TIPC_GRP_BCAST_MSG ))
1941+ else if (unlikely (msg_type (hdr ) > TIPC_GRP_UCAST_MSG ))
18501942 return kfree_skb (skb );
18511943
18521944 if (unlikely (grp ))
0 commit comments