mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-20 22:20:38 +02:00
lldp: decouple NMLldpListener from platform
Make NMLldpListener independent from platform code so that it can be tested more easily.
This commit is contained in:
parent
5b3137984d
commit
6bfa0674c1
3 changed files with 15 additions and 9 deletions
|
|
@ -1189,6 +1189,8 @@ update_dynamic_ip_setup (NMDevice *self)
|
|||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
GError *error;
|
||||
gconstpointer addr;
|
||||
size_t addr_length;
|
||||
|
||||
g_hash_table_remove_all (priv->ip6_saved_properties);
|
||||
|
||||
|
|
@ -1217,8 +1219,10 @@ update_dynamic_ip_setup (NMDevice *self)
|
|||
|
||||
if (priv->lldp_listener && nm_lldp_listener_is_running (priv->lldp_listener)) {
|
||||
nm_lldp_listener_stop (priv->lldp_listener);
|
||||
addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length);
|
||||
|
||||
if (!nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self),
|
||||
nm_device_get_iface (self), &error)) {
|
||||
nm_device_get_iface (self), addr, addr_length, &error)) {
|
||||
_LOGD (LOGD_DEVICE, "LLDP listener %p could not be restarted: %s",
|
||||
priv->lldp_listener, error->message);
|
||||
g_clear_error (&error);
|
||||
|
|
@ -3146,6 +3150,8 @@ activate_stage2_device_config (NMDevice *self)
|
|||
|
||||
if (lldp_rx_enabled (self)) {
|
||||
gs_free_error GError *error = NULL;
|
||||
gconstpointer addr;
|
||||
size_t addr_length;
|
||||
|
||||
if (priv->lldp_listener)
|
||||
nm_lldp_listener_stop (priv->lldp_listener);
|
||||
|
|
@ -3157,8 +3163,10 @@ activate_stage2_device_config (NMDevice *self)
|
|||
self);
|
||||
}
|
||||
|
||||
addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length);
|
||||
|
||||
if (nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self),
|
||||
nm_device_get_iface (self), &error))
|
||||
nm_device_get_iface (self), addr, addr_length, &error))
|
||||
_LOGD (LOGD_DEVICE, "LLDP listener %p started", priv->lldp_listener);
|
||||
else {
|
||||
_LOGD (LOGD_DEVICE, "LLDP listener %p could not be started: %s",
|
||||
|
|
|
|||
|
|
@ -392,11 +392,9 @@ lldp_event_handler (sd_lldp *lldp, int event, void *userdata)
|
|||
|
||||
gboolean
|
||||
nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface,
|
||||
GError **error)
|
||||
const guint8 *mac, guint mac_len, GError **error)
|
||||
{
|
||||
NMLldpListenerPrivate *priv;
|
||||
const struct ether_addr *addr;
|
||||
size_t addr_len;
|
||||
int ret;
|
||||
|
||||
g_return_val_if_fail (NM_IS_LLDP_LISTENER (self), FALSE);
|
||||
|
|
@ -412,14 +410,13 @@ nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
addr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addr_len);
|
||||
if (!addr || addr_len != ETH_ALEN) {
|
||||
if (!mac || mac_len != ETH_ALEN) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
||||
"unsupported device");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ret = sd_lldp_new (ifindex, iface, addr, &priv->lldp_handle);
|
||||
ret = sd_lldp_new (ifindex, iface, (struct ether_addr *) mac, &priv->lldp_handle);
|
||||
if (ret) {
|
||||
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
||||
"initialization failed");
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ typedef struct {
|
|||
|
||||
GType nm_lldp_listener_get_type (void);
|
||||
NMLldpListener *nm_lldp_listener_new (void);
|
||||
gboolean nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface, GError **error);
|
||||
gboolean nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface,
|
||||
const guint8 *mac, guint mac_len, GError **error);
|
||||
void nm_lldp_listener_stop (NMLldpListener *self);
|
||||
gboolean nm_lldp_listener_is_running (NMLldpListener *self);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue