Message ID | CAF=yD-Lacw9T7G0XZBdHZwEb6HgRuaBoyUN1oTvWixu4a0Fy6Q@mail.gmail.com |
---|---|
State | RFC, archived |
Delegated to: | David Miller |
Headers | show |
> There is another difference between reading sk_peek_offset in the > caller or in __skb_try_recv_from_queue. The latter is called repeatedly > when it returns NULL. Each call can modify *off. I believe that it needs > to restart with _off at sk->sk_peek_off each time, as it restarts from the > head of the queue each time. I made a mistake here. *off is not updated when returning NULL. In that case, it is better to read sk_peek_offset once, than to read it each time __skb_try_recv_from_queue is entered.
On Tue, 2017-08-15 at 12:45 -0400, Willem de Bruijn wrote: > On Tue, Aug 15, 2017 at 11:40 AM, Paolo Abeni <pabeni@redhat.com> wrote: > > For the record, I thought something like the following (uncomplete, > > does not even compile): > > --- > > diff --git a/include/linux/socket.h b/include/linux/socket.h > > index 8b13db5163cc..5085cf003b88 100644 > > --- a/include/linux/socket.h > > +++ b/include/linux/socket.h > > @@ -286,6 +286,7 @@ struct ucred { > > #define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */ > > #define MSG_BATCH 0x40000 /* sendmmsg(): more messages coming */ > > #define MSG_EOF MSG_FIN > > +#define MSG_PEEK_OFF 0x80000 > > Yes, that also works well. > > I'm afraid about exhausting the MSG_* flag space here for a > feature that is not exposed to userspace. We don't have many flags > left. We could shadow an existing flag that is unused in this context. That was my concern, too. Fortunately there are a bunch of flags defined but apparently unused (MSG_FIN, MSG_SYN, MSG_RST) since long time (if I'm not too low on coffee). We can shadow one of them (and ev. drop the above define, if really unused). I think that the MSG_PEEK_OFF should be explicitly cleared in sk_peek_offset() when the 'sk_peek_off' is negative, to avoid beeing fooled by stray bits into the 'flags' argument. I'll try to scatch-up something tomorrow. Thanks, Paolo
diff --git a/net/core/datagram.c b/net/core/datagram.c index ee5647bd91b3..06bad8726612 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -170,13 +170,15 @@ struct sk_buff *__skb_try_recv_from_queue(struct sock *sk, struct sk_buff **last) { struct sk_buff *skb; - int _off = *off; + int _off; + bool peek_at_off; + _off = sk_peek_offset(sk, flags); + peek_at_off = _off >= 0; *last = queue->prev; skb_queue_walk(queue, skb) { if (flags & MSG_PEEK) { - if (_off >= skb->len && (skb->len || _off || - skb->peeked)) { + if (peek_at_off && off >= skb->len && + (skb->len || _off || skb->peeked)) { _off -= skb->len; continue; } diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index a7c804f73990..4b51b9853406 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1574,7 +1574,7 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, return ip_recv_error(sk, msg, len, addr_len); try_again: - peeking = off = sk_peek_offset(sk, flags); + peeking = flags & MSG_PEEK; skb = __skb_recv_udp(sk, flags, noblock, &peeked, &off, &err); if (!skb)