From patchwork Mon Jan 14 00:03:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10761525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40FD013BF for ; Mon, 14 Jan 2019 00:36:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3022C2888A for ; Mon, 14 Jan 2019 00:36:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23E4128A38; Mon, 14 Jan 2019 00:36:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 77C5A2888A for ; Mon, 14 Jan 2019 00:36:56 +0000 (UTC) Received: from localhost ([127.0.0.1]:45280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giqFL-0002B1-Nk for patchwork-qemu-devel@patchwork.kernel.org; Sun, 13 Jan 2019 19:36:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gipkY-0003Ix-KU for qemu-devel@nongnu.org; Sun, 13 Jan 2019 19:05:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gipkX-0006if-AP for qemu-devel@nongnu.org; Sun, 13 Jan 2019 19:05:06 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:60522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gipkW-0006X4-Vq for qemu-devel@nongnu.org; Sun, 13 Jan 2019 19:05:05 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id AA31A1B75; Mon, 14 Jan 2019 01:04:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ID1jawnfS1ps; Mon, 14 Jan 2019 01:04:33 +0100 (CET) Received: from function.home (lfbn-1-11161-124.w86-213.abo.wanadoo.fr [86.213.235.124]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B81381BBD; Mon, 14 Jan 2019 01:04:09 +0100 (CET) Received: from samy by function.home with local (Exim 4.92-RC4) (envelope-from ) id 1gipja-0007ou-Ob; Mon, 14 Jan 2019 01:04:06 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 01:03:03 +0100 Message-Id: <20190114000326.29847-43-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114000326.29847-1-samuel.thibault@ens-lyon.org> References: <20190114000326.29847-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULL 42/65] net: do not depend on slirp internals X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Only slirp/libslirp.h should be included. Instead of using some slirp declarations and utility functions directly, let's copy them in net/util.h. Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Samuel Thibault --- net/colo-compare.c | 11 +++++---- net/colo.c | 1 + net/colo.h | 7 +++--- net/filter-rewriter.c | 9 +++---- net/slirp.c | 2 +- net/util.h | 55 +++++++++++++++++++++++++++++++++++++++++++ stubs/slirp.c | 2 +- 7 files changed, 72 insertions(+), 15 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 9156ab3349..3e515f3023 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -30,6 +30,7 @@ #include "net/colo-compare.h" #include "migration/colo.h" #include "migration/migration.h" +#include "util.h" #define TYPE_COLO_COMPARE "colo-compare" #define COLO_COMPARE(obj) \ @@ -129,19 +130,19 @@ static int compare_chr_send(CompareState *s, static gint seq_sorter(Packet *a, Packet *b, gpointer data) { - struct tcphdr *atcp, *btcp; + struct tcp_hdr *atcp, *btcp; - atcp = (struct tcphdr *)(a->transport_header); - btcp = (struct tcphdr *)(b->transport_header); + atcp = (struct tcp_hdr *)(a->transport_header); + btcp = (struct tcp_hdr *)(b->transport_header); return ntohl(atcp->th_seq) - ntohl(btcp->th_seq); } static void fill_pkt_tcp_info(void *data, uint32_t *max_ack) { Packet *pkt = data; - struct tcphdr *tcphd; + struct tcp_hdr *tcphd; - tcphd = (struct tcphdr *)pkt->transport_header; + tcphd = (struct tcp_hdr *)pkt->transport_header; pkt->tcp_seq = ntohl(tcphd->th_seq); pkt->tcp_ack = ntohl(tcphd->th_ack); diff --git a/net/colo.c b/net/colo.c index 49176bf07b..8196b35837 100644 --- a/net/colo.c +++ b/net/colo.c @@ -15,6 +15,7 @@ #include "qemu/osdep.h" #include "trace.h" #include "colo.h" +#include "util.h" uint32_t connection_key_hash(const void *opaque) { diff --git a/net/colo.h b/net/colo.h index 11c5226488..b21c6830b5 100644 --- a/net/colo.h +++ b/net/colo.h @@ -15,10 +15,9 @@ #ifndef QEMU_COLO_PROXY_H #define QEMU_COLO_PROXY_H -#include "slirp/slirp.h" #include "qemu/jhash.h" #include "qemu/timer.h" -#include "slirp/tcp.h" +#include "net/eth.h" #define HASHTABLE_MAX_SIZE 16384 @@ -81,10 +80,10 @@ typedef struct Connection { /* the maximum of acknowledgement number in secondary_list queue */ uint32_t sack; /* offset = secondary_seq - primary_seq */ - tcp_seq offset; + uint32_t offset; int tcp_state; /* TCP FSM state */ - tcp_seq fin_ack_seq; /* the seq of 'fin=1,ack=1' */ + uint32_t fin_ack_seq; /* the seq of 'fin=1,ack=1' */ } Connection; uint32_t connection_key_hash(const void *opaque); diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 2e26839bc2..b464abe5e8 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -22,6 +22,7 @@ #include "net/checksum.h" #include "net/colo.h" #include "migration/colo.h" +#include "util.h" #define FILTER_COLO_REWRITER(obj) \ OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER) @@ -73,9 +74,9 @@ static int handle_primary_tcp_pkt(RewriterState *rf, Connection *conn, Packet *pkt, ConnectionKey *key) { - struct tcphdr *tcp_pkt; + struct tcp_hdr *tcp_pkt; - tcp_pkt = (struct tcphdr *)pkt->transport_header; + 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), @@ -176,9 +177,9 @@ static int handle_secondary_tcp_pkt(RewriterState *rf, Connection *conn, Packet *pkt, ConnectionKey *key) { - struct tcphdr *tcp_pkt; + struct tcp_hdr *tcp_pkt; - tcp_pkt = (struct tcphdr *)pkt->transport_header; + 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__, diff --git a/net/slirp.c b/net/slirp.c index ea8b04e007..b1c98b9470 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -38,12 +38,12 @@ #include "qemu/error-report.h" #include "qemu/sockets.h" #include "slirp/libslirp.h" -#include "slirp/ip6.h" #include "chardev/char-fe.h" #include "sysemu/sysemu.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" +#include "util.h" static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) { diff --git a/net/util.h b/net/util.h index 60b73d372d..358185fd50 100644 --- a/net/util.h +++ b/net/util.h @@ -26,6 +26,61 @@ #define QEMU_NET_UTIL_H +/* + * Structure of an internet header, naked of options. + */ +struct ip { +#ifdef HOST_WORDS_BIGENDIAN + uint8_t ip_v:4, /* version */ + ip_hl:4; /* header length */ +#else + uint8_t ip_hl:4, /* header length */ + ip_v:4; /* version */ +#endif + uint8_t ip_tos; /* type of service */ + uint16_t ip_len; /* total length */ + uint16_t ip_id; /* identification */ + uint16_t ip_off; /* fragment offset field */ +#define IP_DF 0x4000 /* don't fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + uint8_t ip_ttl; /* time to live */ + uint8_t ip_p; /* protocol */ + uint16_t ip_sum; /* checksum */ + struct in_addr ip_src, ip_dst; /* source and dest address */ +} QEMU_PACKED; + +static inline bool in6_equal_net(const struct in6_addr *a, + const struct in6_addr *b, + int prefix_len) +{ + if (memcmp(a, b, prefix_len / 8) != 0) { + return 0; + } + + if (prefix_len % 8 == 0) { + return 1; + } + + return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) + == b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); +} + +#define TCPS_CLOSED 0 /* closed */ +#define TCPS_LISTEN 1 /* listening for connection */ +#define TCPS_SYN_SENT 2 /* active, have sent syn */ +#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ +/* states < TCPS_ESTABLISHED are those where connections not established */ +#define TCPS_ESTABLISHED 4 /* established */ +#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ +/* states > TCPS_CLOSE_WAIT are those where user has closed */ +#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ +#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ +#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ +/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ +#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ +#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ + int net_parse_macaddr(uint8_t *macaddr, const char *p); #endif /* QEMU_NET_UTIL_H */ diff --git a/stubs/slirp.c b/stubs/slirp.c index 42f7e1afd0..70704346fd 100644 --- a/stubs/slirp.c +++ b/stubs/slirp.c @@ -1,7 +1,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/host-utils.h" -#include "slirp/slirp.h" +#include "slirp/libslirp.h" void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) {