Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions subsys/net/ip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2719,8 +2719,8 @@
}

static enum net_verdict tcp_data_received(struct tcp *conn, struct net_pkt *pkt,
size_t *len, bool psh)
size_t *len, bool psh, bool fin)
{

Check notice on line 2723 in subsys/net/ip/tcp.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/tcp.c:2723 -static enum net_verdict tcp_data_received(struct tcp *conn, struct net_pkt *pkt, - size_t *len, bool psh, bool fin) +static enum net_verdict tcp_data_received(struct tcp *conn, struct net_pkt *pkt, size_t *len, + bool psh, bool fin)
enum net_verdict ret;

if (*len == 0) {
Expand All @@ -2732,6 +2732,13 @@
net_stats_update_tcp_seg_recv(conn->iface);
conn_ack(conn, *len);

/* In case FIN was received, don't send ACK just yet, FIN,ACK will be
* sent instead.
*/
if (fin) {
return ret;
}

/* Delay ACK response in case of small window or missing PSH,
* as described in RFC 813.
*/
Expand Down Expand Up @@ -3143,37 +3150,8 @@
}

break;
case TCP_ESTABLISHED:
/* full-close */
if (FL(&fl, &, FIN, th_seq(th) == conn->ack)) {
if (len) {
verdict = tcp_data_get(conn, pkt, &len);
if (verdict == NET_OK) {
/* net_pkt owned by the recv fifo now */
pkt = NULL;
}
} else {
verdict = NET_OK;
}

conn_ack(conn, + len + 1);
keep_alive_timer_stop(conn);

if (net_tcp_seq_cmp(th_ack(th), conn->seq) > 0) {
uint32_t len_acked = th_ack(th) - conn->seq;

conn_seq(conn, + len_acked);
}

tcp_out(conn, FIN | ACK);
conn_seq(conn, + 1);
tcp_setup_retransmission(conn);

tcp_setup_last_ack_timer(conn);
next = TCP_LAST_ACK;

break;
}
case TCP_ESTABLISHED: {
bool fin = FL(&fl, &, FIN, th_seq(th) == conn->ack);

/* Whatever we've received, we know that peer is alive, so reset
* the keepalive timer.
Expand Down Expand Up @@ -3279,11 +3257,21 @@

/* We are closing the connection, send a FIN to peer */
if (conn->in_close && conn->send_data_total == 0) {
next = TCP_FIN_WAIT_1;

k_work_reschedule_for_queue(&tcp_work_q,
&conn->fin_timer,
FIN_TIMEOUT);
if (fin) {
/* If FIN was also present in the processed
* packet, acknowledge that and jump directly
* to TCP_LAST_ACK.
*/
conn_ack(conn, + 1);
next = TCP_LAST_ACK;
tcp_setup_last_ack_timer(conn);
} else {
/* Otherwise, wait for FIN in TCP_FIN_WAIT_1 */
next = TCP_FIN_WAIT_1;
k_work_reschedule_for_queue(&tcp_work_q,
&conn->fin_timer,
FIN_TIMEOUT);

Check notice on line 3273 in subsys/net/ip/tcp.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/tcp.c:3273 - conn_ack(conn, + 1); + conn_ack(conn, +1); next = TCP_LAST_ACK; tcp_setup_last_ack_timer(conn); } else { /* Otherwise, wait for FIN in TCP_FIN_WAIT_1 */ next = TCP_FIN_WAIT_1; - k_work_reschedule_for_queue(&tcp_work_q, - &conn->fin_timer, + k_work_reschedule_for_queue(&tcp_work_q, &conn->fin_timer,
}

tcp_out(conn, FIN | ACK);
conn_seq(conn, + 1);
Expand Down Expand Up @@ -3314,7 +3302,7 @@
data_recv:
psh = FL(&fl, &, PSH);

verdict = tcp_data_received(conn, pkt, &len, psh);
verdict = tcp_data_received(conn, pkt, &len, psh, fin);
if (verdict == NET_OK) {
/* net_pkt owned by the recv fifo now */
pkt = NULL;
Expand Down Expand Up @@ -3358,7 +3346,19 @@
k_sem_give(&conn->tx_sem);
}

/* Finally, after all Data/ACK processing, check for FIN flag. */
if (fin) {
keep_alive_timer_stop(conn);
conn_ack(conn, + 1);
tcp_out(conn, FIN | ACK);
conn_seq(conn, + 1);
tcp_setup_retransmission(conn);

Check notice on line 3355 in subsys/net/ip/tcp.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/ip/tcp.c:3355 - conn_ack(conn, + 1); + conn_ack(conn, +1); tcp_out(conn, FIN | ACK); - conn_seq(conn, + 1); + conn_seq(conn, +1);
tcp_setup_last_ack_timer(conn);
next = TCP_LAST_ACK;
}

break;
}
case TCP_CLOSE_WAIT:
/* Half-close is not supported, so do nothing here */
break;
Expand Down
25 changes: 11 additions & 14 deletions subsys/net/lib/dns/llmnr_responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,19 @@

static void add_question(struct net_buf *query, enum dns_rr_type qtype)
{
char *dot = query->data + DNS_MSG_HEADER_SIZE;
char *prev = NULL;
char *dot = query->data + DNS_MSG_HEADER_SIZE + 1;
char *prev = query->data + DNS_MSG_HEADER_SIZE;
uint16_t offset;

while ((dot = strchr(dot, '.'))) {
if (!prev) {
prev = dot++;
continue;
}
/* For the length of the first label. */
query->len += 1;

while ((dot = strchr(dot, '.')) != NULL) {
*prev = dot - prev - 1;
prev = dot++;
}

if (prev) {
*prev = strlen(prev) - 1;
}
*prev = strlen(prev + 1);

offset = DNS_MSG_HEADER_SIZE + query->len + 1;
UNALIGNED_PUT(htons(qtype), (uint16_t *)(query->data+offset));
Expand Down Expand Up @@ -245,14 +241,15 @@
/* Prepare the response into the query buffer: move the name
* query buffer has to get enough free space: dns_hdr + query + answer
*/
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE +
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE + 1 +
(DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 +
DNS_TTL_LEN + DNS_RDLENGTH_LEN +
addr_len + query->len)) {
return -ENOBUFS;

Check notice on line 248 in subsys/net/lib/dns/llmnr_responder.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/dns/llmnr_responder.c:248 - if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE + 1 + - (DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 + - DNS_TTL_LEN + DNS_RDLENGTH_LEN + - addr_len + query->len)) { + if ((net_buf_max_len(query) - query->len) < + (DNS_MSG_HEADER_SIZE + 1 + (DNS_QTYPE_LEN + DNS_QCLASS_LEN) * 2 + DNS_TTL_LEN + + DNS_RDLENGTH_LEN + addr_len + query->len)) {
}

memmove(query->data + DNS_MSG_HEADER_SIZE, query->data, query->len);
/* +1 for the initial label length */
memmove(query->data + DNS_MSG_HEADER_SIZE + 1, query->data, query->len);

setup_dns_hdr(query->data, 1, dns_id);

Expand Down Expand Up @@ -488,8 +485,8 @@
result->data, ret);

/* If the query matches to our hostname, then send reply */
if (!strncasecmp(hostname, result->data + 1, hostname_len) &&
(result->len - 1) >= hostname_len) {
if (!strncasecmp(hostname, result->data, hostname_len) &&
(result->len) >= hostname_len) {
NET_DBG("%s query to our hostname %s", "LLMNR",
hostname);
ret = send_response(sock, src_addr, addrlen, result, qtype,
Expand Down
29 changes: 13 additions & 16 deletions subsys/net/lib/dns/mdns_responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,19 @@
static void add_answer(struct net_buf *query, enum dns_rr_type qtype,
uint32_t ttl, uint16_t addr_len, uint8_t *addr)
{
char *dot = query->data + DNS_MSG_HEADER_SIZE;
char *prev = NULL;
char *dot = query->data + DNS_MSG_HEADER_SIZE + 1;
char *prev = query->data + DNS_MSG_HEADER_SIZE;
uint16_t offset;

while ((dot = strchr(dot, '.'))) {
if (!prev) {
prev = dot++;
continue;
}
/* For the length of the first label. */
query->len += 1;

while ((dot = strchr(dot, '.')) != NULL) {
*prev = dot - prev - 1;
prev = dot++;
}

if (prev) {
*prev = strlen(prev) - 1;
}
*prev = strlen(prev + 1);

/* terminator byte (0x00) */
query->len += 1;
Expand Down Expand Up @@ -322,14 +318,15 @@
/* Prepare the response into the query buffer: move the name
* query buffer has to get enough free space: dns_hdr + answer
*/
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE +
if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE + 1 +
DNS_QTYPE_LEN + DNS_QCLASS_LEN +
DNS_TTL_LEN + DNS_RDLENGTH_LEN +
addr_len)) {
return -ENOBUFS;

Check notice on line 325 in subsys/net/lib/dns/mdns_responder.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/dns/mdns_responder.c:325 - if ((net_buf_max_len(query) - query->len) < (DNS_MSG_HEADER_SIZE + 1 + - DNS_QTYPE_LEN + DNS_QCLASS_LEN + - DNS_TTL_LEN + DNS_RDLENGTH_LEN + - addr_len)) { + if ((net_buf_max_len(query) - query->len) < + (DNS_MSG_HEADER_SIZE + 1 + DNS_QTYPE_LEN + DNS_QCLASS_LEN + DNS_TTL_LEN + + DNS_RDLENGTH_LEN + addr_len)) {
}

memmove(query->data + DNS_MSG_HEADER_SIZE, query->data, query->len);
/* +1 for the initial label length */
memmove(query->data + DNS_MSG_HEADER_SIZE + 1, query->data, query->len);

setup_dns_hdr(query->data, 1);

Expand Down Expand Up @@ -641,7 +638,7 @@
}

/* Handle only .local queries */
lquery = strrchr(result->data + 1, '.');
lquery = strrchr(result->data, '.');
if (!lquery || memcmp(lquery, (const void *){ ".local" }, 7)) {
continue;
}
Expand All @@ -654,9 +651,9 @@
* We skip the first dot, and make sure there is dot after
* matching hostname.
*/
if (!strncasecmp(hostname, result->data + 1, hostname_len) &&
(result->len - 1) >= hostname_len &&
&(result->data + 1)[hostname_len] == lquery) {
if (!strncasecmp(hostname, result->data, hostname_len) &&
(result->len) >= hostname_len &&
&result->data[hostname_len] == lquery) {
NET_DBG("%s %s %s to our hostname %s%s", "mDNS",
family == AF_INET ? "IPv4" : "IPv6", "query",
hostname, ".local");
Expand All @@ -664,7 +661,7 @@
result, qtype);
} else if (IS_ENABLED(CONFIG_MDNS_RESPONDER_DNS_SD)
&& qtype == DNS_RR_TYPE_PTR) {
send_sd_response(sock, family, src_addr, addrlen,

Check notice on line 664 in subsys/net/lib/dns/mdns_responder.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/net/lib/dns/mdns_responder.c:664 - (result->len) >= hostname_len && - &result->data[hostname_len] == lquery) { + (result->len) >= hostname_len && &result->data[hostname_len] == lquery) { NET_DBG("%s %s %s to our hostname %s%s", "mDNS", family == AF_INET ? "IPv4" : "IPv6", "query", hostname, ".local"); send_response(sock, family, src_addr, addrlen, result, qtype); - } else if (IS_ENABLED(CONFIG_MDNS_RESPONDER_DNS_SD) - && qtype == DNS_RR_TYPE_PTR) { + } else if (IS_ENABLED(CONFIG_MDNS_RESPONDER_DNS_SD) && qtype == DNS_RR_TYPE_PTR) {
&dns_msg, result);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/net/socket/getaddrinfo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
/* In this test we are just checking if the query came to us in correct
* form, we are not creating a DNS server implementation here.
*/
if (strncmp(result->data + 1, QUERY_HOST,
if (strncmp(result->data, QUERY_HOST,
sizeof(QUERY_HOST) - 1)) {
net_buf_unref(result);

Check notice on line 101 in tests/net/socket/getaddrinfo/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/net/socket/getaddrinfo/src/main.c:101 - if (strncmp(result->data, QUERY_HOST, - sizeof(QUERY_HOST) - 1)) { + if (strncmp(result->data, QUERY_HOST, sizeof(QUERY_HOST) - 1)) {
return false;
}

Expand Down
Loading
Loading