aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--flow.c1
-rw-r--r--migrate.c1
-rw-r--r--pcap.c1
-rw-r--r--serialise.c88
-rw-r--r--serialise.h14
-rw-r--r--tcp.c1
-rw-r--r--util.c70
-rw-r--r--util.h2
9 files changed, 113 insertions, 76 deletions
diff --git a/Makefile b/Makefile
index 513dc6c..5b6891d 100644
--- a/Makefile
+++ b/Makefile
@@ -40,8 +40,8 @@ FLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c epoll_ctl.c \
flow.c fwd.c icmp.c igmp.c inany.c iov.c ip.c isolation.c lineread.c \
log.c mld.c ndp.c netlink.c migrate.c packet.c passt.c pasta.c pcap.c \
- pif.c repair.c tap.c tcp.c tcp_buf.c tcp_splice.c tcp_vu.c udp.c \
- udp_flow.c udp_vu.c util.c vhost_user.c virtio.c vu_common.c
+ pif.c repair.c serialise.c tap.c tcp.c tcp_buf.c tcp_splice.c tcp_vu.c \
+ udp.c udp_flow.c udp_vu.c util.c vhost_user.c virtio.c vu_common.c
QRAP_SRCS = qrap.c
PASST_REPAIR_SRCS = passt-repair.c
SRCS = $(PASST_SRCS) $(QRAP_SRCS) $(PASST_REPAIR_SRCS)
@@ -51,9 +51,10 @@ MANPAGES = passt.1 pasta.1 qrap.1 passt-repair.1
PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h epoll_ctl.h \
flow.h fwd.h flow_table.h icmp.h icmp_flow.h inany.h iov.h ip.h \
isolation.h lineread.h log.h migrate.h ndp.h netlink.h packet.h \
- passt.h pasta.h pcap.h pif.h repair.h siphash.h tap.h tcp.h tcp_buf.h \
- tcp_conn.h tcp_internal.h tcp_splice.h tcp_vu.h udp.h udp_flow.h \
- udp_internal.h udp_vu.h util.h vhost_user.h virtio.h vu_common.h
+ passt.h pasta.h pcap.h pif.h repair.h serialise.h siphash.h tap.h tcp.h \
+ tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h tcp_vu.h udp.h \
+ udp_flow.h udp_internal.h udp_vu.h util.h vhost_user.h virtio.h \
+ vu_common.h
HEADERS = $(PASST_HEADERS) seccomp.h
C := \#include <sys/random.h>\nint main(){int a=getrandom(0, 0, 0);}
diff --git a/flow.c b/flow.c
index 4282da2..25a6f1a 100644
--- a/flow.c
+++ b/flow.c
@@ -21,6 +21,7 @@
#include "flow_table.h"
#include "repair.h"
#include "epoll_ctl.h"
+#include "serialise.h"
const char *flow_state_str[] = {
[FLOW_STATE_FREE] = "FREE",
diff --git a/migrate.c b/migrate.c
index 1e8858a..8937b85 100644
--- a/migrate.c
+++ b/migrate.c
@@ -24,6 +24,7 @@
#include "migrate.h"
#include "repair.h"
+#include "serialise.h"
/* Magic identifier for migration data */
#define MIGRATE_MAGIC 0xB1BB1D1B0BB1D1B0
diff --git a/pcap.c b/pcap.c
index 54fba5c..a026f17 100644
--- a/pcap.c
+++ b/pcap.c
@@ -34,6 +34,7 @@
#include "pcap.h"
#include "iov.h"
#include "tap.h"
+#include "serialise.h"
#define PCAP_VERSION_MINOR 4
diff --git a/serialise.c b/serialise.c
new file mode 100644
index 0000000..f162eeb
--- /dev/null
+++ b/serialise.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/* PASST - Plug A Simple Socket Transport
+ * for qemu/UNIX domain socket mode
+ *
+ * PASTA - Pack A Subtle Tap Abstraction
+ * for network namespace/tap device mode
+ *
+ * serialise.c - Serialisation of data structures over bytestreams
+ *
+ * Copyright Red Hat
+ * Author: David Gibson <david@gibson.dropbear.id.au>
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "serialise.h"
+
+/**
+ * read_all_buf() - Fill a whole buffer from a file descriptor
+ * @fd: File descriptor
+ * @buf: Pointer to base of buffer
+ * @len: Length of buffer
+ *
+ * Return: 0 on success, -1 on error (with errno set)
+ *
+ * #syscalls read
+ */
+int read_all_buf(int fd, void *buf, size_t len)
+{
+ size_t left = len;
+ char *p = buf;
+
+ while (left) {
+ ssize_t rc;
+
+ assert(left <= len);
+
+ do
+ rc = read(fd, p, left);
+ while ((rc < 0) && errno == EINTR);
+
+ if (rc < 0)
+ return -1;
+
+ if (rc == 0) {
+ errno = ENODATA;
+ return -1;
+ }
+
+ p += rc;
+ left -= rc;
+ }
+ return 0;
+}
+
+/**
+ * write_all_buf() - write all of a buffer to an fd
+ * @fd: File descriptor
+ * @buf: Pointer to base of buffer
+ * @len: Length of buffer
+ *
+ * Return: 0 on success, -1 on error (with errno set)
+ *
+ * #syscalls write
+ */
+int write_all_buf(int fd, const void *buf, size_t len)
+{
+ const char *p = buf;
+ size_t left = len;
+
+ while (left) {
+ ssize_t rc;
+
+ do
+ rc = write(fd, p, left);
+ while ((rc < 0) && errno == EINTR);
+
+ if (rc < 0)
+ return -1;
+
+ p += rc;
+ left -= rc;
+ }
+ return 0;
+}
diff --git a/serialise.h b/serialise.h
new file mode 100644
index 0000000..251c772
--- /dev/null
+++ b/serialise.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright Red Hat
+ * Author: David Gibson <david@gibson.dropbear.id.au>
+ */
+
+#ifndef SERIALISE_H
+#define SERIALISE_H
+
+#include <stddef.h>
+
+int read_all_buf(int fd, void *buf, size_t len);
+int write_all_buf(int fd, const void *buf, size_t len);
+
+#endif /* SERIALISE_H */
diff --git a/tcp.c b/tcp.c
index b145862..8ea9be8 100644
--- a/tcp.c
+++ b/tcp.c
@@ -308,6 +308,7 @@
#include "flow.h"
#include "repair.h"
#include "linux_dep.h"
+#include "serialise.h"
#include "flow_table.h"
#include "tcp_internal.h"
diff --git a/util.c b/util.c
index 22318c0..faa2c6a 100644
--- a/util.c
+++ b/util.c
@@ -37,6 +37,7 @@
#include "pcap.h"
#include "epoll_ctl.h"
#include "pasta.h"
+#include "serialise.h"
#ifdef HAS_GETRANDOM
#include <sys/random.h>
#endif
@@ -800,37 +801,6 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
}
/**
- * write_all_buf() - write all of a buffer to an fd
- * @fd: File descriptor
- * @buf: Pointer to base of buffer
- * @len: Length of buffer
- *
- * Return: 0 on success, -1 on error (with errno set)
- *
- * #syscalls write
- */
-int write_all_buf(int fd, const void *buf, size_t len)
-{
- const char *p = buf;
- size_t left = len;
-
- while (left) {
- ssize_t rc;
-
- do
- rc = write(fd, p, left);
- while ((rc < 0) && errno == EINTR);
-
- if (rc < 0)
- return -1;
-
- p += rc;
- left -= rc;
- }
- return 0;
-}
-
-/**
* write_remainder() - write the tail of an IO vector to an fd
* @fd: File descriptor
* @iov: IO vector
@@ -867,44 +837,6 @@ int write_remainder(int fd, const struct iovec *iov, size_t iovcnt, size_t skip)
}
/**
- * read_all_buf() - Fill a whole buffer from a file descriptor
- * @fd: File descriptor
- * @buf: Pointer to base of buffer
- * @len: Length of buffer
- *
- * Return: 0 on success, -1 on error (with errno set)
- *
- * #syscalls read
- */
-int read_all_buf(int fd, void *buf, size_t len)
-{
- size_t left = len;
- char *p = buf;
-
- while (left) {
- ssize_t rc;
-
- assert(left <= len);
-
- do
- rc = read(fd, p, left);
- while ((rc < 0) && errno == EINTR);
-
- if (rc < 0)
- return -1;
-
- if (rc == 0) {
- errno = ENODATA;
- return -1;
- }
-
- p += rc;
- left -= rc;
- }
- return 0;
-}
-
-/**
* read_remainder() - Read the tail of an IO vector from a file descriptor
* @fd: File descriptor
* @iov: IO vector
diff --git a/util.h b/util.h
index 2fc5cd7..cb66910 100644
--- a/util.h
+++ b/util.h
@@ -245,9 +245,7 @@ int fls(unsigned long x);
int ilog2(unsigned long x);
int write_file(const char *path, const char *buf);
intmax_t read_file_integer(const char *path, intmax_t fallback);
-int write_all_buf(int fd, const void *buf, size_t len);
int write_remainder(int fd, const struct iovec *iov, size_t iovcnt, size_t skip);
-int read_all_buf(int fd, void *buf, size_t len);
int read_remainder(int fd, const struct iovec *iov, size_t cnt, size_t skip);
void close_open_files(int argc, char **argv);
bool snprintf_check(char *str, size_t size, const char *format, ...);