예제 #1
0
void
nm_lldp_listener_stop (NMLldpListener *self)
{
	NMLldpListenerPrivate *priv;
	guint size;

	g_return_if_fail (NM_IS_LLDP_LISTENER (self));
	priv = NM_LLDP_LISTENER_GET_PRIVATE (self);

	if (priv->lldp_handle) {
		sd_lldp_stop (priv->lldp_handle);
		sd_lldp_detach_event (priv->lldp_handle);
		sd_lldp_unref (priv->lldp_handle);
		g_clear_pointer (&priv->iface, g_free);
		priv->lldp_handle = NULL;

		size = g_hash_table_size (priv->lldp_neighbors);
		g_hash_table_remove_all (priv->lldp_neighbors);
		if (size) {
			nm_clear_g_variant (&priv->variant);
			g_object_notify (G_OBJECT (self), NM_LLDP_LISTENER_NEIGHBORS);
		}
	}

	nm_clear_g_source (&priv->timer);
}
예제 #2
0
static int stop_lldp(sd_lldp *lldp) {
    int r;

    r = sd_lldp_stop(lldp);
    if (r)
        return r;

    r = sd_lldp_detach_event(lldp);
    if (r)
        return r;

    sd_lldp_unref(lldp);
    safe_close(test_fd[1]);

    return 0;
}
예제 #3
0
파일: fuzz-lldp.c 프로젝트: floppym/systemd
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
        _cleanup_(sd_event_unrefp) sd_event *e = NULL;
        _cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL;

        assert_se(sd_event_new(&e) == 0);
        assert_se(sd_lldp_new(&lldp) >= 0);
        assert_se(sd_lldp_set_ifindex(lldp, 42) >= 0);
        assert_se(sd_lldp_attach_event(lldp, e, 0) >= 0);
        assert_se(sd_lldp_start(lldp) >= 0);

        assert_se(write(test_fd[1], data, size) == (ssize_t) size);
        assert_se(sd_event_run(e, 0) >= 0);

        assert_se(sd_lldp_stop(lldp) >= 0);
        assert_se(sd_lldp_detach_event(lldp) >= 0);
        test_fd[1] = safe_close(test_fd[1]);

        return 0;
}
예제 #4
0
_public_ sd_lldp* sd_lldp_unref(sd_lldp *lldp) {

        if (!lldp)
                return NULL;

        assert(lldp->n_ref > 0);
        lldp->n_ref --;

        if (lldp->n_ref > 0)
                return NULL;

        lldp_reset(lldp);
        sd_lldp_detach_event(lldp);
        lldp_flush_neighbors(lldp);

        hashmap_free(lldp->neighbor_by_id);
        prioq_free(lldp->neighbor_by_expiry);
        return mfree(lldp);
}
예제 #5
0
gboolean
nm_lldp_listener_start (NMLldpListener *self, int ifindex, const char *iface,
                        const guint8 *mac, guint mac_len, GError **error)
{
	NMLldpListenerPrivate *priv;
	int ret;

	g_return_val_if_fail (NM_IS_LLDP_LISTENER (self), FALSE);
	g_return_val_if_fail (ifindex > 0, FALSE);
	g_return_val_if_fail (iface, FALSE);
	g_return_val_if_fail (!error || !*error, FALSE);

	priv = NM_LLDP_LISTENER_GET_PRIVATE (self);

	if (priv->lldp_handle) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
		                     "already running");
		return FALSE;
	}

	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, (struct ether_addr *) mac, &priv->lldp_handle);
	if (ret) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
		                     "initialization failed");
		return FALSE;
	}

	ret = sd_lldp_attach_event (priv->lldp_handle, NULL, 0);
	if (ret) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
		                     "attach event failed");
		goto err_free;
	}

	ret = sd_lldp_set_callback (priv->lldp_handle, lldp_event_handler, self);
	if (ret) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
		                     "set callback failed");
		goto err;
	}

	ret = sd_lldp_start (priv->lldp_handle);
	if (ret) {
		g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
		                     "start failed");
		goto err;
	}

	priv->ifindex = ifindex;
	priv->iface = strdup (iface);
	return TRUE;

err:
	sd_lldp_detach_event (priv->lldp_handle);
err_free:
	sd_lldp_unref (priv->lldp_handle);
	priv->lldp_handle = NULL;
	return FALSE;
}