Hi Daniel,
On Thu, Feb 03, 2011 at 05:33:28PM +0100, Daniel Wagner wrote:
> From: Daniel Wagner <[email protected]>
>
> The current __connman_service_append/remove_nameserver allows only
> changing nameserver for the manual (e.g. non DHCP) setup.
It is also currently used by the DHCP code, by setting the IPv4 element
nameserver string.
> __connman_service_append/remove_namerserver() is renamed to
> __connman_service_nameserver_append/remove to be more consistent with
> the other Service API naming.
That makes sense.
> Additional the two function take now the type of nameserver (automatic
> or manual) and do append or remove the nameserer from the defined list
> of nameservers.
I'm not sure this disctinction is needed.
We currently have nameserver and nameservers, but what we should really have
are nameservers and nameservers_config. nameservers should be used for DNS
settings coming from the network, while nameservers_config should hold the
ones coming from Nameservers.Configuration. The nameservers_config should
override the nameservers one.
So the logic here is easy: Anything you get from DHCP, VPN or fixed 3G
settings should belong to nameservers, while entries arriving from a
Nameservers.Configuration property setting should be going to
nameservers_config and all existing resolver entries should be removed and
replaced by the nameservers_config ones.
Moreover, a manually set service should use the DNS entries from
nameservers_config, if they exist.
What the code is currently lacking is:
- The nameservers and nameservers_config arrays.
- VPN, DHCP and 3G fixed networks filling the nameservers array.
- Manually configured services using the nameservers_config array (filled from
either service_load or Nameservers.Configuration).
- nameservers_config priority over nameservers.
> The previously implementation had a set/clear
> semantic.
> ---
> include/service.h | 2 +-
> plugins/pacrunner.c | 7 +-
> src/connman.h | 15 +++-
> src/ipv4.c | 11 ++-
> src/network.c | 7 +-
> src/provider.c | 4 +-
> src/service.c | 237
> ++++++++++++++++++++++++++++++++++++++++-----------
> src/wpad.c | 11 ++-
> 8 files changed, 225 insertions(+), 69 deletions(-)
>
> diff --git a/include/service.h b/include/service.h
> index faa6cf8..ad9a494 100644
> --- a/include/service.h
> +++ b/include/service.h
> @@ -104,7 +104,7 @@ enum connman_service_type connman_service_get_type(struct
> connman_service *servi
> char *connman_service_get_interface(struct connman_service *service);
>
> const char *connman_service_get_domainname(struct connman_service *service);
> -const char *connman_service_get_nameserver(struct connman_service *service);
> +char **connman_service_get_nameservers(struct connman_service *service);
> void connman_service_set_proxy_method(struct connman_service *service, enum
> connman_service_proxy_method method);
> enum connman_service_proxy_method connman_service_get_proxy_method(struct
> connman_service *service);
> char **connman_service_get_proxy_servers(struct connman_service *service);
> diff --git a/plugins/pacrunner.c b/plugins/pacrunner.c
> index 2d0a419..9e94d60 100644
> --- a/plugins/pacrunner.c
> +++ b/plugins/pacrunner.c
> @@ -168,10 +168,11 @@ static void create_proxy_configuration(void)
> connman_dbus_dict_append_array(&dict, "Domains",
> DBUS_TYPE_STRING, append_string, &str);
>
> - str = connman_service_get_nameserver(default_service);
> - if (str != NULL)
> + str_list = connman_service_get_nameservers(default_service);
> + if (str_list != NULL)
> connman_dbus_dict_append_array(&dict, "Nameservers",
> - DBUS_TYPE_STRING, append_string, &str);
> + DBUS_TYPE_STRING, append_string_list,
> + &str_list);
>
> connman_dbus_dict_close(&iter, &dict);
>
> diff --git a/src/connman.h b/src/connman.h
> index 992d533..b61a626 100644
> --- a/src/connman.h
> +++ b/src/connman.h
> @@ -492,10 +492,17 @@ struct connman_service
> *__connman_service_connect_type(enum connman_service_type
>
> const char *__connman_service_type2string(enum connman_service_type type);
>
> -void __connman_service_append_nameserver(struct connman_service *service,
> - const char *nameserver);
> -void __connman_service_remove_nameserver(struct connman_service *service,
> - const char *nameserver);
> +enum connman_service_nameserver_type {
> + CONNMAN_SERVICE_NAMESERVER_TYPE_AUTO = 0,
> + CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL = 1,
> +};
> +
> +int __connman_service_nameserver_append(struct connman_service *service,
> + enum connman_service_nameserver_type
> type,
> + const char *nameserver);
> +int __connman_service_nameserver_remove(struct connman_service *service,
> + enum connman_service_nameserver_type
> type,
> + const char *nameserver);
> void __connman_service_nameserver_add_routes(struct connman_service *service,
> const char *gw);
> void __connman_service_nameserver_del_routes(struct connman_service
> *service);
> diff --git a/src/ipv4.c b/src/ipv4.c
> index f6e436c..628a35c 100644
> --- a/src/ipv4.c
> +++ b/src/ipv4.c
> @@ -83,8 +83,11 @@ static int ipv4_probe(struct connman_element *element)
> if (pac != NULL)
> __connman_service_set_proxy_autoconfig(service, pac);
>
> - if (nameserver != NULL)
> - __connman_service_append_nameserver(service, nameserver);
> + if (nameserver != NULL) {
> + __connman_service_nameserver_append(service,
> + CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL,
> + nameserver);
> + }
>
> connman_timeserver_append(timeserver);
>
> @@ -139,7 +142,9 @@ static void ipv4_remove(struct connman_element *element)
> struct connman_service *service;
>
> service = __connman_element_get_service(element);
> - __connman_service_remove_nameserver(service, nameserver);
> + __connman_service_nameserver_remove(service,
> + CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL,
> + nameserver);
> }
>
> prefixlen = __connman_ipconfig_netmask_prefix_len(netmask);
> diff --git a/src/network.c b/src/network.c
> index 02d7c5c..4832606 100644
> --- a/src/network.c
> +++ b/src/network.c
> @@ -688,8 +688,11 @@ static void set_connected_manual(struct connman_network
> *network)
>
> connman_element_get_value(&network->element,
> CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
> - if (nameserver != NULL)
> - __connman_service_append_nameserver(service, nameserver);
> + if (nameserver != NULL) {
> + __connman_service_nameserver_append(service,
> + CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL,
> + nameserver);
> + }
>
> __connman_ipconfig_set_gateway(ipconfig, &network->element);
>
> diff --git a/src/provider.c b/src/provider.c
> index 6bd2df5..77eae1b 100644
> --- a/src/provider.c
> +++ b/src/provider.c
> @@ -297,7 +297,9 @@ static void provider_set_nameservers(struct
> connman_provider *provider)
> second_ns = strchr(value, ' ');
> if (second_ns)
> *(second_ns++) = 0;
> - __connman_service_append_nameserver(service, value);
> + __connman_service_nameserver_append(service,
> + CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL,
> + value);
> value = second_ns;
>
> while (value) {
> diff --git a/src/service.c b/src/service.c
> index fa2d3e4..e914197 100644
> --- a/src/service.c
> +++ b/src/service.c
> @@ -84,7 +84,7 @@ struct connman_service {
> struct connman_network *network;
> struct connman_provider *provider;
> char **nameservers;
> - char *nameserver;
> + char **nameservers_manual;
> char **domains;
> char *domainname;
> /* 802.1x settings from the config files */
> @@ -308,6 +308,18 @@ static enum connman_service_proxy_method
> string2proxymethod(const char *method)
> return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
> }
>
> +static const char *nameservertype2string(enum
> connman_service_nameserver_type type)
> +{
> + switch (type) {
> + case CONNMAN_SERVICE_NAMESERVER_TYPE_AUTO:
> + return "automatic";
> + case CONNMAN_SERVICE_NAMESERVER_TYPE_MANUAL:
> + return "manual";
> + }
> +
> + return NULL;
> +}
> +
> static connman_bool_t is_connecting(struct connman_service *service)
> {
> switch (service->state) {
> @@ -381,11 +393,18 @@ static void update_nameservers(struct connman_service
> *service)
> if (service->nameservers != NULL) {
> int i;
>
> - for (i = 0; service->nameservers[i]; i++)
> + for (i = 0; service->nameservers[i] != NULL; i++) {
> connman_resolver_append(ifname, NULL,
> service->nameservers[i]);
> - } else if (service->nameserver != NULL)
> - connman_resolver_append(ifname, NULL, service->nameserver);
> + }
> + } else if (service->nameservers_manual != NULL) {
> + int i;
> +
> + for (i = 0; service->nameservers_manual[i] != NULL; i++) {
> + connman_resolver_append(ifname, NULL,
> + service->nameservers_manual[i]);
> + }
> + }
>
> if (service->domains != NULL) {
> int i;
> @@ -399,32 +418,158 @@ static void update_nameservers(struct connman_service
> *service)
> connman_resolver_flush();
> }
>
> -void __connman_service_append_nameserver(struct connman_service *service,
> +static int nameserver_append(char ***nameservers, const char *nameserver
So your nameserver_append() routine here should always modify
service->nameservers (the new one, fro network settings).
service->nameservers_config should be modified by the
Nameservers.Configuration property setting path.
Cheers,
Samuel.
--
Intel Open Source Technology Centre
http://oss.intel.com/
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman