[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 59/65] slirp: factor out guestfwd addition checks
From: |
Samuel Thibault |
Subject: |
[Qemu-devel] [PULL 59/65] slirp: factor out guestfwd addition checks |
Date: |
Mon, 14 Jan 2019 01:03:20 +0100 |
From: Marc-André Lureau <address@hidden>
This will allow reusing the function in a following patch.
Signed-off-by: Marc-André Lureau <address@hidden>
Signed-off-by: Samuel Thibault <address@hidden>
---
slirp/misc.c | 7 -------
slirp/slirp.c | 23 +++++++++++++++++++++--
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/slirp/misc.c b/slirp/misc.c
index a0f104be5e..eae9596a55 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -37,13 +37,6 @@ int add_exec(struct gfwd_list **ex_ptr, void *chardev, const
char *cmdline,
{
struct gfwd_list *tmp_ptr;
- /* First, check if the port is "bound" */
- for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
- if (port == tmp_ptr->ex_fport &&
- addr.s_addr == tmp_ptr->ex_addr.s_addr)
- return -1;
- }
-
tmp_ptr = *ex_ptr;
*ex_ptr = g_new0(struct gfwd_list, 1);
(*ex_ptr)->ex_fport = port;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 851462a4cd..882d28a4de 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -1046,9 +1046,11 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct
in_addr host_addr,
return 0;
}
-int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline,
- struct in_addr *guest_addr, int guest_port)
+static bool
+check_guestfwd(Slirp *slirp, struct in_addr *guest_addr, int guest_port)
{
+ struct gfwd_list *tmp_ptr;
+
if (!guest_addr->s_addr) {
guest_addr->s_addr = slirp->vnetwork_addr.s_addr |
(htonl(0x0204) & ~slirp->vnetwork_mask.s_addr);
@@ -1057,6 +1059,23 @@ int slirp_add_exec(Slirp *slirp, void *chardev, const
char *cmdline,
slirp->vnetwork_addr.s_addr ||
guest_addr->s_addr == slirp->vhost_addr.s_addr ||
guest_addr->s_addr == slirp->vnameserver_addr.s_addr) {
+ return false;
+ }
+
+ /* check if the port is "bound" */
+ for (tmp_ptr = slirp->guestfwd_list; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
+ if (guest_port == tmp_ptr->ex_fport &&
+ guest_addr->s_addr == tmp_ptr->ex_addr.s_addr)
+ return false;
+ }
+
+ return true;
+}
+
+int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline,
+ struct in_addr *guest_addr, int guest_port)
+{
+ if (!check_guestfwd(slirp, guest_addr, guest_port)) {
return -1;
}
--
2.20.1
- [Qemu-devel] [PULL 40/65] slirp: remove dead TCP_ACK_HACK code, (continued)
- [Qemu-devel] [PULL 40/65] slirp: remove dead TCP_ACK_HACK code, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 26/65] slirp: remove HAVE_SYS_IOCTL_H, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 23/65] slirp: remove unused HAVE_ARPA_INET_H, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 25/65] slirp: remove unused HAVE_SYS_SELECT_H, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 38/65] slirp: remove unused sbflush(), Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 16/65] slirp: remove PROBE_CONN dead-code, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 29/65] slirp: remove unused HAVE_INET_ATON, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 37/65] slirp: remove #if notdef dead code, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 44/65] slirp: simplify fork_exec(), Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 47/65] slirp: drop <Vista compatibility, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 59/65] slirp: factor out guestfwd addition checks,
Samuel Thibault <=
- [Qemu-devel] [PULL 60/65] slirp: add clock_get_ns() callback, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 49/65] slirp: use virtual time for packet expiration, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 53/65] slirp: no need to make DPRINTF conditional on DEBUG, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 62/65] slirp: set G_LOG_DOMAIN, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 50/65] slirp: replace a fprintf with g_critical(), Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 58/65] slirp: replace DEBUG_ARGS with DEBUG_ARG, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 63/65] slirp: call into g_debug() for DEBUG macros, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 55/65] slirp: introduce SLIRP_DEBUG environment variable, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 52/65] slirp: replace a DEBUG block with WITH_ICMP_ERROR_MSG, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 51/65] slirp: replace some fprintf() with DEBUG_MISC, Samuel Thibault, 2019/01/13