- TCP client/server initial implementation - TCPWindow reworked, now without MP
90 lines
2.6 KiB
C
90 lines
2.6 KiB
C
#ifndef ETHERLIB_TCP_SEGMENT_H
|
|
#define ETHERLIB_TCP_SEGMENT_H
|
|
|
|
#include <stdint.h>
|
|
#include "../../packet_sieve.h"
|
|
|
|
#define ETH_TCP_PACKET_CLASS (6)
|
|
#define ETH_TCP_HEADER_SIZE (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;
|
|
|
|
/**
|
|
* Allocate new TCP option.
|
|
* @param kind kind of TCP option.
|
|
* @param size size of value
|
|
* @return pointer to newly allocated option
|
|
*/
|
|
TcpOption * tcpopt_new(uint32_t kind, uint32_t size);
|
|
|
|
/**
|
|
* 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, PcktProcFnPassbackData *pb);
|
|
|
|
/**
|
|
* 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, struct EthInterface_ *intf);
|
|
|
|
/**
|
|
* Get the flattened size of the option chain.
|
|
* @param optLe list of TCP options
|
|
* @return flattened size of options
|
|
*/
|
|
uint32_t tcp_get_options_size(TcpOption * optLe);
|
|
|
|
/**
|
|
* Get TCP option by filtering against kind field.
|
|
* @param kind option kind to lookup
|
|
* @param opt linked list of options
|
|
* @return pointer to option OR NULL if not found
|
|
*/
|
|
TcpOption * tcp_get_option_by_kind(TcpOption * opt, uint16_t kind);
|
|
|
|
#endif //ETHERLIB_TCP_SEGMENT_H
|