mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-27 12:38:11 +00:00
tap-vsockd: add a function to open a TAP device
Signed-off-by: David Scott <dave@recoil.org>
This commit is contained in:
parent
17ced40bf4
commit
cd441c5f29
@ -1,6 +1,6 @@
|
|||||||
FROM alpine:3.3
|
FROM alpine:3.3
|
||||||
|
|
||||||
RUN apk update && apk upgrade && apk add alpine-sdk util-linux-dev
|
RUN apk update && apk upgrade && apk add alpine-sdk util-linux-dev linux-headers
|
||||||
|
|
||||||
RUN mkdir -p /tap-vsockd
|
RUN mkdir -p /tap-vsockd
|
||||||
WORKDIR /tap-vsockd
|
WORKDIR /tap-vsockd
|
||||||
|
@ -6,10 +6,52 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <linux/if_tun.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
int verbose_flag = 0;
|
int verbose_flag = 0;
|
||||||
|
|
||||||
|
int alloc_tap(char *dev) {
|
||||||
|
int fd;
|
||||||
|
struct ifreq ifr;
|
||||||
|
const char *clonedev = "/dev/net/tun";
|
||||||
|
if ((fd = open(clonedev, O_RDWR)) == -1) {
|
||||||
|
perror("Failed to open /dev/net/tun");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
||||||
|
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
||||||
|
if (ioctl(fd, TUNSETIFF, (void*) &ifr) < 0) {
|
||||||
|
perror("TUNSETIFF failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int persist = 1;
|
||||||
|
if (ioctl(fd, TUNSETPERSIST, persist) < 0) {
|
||||||
|
perror("TUNSETPERSIST failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fprintf(stderr, "successfully created TAP device %s\n", dev);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define SVR_BUF_LEN (3 * 4096)
|
#define SVR_BUF_LEN (3 * 4096)
|
||||||
#define MAX_BUF_LEN (2 * 1024 * 1024)
|
#define MAX_BUF_LEN (2 * 1024 * 1024)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user