dnsproxy: Make sure we are not accessing null hash

If dnsproxy is not in use, like when connman has been started
with -r option, then the listener_table will be NULL which can
cause crash in hash table lookup call.
iptables: Prepare rule to be inserted or appended

Add a boolean helper to distinguish between insert and append operations.
When chain_head == chain_tail->prev, the builtin chain is empty which makes
an intended append operation equivalent to an insert operation.
iptables: Add __connman_iptables_insert()

This was wrongly removed with commit 161efbae
iptables-test: Add insert support
session: Add callback helpers

There is a common pattern when writing a callback function. Let's
add a few helper for this.

It is added to session.h because apart from the core also
the session_policy_local.c will make use of it.

This is shamelessly stolen from oFono.
iptables: Add chain iterator

We will implement the ConnMan iptables specific part in a different
file and leave the iptables.c file as small as possible.

Therefore, we move the flushing part out, but we need a way to
find our chains on bootup (left over from a crash). Let's add an
interater which walks over all chains which allows a higher level
to find the chains it is looking for (e.g. connman-INPUT)
firewall: Add firewall file
firewall: Flush managed chains

ConnMan maintains its own chain per builtin chain. The managed
chain have a prefix 'connman-' and one rule in the corresponding
builtin chain which jumps uncoditional to the managed chain.

In case ConnMan crashed we need to cleanup first.
firewall: Add firewall API

The main idea behind this API is to collect several iptables rules
together and enable or disable in one go.

For this a context is created via __connman_firewall_create() and
the rules added to this context via __connman_firewall_add_rule().

In order to append all rules __connman_firewall_enable() has
to be called. To remove all rules associated with one context
__connman_firewall_disable() has to be used.

If something goes awry the code tries to get back to the initial
state.
firewall: Maintain iptables rules in dedicated ConnMan chains

Instead appending ConnMan iptables rules into the builtin chains
we append them into chains managed by ConnMan.

If a rule needs to be inserted into a bultin chain, ConnMan
will create a 'connman-' prefixed builtin chain name and appends
the user rules there. Then ConnMan will insert a unconditional jump
rule in the builtin chain.

Basically,

  iptables -t filter -A INPUT -m mark --mark 1 -j LOG

will be translated to this:

  iptables -t filter -N connman-INPUT
  iptables -t filter -A connman-INPUT -m mark --mark 1 -j LOG
  iptables -t filter -I INPUT -j connman-INPUT

When the last rule in a managed chain is removed, the managed
chain will also be removed.
iptables-unit: Add firewall API tests
config: Allow user to specify how IP address is used

If IPv4 address is missing then DHCPv4 is used. If IPv6 address is missing,
then SLAAC or DHCPv6 is used. This was specified in doc/config-format.txt
but implementation was missing.

We also allow the IP address to contain "off", "dhcp" or "auto" string,
so user can specify how the IP address can be set for the interface.

Fixes BMC#25985
service: Only send correct ipconfig changed signal

If we are changing IPv4 config, then send only IPv4 changed signal
and not the IPv6 one. Same is done for IPv6 config when it changes.
service: Send IP config changed signal in disconnect

We did not send the IP config changed signal during disconnect.
This can confuse the dbus signal listeners.

Fixes BMC#25989
tethering: Fix build with kernel headers 3.8+

Highly inspired by:
    https://git.kernel.org/cgit/linux/kernel/git/shemminger/bridge-utils.git/commit/?id=5eebb7f9288b7881ffb929b1fd494fe3ac3be27d

As Russel puts it in his commit message for bridge-utils:

    Linux 3.8 has a header, include/uapi/linux/if_bridge.h that uses a
    struct in6_addr but doesn't define it. The trivial seeming fix of
    including the header that does define it causes more problems. The
    problem was discussed on mailing lists in January 2013. The final
    suggestion I found was here:
        http://www.redhat.com/archives/libvir-list/2013-January/msg01253.html
    This is intended to implement that suggestion.

This changeset transplants this trivial fix to connman.
vpn-provider: Fix uninitialized memory read

The immutable field might be left uninitialized without this.
service: Disconnect the connecting service when needed

If we are trying to connect a service and there is another
service connecting, then we disconnect the pending service
and connect the new one.

Fixes BMC#25981
wifi: terminate autoscan stop if autoscan is not active

This terminates the body of stop_autoscan if autoscan is
not active. Per MEEGO-25987 <http://bugs.meego.com/show_bug.cgi?id=25987>,
running stop_autoscan when changing connected services can prematurely and
incorrectly terminate a new, in-flight service connection and result in a
failure of that connection with "net.connman.Error.OperationAborted:
Operation aborted".

When a scan is started, all networks are marked unavailable. Should the check
added in this patch not be present, device scanning is set to false and all
not yet found networks are removed. Thus the service will not be able to
connect if its network wasn't already found.
provider: Set nameservers if we receive them from vpnd

If we receive nameservers from vpnd we must set them in provider.
The connman_provider_set_nameservers() function needs changes
because we get the nameservers as an array, it makes no sense to
convert the array to string and then back to array.
openvpn: Set the nameservers in correct order

The nameservers that we get from OpenVPN server can be received
in any order. Make sure that we sort them in correct order before
sending them to connmand.