Exemplo n.º 1
0
static ni_netdev_t *
ni_objectmodel_ppp_device_create(ni_netdev_t *cfg, const char *ifname, DBusError *error)
{
	ni_netconfig_t *nc = ni_global_state_handle(0);
	ni_netdev_t *dev = NULL;
	int rv;

	ni_netdev_get_ppp(cfg);
	if (ifname == NULL && !(ifname = ni_netdev_make_name(nc, "ppp", 0))) {
		dbus_set_error(error, DBUS_ERROR_FAILED,
				"Unable to create ppp interface - too many interfaces");
		return NULL;
	}
	ni_string_dup(&cfg->name, ifname);

	if ((rv = ni_system_ppp_create(nc, cfg, &dev)) < 0) {
		dbus_set_error(error, DBUS_ERROR_FAILED, "Unable to create ppp interface '%s'",
				cfg->name);
		return NULL;
	}

	if (dev && dev->link.type != NI_IFTYPE_PPP) {
		dbus_set_error(error, DBUS_ERROR_FAILED,
			"Unable to create ppp interface: new interface is of type %s",
			ni_linktype_type_to_name(dev->link.type));
		return NULL;
	}
	return dev;
}
Exemplo n.º 2
0
Arquivo: ppp.c Projeto: mchf/wicked
static ni_netdev_t *
__ni_objectmodel_ppp_newlink(ni_netdev_t *cfg, const char *ifname, DBusError *error)
{
	ni_netconfig_t *nc = ni_global_state_handle(0);
	ni_netdev_t *new_dev = NULL;
	int rv;

	ni_debug_dbus("PPP.newDevice(name=%s)", ifname);

	if (ifname == NULL && !(ifname = ni_netdev_make_name(nc, "ppp"))) {
		dbus_set_error(error, DBUS_ERROR_FAILED, "Unable to create ppp - too many interfaces");
		return NULL;
	}

	if ((rv = ni_system_ppp_create(nc, ifname, cfg->ppp, &new_dev)) < 0) {
		if (rv != -NI_ERROR_DEVICE_EXISTS
		 && (ifname != NULL && strcmp(ifname, new_dev->name))) {
			ni_dbus_set_error_from_code(error, rv,
					"unable to create PPP interface %s",
					ifname);
			return NULL;
		}
		ni_debug_dbus("PPP interface exists (and name matches)");
	}

	if (new_dev->link.type != NI_IFTYPE_PPP) {
		dbus_set_error(error,
				DBUS_ERROR_FAILED,
				"Unable to create PPP interface: new interface is of type %s",
				ni_linktype_type_to_name(new_dev->link.type));
		/* FIXME: delete device? */
		return NULL;
	}

	if (ni_ppp_write_config(new_dev->ppp) < 0) {
		dbus_set_error(error,
				DBUS_ERROR_FAILED,
				"Unable to create PPP interface: failed to write coniguration files");
		/* FIXME: delete device */
		return NULL;
	}

	return new_dev;
}