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; }
/* * Helper function to obtain ppp config from dbus object */ static ni_ppp_t * ni_objectmodel_ppp_handle(const ni_dbus_object_t *object, ni_bool_t write_access, DBusError *error) { ni_netdev_t *dev; ni_ppp_t *ppp; if (!(dev = ni_objectmodel_unwrap_netif(object, error))) return NULL; if (!write_access) return dev->ppp; if (!(ppp = ni_netdev_get_ppp(dev))) { if (error) dbus_set_error(error, DBUS_ERROR_FAILED, "Error getting ppp handle for interface %s", dev->name); return NULL; } return ppp; }
/* * PPP device properties */ static ni_ppp_config_t * __ni_objectmodel_ppp_handle(const ni_dbus_object_t *object, ni_bool_t write_access, DBusError *error) { ni_netdev_t *dev; ni_ppp_t *ppp; if (!(dev = ni_objectmodel_unwrap_netif(object, error))) return NULL; if (!write_access) { if (!dev->ppp) return NULL; return dev->ppp->config; } ppp = ni_netdev_get_ppp(dev); if (!ppp->config) ppp->config = ni_ppp_config_new(); return ppp->config; }
/* * Support for PPP over serial */ static inline ni_netdev_t * __ni_objectmodel_ppp_device_arg(const ni_dbus_variant_t *dict, DBusError *error) { ni_netdev_t *ppp_dev; const char *device_path; ni_dbus_object_t *device_object; ni_ppp_t *ppp; ni_modem_t *modem; if (!(ppp_dev = ni_objectmodel_get_netif_argument(dict, NI_IFTYPE_PPP, &ni_objectmodel_ppp_service))) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "Error unwrapping PPP device configuration"); return NULL; } ppp = ni_netdev_get_ppp(ppp_dev); if (!ni_ppp_check_config(ppp) || !(device_path = ppp->config->device.object_path)) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "No or incomplete PPP device configuration"); return NULL; } device_object = ni_objectmodel_object_by_path(device_path); if (device_object == NULL) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "PPP device configuration references unknown object path \"%s\"", device_path); return NULL; } modem = ni_objectmodel_unwrap_modem(device_object, error); if (modem == NULL) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "PPP device configuration references incompatible object (expected a modem)"); return NULL; } ppp->config->device.modem = ni_modem_hold(modem); ni_string_dup(&ppp->config->device.name, modem->device); return ppp_dev; }
/* * Support for PPP over Ethernet */ static inline ni_netdev_t * __ni_objectmodel_pppoe_device_arg(const ni_dbus_variant_t *dict, DBusError *error) { ni_netdev_t *ppp_dev, *eth_dev; const char *device_path; ni_dbus_object_t *device_object; ni_ppp_t *ppp; if (!(ppp_dev = ni_objectmodel_get_netif_argument(dict, NI_IFTYPE_PPP, &ni_objectmodel_ppp_service))) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "Error unwrapping PPP device configuration"); return NULL; } ppp = ni_netdev_get_ppp(ppp_dev); if (!ppp || !ppp->config || !(device_path = ppp->config->device.object_path)) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "No or incomplete PPP device configuration"); return NULL; } device_object = ni_objectmodel_object_by_path(device_path); if (device_object == NULL) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "PPP device configuration references unknown object path \"%s\"", device_path); return NULL; } eth_dev = ni_objectmodel_unwrap_netif(device_object, error); if (eth_dev == NULL || !eth_dev->ethernet) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "PPP device configuration references incompatible object (expected an ethernet device)"); return NULL; } ppp->config->device.ethernet = ni_netdev_get(eth_dev); ni_string_dup(&ppp->config->device.name, eth_dev->name); return ppp_dev; }