Skip to content

Commit 0232fd0

Browse files
ajstephensPaul Gortmaker
authored andcommitted
tipc: Allow receiving into iovec containing multiple entries
Enhances TIPC's socket receive routines to support iovec structures containing more than a single entry. This change leverages existing sk_buff routines to do most of the work; the only significant change to TIPC itself is that an sk_buff now records how much data has been already consumed as an numeric offset, rather than as a pointer to the first unread data byte. Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
1 parent bef55ae commit 0232fd0

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

‎net/tipc/socket.c‎

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int release(struct socket *sock)
289289
if (buf == NULL)
290290
break;
291291
atomic_dec(&tipc_queue_size);
292-
if (TIPC_SKB_CB(buf)->handle != msg_data(buf_msg(buf)))
292+
if (TIPC_SKB_CB(buf)->handle != 0)
293293
buf_discard(buf);
294294
else {
295295
if ((sock->state == SS_CONNECTING) ||
@@ -917,9 +917,6 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
917917

918918
/* Catch invalid receive requests */
919919

920-
if (m->msg_iovlen != 1)
921-
return -EOPNOTSUPP; /* Don't do multiple iovec entries yet */
922-
923920
if (unlikely(!buf_len))
924921
return -EINVAL;
925922

@@ -991,11 +988,10 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
991988
sz = buf_len;
992989
m->msg_flags |= MSG_TRUNC;
993990
}
994-
if (unlikely(copy_to_user(m->msg_iov->iov_base, msg_data(msg),
995-
sz))) {
996-
res = -EFAULT;
991+
res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg),
992+
m->msg_iov, sz);
993+
if (res)
997994
goto exit;
998-
}
999995
res = sz;
1000996
} else {
1001997
if ((sock->state == SS_READY) ||
@@ -1041,16 +1037,11 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
10411037
unsigned int sz;
10421038
int sz_to_copy, target, needed;
10431039
int sz_copied = 0;
1044-
char __user *crs = m->msg_iov->iov_base;
1045-
unsigned char *buf_crs;
10461040
u32 err;
10471041
int res = 0;
10481042

10491043
/* Catch invalid receive attempts */
10501044

1051-
if (m->msg_iovlen != 1)
1052-
return -EOPNOTSUPP; /* Don't do multiple iovec entries yet */
1053-
10541045
if (unlikely(!buf_len))
10551046
return -EINVAL;
10561047

@@ -1112,24 +1103,25 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
11121103
/* Capture message data (if valid) & compute return value (always) */
11131104

11141105
if (!err) {
1115-
buf_crs = (unsigned char *)(TIPC_SKB_CB(buf)->handle);
1116-
sz = (unsigned char *)msg + msg_size(msg) - buf_crs;
1106+
u32 offset = (u32)(unsigned long)(TIPC_SKB_CB(buf)->handle);
11171107

1108+
sz -= offset;
11181109
needed = (buf_len - sz_copied);
11191110
sz_to_copy = (sz <= needed) ? sz : needed;
1120-
if (unlikely(copy_to_user(crs, buf_crs, sz_to_copy))) {
1121-
res = -EFAULT;
1111+
1112+
res = skb_copy_datagram_iovec(buf, msg_hdr_sz(msg) + offset,
1113+
m->msg_iov, sz_to_copy);
1114+
if (res)
11221115
goto exit;
1123-
}
1116+
11241117
sz_copied += sz_to_copy;
11251118

11261119
if (sz_to_copy < sz) {
11271120
if (!(flags & MSG_PEEK))
1128-
TIPC_SKB_CB(buf)->handle = buf_crs + sz_to_copy;
1121+
TIPC_SKB_CB(buf)->handle =
1122+
(void *)(unsigned long)(offset + sz_to_copy);
11291123
goto exit;
11301124
}
1131-
1132-
crs += sz_to_copy;
11331125
} else {
11341126
if (sz_copied != 0)
11351127
goto exit; /* can't add error msg to valid data */
@@ -1256,7 +1248,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)
12561248

12571249
/* Enqueue message (finally!) */
12581250

1259-
TIPC_SKB_CB(buf)->handle = msg_data(msg);
1251+
TIPC_SKB_CB(buf)->handle = 0;
12601252
atomic_inc(&tipc_queue_size);
12611253
__skb_queue_tail(&sk->sk_receive_queue, buf);
12621254

@@ -1608,7 +1600,7 @@ static int shutdown(struct socket *sock, int how)
16081600
buf = __skb_dequeue(&sk->sk_receive_queue);
16091601
if (buf) {
16101602
atomic_dec(&tipc_queue_size);
1611-
if (TIPC_SKB_CB(buf)->handle != msg_data(buf_msg(buf))) {
1603+
if (TIPC_SKB_CB(buf)->handle != 0) {
16121604
buf_discard(buf);
16131605
goto restart;
16141606
}

0 commit comments

Comments
 (0)