connection: Improve Connection Gateway Debugging and Documentation
cover connection: Improve Connection Gateway Debugging and Documentation
This improves connection gateway debugging with the following changes:
* This introduces and leverages two functions 'gateway_{config,data}_debug' to conditionally log gateway data and configuration at the debug level.
* Expands, exhances, and refactors 'DBG' statements throughout the module to improve symmetry in content, aid in debugging, and to reflect the newly-leveraged 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' macro which, in turn, are wrappers around 'gateway_{config,data}_debug'.
In addition, this adds to or expands on function- and body-level documentation for:
* connection_{add,del}gateway
* __connman_connection_gateway_{add,remove}
* __connman_connection_update_gateway
The aforementioned 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' are supported by log module changes, including:
* Introduces 'CONNMAN_DEBUG_DESC_INSTANTIATE' which declares and instantiates an instance of 'connmand_debug_desc'.
* Replaces 'CONNMAN_DEBUG_DEFINE' with 'CONNMAN_DEBUG_ALIAS' which declares and instantiates an alias (that is, asserts the 'CONNMAN_DEBUG_FLAG_ALIAS' flag) instance of 'connmand_debug_desc', using 'CONNMAN_DEBUG_DESC_INSTANTIATE'.
* Introduces 'CONNMAN_DEBUG' which declares and instantiates an instance of 'connmand_debug_desc', again using 'CONNMAN_DEBUG_DESC_INSTANTIATE', for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.
- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '__FUNCTION__'.
* Redefines 'DBG' against 'CONNMAN_DEBUG' with '__func__' as the function parameter.
Grant Erickson (8):
log: Refactor debugging preprocessor macros.
log: Document debugging preprocessor macros.
connection: Introduce and leverage 'gateway_{config,data}_debug'.
connection: Document 'gateway_{config,data}_debug'.
connection: Expand, Enhance, and Refactor 'DBG'.
connection: Document 'connection_{add,del}gateway'.
connection: Document '__connman_connection_gateway_{add,remove}'.
connection: Document '__connman_connection_update_gateway'.
include/log.h | 141 ++++++++++++++--- src/connection.c | 390 +++++++++++++++++++++++++++++++++++++++++++++-- src/log.c | 2 +- 3 files changed, 502 insertions(+), 31 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/8 log: Refactor debugging preprocessor macros.
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces CONNMAN_DEBUG_DESC_INSTANTIATE which declares and instantiates an instance of 'connmand_debug_desc'.
* Replaces CONNMAN_DEBUG_DEFINE with CONNMAN_DEBUG_ALIAS which declares and instantiates an alias (that is, asserts the CONNMAN_DEBUG_FLAG_ALIAS flag) instance of 'connmand_debug_desc', using CONNMAN_DEBUG_DESC_INSTANTIATE.
* Introduces CONNMAN_DEBUG which declares and instantiates an instance of 'connmand_debug_desc', again using CONNMAN_DEBUG_DESC_INSTANTIATE, for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.
- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '__FUNCTION__' (or __func__).
* Redefines 'DBG' against 'CONNMAN_DEBUG' with '__func__' as the function parameter.
--- include/log.h | 34 +++++++++++++++++++++------------- src/log.c | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-)
include/log.h +21 -13
@@ -58,11 +58,27 @@ struct connman_debug_desc {unsigned int flags; } __attribute__((aligned(8))); -#define CONNMAN_DEBUG_DEFINE (name) \ - static struct connman_debug_desc __debug_alias_ ## name \ +#define CONNMAN_DEBUG_DESC_INSTANTIATE (symbol, _name, _file, _flags) \ + static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ - #name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \ - }; + .name = _name, .file = _file, .flags = _flags \ + } + +#define CONNMAN_DEBUG_ALIAS (suffix) \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ + #suffix, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_ALIAS) + +#define CONNMAN_DEBUG(function, fmt, args...) do { \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ + 0, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_DEFAULT); \ + if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ + connman_debug("%s:%s() " fmt, \ + __FILE__, function, ##args); \ + } while (0)/** * DBG:
@@ -72,15 +88,7 @@ struct connman_debug_desc {* Simple macro around connman_debug() which also include the function * name it is called in. */ -#define DBG(fmt, arg...) do { \ - static struct connman_debug_desc __connman_debug_desc \ - __attribute__((used, section("__debug"), aligned(8))) = { \ - .file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \ - }; \ - if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ - connman_debug("%s:%s() " fmt, \ - __FILE__, __FUNCTION__ , ## arg); \ -} while (0) +#define DBG(fmt, args...) CONNMAN_DEBUG(__func__, fmt, ##args) #ifdef __cplusplus }
src/log.c +1 -1
@@ -38,7 +38,7 @@ static const char *program_exec;static const char *program_path;/* This makes sure we always have a __debug section. */ -CONNMAN_DEBUG_DEFINE (dummy); +CONNMAN_DEBUG_ALIAS (dummy);/** * connman_info:
Signature · 1 line
2.42.0
Re: [PATCH 1/8] log: Refactor debugging preprocessor macros.
Hi Grant,
Quoted 21 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connmand_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.* Introduces
CONNMAN_DEBUGwhich declares and instantiates an instance of 'connmand_debug_desc', again usingCONNMAN_DEBUG_DESC_INSTANTIATE, for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '
__FUNCTION__' (or__func__).
Quoted 6 lines
* Redefines 'DBG' against '
CONNMAN_DEBUG' with '__func__' as the function parameter.
---include/log.h| 34 +++++++++++++++++++++-------------src/log.c| 2 +-2 files changed, 22 insertions(+), 14 deletions(-)
I don’t like this since it ends up bloating the DBG part of it and you spent more time making debug look pretty than making the code look good.
The kernel has a nice concept with pr_fmt where you can overwrite pr_debug on a per file basis. I rather prefer that we adopt such a scheme. It will make things a lot simpler and have less boilerplate.
Long term this needs to get all into ELL and we need to use ELL debug functionality instead of having separate ones in each project.
Regards
Marcel
Re: [PATCH 1/8] log: Refactor debugging preprocessor macros.
Quoted 21 lines · Marcel Holtmann
Quoted 21 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connmand_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.* Introduces
CONNMAN_DEBUGwhich declares and instantiates an instance of 'connmand_debug_desc', again usingCONNMAN_DEBUG_DESC_INSTANTIATE, for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '
__FUNCTION__' (or__func__).
Quoted 8 lines
Quoted 6 lines
* Redefines 'DBG' against '
CONNMAN_DEBUG' with '__func__' as the function parameter.
---include/log.h| 34 +++++++++++++++++++++-------------src/log.c| 2 +-2 files changed, 22 insertions(+), 14 deletions(-)I don’t like this since it ends up bloating the DBG part of it...
Can you clarify? Beyond eliminating the bit of copy-and-paste that was previously in log.h prior to this patch, the emitted and compiled code is identical.
Quoted 1 line
and you spent more time making debug look pretty than making the code look good.
These are both laudable goals and ends and I don’t see a barrier to trading off one for the other.
Making the code look good and function well and correctly is absolutely the top priority.
However, at the end of the day, software is software and humans are humans and getting to perfect can be asymptotically expensive and, perhaps, is never attainable. Moreover, when extending the envelope of functionality on a base of software, particular in the face of limited internals documentation and little to no spatial or temporal access to the original authors of the code to clarify intent, having code that is easily debugged (and well documented) is at least as important.
That said, I think the DBG and -d facilities in connman are both useful and quite ingenious. They are very effective and work and scale far better than sections/modules, etc and other schemes I’ve encountered and used in the past.
But, having spent the last week (and, before that, debugging WISPr/online check) trying to build an understanding of how and where connection.c fits into the overall system, the content and efficacy of the debug output is important.
The end goal for this particular patch was, “How do I achieve a single place for debug-logging the contents of a gateway_config and/or gateway_debug structure (which happens at many places in connection.c), attribute the output to the appropriate call site and function, without copying-and-pasting the DBG to do so in every call site?”
Absent the approach I took, the other alternative is to include a “from %s” in the format such that the log output ends up being:
connmand[16689]: src/connection.c:gateway_data_debug() from __connman_connection_gateway_add() new_gateway 0x7471c060: { index: 4 (eth0), service: 0x72503240 (ethernet_0004f31a5ee0_cable), ipv4_config: 0x7471c030, ipv6_config: (nil), default_checked: 0 } connmand[16689]: src/connection.c:gateway_config_debug() from __connman_connection_gateway_add() ipv4_config 0x7471c030: { flags: 0x0 (), gateway: 0x7511d7f0 (192.168.2.1), vpn_ip: (nil) (<null>), vpn_phy_index: -1 (<null>), vpn_phy_ip: (nil) (<null>) }
which adds an extraneous bit of information which, since it doesn’t aid in debug or understanding, ends up being mental and visual “noise” and doesn’t further the debug goals. However, if that’s preferable to the approach I took, I’m happy to go that direction and recast the patches toward that end. Let me know if that’s an acceptable alternative.
Quoted 1 line
The kernel has a nice concept with
pr_fmtwhere you can overwritepr_debugon a per file basis. I rather prefer that we adopt such a scheme. It will make things a lot simpler and have less boilerplate.
I’d be happy to learn more and take a look. Do you have a link from the kernel git that demonstrates this?
Quoted 1 line
Long term this needs to get all into ELL and we need to use ELL debug functionality instead of having separate ones in each project.
That seems like a great outcome and seems like it would work well with or without these patches: connman_debug_desc becomes ell_debug_desc, and generally anything connman_ or CONNMAN_ namespaced in log.h becomes ell_ or ELL_ namespaced and sourced from ell/log.h (or some such) rather than connman/log.h.
CONNMAN_DEBUG aside, are you otherwise OK with the clean ups and documentation to log.h embodied in this patch?
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] http://www.nuovations.com/
Re: [PATCH 1/8] log: Refactor debugging preprocessor macros.
Hi Grant,
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connmand_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.* Introduces
CONNMAN_DEBUGwhich declares and instantiates an instance of 'connmand_debug_desc', again usingCONNMAN_DEBUG_DESC_INSTANTIATE, for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '
__FUNCTION__' (or__func__).* Redefines 'DBG' against '
CONNMAN_DEBUG' with '__func__' as the function parameter.
---include/log.h| 34 +++++++++++++++++++++-------------src/log.c| 2 +-2 files changed, 22 insertions(+), 14 deletions(-)
Quoted 3 lines
Quoted 1 line
I don’t like this since it ends up bloating the DBG part of it...
Can you clarify? Beyond eliminating the bit of copy-and-paste that was previously in
log.hprior to this patch, the emitted and compiled code is identical.
my presence is that you use DBG() and only that in your code to have debug prints. It is easy to spot and easy to grep for and you can compile it into a nop if you want to.
If you need anything else, it should be a one time thing at the top of your *.c file. My main model is what the kernel called dynamic_debug.
Quoted 12 lines
Quoted 1 line
and you spent more time making debug look pretty than making the code look good.
These are both laudable goals and ends and I don’t see a barrier to trading off one for the other.
Making the code look good and function well and correctly is absolutely the top priority.
However, at the end of the day, software is software and humans are humans and getting to perfect can be asymptotically expensive and, perhaps, is never attainable. Moreover, when extending the envelope of functionality on a base of software, particular in the face of limited internals documentation and little to no spatial or temporal access to the original authors of the code to clarify intent, having code that is easily debugged (and well documented) is at least as important.
That said, I think the DBG and -d facilities in connman are both useful and quite ingenious. They are very effective and work and scale far better than sections/modules, etc and other schemes I’ve encountered and used in the past.
But, having spent the last week (and, before that, debugging WISPr/online check) trying to build an understanding of how and where
connection.cfits into the overall system, the content and efficacy of the debug output is important.
Quoted 8 lines
The end goal for this particular patch was, “How do I achieve a single place for debug-logging the contents of a
gateway_configand/orgateway_debugstructure (which happens at many places inconnection.c), attribute the output to the appropriate call site and function, without copying-and-pasting the DBG to do so in every call site?”Absent the approach I took, the other alternative is to include a “from %s” in the format such that the log output ends up being:
connmand[16689]: src/connection.c:gateway_data_debug() from
__connman_connection_gateway_add()new_gateway0x7471c060: { index: 4 (eth0), service:0x72503240(ethernet_0004f31a5ee0_cable),ipv4_config:0x7471c030,ipv6_config: (nil),default_checked: 0 } connmand[16689]: src/connection.c:gateway_config_debug() from__connman_connection_gateway_add()ipv4_config0x7471c030: { flags:0x0(), gateway:0x7511d7f0(192.168.2.1),vpn_ip: (nil) (<null>),vpn_phy_index: -1 (<null>),vpn_phy_ip: (nil) (<null>) }which adds an extraneous bit of information which, since it doesn’t aid in debug or understanding, ends up being mental and visual “noise” and doesn’t further the debug goals. However, if that’s preferable to the approach I took, I’m happy to go that direction and recast the patches toward that end. Let me know if that’s an acceptable alternative.
We currently only have the PRINT flag (and so does ELL btw), but the kernel has a lot more flags that define on how the output looks like and what information are printed. I would thing that is the way to go. Have a generic DBG statement and then decide from command line or some external input what gets printed in the debug logs.
That said, I never thought about printing the call of the current function. That is a nice idea and in indeed really useful at times. So yes, we should have an option for that.
Quoted 3 lines
Quoted 1 line
The kernel has a nice concept with
pr_fmtwhere you can overwritepr_debugon a per file basis. I rather prefer that we adopt such a scheme. It will make things a lot simpler and have less boilerplate.I’d be happy to learn more and take a look. Do you have a link from the kernel git that demonstrates this?
https://www.kernel.org/doc/html/next/core-api/printk-basics.html
This would be a starting point. Essentially you define pr_fmt(fmt) and that modifies you pr_* type of functions. If you grep for pr_fmt than you see how different subsystems, drivers etc. define it and have specific information for their needs.
For example for Bluetooth we did a real simple one:
#define pr_fmt(fmt) "Bluetooth: “ fmt
And that ends up providing the string Bluetooth: as prefix for every message printed. Was properly a bad idea, but this way we didn’t have to change any log messages we had.
Some add KBUILD_NAME or the DRVNAME or other details in there.
If you look at include/linux/dynamic_debug.h you see all the flags the kernel currently supports.
#define _DPRINTK_FLAGS_NONE 0
#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ #define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
#define _DPRINTK_FLAGS_INCL_TID (1<<4)
#define _DPRINTK_FLAGS_INCL_SOURCENAME (1<<5)
So I prefer to do something similar and then just modify these via a command line switch. Right now we basically just do a BLOB pattern, but we could do more.
Quoted 5 lines
Quoted 1 line
Long term this needs to get all into ELL and we need to use ELL debug functionality instead of having separate ones in each project.
That seems like a great outcome and seems like it would work well with or without these patches:
connman_debug_descbecomesell_debug_desc, and generally anythingconnman_orCONNMAN_namespaced inlog.hbecomesell_orELL_namespaced and sourced fromell/log.h(or some such) rather thanconnman/log.h.
CONNMAN_DEBUGaside, are you otherwise OK with the clean ups and documentation tolog.hembodied in this patch?
I am fine with all the cleanups, but I prefer you don’t introduce CONNMAN_DEBUG and stick with DBG instead and we try to figure out on how to make DBG work the way you want to use it.
Regards
Marcel
Re: [PATCH 1/8] log: Refactor debugging preprocessor macros.
Quoted 28 lines · Marcel Holtmann
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connmand_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.* Introduces
CONNMAN_DEBUGwhich declares and instantiates an instance of 'connmand_debug_desc', again usingCONNMAN_DEBUG_DESC_INSTANTIATE, for controlling an invocation of 'connman_debug' with it that includes both the file and function name the macro was invoked in or attributed to.- The key difference between this and 'DBG' is that this allows the caller to specify the function string rather than relying on '
__FUNCTION__' (or__func__).* Redefines 'DBG' against '
CONNMAN_DEBUG' with '__func__' as the function parameter.
---include/log.h| 34 +++++++++++++++++++++-------------src/log.c| 2 +-2 files changed, 22 insertions(+), 14 deletions(-)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I don’t like this since it ends up bloating the DBG part of it...
CONNMAN_DEBUGaside, are you otherwise OK with the clean ups and documentation tolog.hembodied in this patch?I am fine with all the cleanups, but I prefer you don’t introduce
CONNMAN_DEBUGand stick with DBG instead and we try to figure out on how to make DBG work the way you want to use it.
Resubmitted as a v2 patch with the suggested revisions.
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] http://www.nuovations.com/
PATCH 2/8 log: Document debugging preprocessor macros.
In reply to Grant EricksonThis adds documentation to the following debugging- / debug logging-related data types and preprocessor macros:
* connman_debug_desc
* CONNMAN_DEBUG_DESC_INSTANTIATE
* CONNMAN_DEBUG_ALIAS
* CONNMAN_DEBUG
and expands the existing documentation for the 'DBG' preprocessor macro.
--- include/log.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 5 deletions(-)
include/log.h +102 -5
@@ -49,6 +49,10 @@ void connman_debug(const char *format, ...) } \ }while (0 ) +/** +* Debug-level logging descriptor that may be used to control debug +* output on a per-file or -symbol basis. +*/ struct connman_debug_desc {const char *name;const char *file;
@@ -58,18 +62,88 @@ struct connman_debug_desc {unsigned int flags; } __attribute__((aligned(8))); +/** +* @def CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) +* +* @brief +* Convenience preprocessor macro for declaring and instantiating an +* instance of #connmand_debug_desc. +* +* @param[in] symbol The name of the #connman_debug_desc instance +* to instantiate. +* @param[in] _name An optional pointer to an immutable null- +* terminated C string containing the name of +* the #connman_debug_desc- controlled symbol. +* @param[in] _file A pointer to an immutable null-terminated C +* string containing the name of the +* #connman_debug_desc-controlled source file. +* @param[in] _flags Flags that control the interpretation and +* behavior of the instantiated +* #connman_debug_desc instance. +* +*/ #define CONNMAN_DEBUG_DESC_INSTANTIATE (symbol, _name, _file, _flags) \ static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ .name = _name, .file = _file, .flags = _flags \ } +/** +* @def CONNMAN_DEBUG_ALIAS(suffix) +* +* @brief +* Convenience preprocessor macro for declaring and instantiating +* an alias (see #CONNMAN_DEBUG_FLAG_ALIAS) instance of +* #connmand_debug_desc. +* +* @param[in] suffix The suffix to concatenate to the name of the +* #connman_debug_desc alias instance to +* instantiate. +* +*/ #define CONNMAN_DEBUG_ALIAS (suffix) \ CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ #suffix, \ __FILE__, \ CONNMAN_DEBUG_FLAG_ALIAS) +/** +* @def CONNMAN_DEBUG(function, fmt, args...) +* +* @brief +* Convenience preprocessor macro for declaring and instantiating +* an instance of #connmand_debug_desc for controlling an +* invocation of #connman_debug with it that includes both the +* file and function name the macro was invoked in or attributed +* to. +* +* This instantiates a scoped-instance of #connmand_debug_desc and +* then, if that instance has its #CONNMAN_DEBUG_FLAG_PRINT flag +* asserted, invokes a call to #connman_debug with the format: +* +* "<file>:<function>() <fmt> ..." +* +* where <file> is the preprocessor symbol __FILE__, <function> is +* caller-specified, <fmt> is from @a fmt, and '...' is from @a +* 'args...'. +* +* @param[in] function A pointer to an immutble null-terminated C +* string containing the name of the function +* in which the macro is being instantiated or +* to which the invocation of the macro should +* be attributed to. For example, __FUNCTION__. +* @param[in] fmt A pointer to an immutable null-terminated C +* string container the log message, consisting +* of a printf-style format string composed of +* zero or more output conversion directives. +* @param[in] args... A variadic argument list, where each +* argument corresponds with its peer output +* conversion directive in @a fmt. +* +* @sa CONNMAN_DEBUG_DESC_INSTANTIATE +* @sa connman_debug +* +*/ #define CONNMAN_DEBUG(function, fmt, args...) do { \ CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ 0, \
@@ -81,12 +155,35 @@ struct connman_debug_desc { }while (0 )/** -* DBG: -* @fmt: format string -* @arg...: list of arguments +* @def DBG(fmt, args...) +* +* @brief +* Convenience preprocessor macro for declaring an instance of +* #connmand_debug_desc for controlling an invocation of +* #connman_debug with it that includes both the file and function +* name the macro was invoked in. +* +* This instantiates a scoped-instance of #connmand_debug_desc and +* then, if that instance has its #CONNMAN_DEBUG_FLAG_PRINT flag +* asserted, invokes a call to #connman_debug with the format: +* +* "<file>:<function>() <fmt> ..." +* +* where <file> is the preprocessor symbol __FILE__, <function> is +* the preprocessor symbol __func__, <fmt> is from @a fmt, and +* '...' is from @a 'args...'. +* +* @param[in] fmt A pointer to an immutable null-terminated C +* string container the log message, consisting +* of a printf-style format string composed of +* zero or more output conversion directives. +* @param[in] args... A variadic argument list, where each +* argument corresponds with its peer output +* conversion directive in @a fmt. +* +* @sa CONNMAN_DEBUG +* @sa connman_debug * -* Simple macro around connman_debug() which also include the function -* name it is called in. */ #define DBG(fmt, args...) CONNMAN_DEBUG(__func__, fmt, ##args)
Signature · 1 line
2.42.0
PATCH 3/8 connection: Introduce and leverage 'gateway_{config,data}_debug'.
In reply to Grant EricksonThis introduces and leverages two functions 'gateway_{config,data}_debug' to conditionally log gateway data and configuration at the debug level.
--- src/connection.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-)
src/connection.c +117 -2
@@ -32,6 +32,12 @@#include "connman.h" +#define GATEWAY_CONFIG_DBG (description, config) \ + gateway_config_debug(__func__, description, config) + +#define GATEWAY_DATA_DBG (description, data) \ + gateway_data_debug(__func__, description, data) +struct gateway_config {bool active;char *gateway;
@@ -53,6 +59,79 @@ struct gateway_data {static GHashTable *gateway_hash =NULL ; +static const char *maybe_null (const void *pointer) +{ +return pointer ? pointer :"<null>" ; +} + +static void gateway_config_debug (const char *function, +const char *description, +const struct gateway_config *config) +{ + g_autofree char *vpn_phy_interface = NULL; + +if (!function || !description) +return ; + +if (!config) +CONNMAN_DEBUG (function,"%s %p" , description, config); +else { +if (config->vpn_phy_index >=0 ) + vpn_phy_interface = +connman_inet_ifname (config->vpn_phy_index); + +CONNMAN_DEBUG (function, +"%s %p: { active: %u, gateway: %p (%s), " +"vpn: %u, vpn_ip: %p (%s), vpn_phy_index: %d (%s), " +"vpn_phy_ip: %p (%s) }" , + description, + config, + config->active, + config->gateway,maybe_null (config->gateway), + config->vpn, + config->vpn_ip,maybe_null (config->vpn_ip), + config->vpn_phy_index,maybe_null (vpn_phy_interface), + config->vpn_phy_ip,maybe_null (config->vpn_phy_ip)); + } +} + +static void gateway_data_debug (const char *function, +const char *description, +const struct gateway_data *data) +{ + g_autofree char *interface = NULL; + +if (!function || !description) +return ; + +if (!data) +CONNMAN_DEBUG (function,"%s %p" , description, data); +else { + interface =connman_inet_ifname (data->index); + +CONNMAN_DEBUG (function, +"%s %p: { index: %d (%s), service: %p (%s), " +"ipv4_gateway: %p, ipv6_gateway: %p, default_checked: %u }" , + description, + data, + data->index, +maybe_null (interface), + data->service, +connman_service_get_identifier (data->service), + data->ipv4_gateway, + data->ipv6_gateway, + data->default_checked); + +if (data->ipv4_gateway) +gateway_config_debug (function,"ipv4_gateway" , + data->ipv4_gateway); + +if (data->ipv6_gateway) +gateway_config_debug (function,"ipv6_gateway" , + data->ipv6_gateway); + } +} +static struct gateway_config *find_gateway (int index,const char *gateway) {GHashTableIter iter;
@@ -282,6 +361,8 @@ static int del_routes(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -334,6 +415,8 @@ static int disable_gateway(struct gateway_data *data, {bool active = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) {if (data->ipv4_gateway) active = data->ipv4_gateway->active;
@@ -426,6 +509,8 @@ static void set_default_gateway(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -507,6 +592,8 @@ static void unset_default_gateway(struct gateway_data *data,int index;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -586,6 +673,9 @@ static bool choose_default_gateway(struct gateway_data *data, {bool downgraded = false; +GATEWAY_DATA_DBG ("data" , data); +GATEWAY_DATA_DBG ("candidate" , candidate); +/* * If the current default is not active, then we mark * this one as default. If the other one is already active
@@ -641,6 +731,8 @@ static void connection_newgateway(int index, const char *gateway)if (!config)return ; +GATEWAY_CONFIG_DBG ("config" , config); + config->active = true;/*
@@ -652,6 +744,8 @@ static void connection_newgateway(int index, const char *gateway)if (!data)return ; +GATEWAY_DATA_DBG ("data" , data); +if (data->default_checked)return ;
@@ -690,6 +784,8 @@ static void remove_gateway(gpointer user_data)DBG ("gateway ipv4 %p ipv6 %p" , data->ipv4_gateway, data->ipv6_gateway); +GATEWAY_DATA_DBG ("data" , data); +if (data->ipv4_gateway) {g_free (data->ipv4_gateway->gateway);g_free (data->ipv4_gateway->vpn_ip);
@@ -717,12 +813,18 @@ static void connection_delgateway(int index, const char *gateway)DBG ("index %d gateway %s" , index, gateway); config =find_gateway (index, gateway); -if (config) +if (config) { +GATEWAY_CONFIG_DBG ("config" , config); + config->active = false; + } data =find_default_gateway (); -if (data) +if (data) { +GATEWAY_DATA_DBG ("data" , data); +set_default_gateway (data,CONNMAN_IPCONFIG_TYPE_ALL ); + } }static struct connman_rtnl connection_rtnl = {
@@ -836,11 +938,15 @@ int __connman_connection_gateway_add(struct connman_service *service,if (!new_gateway)return -EINVAL ; +GATEWAY_DATA_DBG ("new_gateway" , new_gateway); + active_gateway =find_active_gateway ();DBG ("active %p index %d new %p" , active_gateway, active_gateway ? active_gateway->index :-1 , new_gateway); +GATEWAY_DATA_DBG ("active_gateway" , active_gateway); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 && new_gateway->ipv4_gateway) {add_host_route (AF_INET , index, gateway, service_type);
@@ -931,6 +1037,8 @@ void __connman_connection_gateway_remove(struct connman_service *service,if (!data)return ; +GATEWAY_DATA_DBG ("service_data" , data); +if (do_ipv4 && data->ipv4_gateway) set_default4 = data->ipv4_gateway->vpn;
@@ -977,6 +1085,9 @@ void __connman_connection_gateway_remove(struct connman_service *service,*/ if (set_default4 || set_default6 || err <0 ) { data =find_default_gateway (); + +GATEWAY_DATA_DBG ("default_data" , data); +if (data)set_default_gateway (data, type); }
@@ -996,6 +1107,8 @@ bool __connman_connection_update_gateway(void)DBG ("default %p" , default_gateway); +GATEWAY_DATA_DBG ("default_gateway" , default_gateway); +/* * There can be multiple active gateways so we need to * check them all.
@@ -1005,6 +1118,8 @@ bool __connman_connection_update_gateway(void)while (g_hash_table_iter_next (&iter, &key, &value)) {struct gateway_data *active_gateway = value; +GATEWAY_DATA_DBG ("active_gateway" , active_gateway); +if (active_gateway == default_gateway)continue ;
Signature · 1 line
2.42.0
PATCH 4/8 connection: Document 'gateway_{config,data}_debug'.
In reply to Grant EricksonThis adds documentation to the 'gateway_{config,data}_debug' functions.
--- src/connection.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
src/connection.c +57 -0
@@ -59,11 +59,45 @@ struct gateway_data {static GHashTable *gateway_hash =NULL ; +/** +* @brief +* Return the specified pointer if non-null; otherwise, the +* immutable "<null>" string. +* +* @param[in] pointer The pointer to be returned if non-null. +* +* @returns +* @a pointer if non-null; otherwise the "<null>" immutable +* null-terminated C string. +* +*/ static const char *maybe_null (const void *pointer) {return pointer ? pointer :"<null>" ; } +/** +* @brief +* Conditionally log the specified gateway configuration. +* +* This conditionally logs at the debug level the specified +* #gateway_config gateway configuration, @a config, with the +* provided description, @a description, attributed to the provided +* function name, @a function. +* +* @param[in] function A pointer to an immutable null-terminated +* C string containing the function name to +* which the call to this function should be +* attributed. +* @param[in] description A pointer to an immutable null-terminated +* C string briefly describing @a +* config. For example, "ipv4_config". +* @param[in] config A pointer to the immutable gateway +* configuration to conditionally log. +* +* @sa CONNMAN_DEBUG +* +*/ static void gateway_config_debug (const char *function,const char *description,const struct gateway_config *config)
@@ -95,6 +129,29 @@ static void gateway_config_debug(const char *function, } } +/** +* @brief +* Conditionally log the specified gateway data. +* +* This conditionally logs at the debug level the specified +* #gateway_data gateway data, @a data, with the provided +* description, @a description, attributed to the provided function +* name, @a function. +* +* @param[in] function A pointer to an immutable null-terminated +* C string containing the function name to +* which the call to this function should be +* attributed. +* @param[in] description A pointer to an immutable null-terminated +* C string briefly describing @a +* data. For example, "default_gateway". +* @param[in] data A pointer to the immutable gateway +* data to conditionally log. +* +* @sa CONNMAN_DEBUG +* @sa gateway_config_debug +* +*/ static void gateway_data_debug (const char *function,const char *description,const struct gateway_data *data)
Signature · 1 line
2.42.0
PATCH 5/8 connection: Expand, Enhance, and Refactor 'DBG'.
In reply to Grant EricksonThis expands, exhances, and refactors 'DBG' statements throughout the module to improve symmetry in content, aid in debugging, and to reflect the newly-leveraged 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' macros.
--- src/connection.c | 52 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-)
src/connection.c +44 -8
@@ -566,6 +566,9 @@ static void set_default_gateway(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +DBG ("data %p type %d (%s)" , data, + type,__connman_ipconfig_type2string (type)); +GATEWAY_DATA_DBG ("data" , data);if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 )
@@ -575,9 +578,6 @@ static void set_default_gateway(struct gateway_data *data,else do_ipv4 = do_ipv6 = true; -DBG ("type %d gateway ipv4 %p ipv6 %p" , type, data->ipv4_gateway, - data->ipv6_gateway); -if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn) {connman_inet_set_gateway_interface (data->index);
@@ -649,6 +649,9 @@ static void unset_default_gateway(struct gateway_data *data,int index;bool do_ipv4 = false, do_ipv6 = false; +DBG ("data %p type %d (%s)" , data, + type,__connman_ipconfig_type2string (type)); +GATEWAY_DATA_DBG ("data" , data);if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 )
@@ -776,13 +779,17 @@ static bool choose_default_gateway(struct gateway_data *data,static void connection_newgateway (int index,const char *gateway) { + g_autofree char *interface = NULL;struct gateway_config *config;struct gateway_data *data;GHashTableIter iter;gpointer value, key;bool found = false; -DBG ("index %d gateway %s" , index, gateway); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), + gateway); config =find_gateway (index, gateway);if (!config)
@@ -839,7 +846,7 @@ static void remove_gateway(gpointer user_data) {struct gateway_data *data = user_data; -DBG ("gateway ipv4 %p ipv6 %p" , data->ipv4_gateway, data->ipv6_gateway); +DBG ("data %p" , data);GATEWAY_DATA_DBG ("data" , data);
@@ -864,10 +871,14 @@ static void remove_gateway(gpointer user_data)static void connection_delgateway (int index,const char *gateway) { + g_autofree char *interface = NULL;struct gateway_config *config;struct gateway_data *data; -DBG ("index %d gateway %s" , index, gateway); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), + gateway); config =find_gateway (index, gateway);if (config) {
@@ -974,9 +985,20 @@ int __connman_connection_gateway_add(struct connman_service *service,enum connman_service_type service_type =connman_service_get_type (service);int index; + g_autofree char *interface = NULL; + +DBG ("service %p (%s) gateway %p (%s) type %d (%s) peer %p (%s)" , + service,maybe_null (connman_service_get_identifier (service)), + gateway,maybe_null (gateway), + type,__connman_ipconfig_type2string (type), + peer,maybe_null (peer)); index =__connman_service_get_index (service); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s)" , index,maybe_null (interface)); +/* * If gateway is NULL, it's a point to point link and the default * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
@@ -1077,9 +1099,21 @@ void __connman_connection_gateway_remove(struct connman_service *service,struct gateway_data *data =NULL ;bool set_default4 = false, set_default6 = false;bool do_ipv4 = false, do_ipv6 = false; +int index; + g_autofree char *interface = NULL;int err; -DBG ("service %p type %d" , service, type); +DBG ("service %p (%s) type %d (%s)" , + service,maybe_null (connman_service_get_identifier (service)), + type,__connman_ipconfig_type2string (type)); + + index =__connman_service_get_index (service); +if (index <0 ) +return ; + + interface =connman_inet_ifname (index); + +DBG ("index %d (%s)" , index,maybe_null (interface));if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;
@@ -1157,12 +1191,14 @@ bool __connman_connection_update_gateway(void)GHashTableIter iter;gpointer value, key; +DBG ("" ); +if (!gateway_hash)return updated; default_gateway =find_default_gateway (); -DBG ("default %p" , default_gateway); +DBG ("default_gateway %p" , default_gateway);GATEWAY_DATA_DBG ("default_gateway" , default_gateway);
Signature · 1 line
2.42.0
PATCH 6/8 connection: Document 'connection_{add,del}gateway'.
In reply to Grant EricksonThis adds documentation to the 'connection_{add,del}gateway' functions.
--- src/connection.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
src/connection.c +67 -0
@@ -777,6 +777,29 @@ static bool choose_default_gateway(struct gateway_data *data,return downgraded; } +/** +* @brief +* Handler for gateway, or default route, -specific routes newly +* added to the Linux kernel routing tables. +* +* This is the Linux Routing Netlink (rtnl) handler for gateway, or +* default route, -specific routes newly-added to the Linux kernel +* routing tables. Its primary role and goal is to serve as a +* round-trip acknowledgement that gateway-, or default route, +* related routes added or set to the kernel are now active and in +* use. +* +* @param[in] index The network interface index associated with +* the newly-added gateway, or default router. +* @param[in] gateway An pointer to an immutable null-terminated +* C string containing the text- +* formatted address of the gateway, or default +* router, that was added. +* +* @sa set_default_gateway +* @sa connection_delgateway +* +*/ static void connection_newgateway (int index,const char *gateway) { g_autofree char *interface = NULL;
@@ -791,12 +814,23 @@ static void connection_newgateway(int index, const char *gateway)DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), gateway); +/* +* If there is no gateway configuration, then this is not a +* gateway, or default router, route we added or +* set. Consequently, ignore it and return. +*/ config =find_gateway (index, gateway);if (!config)return ;GATEWAY_CONFIG_DBG ("config" , config); +/* +* Otherwise, this is a gateway, or default router, route we added +* or set and it is now acknowledged by the kernel. Consequently, +* prospectively mark it as active; however, this may be +* subsequently modified as default route determinations are made. +*/ config->active = true;/*
@@ -869,6 +903,29 @@ static void remove_gateway(gpointer user_data)g_free (data); } +/** +* @brief +* Handler for gateway, or default route, -specific routes newly +* removed from the Linux kernel routing tables. +* +* This is the Linux Routing Netlink (rtnl) handler for gateway, or +* default route, -specific routes newly-removed from the Linux +* kernel routing tables. Its primary role and goal is to serve as +* a round-trip acknowledgement that gateway-, or default route, +* related routes removed or cleared from the kernel are now inactive +* and are no longer in use. +* +* @param[in] index The network interface index associated with +* the newly-removed gateway, or default router. +* @param[in] gateway An pointer to an immutable null-terminated +* C string containing the text- +* formatted address of the gateway, or default +* router, that was removed. +* +* @sa connection_newgateway +* @sa set_default_gateway +* +*/ static void connection_delgateway (int index,const char *gateway) { g_autofree char *interface = NULL;
@@ -880,6 +937,10 @@ static void connection_delgateway(int index, const char *gateway)DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), gateway); +/* +* This ends the lifecycle of the gateway associated with the +* newly-removed route; mark it as no longer active. +*/ config =find_gateway (index, gateway);if (config) {GATEWAY_CONFIG_DBG ("config" , config);
@@ -887,6 +948,12 @@ static void connection_delgateway(int index, const char *gateway) config->active = false; } +/* +* Due to the newly-removed gateway route, there may have been a +* concomitant change in service order that has resulted in a new, +* default service, if any. If so, ensure that service acquires +* the high priority default route. +*/ data =find_default_gateway ();if (data) {GATEWAY_DATA_DBG ("data" , data);
Signature · 1 line
2.42.0
PATCH 7/8 connection: Document '__connman_connection_gateway_{add,remove}'.
In reply to Grant EricksonThis adds documentation to the '__connman_connection_gateway_{add,remove}' functions.
--- src/connection.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-)
src/connection.c +71 -2
@@ -1040,6 +1040,41 @@ static void add_host_route(int family, int index, const char *gateway, } } +/** +* @brief +* Add, or set, the gateway, or default router, for a network +* service. +* +* This attempts to add, or set, the gateway, or default router, for +* a network service using the specified IP configuration gateway +* address and network interface index as the lookup key for the +* network service. +* +* @param[in,out] service A pointer to the mutable network service +* for which to add a gateway, or default +* router. +* @param[in] gateway An optional pointer to an immutable null- +* terminated C string containing the +* text-formatted address of the gateway, or +* default router, to add to or associate +* with @a service. +* @param[in] type The IP configuration type for which +* gateway, or default router, is to be +* added. +* @param[in] peer An optional pointer to an immutable null- +* terminated C string containing the +* text-formatted address of the network +* peer, for point-to-point links, +* associated with the gateway. +* +* @retval 0 If successful. +* @retval -EINVAL If service is null or if network interface +* index associated with @a service is invalid. +* +* @sa __connman_connection_gateway_remove +* @sa __connman_connection_update_gateway +* +*/ int __connman_connection_gateway_add(struct connman_service *service, const char *gateway, enum connman_ipconfig_type type,
@@ -1160,6 +1195,30 @@ done:return 0 ; } +/** +* @brief +* Remove, or clear, the gateway, or default router, for a network +* service. +* +* This attempts to remove, or clear, the gateway, or default router, +* for a network service using the specified network service and IP +* configuration type. +* +* @param[in,out] service A pointer to the mutable network service +* for which to remove, or clear, a gateway, +* or default router. +* @param[in] type The IP configuration type for which +* gateway, or default router, is to be +* removed. +* +* @retval 0 If successful. +* @retval -EINVAL If service is null or if network interface +* index associated with @a service is invalid. +* +* @sa __connman_connection_gateway_add +* @sa __connman_connection_update_gateway +* +*/ void __connman_connection_gateway_remove (struct connman_service *service,enum connman_ipconfig_type type) {
@@ -1189,8 +1248,14 @@ void __connman_connection_gateway_remove(struct connman_service *service,else do_ipv4 = do_ipv6 = true; +/* Delete any routes associated with this service's nameservers. */ +__connman_service_nameserver_del_routes (service, type); +/* +* If there is no hash table / map entry for this service, then +* there are no gateways associated with it; simply return. +*/ data =g_hash_table_lookup (gateway_hash, service);if (!data)return ;
@@ -1208,6 +1273,8 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway ? data->ipv6_gateway->gateway :"<null>" , set_default4, set_default6); +/* If necessary, delete any VPN-related host routes. */ +if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn && data->index >=0 ) connman_inet_del_host_route(data->ipv4_gateway->vpn_phy_index,
@@ -1219,11 +1286,13 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway->vpn_phy_index, data->ipv6_gateway->gateway); +/* Remove all active routes associated with this gateway data. */ + err =disable_gateway (data, type);/* -* We remove the service from the hash only if all the gateway -* settings are to be removed. +* We remove the service from the service/gateway map only if ALL +* of the gateway settings are to be removed. */ if (do_ipv4 == do_ipv6 || (data->ipv4_gateway && !data->ipv6_gateway
Signature · 1 line
2.42.0
PATCH 8/8 connection: Document '__connman_connection_update_gateway'.
In reply to Grant EricksonThis adds documentation to the '__connman_connection_update_gateway' function.
--- src/connection.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
src/connection.c +22 -0
@@ -1320,6 +1320,24 @@ void __connman_connection_gateway_remove(struct connman_service *service, } } +/** +* @brief +* Handle a potential change in gateways. +* +* This may be invoked by other modules in the event of service and +* technology changes to reexamine and, if necessary, update active +* network interface gateways and their associated routing table +* entries. +* +* @returns +* True if an active gateway was updated; otherwise, false. +* +* @sa __connman_connection_gateway_add +* @sa __connman_connection_gateway_remove +* @sa set_default_gateway +* @sa unset_default_gateway +* +*/ bool __connman_connection_update_gateway (void ) {struct gateway_data *default_gateway;
@@ -1329,6 +1347,10 @@ bool __connman_connection_update_gateway(void)DBG ("" ); +/* +* If there is no service-to-gateway data hash, then there is +* nothing to update and do; simply return. +*/ if (!gateway_hash)return updated;
Signature · 1 line
2.42.0
cover connection: Improve Connection Gateway Debugging and Documentation
In reply to Grant EricksonThis improves connection gateway debugging with the following changes:
* This introduces and leverages two functions 'gateway_{config,data}_debug' to conditionally log gateway data and configuration at the debug level.
* Expands, exhances, and refactors 'DBG' statements throughout the module to improve symmetry in content, aid in debugging, and to reflect the newly-leveraged 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' macro which, in turn, are wrappers around 'gateway_{config,data}_debug'.
In addition, this adds to or expands on function- and body-level documentation for:
* connection_{add,del}gateway
* __connman_connection_gateway_{add,remove}
* __connman_connection_update_gateway
The aforementioned 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' are supported by log module changes, including:
* Introduces 'CONNMAN_DEBUG_DESC_INSTANTIATE' which declares and instantiates an instance of 'connman_debug_desc'.
* Replaces 'CONNMAN_DEBUG_DEFINE' with 'CONNMAN_DEBUG_ALIAS' which declares and instantiates an alias (that is, asserts the 'CONNMAN_DEBUG_FLAG_ALIAS' flag) instance of 'connmand_debug_desc', using 'CONNMAN_DEBUG_DESC_INSTANTIATE'.
* Redefines 'DBG' against 'CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter.
Grant Erickson (8):
log: Refactor debugging preprocessor macros.
log: Document debugging preprocessor macros.
connection: Introduce and leverage 'gateway_{config,data}_debug'.
connection: Document 'gateway_{config,data}_debug'.
connection: Expand, Enhance, and Refactor 'DBG'.
connection: Document 'connection_{add,del}gateway'.
connection: Document '__connman_connection_gateway_{add,remove}'.
connection: Document '__connman_connection_update_gateway'.
include/log.h | 99 +++++++++--- src/connection.c | 390 +++++++++++++++++++++++++++++++++++++++++++++-- src/log.c | 2 +- 3 files changed, 461 insertions(+), 30 deletions(-)
Signature · 1 line
2.42.0
PATCH v2 1/8 log: Refactor debugging preprocessor macros.
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces CONNMAN_DEBUG_DESC_INSTANTIATE which declares and instantiates an instance of 'connman_debug_desc'.
* Replaces CONNMAN_DEBUG_DEFINE with CONNMAN_DEBUG_ALIAS which declares and instantiates an alias (that is, asserts the CONNMAN_DEBUG_FLAG_ALIAS flag) instance of 'connmand_debug_desc', using CONNMAN_DEBUG_DESC_INSTANTIATE.
* Redefines 'DBG' against 'CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter.
--- include/log.h | 28 +++++++++++++++++----------- src/log.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-)
include/log.h +17 -11
@@ -58,11 +58,17 @@ struct connman_debug_desc {unsigned int flags; } __attribute__((aligned(8))); -#define CONNMAN_DEBUG_DEFINE (name) \ - static struct connman_debug_desc __debug_alias_ ## name \ +#define CONNMAN_DEBUG_DESC_INSTANTIATE (symbol, _name, _file, _flags) \ + static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ - #name, __FILE__, CONNMAN_DEBUG_FLAG_ALIAS \ - }; + .name = _name, .file = _file, .flags = _flags \ + } + +#define CONNMAN_DEBUG_ALIAS (suffix) \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ + #suffix, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_ALIAS)/** * DBG:
@@ -73,13 +79,13 @@ struct connman_debug_desc {* name it is called in. */ #define DBG(fmt, arg...) do { \ - static struct connman_debug_desc __connman_debug_desc \ - __attribute__((used, section("__debug"), aligned(8))) = { \ - .file = __FILE__, .flags = CONNMAN_DEBUG_FLAG_DEFAULT, \ - }; \ - if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ - connman_debug("%s:%s() " fmt, \ - __FILE__, __FUNCTION__ , ## arg); \ + CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \ + 0, \ + __FILE__, \ + CONNMAN_DEBUG_FLAG_DEFAULT); \ + if (__connman_debug_desc.flags & CONNMAN_DEBUG_FLAG_PRINT) \ + connman_debug("%s:%s() " fmt, \ + __FILE__, __func__, ##arg); \ } while (0)#ifdef __cplusplus
src/log.c +1 -1
@@ -38,7 +38,7 @@ static const char *program_exec;static const char *program_path;/* This makes sure we always have a __debug section. */ -CONNMAN_DEBUG_DEFINE (dummy); +CONNMAN_DEBUG_ALIAS (dummy);/** * connman_info:
Signature · 1 line
2.42.0
Re: [PATCH v2 1/8] log: Refactor debugging preprocessor macros.
Hi Grant,
Quoted 11 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connman_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.
Quoted 6 lines
* Redefines 'DBG' against '
CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter.
---include/log.h| 28 +++++++++++++++++-----------src/log.c| 2 +-2 files changed, 18 insertions(+), 12 deletions(-)
I am bit confused. I thought we leave this out for now and get the fixes merged and look into improving DBG.
Regards
Marcel
Re: [PATCH v2 1/8] log: Refactor debugging preprocessor macros.
Quoted 11 lines · Marcel Holtmann
Quoted 11 lines
This refactors the debugging / debug log preprocessor-related macros. In particular, it:
* Introduces
CONNMAN_DEBUG_DESC_INSTANTIATEwhich declares and instantiates an instance of 'connman_debug_desc'.* Replaces
CONNMAN_DEBUG_DEFINEwithCONNMAN_DEBUG_ALIASwhich declares and instantiates an alias (that is, asserts theCONNMAN_DEBUG_FLAG_ALIASflag) instance of 'connmand_debug_desc', usingCONNMAN_DEBUG_DESC_INSTANTIATE.
Quoted 8 lines
Quoted 6 lines
* Redefines 'DBG' against '
CONNMAN_DEBUG_DESC_INSTANTIATE' with '__func__' as the function parameter.
---include/log.h| 28 +++++++++++++++++-----------src/log.c| 2 +-2 files changed, 18 insertions(+), 12 deletions(-)I am bit confused. I thought we leave this out for now and get the fixes merged and look into improving DBG.
As we last discussed on the thread:
Quoted 3 lines
Quoted 1 line
CONNMAN_DEBUGaside, are you otherwise OK with the clean ups and documentation tolog.hembodied in this patch?I am fine with all the cleanups, but I prefer you don’t introduce
CONNMAN_DEBUGand stick with DBG instead and we try to figure out on how to make DBG work the way you want to use it.
As discussed and agreed, I dropped the CONNMAN_DEBUG macro from that part of the patch set and simply documented the existing macros and eliminated the copy-and-paste by preserving the CONNMAN_DEBUG_DESC_INSTANTIATE macro. So, as preferred, everything that follows remains exclusively with DBG and DBG only.
I remain happy to loop back and improve DBG at a later time. Specifically, for the “called by function” use case of DBG that we discussed, there are a healthy number of existing use cases in the code base that would benefit, the most notable of which are the ‘*_{ref,unref}_debug’ functions used for reference counting tracking and debugging (the whole reference counting pattern seems replicated, ideally it could all be embodied in infrastructure written once and instantiated where necessary).
Does that help clarify?
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] http://www.nuovations.com/
PATCH v2 2/8 log: Document debugging preprocessor macros.
In reply to Grant EricksonThis adds documentation to the following debugging- / debug logging-related data types and preprocessor macros:
* connman_debug_desc
* CONNMAN_DEBUG_DESC_INSTANTIATE
* CONNMAN_DEBUG_ALIAS
and expands the existing documentation for the 'DBG' preprocessor macro.
--- include/log.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-)
include/log.h +64 -5
@@ -49,6 +49,10 @@ void connman_debug(const char *format, ...) } \ }while (0 ) +/** +* Debug-level logging descriptor that may be used to control debug +* output on a per-file or -symbol basis. +*/ struct connman_debug_desc {const char *name;const char *file;
@@ -58,12 +62,45 @@ struct connman_debug_desc {unsigned int flags; } __attribute__((aligned(8))); +/** +* @def CONNMAN_DEBUG_DESC_INSTANTIATE(symbol, _name, _file, _flags) +* +* @brief +* Convenience preprocessor macro for declaring and instantiating an +* instance of #connmand_debug_desc. +* +* @param[in] symbol The name of the #connman_debug_desc instance +* to instantiate. +* @param[in] _name An optional pointer to an immutable null- +* terminated C string containing the name of +* the #connman_debug_desc- controlled symbol. +* @param[in] _file A pointer to an immutable null-terminated C +* string containing the name of the +* #connman_debug_desc-controlled source file. +* @param[in] _flags Flags that control the interpretation and +* behavior of the instantiated +* #connman_debug_desc instance. +* +*/ #define CONNMAN_DEBUG_DESC_INSTANTIATE (symbol, _name, _file, _flags) \ static struct connman_debug_desc symbol \ __attribute__((used, section("__debug"), aligned(8))) = { \ .name = _name, .file = _file, .flags = _flags \ } +/** +* @def CONNMAN_DEBUG_ALIAS(suffix) +* +* @brief +* Convenience preprocessor macro for declaring and instantiating +* an alias (see #CONNMAN_DEBUG_FLAG_ALIAS) instance of +* #connmand_debug_desc. +* +* @param[in] suffix The suffix to concatenate to the name of the +* #connman_debug_desc alias instance to +* instantiate. +* +*/ #define CONNMAN_DEBUG_ALIAS (suffix) \ CONNMAN_DEBUG_DESC_INSTANTIATE(__debug_alias_##suffix, \ #suffix, \
@@ -71,12 +108,34 @@ struct connman_debug_desc { CONNMAN_DEBUG_FLAG_ALIAS)/** -* DBG: -* @fmt: format string -* @arg...: list of arguments +* @def DBG(fmt, arg...) +* +* @brief +* Convenience preprocessor macro for declaring an instance of +* #connmand_debug_desc for controlling an invocation of +* #connman_debug with it that includes both the file and function +* name the macro was invoked in. +* +* This instantiates a scoped-instance of #connmand_debug_desc and +* then, if that instance has its #CONNMAN_DEBUG_FLAG_PRINT flag +* asserted, invokes a call to #connman_debug with the format: +* +* "<file>:<function>() <fmt> ..." +* +* where <file> is the preprocessor symbol __FILE__, <function> is +* the preprocessor symbol __func__, <fmt> is from @a fmt, and +* '...' is from @a 'arg...'. +* +* @param[in] fmt A pointer to an immutable null-terminated C +* string container the log message, consisting +* of a printf-style format string composed of +* zero or more output conversion directives. +* @param[in] arg... A variadic argument list, where each +* argument corresponds with its peer output +* conversion directive in @a fmt. +* +* @sa connman_debug * -* Simple macro around connman_debug() which also include the function -* name it is called in. */ #define DBG(fmt, arg...) do { \ CONNMAN_DEBUG_DESC_INSTANTIATE(__connman_debug_desc, \
Signature · 1 line
2.42.0
PATCH v2 3/8 connection: Introduce and leverage 'gateway_{config,data}_debug'.
In reply to Grant EricksonThis introduces and leverages two functions 'gateway_{config,data}_debug' to conditionally log gateway data and configuration at the debug level.
--- src/connection.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-)
src/connection.c +117 -2
@@ -32,6 +32,12 @@#include "connman.h" +#define GATEWAY_CONFIG_DBG (description, config) \ + gateway_config_debug(__func__, description, config) + +#define GATEWAY_DATA_DBG (description, data) \ + gateway_data_debug(__func__, description, data) +struct gateway_config {bool active;char *gateway;
@@ -53,6 +59,79 @@ struct gateway_data {static GHashTable *gateway_hash =NULL ; +static const char *maybe_null (const void *pointer) +{ +return pointer ? pointer :"<null>" ; +} + +static void gateway_config_debug (const char *function, +const char *description, +const struct gateway_config *config) +{ + g_autofree char *vpn_phy_interface = NULL; + +if (!function || !description) +return ; + +if (!config) +DBG ("from %s %s %p" , function, description, config); +else { +if (config->vpn_phy_index >=0 ) + vpn_phy_interface = +connman_inet_ifname (config->vpn_phy_index); + +DBG ("from %s %s %p: { active: %u, gateway: %p (%s), " +"vpn: %u, vpn_ip: %p (%s), vpn_phy_index: %d (%s), " +"vpn_phy_ip: %p (%s) }" , + function, + description, + config, + config->active, + config->gateway,maybe_null (config->gateway), + config->vpn, + config->vpn_ip,maybe_null (config->vpn_ip), + config->vpn_phy_index,maybe_null (vpn_phy_interface), + config->vpn_phy_ip,maybe_null (config->vpn_phy_ip)); + } +} + +static void gateway_data_debug (const char *function, +const char *description, +const struct gateway_data *data) +{ + g_autofree char *interface = NULL; + +if (!function || !description) +return ; + +if (!data) +DBG ("from %s %s %p" , function, description, data); +else { + interface =connman_inet_ifname (data->index); + +DBG ("from %s %s %p: { index: %d (%s), service: %p (%s), " +"ipv4_gateway: %p, ipv6_gateway: %p, default_checked: %u }" , + function, + description, + data, + data->index, +maybe_null (interface), + data->service, +connman_service_get_identifier (data->service), + data->ipv4_gateway, + data->ipv6_gateway, + data->default_checked); + +if (data->ipv4_gateway) +gateway_config_debug (function,"ipv4_gateway" , + data->ipv4_gateway); + +if (data->ipv6_gateway) +gateway_config_debug (function,"ipv6_gateway" , + data->ipv6_gateway); + } +} +static struct gateway_config *find_gateway (int index,const char *gateway) {GHashTableIter iter;
@@ -282,6 +361,8 @@ static int del_routes(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -334,6 +415,8 @@ static int disable_gateway(struct gateway_data *data, {bool active = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) {if (data->ipv4_gateway) active = data->ipv4_gateway->active;
@@ -426,6 +509,8 @@ static void set_default_gateway(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -507,6 +592,8 @@ static void unset_default_gateway(struct gateway_data *data,int index;bool do_ipv4 = false, do_ipv6 = false; +GATEWAY_DATA_DBG ("data" , data); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;else if (type ==CONNMAN_IPCONFIG_TYPE_IPV6 )
@@ -586,6 +673,9 @@ static bool choose_default_gateway(struct gateway_data *data, {bool downgraded = false; +GATEWAY_DATA_DBG ("data" , data); +GATEWAY_DATA_DBG ("candidate" , candidate); +/* * If the current default is not active, then we mark * this one as default. If the other one is already active
@@ -641,6 +731,8 @@ static void connection_newgateway(int index, const char *gateway)if (!config)return ; +GATEWAY_CONFIG_DBG ("config" , config); + config->active = true;/*
@@ -652,6 +744,8 @@ static void connection_newgateway(int index, const char *gateway)if (!data)return ; +GATEWAY_DATA_DBG ("data" , data); +if (data->default_checked)return ;
@@ -690,6 +784,8 @@ static void remove_gateway(gpointer user_data)DBG ("gateway ipv4 %p ipv6 %p" , data->ipv4_gateway, data->ipv6_gateway); +GATEWAY_DATA_DBG ("data" , data); +if (data->ipv4_gateway) {g_free (data->ipv4_gateway->gateway);g_free (data->ipv4_gateway->vpn_ip);
@@ -717,12 +813,18 @@ static void connection_delgateway(int index, const char *gateway)DBG ("index %d gateway %s" , index, gateway); config =find_gateway (index, gateway); -if (config) +if (config) { +GATEWAY_CONFIG_DBG ("config" , config); + config->active = false; + } data =find_default_gateway (); -if (data) +if (data) { +GATEWAY_DATA_DBG ("data" , data); +set_default_gateway (data,CONNMAN_IPCONFIG_TYPE_ALL ); + } }static struct connman_rtnl connection_rtnl = {
@@ -836,11 +938,15 @@ int __connman_connection_gateway_add(struct connman_service *service,if (!new_gateway)return -EINVAL ; +GATEWAY_DATA_DBG ("new_gateway" , new_gateway); + active_gateway =find_active_gateway ();DBG ("active %p index %d new %p" , active_gateway, active_gateway ? active_gateway->index :-1 , new_gateway); +GATEWAY_DATA_DBG ("active_gateway" , active_gateway); +if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 && new_gateway->ipv4_gateway) {add_host_route (AF_INET , index, gateway, service_type);
@@ -931,6 +1037,8 @@ void __connman_connection_gateway_remove(struct connman_service *service,if (!data)return ; +GATEWAY_DATA_DBG ("service_data" , data); +if (do_ipv4 && data->ipv4_gateway) set_default4 = data->ipv4_gateway->vpn;
@@ -977,6 +1085,9 @@ void __connman_connection_gateway_remove(struct connman_service *service,*/ if (set_default4 || set_default6 || err <0 ) { data =find_default_gateway (); + +GATEWAY_DATA_DBG ("default_data" , data); +if (data)set_default_gateway (data, type); }
@@ -996,6 +1107,8 @@ bool __connman_connection_update_gateway(void)DBG ("default %p" , default_gateway); +GATEWAY_DATA_DBG ("default_gateway" , default_gateway); +/* * There can be multiple active gateways so we need to * check them all.
@@ -1005,6 +1118,8 @@ bool __connman_connection_update_gateway(void)while (g_hash_table_iter_next (&iter, &key, &value)) {struct gateway_data *active_gateway = value; +GATEWAY_DATA_DBG ("active_gateway" , active_gateway); +if (active_gateway == default_gateway)continue ;
Signature · 1 line
2.42.0
PATCH v2 4/8 connection: Document 'gateway_{config,data}_debug'.
In reply to Grant EricksonThis adds documentation to the 'gateway_{config,data}_debug' functions.
--- src/connection.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
src/connection.c +57 -0
@@ -59,11 +59,45 @@ struct gateway_data {static GHashTable *gateway_hash =NULL ; +/** +* @brief +* Return the specified pointer if non-null; otherwise, the +* immutable "<null>" string. +* +* @param[in] pointer The pointer to be returned if non-null. +* +* @returns +* @a pointer if non-null; otherwise the "<null>" immutable +* null-terminated C string. +* +*/ static const char *maybe_null (const void *pointer) {return pointer ? pointer :"<null>" ; } +/** +* @brief +* Conditionally log the specified gateway configuration. +* +* This conditionally logs at the debug level the specified +* #gateway_config gateway configuration, @a config, with the +* provided description, @a description, attributed to the provided +* function name, @a function. +* +* @param[in] function A pointer to an immutable null-terminated +* C string containing the function name to +* which the call to this function should be +* attributed. +* @param[in] description A pointer to an immutable null-terminated +* C string briefly describing @a +* config. For example, "ipv4_config". +* @param[in] config A pointer to the immutable gateway +* configuration to conditionally log. +* +* @sa DBG +* +*/ static void gateway_config_debug (const char *function,const char *description,const struct gateway_config *config)
@@ -95,6 +129,29 @@ static void gateway_config_debug(const char *function, } } +/** +* @brief +* Conditionally log the specified gateway data. +* +* This conditionally logs at the debug level the specified +* #gateway_data gateway data, @a data, with the provided +* description, @a description, attributed to the provided function +* name, @a function. +* +* @param[in] function A pointer to an immutable null-terminated +* C string containing the function name to +* which the call to this function should be +* attributed. +* @param[in] description A pointer to an immutable null-terminated +* C string briefly describing @a +* data. For example, "default_gateway". +* @param[in] data A pointer to the immutable gateway +* data to conditionally log. +* +* @sa DBG +* @sa gateway_config_debug +* +*/ static void gateway_data_debug (const char *function,const char *description,const struct gateway_data *data)
Signature · 1 line
2.42.0
PATCH v2 5/8 connection: Expand, Enhance, and Refactor 'DBG'.
In reply to Grant EricksonThis expands, exhances, and refactors 'DBG' statements throughout the module to improve symmetry in content, aid in debugging, and to reflect the newly-leveraged 'GATEWAY_CONFIG_DBG' and 'GATEWAY_DATA_DBG' macros.
--- src/connection.c | 52 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-)
src/connection.c +44 -8
@@ -566,6 +566,9 @@ static void set_default_gateway(struct gateway_data *data,int status4 =0 , status6 =0 ;bool do_ipv4 = false, do_ipv6 = false; +DBG ("data %p type %d (%s)" , data, + type,__connman_ipconfig_type2string (type)); +GATEWAY_DATA_DBG ("data" , data);if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 )
@@ -575,9 +578,6 @@ static void set_default_gateway(struct gateway_data *data,else do_ipv4 = do_ipv6 = true; -DBG ("type %d gateway ipv4 %p ipv6 %p" , type, data->ipv4_gateway, - data->ipv6_gateway); -if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn) {connman_inet_set_gateway_interface (data->index);
@@ -649,6 +649,9 @@ static void unset_default_gateway(struct gateway_data *data,int index;bool do_ipv4 = false, do_ipv6 = false; +DBG ("data %p type %d (%s)" , data, + type,__connman_ipconfig_type2string (type)); +GATEWAY_DATA_DBG ("data" , data);if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 )
@@ -776,13 +779,17 @@ static bool choose_default_gateway(struct gateway_data *data,static void connection_newgateway (int index,const char *gateway) { + g_autofree char *interface = NULL;struct gateway_config *config;struct gateway_data *data;GHashTableIter iter;gpointer value, key;bool found = false; -DBG ("index %d gateway %s" , index, gateway); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), + gateway); config =find_gateway (index, gateway);if (!config)
@@ -839,7 +846,7 @@ static void remove_gateway(gpointer user_data) {struct gateway_data *data = user_data; -DBG ("gateway ipv4 %p ipv6 %p" , data->ipv4_gateway, data->ipv6_gateway); +DBG ("data %p" , data);GATEWAY_DATA_DBG ("data" , data);
@@ -864,10 +871,14 @@ static void remove_gateway(gpointer user_data)static void connection_delgateway (int index,const char *gateway) { + g_autofree char *interface = NULL;struct gateway_config *config;struct gateway_data *data; -DBG ("index %d gateway %s" , index, gateway); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), + gateway); config =find_gateway (index, gateway);if (config) {
@@ -974,9 +985,20 @@ int __connman_connection_gateway_add(struct connman_service *service,enum connman_service_type service_type =connman_service_get_type (service);int index; + g_autofree char *interface = NULL; + +DBG ("service %p (%s) gateway %p (%s) type %d (%s) peer %p (%s)" , + service,maybe_null (connman_service_get_identifier (service)), + gateway,maybe_null (gateway), + type,__connman_ipconfig_type2string (type), + peer,maybe_null (peer)); index =__connman_service_get_index (service); + interface =connman_inet_ifname (index); + +DBG ("index %d (%s)" , index,maybe_null (interface)); +/* * If gateway is NULL, it's a point to point link and the default * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
@@ -1077,9 +1099,21 @@ void __connman_connection_gateway_remove(struct connman_service *service,struct gateway_data *data =NULL ;bool set_default4 = false, set_default6 = false;bool do_ipv4 = false, do_ipv6 = false; +int index; + g_autofree char *interface = NULL;int err; -DBG ("service %p type %d" , service, type); +DBG ("service %p (%s) type %d (%s)" , + service,maybe_null (connman_service_get_identifier (service)), + type,__connman_ipconfig_type2string (type)); + + index =__connman_service_get_index (service); +if (index <0 ) +return ; + + interface =connman_inet_ifname (index); + +DBG ("index %d (%s)" , index,maybe_null (interface));if (type ==CONNMAN_IPCONFIG_TYPE_IPV4 ) do_ipv4 = true;
@@ -1157,12 +1191,14 @@ bool __connman_connection_update_gateway(void)GHashTableIter iter;gpointer value, key; +DBG ("" ); +if (!gateway_hash)return updated; default_gateway =find_default_gateway (); -DBG ("default %p" , default_gateway); +DBG ("default_gateway %p" , default_gateway);GATEWAY_DATA_DBG ("default_gateway" , default_gateway);
Signature · 1 line
2.42.0
PATCH v2 6/8 connection: Document 'connection_{add,del}gateway'.
In reply to Grant EricksonThis adds documentation to the 'connection_{add,del}gateway' functions.
--- src/connection.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
src/connection.c +67 -0
@@ -777,6 +777,29 @@ static bool choose_default_gateway(struct gateway_data *data,return downgraded; } +/** +* @brief +* Handler for gateway, or default route, -specific routes newly +* added to the Linux kernel routing tables. +* +* This is the Linux Routing Netlink (rtnl) handler for gateway, or +* default route, -specific routes newly-added to the Linux kernel +* routing tables. Its primary role and goal is to serve as a +* round-trip acknowledgement that gateway-, or default route, +* related routes added or set to the kernel are now active and in +* use. +* +* @param[in] index The network interface index associated with +* the newly-added gateway, or default router. +* @param[in] gateway An pointer to an immutable null-terminated +* C string containing the text- +* formatted address of the gateway, or default +* router, that was added. +* +* @sa set_default_gateway +* @sa connection_delgateway +* +*/ static void connection_newgateway (int index,const char *gateway) { g_autofree char *interface = NULL;
@@ -791,12 +814,23 @@ static void connection_newgateway(int index, const char *gateway)DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), gateway); +/* +* If there is no gateway configuration, then this is not a +* gateway, or default router, route we added or +* set. Consequently, ignore it and return. +*/ config =find_gateway (index, gateway);if (!config)return ;GATEWAY_CONFIG_DBG ("config" , config); +/* +* Otherwise, this is a gateway, or default router, route we added +* or set and it is now acknowledged by the kernel. Consequently, +* prospectively mark it as active; however, this may be +* subsequently modified as default route determinations are made. +*/ config->active = true;/*
@@ -869,6 +903,29 @@ static void remove_gateway(gpointer user_data)g_free (data); } +/** +* @brief +* Handler for gateway, or default route, -specific routes newly +* removed from the Linux kernel routing tables. +* +* This is the Linux Routing Netlink (rtnl) handler for gateway, or +* default route, -specific routes newly-removed from the Linux +* kernel routing tables. Its primary role and goal is to serve as +* a round-trip acknowledgement that gateway-, or default route, +* related routes removed or cleared from the kernel are now inactive +* and are no longer in use. +* +* @param[in] index The network interface index associated with +* the newly-removed gateway, or default router. +* @param[in] gateway An pointer to an immutable null-terminated +* C string containing the text- +* formatted address of the gateway, or default +* router, that was removed. +* +* @sa connection_newgateway +* @sa set_default_gateway +* +*/ static void connection_delgateway (int index,const char *gateway) { g_autofree char *interface = NULL;
@@ -880,6 +937,10 @@ static void connection_delgateway(int index, const char *gateway)DBG ("index %d (%s) gateway %s" , index,maybe_null (interface), gateway); +/* +* This ends the lifecycle of the gateway associated with the +* newly-removed route; mark it as no longer active. +*/ config =find_gateway (index, gateway);if (config) {GATEWAY_CONFIG_DBG ("config" , config);
@@ -887,6 +948,12 @@ static void connection_delgateway(int index, const char *gateway) config->active = false; } +/* +* Due to the newly-removed gateway route, there may have been a +* concomitant change in service order that has resulted in a new, +* default service, if any. If so, ensure that service acquires +* the high priority default route. +*/ data =find_default_gateway ();if (data) {GATEWAY_DATA_DBG ("data" , data);
Signature · 1 line
2.42.0
PATCH v2 7/8 connection: Document '__connman_connection_gateway_{add,remove}'.
In reply to Grant EricksonThis adds documentation to the '__connman_connection_gateway_{add,remove}' functions.
--- src/connection.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-)
src/connection.c +71 -2
@@ -1040,6 +1040,41 @@ static void add_host_route(int family, int index, const char *gateway, } } +/** +* @brief +* Add, or set, the gateway, or default router, for a network +* service. +* +* This attempts to add, or set, the gateway, or default router, for +* a network service using the specified IP configuration gateway +* address and network interface index as the lookup key for the +* network service. +* +* @param[in,out] service A pointer to the mutable network service +* for which to add a gateway, or default +* router. +* @param[in] gateway An optional pointer to an immutable null- +* terminated C string containing the +* text-formatted address of the gateway, or +* default router, to add to or associate +* with @a service. +* @param[in] type The IP configuration type for which +* gateway, or default router, is to be +* added. +* @param[in] peer An optional pointer to an immutable null- +* terminated C string containing the +* text-formatted address of the network +* peer, for point-to-point links, +* associated with the gateway. +* +* @retval 0 If successful. +* @retval -EINVAL If service is null or if network interface +* index associated with @a service is invalid. +* +* @sa __connman_connection_gateway_remove +* @sa __connman_connection_update_gateway +* +*/ int __connman_connection_gateway_add(struct connman_service *service, const char *gateway, enum connman_ipconfig_type type,
@@ -1160,6 +1195,30 @@ done:return 0 ; } +/** +* @brief +* Remove, or clear, the gateway, or default router, for a network +* service. +* +* This attempts to remove, or clear, the gateway, or default router, +* for a network service using the specified network service and IP +* configuration type. +* +* @param[in,out] service A pointer to the mutable network service +* for which to remove, or clear, a gateway, +* or default router. +* @param[in] type The IP configuration type for which +* gateway, or default router, is to be +* removed. +* +* @retval 0 If successful. +* @retval -EINVAL If service is null or if network interface +* index associated with @a service is invalid. +* +* @sa __connman_connection_gateway_add +* @sa __connman_connection_update_gateway +* +*/ void __connman_connection_gateway_remove (struct connman_service *service,enum connman_ipconfig_type type) {
@@ -1189,8 +1248,14 @@ void __connman_connection_gateway_remove(struct connman_service *service,else do_ipv4 = do_ipv6 = true; +/* Delete any routes associated with this service's nameservers. */ +__connman_service_nameserver_del_routes (service, type); +/* +* If there is no hash table / map entry for this service, then +* there are no gateways associated with it; simply return. +*/ data =g_hash_table_lookup (gateway_hash, service);if (!data)return ;
@@ -1208,6 +1273,8 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway ? data->ipv6_gateway->gateway :"<null>" , set_default4, set_default6); +/* If necessary, delete any VPN-related host routes. */ +if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn && data->index >=0 ) connman_inet_del_host_route(data->ipv4_gateway->vpn_phy_index,
@@ -1219,11 +1286,13 @@ void __connman_connection_gateway_remove(struct connman_service *service, data->ipv6_gateway->vpn_phy_index, data->ipv6_gateway->gateway); +/* Remove all active routes associated with this gateway data. */ + err =disable_gateway (data, type);/* -* We remove the service from the hash only if all the gateway -* settings are to be removed. +* We remove the service from the service/gateway map only if ALL +* of the gateway settings are to be removed. */ if (do_ipv4 == do_ipv6 || (data->ipv4_gateway && !data->ipv6_gateway
Signature · 1 line
2.42.0
PATCH v2 8/8 connection: Document '__connman_connection_update_gateway'.
In reply to Grant EricksonThis adds documentation to the '__connman_connection_update_gateway' function.
--- src/connection.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
src/connection.c +22 -0
@@ -1320,6 +1320,24 @@ void __connman_connection_gateway_remove(struct connman_service *service, } } +/** +* @brief +* Handle a potential change in gateways. +* +* This may be invoked by other modules in the event of service and +* technology changes to reexamine and, if necessary, update active +* network interface gateways and their associated routing table +* entries. +* +* @returns +* True if an active gateway was updated; otherwise, false. +* +* @sa __connman_connection_gateway_add +* @sa __connman_connection_gateway_remove +* @sa set_default_gateway +* @sa unset_default_gateway +* +*/ bool __connman_connection_update_gateway (void ) {struct gateway_data *default_gateway;
@@ -1329,6 +1347,10 @@ bool __connman_connection_update_gateway(void)DBG ("" ); +/* +* If there is no service-to-gateway data hash, then there is +* nothing to update and do; simply return. +*/ if (!gateway_hash)return updated;
Signature · 1 line
2.42.0