nbd/server: Add helper functions for parsing option payload
commit894e02804c862c6940b43a0a488164655d3fb3f0
authorEric Blake <eblake@redhat.com>
Wed, 10 Jan 2018 23:08:24 +0000 (10 17:08 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 18 Jan 2018 02:14:12 +0000 (17 20:14 -0600)
tree9994f5b536c702f336f6c5e34f051ba750c75dcc
parent41f5dfafbb158d2bed0b6abcb7d16b77c56ea5a1
nbd/server: Add helper functions for parsing option payload

Rather than making every callsite perform length sanity checks
and error reporting, add the helper functions nbd_opt_read()
and nbd_opt_drop() that use the length stored in the client
struct; also add an assertion that optlen is 0 before any
option (ie. any previous option was fully handled), complementing
the assertion added in an earlier patch that optlen is 0 after
all negotiation completes.

Note that the call in nbd_negotiate_handle_export_name() does
not use the new helper (in part because the server cannot
reply to NBD_OPT_EXPORT_NAME - it either succeeds or the
connection drops).

Based on patches by Vladimir Sementsov-Ogievskiy.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20180110230825.18321-6-eblake@redhat.com>
nbd/server.c