Exemplo n.º 1
0
static dbus_bool_t
__ni_objectmodel_ovs_bridge_set_vlan(ni_dbus_object_t *object, const ni_dbus_property_t *property,
					const ni_dbus_variant_t *argument, DBusError *error)
{
	ni_ovs_bridge_t *ovsbr;
	const char *parent = NULL;
	uint16_t tag = 0;

	if (!ni_dbus_variant_is_dict(argument))
		return FALSE;

	if (!(ovsbr = __ni_objectmodel_ovs_bridge_write_handle(object, error)))
		return FALSE;

	ni_dbus_dict_get_string(argument, "parent", &parent);
	ni_dbus_dict_get_uint16(argument, "tag", &tag);

	if (!ni_string_empty(parent) && tag < 0x0fff) {
		ovsbr->config.vlan.tag = tag;
		ni_netdev_ref_set_ifname(&ovsbr->config.vlan.parent, parent);
	} else {
		ovsbr->config.vlan.tag = 0;
		ni_netdev_ref_destroy(&ovsbr->config.vlan.parent);
	}
	return TRUE;
}
Exemplo n.º 2
0
Arquivo: team.c Projeto: gsanso/wicked
void
ni_team_port_free(ni_team_port_t *port)
{
	ni_netdev_ref_destroy(&port->device);
	ni_team_port_config_destroy(&port->config);
	free(port);
}
Exemplo n.º 3
0
static void
ni_netdev_free(ni_netdev_t *dev)
{
	/* Clear out linkinfo */
	ni_string_free(&dev->link.qdisc);
	ni_string_free(&dev->link.kind);
	ni_string_free(&dev->link.alias);
	ni_netdev_ref_destroy(&dev->link.lowerdev);
	ni_netdev_ref_destroy(&dev->link.masterdev);
	ni_netdev_slaveinfo_destroy(&dev->link.slave);
	ni_netdev_set_link_stats(dev, NULL);

	/* Clear out addresses, routes, ... */
	ni_netdev_clear_addresses(dev);
	ni_netdev_clear_routes(dev);
	ni_netdev_set_ethernet(dev, NULL);
	ni_netdev_set_infiniband(dev, NULL);
	ni_netdev_set_bonding(dev, NULL);
	ni_netdev_set_team(dev, NULL);
	ni_netdev_set_bridge(dev, NULL);
	ni_netdev_set_ovs_bridge(dev, NULL);
	ni_netdev_set_vlan(dev, NULL);
	ni_netdev_set_vxlan(dev, NULL);
	ni_netdev_set_macvlan(dev, NULL);
	ni_netdev_set_ipip(dev, NULL);
	ni_netdev_set_sit(dev, NULL);
	ni_netdev_set_gre(dev, NULL);
	ni_netdev_set_wireless(dev, NULL);
	ni_netdev_set_openvpn(dev, NULL);
	ni_netdev_set_ppp(dev, NULL);
	ni_netdev_set_dcb(dev, NULL);
	ni_netdev_set_lldp(dev, NULL);
	ni_netdev_set_client_state(dev, NULL);

	ni_netdev_set_ipv4(dev, NULL);
	ni_netdev_set_ipv6(dev, NULL);
	ni_netdev_set_auto6(dev, NULL);

	ni_netdev_set_pci(dev, NULL);
	ni_netdev_set_ethtool(dev, NULL);
	ni_netdev_clear_event_filters(dev);

	ni_addrconf_lease_list_destroy(&dev->leases);

	ni_string_free(&dev->name);
	free(dev);
}
Exemplo n.º 4
0
void
ni_netdev_req_free(ni_netdev_req_t *req)
{
	ni_string_free(&req->alias);
	ni_netdev_ref_destroy(&req->master);
	ni_netdev_port_req_free(req->port);
	free(req);
}
Exemplo n.º 5
0
static void
ni_updater_source_free(ni_updater_source_t *src)
{
	if (src) {
		ni_assert(src->users);
		src->users--;

		if (src->users == 0) {
			src->seqno = 0;
			src->lease = NULL;
			ni_netdev_ref_destroy(&src->d_ref);
			free(src);
		}
	}
}
Exemplo n.º 6
0
int
ni_do_ethtool(const char *caller, int argc, char **argv)
{
	enum { OPT_HELP };
	static struct option      options[] = {
		{ "help",         no_argument,       NULL, OPT_HELP        },

		{ NULL,           no_argument,       NULL, 0               }
	};
	int c, n, status = NI_WICKED_RC_USAGE;
	const struct ethtool_opt *opt;
	ni_netdev_ref_t ref = { 0, NULL };
	ni_ethtool_t *ethtool = NULL;

	optind = 1;
	while ((c = getopt_long(argc, argv, "+", options, NULL)) != EOF) {
		switch (c) {
		case OPT_HELP:
			status = NI_WICKED_RC_SUCCESS;
			/* fall through */
		default:
		usage:
			fprintf(stderr,
				"wicked %s [global options ...] <ifname> <action options [arguments] > ...\n"
				"\n"
				"Supported global options:\n"
				"  --help\n"
				"      Show this help text.\n"
				"\n"
				"Supported action options:\n"
				, argv[0]
			);
			for (opt = ethtool_opts; opt && opt->name; opt++)
				ethtool_opt_usage(opt);
			goto cleanup;
		}
	}

	if (optind >= argc) {
		fprintf(stderr, "%s: missing interface argument\n\n", argv[0]);
		goto usage;
	}
	if (optind + 1 >= argc) {
		fprintf(stderr, "%s: missing interface action option\n\n", argv[0]);
		goto usage;
	}

	status = NI_WICKED_RC_ERROR;
	ni_netdev_ref_init(&ref, argv[optind], if_nametoindex(argv[optind]));
	if (!ref.index) {
		fprintf(stderr, "%s: cannot find interface with name '%s'\n", argv[0], argv[optind]);
		goto cleanup;
	}
	if (!(ethtool = ni_ethtool_new())) {
		fprintf(stderr, "%s: cannot allocate ethtool parameters for '%s'\n", argv[0], ref.name);
		goto cleanup;
	}

	status = NI_WICKED_RC_SUCCESS;
	for (n = ++optind; n < argc; ) {
		if ((opt = ethtool_opt_find(ethtool_opts, argv[n]))) {
			struct ethtool_args args;
			char * argn;

			ethtool_args_set(&args, &argn, argc - n - 1, argv + n + 1);
			n += args.argc + 1;
			if (opt->func(&ref, ethtool, &args) < 0)
				status = NI_WICKED_RC_ERROR;
			argv[n] = argn;
		} else
		if (!ni_string_eq(argv[n], "--")) {
			fprintf(stderr, "%s: unknown interface action option '%s'\n\n",
					argv[0], argv[n]);
			status = NI_WICKED_RC_USAGE;
			goto cleanup;
		} else
			n++;
	}

cleanup:
	ni_ethtool_free(ethtool);
	ni_netdev_ref_destroy(&ref);
	return status;
}