Skip to content

Commit

Permalink
Merge remote-tracking branch 'sthibault/tags/samuel-thibault' into st…
Browse files Browse the repository at this point in the history
…aging

slirp updates

# gpg: Signature made Sat 29 Apr 2017 05:45:24 PM BST
# gpg:                using RSA key 0xB0A51BF58C9179C5
# gpg: Good signature from "Samuel Thibault <samuel.thibault@aquilenet.fr>"
# gpg:                 aka "Samuel Thibault <sthibault@debian.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@gnu.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@inria.fr>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@labri.fr>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@ens-lyon.org>"
# gpg:                 aka "Samuel Thibault <samuel.thibault@u-bordeaux.fr>"
# Primary key fingerprint: 900C B024 B679 31D4 0F82  304B D017 8C76 7D06 9EE6
#      Subkey fingerprint: AEBF 7448 FAB9 453A 4552  390E B0A5 1BF5 8C91 79C5

* sthibault/tags/samuel-thibault:
  slirp: VMStatify remaining except for loop
  slirp: VMStatify socket level
  slirp: Common lhost/fhost union
  slirp: VMStatify sbuf
  slirp: VMState conversion; tcpcb
  slirp: fix pinging the virtual ipv4 DNS server
  slirp: tftp, copy sockaddr_size
  slirp/smb: Replace constant strings by glib string
  slirp: allow host port 0 for hostfwd

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefanhaRH committed May 2, 2017
2 parents 38bb54f + eb5d4f5 commit e619b14
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 257 deletions.
32 changes: 18 additions & 14 deletions net/slirp.c
Expand Up @@ -80,7 +80,7 @@ typedef struct SlirpState {
Slirp *slirp;
Notifier exit_notifier;
#ifndef _WIN32
char smb_dir[128];
gchar *smb_dir;
#endif
} SlirpState;

Expand Down Expand Up @@ -487,7 +487,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str,
goto fail_syntax;
}
host_port = strtol(buf, &end, 0);
if (*end != '\0' || host_port < 1 || host_port > 65535) {
if (*end != '\0' || host_port < 0 || host_port > 65535) {
goto fail_syntax;
}

Expand Down Expand Up @@ -558,27 +558,28 @@ int net_slirp_redir(const char *redir_str)
/* automatic user mode samba server configuration */
static void slirp_smb_cleanup(SlirpState *s)
{
char cmd[128];
int ret;

if (s->smb_dir[0] != '\0') {
snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
if (s->smb_dir) {
gchar *cmd = g_strdup_printf("rm -rf %s", s->smb_dir);
ret = system(cmd);
if (ret == -1 || !WIFEXITED(ret)) {
error_report("'%s' failed.", cmd);
} else if (WEXITSTATUS(ret)) {
error_report("'%s' failed. Error code: %d",
cmd, WEXITSTATUS(ret));
}
s->smb_dir[0] = '\0';
g_free(cmd);
g_free(s->smb_dir);
s->smb_dir = NULL;
}
}

static int slirp_smb(SlirpState* s, const char *exported_dir,
struct in_addr vserver_addr)
{
char smb_conf[128];
char smb_cmdline[128];
char *smb_conf;
char *smb_cmdline;
struct passwd *passwd;
FILE *f;

Expand All @@ -600,19 +601,19 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
return -1;
}

snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.XXXXXX");
if (!mkdtemp(s->smb_dir)) {
error_report("could not create samba server dir '%s'", s->smb_dir);
s->smb_dir[0] = 0;
s->smb_dir = g_dir_make_tmp("qemu-smb.XXXXXX", NULL);
if (!s->smb_dir) {
error_report("could not create samba server dir");
return -1;
}
snprintf(smb_conf, sizeof(smb_conf), "%s/%s", s->smb_dir, "smb.conf");
smb_conf = g_strdup_printf("%s/%s", s->smb_dir, "smb.conf");

f = fopen(smb_conf, "w");
if (!f) {
slirp_smb_cleanup(s);
error_report("could not create samba server configuration file '%s'",
smb_conf);
g_free(smb_conf);
return -1;
}
fprintf(f,
Expand Down Expand Up @@ -651,15 +652,18 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
);
fclose(f);

snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -l %s -s %s",
smb_cmdline = g_strdup_printf("%s -l %s -s %s",
CONFIG_SMBD_COMMAND, s->smb_dir, smb_conf);
g_free(smb_conf);

if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0 ||
slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 445) < 0) {
slirp_smb_cleanup(s);
g_free(smb_cmdline);
error_report("conflicting/invalid smbserver address");
return -1;
}
g_free(smb_cmdline);
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions slirp/ip_icmp.c
Expand Up @@ -152,8 +152,9 @@ icmp_input(struct mbuf *m, int hlen)
switch (icp->icmp_type) {
case ICMP_ECHO:
ip->ip_len += hlen; /* since ip_input subtracts this */
if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) {
icmp_reflect(m);
if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr ||
ip->ip_dst.s_addr == slirp->vnameserver_addr.s_addr) {
icmp_reflect(m);
} else if (slirp->restricted) {
goto freeit;
} else {
Expand Down
4 changes: 2 additions & 2 deletions slirp/sbuf.h
Expand Up @@ -12,8 +12,8 @@
#define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc)

struct sbuf {
u_int sb_cc; /* actual chars in buffer */
u_int sb_datalen; /* Length of data */
uint32_t sb_cc; /* actual chars in buffer */
uint32_t sb_datalen; /* Length of data */
char *sb_wptr; /* write pointer. points to where the next
* bytes should be written in the sbuf */
char *sb_rptr; /* read pointer. points to where the next
Expand Down

0 comments on commit e619b14

Please sign in to comment.