Skip to content

Commit

Permalink
net: Add and use skb_copy_datagram_msg() helper.
Browse files Browse the repository at this point in the history
This encapsulates all of the skb_copy_datagram_iovec() callers
with call argument signature "skb, offset, msghdr->msg_iov, length".

When we move to iov_iters in the networking, the iov_iter object will
sit in the msghdr.

Having a helper like this means there will be less places to touch
during that transformation.

Based upon descriptions and patch from Al Viro.

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Nov 5, 2014
1 parent 1d76c1d commit 51f3d02
Show file tree
Hide file tree
Showing 43 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion drivers/isdn/mISDN/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mISDN_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
memcpy(skb_push(skb, MISDN_HEADER_LEN), mISDN_HEAD_P(skb),
MISDN_HEADER_LEN);

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);

mISDN_sock_cmsg(sk, msg, skb);

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ppp/pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ static int pppoe_recvmsg(struct kiocb *iocb, struct socket *sock,

if (skb) {
total_len = min_t(size_t, total_len, skb->len);
error = skb_copy_datagram_iovec(skb, 0, m->msg_iov, total_len);
error = skb_copy_datagram_msg(skb, 0, m, total_len);
if (error == 0) {
consume_skb(skb);
return total_len;
Expand Down
6 changes: 6 additions & 0 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/bug.h>
#include <linux/cache.h>
#include <linux/rbtree.h>
#include <linux/socket.h>

#include <linux/atomic.h>
#include <asm/types.h>
Expand Down Expand Up @@ -2639,6 +2640,11 @@ unsigned int datagram_poll(struct file *file, struct socket *sock,
struct poll_table_struct *wait);
int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
struct iovec *to, int size);
static inline int skb_copy_datagram_msg(const struct sk_buff *from, int offset,
struct msghdr *msg, int size)
{
return skb_copy_datagram_iovec(from, offset, msg->msg_iov, size);
}
int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
struct iovec *iov);
int skb_copy_datagram_from_iovec(struct sk_buff *skb, int offset,
Expand Down
2 changes: 1 addition & 1 deletion net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
copied = size;
msg->msg_flags |= MSG_TRUNC;
}
err = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, offset, msg, copied);

if (!err && msg->msg_name) {
DECLARE_SOCKADDR(struct sockaddr_at *, sat, msg->msg_name);
Expand Down
2 changes: 1 addition & 1 deletion net/atm/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
msg->msg_flags |= MSG_TRUNC;
}

error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
error = skb_copy_datagram_msg(skb, 0, msg, copied);
if (error)
return error;
sock_recv_ts_and_drops(msg, sk, skb);
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_flags |= MSG_TRUNC;
}

skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
skb_copy_datagram_msg(skb, 0, msg, copied);

if (msg->msg_name) {
ax25_digi digi;
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/af_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
}

skb_reset_transport_header(skb);
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err == 0) {
sock_recv_ts_and_drops(msg, sk, skb);

Expand Down Expand Up @@ -328,7 +328,7 @@ int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
}

chunk = min_t(unsigned int, skb->len, size);
if (skb_copy_datagram_iovec(skb, 0, msg->msg_iov, chunk)) {
if (skb_copy_datagram_msg(skb, 0, msg, chunk)) {
skb_queue_head(&sk->sk_receive_queue, skb);
if (!copied)
copied = -EFAULT;
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
}

skb_reset_transport_header(skb);
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);

switch (hci_pi(sk)->channel) {
case HCI_CHANNEL_RAW:
Expand Down
2 changes: 1 addition & 1 deletion net/caif/caif_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static int caif_seqpkt_recvmsg(struct kiocb *iocb, struct socket *sock,
copylen = len;
}

ret = skb_copy_datagram_iovec(skb, 0, m->msg_iov, copylen);
ret = skb_copy_datagram_msg(skb, 0, m, copylen);
if (ret)
goto out_free;

Expand Down
2 changes: 1 addition & 1 deletion net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
msg->msg_flags |= MSG_TRUNC;
copied = len;
}
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free_skb;

Expand Down
2 changes: 1 addition & 1 deletion net/dccp/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
else if (len < skb->len)
msg->msg_flags |= MSG_TRUNC;

if (skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len)) {
if (skb_copy_datagram_msg(skb, 0, msg, len)) {
/* Exception. Bailout! */
len = -EFAULT;
break;
Expand Down
2 changes: 1 addition & 1 deletion net/ieee802154/dgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
}

/* FIXME: skip headers if necessary ?! */
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
2 changes: 1 addition & 1 deletion net/ieee802154/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
copied = len;
}

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
msg->msg_flags |= MSG_TRUNC;
copied = len;
}
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free_skb;

Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
}

/* Don't bother checking the checksum */
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
copied = len;
}

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ static int tcp_peek_sndq(struct sock *sk, struct msghdr *msg, int len)
/* XXX -- need to support SO_PEEK_OFF */

skb_queue_walk(&sk->sk_write_queue, skb) {
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, skb->len);
err = skb_copy_datagram_msg(skb, 0, msg, skb->len);
if (err)
break;

Expand Down Expand Up @@ -1833,8 +1833,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
}

if (!(flags & MSG_TRUNC)) {
err = skb_copy_datagram_iovec(skb, offset,
msg->msg_iov, used);
err = skb_copy_datagram_msg(skb, offset, msg, used);
if (err) {
/* Exception. Bailout! */
if (!copied)
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,8 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
}

if (skb_csum_unnecessary(skb))
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, sizeof(struct udphdr),
msg, copied);
else {
err = skb_copy_and_csum_datagram_iovec(skb,
sizeof(struct udphdr),
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
msg->msg_flags |= MSG_TRUNC;
copied = len;
}
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free_skb;

Expand Down Expand Up @@ -445,7 +445,7 @@ int ipv6_recv_rxpmtu(struct sock *sk, struct msghdr *msg, int len,
msg->msg_flags |= MSG_TRUNC;
copied = len;
}
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free_skb;

Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,11 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
}

if (skb_csum_unnecessary(skb)) {
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
} else if (msg->msg_flags&MSG_TRUNC) {
if (__skb_checksum_complete(skb))
goto csum_copy_err;
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
} else {
err = skb_copy_and_csum_datagram_iovec(skb, 0, msg->msg_iov);
if (err == -EINVAL)
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
}

if (skb_csum_unnecessary(skb))
err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr),
msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, sizeof(struct udphdr),
msg, copied);
else {
err = skb_copy_and_csum_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov);
if (err == -EINVAL)
Expand Down
3 changes: 1 addition & 2 deletions net/ipx/af_ipx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1805,8 +1805,7 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_flags |= MSG_TRUNC;
}

rc = skb_copy_datagram_iovec(skb, sizeof(struct ipxhdr), msg->msg_iov,
copied);
rc = skb_copy_datagram_msg(skb, sizeof(struct ipxhdr), msg, copied);
if (rc)
goto out_free;
if (skb->tstamp.tv64)
Expand Down
2 changes: 1 addition & 1 deletion net/irda/af_irda.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ static int irda_recvmsg_dgram(struct kiocb *iocb, struct socket *sock,
copied = size;
msg->msg_flags |= MSG_TRUNC;
}
skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
skb_copy_datagram_msg(skb, 0, msg, copied);

skb_free_datagram(sk, skb);

Expand Down
2 changes: 1 addition & 1 deletion net/iucv/af_iucv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
sk->sk_shutdown = sk->sk_shutdown | RCV_SHUTDOWN;

cskb = skb;
if (skb_copy_datagram_iovec(cskb, offset, msg->msg_iov, copied)) {
if (skb_copy_datagram_msg(cskb, offset, msg, copied)) {
if (!(flags & MSG_PEEK))
skb_queue_head(&sk->sk_receive_queue, skb);
return -EFAULT;
Expand Down
2 changes: 1 addition & 1 deletion net/key/af_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -3654,7 +3654,7 @@ static int pfkey_recvmsg(struct kiocb *kiocb,
}

skb_reset_transport_header(skb);
err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free;

Expand Down
2 changes: 1 addition & 1 deletion net/l2tp/l2tp_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
copied = len;
}

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
2 changes: 1 addition & 1 deletion net/l2tp/l2tp_ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ static int l2tp_ip6_recvmsg(struct kiocb *iocb, struct sock *sk,
copied = len;
}

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto done;

Expand Down
2 changes: 1 addition & 1 deletion net/l2tp/l2tp_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
else if (len < skb->len)
msg->msg_flags |= MSG_TRUNC;

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
err = skb_copy_datagram_msg(skb, 0, msg, len);
if (likely(err == 0))
err = len;

Expand Down
3 changes: 1 addition & 2 deletions net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,7 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
used = len;

if (!(flags & MSG_TRUNC)) {
int rc = skb_copy_datagram_iovec(skb, offset,
msg->msg_iov, used);
int rc = skb_copy_datagram_msg(skb, offset, msg, used);
if (rc) {
/* Exception. Bailout! */
if (!copied)
Expand Down
2 changes: 1 addition & 1 deletion net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
}

skb_reset_transport_header(data_skb);
err = skb_copy_datagram_iovec(data_skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(data_skb, 0, msg, copied);

if (msg->msg_name) {
DECLARE_SOCKADDR(struct sockaddr_nl *, addr, msg->msg_name);
Expand Down
2 changes: 1 addition & 1 deletion net/netrom/af_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ static int nr_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_flags |= MSG_TRUNC;
}

er = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
er = skb_copy_datagram_msg(skb, 0, msg, copied);
if (er < 0) {
skb_free_datagram(sk, skb);
release_sock(sk);
Expand Down
2 changes: 1 addition & 1 deletion net/nfc/llcp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static int llcp_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
copied = min_t(unsigned int, rlen, len);

cskb = skb;
if (skb_copy_datagram_iovec(cskb, 0, msg->msg_iov, copied)) {
if (skb_copy_datagram_msg(cskb, 0, msg, copied)) {
if (!(flags & MSG_PEEK))
skb_queue_head(&sk->sk_receive_queue, skb);
return -EFAULT;
Expand Down
2 changes: 1 addition & 1 deletion net/nfc/rawsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static int rawsock_recvmsg(struct kiocb *iocb, struct socket *sock,
copied = len;
}

rc = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
rc = skb_copy_datagram_msg(skb, 0, msg, copied);

skb_free_datagram(sk, skb);

Expand Down
2 changes: 1 addition & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_flags |= MSG_TRUNC;
}

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
err = skb_copy_datagram_msg(skb, 0, msg, copied);
if (err)
goto out_free;

Expand Down
2 changes: 1 addition & 1 deletion net/phonet/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
copylen = len;
}

rval = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copylen);
rval = skb_copy_datagram_msg(skb, 0, msg, copylen);
if (rval) {
rval = -EFAULT;
goto out;
Expand Down
2 changes: 1 addition & 1 deletion net/phonet/pep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
else
len = skb->len;

err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
err = skb_copy_datagram_msg(skb, 0, msg, len);
if (!err)
err = (flags & MSG_TRUNC) ? skb->len : len;

Expand Down
2 changes: 1 addition & 1 deletion net/rose/af_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static int rose_recvmsg(struct kiocb *iocb, struct socket *sock,
msg->msg_flags |= MSG_TRUNC;
}

skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
skb_copy_datagram_msg(skb, 0, msg, copied);

if (msg->msg_name) {
struct sockaddr_rose *srose;
Expand Down
2 changes: 1 addition & 1 deletion net/rxrpc/ar-recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int rxrpc_recvmsg(struct kiocb *iocb, struct socket *sock,
if (copy > len - copied)
copy = len - copied;

ret = skb_copy_datagram_iovec(skb, offset, msg->msg_iov, copy);
ret = skb_copy_datagram_msg(skb, offset, msg, copy);

if (ret < 0)
goto copy_error;
Expand Down
Loading

0 comments on commit 51f3d02

Please sign in to comment.