Beispiel #1
0
static int lldp_parse_port_id_tlv(tlv_packet *m) {
    _cleanup_free_ char *p = NULL;
    char *str = NULL;
    uint16_t length;
    uint8_t subtype;

    assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_PORT_ID) >= 0);

    assert_se(tlv_packet_read_u8(m, &subtype) >= 0);

    switch (subtype) {
    case LLDP_PORT_SUBTYPE_INTERFACE_NAME:
        assert_se(tlv_packet_read_string(m, &str, &length) >= 0);

        p = strndup(str, length-1);
        assert_se(p);

        assert_se(streq(p, TEST_LLDP_PORT) == 1);
        break;
    default:
        assert_not_reached("Unhandled option");
    }

    assert_se(lldp_tlv_packet_exit_container(m) >= 0);

    return 0;
}
Beispiel #2
0
static int lldp_parse_ttl_tlv(tlv_packet *m) {
    uint16_t ttl;

    assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_TTL) >= 0);
    assert_se(tlv_packet_read_u16(m, &ttl) >= 0);

    assert_se(ttl == 170);

    assert_se(lldp_tlv_packet_exit_container(m) >= 0);

    return 0;
}
Beispiel #3
0
static int lldp_parse_system_desc_tlv(tlv_packet *m) {
        char *str = NULL, *p;
        uint16_t length;

        assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_DESCRIPTION) >= 0);
        assert_se(tlv_packet_read_string(m, &str, &length) >= 0);

        p = malloc0(length + 1);
        strncpy(p, str, length);

        assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_DESC) == 1);

        assert_se(lldp_tlv_packet_exit_container(m) >= 0);

        return 0;
}
Beispiel #4
0
static int lldp_parse_system_desc_tlv(tlv_packet *m) {
    _cleanup_free_ char *p = NULL;
    char *str = NULL;
    uint16_t length;

    assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_SYSTEM_DESCRIPTION) >= 0);
    assert_se(tlv_packet_read_string(m, &str, &length) >= 0);

    p = strndup(str, length);
    assert_se(p);

    assert_se(streq(p, TEST_LLDP_TYPE_SYSTEM_DESC) == 1);

    assert_se(lldp_tlv_packet_exit_container(m) >= 0);

    return 0;
}
Beispiel #5
0
static int lldp_parse_chassis_tlv(tlv_packet *m, uint8_t *type) {
    uint8_t *p, subtype;
    uint16_t length;

    assert_se(lldp_tlv_packet_enter_container(m, LLDP_TYPE_CHASSIS_ID) >= 0);
    assert_se(tlv_packet_read_u8(m, &subtype) >= 0);

    switch (subtype) {
    case LLDP_CHASSIS_SUBTYPE_MAC_ADDRESS:

        *type = LLDP_CHASSIS_SUBTYPE_MAC_ADDRESS;
        assert_se(tlv_packet_read_bytes(m, &p, &length) >= 0);

        assert_se(memcmp(p, &mac_addr.ether_addr_octet, ETHER_ADDR_LEN) == 0);

        break;
    default:
        assert_not_reached("Unhandled option");
    }

    assert_se(lldp_tlv_packet_exit_container(m) >= 0);

    return 0;
}