ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz at gmail.com>
To: ell at lists.01.org
Subject: Re: [PATCH 01/13] net: Add l_net_clear_host_bits utility
Date: Thu, 12 May 2022 11:02:34 -0500	[thread overview]
Message-ID: <9ebeb857-4ac0-9d3f-e47f-182b1758ebf9@gmail.com> (raw)
In-Reply-To: 20220505231539.888792-1-andrew.zaborowski@intel.com

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

Hi Andrew,

On 5/5/22 18:15, Andrew Zaborowski wrote:
> Add function that zeros bits after prefix_len'th bit in an address.  Put
> it in net.h so it can be use by both netconfig.c and icmp6.c,
> potentially others.
> ---
>   ell/net.h | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/ell/net.h b/ell/net.h
> index 0521d75..e193eef 100644
> --- a/ell/net.h
> +++ b/ell/net.h
> @@ -61,6 +61,19 @@ static inline bool l_net_prefix_matches(const void *a, const void *b,
>   	return !bits || ((left ^ right) & (0xff00u >> bits)) == 0;
>   }
>   
> +static inline void l_net_clear_host_bits(uint8_t *address, uint8_t prefix_len,
> +						uint8_t bytes)

I'm not super excited about the naming.  What about l_net_prefix_from_address()? 
  Alternatively, we do have net-private.h where we can stuff this for now and 
not expose it to public API.

> +{
> +	uint8_t last_byte = prefix_len / 8;
> +
> +	if (prefix_len & 7) {
> +		address[last_byte] &= 0xff00 >> (prefix_len & 7);
> +		last_byte++;
> +	}
> +
> +	memset(address + last_byte, 0, bytes - last_byte);
> +}
> +
>   #ifdef __cplusplus
>   }
>   #endif
> 

Regards,
-Denis

             reply	other threads:[~2022-05-12 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 16:02 Denis Kenzior [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-05-13 22:41 [PATCH 01/13] net: Add l_net_clear_host_bits utility Andrew Zaborowski
2022-05-13 14:15 Denis Kenzior
2022-05-13 12:26 Andrew Zaborowski
2022-05-05 23:15 Andrew Zaborowski

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=9ebeb857-4ac0-9d3f-e47f-182b1758ebf9@gmail.com \
    --to=ell@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).