- generic Queue implemented - PacketRegistry allocation bug fixed - TCP implementation initials - ALIGN to type macros added
82 lines
2.2 KiB
C
82 lines
2.2 KiB
C
#ifndef ETHERLIB_TEST_TCP_SEGMENT_H
|
|
#define ETHERLIB_TEST_TCP_SEGMENT_H
|
|
|
|
#include <stdint.h>
|
|
#include "../../packet_sieve.h"
|
|
|
|
#define ETH_TCP_PACKET_CLASS (6)
|
|
#define ETH_TCP_HEADER_LENGTH (20)
|
|
|
|
#define TCP_MAX_OPT_VAL_LEN (8)
|
|
|
|
/**
|
|
* TCP option kinds.
|
|
*/
|
|
typedef enum {
|
|
TCP_OPT_KIND_EOL = 0, // End of Operation List Option
|
|
TCP_OPT_KIND_NOP = 1, // No-Operation
|
|
TCP_OPT_KIND_MSS = 2 // Maximum Segment Size
|
|
} TcpOptionKind;
|
|
|
|
/**
|
|
* TCP options
|
|
*/
|
|
typedef struct TcpOption_ {
|
|
uint8_t kind; ///< Kind of the specific option (~type)
|
|
uint8_t size; ///< Size of value (NOT including 'kind' and 'length' fields) [=TCP opt length - 2]
|
|
struct TcpOption_ * next; ///< Next option in the list
|
|
uint8_t value[]; ///< Value
|
|
} TcpOption;
|
|
|
|
/**
|
|
* TCP segment flags
|
|
*/
|
|
typedef enum {
|
|
TCP_FLAG_FIN = 0x01,
|
|
TCP_FLAG_SYN = 0x02,
|
|
TCP_FLAG_RESET = 0x04,
|
|
TCP_FLAG_PUSH = 0x08,
|
|
TCP_FLAG_ACK = 0x10,
|
|
TCP_FLAG_URGENT = 0x20,
|
|
TCP_FLAG_ECNECHO = 0x40,
|
|
TCP_FLAG_CWR = 0x80,
|
|
TCP_FLAG_NONCE = 0x100
|
|
} TcpFlag;
|
|
|
|
/**
|
|
* TCP segment properties.
|
|
*/
|
|
typedef struct {
|
|
PcktPropsHeader
|
|
uint16_t SourcePort; ///< Source port
|
|
uint16_t DestinationPort; ///< Destination port
|
|
uint32_t SequenceNumber; ///< TCP sequence number
|
|
uint32_t AcknowledgementNumber; ///< TCP ack. number
|
|
uint8_t DataOffset; ///< Data offset in 32-bits (4 bit-long field)
|
|
uint16_t Flags; ///< TCP flags (9-bit, 8 + 4, but upper 3 is reserved)
|
|
uint16_t Window; ///< TCP window
|
|
uint16_t Checksum; ///< Checksum
|
|
uint16_t UrgentPtr; ///< Urgent pointer
|
|
TcpOption * options; ///< Linked list of TCP options
|
|
} TcpProps;
|
|
|
|
struct EthInterface_;
|
|
|
|
/**
|
|
* Parse raw TCP segments.
|
|
* @param hdr pointer to the TCP packet header
|
|
* @param size total packet size
|
|
* @param pcktHdrLe pointer to property storage
|
|
* @return 0 on success or -1 on failure
|
|
*/
|
|
int parse_tcp(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf);
|
|
|
|
/**
|
|
* Insert TCP header.
|
|
* @param hdr space where the header is to be inserted
|
|
* @param headers linked list of header, top is always relevant
|
|
*/
|
|
void insert_tcp_header(uint8_t * hdr, const PcktHeaderElement * headers);
|
|
|
|
#endif //ETHERLIB_TEST_TCP_SEGMENT_H
|