The queues and structures previously used for TCPv4 traffic are now
used for both IP protocols. We therefore need to replace the prefix
tcp4_* with the generic tcp_ everywhere applicable.
There are no functional changes in this commit.
Signed-off-by: Jon Maloy
---
tcp.c | 4 +-
tcp_buf.c | 115 +++++++++++++++++++++++++++---------------------------
tcp_buf.h | 2 +-
3 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/tcp.c b/tcp.c
index 19cf9e5..433dce4 100644
--- a/tcp.c
+++ b/tcp.c
@@ -998,14 +998,14 @@ size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
if (a4) {
iov[TCP_IOV_IP].iov_len = sizeof(struct iphdr);
- tcp4_eth_src.h_proto = htons_constant(ETH_P_IP);
+ tcp_eth_src.h_proto = htons_constant(ETH_P_IP);
return tcp_fill_headers4(conn, iov[TCP_IOV_TAP].iov_base,
iov[TCP_IOV_IP].iov_base,
iov[TCP_IOV_PAYLOAD].iov_base, dlen,
check, seq);
} else {
iov[TCP_IOV_IP].iov_len = sizeof(struct ipv6hdr);
- tcp4_eth_src.h_proto = htons_constant(ETH_P_IPV6);
+ tcp_eth_src.h_proto = htons_constant(ETH_P_IPV6);
return tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base,
iov[TCP_IOV_IP].iov_base,
iov[TCP_IOV_PAYLOAD].iov_base, dlen,
diff --git a/tcp_buf.c b/tcp_buf.c
index 92c4d73..0476184 100644
--- a/tcp_buf.c
+++ b/tcp_buf.c
@@ -80,28 +80,27 @@ struct tcp_flags_t {
#endif
/* Ethernet header for IPv4 frames */
-struct ethhdr tcp4_eth_src;
+struct ethhdr tcp_eth_src;
-static struct tap_hdr tcp4_payload_tap_hdr[TCP_FRAMES_MEM];
+static struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM];
/* IPv4 headers */
struct iphdr tcp_payload_ip4;
-static struct iphdr_t tcp4_payload_ip[TCP_FRAMES_MEM];
+static struct iphdr_t tcp_payload_ip[TCP_FRAMES_MEM];
/* TCP segments with payload for IPv4 frames */
-static struct tcp_payload_t tcp4_payload[TCP_FRAMES_MEM];
+static struct tcp_payload_t tcp_payload[TCP_FRAMES_MEM];
-static_assert(MSS4 <= sizeof(tcp4_payload[0].data), "MSS4 is greater than 65516");
+static_assert(sizeof(tcp_payload[0].data) > MSS4, "MSS4 is greater than 65516");
/* References tracking the owner connection of frames in the tap outqueue */
-static struct tcp_tap_conn *tcp4_frame_conns[TCP_FRAMES_MEM];
-static unsigned int tcp4_payload_used;
+static struct tcp_tap_conn *tcp_frame_conns[TCP_FRAMES_MEM];
+static unsigned int tcp_payload_used;
-static struct tap_hdr tcp4_flags_tap_hdr[TCP_FRAMES_MEM];
+static struct tap_hdr tcp_flags_tap_hdr[TCP_FRAMES_MEM];
/* IPv4 headers for TCP segment without payload */
-static struct iphdr_t tcp4_flags_ip[TCP_FRAMES_MEM];
+static struct iphdr_t tcp_flags_ip[TCP_FRAMES_MEM];
/* TCP segments without payload for IPv4 frames */
-static struct tcp_flags_t tcp4_flags[TCP_FRAMES_MEM];
-
-static unsigned int tcp4_flags_used;
+static struct tcp_flags_t tcp_flags[TCP_FRAMES_MEM];
+static unsigned int tcp_flags_used;
/* Ethernet header for IPv6 frames */
struct ipv6hdr tcp_payload_ip6;
@@ -109,8 +108,8 @@ struct ipv6hdr tcp_payload_ip6;
/* recvmsg()/sendmsg() data for tap */
static struct iovec iov_sock [TCP_FRAMES_MEM + 1];
-static struct iovec tcp4_l2_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS];
-static struct iovec tcp4_l2_flags_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS];
+static struct iovec tcp_l2_iov[TCP_FRAMES_MEM][TCP_NUM_IOVS];
+static struct iovec tcp_l2_flags_iov[TCP_FRAMES_MEM][TCP_NUM_IOVS];
/**
* tcp_update_l2_buf() - Update Ethernet header buffers with addresses
@@ -119,7 +118,7 @@ static struct iovec tcp4_l2_flags_iov [TCP_FRAMES_MEM][TCP_NUM_IOVS];
*/
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s)
{
- eth_update_mac(&tcp4_eth_src, eth_d, eth_s);
+ eth_update_mac(&tcp_eth_src, eth_d, eth_s);
}
/**
@@ -132,39 +131,39 @@ void tcp_sock4_iov_init(const struct ctx *c)
struct iovec *iov;
int i;
- tcp4_eth_src.h_proto = htons_constant(ETH_P_IP);
+ tcp_eth_src.h_proto = htons_constant(ETH_P_IP);
tcp_payload_ip4 = iph;
- for (i = 0; i < ARRAY_SIZE(tcp4_payload); i++) {
- tcp4_payload[i].th.doff = sizeof(struct tcphdr) / 4;
- tcp4_payload[i].th.ack = 1;
+ for (i = 0; i < ARRAY_SIZE(tcp_payload); i++) {
+ tcp_payload[i].th.doff = sizeof(struct tcphdr) / 4;
+ tcp_payload[i].th.ack = 1;
}
- for (i = 0; i < ARRAY_SIZE(tcp4_flags); i++) {
- tcp4_flags_ip[i].ip4 = iph;
- tcp4_flags[i].th.doff = sizeof(struct tcphdr) / 4;
- tcp4_flags[i].th.ack = 1;
+ for (i = 0; i < ARRAY_SIZE(tcp_flags); i++) {
+ tcp_flags_ip[i].ip4 = iph;
+ tcp_flags[i].th.doff = sizeof(struct tcphdr) / 4;
+ tcp_flags[i].th.ack = 1;
}
for (i = 0; i < TCP_FRAMES_MEM; i++) {
- iov = tcp4_l2_iov[i];
+ iov = tcp_l2_iov[i];
- iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_payload_tap_hdr[i]);
- iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src);
- iov[TCP_IOV_IP].iov_base = &tcp4_payload_ip[i];
- iov[TCP_IOV_IP].iov_len = sizeof(tcp4_payload_ip[i].ip4);
- iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_payload[i];
+ iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp_payload_tap_hdr[i]);
+ iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp_eth_src);
+ iov[TCP_IOV_IP].iov_base = &tcp_payload_ip[i];
+ iov[TCP_IOV_IP].iov_len = sizeof(tcp_payload_ip[i].ip4);
+ iov[TCP_IOV_PAYLOAD].iov_base = &tcp_payload[i];
}
for (i = 0; i < TCP_FRAMES_MEM; i++) {
- iov = tcp4_l2_flags_iov[i];
-
- iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_flags_tap_hdr[i]);
- iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src;
- iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src);
- iov[TCP_IOV_IP].iov_base = &tcp4_flags_ip[i];
- iov[TCP_IOV_IP].iov_len = sizeof(tcp4_flags_ip[i].ip4);
- iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_flags[i];
+ iov = tcp_l2_flags_iov[i];
+
+ iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp_flags_tap_hdr[i]);
+ iov[TCP_IOV_ETH].iov_base = &tcp_eth_src;
+ iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp_eth_src);
+ iov[TCP_IOV_IP].iov_base = &tcp_flags_ip[i];
+ iov[TCP_IOV_IP].iov_len = sizeof(tcp_flags_ip[i].ip4);
+ iov[TCP_IOV_PAYLOAD].iov_base = &tcp_flags[i];
}
}
@@ -174,9 +173,9 @@ void tcp_sock4_iov_init(const struct ctx *c)
*/
void tcp_flags_flush(const struct ctx *c)
{
- tap_send_frames(c, &tcp4_l2_flags_iov[0][0], TCP_NUM_IOVS,
- tcp4_flags_used);
- tcp4_flags_used = 0;
+ tap_send_frames(c, &tcp_l2_flags_iov[0][0], TCP_NUM_IOVS,
+ tcp_flags_used);
+ tcp_flags_used = 0;
}
/**
@@ -215,13 +214,13 @@ void tcp_payload_flush(struct ctx *c)
{
size_t m;
- m = tap_send_frames(c, &tcp4_l2_iov[0][0], TCP_NUM_IOVS,
- tcp4_payload_used);
- if (m != tcp4_payload_used) {
- tcp_revert_seq(c, &tcp4_frame_conns[m], &tcp4_l2_iov[m],
- tcp4_payload_used - m);
+ m = tap_send_frames(c, &tcp_l2_iov[0][0], TCP_NUM_IOVS,
+ tcp_payload_used);
+ if (m != tcp_payload_used) {
+ tcp_revert_seq(c, &tcp_frame_conns[m], &tcp_l2_iov[m],
+ tcp_payload_used - m);
}
- tcp4_payload_used = 0;
+ tcp_payload_used = 0;
}
/**
@@ -241,13 +240,13 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
uint32_t seq;
int ret;
- iov = tcp4_l2_flags_iov[tcp4_flags_used++];
+ iov = tcp_l2_flags_iov[tcp_flags_used++];
payload = iov[TCP_IOV_PAYLOAD].iov_base;
seq = conn->seq_to_tap;
ret = tcp_prepare_flags(c, conn, flags, &payload->th,
payload->opts, &optlen);
if (ret <= 0) {
- tcp4_flags_used--;
+ tcp_flags_used--;
return ret;
}
@@ -258,7 +257,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
struct iovec *dup_iov;
int i;
- dup_iov = tcp4_l2_flags_iov[tcp4_flags_used++];
+ dup_iov = tcp_l2_flags_iov[tcp_flags_used++];
for (i = 0; i < TCP_NUM_IOVS; i++)
memcpy(dup_iov[i].iov_base, iov[i].iov_base,
@@ -266,7 +265,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
dup_iov[TCP_IOV_PAYLOAD].iov_len = iov[TCP_IOV_PAYLOAD].iov_len;
}
- if (tcp4_flags_used > TCP_FRAMES_MEM - 2)
+ if (tcp_flags_used > TCP_FRAMES_MEM - 2)
tcp_flags_flush(c);
return 0;
@@ -283,7 +282,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn,
ssize_t dlen, int no_csum, uint32_t seq)
{
- struct iovec *iov_prev = tcp4_l2_iov[tcp4_payload_used - 1];
+ struct iovec *iov_prev = tcp_l2_iov[tcp_payload_used - 1];
const uint16_t *check = NULL;
struct iovec *iov;
size_t l4len;
@@ -296,12 +295,12 @@ static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn,
check = &iph->check;
}
- tcp4_frame_conns[tcp4_payload_used] = conn;
+ tcp_frame_conns[tcp_payload_used] = conn;
- iov = tcp4_l2_iov[tcp4_payload_used++];
+ iov = tcp_l2_iov[tcp_payload_used++];
l4len = tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq);
iov[TCP_IOV_PAYLOAD].iov_len = l4len;
- if (tcp4_payload_used > TCP_FRAMES_MEM - 1)
+ if (tcp_payload_used > TCP_FRAMES_MEM - 1)
tcp_payload_flush(c);
}
@@ -366,15 +365,15 @@ int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn)
mh_sock.msg_iovlen = fill_bufs;
}
- if ((v4 && tcp4_payload_used + fill_bufs > TCP_FRAMES_MEM)) {
+ if ((v4 && tcp_payload_used + fill_bufs > TCP_FRAMES_MEM)) {
tcp_payload_flush(c);
/* Silence Coverity CWE-125 false positive */
- tcp4_payload_used = 0;
+ tcp_payload_used = 0;
}
for (i = 0, iov = iov_sock + 1; i < fill_bufs; i++, iov++) {
- iov->iov_base = &tcp4_payload[tcp4_payload_used + i].data;
+ iov->iov_base = &tcp_payload[tcp_payload_used + i].data;
iov->iov_len = mss;
}
if (iov_rem)
@@ -422,7 +421,7 @@ int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn)
dlen = mss;
seq = conn->seq_to_tap;
for (i = 0; i < send_bufs; i++) {
- int no_csum = i && i != send_bufs - 1 && tcp4_payload_used;
+ int no_csum = i && i != send_bufs - 1 && tcp_payload_used;
if (i == send_bufs - 1)
dlen = last_len;
diff --git a/tcp_buf.h b/tcp_buf.h
index d7cdbaf..3dc3c95 100644
--- a/tcp_buf.h
+++ b/tcp_buf.h
@@ -13,7 +13,7 @@ void tcp_payload_flush(struct ctx *c);
int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn);
int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags);
-extern struct ethhdr tcp4_eth_src;
+extern struct ethhdr tcp_eth_src;
extern struct iphdr tcp_payload_ip4;
extern struct ipv6hdr tcp_payload_ip6;
#endif /*TCP_BUF_H */
--
2.45.2