mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brett Sheffield <bacs@librecast.net>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Greg KH <gregkh@linuxfoundation.org>,
	Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net-next] selftests: net: add test for ipv6 fragmentation
Date: Tue, 26 Aug 2025 17:26:10 +0200	[thread overview]
Message-ID: <aK3SEhq1GQFOHKzg@karahi.gladserv.com> (raw)
In-Reply-To: <willemdebruijn.kernel.143e90d593cff@gmail.com>

Thanks for the review, Willem.

On 2025-08-25 12:16, Willem de Bruijn wrote:
> Brett A C Sheffield wrote:
> > Add selftest for the IPv6 fragmentation regression which affected
> > several stable kernels.
> > 
> > Commit a18dfa9925b9 ("ipv6: save dontfrag in cork") was backported to
> > stable without some prerequisite commits.  This caused a regression when
> > sending IPv6 UDP packets by preventing fragmentation and instead
> > returning -1 (EMSGSIZE).
> > 
> > Add selftest to check for this issue by attempting to send a packet
> > larger than the interface MTU. The packet will be fragmented on a
> > working kernel, with sendmsg(2) correctly returning the expected number
> > of bytes sent.  When the regression is present, sendmsg returns -1 and
> > sets errno to EMSGSIZE.
> > 
> > Signed-off-by: Brett A C Sheffield <bacs@librecast.net>
> > Link: https://lore.kernel.org/stable/aElivdUXqd1OqgMY@karahi.gladserv.com
> 
> Thanks for adding a regression test for this.

No problem. I wrote a test for myself when bisecting the problem back in June -
makes sense to convert it to a selftest.

> > +/* we need to set MTU, so do this in a namespace to play nicely */
> > +static int create_namespace(void)
> > +{
> > +	const char *netns_path = "/proc/self/ns/net";
> > +	int fd;
> > +
> > +	if (unshare(CLONE_NEWNET) != 0) {
> > +		perror("unshare");
> > +		return -1;
> > +	}
> 
> Is this not sufficient to move the current process in its own netns?

Yes. Yes it is. Apparently I did not read the man page properly.

> > +	fd = open(netns_path, O_RDONLY);
> > +	if (fd == -1) {
> > +		perror("open");
> > +		return -1;
> > +	}
> > +
> > +	if (setns(fd, CLONE_NEWNET)) {
> > +		perror("setns");
> > +		return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int setup(void)
> > +{
> > +	struct ifreq ifr = {0};
> > +	char ifname[IFNAMSIZ];
> > +	int fd = -1;
> > +	int ctl;
> > +
> > +	if (create_namespace() == -1)
> > +		return -1;
> > +
> > +	ctl = socket(AF_LOCAL, SOCK_STREAM, 0);
> > +	if (ctl == -1)
> > +		return -1;
> > +
> > +	memset(ifname, 0, sizeof(ifname));
> > +	fd = create_interface(ctl, ifname, &ifr);
> > +	if (fd == -1)
> > +		goto err_close_ctl;
> > +	if (disable_dad(ifname) == -1)
> > +		goto err_close_fd;
> > +	if (interface_up(ctl, ifname, &ifr) == -1)
> > +		goto err_close_fd;
> > +	if (set_mtu(ctl, ifname, &ifr) == -1)
> > +		goto err_close_fd;
> > +	usleep(10000); /* give interface a moment to wake up */
> 
> This may be racy. Wait on a more explicit signal? E.g.,
> /sys/class/net/$DEV/operstate.

Good thinking. I'll try that.

> > +	struct msghdr msg = {
> > +		.msg_iov = &iov,
> > +		.msg_iovlen = 1,
> > +		.msg_name = (struct sockaddr *)&sa,
> > +		.msg_namelen = sizeof(sa),
> > +	};
> > +	ssize_t rc;
> > +	int ns_fd;
> > +	int s;
> > +
> > +	printf("Testing IPv6 fragmentation\n");
> > +	ns_fd = setup();
> > +	if (ns_fd == -1)
> > +		return 1;
> > +	s = socket(AF_INET6, SOCK_DGRAM, 0);
> > +	msg.msg_name = (struct sockaddr *)&sa;
> > +	msg.msg_namelen = sizeof(sa);
> 
> nit: duplicate?

Well spotted. Will fix.

> Also, no local address is set. This uses the IPv6 auto assigned
> address?

Correct. The test sends to a link-local scope multicast group from the autoconf
link-local address.  I'll clarify that in the comments at the top of the test.

> > +	rc = sendmsg(s, &msg, 0);
> > +	if (rc == -1) {
> > +		perror("send");
> > +		return 1;
> 
> Probably want to cleanup state both on success and failure.

Ack.

> Could use KSFT_.. exit codes, though 0/1 works just as well for
> kselftests in practice.

Ok.

> > +	} else if (rc != LARGER_THAN_MTU) {
> > +		fprintf(stderr, "send() returned %zi\n", rc);
> > +		return 1;
> > +	}
> > +	close(s);
> > +	close(ns_fd);
> > +
> > +	return 0;
> > +}
> > -- 
> > 2.49.1
> > 

Thanks again - expect a v2 when I have that cleaned up and re-tested.

Cheers,


Brett
--

  reply	other threads:[~2025-08-26 15:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25  9:25 Brett A C Sheffield
2025-08-25 16:16 ` Willem de Bruijn
2025-08-26 15:26   ` Brett Sheffield [this message]
2025-08-31 10:18   ` [PATCH net-next v2] " Brett A C Sheffield
2025-08-31 21:47     ` Willem de Bruijn
2025-08-31 21:41 ` [PATCH net-next] " Willem de Bruijn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aK3SEhq1GQFOHKzg@karahi.gladserv.com \
    --to=bacs@librecast.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®