mbox series

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

Message ID 20231130052622.1335266-1-gerickson@nuovations.com (mailing list archive)
Headers show
Series connection: Simplify '{un,}set_default_gateway' Flow | expand

Message

Grant Erickson Nov. 30, 2023, 5:26 a.m. UTC
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(-)