From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: Re: [PATCH 1/2] udp: Don't drop zero-length outbound UDP packets Date: Fri, 09 Sep 2022 20:39:44 +1000 Message-ID: In-Reply-To: <20220909112658.5dccf03a@elisabeth> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1584578105022571807==" --===============1584578105022571807== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 09, 2022 at 11:26:58AM +0200, Stefano Brivio wrote: > On Fri, 9 Sep 2022 14:27:13 +1000 > David Gibson wrote: >=20 > > udp_tap_handler() currently skips outbound packets if they have a payload > > length of zero. This is not correct, since in a datagram protocol zero > > length packets still have meaning. >=20 > Right, nice catch. As far as I can tell it's an issue I added with > commit bb708111833e ("treewide: Packet abstraction with mandatory > boundary checks"). >=20 > > Adjust this to correctly forward the zero-length packets by using a msghdr > > with msg_iovlen =3D=3D 0. > >=20 > > Bugzilla: https://bugs.passt.top/show_bug.cgi?id=3D19 > >=20 > > Signed-off-by: David Gibson > > --- > > udp.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > >=20 > > diff --git a/udp.c b/udp.c > > index c4ebecc..caa852a 100644 > > --- a/udp.c > > +++ b/udp.c > > @@ -1075,19 +1075,19 @@ int udp_tap_handler(struct ctx *c, int af, const = void *addr, > > uh_send =3D packet_get(p, i, 0, sizeof(*uh), &len); > > if (!uh_send) > > return p->count; > > + > > + mm[i].msg_hdr.msg_name =3D sa; > > + mm[i].msg_hdr.msg_namelen =3D sl; > > + count++; > > + > > if (!len) > > continue; > > =20 > > m[i].iov_base =3D (char *)(uh_send + 1); > > m[i].iov_len =3D len; >=20 > I haven't tested this yet, but: >=20 > - shouldn't iov_len be set to 0 (moving also this line before)? Note > that I'm not initialising m >=20 > - shouldn't iov_base point to NULL to avoid noise from valgrind? No, because with this change m[i] is entirely unreferenced by mm[]. > Also: >=20 > > =20 > > - mm[i].msg_hdr.msg_name =3D sa; > > - mm[i].msg_hdr.msg_namelen =3D sl; > > - > > mm[i].msg_hdr.msg_iov =3D m + i; > > mm[i].msg_hdr.msg_iovlen =3D 1; >=20 > ...I guess we should still go through those even if the size is zero, > because we're appending a message. If we don't, I would expect some > subsequent messages in the batch to be dropped (as many as zero sized > packets we have). Here I'm relying on the fact that mm[] (unlike m[]) *is* initialized, so if we don't alter it here, msg_iov is NULL and msg_iovlen is 0. I was looking at removing that initialization, but I haven't gotten that working yet. > That is, I suppose we could just drop the continue statement on if > (!len) above -- but, again, I haven't tested it. My first version actually did that, so it also works, but I think setting msg_iovlen to 0 is a bit neater. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --===============1584578105022571807== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSXpCQUVCQ0FBZEZpRUVvVUx4V3U0L1dz MGRCK1h0Z3lwWTRnRXdZU0lGQW1NYkY5c0FDZ2tRZ3lwWTRnRXcKWVNMa2Z3LzhERUFQZlVSQk9m WmR4NG1meWRwZFo3TnBHQ2ZBYkV3V3MyU3VBWmlnQ0dobTkwTWRqTkxiSGhXQQowYWcxT0tBOHht K3hrajhHTGF5SnkxZDRpM2ZHcnN3aS9pK01nMEh5ZURTd0ZSTGZOdmFyV1J2aSt5Tm80WU1EClJC MjJlVUZLbnRhN1JCYll3RHN2clhUUjFxa3ltMk1SRkhmTFhrSU9GNy9vZ09yRTFYSkRLdzZoM3hO L3RiVk0KMzFMRWt1aWhZdHhQNy9oNE5KUnpJVlQwMVlmL2swWUsrY2dJSXhwNVkxeEo4cE5RdGU4 Q1RueUQ3VElsUlNHNApIbFNNcldYSnJ1KzhXK0NGSWNYdEEwRWNwODZRNnl0UjFpWVFraTVNVlN4 YVlHQ2RRdj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