static void register_commands_pow_priority(struct cmd_node *priority, int key) { for (lldpctl_map_t *prio_map = lldpctl_key_get_map(key); 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); } }
/** * 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 }
static void display_med(struct writer *w, lldpctl_atom_t *port) { lldpctl_atom_t *medpolicies, *medpolicy; lldpctl_atom_t *medlocations, *medlocation; lldpctl_atom_t *caelements, *caelement; long int cap = lldpctl_atom_get_int(port, lldpctl_k_chassis_med_cap); const char *type; if (lldpctl_atom_get_int(port, lldpctl_k_chassis_med_type) <= 0) return; tag_start(w, "lldp-med", "LLDP-MED"); tag_datatag(w, "device-type", "Device Type", lldpctl_atom_get_str(port, lldpctl_k_chassis_med_type)); display_med_capability(w, cap, LLDP_MED_CAP_CAP, "Capabilities"); display_med_capability(w, cap, LLDP_MED_CAP_POLICY, "Policy"); display_med_capability(w, cap, LLDP_MED_CAP_LOCATION, "Location"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PSE, "MDI/PSE"); display_med_capability(w, cap, LLDP_MED_CAP_MDI_PD, "MDI/PD"); display_med_capability(w, cap, LLDP_MED_CAP_IV, "Inventory"); /* LLDP MED policies */ medpolicies = lldpctl_atom_get(port, lldpctl_k_port_med_policies); lldpctl_atom_foreach(medpolicies, medpolicy) { if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_type) <= 0) continue; tag_start(w, "policy", "LLDP-MED Network Policy for"); tag_attr(w, "apptype", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_type)); tag_attr(w, "defined", "Defined", (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_unknown) > 0)?"no":"yes"); if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_tagged) > 0) { int vid = lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_vid); tag_start(w, "vlan", "VLAN"); if (vid == 0) { tag_attr(w, "vid", "", "priority"); } else if (vid == 4095) { tag_attr(w, "vid", "", "reserved"); } else { tag_attr(w, "vid", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_vid)); } tag_end(w); } tag_datatag(w, "priority", "Priority", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_priority)); tag_datatag(w, "dscp", "DSCP Value", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_dscp)); tag_end(w); } lldpctl_atom_dec_ref(medpolicies); /* LLDP MED locations */ medlocations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); lldpctl_atom_foreach(medlocations, medlocation) { int format = lldpctl_atom_get_int(medlocation, lldpctl_k_med_location_format); if (format <= 0) continue; tag_start(w, "location", "LLDP-MED Location Identification"); tag_attr(w, "type", "Type", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_format)); switch (format) { case LLDP_MED_LOCFORMAT_COORD: tag_attr(w, "geoid", "Geoid", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_geoid)); tag_datatag(w, "lat", "Latitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_latitude)); tag_datatag(w, "lon", "Longitude", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_longitude)); tag_start(w, "altitude", "Altitude"); tag_attr(w, "unit", "", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude_unit)); tag_data(w, lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude)); tag_end(w); break; case LLDP_MED_LOCFORMAT_CIVIC: tag_datatag(w, "country", "Country", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_country)); caelements = lldpctl_atom_get(medlocation, lldpctl_k_med_location_ca_elements); lldpctl_atom_foreach(caelements, caelement) { type = lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_type); tag_datatag(w, totag(type), type, lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_value)); } lldpctl_atom_dec_ref(caelements); break; case LLDP_MED_LOCFORMAT_ELIN: tag_datatag(w, "ecs", "ECS ELIN", lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_elin)); break; }
/** * 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); } }
/** * 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"); }