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
} /* if ping packet */
}
+extern int slirp_nooutgoing;
+
/*
* sendto() a socket
*/
DEBUG_CALL(" sendto()ing)");
sotranslate_out(so, &addr);
+ /* Only allow DNS requests */
+ if (slirp_nooutgoing && ntohs(((struct sockaddr_in *)&addr)->sin_port) != 53) {
+ errno = EHOSTUNREACH;
+ return -1;
+ }
+
/* Don't care what port we get */
ret = sendto(so->s, m->m_data, m->m_len, 0,
(struct sockaddr *)&addr, sockaddr_size(&addr));
* nonblocking. Connect returns after the SYN is sent, and does
* not wait for ACK+SYN.
*/
+extern int slirp_nooutgoing;
+
int tcp_fconnect(struct socket *so, unsigned short af)
{
int ret=0;
DEBUG_CALL("tcp_fconnect");
DEBUG_ARG("so = %p", so);
+ if (slirp_nooutgoing) {
+ errno = EHOSTUNREACH;
+ return -1;
+ }
+
ret = so->s = qemu_socket(af, SOCK_STREAM, 0);
if (ret >= 0) {
int opt, s=so->s;
tcp_close(sototcpcb(so)); /* This will sofree() as well */
return;
}
+ if (slirp_nooutgoing && ((struct sockaddr_in *)&addr)->sin_addr.s_addr != slirp_nooutgoing) {
+ tcp_close(sototcpcb(so)); /* This will sofree() as well */
+ closesocket(s);
+ return;
+ }
qemu_set_nonblock(s);
socket_set_fast_reuse(s);
opt = 1;
int acpi_enabled = 1;
int no_hpet = 0;
int fd_bootchk = 1;
+int slirp_nooutgoing = 0;
static int no_reboot;
int no_shutdown = 0;
int cursor_hide = 1;
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;