Commit 40babe1c authored by Beniamino Galvani's avatar Beniamino Galvani

dhcp: pass broadcast address to clients

Read the broadcast address from platform and pass it to
clients. Currently only the nettool backends uses it.
parent 1609f508
......@@ -7966,6 +7966,7 @@ dhcp4_start (NMDevice *self)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMSettingIPConfig *s_ip4;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *client_id = NULL;
NMConnection *connection;
GError *error = NULL;
......@@ -7981,8 +7982,10 @@ dhcp4_start (NMDevice *self)
priv->dhcp4.config = nm_dhcp4_config_new ();
pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self));
if (pllink)
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
client_id = dhcp4_get_client_id (self, connection, hwaddr);
......@@ -7992,6 +7995,7 @@ dhcp4_start (NMDevice *self)
nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self),
hwaddr,
bcast_hwaddr,
nm_connection_get_uuid (connection),
nm_device_get_route_table (self, AF_INET),
nm_device_get_route_metric (self, AF_INET),
......@@ -8769,6 +8773,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMSettingIPConfig *s_ip6;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *duid = NULL;
gboolean enforce_duid = FALSE;
const NMPlatformLink *pllink;
......@@ -8792,8 +8797,10 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
}
pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self));
if (pllink)
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
duid = dhcp6_get_duid (self, connection, hwaddr, &enforce_duid);
priv->dhcp6.client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (),
......@@ -8801,6 +8808,7 @@ dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
nm_device_get_ip_iface (self),
nm_device_get_ip_ifindex (self),
hwaddr,
bcast_hwaddr,
&ll_addr->address,
nm_connection_get_uuid (connection),
nm_device_get_route_table (self, AF_INET6),
......
......@@ -51,6 +51,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpClient,
PROP_ADDR_FAMILY,
PROP_FLAGS,
PROP_HWADDR,
PROP_BROADCAST_HWADDR,
PROP_IFACE,
PROP_IFINDEX,
PROP_MULTI_IDX,
......@@ -65,6 +66,7 @@ typedef struct _NMDhcpClientPrivate {
NMDedupMultiIndex *multi_idx;
char * iface;
GBytes * hwaddr;
GBytes * bcast_hwaddr;
char * uuid;
GBytes * client_id;
char * hostname;
......@@ -143,6 +145,14 @@ nm_dhcp_client_get_hw_addr (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->hwaddr;
}
GBytes *
nm_dhcp_client_get_broadcast_hw_addr (NMDhcpClient *self)
{
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
return NM_DHCP_CLIENT_GET_PRIVATE (self)->bcast_hwaddr;
}
guint32
nm_dhcp_client_get_route_table (NMDhcpClient *self)
{
......@@ -869,6 +879,9 @@ get_property (GObject *object, guint prop_id,
case PROP_HWADDR:
g_value_set_boxed (value, priv->hwaddr);
break;
case PROP_BROADCAST_HWADDR:
g_value_set_boxed (value, priv->bcast_hwaddr);
break;
case PROP_ADDR_FAMILY:
g_value_set_int (value, priv->addr_family);
break;
......@@ -930,6 +943,10 @@ set_property (GObject *object, guint prop_id,
/* construct-only */
priv->hwaddr = g_value_dup_boxed (value);
break;
case PROP_BROADCAST_HWADDR:
/* construct-only */
priv->bcast_hwaddr = g_value_dup_boxed (value);
break;
case PROP_ADDR_FAMILY:
/* construct-only */
priv->addr_family = g_value_get_int (value);
......@@ -996,6 +1013,7 @@ dispose (GObject *object)
g_clear_pointer (&priv->uuid, g_free);
g_clear_pointer (&priv->client_id, g_bytes_unref);
g_clear_pointer (&priv->hwaddr, g_bytes_unref);
g_clear_pointer (&priv->bcast_hwaddr, g_bytes_unref);
G_OBJECT_CLASS (nm_dhcp_client_parent_class)->dispose (object);
......@@ -1040,6 +1058,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_BROADCAST_HWADDR] =
g_param_spec_boxed (NM_DHCP_CLIENT_BROADCAST_HWADDR, "", "",
G_TYPE_BYTES,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_ADDR_FAMILY] =
g_param_spec_int (NM_DHCP_CLIENT_ADDR_FAMILY, "", "",
0, G_MAXINT, AF_UNSPEC,
......
......@@ -34,17 +34,18 @@
#define NM_IS_DHCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CLIENT))
#define NM_DHCP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClientClass))
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
#define NM_DHCP_CLIENT_FLAGS "flags"
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
#define NM_DHCP_CLIENT_INTERFACE "iface"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_HOSTNAME "hostname"
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_ADDR_FAMILY "addr-family"
#define NM_DHCP_CLIENT_FLAGS "flags"
#define NM_DHCP_CLIENT_HWADDR "hwaddr"
#define NM_DHCP_CLIENT_BROADCAST_HWADDR "broadcast-hwaddr"
#define NM_DHCP_CLIENT_IFINDEX "ifindex"
#define NM_DHCP_CLIENT_INTERFACE "iface"
#define NM_DHCP_CLIENT_MULTI_IDX "multi-idx"
#define NM_DHCP_CLIENT_HOSTNAME "hostname"
#define NM_DHCP_CLIENT_ROUTE_METRIC "route-metric"
#define NM_DHCP_CLIENT_ROUTE_TABLE "route-table"
#define NM_DHCP_CLIENT_TIMEOUT "timeout"
#define NM_DHCP_CLIENT_UUID "uuid"
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
......@@ -129,6 +130,8 @@ GBytes *nm_dhcp_client_get_duid (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_broadcast_hw_addr (NMDhcpClient *self);
guint32 nm_dhcp_client_get_route_table (NMDhcpClient *self);
void nm_dhcp_client_set_route_table (NMDhcpClient *self, guint32 route_table);
......
......@@ -204,6 +204,7 @@ client_start (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
......@@ -233,10 +234,11 @@ client_start (NMDhcpManager *self,
g_return_val_if_fail (!dhcp_client_id || g_bytes_get_size (dhcp_client_id) >= 2, NULL);
g_return_val_if_fail (!error || !*error, NULL);
if (!hwaddr) {
if (!hwaddr || !bcast_hwaddr) {
nm_utils_error_set (error,
NM_UTILS_ERROR_UNKNOWN,
"missing MAC address");
"missing %s address",
hwaddr ? "broadcast" : "MAC");
return NULL;
}
......@@ -249,6 +251,8 @@ client_start (NMDhcpManager *self,
g_return_val_if_reached (NULL) ;
}
nm_assert (g_bytes_get_size (hwaddr) == g_bytes_get_size (bcast_hwaddr));
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
client_factory = _client_factory_get_effective (priv->client_factory, addr_family);
......@@ -273,6 +277,7 @@ client_start (NMDhcpManager *self,
NM_DHCP_CLIENT_INTERFACE, iface,
NM_DHCP_CLIENT_IFINDEX, ifindex,
NM_DHCP_CLIENT_HWADDR, hwaddr,
NM_DHCP_CLIENT_BROADCAST_HWADDR, bcast_hwaddr,
NM_DHCP_CLIENT_UUID, uuid,
NM_DHCP_CLIENT_HOSTNAME, hostname,
NM_DHCP_CLIENT_ROUTE_TABLE, (guint) route_table,
......@@ -345,6 +350,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
......@@ -395,6 +401,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
iface,
ifindex,
hwaddr,
bcast_hwaddr,
uuid,
route_table,
route_metric,
......@@ -419,6 +426,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const struct in6_addr *ll_addr,
const char *uuid,
guint32 route_table,
......@@ -450,6 +458,7 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
iface,
ifindex,
hwaddr,
bcast_hwaddr,
uuid,
route_table,
route_metric,
......
......@@ -49,6 +49,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const char *uuid,
guint32 route_table,
guint32 route_metric,
......@@ -66,6 +67,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
const char *iface,
int ifindex,
GBytes *hwaddr,
GBytes *bcast_hwaddr,
const struct in6_addr *ll_addr,
const char *uuid,
guint32 route_table,
......
......@@ -1083,8 +1083,11 @@ nettools_create (NMDhcpNettools *self,
nm_auto (n_dhcp4_client_config_freep) NDhcp4ClientConfig *config = NULL;
nm_auto (n_dhcp4_client_unrefp) NDhcp4Client *client = NULL;
GBytes *hwaddr;
GBytes *bcast_hwaddr;
const uint8_t *hwaddr_arr;
const uint8_t *bcast_hwaddr_arr;
gsize hwaddr_len;
gsize bcast_hwaddr_len;
GBytes *client_id;
gs_unref_bytes GBytes *client_id_new = NULL;
const uint8_t *client_id_arr;
......@@ -1101,6 +1104,9 @@ nettools_create (NMDhcpNettools *self,
return FALSE;
}
bcast_hwaddr = nm_dhcp_client_get_broadcast_hw_addr (NM_DHCP_CLIENT (self));
bcast_hwaddr_arr = g_bytes_get_data (bcast_hwaddr, &bcast_hwaddr_len);
switch (arp_type) {
case ARPHRD_ETHER:
transport = N_DHCP4_TRANSPORT_ETHERNET;
......@@ -1140,7 +1146,7 @@ nettools_create (NMDhcpNettools *self,
n_dhcp4_client_config_set_ifindex (config, nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)));
n_dhcp4_client_config_set_transport (config, transport);
n_dhcp4_client_config_set_mac (config, hwaddr_arr, hwaddr_len);
n_dhcp4_client_config_set_broadcast_mac (config, (unsigned char[]){ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, ETH_ALEN); /* XXX */
n_dhcp4_client_config_set_broadcast_mac (config, bcast_hwaddr_arr, bcast_hwaddr_len);
r = n_dhcp4_client_config_set_client_id (config, client_id_arr, client_id_len);
if (r) {
nm_utils_error_set_errno (error, r, "failed to set client-id: %s");
......
......@@ -381,6 +381,7 @@ main (int argc, char *argv[])
gs_unref_object NMDhcpClient *dhcp4_client = NULL;
gs_unref_object NMNDisc *ndisc = NULL;
gs_unref_bytes GBytes *hwaddr = NULL;
gs_unref_bytes GBytes *bcast_hwaddr = NULL;
gs_unref_bytes GBytes *client_id = NULL;
gs_free NMUtilsIPv6IfaceId *iid = NULL;
const NMPlatformLink *pllink;
......@@ -471,8 +472,10 @@ main (int argc, char *argv[])
nm_linux_platform_setup ();
pllink = nm_platform_link_get (NM_PLATFORM_GET, gl.ifindex);
if (pllink)
if (pllink) {
hwaddr = nmp_link_address_get_as_bytes (&pllink->l_address);
bcast_hwaddr = nmp_link_address_get_as_bytes (&pllink->l_broadcast);
}
if (global_opt.iid_str) {
GBytes *bytes;
......@@ -508,6 +511,7 @@ main (int argc, char *argv[])
global_opt.ifname,
gl.ifindex,
hwaddr,
bcast_hwaddr,
global_opt.uuid,
RT_TABLE_MAIN,
global_opt.priority_v4,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment