diff options
Diffstat (limited to 'include/libnet')
-rw-r--r-- | include/libnet/libnet-functions.h | 115 | ||||
-rw-r--r-- | include/libnet/libnet-headers.h | 59 | ||||
-rw-r--r-- | include/libnet/libnet-structures.h | 8 |
3 files changed, 182 insertions, 0 deletions
diff --git a/include/libnet/libnet-functions.h b/include/libnet/libnet-functions.h index 45e3656..c91c1d5 100644 --- a/include/libnet/libnet-functions.h +++ b/include/libnet/libnet-functions.h @@ -1464,6 +1464,121 @@ libnet_build_stp_tcn(uint16_t id, uint8_t version, uint8_t bpdu_type, const uint8_t* payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag); /** + * Builds an UniDirectional Link Detection(UDLD) header. + * UDLD frames are usually encapsulated inside of an 802.2 + 802.3 frame + * combination. + * @param version UDLD PDU version number + * @param opcode operation code + * @param flags flags + * @param checksum checksum (0 for libnet to auto-fill) + * @param payload optional payload or NULL + * @param payload_s payload length or 0 + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_hdr(uint8_t version, uint8_t opcode, uint8_t flags, uint8_t checksum, +const uint8_t* payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Device ID TLV. + * @param value device id(ASCII character string) + * @param value_s device id(ASCII character string) length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_device_id(const uint8_t *value, const uint8_t value_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Port ID TLV. + * @param value port id(ASCII character string) + * @param value_s port id(ASCII character string) length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_port_id(const uint8_t *value, const uint8_t value_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Echo TLV. + * @param value list of ID pairs + * @param value_s ID pairs length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_echo(const uint8_t *value, const uint8_t value_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Message Interval TLV. + * @param value time interval(8-bit unsigned integer) + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_message_interval(const uint8_t *value, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Timeout Interval TLV. + * @param value timeout interval(8-bit unsigned integer) + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_timeout_interval(const uint8_t *value, libnet_t *l, +libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Device Name TLV. + * @param value device name(ASCII character string) + * @param value_s device name length + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_device_name(const uint8_t *value, const uint8_t value_s, +libnet_t *l, libnet_ptag_t ptag); + +/** + * Builds an UniDirectional Link Detection(UDLD) Sequence Number TLV. + * @param value sequence number(32-bit unsigned integer) + * @param l pointer to a libnet context + * @param ptag protocol tag to modify an existing header, 0 to build a new one + * @return protocol tag value on success + * @retval -1 on error + */ +LIBNET_API +libnet_ptag_t +libnet_build_udld_sequence_number(const uint8_t *value, libnet_t *l, +libnet_ptag_t ptag); + +/** * Builds a token ring header. * @param ac access control * @param fc frame control diff --git a/include/libnet/libnet-headers.h b/include/libnet/libnet-headers.h index afbb5c3..01194c9 100644 --- a/include/libnet/libnet-headers.h +++ b/include/libnet/libnet-headers.h @@ -107,6 +107,7 @@ #define LIBNET_SEBEK_H 0x30 /* sebek header: 48 bytes */ #define LIBNET_STP_CONF_H 0x23 /**< STP conf header: 35 bytes */ #define LIBNET_STP_TCN_H 0x04 /**< STP tcn header: 4 bytes */ +#define LIBNET_UDLD_H 0x04 /**< UDLD header: 4 bytes */ #define LIBNET_TOKEN_RING_H 0x16 /**< Token Ring header: 22 bytes */ #define LIBNET_TCP_H 0x14 /**< TCP header: 20 bytes */ #define LIBNET_UDP_H 0x08 /**< UDP header: 8 bytes */ @@ -1734,6 +1735,64 @@ struct libnet_stp_tcn_hdr uint8_t stp_bpdu_type; /* bridge protocol data unit type */ }; +/* + * UDLD header + * UniDirectional Link Detection + * Base header size: 4 bytes +*/ +struct libnet_udld_hdr +{ + /* LLC Info */ +#define LIBNET_UDLD_DEST_MAC {0x01, 0x00, 0x0C, 0xCC, 0xCC, 0xCC} + + /* UDLD SNAP Format */ +#define LIBNET_UDLD_LLC_DSAP 0xAA +#define LIBNET_UDLD_LLC_SSAP 0xAA +#define LIBNET_UDLD_LLC_CONTROL 0x03 +#define LIBNET_UDLD_OID {0x00, 0x00, 0x0C} +#define LIBNET_UDLD_HDLC_PROTO_TYPE 0x0111 + + /* Protocol Data Unit (PDU) Format */ + uint8_t version_opcode; +#define LIBNET_UDLD_PDU_VERSION 0x01 +#define LIBNET_UDLD_PDU_VERSION_OFFSET (5) + +#define LIBNET_UDLD_PDU_OPCODE_RESERVED 0x00 /* Reserved opcode message */ +#define LIBNET_UDLD_PDU_OPCODE_PROBE 0x01 /* Probe opcode message */ +#define LIBNET_UDLD_PDU_OPCODE_ECHO 0x02 /* Echo opcode message */ +#define LIBNET_UDLD_PDU_OPCODE_FLUSH 0x03 /* Flush opcode message */ +#define LIBNET_UDLD_PDU_OPCODE_RESERVED_FUTURE 0x04 /* Reserved for future use 0x04-0x1F */ +#define LIBNET_UDLD_PDU_OPCODE_MASK 0x1F + + uint8_t flags; +#define LIBNET_UDLD_FLAG_RT 0x01 /* Bit 0 : Recommended timeout flag (RT) */ +#define LIBNET_UDLD_FLAG_RSY 0x02 /* Bit 1 : ReSynch flag (RSY) */ +#define LIBNET_UDLD_FLAG_RESERVED 0x03 /* Bit 2-7: Reserved for future use */ + + uint16_t checksum; /* IP-like checksum */ +#define LIBNET_PROTO_UDLD 202 + + /* TLVs */ +#define LIBNET_UDLD_TLV_HDR_SIZE 0x04 /* UDLD TLV's header size 4 bytes */ + + uint16_t tlv__type; +#define LIBNET_UDLD_DEVICE_ID 0x0001 /* Value format: ASCII character string */ +#define LIBNET_UDLD_PORT_ID 0x0002 /* Value format: ASCII character string */ +#define LIBNET_UDLD_ECHO 0x0003 /* Value format: List of ID pairs */ +#define LIBNET_UDLD_MESSAGE_INTERVAL 0x0004 /* Value format: 8-bit unsigned integer */ +#define LIBNET_UDLD_TIMEOUT_INTERVAL 0x0005 /* Value format: 8-bit unsigned integer */ +#define LIBNET_UDLD_DEVICE_NAME 0x0006 /* Value format: ASCII character string */ +#define LIBNET_UDLD_SEQUENCE_NUMBER 0x0007 /* Value format: 32-bit unsigned integer */ +/* Reserved TLVs >0x0007 Value format: To be skipped by parsing routine */ + + uint16_t tlv__length; + + /* TLV value types */ +#define LIBNET_UDLD_VALUE_TYPE_ASCII (0) +#define LIBNET_UDLD_VALUE_TYPE_ID_PAIRS (1) +#define LIBNET_UDLD_VALUE_TYPE_8_BIT_UINT (2) +#define LIBNET_UDLD_VALUE_TYPE_32_BIT_UINT (3) +}; /* * TCP header diff --git a/include/libnet/libnet-structures.h b/include/libnet/libnet-structures.h index 4fc135e..a733ecb 100644 --- a/include/libnet/libnet-structures.h +++ b/include/libnet/libnet-structures.h @@ -162,6 +162,14 @@ struct libnet_protocol_block #define LIBNET_PBLOCK_LLDP_TTL_H 0x53 /* LLDP TTL header */ #define LIBNET_PBLOCK_LLDP_END_H 0x54 /* LLDP End of LLDPDU header */ #define LIBNET_PBLOCK_LLDP_ORG_SPEC_H 0x55 /* LLDP Organization Specific header */ +#define LIBNET_PBLOCK_UDLD_H 0x56 /* UDLD header */ +#define LIBNET_PBLOCK_UDLD_DEVICE_ID_H 0x57 /* UDLD Device ID header*/ +#define LIBNET_PBLOCK_UDLD_PORT_ID_H 0x58 /* UDLD Port ID header */ +#define LIBNET_PBLOCK_UDLD_ECHO_H 0x59 /* UDLD Echo ID header */ +#define LIBNET_PBLOCK_UDLD_MSG_INTERVAL_H 0x60 /* UDLD Message Interval header */ +#define LIBNET_PBLOCK_UDLD_TMT_INTERVAL_H 0x61 /* UDLD Timeout Interval header */ +#define LIBNET_PBLOCK_UDLD_DEVICE_NAME_H 0x62 /* UDLD Device Name header*/ +#define LIBNET_PBLOCK_UDLD_SEQ_NUMBER_H 0x63 /* UDLD Sequence Number header */ uint8_t flags; /* control flags */ #define LIBNET_PBLOCK_DO_CHECKSUM 0x01 /* needs a checksum */ |