From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
"Li Zhijian" <lizhijian@cn.fujitsu.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Zhang Chen" <chen.zhang@intel.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [Qemu-devel] [PATCH 3/6] net/filter-rewriter: Use the tcp_header structure
Date: Thu, 8 Aug 2019 16:34:54 +0200 [thread overview]
Message-ID: <20190808143457.14111-4-philmd@redhat.com> (raw)
In-Reply-To: <20190808143457.14111-1-philmd@redhat.com>
The tcp_header structure comes convenient macros to avoid
manipulating the TCP header flags/offset bits manually.
Replace the tcp_hdr structure by the tcp_header equivalent,
and use the TCP_HEADER_FLAGS macro.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
net/filter-rewriter.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index 31da08a2f4..62e0de1293 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -73,23 +73,26 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
Connection *conn,
Packet *pkt, ConnectionKey *key)
{
- struct tcp_hdr *tcp_pkt;
+ struct tcp_header *tcp_pkt;
+ uint8_t tcp_flags;
+
+ tcp_pkt = (struct tcp_header *)pkt->transport_header;
+ tcp_flags = TCP_HEADER_FLAGS(tcp_pkt);
- tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
trace_colo_filter_rewriter_pkt_info(__func__,
inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
- tcp_pkt->th_flags);
+ tcp_flags);
trace_colo_filter_rewriter_conn_offset(conn->offset);
}
- if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN)) &&
+ if (((tcp_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN)) &&
conn->tcp_state == TCPS_SYN_SENT) {
conn->tcp_state = TCPS_ESTABLISHED;
}
- if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
+ if (((tcp_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
/*
* we use this flag update offset func
* run once in independent tcp connection
@@ -97,7 +100,7 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
conn->tcp_state = TCPS_SYN_RECEIVED;
}
- if (((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_ACK)) {
+ if (((tcp_flags & (TH_ACK | TH_SYN)) == TH_ACK)) {
if (conn->tcp_state == TCPS_SYN_RECEIVED) {
/*
* offset = secondary_seq - primary seq
@@ -119,13 +122,13 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
* Passive close step 3
*/
if ((conn->tcp_state == TCPS_LAST_ACK) &&
- (ntohl(tcp_pkt->th_ack) == (conn->fin_ack_seq + 1))) {
+ (ldl_be_p(&tcp_pkt->th_ack) == (conn->fin_ack_seq + 1))) {
conn->tcp_state = TCPS_CLOSED;
g_hash_table_remove(rf->connection_track_table, key);
}
}
- if ((tcp_pkt->th_flags & TH_FIN) == TH_FIN) {
+ if ((tcp_flags & TH_FIN) == TH_FIN) {
/*
* Passive close.
* Step 1:
@@ -176,20 +179,22 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
Connection *conn,
Packet *pkt, ConnectionKey *key)
{
- struct tcp_hdr *tcp_pkt;
+ struct tcp_header *tcp_pkt;
+ uint8_t tcp_flags;
- tcp_pkt = (struct tcp_hdr *)pkt->transport_header;
+ tcp_pkt = (struct tcp_header *)pkt->transport_header;
+ tcp_flags = TCP_HEADER_FLAGS(tcp_pkt);
if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
trace_colo_filter_rewriter_pkt_info(__func__,
inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
- tcp_pkt->th_flags);
+ tcp_flags);
trace_colo_filter_rewriter_conn_offset(conn->offset);
}
if (conn->tcp_state == TCPS_SYN_RECEIVED &&
- ((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) {
+ ((tcp_flags & (TH_ACK | TH_SYN)) == (TH_ACK | TH_SYN))) {
/*
* save offset = secondary_seq and then
* in handle_primary_tcp_pkt make offset
@@ -200,11 +205,11 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
/* VM active connect */
if (conn->tcp_state == TCPS_CLOSED &&
- ((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
+ ((tcp_flags & (TH_ACK | TH_SYN)) == TH_SYN)) {
conn->tcp_state = TCPS_SYN_SENT;
}
- if ((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) == TH_ACK) {
+ if ((tcp_flags & (TH_ACK | TH_SYN)) == TH_ACK) {
/* Only need to adjust seq while offset is Non-zero */
if (conn->offset) {
/* handle packets to the primary from the secondary*/
@@ -219,7 +224,7 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
* Passive close step 2:
*/
if (conn->tcp_state == TCPS_CLOSE_WAIT &&
- (tcp_pkt->th_flags & (TH_ACK | TH_FIN)) == (TH_ACK | TH_FIN)) {
+ (tcp_flags & (TH_ACK | TH_FIN)) == (TH_ACK | TH_FIN)) {
conn->fin_ack_seq = ntohl(tcp_pkt->th_seq);
conn->tcp_state = TCPS_LAST_ACK;
}
@@ -237,7 +242,7 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
* CLOSING status.
*/
if (conn->tcp_state == TCPS_ESTABLISHED &&
- (tcp_pkt->th_flags & (TH_ACK | TH_FIN)) == TH_FIN) {
+ (tcp_flags & (TH_ACK | TH_FIN)) == TH_FIN) {
conn->tcp_state = TCPS_FIN_WAIT_1;
}
--
2.20.1
next prev parent reply other threads:[~2019-08-08 14:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-08 14:34 [Qemu-devel] [PATCH 0/6] net/eth: Remove duplicated tcp/udp_hdr structures Philippe Mathieu-Daudé
2019-08-08 14:34 ` [Qemu-devel] [RFC PATCH 1/6] hw/net/virtio-net: Use TCP_HEADER_FLAGS/TCP_HEADER_DATA_OFFSET macros Philippe Mathieu-Daudé
2019-08-08 14:34 ` [Qemu-devel] [RFC PATCH 2/6] net/colo-compare: Use the tcp_header structure Philippe Mathieu-Daudé
2019-08-08 14:34 ` Philippe Mathieu-Daudé [this message]
2019-08-08 14:34 ` [Qemu-devel] [RFC PATCH 4/6] hw/net/vmxnet3: " Philippe Mathieu-Daudé
2019-08-08 14:34 ` [Qemu-devel] [PATCH 5/6] net/eth: Remove the unused tcp_hdr structure Philippe Mathieu-Daudé
2019-08-08 14:34 ` [Qemu-devel] [PATCH 6/6] net/eth: Remove the single use of udp_hdr structure Philippe Mathieu-Daudé
2019-08-12 8:21 ` [Qemu-devel] [PATCH 0/6] net/eth: Remove duplicated tcp/udp_hdr structures Dmitry Fleytman
2019-08-18 21:38 ` Philippe Mathieu-Daudé
2019-08-19 3:08 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190808143457.14111-4-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=chen.zhang@intel.com \
--cc=dmitry.fleytman@gmail.com \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).