2017-04-12 21:10:15 +02:00
|
|
|
From 789139fbc94dee4839b29c511816c6e3398407b5 Mon Sep 17 00:00:00 2001
|
2013-02-10 19:32:29 +01:00
|
|
|
From: =?UTF-8?q?Andreas=20F=C3=A4rber?= <afaerber@suse.de>
|
2012-09-05 13:51:25 +02:00
|
|
|
Date: Wed, 29 Aug 2012 18:42:56 +0200
|
|
|
|
Subject: [PATCH] slirp: -nooutgoing
|
|
|
|
|
|
|
|
TBD (from SUSE Studio team)
|
|
|
|
---
|
2014-01-17 23:04:30 +01:00
|
|
|
qemu-options.hx | 10 ++++++++++
|
|
|
|
slirp/socket.c | 8 ++++++++
|
2016-04-05 15:18:15 +02:00
|
|
|
slirp/tcp_subr.c | 12 ++++++++++++
|
2014-01-17 23:04:30 +01:00
|
|
|
vl.c | 9 +++++++++
|
2016-04-05 15:18:15 +02:00
|
|
|
4 files changed, 39 insertions(+)
|
2012-09-05 13:51:25 +02:00
|
|
|
|
|
|
|
diff --git a/qemu-options.hx b/qemu-options.hx
|
2017-04-12 21:10:15 +02:00
|
|
|
index 99af8edf5f..4712277d7c 100644
|
2012-09-05 13:51:25 +02:00
|
|
|
--- a/qemu-options.hx
|
|
|
|
+++ b/qemu-options.hx
|
2017-03-29 06:22:10 +02:00
|
|
|
@@ -3215,6 +3215,16 @@ Store the QEMU process PID in @var{file}. It is useful if you launch QEMU
|
2012-09-05 13:51:25 +02:00
|
|
|
from a script.
|
|
|
|
ETEXI
|
|
|
|
|
|
|
|
+DEF("nooutgoing", HAS_ARG, QEMU_OPTION_nooutgoing, \
|
|
|
|
+ "-nooutgoing <IP>\n" \
|
|
|
|
+ " incoming traffic only from IP, no outgoing\n", \
|
|
|
|
+ QEMU_ARCH_ALL)
|
|
|
|
+STEXI
|
|
|
|
+@item -nooutgoing
|
|
|
|
+Forbid userspace networking to make outgoing connections. Only accept incoming
|
|
|
|
+connections from ip address IP.
|
|
|
|
+ETEXI
|
|
|
|
+
|
|
|
|
DEF("singlestep", 0, QEMU_OPTION_singlestep, \
|
|
|
|
"-singlestep always run in singlestep mode\n", QEMU_ARCH_ALL)
|
|
|
|
STEXI
|
|
|
|
diff --git a/slirp/socket.c b/slirp/socket.c
|
2017-04-12 21:10:15 +02:00
|
|
|
index 86927722e1..5c89064e15 100644
|
2012-09-05 13:51:25 +02:00
|
|
|
--- a/slirp/socket.c
|
|
|
|
+++ b/slirp/socket.c
|
2017-03-15 20:38:55 +01:00
|
|
|
@@ -625,6 +625,8 @@ sorecvfrom(struct socket *so)
|
2012-09-05 13:51:25 +02:00
|
|
|
} /* if ping packet */
|
|
|
|
}
|
|
|
|
|
|
|
|
+extern int slirp_nooutgoing;
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* sendto() a socket
|
|
|
|
*/
|
2017-03-15 20:38:55 +01:00
|
|
|
@@ -642,6 +644,12 @@ sosendto(struct socket *so, struct mbuf *m)
|
2016-04-05 15:18:15 +02:00
|
|
|
DEBUG_CALL(" sendto()ing)");
|
|
|
|
sotranslate_out(so, &addr);
|
2012-09-05 13:51:25 +02:00
|
|
|
|
|
|
|
+ /* Only allow DNS requests */
|
2016-04-05 15:18:15 +02:00
|
|
|
+ if (slirp_nooutgoing && ntohs(((struct sockaddr_in *)&addr)->sin_port) != 53) {
|
2012-09-05 13:51:25 +02:00
|
|
|
+ errno = EHOSTUNREACH;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/* Don't care what port we get */
|
|
|
|
ret = sendto(so->s, m->m_data, m->m_len, 0,
|
2016-05-31 23:05:30 +02:00
|
|
|
(struct sockaddr *)&addr, sockaddr_size(&addr));
|
2012-09-05 13:51:25 +02:00
|
|
|
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
|
2017-04-12 21:10:15 +02:00
|
|
|
index ed16e1807f..b2c7a8cba0 100644
|
2012-09-05 13:51:25 +02:00
|
|
|
--- a/slirp/tcp_subr.c
|
|
|
|
+++ b/slirp/tcp_subr.c
|
2016-04-22 20:44:30 +02:00
|
|
|
@@ -391,6 +391,8 @@ tcp_sockclosed(struct tcpcb *tp)
|
2012-09-05 13:51:25 +02:00
|
|
|
* nonblocking. Connect returns after the SYN is sent, and does
|
|
|
|
* not wait for ACK+SYN.
|
|
|
|
*/
|
|
|
|
+extern int slirp_nooutgoing;
|
|
|
|
+
|
2016-04-05 15:18:15 +02:00
|
|
|
int tcp_fconnect(struct socket *so, unsigned short af)
|
2012-09-05 13:51:25 +02:00
|
|
|
{
|
2016-04-05 15:18:15 +02:00
|
|
|
int ret=0;
|
2016-04-22 20:44:30 +02:00
|
|
|
@@ -398,6 +400,11 @@ int tcp_fconnect(struct socket *so, unsigned short af)
|
2012-09-05 13:51:25 +02:00
|
|
|
DEBUG_CALL("tcp_fconnect");
|
2016-01-19 19:31:32 +01:00
|
|
|
DEBUG_ARG("so = %p", so);
|
2012-09-05 13:51:25 +02:00
|
|
|
|
|
|
|
+ if (slirp_nooutgoing) {
|
|
|
|
+ errno = EHOSTUNREACH;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
2016-04-05 15:18:15 +02:00
|
|
|
ret = so->s = qemu_socket(af, SOCK_STREAM, 0);
|
|
|
|
if (ret >= 0) {
|
2012-09-05 13:51:25 +02:00
|
|
|
int opt, s=so->s;
|
2016-04-22 20:44:30 +02:00
|
|
|
@@ -478,6 +485,11 @@ void tcp_connect(struct socket *inso)
|
2013-05-14 22:46:08 +02:00
|
|
|
tcp_close(sototcpcb(so)); /* This will sofree() as well */
|
|
|
|
return;
|
|
|
|
}
|
2016-04-05 15:18:15 +02:00
|
|
|
+ if (slirp_nooutgoing && ((struct sockaddr_in *)&addr)->sin_addr.s_addr != slirp_nooutgoing) {
|
2013-05-14 22:46:08 +02:00
|
|
|
+ tcp_close(sototcpcb(so)); /* This will sofree() as well */
|
2016-04-05 15:18:15 +02:00
|
|
|
+ closesocket(s);
|
2013-05-14 22:46:08 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
qemu_set_nonblock(s);
|
2013-12-08 06:19:09 +01:00
|
|
|
socket_set_fast_reuse(s);
|
2013-05-14 22:46:08 +02:00
|
|
|
opt = 1;
|
2012-09-05 13:51:25 +02:00
|
|
|
diff --git a/vl.c b/vl.c
|
2017-04-12 21:10:15 +02:00
|
|
|
index 0b4ed5241c..e0f2ec86a9 100644
|
2012-09-05 13:51:25 +02:00
|
|
|
--- a/vl.c
|
|
|
|
+++ b/vl.c
|
2017-03-29 06:22:10 +02:00
|
|
|
@@ -168,6 +168,7 @@ int smp_threads = 1;
|
2012-09-05 13:51:25 +02:00
|
|
|
int acpi_enabled = 1;
|
|
|
|
int no_hpet = 0;
|
|
|
|
int fd_bootchk = 1;
|
|
|
|
+int slirp_nooutgoing = 0;
|
2012-11-27 21:42:06 +01:00
|
|
|
static int no_reboot;
|
2012-09-05 13:51:25 +02:00
|
|
|
int no_shutdown = 0;
|
|
|
|
int cursor_hide = 1;
|
2017-03-29 06:22:10 +02:00
|
|
|
@@ -3405,6 +3406,14 @@ int main(int argc, char **argv, char **envp)
|
2012-09-05 13:51:25 +02:00
|
|
|
case QEMU_OPTION_singlestep:
|
|
|
|
singlestep = 1;
|
|
|
|
break;
|
|
|
|
+ case QEMU_OPTION_nooutgoing:
|
|
|
|
+ slirp_nooutgoing = inet_addr(optarg);
|
|
|
|
+ if (slirp_nooutgoing == INADDR_NONE) {
|
|
|
|
+ printf("Invalid address: %s.\nOnly addresses of the format "
|
|
|
|
+ "xxx.xxx.xxx.xxx are supported.\n", optarg);
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
case QEMU_OPTION_S:
|
|
|
|
autostart = 0;
|
|
|
|
break;
|