Message ID | 20190722132344.30798-2-alxndr@bu.edu |
---|---|
State | New |
Headers | show |
Series | Avoid sending zero-size packets | expand |
On 2019/7/22 下午9:24, Oleinik, Alexander wrote: > Virtual devices should not try to send zero-sized packets. The caller > should check the size prior to calling qemu_sendv_packet_async. > > Signed-off-by: Alexander Oleinik <alxndr@bu.edu> > --- > v2: > * Improve the comment to explain the rationale for adding the assert. > net/net.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/net/net.c b/net/net.c > index 7d4098254f..4ad21df36f 100644 > --- a/net/net.c > +++ b/net/net.c > @@ -741,6 +741,15 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender, > size_t size = iov_size(iov, iovcnt); > int ret; > > + /* > + * Since this function returns the size of the sent packets, and a return > + * value of zero indicates that the packet will be sent asynchronously, > + * there is currently no way to report that a 0-sized packet has been sent > + * successfully. Forbid it for now, and if someone needs this functionality > + * later, the API will require a change. > + */ > + assert(size); This probably will make the assertion triggerable from guest. Is this better to warn and return NET_BUFSIZE + 1 here? Thanks > + > if (size > NET_BUFSIZE) { > return size; > }
On 191107 1221, Jason Wang wrote: > > On 2019/7/22 下午9:24, Oleinik, Alexander wrote: > > Virtual devices should not try to send zero-sized packets. The caller > > should check the size prior to calling qemu_sendv_packet_async. > > > > Signed-off-by: Alexander Oleinik <alxndr@bu.edu> > > --- > > v2: > > * Improve the comment to explain the rationale for adding the assert. > > net/net.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/net/net.c b/net/net.c > > index 7d4098254f..4ad21df36f 100644 > > --- a/net/net.c > > +++ b/net/net.c > > @@ -741,6 +741,15 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender, > > size_t size = iov_size(iov, iovcnt); > > int ret; > > + /* > > + * Since this function returns the size of the sent packets, and a return > > + * value of zero indicates that the packet will be sent asynchronously, > > + * there is currently no way to report that a 0-sized packet has been sent > > + * successfully. Forbid it for now, and if someone needs this functionality > > + * later, the API will require a change. > > + */ > > + assert(size); > > > This probably will make the assertion triggerable from guest. Is this better > to warn and return NET_BUFSIZE + 1 here? Will do. I'll send a v3 out with this change. Thank you > Thanks > > > > + > > if (size > NET_BUFSIZE) { > > return size; > > } >
diff --git a/net/net.c b/net/net.c index 7d4098254f..4ad21df36f 100644 --- a/net/net.c +++ b/net/net.c @@ -741,6 +741,15 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender, size_t size = iov_size(iov, iovcnt); int ret; + /* + * Since this function returns the size of the sent packets, and a return + * value of zero indicates that the packet will be sent asynchronously, + * there is currently no way to report that a 0-sized packet has been sent + * successfully. Forbid it for now, and if someone needs this functionality + * later, the API will require a change. + */ + assert(size); + if (size > NET_BUFSIZE) { return size; }
Virtual devices should not try to send zero-sized packets. The caller should check the size prior to calling qemu_sendv_packet_async. Signed-off-by: Alexander Oleinik <alxndr@bu.edu> --- v2: * Improve the comment to explain the rationale for adding the assert. net/net.c | 9 +++++++++ 1 file changed, 9 insertions(+)