Output Flag Fixes
cover Output Flag Fixes
A handful of output-flag fixes: some missing documentation, a missing long option, some missing Python methods and a superfluous assigment.
Jeremy Sowden (4):
doc: add missing output flag documentation.
py: add missing output flags.
main: add missing OPT_NUMERIC_PROTO long option.
main: remove duplicate output flag assignment.
doc/libnftables.adoc | 6 ++++++ py/nftables.py | 35 +++++++++++++++++++++++++++++++++++ src/main.c | 5 ++++- 3 files changed, 45 insertions(+), 1 deletion(-)
Signature · 1 line
2.23.0
PATCH 1/4 doc: add missing output flag documentation.
The documentation for NFT_CTX_OUTPUT_FLAG_NUMERIC_TIME and NFT_CTX_OUTPUT_FLAG_NUMERIC_ALL is incomplete. Add the missing bits.
--- doc/libnftables.adoc | 6 ++++++ 1 file changed, 6 insertions(+)
doc/libnftables.adoc +6 -0
@@ -90,6 +90,10 @@ enum { NFT_CTX_OUTPUT_NUMERIC_PROTO = (1 << 7), NFT_CTX_OUTPUT_NUMERIC_PRIO = (1 << 8), NFT_CTX_OUTPUT_NUMERIC_SYMBOL = (1 << 9), + NFT_CTX_OUTPUT_NUMERIC_TIME = (1 << 10), + NFT_CTX_OUTPUT_NUMERIC_ALL = (NFT_CTX_OUTPUT_NUMERIC_PROTO | + NFT_CTX_OUTPUT_NUMERIC_PRIO | + NFT_CTX_OUTPUT_NUMERIC_TIME), NFT_CTX_OUTPUT_TERSE = (1 << 11), }; ----
@@ -122,6 +126,8 @@ NFT_CTX_OUTPUT_NUMERIC_PRIO:: Display base chain priority numerically. NFT_CTX_OUTPUT_NUMERIC_SYMBOL:: Display expression datatype as numeric value. +NFT_CTX_OUTPUT_NUMERIC_TIME:: + Display time, day and hour values in numeric format. NFT_CTX_OUTPUT_NUMERIC_ALL:: Display all numerically. NFT_CTX_OUTPUT_TERSE::
Signature · 1 line
2.23.0
Re: [PATCH nft 1/4] doc: add missing output flag documentation.
Quoted 2 lines · Jeremy Sowden
The documentation for
NFT_CTX_OUTPUT_FLAG_NUMERIC_TIMEandNFT_CTX_OUTPUT_FLAG_NUMERIC_ALLis incomplete. Add the missing bits.
Applied, thanks.
PATCH 2/4 py: add missing output flags.
In reply to Jeremy Sowdenterse and numeric_time are missing from the output_flags dict. Add them and getters and setters for them.
--- py/nftables.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
py/nftables.py +35 -0
@@ -58,6 +58,8 @@ class Nftables: "numeric_proto": (1 << 7), "numeric_prio": (1 << 8), "numeric_symbol": (1 << 9), + "numeric_time": (1 << 10), + "terse": (1 << 11), } validator = None
@@ -305,6 +307,39 @@ class Nftables: """ return self.__set_output_flag("numeric_symbol", val) + def get_numeric_time_output(self): + """Get current status of numeric times output flag. + + Returns a boolean value indicating the status. + """ + return self.__get_output_flag("numeric_time") + + def set_numeric_time_output(self, val): + """Set numeric times output flag. + + Accepts a boolean turning numeric representation of time values + in output either on or off. + + Returns the previous value. + """ + return self.__set_output_flag("numeric_time", val) + + def get_terse_output(self): + """Get the current state of terse output. + + Returns a boolean indicating whether terse output is active or not. + """ + return self.__get_output_flag("terse") + + def set_terse_output(self, val): + """Enable or disable terse output. + + Accepts a boolean turning terse output either on or off. + + Returns the previous value. + """ + return self.__set_output_flag("terse", val) + def get_debug(self): """Get currently active debug flags.
Signature · 1 line
2.23.0
Pablo Neira Ayuso
maintainerRe: [PATCH nft 2/4] py: add missing output flags.
Quoted 2 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.
LGTM.
@Phil, is this fine with you? I let you decide on this.
BTW, would it make sense at some point to remove all the getter/setter per option and use the setter/getter flags approach as in libnftables?
Thanks.
Quoted 61 lines
Signed-off-by Jeremy Sowden <[email protected]>--- py/nftables.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)py/nftables.py +35
-0@@ -58,6 +58,8 @@ class Nftables: "numeric_proto": (1 << 7), "numeric_prio": (1 << 8), "numeric_symbol": (1 << 9), + "numeric_time": (1 << 10), + "terse": (1 << 11), } validator = None@@ -305,6 +307,39 @@ class Nftables: """ return self.__set_output_flag("numeric_symbol", val) + def get_numeric_time_output(self): + """Get current status of numeric times output flag. + + Returns a boolean value indicating the status. + """ + return self.__get_output_flag("numeric_time") + + def set_numeric_time_output(self, val): + """Set numeric times output flag. + + Accepts a boolean turning numeric representation of time values + in output either on or off. + + Returns the previous value. + """ + return self.__set_output_flag("numeric_time", val) + + def get_terse_output(self): + """Get the current state of terse output. + + Returns a boolean indicating whether terse output is active or not. + """ + return self.__get_output_flag("terse") + + def set_terse_output(self, val): + """Enable or disable terse output. + + Accepts a boolean turning terse output either on or off. + + Returns the previous value. + """ + return self.__set_output_flag("terse", val) + def get_debug(self): """Get currently active debug flags.Signature · 1 line
2.23.0
Phil Sutter
reviewerRe: [PATCH nft 2/4] py: add missing output flags.
Hi,
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.LGTM.
@Phil, is this fine with you? I let you decide on this.
I just pushed it. Could you please update Patchwork? I'm not allowed to.
Quoted 2 lines
BTW, would it make sense at some point to remove all the getter/setter per option and use the setter/getter flags approach as in libnftables?
Well, from a compat standpoint we can't remove them. The benefit of those setter/getter methods is the clean interface (user's don't have to memorize flag names) and the semantics of returning the old value. The latter comes in handy when changing flags temporarily.
One could change the private __{g,s}et_output_flag() methods though and make them similar to {g,s}et_debug() methods which probably resemble the syntax you're looking for.
Cheers, Phil
Pablo Neira Ayuso
maintainerRe: [PATCH nft 2/4] py: add missing output flags.
Quoted 13 lines · Phil Sutter
Hi,
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.LGTM.
@Phil, is this fine with you? I let you decide on this.
I just pushed it. Could you please update Patchwork? I'm not allowed to.
Quoted 7 lines
Quoted 2 lines
BTW, would it make sense at some point to remove all the getter/setter per option and use the setter/getter flags approach as in libnftables?
Well, from a compat standpoint we can't remove them. The benefit of those setter/getter methods is the clean interface (user's don't have to memorize flag names) and the semantics of returning the old value. The latter comes in handy when changing flags temporarily.
Probably some transitioning? ie. add the generic set/get flag interface. Update clients of this (Eric's code) to use. Leave the old interfaces for a while there to make sure people have time to migrate. Then remove them.
Anyway, I'm fine if you prefer this more verbose interface for python, no issue.
Quoted 3 lines
One could change the private __{g,s}et_output_flag() methods though and make them similar to {g,s}et_debug() methods which probably resemble the syntax you're looking for.
Hm, not sure what you mean.
Phil Sutter
reviewerRe: [PATCH nft 2/4] py: add missing output flags.
Hi,
Quoted 22 lines · Pablo Neira Ayuso
Quoted 13 lines · Phil Sutter
Hi,
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.LGTM.
@Phil, is this fine with you? I let you decide on this.
I just pushed it. Could you please update Patchwork? I'm not allowed to.
Quoted 7 lines
Quoted 2 lines
BTW, would it make sense at some point to remove all the getter/setter per option and use the setter/getter flags approach as in libnftables?
Well, from a compat standpoint we can't remove them. The benefit of those setter/getter methods is the clean interface (user's don't have to memorize flag names) and the semantics of returning the old value. The latter comes in handy when changing flags temporarily.
Quoted 4 lines
Probably some transitioning? ie. add the generic set/get flag interface. Update clients of this (Eric's code) to use. Leave the old interfaces for a while there to make sure people have time to migrate. Then remove them.
Sounds good!
Quoted 2 lines
Anyway, I'm fine if you prefer this more verbose interface for python, no issue.
Main goal was to keep the bit-fiddling away from users, but a method which accepts an array of flag names (or flag values) and does the binary OR'ing should serve fine, too.
Quoted 5 lines
Quoted 3 lines
One could change the private __{g,s}et_output_flag() methods though and make them similar to {g,s}et_debug() methods which probably resemble the syntax you're looking for.
Hm, not sure what you mean.
I was referring to get_debug() and set_debug() methods of class Nftables. The getter returns an array of debug flag names, the setter accepts either a single flag name/value or an array of those.
Cheers, Phil
Pablo Neira Ayuso
maintainerRe: [PATCH nft 2/4] py: add missing output flags.
Quoted 30 lines · Phil Sutter
Hi,
Quoted 22 lines · Pablo Neira Ayuso
Quoted 13 lines · Phil Sutter
Hi,
Quoted 7 lines · Pablo Neira Ayuso
Quoted 2 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.LGTM.
@Phil, is this fine with you? I let you decide on this.
I just pushed it. Could you please update Patchwork? I'm not allowed to.
Quoted 7 lines
Quoted 2 lines
BTW, would it make sense at some point to remove all the getter/setter per option and use the setter/getter flags approach as in libnftables?
Well, from a compat standpoint we can't remove them. The benefit of those setter/getter methods is the clean interface (user's don't have to memorize flag names) and the semantics of returning the old value. The latter comes in handy when changing flags temporarily.
Quoted 4 lines
Probably some transitioning? ie. add the generic set/get flag interface. Update clients of this (Eric's code) to use. Leave the old interfaces for a while there to make sure people have time to migrate. Then remove them.
Quoted 8 lines
Sounds good!
Quoted 2 lines
Anyway, I'm fine if you prefer this more verbose interface for python, no issue.
Main goal was to keep the bit-fiddling away from users, but a method which accepts an array of flag names (or flag values) and does the binary OR'ing should serve fine, too.
Good.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
One could change the private __{g,s}et_output_flag() methods though and make them similar to {g,s}et_debug() methods which probably resemble the syntax you're looking for.
Hm, not sure what you mean.
I was referring to
get_debug()andset_debug()methods of class Nftables. The getter returns an array of debug flag names, the setter accepts either a single flag name/value or an array of those.
If that's the preferred way to do things in python, rather that using flags like in C, that's fine with me.
Re: [PATCH nft 2/4] py: add missing output flags.
In reply to Jeremy SowdenQuoted 4 lines · Jeremy Sowden
terseandnumeric_timeare missing from theoutput_flagsdict. Add them and getters and setters for them.Signed-off-by Jeremy Sowden <[email protected]>
Applied, thanks!
PATCH 3/4 main: add missing `OPT_NUMERIC_PROTO` long option.
In reply to Jeremy SowdenThe options array is missing an entry for OPT_NUMERIC_PROTO. Add a new option, --numeric-protocol, consistent with the documentation.
--- src/main.c | 4 ++++ 1 file changed, 4 insertions(+)
src/main.c +4 -0
@@ -116,6 +116,10 @@ static const struct option options[] = { .name = "numeric-priority", .val = OPT_NUMERIC_PRIO, }, + { + .name = "numeric-protocol", + .val = OPT_NUMERIC_PROTO, + }, { .name = "numeric-time", .val = OPT_NUMERIC_TIME,
Signature · 1 line
2.23.0
Re: [PATCH nft 3/4] main: add missing `OPT_NUMERIC_PROTO` long option.
Quoted 2 lines · Jeremy Sowden
The
optionsarray is missing an entry forOPT_NUMERIC_PROTO. Add a new option,--numeric-protocol, consistent with the documentation.
Applied, thanks.
PATCH 4/4 main: remove duplicate output flag assignment.
In reply to Jeremy SowdenNFT_CTX_OUTPUT_NUMERIC_TIME is implicit in NFT_CTX_OUTPUT_NUMERIC_ALL: there are is no need explicitly to OR it into output_flags when --numeric is passed.
--- src/main.c | 1 - 1 file changed, 1 deletion(-)
src/main.c +0 -1
@@ -245,7 +245,6 @@ int main(int argc, char * const *argv)break ;case OPT_NUMERIC : output_flags |=NFT_CTX_OUTPUT_NUMERIC_ALL ; - output_flags |=NFT_CTX_OUTPUT_NUMERIC_TIME ;break ;case OPT_STATELESS : output_flags |=NFT_CTX_OUTPUT_STATELESS ;
Signature · 1 line
2.23.0
Pablo Neira Ayuso
maintainerRe: [PATCH nft 4/4] main: remove duplicate output flag assignment.
Quoted 3 lines · Jeremy Sowden
NFT_CTX_OUTPUT_NUMERIC_TIMEis implicit inNFT_CTX_OUTPUT_NUMERIC_ALL: there are is no need explicitly to OR it intooutput_flagswhen--numericis passed.
Also applied, thanks.