aboutsummaryrefslogtreecommitdiff
path: root/slirp/slirp.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-11-22 02:06:23 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-01-14 00:44:29 +0100
commit4246e8cac719317476f5652975f1a4d537b75770 (patch)
treeb850ee828b15b46458b52effb58a483043a4d873 /slirp/slirp.c
parenta857d91d8cbf76f9485641fdcbb84ef4e510a67c (diff)
slirp: factor out guestfwd addition checks
This will allow reusing the function in a following patch. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'slirp/slirp.c')
-rw-r--r--slirp/slirp.c23
1 files changed, 21 insertions, 2 deletions
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;
}