A DHCP anycast address can now be specified for each NMDevice.
The OLPC mesh device will use this to target DHCP requests at
the predefined mesh portal anycast addresses.
---
 src/dhcp-manager/nm-dhcp-dhclient.c |   22 ++++++++++++++++++----
 src/dhcp-manager/nm-dhcp-dhcpcd.c   |    3 ++-
 src/dhcp-manager/nm-dhcp-manager.c  |    5 +++--
 src/dhcp-manager/nm-dhcp-manager.h  |    6 ++++--
 src/nm-device.c                     |   31 ++++++++++++++++++++++++++++++-
 src/nm-device.h                     |    1 +
 6 files changed, 58 insertions(+), 10 deletions(-)

For master branch

diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c 
b/src/dhcp-manager/nm-dhcp-dhclient.c
index 28b5a23..d5b723b 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -84,6 +84,7 @@ get_leasefile_for_iface (const char * iface, const char *uuid)
 static gboolean
 merge_dhclient_config (NMDHCPDevice *device,
                        NMSettingIP4Config *s_ip4,
+                       guint8 *anycast_addr,
                        const char *contents,
                        const char *orig,
                        GError **error)
@@ -143,6 +144,16 @@ merge_dhclient_config (NMDHCPDevice *device,
                        g_string_append_printf (new_contents, 
DHCP_HOSTNAME_FORMAT "\n", tmp);
        }
 
+       if (anycast_addr)
+               g_string_append_printf (new_contents, "interface \"%s\" {\n"
+                                       " initial-interval 1; \n"
+                                       " anycast-mac ethernet 
%02x:%02x:%02x:%02x:%02x:%02x;\n"
+                                       "}\n",
+                                       device->iface,
+                                anycast_addr[0], anycast_addr[1],
+                                anycast_addr[2], anycast_addr[3],
+                                anycast_addr[4], anycast_addr[5]);
+
        if (g_file_set_contents (device->conf_file, new_contents->str, -1, 
error))
                success = TRUE;
 
@@ -157,7 +168,9 @@ merge_dhclient_config (NMDHCPDevice *device,
  * config file along with the NM options.
  */
 static gboolean
-create_dhclient_config (NMDHCPDevice *device, NMSettingIP4Config *s_ip4)
+create_dhclient_config (NMDHCPDevice *device,
+                        NMSettingIP4Config *s_ip4,
+                        guint8 *dhcp_anycast_addr)
 {
        char *orig = NULL, *contents = NULL;
        GError *error = NULL;
@@ -197,7 +210,7 @@ create_dhclient_config (NMDHCPDevice *device, 
NMSettingIP4Config *s_ip4)
 
 out:
        error = NULL;
-       if (merge_dhclient_config (device, s_ip4, contents, orig, &error))
+       if (merge_dhclient_config (device, s_ip4, dhcp_anycast_addr, contents, 
orig, &error))
                success = TRUE;
        else {
                nm_warning ("%s: error creating dhclient configuration: %s",
@@ -223,7 +236,8 @@ dhclient_child_setup (gpointer user_data G_GNUC_UNUSED)
 GPid
 nm_dhcp_client_start (NMDHCPDevice *device,
                       const char *uuid,
-                      NMSettingIP4Config *s_ip4)
+                      NMSettingIP4Config *s_ip4,
+                      guint8 *dhcp_anycast_addr)
 {
        GPtrArray *dhclient_argv = NULL;
        GPid pid = 0;
@@ -247,7 +261,7 @@ nm_dhcp_client_start (NMDHCPDevice *device,
                goto out;
        }
 
-       if (!create_dhclient_config (device, s_ip4))
+       if (!create_dhclient_config (device, s_ip4, dhcp_anycast_addr))
                goto out;
 
        /* Kill any existing dhclient bound to this interface */
diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c 
b/src/dhcp-manager/nm-dhcp-dhcpcd.c
index 05db9dd..a6ce8d2 100644
--- a/src/dhcp-manager/nm-dhcp-dhcpcd.c
+++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c
@@ -62,7 +62,8 @@ dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED)
 GPid
 nm_dhcp_client_start (NMDHCPDevice *device,
                       const char *uuid,
-                      NMSettingIP4Config *s_ip4)
+                      NMSettingIP4Config *s_ip4,
+                      guint8 *dhcp_anycast_addr)
 {
        GPtrArray *argv = NULL;
        GPid pid = 0;
diff --git a/src/dhcp-manager/nm-dhcp-manager.c 
b/src/dhcp-manager/nm-dhcp-manager.c
index c068f10..9c3be37 100644
--- a/src/dhcp-manager/nm-dhcp-manager.c
+++ b/src/dhcp-manager/nm-dhcp-manager.c
@@ -588,7 +588,8 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
                                    const char *iface,
                                    const char *uuid,
                                    NMSettingIP4Config *s_ip4,
-                                   guint32 timeout)
+                                   guint32 timeout,
+                                   guint8 *dhcp_anycast_addr)
 {
        NMDHCPManagerPrivate *priv;
        NMDHCPDevice *device;
@@ -629,7 +630,7 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
                timeout = NM_DHCP_TIMEOUT;
 
        nm_info ("Activation (%s) Beginning DHCP transaction (timeout in 
%dsecs)", iface, timeout);
-       device->pid = nm_dhcp_client_start (device, uuid, setting);
+       device->pid = nm_dhcp_client_start (device, uuid, setting, 
dhcp_anycast_addr);
 
        if (setting)
                g_object_unref (setting);
diff --git a/src/dhcp-manager/nm-dhcp-manager.h 
b/src/dhcp-manager/nm-dhcp-manager.h
index f8737cb..6880a23 100644
--- a/src/dhcp-manager/nm-dhcp-manager.h
+++ b/src/dhcp-manager/nm-dhcp-manager.h
@@ -95,7 +95,8 @@ gboolean       nm_dhcp_manager_begin_transaction    
(NMDHCPManager *manager,
                                                      const char *iface,
                                                      const char *uuid,
                                                      NMSettingIP4Config *s_ip4,
-                                                     guint32 timeout);
+                                                     guint32 timeout,
+                                                     guint8 
*dhcp_anycast_addr);
 void           nm_dhcp_manager_cancel_transaction   (NMDHCPManager *manager,
                                                      const char *iface);
 NMIP4Config *  nm_dhcp_manager_get_ip4_config       (NMDHCPManager *manager, 
const char *iface);
@@ -109,7 +110,8 @@ gboolean       nm_dhcp_manager_foreach_dhcp4_option 
(NMDHCPManager *self,
 /* The following are implemented by the DHCP client backends */
 GPid           nm_dhcp_client_start                 (NMDHCPDevice *device,
                                                      const char *uuid,
-                                                     NMSettingIP4Config 
*s_ip4);
+                                                     NMSettingIP4Config *s_ip4,
+                                                     guint8 *anycast_addr);
 void           nm_dhcp_client_stop                  (NMDHCPDevice *device, 
pid_t pid);
 
 gboolean       nm_dhcp_client_process_classless_routes (GHashTable *options,
diff --git a/src/nm-device.c b/src/nm-device.c
index 114712c..06cfaf1 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -92,6 +92,7 @@ typedef struct {
        guint32         dhcp_timeout;
        gulong          dhcp_state_sigid;
        gulong          dhcp_timeout_sigid;
+       GByteArray *    dhcp_anycast_address;
        NMDHCP4Config * dhcp4_config;
 
        /* dnsmasq stuff for shared connections */
@@ -894,6 +895,10 @@ real_act_stage3_ip_config_start (NMDevice *self, 
NMDeviceStateReason *reason)
        if (!s_ip4 || !method || !strcmp (method, 
NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
                NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
                gboolean success;
+               guint8 *anycast = NULL;
+
+               if (priv->dhcp_anycast_address)
+                       anycast = priv->dhcp_anycast_address->data;
 
                /* Begin a DHCP transaction on the interface */
                nm_device_set_use_dhcp (self, TRUE);
@@ -901,7 +906,7 @@ real_act_stage3_ip_config_start (NMDevice *self, 
NMDeviceStateReason *reason)
                /* DHCP manager will cancel any transaction already in progress 
and we do not
                   want to cancel this activation if we get "down" state from 
that. */
                g_signal_handler_block (priv->dhcp_manager, 
priv->dhcp_state_sigid);
-               success = nm_dhcp_manager_begin_transaction 
(priv->dhcp_manager, ip_iface, uuid, s_ip4, priv->dhcp_timeout);
+               success = nm_dhcp_manager_begin_transaction 
(priv->dhcp_manager, ip_iface, uuid, s_ip4, priv->dhcp_timeout, anycast);
                g_signal_handler_unblock (priv->dhcp_manager, 
priv->dhcp_state_sigid);
 
                if (success) {
@@ -2218,6 +2223,8 @@ finalize (GObject *object)
        g_free (priv->ip_iface);
        g_free (priv->driver);
        g_free (priv->type_desc);
+       if (priv->dhcp_anycast_address)
+               g_byte_array_free (priv->dhcp_anycast_address, TRUE);
 
        G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
 }
@@ -2547,3 +2554,25 @@ nm_device_set_dhcp_timeout (NMDevice *device,
        NM_DEVICE_GET_PRIVATE (device)->dhcp_timeout = timeout;
 }
 
+void
+nm_device_set_dhcp_anycast_address (NMDevice *device,
+                                    guint8 *addr)
+{
+       NMDevicePrivate *priv;
+
+       g_return_if_fail (NM_IS_DEVICE (device));
+
+       priv = NM_DEVICE_GET_PRIVATE (device);
+
+       if (priv->dhcp_anycast_address)
+               g_byte_array_free (priv->dhcp_anycast_address, TRUE);
+
+       if (addr) {
+               priv->dhcp_anycast_address = g_byte_array_sized_new (ETH_ALEN);
+               g_byte_array_append (priv->dhcp_anycast_address, addr, 
ETH_ALEN);
+       } else {
+               priv->dhcp_anycast_address = NULL;
+       }
+}
+
+
diff --git a/src/nm-device.h b/src/nm-device.h
index 3900393..45a3f9e 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -163,6 +163,7 @@ void nm_device_set_managed (NMDevice *device,
                             NMDeviceStateReason reason);
 
 void nm_device_set_dhcp_timeout (NMDevice *device, guint32 timeout);
+void nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr);
 
 G_END_DECLS
 
-- 
1.6.2.5

_______________________________________________
NetworkManager-list mailing list
NetworkManager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to