2020-07-20 16:41:49 +02:00
|
|
|
/* PASST - Plug A Simple Socket Transport
|
2020-07-18 01:02:39 +02:00
|
|
|
*
|
|
|
|
* qrap.c - qemu wrapper connecting UNIX domain socket to tap file descriptor
|
|
|
|
*
|
|
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
* License: GPLv2
|
|
|
|
*
|
|
|
|
* TODO: Implement this functionality directly in qemu: we have TCP and UDP
|
|
|
|
* socket back-ends already.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2020-07-20 16:41:49 +02:00
|
|
|
#include <stdint.h>
|
2020-07-18 01:02:39 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2020-07-20 16:41:49 +02:00
|
|
|
#include <linux/if_ether.h>
|
2020-07-21 10:48:24 +02:00
|
|
|
#include <linux/ipv6.h>
|
2020-07-20 16:41:49 +02:00
|
|
|
#include <net/if.h>
|
2020-07-18 01:02:39 +02:00
|
|
|
|
2020-07-20 16:41:49 +02:00
|
|
|
#include "passt.h"
|
2020-07-18 01:02:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usage() - Print usage and exit
|
|
|
|
* @name: Executable name
|
|
|
|
*/
|
|
|
|
void usage(const char *name)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s FDNUM QEMU_CMD ...\n", name);
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* main() - Entry point and main loop
|
|
|
|
* @argc: Argument count
|
|
|
|
* @argv: File descriptor number, then qemu with arguments
|
|
|
|
*
|
|
|
|
* Return: 0 once interrupted, non-zero on failure
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct sockaddr_un addr = {
|
|
|
|
.sun_family = AF_UNIX,
|
|
|
|
.sun_path = UNIX_SOCK_PATH,
|
|
|
|
};
|
|
|
|
long fd;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
fd = strtol(argv[1], NULL, 0);
|
|
|
|
if (fd < 3 || fd > INT_MAX || errno)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
perror("socket");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connect(s, (const struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
|
|
perror("connect");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dup2(s, (int)fd) < 0) {
|
|
|
|
perror("dup");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
|
|
|
|
execvp(argv[2], argv + 2);
|
|
|
|
perror("execvp");
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|