Skip to content

Commit e2dafe8

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: RDM/DGRAM transport uses new fragmenting and sending functions
We merge the code for sending port name and port identity addressed messages into the corresponding send functions in socket.c, and start using the new fragmenting and transmit functions we just have introduced. This saves a call level and quite a few code lines, as well as making this part of the code easier to follow. As a consequence, the functions tipc_send2name() and tipc_send2port() in port.c can be removed. For practical reasons, we break out the code for sending multicast messages from tipc_sendmsg() and move it into a separate function, tipc_sendmcast(), but we do not yet convert it into using the new build/send functions. Signed-off-by: Jon Maloy <[email protected]> Reviewed-by: Erik Hugne <[email protected]> Reviewed-by: Ying Xue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5a37907 commit e2dafe8

File tree

3 files changed

+110
-149
lines changed

3 files changed

+110
-149
lines changed

net/tipc/port.c

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -806,93 +806,3 @@ int tipc_send(struct tipc_port *p_ptr,
806806
}
807807
return -ELINKCONG;
808808
}
809-
810-
/**
811-
* tipc_send2name - send message sections to port name
812-
*/
813-
int tipc_send2name(struct tipc_port *p_ptr,
814-
struct tipc_name const *name,
815-
unsigned int domain,
816-
struct iovec const *msg_sect,
817-
unsigned int len)
818-
{
819-
struct tipc_msg *msg;
820-
u32 destnode = domain;
821-
u32 destport;
822-
int res;
823-
824-
if (p_ptr->connected)
825-
return -EINVAL;
826-
827-
msg = &p_ptr->phdr;
828-
msg_set_type(msg, TIPC_NAMED_MSG);
829-
msg_set_hdr_sz(msg, NAMED_H_SIZE);
830-
msg_set_nametype(msg, name->type);
831-
msg_set_nameinst(msg, name->instance);
832-
msg_set_lookup_scope(msg, tipc_addr_scope(domain));
833-
destport = tipc_nametbl_translate(name->type, name->instance, &destnode);
834-
msg_set_destnode(msg, destnode);
835-
msg_set_destport(msg, destport);
836-
837-
if (likely(destport || destnode)) {
838-
if (likely(in_own_node(destnode)))
839-
res = tipc_port_iovec_rcv(p_ptr, msg_sect, len);
840-
else if (tipc_own_addr)
841-
res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len,
842-
destnode);
843-
else
844-
res = tipc_port_iovec_reject(p_ptr, msg, msg_sect,
845-
len, TIPC_ERR_NO_NODE);
846-
if (likely(res != -ELINKCONG)) {
847-
if (res > 0)
848-
p_ptr->sent++;
849-
return res;
850-
}
851-
if (tipc_port_unreliable(p_ptr))
852-
return len;
853-
854-
return -ELINKCONG;
855-
}
856-
return tipc_port_iovec_reject(p_ptr, msg, msg_sect, len,
857-
TIPC_ERR_NO_NAME);
858-
}
859-
860-
/**
861-
* tipc_send2port - send message sections to port identity
862-
*/
863-
int tipc_send2port(struct tipc_port *p_ptr,
864-
struct tipc_portid const *dest,
865-
struct iovec const *msg_sect,
866-
unsigned int len)
867-
{
868-
struct tipc_msg *msg;
869-
int res;
870-
871-
if (p_ptr->connected)
872-
return -EINVAL;
873-
874-
msg = &p_ptr->phdr;
875-
msg_set_type(msg, TIPC_DIRECT_MSG);
876-
msg_set_lookup_scope(msg, 0);
877-
msg_set_destnode(msg, dest->node);
878-
msg_set_destport(msg, dest->ref);
879-
msg_set_hdr_sz(msg, BASIC_H_SIZE);
880-
881-
if (in_own_node(dest->node))
882-
res = tipc_port_iovec_rcv(p_ptr, msg_sect, len);
883-
else if (tipc_own_addr)
884-
res = tipc_link_iovec_xmit_fast(p_ptr, msg_sect, len,
885-
dest->node);
886-
else
887-
res = tipc_port_iovec_reject(p_ptr, msg, msg_sect, len,
888-
TIPC_ERR_NO_NODE);
889-
if (likely(res != -ELINKCONG)) {
890-
if (res > 0)
891-
p_ptr->sent++;
892-
return res;
893-
}
894-
if (tipc_port_unreliable(p_ptr))
895-
return len;
896-
897-
return -ELINKCONG;
898-
}

net/tipc/port.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,6 @@ int tipc_send(struct tipc_port *port,
140140
struct iovec const *msg_sect,
141141
unsigned int len);
142142

143-
int tipc_send2name(struct tipc_port *port,
144-
struct tipc_name const *name,
145-
u32 domain,
146-
struct iovec const *msg_sect,
147-
unsigned int len);
148-
149-
int tipc_send2port(struct tipc_port *port,
150-
struct tipc_portid const *dest,
151-
struct iovec const *msg_sect,
152-
unsigned int len);
153-
154143
int tipc_port_mcast_xmit(struct tipc_port *port,
155144
struct tipc_name_seq const *seq,
156145
struct iovec const *msg,

net/tipc/socket.c

Lines changed: 110 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636

3737
#include "core.h"
3838
#include "port.h"
39+
#include "name_table.h"
3940
#include "node.h"
40-
41+
#include "link.h"
4142
#include <linux/export.h>
4243
#include "link.h"
4344

@@ -545,6 +546,8 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m)
545546
{
546547
struct tipc_cfg_msg_hdr hdr;
547548

549+
if (unlikely(dest->addrtype == TIPC_ADDR_ID))
550+
return 0;
548551
if (likely(dest->addr.name.name.type >= TIPC_RESERVED_TYPES))
549552
return 0;
550553
if (likely(dest->addr.name.name.type == TIPC_TOP_SRV))
@@ -587,13 +590,49 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
587590
return 0;
588591
}
589592

593+
/**
594+
* tipc_sendmcast - send multicast message
595+
* @sock: socket structure
596+
* @seq: destination address
597+
* @iov: message data to send
598+
* @dsz: total length of message data
599+
* @timeo: timeout to wait for wakeup
600+
*
601+
* Called from function tipc_sendmsg(), which has done all sanity checks
602+
* Returns the number of bytes sent on success, or errno
603+
*/
604+
static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
605+
struct iovec *iov, size_t dsz, long timeo)
606+
{
607+
struct sock *sk = sock->sk;
608+
struct tipc_sock *tsk = tipc_sk(sk);
609+
int rc;
610+
611+
do {
612+
if (sock->state != SS_READY) {
613+
rc = -EOPNOTSUPP;
614+
break;
615+
}
616+
rc = tipc_port_mcast_xmit(&tsk->port, seq, iov, dsz);
617+
if (likely(rc >= 0)) {
618+
if (sock->state != SS_READY)
619+
sock->state = SS_CONNECTING;
620+
break;
621+
}
622+
if (rc != -ELINKCONG)
623+
break;
624+
rc = tipc_wait_for_sndmsg(sock, &timeo);
625+
} while (!rc);
626+
627+
return rc;
628+
}
590629

591630
/**
592631
* tipc_sendmsg - send message in connectionless manner
593632
* @iocb: if NULL, indicates that socket lock is already held
594633
* @sock: socket structure
595634
* @m: message to send
596-
* @total_len: length of message
635+
* @dsz: amount of user data to be sent
597636
*
598637
* Message must have an destination specified explicitly.
599638
* Used for SOCK_RDM and SOCK_DGRAM messages,
@@ -603,93 +642,116 @@ static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p)
603642
* Returns the number of bytes sent on success, or errno otherwise
604643
*/
605644
static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
606-
struct msghdr *m, size_t total_len)
645+
struct msghdr *m, size_t dsz)
607646
{
647+
DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
608648
struct sock *sk = sock->sk;
609649
struct tipc_sock *tsk = tipc_sk(sk);
610650
struct tipc_port *port = &tsk->port;
611-
DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);
612-
int needs_conn;
651+
struct tipc_msg *mhdr = &port->phdr;
652+
struct iovec *iov = m->msg_iov;
653+
u32 dnode, dport;
654+
struct sk_buff *buf;
655+
struct tipc_name_seq *seq = &dest->addr.nameseq;
656+
u32 mtu;
613657
long timeo;
614-
int res = -EINVAL;
658+
int rc = -EINVAL;
615659

616660
if (unlikely(!dest))
617661
return -EDESTADDRREQ;
662+
618663
if (unlikely((m->msg_namelen < sizeof(*dest)) ||
619664
(dest->family != AF_TIPC)))
620665
return -EINVAL;
621-
if (total_len > TIPC_MAX_USER_MSG_SIZE)
666+
667+
if (dsz > TIPC_MAX_USER_MSG_SIZE)
622668
return -EMSGSIZE;
623669

624670
if (iocb)
625671
lock_sock(sk);
626672

627-
needs_conn = (sock->state != SS_READY);
628-
if (unlikely(needs_conn)) {
673+
if (unlikely(sock->state != SS_READY)) {
629674
if (sock->state == SS_LISTENING) {
630-
res = -EPIPE;
675+
rc = -EPIPE;
631676
goto exit;
632677
}
633678
if (sock->state != SS_UNCONNECTED) {
634-
res = -EISCONN;
679+
rc = -EISCONN;
635680
goto exit;
636681
}
637682
if (tsk->port.published) {
638-
res = -EOPNOTSUPP;
683+
rc = -EOPNOTSUPP;
639684
goto exit;
640685
}
641686
if (dest->addrtype == TIPC_ADDR_NAME) {
642687
tsk->port.conn_type = dest->addr.name.name.type;
643688
tsk->port.conn_instance = dest->addr.name.name.instance;
644689
}
645-
646-
/* Abort any pending connection attempts (very unlikely) */
647-
reject_rx_queue(sk);
648690
}
691+
rc = dest_name_check(dest, m);
692+
if (rc)
693+
goto exit;
649694

650695
timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT);
651-
do {
652-
if (dest->addrtype == TIPC_ADDR_NAME) {
653-
res = dest_name_check(dest, m);
654-
if (res)
655-
break;
656-
res = tipc_send2name(port,
657-
&dest->addr.name.name,
658-
dest->addr.name.domain,
659-
m->msg_iov,
660-
total_len);
661-
} else if (dest->addrtype == TIPC_ADDR_ID) {
662-
res = tipc_send2port(port,
663-
&dest->addr.id,
664-
m->msg_iov,
665-
total_len);
666-
} else if (dest->addrtype == TIPC_ADDR_MCAST) {
667-
if (needs_conn) {
668-
res = -EOPNOTSUPP;
669-
break;
670-
}
671-
res = dest_name_check(dest, m);
672-
if (res)
673-
break;
674-
res = tipc_port_mcast_xmit(port,
675-
&dest->addr.nameseq,
676-
m->msg_iov,
677-
total_len);
696+
697+
if (dest->addrtype == TIPC_ADDR_MCAST) {
698+
rc = tipc_sendmcast(sock, seq, iov, dsz, timeo);
699+
goto exit;
700+
} else if (dest->addrtype == TIPC_ADDR_NAME) {
701+
u32 type = dest->addr.name.name.type;
702+
u32 inst = dest->addr.name.name.instance;
703+
u32 domain = dest->addr.name.domain;
704+
705+
dnode = domain;
706+
msg_set_type(mhdr, TIPC_NAMED_MSG);
707+
msg_set_hdr_sz(mhdr, NAMED_H_SIZE);
708+
msg_set_nametype(mhdr, type);
709+
msg_set_nameinst(mhdr, inst);
710+
msg_set_lookup_scope(mhdr, tipc_addr_scope(domain));
711+
dport = tipc_nametbl_translate(type, inst, &dnode);
712+
msg_set_destnode(mhdr, dnode);
713+
msg_set_destport(mhdr, dport);
714+
if (unlikely(!dport && !dnode)) {
715+
rc = -EHOSTUNREACH;
716+
goto exit;
678717
}
679-
if (likely(res != -ELINKCONG)) {
680-
if (needs_conn && (res >= 0))
718+
} else if (dest->addrtype == TIPC_ADDR_ID) {
719+
dnode = dest->addr.id.node;
720+
msg_set_type(mhdr, TIPC_DIRECT_MSG);
721+
msg_set_lookup_scope(mhdr, 0);
722+
msg_set_destnode(mhdr, dnode);
723+
msg_set_destport(mhdr, dest->addr.id.ref);
724+
msg_set_hdr_sz(mhdr, BASIC_H_SIZE);
725+
}
726+
727+
new_mtu:
728+
mtu = tipc_node_get_mtu(dnode, tsk->port.ref);
729+
rc = tipc_msg_build2(mhdr, iov, 0, dsz, mtu, &buf);
730+
if (rc < 0)
731+
goto exit;
732+
733+
do {
734+
rc = tipc_link_xmit2(buf, dnode, tsk->port.ref);
735+
if (likely(rc >= 0)) {
736+
if (sock->state != SS_READY)
681737
sock->state = SS_CONNECTING;
738+
rc = dsz;
682739
break;
683740
}
684-
res = tipc_wait_for_sndmsg(sock, &timeo);
685-
if (res)
741+
if (rc == -EMSGSIZE)
742+
goto new_mtu;
743+
744+
if (rc != -ELINKCONG)
686745
break;
687-
} while (1);
746+
747+
rc = tipc_wait_for_sndmsg(sock, &timeo);
748+
} while (!rc);
688749

689750
exit:
690751
if (iocb)
691752
release_sock(sk);
692-
return res;
753+
754+
return rc;
693755
}
694756

695757
static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)

0 commit comments

Comments
 (0)