public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH] ndp: Don't send first periodic router advertisement right after guest connects
Date: Tue, 26 Nov 2024 05:48:03 +0100	[thread overview]
Message-ID: <20241126054803.33a7999a@elisabeth> (raw)
In-Reply-To: <Z0VNDkQxcd4FIoKi@zatzit>

On Tue, 26 Nov 2024 15:22:38 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Nov 25, 2024 at 09:09:05AM +0100, Stefano Brivio wrote:
> >
> > [...]
> >
> > @@ -420,9 +420,13 @@ void ndp_timer(const struct ctx *c, const struct timespec *now)
> >  	interval = min_rtr_adv_interval +
> >  		random() % (max_rtr_adv_interval - min_rtr_adv_interval);
> >  
> > +	if (!next_ra)
> > +		goto first;  
> 
> I don't think avoiding re-indenting two lines is sufficient reason to
> introduce yet another goto, though..
> 
> > +
> >  	info("NDP: sending unsolicited RA, next in %llds", (long long)interval);
> >  
> >  	ndp_ra(c, &in6addr_ll_all_nodes);
> >  
> > +first:
> >  	next_ra = now->tv_sec + interval;
> >  }  

At the cost of one additional line (and zero non-blank lines):

--
$ git diff --patch --stat
 ndp.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/ndp.c b/ndp.c
index 37bf7a3..d1ba867 100644
--- a/ndp.c
+++ b/ndp.c
@@ -420,13 +420,12 @@ void ndp_timer(const struct ctx *c, const struct timespec *now)
        interval = min_rtr_adv_interval +
                random() % (max_rtr_adv_interval - min_rtr_adv_interval);
 
-       if (!next_ra)
-               goto first;
+       if (next_ra) {
+               info("NDP: sending unsolicited RA, next in %llds",
+                    (long long)interval);
 
-       info("NDP: sending unsolicited RA, next in %llds", (long long)interval);
-
-       ndp_ra(c, &in6addr_ll_all_nodes);
+               ndp_ra(c, &in6addr_ll_all_nodes);
+       }
 
-first:
        next_ra = now->tv_sec + interval;
 }
--

we get:

- clarity about the fact that 'next_ra' happens to be 0 on the *first*
  run (the label says it)

- clarity about the fact that it's a special case (it's a goto)

- no wrapped lines

-- 
@@ -420,13 +420,12 @@ void ndp_timer(const struct ctx *c, const struct timespec *now)
        interval = min_rtr_adv_interval +
                random() % (max_rtr_adv_interval - min_rtr_adv_interval);
 
-       if (!next_ra)
-               goto first;
+       if (next_ra) {
+               info("NDP: sending unsolicited RA, next in %llds",
+                    (long long)interval);
 
-       info("NDP: sending unsolicited RA, next in %llds", (long long)interval);
-
-       ndp_ra(c, &in6addr_ll_all_nodes);
+               ndp_ra(c, &in6addr_ll_all_nodes);
+       }
 
-first:
        next_ra = now->tv_sec + interval;
 }
--

we get:

- clarity about the fact that 'next_ra' happens to be 0 on the *first*
  run (the label says it)

- clarity about the fact that it's a special case (it's a goto)

- no wrapped lines

-- 
Stefano


  reply	other threads:[~2024-11-26  4:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25  8:09 [PATCH] ndp: Don't send first periodic router advertisement right after guest connects Stefano Brivio
2024-11-26  4:22 ` David Gibson
2024-11-26  4:48   ` Stefano Brivio [this message]
2024-11-26  5:30     ` David Gibson

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=20241126054803.33a7999a@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).