diff mbox series

[RFC,net-next] rtnetlink: add RTNH_F_REJECT_MASK

Message ID 20211111160240.739294-2-alexander.mikhalitsyn@virtuozzo.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series [RFC,net-next] rtnetlink: add RTNH_F_REJECT_MASK | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4076 this patch: 4076
netdev/cc_maintainers warning 4 maintainers not CCed: yoshfuji@linux-ipv6.org vlad@buslov.dev petrm@nvidia.com dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 825 this patch: 825
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4210 this patch: 4210
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexander Mikhalitsyn Nov. 11, 2021, 4:02 p.m. UTC
Introduce RTNH_F_REJECT_MASK mask which contains
all rtnh_flags which can't be set by the userspace
directly.

This mask will be used in the iproute utility
to exclude rtnh_flags which can't be restored
from "ip route save" image.

This patch doesn't change kernel behavior, but
it looks like we need to prohibit setting
RTNH_F_OFFLOAD, RTNH_F_TRAP flags too.
Am I right?

Please, take a look on
[RFC PATCH iproute2] ip route: save: exclude rtnh_flags which can't be set

Cc: David Miller <davem@davemloft.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Ido Schimmel <idosch@nvidia.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Andrei Vagin <avagin@gmail.com>
Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
---
 include/uapi/linux/rtnetlink.h | 3 +++
 net/ipv4/fib_semantics.c       | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski Nov. 11, 2021, 5:48 p.m. UTC | #1
On Thu, 11 Nov 2021 19:02:40 +0300 Alexander Mikhalitsyn wrote:
> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> index 5888492a5257..c15e591e5d25 100644
> --- a/include/uapi/linux/rtnetlink.h
> +++ b/include/uapi/linux/rtnetlink.h
> @@ -417,6 +417,9 @@ struct rtnexthop {
>  #define RTNH_COMPARE_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN | \
>  				 RTNH_F_OFFLOAD | RTNH_F_TRAP)
>  
> +/* these flags can't be set by the userspace */
> +#define RTNH_F_REJECT_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN)

You should probably drop the _F_ since RTNH_COMPARE_MASK above 
does not have it.
Alexander Mikhalitsyn Nov. 11, 2021, 5:51 p.m. UTC | #2
Dear Jakub,

Thanks for your attention to the patch. Sure, I will do it.

Please, let me know, what do you think about RTNH_F_OFFLOAD,
RTNH_F_TRAP flags? Don't we need to prohibit it too?

Alex

On Thu, Nov 11, 2021 at 8:48 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 11 Nov 2021 19:02:40 +0300 Alexander Mikhalitsyn wrote:
> > diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> > index 5888492a5257..c15e591e5d25 100644
> > --- a/include/uapi/linux/rtnetlink.h
> > +++ b/include/uapi/linux/rtnetlink.h
> > @@ -417,6 +417,9 @@ struct rtnexthop {
> >  #define RTNH_COMPARE_MASK    (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
> >                                RTNH_F_OFFLOAD | RTNH_F_TRAP)
> >
> > +/* these flags can't be set by the userspace */
> > +#define RTNH_F_REJECT_MASK   (RTNH_F_DEAD | RTNH_F_LINKDOWN)
>
> You should probably drop the _F_ since RTNH_COMPARE_MASK above
> does not have it.
Jakub Kicinski Nov. 11, 2021, 5:56 p.m. UTC | #3
On Thu, 11 Nov 2021 20:51:20 +0300 Alexander Mikhalitsyn wrote:
> Thanks for your attention to the patch. Sure, I will do it.
> 
> Please, let me know, what do you think about RTNH_F_OFFLOAD,
> RTNH_F_TRAP flags? Don't we need to prohibit it too?

Looks like an omission indeed but I'll let Dave and Ido comment.

Reminder: please don't top post on the ML.
Alexander Mikhalitsyn Nov. 11, 2021, 6:01 p.m. UTC | #4
On Thu, Nov 11, 2021 at 8:56 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 11 Nov 2021 20:51:20 +0300 Alexander Mikhalitsyn wrote:
> > Thanks for your attention to the patch. Sure, I will do it.
> >
> > Please, let me know, what do you think about RTNH_F_OFFLOAD,
> > RTNH_F_TRAP flags? Don't we need to prohibit it too?
>
> Looks like an omission indeed but I'll let Dave and Ido comment.
Sure.

>
> Reminder: please don't top post on the ML.
Oh, yep. I'm sorry.
David Ahern Nov. 11, 2021, 7:13 p.m. UTC | #5
On 11/11/21 9:02 AM, Alexander Mikhalitsyn wrote:
> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> index 5888492a5257..c15e591e5d25 100644
> --- a/include/uapi/linux/rtnetlink.h
> +++ b/include/uapi/linux/rtnetlink.h
> @@ -417,6 +417,9 @@ struct rtnexthop {
>  #define RTNH_COMPARE_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN | \
>  				 RTNH_F_OFFLOAD | RTNH_F_TRAP)
>  
> +/* these flags can't be set by the userspace */
> +#define RTNH_F_REJECT_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN)
> +
>  /* Macros to handle hexthops */

Userspace can not set any of the flags in RTNH_COMPARE_MASK.
Alexander Mikhalitsyn Nov. 11, 2021, 7:23 p.m. UTC | #6
On Thu, Nov 11, 2021 at 10:13 PM David Ahern <dsahern@gmail.com> wrote:
>
> On 11/11/21 9:02 AM, Alexander Mikhalitsyn wrote:
> > diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> > index 5888492a5257..c15e591e5d25 100644
> > --- a/include/uapi/linux/rtnetlink.h
> > +++ b/include/uapi/linux/rtnetlink.h
> > @@ -417,6 +417,9 @@ struct rtnexthop {
> >  #define RTNH_COMPARE_MASK    (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
> >                                RTNH_F_OFFLOAD | RTNH_F_TRAP)
> >
> > +/* these flags can't be set by the userspace */
> > +#define RTNH_F_REJECT_MASK   (RTNH_F_DEAD | RTNH_F_LINKDOWN)
> > +
> >  /* Macros to handle hexthops */
>
> Userspace can not set any of the flags in RTNH_COMPARE_MASK.

Hi David,

thanks! So, I have to prepare a patch which fixes current checks for rtnh_flags
against RTNH_COMPARE_MASK. So, there is no need to introduce a separate
RTNH_F_REJECT_MASK.
Am I right?

Regards,
Alex
David Ahern Nov. 11, 2021, 10:19 p.m. UTC | #7
[ cc roopa]

On 11/11/21 12:23 PM, Alexander Mikhalitsyn wrote:
> On Thu, Nov 11, 2021 at 10:13 PM David Ahern <dsahern@gmail.com> wrote:
>>
>> On 11/11/21 9:02 AM, Alexander Mikhalitsyn wrote:
>>> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>>> index 5888492a5257..c15e591e5d25 100644
>>> --- a/include/uapi/linux/rtnetlink.h
>>> +++ b/include/uapi/linux/rtnetlink.h
>>> @@ -417,6 +417,9 @@ struct rtnexthop {
>>>  #define RTNH_COMPARE_MASK    (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
>>>                                RTNH_F_OFFLOAD | RTNH_F_TRAP)
>>>
>>> +/* these flags can't be set by the userspace */
>>> +#define RTNH_F_REJECT_MASK   (RTNH_F_DEAD | RTNH_F_LINKDOWN)
>>> +
>>>  /* Macros to handle hexthops */
>>
>> Userspace can not set any of the flags in RTNH_COMPARE_MASK.
> 
> Hi David,
> 
> thanks! So, I have to prepare a patch which fixes current checks for rtnh_flags
> against RTNH_COMPARE_MASK. So, there is no need to introduce a separate
> RTNH_F_REJECT_MASK.
> Am I right?
> 

Added Roopa to double check if Cumulus relies on this for their switchd.

If that answer is no, then there is no need for a new mask.
Roopa Prabhu Nov. 12, 2021, 1:02 a.m. UTC | #8
On 11/11/21 2:19 PM, David Ahern wrote:
> [ cc roopa]
>
> On 11/11/21 12:23 PM, Alexander Mikhalitsyn wrote:
>> On Thu, Nov 11, 2021 at 10:13 PM David Ahern <dsahern@gmail.com> wrote:
>>> On 11/11/21 9:02 AM, Alexander Mikhalitsyn wrote:
>>>> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>>>> index 5888492a5257..c15e591e5d25 100644
>>>> --- a/include/uapi/linux/rtnetlink.h
>>>> +++ b/include/uapi/linux/rtnetlink.h
>>>> @@ -417,6 +417,9 @@ struct rtnexthop {
>>>>   #define RTNH_COMPARE_MASK    (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
>>>>                                 RTNH_F_OFFLOAD | RTNH_F_TRAP)
>>>>
>>>> +/* these flags can't be set by the userspace */
>>>> +#define RTNH_F_REJECT_MASK   (RTNH_F_DEAD | RTNH_F_LINKDOWN)
>>>> +
>>>>   /* Macros to handle hexthops */
>>> Userspace can not set any of the flags in RTNH_COMPARE_MASK.
>> Hi David,
>>
>> thanks! So, I have to prepare a patch which fixes current checks for rtnh_flags
>> against RTNH_COMPARE_MASK. So, there is no need to introduce a separate
>> RTNH_F_REJECT_MASK.
>> Am I right?
>>
> Added Roopa to double check if Cumulus relies on this for their switchd.
>
> If that answer is no, then there is no need for a new mask.
>

yes, these flags are already exposed to userspace and we do use it.

We have also considered optimizations where routing daemons set OFFLOAD 
and drivers clear it when offload fails.

I wont be surprised if other open network os distributions are also 
using it.


Thanks for the headsup David.
David Ahern Nov. 12, 2021, 2:27 a.m. UTC | #9
On 11/11/21 6:02 PM, Roopa Prabhu wrote:
> 
> On 11/11/21 2:19 PM, David Ahern wrote:
>> [ cc roopa]
>>
>> On 11/11/21 12:23 PM, Alexander Mikhalitsyn wrote:
>>> On Thu, Nov 11, 2021 at 10:13 PM David Ahern <dsahern@gmail.com> wrote:
>>>> On 11/11/21 9:02 AM, Alexander Mikhalitsyn wrote:
>>>>> diff --git a/include/uapi/linux/rtnetlink.h
>>>>> b/include/uapi/linux/rtnetlink.h
>>>>> index 5888492a5257..c15e591e5d25 100644
>>>>> --- a/include/uapi/linux/rtnetlink.h
>>>>> +++ b/include/uapi/linux/rtnetlink.h
>>>>> @@ -417,6 +417,9 @@ struct rtnexthop {
>>>>>   #define RTNH_COMPARE_MASK    (RTNH_F_DEAD | RTNH_F_LINKDOWN | \
>>>>>                                 RTNH_F_OFFLOAD | RTNH_F_TRAP)
>>>>>
>>>>> +/* these flags can't be set by the userspace */
>>>>> +#define RTNH_F_REJECT_MASK   (RTNH_F_DEAD | RTNH_F_LINKDOWN)
>>>>> +
>>>>>   /* Macros to handle hexthops */
>>>> Userspace can not set any of the flags in RTNH_COMPARE_MASK.
>>> Hi David,
>>>
>>> thanks! So, I have to prepare a patch which fixes current checks for
>>> rtnh_flags
>>> against RTNH_COMPARE_MASK. So, there is no need to introduce a separate
>>> RTNH_F_REJECT_MASK.
>>> Am I right?
>>>
>> Added Roopa to double check if Cumulus relies on this for their switchd.
>>
>> If that answer is no, then there is no need for a new mask.
>>
> 
> yes, these flags are already exposed to userspace and we do use it.
> 
> We have also considered optimizations where routing daemons set OFFLOAD
> and drivers clear it when offload fails.
> 
> I wont be surprised if other open network os distributions are also
> using it.
> 
> 
> Thanks for the headsup David.
> 

Thanks, Roopa. So then the separate mask is needed.
diff mbox series

Patch

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 5888492a5257..c15e591e5d25 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -417,6 +417,9 @@  struct rtnexthop {
 #define RTNH_COMPARE_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN | \
 				 RTNH_F_OFFLOAD | RTNH_F_TRAP)
 
+/* these flags can't be set by the userspace */
+#define RTNH_F_REJECT_MASK	(RTNH_F_DEAD | RTNH_F_LINKDOWN)
+
 /* Macros to handle hexthops */
 
 #define RTNH_ALIGNTO	4
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index 4c0c33e4710d..7a383c54fe46 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -685,7 +685,7 @@  static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
 			return -EINVAL;
 		}
 
-		if (rtnh->rtnh_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
+		if (rtnh->rtnh_flags & RTNH_F_REJECT_MASK) {
 			NL_SET_ERR_MSG(extack,
 				       "Invalid flags for nexthop - can not contain DEAD or LINKDOWN");
 			return -EINVAL;
@@ -1363,7 +1363,7 @@  struct fib_info *fib_create_info(struct fib_config *cfg,
 		goto err_inval;
 	}
 
-	if (cfg->fc_flags & (RTNH_F_DEAD | RTNH_F_LINKDOWN)) {
+	if (cfg->fc_flags & RTNH_F_REJECT_MASK) {
 		NL_SET_ERR_MSG(extack,
 			       "Invalid rtm_flags - can not contain DEAD or LINKDOWN");
 		goto err_inval;