This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 Makefile.am            |    2 +-
 client/Makefile.am     |    2 +
 configure.ac           |    4 +-
 doc/connection-api.txt |    5 +
 include/property.h     |    1 +
 include/rtnl.h         |    3 +
 plugins/dnsproxy.c     |    6 +-
 plugins/ipv4.c         |  317 +++++++++++++++++++++++++++++++++++++++++++-----
 src/element.c          |   65 ++++++++++-
 src/rtnl.c             |  316 +++++++++++++++++++++++++++++++++++++++--------
 test/Makefile.am       |    2 +-
 test/select-connection |   23 ++++
 test/test-manager      |   16 ++-
 13 files changed, 665 insertions(+), 97 deletions(-)

New commits:
commit 6fc25870e4cb00374c96ce31f012fe188475f4aa
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 09:11:05 2008 +0100

    Fix offline state signal emission

commit 212b3e0a7b14bebbf9886ac16eaf8a8b33a985be
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:54:31 2008 +0100

    Print boolean properties as true or false

commit f457515a077ff1946ec5ab00635c47a2a40bab8a
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:50:11 2008 +0100

    Add script for selecting connections

commit 93ee679d1e82bbc875130e077f8558230b8d4b29
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:46:10 2008 +0100

    Add support for changing default connections

commit 0be58a73c3f1def6e578424380b15370a9a6440c
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:45:41 2008 +0100

    Add support for enabling/disabling gateway setting

commit 6d80d487757835256edbeb32beddde8fb93ac99d
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:18:54 2008 +0100

    Track gateway changes and don't overwrite default gateway

commit 3bbee5b2cc7b77a044ea32f46a4469d0b5cdddf2
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 08:09:03 2008 +0100

    Add property to indicate default connections

commit 97fc312c6036c72eb392dcefe080e30404673f18
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 07:49:43 2008 +0100

    Add support RTNL gateway change notifications

commit 0323435d73aeaf0dea25e40e7b41bf6d1a4534f3
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 04:59:36 2008 +0100

    Add support for IPv4.Broadcast property

commit 09959bf44d59941446f11980dcaf3aa1061edc13
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 04:09:20 2008 +0100

    Fix error handling of init routine

commit 273799ecfabe3d3a696dda38d8a400fac08d12d0
Author: Marcel Holtmann <[email protected]>
Date:   Mon Dec 15 04:05:18 2008 +0100

    Add directory for client application


Diff in this email is a maximum of 400 lines.
diff --git a/Makefile.am b/Makefile.am
index 0b875b7..78c98b8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
 
-SUBDIRS = gdbus include src plugins scripts test doc
+SUBDIRS = gdbus include src plugins client scripts test doc
 
 pkgconfigdir = $(libdir)/pkgconfig
 
diff --git a/client/Makefile.am b/client/Makefile.am
new file mode 100644
index 0000000..0274292
--- /dev/null
+++ b/client/Makefile.am
@@ -0,0 +1,2 @@
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/configure.ac b/configure.ac
index 0a10c57..c5a7a1d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,5 +89,5 @@ AC_ARG_ENABLE(fake, AC_HELP_STRING([--enable-fake],
 AM_CONDITIONAL(FAKE, test "${enable_fake}" = "yes")
 
 AC_OUTPUT(Makefile gdbus/Makefile include/Makefile src/Makefile doc/Makefile
-               test/Makefile plugins/Makefile scripts/Makefile scripts/connman
-                               src/connman.service doc/version.xml connman.pc)
+               test/Makefile plugins/Makefile client/Makefile scripts/Makefile
+               scripts/connman src/connman.service doc/version.xml connman.pc)
diff --git a/doc/connection-api.txt b/doc/connection-api.txt
index 7356b34..c39c6d2 100644
--- a/doc/connection-api.txt
+++ b/doc/connection-api.txt
@@ -27,6 +27,11 @@ Properties   string Type [readonly]
 
                        This property is optional and not always present.
 
+               boolean Default [readonly]
+
+                       Indicates if it is a default connection. It is
+                       possible to have multiple default connections.
+
                string IPv4.Method [readonly]
 
                        Indicates the way how the IPv4 settings were
diff --git a/include/property.h b/include/property.h
index 4c42f44..fe734c2 100644
--- a/include/property.h
+++ b/include/property.h
@@ -39,6 +39,7 @@ enum connman_property_id {
        CONNMAN_PROPERTY_ID_IPV4_ADDRESS,
        CONNMAN_PROPERTY_ID_IPV4_NETMASK,
        CONNMAN_PROPERTY_ID_IPV4_GATEWAY,
+       CONNMAN_PROPERTY_ID_IPV4_BROADCAST,
        CONNMAN_PROPERTY_ID_IPV4_NAMESERVER,
 
        CONNMAN_PROPERTY_ID_WIFI_SECURITY,
diff --git a/include/rtnl.h b/include/rtnl.h
index 395d20b..5637fb9 100644
--- a/include/rtnl.h
+++ b/include/rtnl.h
@@ -43,12 +43,15 @@ struct connman_rtnl {
                                        unsigned flags, unsigned change);
        void (*dellink) (unsigned short type, int index,
                                        unsigned flags, unsigned change);
+       void (*newgateway) (int index, const char *gateway);
+       void (*delgateway) (int index, const char *gateway);
 };
 
 extern int connman_rtnl_register(struct connman_rtnl *rtnl);
 extern void connman_rtnl_unregister(struct connman_rtnl *rtnl);
 
 int connman_rtnl_send_getlink(void);
+int connman_rtnl_send_getroute(void);
 
 #ifdef __cplusplus
 }
diff --git a/plugins/dnsproxy.c b/plugins/dnsproxy.c
index bc61d51..39eefec 100644
--- a/plugins/dnsproxy.c
+++ b/plugins/dnsproxy.c
@@ -368,12 +368,10 @@ static int dnsproxy_init(void)
                return err;
 
        err = connman_resolver_register(&dnsproxy_resolver);
-       if (err < 0) {
+       if (err < 0)
                destroy_listener();
-               return err;
-       }
 
-       return 0;
+       return err;
 }
 
 static void dnsproxy_exit(void)
diff --git a/plugins/ipv4.c b/plugins/ipv4.c
index ddff153..b1c26d4 100644
--- a/plugins/ipv4.c
+++ b/plugins/ipv4.c
@@ -38,6 +38,7 @@
 #include <connman/plugin.h>
 #include <connman/driver.h>
 #include <connman/resolver.h>
+#include <connman/rtnl.h>
 #include <connman/log.h>
 
 #include "inet.h"
@@ -53,17 +54,41 @@ struct connman_ipv4 {
        enum connman_ipv4_method method;
        struct in_addr address;
        struct in_addr netmask;
-       struct in_addr gateway;
-       struct in_addr network;
        struct in_addr broadcast;
-       struct in_addr nameserver;
 };
 
+struct gateway_data {
+       int index;
+       char *gateway;
+};
+
+static GSList *gateway_list = NULL;
+
+static struct gateway_data *find_gateway(int index, const char *gateway)
+{
+       GSList *list;
+
+       if (gateway == NULL)
+               return NULL;
+
+       for (list = gateway_list; list; list = list->next) {
+               struct gateway_data *data = list->data;
+
+               if (data->gateway == NULL)
+                       continue;
+
+               if (data->index == index &&
+                               g_str_equal(data->gateway, gateway) == TRUE)
+                       return data;
+       }
+
+       return NULL;
+}
+
 static int set_ipv4(struct connman_element *element,
                        struct connman_ipv4 *ipv4, const char *nameserver)
 {
        struct ifreq ifr;
-       struct rtentry rt;
        struct sockaddr_in *addr;
        int sk, err;
 
@@ -110,6 +135,77 @@ static int set_ipv4(struct connman_element *element,
        if (err < 0)
                DBG("broadcast setting failed (%s)", strerror(errno));
 
+       close(sk);
+
+       connman_resolver_append(ifr.ifr_name, NULL, nameserver);
+
+       return 0;
+}
+
+static int clear_ipv4(struct connman_element *element)
+{
+       struct ifreq ifr;
+       struct sockaddr_in *addr;
+       int sk, err;
+
+       DBG("element %p", element);
+
+       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       if (sk < 0)
+               return -1;
+
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_ifindex = element->index;
+
+       if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+               close(sk);
+               return -1;
+       }
+
+       DBG("ifname %s", ifr.ifr_name);
+
+       connman_resolver_remove_all(ifr.ifr_name);
+
+       addr = (struct sockaddr_in *) &ifr.ifr_addr;
+       addr->sin_family = AF_INET;
+       addr->sin_addr.s_addr = INADDR_ANY;
+
+       //err = ioctl(sk, SIOCDIFADDR, &ifr);
+       err = ioctl(sk, SIOCSIFADDR, &ifr);
+
+       close(sk);
+
+       if (err < 0 && errno != EADDRNOTAVAIL) {
+               DBG("address removal failed (%s)", strerror(errno));
+               return -1;
+       }
+
+       return 0;
+}
+
+static int set_route(struct connman_element *element, const char *gateway)
+{
+       struct ifreq ifr;
+       struct rtentry rt;
+       struct sockaddr_in *addr;
+       int sk, err;
+
+       DBG("element %p", element);
+
+       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       if (sk < 0)
+               return -1;
+
+       memset(&ifr, 0, sizeof(ifr));
+       ifr.ifr_ifindex = element->index;
+
+       if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
+               close(sk);
+               return -1;
+       }
+
+       DBG("ifname %s", ifr.ifr_name);
+
        memset(&rt, 0, sizeof(rt));
        rt.rt_flags = RTF_UP | RTF_GATEWAY;
 
@@ -119,29 +215,25 @@ static int set_ipv4(struct connman_element *element,
 
        addr = (struct sockaddr_in *) &rt.rt_gateway;
        addr->sin_family = AF_INET;
-       addr->sin_addr = ipv4->gateway;
+       addr->sin_addr.s_addr = inet_addr(gateway);
 
        addr = (struct sockaddr_in *) &rt.rt_genmask;
        addr->sin_family = AF_INET;
        addr->sin_addr.s_addr = INADDR_ANY;
 
        err = ioctl(sk, SIOCADDRT, &rt);
+       if (err < 0)
+               DBG("default route setting failed (%s)", strerror(errno));
 
        close(sk);
 
-       if (err < 0) {
-               DBG("default route failed (%s)", strerror(errno));
-               return -1;
-       }
-
-       connman_resolver_append(ifr.ifr_name, NULL, nameserver);
-
-       return 0;
+       return err;
 }
 
-static int clear_ipv4(struct connman_element *element)
+static int del_route(struct connman_element *element, const char *gateway)
 {
        struct ifreq ifr;
+       struct rtentry rt;
        struct sockaddr_in *addr;
        int sk, err;
 
@@ -161,30 +253,119 @@ static int clear_ipv4(struct connman_element *element)
 
        DBG("ifname %s", ifr.ifr_name);
 
-       connman_resolver_remove_all(ifr.ifr_name);
+       memset(&rt, 0, sizeof(rt));
+       rt.rt_flags = RTF_UP | RTF_GATEWAY;
 
-       addr = (struct sockaddr_in *) &ifr.ifr_addr;
+       addr = (struct sockaddr_in *) &rt.rt_dst;
        addr->sin_family = AF_INET;
        addr->sin_addr.s_addr = INADDR_ANY;
 
-       //err = ioctl(sk, SIOCDIFADDR, &ifr);
-       err = ioctl(sk, SIOCSIFADDR, &ifr);
+       addr = (struct sockaddr_in *) &rt.rt_gateway;
+       addr->sin_family = AF_INET;
+       addr->sin_addr.s_addr = inet_addr(gateway);
+
+       addr = (struct sockaddr_in *) &rt.rt_genmask;
+       addr->sin_family = AF_INET;
+       addr->sin_addr.s_addr = INADDR_ANY;
+
+       err = ioctl(sk, SIOCDELRT, &rt);
+       if (err < 0)
+               DBG("default route removal failed (%s)", strerror(errno));
 
        close(sk);
 
-       if (err < 0 && errno != EADDRNOTAVAIL) {
-               DBG("address removal failed (%s)", strerror(errno));
-               return -1;
+       return err;
+}
+
+static int conn_probe(struct connman_element *element)
+{
+       const char *gateway = NULL;
+
+       DBG("element %p name %s", element, element->name);
+
+       if (element->parent == NULL)
+               return -ENODEV;
+
+       if (element->parent->type != CONNMAN_ELEMENT_TYPE_IPV4)
+               return -ENODEV;
+
+       connman_element_get_value(element,
+                               CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
+
+       DBG("gateway %s", gateway);
+
+       if (gateway == NULL)
+               return 0;
+
+       if (g_slist_length(gateway_list) > 0) {
+               DBG("default already present");
+               return 0;
        }
 
+       set_route(element, gateway);
+
+       connman_element_set_enabled(element, TRUE);
+
        return 0;
 }
 
+static void conn_remove(struct connman_element *element)
+{
+       DBG("element %p name %s", element, element->name);
+}
+
+static int conn_enable(struct connman_element *element)
+{
+       const char *gateway = NULL;
+
+       DBG("element %p name %s", element, element->name);
+
+       connman_element_get_value(element,
+                               CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
+
+       DBG("gateway %s", gateway);
+
+       if (gateway == NULL)
+               return -EINVAL;
+
+       set_route(element, gateway);
+
+       return 0;
+}
+
+static int conn_disable(struct connman_element *element)
+{
+       const char *gateway = NULL;
+
+       DBG("element %p name %s", element, element->name);
+
+       connman_element_get_value(element,
+                               CONNMAN_PROPERTY_ID_IPV4_GATEWAY, &gateway);
+
+       DBG("gateway %s", gateway);
+
+       if (gateway == NULL)
+               return -EINVAL;
+
+       del_route(element, gateway);
+
+       return 0;
+}
+
+static struct connman_driver conn_driver = {
+       .name           = "ipv4-connection",
+       .type           = CONNMAN_ELEMENT_TYPE_CONNECTION,
+       .probe          = conn_probe,
+       .remove         = conn_remove,
+       .enable         = conn_enable,
+       .disable        = conn_disable,
+};
+
 static int ipv4_probe(struct connman_element *element)
 {
        struct connman_element *connection;
        struct connman_ipv4 ipv4;
-       const char *address = NULL, *netmask = NULL, *gateway = NULL;
+       const char *address = NULL, *netmask = NULL, *broadcast = NULL;
        const char *nameserver = NULL;
 
        DBG("element %p name %s", element, element->name);
@@ -194,22 +375,22 @@ static int ipv4_probe(struct connman_element *element)
        connman_element_get_value(element,
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to