/** * Register `configure system bond-slave-src-mac-type` */ static void register_commands_srcmac_type(struct cmd_node *configure) { struct cmd_node *bond_slave_src_mac_type = commands_new(configure, "bond-slave-src-mac-type", "Set LLDP bond slave source MAC type", NULL, NULL, NULL); for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_bond_slave_src_mac_type); b_map->string; b_map++) { if (!strcmp(b_map->string, "real")) { commands_new( commands_new(bond_slave_src_mac_type, b_map->string, "Real mac", NULL, NULL, NULL), NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, b_map->string); } else if (!strcmp(b_map->string, "zero")) { commands_new( commands_new(bond_slave_src_mac_type, b_map->string, "All zero mac", NULL, NULL, NULL), NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, b_map->string); } else if (!strcmp(b_map->string, "fixed")) { commands_new( commands_new(bond_slave_src_mac_type, b_map->string, "Fixed value (3Com card)", NULL, NULL, NULL), NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, b_map->string); } else if (!strcmp(b_map->string, "local")) { commands_new( commands_new(bond_slave_src_mac_type, b_map->string, "Real Mac with locally " "administered bit set", NULL, NULL, NULL), NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, b_map->string); } } }
static int cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) { char *value_str; int value = -1; log_debug("lldpctl", "lldp PortID TLV Subtype"); lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { log_warnx("lldpctl", "unable to get configuration from lldpd. %s", lldpctl_last_strerror(conn)); return 0; } value_str = arg; for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, value_str)) { value = b_map->value; break; } } if (value == -1) { log_warnx("lldpctl", "invalid value"); lldpctl_atom_dec_ref(config); return 0; } if (lldpctl_atom_set_int(config, lldpctl_k_config_lldp_portid_type, value) == NULL) { log_warnx("lldpctl", "unable to set LLDP PortID type." " %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "LLDP PortID TLV type set to new value : %s", value_str); lldpctl_atom_dec_ref(config); return 1; }
/** * Register "configure med *" */ void register_commands_configure_med(struct cmd_node *configure, struct cmd_node *unconfigure) { if (lldpctl_key_get_map( lldpctl_k_med_policy_type)[0].string == NULL) return; struct cmd_node *configure_med = commands_new( configure, "med", "MED configuration", NULL, NULL, NULL); struct cmd_node *unconfigure_med = commands_new( unconfigure, "med", "MED configuration", NULL, NULL, NULL); register_commands_medloc(configure_med); register_commands_medpol(configure_med); register_commands_medpow(configure_med); register_commands_medfast(configure_med, unconfigure_med); }
/** * Register `configure med location address` commands. */ static void register_commands_medloc_addr(struct cmd_node *configure_medlocation) { /* MED location address (set) */ struct cmd_node *configure_medloc_addr = commands_new( configure_medlocation, "address", "MED location address configuration", NULL, NULL, NULL); commands_new(configure_medloc_addr, NEWLINE, "Configure MED location address", cmd_check_env, cmd_medlocation_address, "country"); /* Country */ commands_new( commands_new( configure_medloc_addr, "country", "Specify country (mandatory)", cmd_check_no_env, NULL, "country"), NULL, "Country as a two-letter code", NULL, cmd_store_env_value_and_pop2, "country"); /* Other fields */ for (lldpctl_map_t *addr_map = lldpctl_key_get_map(lldpctl_k_med_civicaddress_type); addr_map->string; addr_map++) commands_new( commands_new( configure_medloc_addr, strdup(totag(addr_map->string)), /* TODO: memory leak, happens once */ addr_map->string, cmd_check_no_env, NULL, addr_map->string), NULL, addr_map->string, NULL, cmd_store_env_value_and_pop2, addr_map->string); }
/** * Register `configure lldp` commands. * * Those are the commands that are related to the LLDP protocol but not * Dot1/Dot3/MED. Commands not related to LLDP should go in system instead. */ void register_commands_configure_lldp(struct cmd_node *configure, struct cmd_node *unconfigure) { struct cmd_node *configure_lldp = commands_new( configure, "lldp", "LLDP configuration", NULL, NULL, NULL); struct cmd_node *unconfigure_lldp = commands_new( unconfigure, "lldp", "LLDP configuration", NULL, NULL, NULL); commands_new( commands_new( commands_new(configure_lldp, "tx-interval", "Set LLDP transmit delay", cmd_check_no_env, NULL, "ports"), NULL, "LLDP transmit delay in seconds", NULL, cmd_store_env_value, "tx-interval"), NEWLINE, "Set LLDP transmit delay", NULL, cmd_txdelay, NULL); commands_new( commands_new( commands_new(configure_lldp, "tx-hold", "Set LLDP transmit hold", cmd_check_no_env, NULL, "ports"), NULL, "LLDP transmit hold in seconds", NULL, cmd_store_env_value, "tx-hold"), NEWLINE, "Set LLDP transmit hold", NULL, cmd_txhold, NULL); struct cmd_node *status = commands_new(configure_lldp, "status", "Set administrative status", NULL, NULL, NULL); for (lldpctl_map_t *status_map = lldpctl_key_get_map(lldpctl_k_port_status); status_map->string; status_map++) { const char *tag = strdup(totag(status_map->string)); commands_new( commands_new(status, tag, status_map->string, NULL, cmd_store_status_env_value, status_map->string), NEWLINE, "Set port administrative status", NULL, cmd_status, NULL); } /* Now handle the various portid subtypes we can configure. */ struct cmd_node *configure_lldp_portid_type = commands_new( configure_lldp, "portidsubtype", "LLDP PortID TLV Subtype ", NULL, NULL, NULL); for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, "ifname")) { commands_new( commands_new(configure_lldp_portid_type, b_map->string, "Interface Name", cmd_check_no_env, NULL, "ports"), NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } else if (!strcmp(b_map->string, "local")) { struct cmd_node *port_id = commands_new( commands_new(configure_lldp_portid_type, b_map->string, "Local", NULL, NULL, NULL), NULL, "Port ID", NULL, cmd_store_env_value, "port-id"); commands_new(port_id, NEWLINE, "Set local port ID", NULL, cmd_portid_type_local, b_map->string); commands_new( commands_new( commands_new(port_id, "description", "Also set port description", NULL, NULL, NULL), NULL, "Port description", NULL, cmd_store_env_value, "port-descr"), NEWLINE, "Set local port ID and description", NULL, cmd_portid_type_local, NULL); } else if (!strcmp(b_map->string, "macaddress")) { commands_new( commands_new(configure_lldp_portid_type, b_map->string, "MAC Address", cmd_check_no_env, NULL, "ports"), NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } } commands_new( commands_new(configure_lldp, "capabilities-advertisements", "Enable chassis capabilities advertisement", cmd_check_no_env, NULL, "ports"), NEWLINE, "Enable chassis capabilities advertisement", NULL, cmd_chassis_cap_advertise, "enable"); commands_new( commands_new(unconfigure_lldp, "capabilities-advertisements", "Don't enable chassis capabilities advertisement", NULL, NULL, NULL), NEWLINE, "Don't enable chassis capabilities advertisement", NULL, cmd_chassis_cap_advertise, NULL); commands_new( commands_new(configure_lldp, "management-addresses-advertisements", "Enable management addresses advertisement", NULL, NULL, NULL), NEWLINE, "Enable management addresses advertisement", NULL, cmd_chassis_mgmt_advertise, "enable"); commands_new( commands_new(unconfigure_lldp, "management-addresses-advertisements", "Don't enable management addresses advertisement", NULL, NULL, NULL), NEWLINE, "Don't enable management addresses advertisement", NULL, cmd_chassis_mgmt_advertise, NULL); #ifdef ENABLE_CUSTOM register_commands_configure_lldp_custom_tlvs(configure_lldp); commands_new( commands_new(unconfigure_lldp, "custom-tlv", "Clear all (previously set) custom TLVs", NULL, NULL, NULL), NEWLINE, "Clear all (previously set) custom TLVs", NULL, cmd_custom_tlv_set, NULL); #endif }
/** * Register `configure med policy` commands. */ static void register_commands_medpol(struct cmd_node *configure_med) { struct cmd_node *configure_medpolicy = commands_new( configure_med, "policy", "MED policy configuration", NULL, NULL, NULL); commands_new( configure_medpolicy, NEWLINE, "Apply new MED policy", cmd_check_env, cmd_medpolicy, "application"); /* Application */ struct cmd_node *configure_application = commands_new( configure_medpolicy, "application", "MED policy application", cmd_check_no_env, NULL, "application"); for (lldpctl_map_t *pol_map = lldpctl_key_get_map(lldpctl_k_med_policy_type); pol_map->string; pol_map++) { char *tag = strdup(totag(pol_map->string)); /* TODO: memory leak, happens once */ commands_new( configure_application, tag, pol_map->string, NULL, cmd_store_app_env_value_and_pop2, pol_map->string); } /* Remaining keywords */ commands_new( configure_medpolicy, "unknown", "Set unknown flag", cmd_check_application_but_no, cmd_store_env_and_pop, "unknown"); commands_new( commands_new( configure_medpolicy, "vlan", "VLAN advertising", cmd_check_application_but_no, NULL, "vlan"), NULL, "VLAN ID to advertise", NULL, cmd_store_env_value_and_pop2, "vlan"); commands_new( commands_new( configure_medpolicy, "dscp", "DiffServ advertising", cmd_check_application_but_no, NULL, "dscp"), NULL, "DSCP value to advertise (between 0 and 63)", NULL, cmd_store_env_value_and_pop2, "dscp"); struct cmd_node *priority = commands_new( configure_medpolicy, "priority", "MED policy priority", cmd_check_application_but_no, NULL, "priority"); for (lldpctl_map_t *prio_map = lldpctl_key_get_map(lldpctl_k_med_policy_priority); prio_map->string; prio_map++) { char *tag = strdup(totag(prio_map->string)); /* TODO: memory leak, happens once */ commands_new( priority, tag, prio_map->string, NULL, cmd_store_prio_env_value_and_pop2, prio_map->string); } }
static int _cmd_medlocation(struct lldpctl_conn_t *conn, struct cmd_env *env, int format) { lldpctl_atom_t *iface; while ((iface = cmd_iterate_on_interfaces(conn, env))) { const char *name = lldpctl_atom_get_str(iface, lldpctl_k_interface_name); lldpctl_atom_t *port = lldpctl_get_port(iface); lldpctl_atom_t *med_location = NULL, *med_locations = NULL; const char *what = NULL; int ok = 0; med_locations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); if (med_locations == NULL) { log_warnx("lldpctl", "unable to set LLDP-MED location: support seems unavailable"); goto end; } med_location = lldpctl_atom_iter_value(med_locations, lldpctl_atom_iter_next(med_locations, lldpctl_atom_iter(med_locations))); switch (format) { case LLDP_MED_LOCFORMAT_COORD: if ((what = "format", lldpctl_atom_set_int(med_location, lldpctl_k_med_location_format, format)) == NULL || (what = "latitude", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_latitude, cmdenv_get(env, "latitude"))) == NULL || (what = "longitude", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_longitude, cmdenv_get(env, "longitude"))) == NULL || (what = "altitude", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_altitude, cmdenv_get(env, "altitude"))) == NULL || (what = "altitude unit", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_altitude_unit, cmdenv_get(env, "altitude-unit"))) == NULL || (what = "datum", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_geoid, cmdenv_get(env, "datum"))) == NULL) log_warnx("lldpctl", "unable to set LLDP MED location value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); else ok = 1; break; case LLDP_MED_LOCFORMAT_CIVIC: if ((what = "format", lldpctl_atom_set_int(med_location, lldpctl_k_med_location_format, format)) == NULL || (what = "country", lldpctl_atom_set_str(med_location, lldpctl_k_med_location_country, cmdenv_get(env, "country"))) == NULL) { log_warnx("lldpctl", "unable to set LLDP MED location value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); break; } ok = 1; for (lldpctl_map_t *addr_map = lldpctl_key_get_map(lldpctl_k_med_civicaddress_type); addr_map->string; addr_map++) { lldpctl_atom_t *cael, *caels; const char *value = cmdenv_get(env, addr_map->string); if (!value) continue; caels = lldpctl_atom_get(med_location, lldpctl_k_med_location_ca_elements); cael = lldpctl_atom_create(caels); if (lldpctl_atom_set_str(cael, lldpctl_k_med_civicaddress_type, addr_map->string) == NULL || lldpctl_atom_set_str(cael, lldpctl_k_med_civicaddress_value, value) == NULL || lldpctl_atom_set(med_location, lldpctl_k_med_location_ca_elements, cael) == NULL) { log_warnx("lldpctl", "unable to add a civic address element `%s`. %s", addr_map->string, lldpctl_last_strerror(conn)); ok = 0; } lldpctl_atom_dec_ref(cael); lldpctl_atom_dec_ref(caels); if (!ok) break; } break; case LLDP_MED_LOCFORMAT_ELIN: if (lldpctl_atom_set_int(med_location, lldpctl_k_med_location_format, format) == NULL || lldpctl_atom_set_str(med_location, lldpctl_k_med_location_elin, cmdenv_get(env, "elin")) == NULL) log_warnx("lldpctl", "unable to set LLDP MED location on %s. %s", name, lldpctl_last_strerror(conn)); else ok = 1; break; } if (ok) { if (lldpctl_atom_set(port, lldpctl_k_port_med_locations, med_location) == NULL) { log_warnx("lldpctl", "unable to set LLDP MED location on %s. %s.", name, lldpctl_last_strerror(conn)); } else log_info("lldpctl", "LLDP-MED location has been set for port %s", name); } end: lldpctl_atom_dec_ref(med_location); lldpctl_atom_dec_ref(med_locations); lldpctl_atom_dec_ref(port); } return 1; }
/** * Register `configure med dot3` commands. */ void register_commands_dot3pow(struct cmd_node *configure_dot3) { struct cmd_node *configure_dot3power = commands_new( configure_dot3, "power", "Dot3 power configuration", NULL, NULL, NULL); commands_new( configure_dot3power, NEWLINE, "Apply new Dot3 power configuration", cmd_check_env_power, cmd_dot3power, NULL); /* Type: PSE or PD */ commands_new( configure_dot3power, "pd", "Dot3 power consumer", cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); commands_new( configure_dot3power, "pse", "Dot3 power provider", cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); /* Flags */ commands_new( configure_dot3power, "supported", "MDI power support present", cmd_check_type_but_no, cmd_store_env_and_pop, "supported"); commands_new( configure_dot3power, "enabled", "MDI power support enabled", cmd_check_type_but_no, cmd_store_env_and_pop, "enabled"); commands_new( configure_dot3power, "paircontrol", "MDI power pair can be selected", cmd_check_type_but_no, cmd_store_env_and_pop, "paircontrol"); /* Power pairs */ struct cmd_node *powerpairs = commands_new( configure_dot3power, "powerpairs", "Which pairs are currently used for power (mandatory)", cmd_check_type_but_no, NULL, "powerpairs"); for (lldpctl_map_t *pp_map = lldpctl_key_get_map(lldpctl_k_dot3_power_pairs); pp_map->string; pp_map++) { commands_new( powerpairs, pp_map->string, pp_map->string, NULL, cmd_store_powerpairs_env_value_and_pop2, pp_map->string); } /* Class */ struct cmd_node *class = commands_new( configure_dot3power, "class", "Power class", cmd_check_type_but_no, NULL, "class"); for (lldpctl_map_t *class_map = lldpctl_key_get_map(lldpctl_k_dot3_power_class); class_map->string; class_map++) { const char *tag = strdup(totag(class_map->string)); commands_new( class, tag, class_map->string, NULL, cmd_store_class_env_value_and_pop2, class_map->string); } /* 802.3at type */ struct cmd_node *typeat = commands_new( configure_dot3power, "type", "802.3at device type", cmd_check_type_but_no, NULL, "typeat"); commands_new(typeat, "1", "802.3at type 1", NULL, cmd_store_env_value_and_pop2, "typeat"); commands_new(typeat, "2", "802.3at type 2", NULL, cmd_store_env_value_and_pop2, "typeat"); /* Source */ struct cmd_node *source = commands_new( configure_dot3power, "source", "802.3at dot3 power source (mandatory)", cmd_check_typeat_but_no, NULL, "source"); register_commands_pow_source(source); /* Priority */ struct cmd_node *priority = commands_new( configure_dot3power, "priority", "802.3at dot3 power priority (mandatory)", cmd_check_typeat_but_no, NULL, "priority"); register_commands_pow_priority(priority, lldpctl_k_dot3_power_priority); /* Values */ commands_new( commands_new(configure_dot3power, "requested", "802.3at dot3 power value requested (mandatory)", cmd_check_typeat_but_no, NULL, "requested"), NULL, "802.3at power value requested in milliwatts", NULL, cmd_store_env_value_and_pop2, "requested"); commands_new( commands_new(configure_dot3power, "allocated", "802.3at dot3 power value allocated (mandatory)", cmd_check_typeat_but_no, NULL, "allocated"), NULL, "802.3at power value allocated in milliwatts", NULL, cmd_store_env_value_and_pop2, "allocated"); }