2023-09-06 03:12:58

by David Wang

[permalink] [raw]
Subject: Re: [PATCH] uapi/netfilter: Change netfilter hook verdict code definition from macro to enum



At 2023-09-06 00:38:02, "Daniel Xu" <[email protected]> wrote:
>Hi David,
>
>On Mon, Sep 04, 2023 at 09:02:02PM +0800, David Wang wrote:

>> #include <linux/in6.h>
>>
>> /* Responses from hook functions. */
>> -#define NF_DROP 0
>> -#define NF_ACCEPT 1
>> -#define NF_STOLEN 2
>> -#define NF_QUEUE 3
>> -#define NF_REPEAT 4
>> -#define NF_STOP 5 /* Deprecated, for userspace nf_queue compatibility. */
>> -#define NF_MAX_VERDICT NF_STOP
>> +enum {
>> + NF_DROP = 0,
>> + NF_ACCEPT = 1,
>> + NF_STOLEN = 2,
>> + NF_QUEUE = 3,
>> + NF_REPEAT = 4,
>> + NF_STOP = 5, /* Deprecated, for userspace nf_queue compatibility. */
>> + NF_MAX_VERDICT = NF_STOP,
>> +};
>
>Switching from macro to enum works for almost all use cases, but not
>all. If someone if #ifdefing the symbols (which is plausible) this
>change would break them.
>
>I think I've seen some other networking code define both enums and
>macros. But it was a little ugly. Not sure if that is acceptable here or
>not.
>
>[...]
>
>Thanks,
>Daniel


Thanks for the review~
I do not have a strong reasoning to deny the possibility of breaking unexpected usage of this macros,

but I also agree that it is ugly to use both enum and macro at the same time.

Kind of don't know how to proceed from here now...


2023-09-28 12:07:29

by Florian Westphal

[permalink] [raw]
Subject: Re: [PATCH] uapi/netfilter: Change netfilter hook verdict code definition from macro to enum

David Wang <[email protected]> wrote:

Hello,

> At 2023-09-06 00:38:02, "Daniel Xu" <[email protected]> wrote:
> >Hi David,
> >
> >On Mon, Sep 04, 2023 at 09:02:02PM +0800, David Wang wrote:
>
> >> #include <linux/in6.h>
> >>
> >> /* Responses from hook functions. */
> >> -#define NF_DROP 0
> >> -#define NF_ACCEPT 1
> >> -#define NF_STOLEN 2
> >> -#define NF_QUEUE 3
> >> -#define NF_REPEAT 4
> >> -#define NF_STOP 5 /* Deprecated, for userspace nf_queue compatibility. */
> >> -#define NF_MAX_VERDICT NF_STOP
> >> +enum {
> >> + NF_DROP = 0,
> >> + NF_ACCEPT = 1,
> >> + NF_STOLEN = 2,
> >> + NF_QUEUE = 3,
> >> + NF_REPEAT = 4,
> >> + NF_STOP = 5, /* Deprecated, for userspace nf_queue compatibility. */
> >> + NF_MAX_VERDICT = NF_STOP,
> >> +};
> >
> >Switching from macro to enum works for almost all use cases, but not
> >all. If someone if #ifdefing the symbols (which is plausible) this
> >change would break them.
> >
> >I think I've seen some other networking code define both enums and
> >macros. But it was a little ugly. Not sure if that is acceptable here or
> >not.
> >
> >[...]
> >
> >Thanks,
> >Daniel
>
>
> Thanks for the review~
> I do not have a strong reasoning to deny the possibility of breaking unexpected usage of this macros,
>
> but I also agree that it is ugly to use both enum and macro at the same time.
>
> Kind of don't know how to proceed from here now...

I was about to apply this as-is, but Pablo Neira would prefer to
keep the defines as well.

So, as a compromise, I would suggest to just *add*

/* verdicts available to BPF are exported via vmlinux.h */
enum {
NF_DROP = 0,
NF_ACCEPT = 1,
};

#define NF_DROP 0
...

This way BTF won't have the other verdicts, but ATM those
cannot be used in BPF programs anyway.

Would you mind making a new version of the patch?
Otherwise I can mangle it locally here as needed.

2023-10-16 09:38:40

by David Wang

[permalink] [raw]
Subject: Re:Re: [PATCH] uapi/netfilter: Change netfilter hook verdict code definition from macro to enum




At 2023-09-28 19:53:59, "Florian Westphal" <[email protected]> wrote:

>
>I was about to apply this as-is, but Pablo Neira would prefer to
>keep the defines as well.
>
>So, as a compromise, I would suggest to just *add*
>
>/* verdicts available to BPF are exported via vmlinux.h */
>enum {
> NF_DROP = 0,
> NF_ACCEPT = 1,
>};
>
>#define NF_DROP 0
>...
>
>This way BTF won't have the other verdicts, but ATM those
>cannot be used in BPF programs anyway.
>
>Would you mind making a new version of the patch?
>Otherwise I can mangle it locally here as needed.


Sorry for this late response, I got caught up by an unexpected personal "crisis" for quite a long while..
Hope you have already made the change, and it is OK.

David