Skip to content

connection: Simplify '{un,}set_default_gateway' Flow

Grant Erickson connman 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4connection: Simplify 'set_default_gateway' flow.src/connection.c+38 -450 replies
2/4connection: Simplify 'unset_default_gateway' flow.src/connection.c+31 -390 replies
3/4connection: Add additional DBG statements to '{un,}set_default_gateway'.src/connection.c+26 -00 replies
4/4connection: Document '{un,}set_default_gateway'.src/connection.c+56 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] connection: Simplify '{un,}set_default_gateway' Flow

Ostensibly over time, the logic of both 'set_default_gateway' and 'unset_default_gateway' has become a bit complicated with early returns, gotos (in the case of 'set_default_gateway'), repeated state checks, and duplicated function calls (in the case of 'set_default_gateway').

However, amidst all of that, there is a simpler flow to surface. At its core, the functions are two identical outer conditional blocks:
one for IPv4 and one for IPv6 and three inner conditional blocks within those: one for a VPN, one for a gateway with an any/unspecified address, and one for everything else. In the case of 'set_default_gateway', on success, a call to '__connman_service_indicate_default' is made; on failure, it is not.

This simplifies the flows of both functions accordingly, curtailing the number of early returns, eliminating all of the gotos, and reducing the repeated state checks and function calls to one through the use of those simplified conditional blocks.

Additionally, this adds 'DBG' statements and documentation to both functions.

Grant Erickson (4):
connection: Simplify 'set_default_gateway' flow.
connection: Simplify 'unset_default_gateway' flow.
connection: Add additional DBG statements to '{un,}set_default_gateway'.
connection: Document '{un,}set_default_gateway'.

 src/connection.c | 223 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 145 insertions(+), 78 deletions(-)
Signature · 1 line
2.42.0