public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Yalan Zhang <yalzhang@redhat.com>
Subject: Re: [PATCH] dhcp: Fix netmask calculation for option 1 from prefix length
Date: Thu, 16 Feb 2023 14:48:24 +1100	[thread overview]
Message-ID: <Y+2niLsGPL1I4FdM@yekko> (raw)
In-Reply-To: <20230216010752.2224192-1-sbrivio@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]

On Thu, Feb 16, 2023 at 02:07:52AM +0100, Stefano Brivio wrote:
> Similar to the conf_print() fix from commit 4129764ecaeb ("conf: Fix
> mask calculation from prefix_len in conf_print()"): to calculate an
> IPv4 netmask from the prefix length, we need to left shift 32 all-one
> bits by 32 minus the prefix length -- not by the prefix length
> itself.
> 
> Reported-by: Yalan Zhang <yalzhang@redhat.com>
> Fixes: dd09cceaee21 ("Minor improvements to IPv4 netmask handling")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  dhcp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/dhcp.c b/dhcp.c
> index 6088886..edab780 100644
> --- a/dhcp.c
> +++ b/dhcp.c
> @@ -335,7 +335,7 @@ int dhcp(const struct ctx *c, const struct pool *p)
>  	     m->chaddr[3], m->chaddr[4], m->chaddr[5]);
>  
>  	m->yiaddr = c->ip4.addr;
> -	mask.s_addr = htonl(0xffffffff << c->ip4.prefix_len);
> +	mask.s_addr = htonl(0xffffffff << (32 - c->ip4.prefix_len));
>  	memcpy(opts[1].s,  &mask,        sizeof(mask));
>  	memcpy(opts[3].s,  &c->ip4.gw,   sizeof(c->ip4.gw));
>  	memcpy(opts[54].s, &c->ip4.gw,   sizeof(c->ip4.gw));

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2023-02-16  5:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16  1:07 [PATCH] dhcp: Fix netmask calculation for option 1 from prefix length Stefano Brivio
2023-02-16  3:48 ` David Gibson [this message]

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=Y+2niLsGPL1I4FdM@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    --cc=yalzhang@redhat.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.
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).