/* * Get information about port on bridge. */ int br_get_port_info(const char *brname, const char *port, struct port_info *info) { DIR *d; char path[SYSFS_PATH_MAX]; snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/brport", port); d = opendir(path); if (!d) goto fallback; memset(info, 0, sizeof(*info)); fetch_id(path, "designated_root", &info->designated_root); fetch_id(path, "designated_bridge", &info->designated_bridge); info->port_no = fetch_int(path, "port_no"); info->port_id = fetch_int(path, "port_id"); info->designated_port = fetch_int(path, "designated_port"); info->path_cost = fetch_int(path, "path_cost"); info->designated_cost = fetch_int(path, "designated_cost"); info->state = fetch_int(path, "state"); info->top_change_ack = fetch_int(path, "change_ack"); info->config_pending = fetch_int(path, "config_pending"); fetch_tv(path, "message_age_timer", &info->message_age_timer_value); fetch_tv(path, "forward_delay_timer", &info->forward_delay_timer_value); fetch_tv(path, "hold_timer", &info->hold_timer_value); closedir(d); return 0; fallback: return old_get_port_info(brname, port, info); }
/* * Get information about port on bridge. */ int br_get_port_info(const char *brname, const char *port, struct port_info *info) { #ifndef HAVE_LIBSYSFS return old_get_port_info(brname, port, info); #else struct sysfs_directory *sdir = bridge_sysfs_directory(port, SYSFS_BRIDGE_PORT_ATTR); if (!sdir) return old_get_port_info(brname, port, info); memset(info, 0, sizeof(*info)); fetch_id(sdir, "designated_root", &info->designated_root); fetch_id(sdir, "designated_bridge", &info->designated_bridge); info->port_no = fetch_int(sdir, "port_no"); info->port_id = fetch_int(sdir, "port_id"); info->designated_port = fetch_int(sdir, "designated_port"); info->path_cost = fetch_int(sdir, "path_cost"); info->designated_cost = fetch_int(sdir, "designated_cost"); info->state = fetch_int(sdir, "state"); info->top_change_ack = fetch_int(sdir, "change_ack"); info->config_pending = fetch_int(sdir, "config_pending"); fetch_tv(sdir, "message_age_timer", &info->message_age_timer_value); fetch_tv(sdir, "forward_delay_timer", &info->forward_delay_timer_value); fetch_tv(sdir, "hold_timer", &info->hold_timer_value); sysfs_close_directory(sdir); return 0; #endif }
/* * Get bridge parameters using either sysfs or old * ioctl. */ int br_get_bridge_info(const char *bridge, struct bridge_info *info) { DIR *dir; char path[SYSFS_PATH_MAX]; snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/bridge", bridge); dir = opendir(path); if (dir == NULL) { dprintf("path '%s' is not a directory\n", path); goto fallback; } memset(info, 0, sizeof(*info)); fetch_id(path, "root_id", &info->designated_root); fetch_id(path, "bridge_id", &info->bridge_id); info->root_path_cost = fetch_int(path, "root_path_cost"); fetch_tv(path, "max_age", &info->max_age); fetch_tv(path, "hello_time", &info->hello_time); fetch_tv(path, "forward_delay", &info->forward_delay); fetch_tv(path, "max_age", &info->bridge_max_age); fetch_tv(path, "hello_time", &info->bridge_hello_time); fetch_tv(path, "forward_delay", &info->bridge_forward_delay); fetch_tv(path, "ageing_time", &info->ageing_time); fetch_tv(path, "hello_timer", &info->hello_timer_value); fetch_tv(path, "tcn_timer", &info->tcn_timer_value); fetch_tv(path, "topology_change_timer", &info->topology_change_timer_value);; fetch_tv(path, "gc_timer", &info->gc_timer_value); info->root_port = fetch_int(path, "root_port"); info->stp_enabled = fetch_int(path, "stp_state"); info->topology_change = fetch_int(path, "topology_change"); info->topology_change_detected = fetch_int(path, "topology_change_detected"); closedir(dir); return 0; fallback: return old_get_bridge_info(bridge, info); }
/* * Get bridge parameters using either sysfs or old * ioctl. */ static int br_get_bridge_info(const char *bridge, struct bridge_info *info) { #ifdef HAVE_LIBSYSFS struct sysfs_class_device *dev; char path[SYSFS_PATH_MAX]; if (!br_class_net) goto fallback; dev = sysfs_get_class_device(br_class_net, bridge); if (!dev) { dprintf("get_class_device '%s' failed\n", bridge); goto fallback; } snprintf(path, SYSFS_PATH_MAX, "%s/bridge", dev->path); if (sysfs_path_is_dir(path)) { dprintf("path '%s' is not a directory\n", path); sysfs_close_class_device(dev); goto fallback; } memset(info, 0, sizeof(*info)); fetch_id(dev, BRIDGEATTR("root_id"), &info->designated_root); fetch_id(dev, BRIDGEATTR("bridge_id"), &info->bridge_id); info->root_path_cost = fetch_int(dev, BRIDGEATTR("root_path_cost")); fetch_tv(dev, BRIDGEATTR("max_age"), &info->max_age); fetch_tv(dev, BRIDGEATTR("hello_time"), &info->hello_time); fetch_tv(dev, BRIDGEATTR("forward_delay"), &info->forward_delay); fetch_tv(dev, BRIDGEATTR("max_age"), &info->bridge_max_age); fetch_tv(dev, BRIDGEATTR("hello_time"), &info->bridge_hello_time); fetch_tv(dev, BRIDGEATTR("forward_delay"), &info->bridge_forward_delay); fetch_tv(dev, BRIDGEATTR("ageing_time"), &info->ageing_time); fetch_tv(dev, BRIDGEATTR("hello_timer"), &info->hello_timer_value); fetch_tv(dev, BRIDGEATTR("tcn_timer"), &info->tcn_timer_value); fetch_tv(dev, BRIDGEATTR("topology_change_timer"), &info->topology_change_timer_value);; fetch_tv(dev, BRIDGEATTR("gc_timer"), &info->gc_timer_value); info->root_port = fetch_int(dev, BRIDGEATTR("root_port")); info->stp_enabled = fetch_int(dev, BRIDGEATTR("stp_state")); info->topology_change = fetch_int(dev, BRIDGEATTR("topology_change")); info->topology_change_detected = fetch_int(dev, BRIDGEATTR("topology_change_detected")); sysfs_close_class_device(dev); return 0; fallback: #endif return old_get_bridge_info(bridge, info); }
/* * Get bridge parameters using either sysfs or old * ioctl. */ int br_get_bridge_info(const char *bridge, struct bridge_info *info) { #ifndef HAVE_LIBSYSFS return old_get_bridge_info(bridge, info); #else struct sysfs_directory *sdir; sdir = bridge_sysfs_directory(bridge, SYSFS_BRIDGE_ATTR); if (!sdir) return old_get_bridge_info(bridge,info); memset(info, 0, sizeof(*info)); fetch_id(sdir, "root_id", &info->designated_root); fetch_id(sdir, "bridge_id", &info->bridge_id); info->root_path_cost = fetch_int(sdir, "root_path_cost"); fetch_tv(sdir, "max_age", &info->max_age); fetch_tv(sdir, "hello_time", &info->hello_time); fetch_tv(sdir, "forward_delay", &info->forward_delay); fetch_tv(sdir, "max_age", &info->bridge_max_age); fetch_tv(sdir, "hello_time", &info->bridge_hello_time); fetch_tv(sdir, "forward_delay", &info->bridge_forward_delay); fetch_tv(sdir, "ageing_time", &info->ageing_time); fetch_tv(sdir, "hello_timer", &info->hello_timer_value); fetch_tv(sdir, "tcn_timer", &info->tcn_timer_value); fetch_tv(sdir, "topology_change_timer", &info->topology_change_timer_value);; fetch_tv(sdir, "gc_timer", &info->gc_timer_value); info->root_port = fetch_int(sdir, "root_port"); info->stp_enabled = fetch_int(sdir, "stp_state"); info->topology_change = fetch_int(sdir, "topology_change"); info->topology_change_detected = fetch_int(sdir, "topology_change_detected"); sysfs_close_directory(sdir); return 0; #endif }