datagram: Add offset argument to __skb_recv_datagram
This one is only considered for MSG_PEEK flag and the value pointed by it specifies where to start peeking bytes from. If the offset happens to point into the middle of the returned skb, the offset within this skb is put back to this very argument. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4934b0329f
commit
3f518bf745
|
@ -2046,7 +2046,7 @@ static inline void skb_frag_add_head(struct sk_buff *skb, struct sk_buff *frag)
|
||||||
for (iter = skb_shinfo(skb)->frag_list; iter; iter = iter->next)
|
for (iter = skb_shinfo(skb)->frag_list; iter; iter = iter->next)
|
||||||
|
|
||||||
extern struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags,
|
extern struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags,
|
||||||
int *peeked, int *err);
|
int *peeked, int *off, int *err);
|
||||||
extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
|
extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
|
||||||
int noblock, int *err);
|
int noblock, int *err);
|
||||||
extern unsigned int datagram_poll(struct file *file, struct socket *sock,
|
extern unsigned int datagram_poll(struct file *file, struct socket *sock,
|
||||||
|
|
|
@ -132,6 +132,8 @@ out_noerr:
|
||||||
* __skb_recv_datagram - Receive a datagram skbuff
|
* __skb_recv_datagram - Receive a datagram skbuff
|
||||||
* @sk: socket
|
* @sk: socket
|
||||||
* @flags: MSG_ flags
|
* @flags: MSG_ flags
|
||||||
|
* @off: an offset in bytes to peek skb from. Returns an offset
|
||||||
|
* within an skb where data actually starts
|
||||||
* @peeked: returns non-zero if this packet has been seen before
|
* @peeked: returns non-zero if this packet has been seen before
|
||||||
* @err: error code returned
|
* @err: error code returned
|
||||||
*
|
*
|
||||||
|
@ -158,7 +160,7 @@ out_noerr:
|
||||||
* the standard around please.
|
* the standard around please.
|
||||||
*/
|
*/
|
||||||
struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags,
|
struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags,
|
||||||
int *peeked, int *err)
|
int *peeked, int *off, int *err)
|
||||||
{
|
{
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
long timeo;
|
long timeo;
|
||||||
|
@ -183,20 +185,23 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags,
|
||||||
struct sk_buff_head *queue = &sk->sk_receive_queue;
|
struct sk_buff_head *queue = &sk->sk_receive_queue;
|
||||||
|
|
||||||
spin_lock_irqsave(&queue->lock, cpu_flags);
|
spin_lock_irqsave(&queue->lock, cpu_flags);
|
||||||
skb = skb_peek(queue);
|
skb_queue_walk(queue, skb) {
|
||||||
if (skb) {
|
|
||||||
*peeked = skb->peeked;
|
*peeked = skb->peeked;
|
||||||
if (flags & MSG_PEEK) {
|
if (flags & MSG_PEEK) {
|
||||||
|
if (*off >= skb->len) {
|
||||||
|
*off -= skb->len;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
skb->peeked = 1;
|
skb->peeked = 1;
|
||||||
atomic_inc(&skb->users);
|
atomic_inc(&skb->users);
|
||||||
} else
|
} else
|
||||||
__skb_unlink(skb, queue);
|
__skb_unlink(skb, queue);
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&queue->lock, cpu_flags);
|
||||||
|
return skb;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&queue->lock, cpu_flags);
|
spin_unlock_irqrestore(&queue->lock, cpu_flags);
|
||||||
|
|
||||||
if (skb)
|
|
||||||
return skb;
|
|
||||||
|
|
||||||
/* User doesn't want to wait */
|
/* User doesn't want to wait */
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
if (!timeo)
|
if (!timeo)
|
||||||
|
@ -215,10 +220,10 @@ EXPORT_SYMBOL(__skb_recv_datagram);
|
||||||
struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
|
struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
|
||||||
int noblock, int *err)
|
int noblock, int *err)
|
||||||
{
|
{
|
||||||
int peeked;
|
int peeked, off = 0;
|
||||||
|
|
||||||
return __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
return __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
||||||
&peeked, err);
|
&peeked, &off, err);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(skb_recv_datagram);
|
EXPORT_SYMBOL(skb_recv_datagram);
|
||||||
|
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
|
struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
unsigned int ulen, copied;
|
unsigned int ulen, copied;
|
||||||
int peeked;
|
int peeked, off = 0;
|
||||||
int err;
|
int err;
|
||||||
int is_udplite = IS_UDPLITE(sk);
|
int is_udplite = IS_UDPLITE(sk);
|
||||||
bool slow;
|
bool slow;
|
||||||
|
@ -1183,7 +1183,7 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
||||||
&peeked, &err);
|
&peeked, &off, &err);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -342,7 +342,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
|
||||||
struct inet_sock *inet = inet_sk(sk);
|
struct inet_sock *inet = inet_sk(sk);
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
unsigned int ulen, copied;
|
unsigned int ulen, copied;
|
||||||
int peeked;
|
int peeked, off = 0;
|
||||||
int err;
|
int err;
|
||||||
int is_udplite = IS_UDPLITE(sk);
|
int is_udplite = IS_UDPLITE(sk);
|
||||||
int is_udp4;
|
int is_udp4;
|
||||||
|
@ -359,7 +359,7 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
skb = __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0),
|
||||||
&peeked, &err);
|
&peeked, &off, &err);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue