TSG-13157 Decrypted Traffic Steering构造的SYN/SYN ACK支持窗口扩大选项
This commit is contained in:
@@ -167,7 +167,7 @@ static uint16_t tcp_checksum_v6(const void *l4_hdr, uint16_t l4_len, struct in6_
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
|
||||
int tcp_header_construct(char *buffer, uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, uint16_t urgent)
|
||||
int tcp_header_construct(char *buffer, uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, uint16_t urgent, const char *options, uint16_t options_len)
|
||||
{
|
||||
struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)buffer;
|
||||
|
||||
@@ -175,13 +175,14 @@ int tcp_header_construct(char *buffer, uint16_t src_port, uint16_t dst_port, uin
|
||||
tcp_hdr->dst_port = dst_port;
|
||||
tcp_hdr->sent_seq = htonl(seq);
|
||||
tcp_hdr->recv_ack = htonl(ack);
|
||||
tcp_hdr->data_off = 0x50;
|
||||
tcp_hdr->data_off = (sizeof(struct tcp_hdr) + options_len) << 2;
|
||||
tcp_hdr->flags = flags;
|
||||
tcp_hdr->rx_window = htons(window);
|
||||
tcp_hdr->checksum = 0;
|
||||
tcp_hdr->urgent_ptr = urgent;
|
||||
memcpy(buffer + sizeof(struct tcp_hdr), options, options_len);
|
||||
|
||||
return sizeof(struct tcp_hdr);
|
||||
return sizeof(struct tcp_hdr) + options_len;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@ -312,11 +313,12 @@ int ether_header_construct(char *buffer, struct ether_addr *src_mac, struct ethe
|
||||
******************************************************************************/
|
||||
|
||||
int tcp_packet_v4_construct(
|
||||
char *buffer, // buffer
|
||||
char *buffer, // buffer
|
||||
struct ether_addr *src_mac, struct ether_addr *dst_mac, uint16_t vlan_tci, uint16_t l3_protocol, // Ether
|
||||
struct in_addr *src_addr, struct in_addr *dst_addr, u_char tos, u_char ttl, uint16_t id, // IPv4
|
||||
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP
|
||||
const char *payload, uint16_t payload_len) // APP
|
||||
struct in_addr *src_addr, struct in_addr *dst_addr, u_char tos, u_char ttl, uint16_t id, // IPv4
|
||||
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP Header
|
||||
const char *tcp_options, uint16_t tcp_options_len, // TCP Options
|
||||
const char *payload, uint16_t payload_len) // Payload
|
||||
{
|
||||
uint16_t length = 0;
|
||||
|
||||
@@ -333,15 +335,15 @@ int tcp_packet_v4_construct(
|
||||
// IPv4 Header
|
||||
u_char protocol = IPPROTO_TCP;
|
||||
uint16_t frag = 0;
|
||||
length += ipv4_header_construct(buffer + length, payload_len + sizeof(struct tcphdr), src_addr, dst_addr, tos, id, frag, ttl, protocol);
|
||||
length += ipv4_header_construct(buffer + length, sizeof(struct tcphdr) + tcp_options_len + payload_len, src_addr, dst_addr, tos, id, frag, ttl, protocol);
|
||||
|
||||
// TCP header and payload
|
||||
uint16_t urgent = 0;
|
||||
struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(buffer + length);
|
||||
length += tcp_header_construct((char *)tcp_hdr, src_port, dst_port, seq, ack, flags, window, urgent);
|
||||
length += tcp_header_construct((char *)tcp_hdr, src_port, dst_port, seq, ack, flags, window, urgent, tcp_options, tcp_options_len);
|
||||
memcpy(buffer + length, payload, payload_len);
|
||||
length += payload_len;
|
||||
tcp_hdr->checksum = tcp_checksum_v4((void *)tcp_hdr, sizeof(struct tcp_hdr) + payload_len, src_addr, dst_addr);
|
||||
tcp_hdr->checksum = tcp_checksum_v4((void *)tcp_hdr, sizeof(struct tcp_hdr) + tcp_options_len + payload_len, src_addr, dst_addr);
|
||||
|
||||
return length;
|
||||
}
|
||||
@@ -351,11 +353,12 @@ int tcp_packet_v4_construct(
|
||||
******************************************************************************/
|
||||
|
||||
int tcp_packet_v6_construct(
|
||||
char *buffer, // buffer
|
||||
char *buffer, // buffer
|
||||
struct ether_addr *src_mac, struct ether_addr *dst_mac, uint16_t vlan_tci, uint16_t l3_protocol, // Ether
|
||||
struct in6_addr *src_addr, struct in6_addr *dst_addr, u_char ttl, // IPv6
|
||||
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP
|
||||
const char *payload, uint16_t payload_len) // APP
|
||||
struct in6_addr *src_addr, struct in6_addr *dst_addr, u_char ttl, // IPv6
|
||||
uint16_t src_port, uint16_t dst_port, uint32_t seq, uint32_t ack, u_char flags, uint16_t window, // TCP Header
|
||||
const char *tcp_options, uint16_t tcp_options_len, // TCP Options
|
||||
const char *payload, uint16_t payload_len) // Payload
|
||||
{
|
||||
uint16_t length = 0;
|
||||
|
||||
@@ -371,15 +374,15 @@ int tcp_packet_v6_construct(
|
||||
|
||||
// IPv6 Header
|
||||
u_char protocol = IPPROTO_TCP;
|
||||
length += ipv6_header_construct(buffer + length, payload_len + sizeof(struct tcphdr), src_addr, dst_addr, ttl, protocol);
|
||||
length += ipv6_header_construct(buffer + length, sizeof(struct tcphdr) + tcp_options_len + payload_len, src_addr, dst_addr, ttl, protocol);
|
||||
|
||||
// TCP header and payload
|
||||
uint16_t urgent = 0;
|
||||
struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(buffer + length);
|
||||
length += tcp_header_construct((char *)tcp_hdr, src_port, dst_port, seq, ack, flags, window, urgent);
|
||||
length += tcp_header_construct((char *)tcp_hdr, src_port, dst_port, seq, ack, flags, window, urgent, tcp_options, tcp_options_len);
|
||||
memcpy(buffer + length, payload, payload_len);
|
||||
length += payload_len;
|
||||
tcp_hdr->checksum = tcp_checksum_v6((void *)tcp_hdr, sizeof(struct tcp_hdr) + payload_len, src_addr, dst_addr);
|
||||
tcp_hdr->checksum = tcp_checksum_v6((void *)tcp_hdr, sizeof(struct tcp_hdr) + tcp_options_len + payload_len, src_addr, dst_addr);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user