[vlc-devel] [PATCH] derive truncated packet size in non-linux recvmsg case by using overflow buffer

Ilkka Ollakka ileoo at videolan.org
Sun Oct 28 19:24:18 CET 2018


On Sat, Oct 27, 2018 at 05:58:59PM -0700, Nick Briggs wrote:

> > On Oct 27, 2018, at 10:50 AM, Nick Briggs <nicholas.h.briggs at gmail.com> wrote:

> > Here's an alternate idea to handle the non-Linux case:

> > Since you're allocating the peek_block, make your iov array 2 elements, add the peek buffer as the second element, and just check if the returned length is greater than the primary block you were reading into. MSG_TRUNC will never be set. It would then mirror the logic of the Linux case with the MSG_TRUNC in the recvmsg() flags, and it doesn't depend on PEEKing the *next* block to see if it is also bigger than the expected MTU. 

> For example, and then it also avoids the change to the Windows compatibility code, assuming it handles scatter/gather in recvmsg() the same way.

> The "len > sys->mtu" comparison generates a warning for comparison of differently signed integers (compiling with clang), but those seem to be fairly frequent in the existing code.


Hi,

That sounds actually good idea.

Actually, why not just use that overflow_block and reallocate new one
for next overflow case, that way you wouldn't need to truncate the data.

Also you could use same approach in linux case and don't care about
MSG_TRUNC flag, but just check if received data did go to overflow_block
area and adjust mtu accordingly.

I attached patch for that based on your patch that handle the receiving
like that.


> ---
>  modules/access/udp.c | 35 ++++++++++++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 7 deletions(-)

> diff --git a/modules/access/udp.c b/modules/access/udp.c
> index 654ecf8..7d94796 100644
> --- a/modules/access/udp.c
> +++ b/modules/access/udp.c
> @@ -81,6 +81,7 @@ typedef struct
>      int fd;
>      int timeout;
>      size_t mtu;
> +    block_t *overflow_block;
>  } access_sys_t;

>  /*****************************************************************************
> @@ -104,6 +105,13 @@ static int Open( vlc_object_t *p_this )
>      if( unlikely( sys == NULL ) )
>          return VLC_ENOMEM;

> +    sys->overflow_block = NULL;
> +#ifndef __linux__
> +    sys->overflow_block = block_Alloc(65536);
> +    if( unlikely( sys->overflow_block == NULL ) )
> +        return VLC_ENOMEM;
> +#endif
> +
>      p_access->p_sys = sys;

>      /* Set up p_access */
> @@ -185,6 +193,8 @@ static void Close( vlc_object_t *p_this )
>      stream_t     *p_access = (stream_t*)p_this;
>      access_sys_t *sys = p_access->p_sys;

> +    if( sys->overflow_block )
> +        block_Release( sys->overflow_block );
>      net_Close( sys->fd );
>  }

> @@ -237,14 +247,25 @@ static block_t *BlockUDP(stream_t *access, bool *restrict eof)
>      const int trunc_flag = 0;
>  #endif

> -    struct iovec iov = {
> -        .iov_base = pkt->p_buffer,
> -        .iov_len = sys->mtu,
> +    struct iovec iov[2] = {
> +        {
> +            .iov_base = pkt->p_buffer,
> +            .iov_len = sys->mtu
> +        },
> +#ifndef __linux__
> +        {
> +            .iov_base = sys->overflow_block,
> +            .iov_len = 65536		/* see block_Alloc() */
> +        }
> +#endif
>      };
>      struct msghdr msg = {
> -        .msg_iov = &iov,
> -        .msg_iovlen = 1,
> -        .msg_flags = trunc_flag,
> +        .msg_iov = &iov[0],
> +#ifdef __linux__
> +        .msg_iovlen = 1
> +#else
> +        .msg_iovlen = 2
> +#endif
>      };

>      struct pollfd ufd[1];
> @@ -271,7 +292,7 @@ skip:
>          return NULL;
>      }

> -    if (msg.msg_flags & trunc_flag)
> +    if (len > sys->mtu)
>      {
>          msg_Err(access, "%zd bytes packet truncated (MTU was %zu)",
>                  len, sys->mtu);
-- 
Ilkka Ollakka
"Who is General Failure and why is he reading my hard disk?"
Microsoft spel chekar vor sail, worgs grate !!
		-- Felix von Leitner, leitner at inf.fu-berlin.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-access-udp-use-overflow-block-on-adjusting-mtu.patch
Type: text/x-patch
Size: 3322 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20181028/28243d25/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20181028/28243d25/attachment.sig>


More information about the vlc-devel mailing list