qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

net: do not depend on slirp internals

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 <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

authored by

Marc-André Lureau and committed by
Samuel Thibault
e05ae1d9 37b9117f

+72 -15
+6 -5
net/colo-compare.c
··· 30 30 #include "net/colo-compare.h" 31 31 #include "migration/colo.h" 32 32 #include "migration/migration.h" 33 + #include "util.h" 33 34 34 35 #define TYPE_COLO_COMPARE "colo-compare" 35 36 #define COLO_COMPARE(obj) \ ··· 129 130 130 131 static gint seq_sorter(Packet *a, Packet *b, gpointer data) 131 132 { 132 - struct tcphdr *atcp, *btcp; 133 + struct tcp_hdr *atcp, *btcp; 133 134 134 - atcp = (struct tcphdr *)(a->transport_header); 135 - btcp = (struct tcphdr *)(b->transport_header); 135 + atcp = (struct tcp_hdr *)(a->transport_header); 136 + btcp = (struct tcp_hdr *)(b->transport_header); 136 137 return ntohl(atcp->th_seq) - ntohl(btcp->th_seq); 137 138 } 138 139 139 140 static void fill_pkt_tcp_info(void *data, uint32_t *max_ack) 140 141 { 141 142 Packet *pkt = data; 142 - struct tcphdr *tcphd; 143 + struct tcp_hdr *tcphd; 143 144 144 - tcphd = (struct tcphdr *)pkt->transport_header; 145 + tcphd = (struct tcp_hdr *)pkt->transport_header; 145 146 146 147 pkt->tcp_seq = ntohl(tcphd->th_seq); 147 148 pkt->tcp_ack = ntohl(tcphd->th_ack);
+1
net/colo.c
··· 15 15 #include "qemu/osdep.h" 16 16 #include "trace.h" 17 17 #include "colo.h" 18 + #include "util.h" 18 19 19 20 uint32_t connection_key_hash(const void *opaque) 20 21 {
+3 -4
net/colo.h
··· 15 15 #ifndef QEMU_COLO_PROXY_H 16 16 #define QEMU_COLO_PROXY_H 17 17 18 - #include "slirp/slirp.h" 19 18 #include "qemu/jhash.h" 20 19 #include "qemu/timer.h" 21 - #include "slirp/tcp.h" 20 + #include "net/eth.h" 22 21 23 22 #define HASHTABLE_MAX_SIZE 16384 24 23 ··· 81 80 /* the maximum of acknowledgement number in secondary_list queue */ 82 81 uint32_t sack; 83 82 /* offset = secondary_seq - primary_seq */ 84 - tcp_seq offset; 83 + uint32_t offset; 85 84 86 85 int tcp_state; /* TCP FSM state */ 87 - tcp_seq fin_ack_seq; /* the seq of 'fin=1,ack=1' */ 86 + uint32_t fin_ack_seq; /* the seq of 'fin=1,ack=1' */ 88 87 } Connection; 89 88 90 89 uint32_t connection_key_hash(const void *opaque);
+5 -4
net/filter-rewriter.c
··· 22 22 #include "net/checksum.h" 23 23 #include "net/colo.h" 24 24 #include "migration/colo.h" 25 + #include "util.h" 25 26 26 27 #define FILTER_COLO_REWRITER(obj) \ 27 28 OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER) ··· 73 74 Connection *conn, 74 75 Packet *pkt, ConnectionKey *key) 75 76 { 76 - struct tcphdr *tcp_pkt; 77 + struct tcp_hdr *tcp_pkt; 77 78 78 - tcp_pkt = (struct tcphdr *)pkt->transport_header; 79 + tcp_pkt = (struct tcp_hdr *)pkt->transport_header; 79 80 if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) { 80 81 trace_colo_filter_rewriter_pkt_info(__func__, 81 82 inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst), ··· 176 177 Connection *conn, 177 178 Packet *pkt, ConnectionKey *key) 178 179 { 179 - struct tcphdr *tcp_pkt; 180 + struct tcp_hdr *tcp_pkt; 180 181 181 - tcp_pkt = (struct tcphdr *)pkt->transport_header; 182 + tcp_pkt = (struct tcp_hdr *)pkt->transport_header; 182 183 183 184 if (trace_event_get_state_backends(TRACE_COLO_FILTER_REWRITER_DEBUG)) { 184 185 trace_colo_filter_rewriter_pkt_info(__func__,
+1 -1
net/slirp.c
··· 38 38 #include "qemu/error-report.h" 39 39 #include "qemu/sockets.h" 40 40 #include "slirp/libslirp.h" 41 - #include "slirp/ip6.h" 42 41 #include "chardev/char-fe.h" 43 42 #include "sysemu/sysemu.h" 44 43 #include "qemu/cutils.h" 45 44 #include "qapi/error.h" 46 45 #include "qapi/qmp/qdict.h" 46 + #include "util.h" 47 47 48 48 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) 49 49 {
+55
net/util.h
··· 26 26 #define QEMU_NET_UTIL_H 27 27 28 28 29 + /* 30 + * Structure of an internet header, naked of options. 31 + */ 32 + struct ip { 33 + #ifdef HOST_WORDS_BIGENDIAN 34 + uint8_t ip_v:4, /* version */ 35 + ip_hl:4; /* header length */ 36 + #else 37 + uint8_t ip_hl:4, /* header length */ 38 + ip_v:4; /* version */ 39 + #endif 40 + uint8_t ip_tos; /* type of service */ 41 + uint16_t ip_len; /* total length */ 42 + uint16_t ip_id; /* identification */ 43 + uint16_t ip_off; /* fragment offset field */ 44 + #define IP_DF 0x4000 /* don't fragment flag */ 45 + #define IP_MF 0x2000 /* more fragments flag */ 46 + #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 47 + uint8_t ip_ttl; /* time to live */ 48 + uint8_t ip_p; /* protocol */ 49 + uint16_t ip_sum; /* checksum */ 50 + struct in_addr ip_src, ip_dst; /* source and dest address */ 51 + } QEMU_PACKED; 52 + 53 + static inline bool in6_equal_net(const struct in6_addr *a, 54 + const struct in6_addr *b, 55 + int prefix_len) 56 + { 57 + if (memcmp(a, b, prefix_len / 8) != 0) { 58 + return 0; 59 + } 60 + 61 + if (prefix_len % 8 == 0) { 62 + return 1; 63 + } 64 + 65 + return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) 66 + == b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); 67 + } 68 + 69 + #define TCPS_CLOSED 0 /* closed */ 70 + #define TCPS_LISTEN 1 /* listening for connection */ 71 + #define TCPS_SYN_SENT 2 /* active, have sent syn */ 72 + #define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 73 + /* states < TCPS_ESTABLISHED are those where connections not established */ 74 + #define TCPS_ESTABLISHED 4 /* established */ 75 + #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 76 + /* states > TCPS_CLOSE_WAIT are those where user has closed */ 77 + #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 78 + #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 79 + #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 80 + /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 81 + #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 82 + #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 83 + 29 84 int net_parse_macaddr(uint8_t *macaddr, const char *p); 30 85 31 86 #endif /* QEMU_NET_UTIL_H */
+1 -1
stubs/slirp.c
··· 1 1 #include "qemu/osdep.h" 2 2 #include "qemu-common.h" 3 3 #include "qemu/host-utils.h" 4 - #include "slirp/slirp.h" 4 + #include "slirp/libslirp.h" 5 5 6 6 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout) 7 7 {