Re: [PATCH net-next v2] seg6: fool-proof the processing of SRv6 behavior attributes

2021-02-08 Thread patchwork-bot+netdevbpf
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Sat,  6 Feb 2021 18:09:34 +0100 you wrote:
> The set of required attributes for a given SRv6 behavior is identified
> using a bitmap stored in an unsigned long, since the initial design of SRv6
> networking in Linux. Recently the same approach has been used for
> identifying the optional attributes.
> 
> However, the number of attributes supported by SRv6 behaviors depends on
> the size of the unsigned long type which changes with the architecture.
> Indeed, on a 64-bit architecture, an SRv6 behavior can support up to 64
> attributes while on a 32-bit architecture it can support at most 32
> attributes.
> 
> [...]

Here is the summary with links:
  - [net-next,v2] seg6: fool-proof the processing of SRv6 behavior attributes
https://git.kernel.org/netdev/net-next/c/300a0fd8afb1

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




Re: [PATCH net-next v2] seg6: fool-proof the processing of SRv6 behavior attributes

2021-02-07 Thread David Ahern
On 2/6/21 10:09 AM, Andrea Mayer wrote:
> The set of required attributes for a given SRv6 behavior is identified
> using a bitmap stored in an unsigned long, since the initial design of SRv6
> networking in Linux. Recently the same approach has been used for
> identifying the optional attributes.
> 
> However, the number of attributes supported by SRv6 behaviors depends on
> the size of the unsigned long type which changes with the architecture.
> Indeed, on a 64-bit architecture, an SRv6 behavior can support up to 64
> attributes while on a 32-bit architecture it can support at most 32
> attributes.
> 
> To fool-proof the processing of SRv6 behaviors we verify, at compile time,
> that the set of all supported SRv6 attributes can be encoded into a bitmap
> stored in an unsigned long. Otherwise, kernel build fails forcing
> developers to reconsider adding a new attribute or extend the total
> number of supported attributes by the SRv6 behaviors.
> 
> Moreover, we replace all patterns (1 << i) with the macro SEG6_F_ATTR(i) in
> order to address potential overflow issues caused by 32-bit signed
> arithmetic.
> 
> Thanks to Colin Ian King for catching the overflow problem, providing a
> solution and inspiring this patch.
> Thanks to Jakub Kicinski for his useful suggestions during the design of
> this patch.
> 
> v2:
>  - remove the SEG6_LOCAL_MAX_SUPP which is not strictly needed: it can
>be derived from the unsigned long type. Thanks to David Ahern for
>pointing it out.
> 
> Signed-off-by: Andrea Mayer 
> ---
>  net/ipv6/seg6_local.c | 67 +--
>  1 file changed, 39 insertions(+), 28 deletions(-)
> 

Reviewed-by: David Ahern 





[PATCH net-next v2] seg6: fool-proof the processing of SRv6 behavior attributes

2021-02-06 Thread Andrea Mayer
The set of required attributes for a given SRv6 behavior is identified
using a bitmap stored in an unsigned long, since the initial design of SRv6
networking in Linux. Recently the same approach has been used for
identifying the optional attributes.

However, the number of attributes supported by SRv6 behaviors depends on
the size of the unsigned long type which changes with the architecture.
Indeed, on a 64-bit architecture, an SRv6 behavior can support up to 64
attributes while on a 32-bit architecture it can support at most 32
attributes.

To fool-proof the processing of SRv6 behaviors we verify, at compile time,
that the set of all supported SRv6 attributes can be encoded into a bitmap
stored in an unsigned long. Otherwise, kernel build fails forcing
developers to reconsider adding a new attribute or extend the total
number of supported attributes by the SRv6 behaviors.

Moreover, we replace all patterns (1 << i) with the macro SEG6_F_ATTR(i) in
order to address potential overflow issues caused by 32-bit signed
arithmetic.

Thanks to Colin Ian King for catching the overflow problem, providing a
solution and inspiring this patch.
Thanks to Jakub Kicinski for his useful suggestions during the design of
this patch.

v2:
 - remove the SEG6_LOCAL_MAX_SUPP which is not strictly needed: it can
   be derived from the unsigned long type. Thanks to David Ahern for
   pointing it out.

Signed-off-by: Andrea Mayer 
---
 net/ipv6/seg6_local.c | 67 +--
 1 file changed, 39 insertions(+), 28 deletions(-)

diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index b07f7c1c82a4..c2a0c78e84d4 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -31,6 +31,8 @@
 #include 
 #include 
 
+#define SEG6_F_ATTR(i) BIT(i)
+
 struct seg6_local_lwt;
 
 /* callbacks used for customizing the creation and destruction of a behavior */
@@ -660,8 +662,8 @@ seg6_end_dt_mode seg6_end_dt6_parse_mode(struct 
seg6_local_lwt *slwt)
unsigned long parsed_optattrs = slwt->parsed_optattrs;
bool legacy, vrfmode;
 
-   legacy  = !!(parsed_optattrs & (1 << SEG6_LOCAL_TABLE));
-   vrfmode = !!(parsed_optattrs & (1 << SEG6_LOCAL_VRFTABLE));
+   legacy  = !!(parsed_optattrs & SEG6_F_ATTR(SEG6_LOCAL_TABLE));
+   vrfmode = !!(parsed_optattrs & SEG6_F_ATTR(SEG6_LOCAL_VRFTABLE));
 
if (!(legacy ^ vrfmode))
/* both are absent or present: invalid DT6 mode */
@@ -883,32 +885,32 @@ static struct seg6_action_desc seg6_action_table[] = {
},
{
.action = SEG6_LOCAL_ACTION_END_X,
-   .attrs  = (1 << SEG6_LOCAL_NH6),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_NH6),
.input  = input_action_end_x,
},
{
.action = SEG6_LOCAL_ACTION_END_T,
-   .attrs  = (1 << SEG6_LOCAL_TABLE),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_TABLE),
.input  = input_action_end_t,
},
{
.action = SEG6_LOCAL_ACTION_END_DX2,
-   .attrs  = (1 << SEG6_LOCAL_OIF),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_OIF),
.input  = input_action_end_dx2,
},
{
.action = SEG6_LOCAL_ACTION_END_DX6,
-   .attrs  = (1 << SEG6_LOCAL_NH6),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_NH6),
.input  = input_action_end_dx6,
},
{
.action = SEG6_LOCAL_ACTION_END_DX4,
-   .attrs  = (1 << SEG6_LOCAL_NH4),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_NH4),
.input  = input_action_end_dx4,
},
{
.action = SEG6_LOCAL_ACTION_END_DT4,
-   .attrs  = (1 << SEG6_LOCAL_VRFTABLE),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_VRFTABLE),
 #ifdef CONFIG_NET_L3_MASTER_DEV
.input  = input_action_end_dt4,
.slwt_ops   = {
@@ -920,30 +922,30 @@ static struct seg6_action_desc seg6_action_table[] = {
.action = SEG6_LOCAL_ACTION_END_DT6,
 #ifdef CONFIG_NET_L3_MASTER_DEV
.attrs  = 0,
-   .optattrs   = (1 << SEG6_LOCAL_TABLE) |
- (1 << SEG6_LOCAL_VRFTABLE),
+   .optattrs   = SEG6_F_ATTR(SEG6_LOCAL_TABLE) |
+ SEG6_F_ATTR(SEG6_LOCAL_VRFTABLE),
.slwt_ops   = {
.build_state = seg6_end_dt6_build,
  },
 #else
-   .attrs  = (1 << SEG6_LOCAL_TABLE),
+   .attrs  = SEG6_F_ATTR(SEG6_LOCAL_TABLE),
 #endif
.input  = input_action_end_dt6,
},
{