[connman] Return an in progress error if the service is already connecting.

If the network service is already connecting return an in progress
error and do nothing. Previously only the pending variable was tested
indicating that a previous DBus call started the connection. This
variable is not set for an internally initiated connection.

If the connect_sevice call is not aborted it is possible that the
service connection will be needlessly aborted when looking for an
available interface.
gdhcp: Remove unnecessary listener channel variable

The variable is not used for anything and can be removed.
dhcp: Keep DHCP running until an explicit stop is called

In order to recover from a lost lease, gdhcp will restart the address
acquisition process. As the dhcp structures are removed from the hash
and freed in dhcp_invalidate() without notifying gdhcp, the following
happens:

connmand[28337]: DHCP index 3: lease expired
connmand[28337]: DHCP index 3: restart DHCP (retries 0)
connmand[28337]: DHCP index 3: DHCP client start with state init_reboot
connmand[28337]: DHCP index 3: sending DHCP request
connmand[28337]: src/dhcp.c:lease_lost_cb() Lease lost
connmand[28337]: src/dhcp.c:dhcp_invalidate() dhcp 0xb958a0 callback 1
connmand[28337]: src/dhcp.c:dhcp_invalidate() last address 10.0.0.18
connmand[28337]: src/dhcp.c:__connman_dhcp_stop() network_table 0xb94c60 network 0xb9b500
connmand[28337]: wlan0 {del} address 10.0.0.18/20 label wlan0
connmand[28337]: wlan0 {del} route 10.0.0.0 gw 0.0.0.0 scope 253 <LINK>
connmand[28337]: DHCP index 3: received DHCP packet xid 0x0000 (current state 1)
connmand[28337]: DHCP index 3: switch listening mode (1 ==> 0)
connmand[28337]: src/dhcp.c:lease_available_cb() Lease available
connmand[28337]: Aborting (signal 11) [src/connmand]
connmand[28337]: ++++++++ backtrace ++++++++
connmand[28337]: #0  0x7f1890e98420 in /lib/x86_64-linux-gnu/libc.so.6
connmand[28337]: #1  0x439580 in connman_device_get_ident() at src/device.c:555
connmand[28337]: #2  0x448041 in connman_service_lookup_from_network() at src/service.c:6483
connmand[28337]: #3  0x459d97 in lease_available_cb() at src/dhcp.c:331
connmand[28337]: #4  0x4122b1 in start_bound() at gdhcp/client.c:1740
connmand[28337]: #5  0x7f1891f8a526 in /lib/x86_64-linux-gnu/libglib-2.0.so.0
connmand[28337]: #6  0x7f1891f8a878 in /lib/x86_64-linux-gnu/libglib-2.0.so.0
connmand[28337]: #7  0x7f1891f8ab3a in /lib/x86_64-linux-gnu/libglib-2.0.so.0
connmand[28337]: #8  0x40f902 in main() at src/main.c:690
connmand[28337]: #9  0x7f1890e84b45 in /lib/x86_64-linux-gnu/libc.so.6
connmand[28337]: +++++++++++++++++++++++++++

Fix this by freeing and removing the dhcp structure only when calling
__connman_dhcp_stop() and modify dhcp_invalidate() so that it only
resets IP configuration data for the service.

This also fixes the reference counting issue reported by Eduardo
Abinader.
dhcp: Restart existing DHCP client with __connman_dhcp_start()

Check whether the dhcp structure already exists when calling
 __connman_dhcp_start() and initialize callbacks and other data
only on newly created objects.

As dhcp_request() now handles initialization, rename it to
dhcp_initialize().
Merge pull request #52 from amccarthy/master

[connman] Return an in progress error if the service is already connecti...
[connman] allow user_context to be null when queueing agent message.

This allows our dns error patch to pass.
[connman] Fix memory leak in GetSavedServices.
Merge pull request #55 from lpotter/master

[connman] allow user_context to be null when queueing agent message.
Merge pull request #56 from amccarthy/master

[connman] Fix memory leak in GetSavedServices.
ipconfig: iterate safely over ipconfig_list. Fixes JB#19212

The following valgrind report appears when a network toggled from
enabled to disabled and back; it is due to ipconfig_list being
modified by functions called in the loop while iterating over the
list. When the current list element gets deleted during iteration,
g_list_next() cannot be safely called anymore.

Fixed by making a shallow copy of the list for iteration purposes.

==1638== Invalid read of size 4
==1638==    at 0x542E0: __connman_ipconfig_newlink (ipconfig.c:560)
==1638==    by 0x633F7: process_newlink (rtnl.c:445)
==1638==    by 0x6424F: netlink_event (rtnl.c:958)
==1638==    by 0x4907733: g_io_unix_dispatch (giounix.c:167)
==1638==    by 0x48AC55B: g_main_context_dispatch (gmain.c:3054)
==1638==    by 0x48AC85F: g_main_context_iterate.part.17 (gmain.c:3701)
==1638==    by 0x48ACEB3: g_main_loop_run (gmain.c:3894)
==1638==    by 0x14957: main (main.c:739)
==1638==  Address 0x50df6fc is 4 bytes inside a block of size 12 free'd
==1638==    at 0x483752C: free (vg_replace_malloc.c:446)
==1638==    by 0x48B418B: g_free (gmem.c:252)
==1638==    by 0x48A758F: g_list_remove (glist.c:480)
==1638==    by 0x55AB7: __connman_ipconfig_disable (ipconfig.c:1691)
==1638==    by 0x4376F: service_lower_down (service.c:6703)
==1638==    by 0x54373: __connman_ipconfig_newlink (ipconfig.c:575)
==1638==    by 0x633F7: process_newlink (rtnl.c:445)
==1638==    by 0x6424F: netlink_event (rtnl.c:958)
==1638==    by 0x4907733: g_io_unix_dispatch (giounix.c:167)
==1638==    by 0x48AC55B: g_main_context_dispatch (gmain.c:3054)
==1638==    by 0x48AC85F: g_main_context_iterate.part.17 (gmain.c:3701)
==1638==    by 0x48ACEB3: g_main_loop_run (gmain.c:3894)
==1638==
Merge pull request #57 from hmallat/ipconfig-safe-iteration

ipconfig: iterate safely over ipconfig_list
agent: fix agent message handling bugs.

It could happen that cleaning up a pending message in
agent_receive_message() would as a side effect zero service reference
count via driver context unref function pointer, and service cleanup
would call connman_agent_cancel() which would try to clean up the
pending message for the second time.

Fixed by decoupling the pointer to the pending request from the agent
structure before calling agent_request_free().

Also, added null message pointer handling to agent-connman.c callback
function request_input_login_reply().

[connman] Fix agent message handling bugs.
Merge pull request #58 from hmallat/dbus-agent-message-fix

agent: fix agent message handling bugs.
supplicant: rewrite pending DBus call handling

It is possible to overwrite the pending_call and pending_slot fields
in the GSupplicantInterface structure by making a new supplicant
related DBus call while an older call is still ongoing. This causes
problems with cleanup at interface removal time, as the older call is
not canceled and its reply processing may access already freed memory.

Fixed by having supplicant DBus code keep track of pending calls in a
list which is updated when call replies are processed. Supplicant code
can request cancellation of all pending calls for a particular
interface when needed.

[connman] supplicant: rewrite pending DBus call handling
Merge pull request #59 from hmallat/supplicant-dbus-call-handling-fix

supplicant: rewrite pending DBus call handling
[connman] explicitly allow dns server to be created when no services are
connected.

This allows the use of FallbackNameservers when there is no connman
connection. i.e. a usb network not handled by connman to be able to use dns
Merge pull request #60 from lpotter/master

[connman] explicitly allow dns server to be created when no services are
[connman] don't set ignore flag on disconnect.

The ignore flag will stop an autoconnect, we want to always autoconnect.
[connman] Fix service reference counting when online check fails.
wifi: cancel autoscan timeout when removing device

Usually autoscan is cancelled when the device is disabled, but when
wpa_supplicant leaves D-Bus while device has an ongoing power request,
__connman_device_disable() will return early and thus autoscan timeout
isn't cleared. The timeout callback may then access released memory
when it's activated.

Add stop_autoscan() call to wifi_remove() to make sure there are no
pending timeouts when the autoscan struct is released.

[connman] wifi: cancel autoscan timeout when removing device