Commit 9615c3b9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

tun: Initial skeleton for tun support

There will be two entities handled:

1. tun file -- an opened char device with misc major and tun minor
   that can be attached to item #2

2. tun netdevice -- another type of links
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 92cc20c0
...@@ -5,6 +5,7 @@ obj-y += crtools.o ...@@ -5,6 +5,7 @@ obj-y += crtools.o
obj-y += image.o obj-y += image.o
obj-y += image-desc.o obj-y += image-desc.o
obj-y += net.o obj-y += net.o
obj-y += tun.o
obj-y += proc_parse.o obj-y += proc_parse.o
obj-y += cr-dump.o obj-y += cr-dump.o
obj-y += cr-show.o obj-y += cr-show.o
......
...@@ -74,6 +74,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { ...@@ -74,6 +74,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
FD_ENTRY(SHM_PAGES_OLD, "pages-shmem-%ld", NULL), FD_ENTRY(SHM_PAGES_OLD, "pages-shmem-%ld", NULL),
FD_ENTRY(SIGNAL, "signal-s-%d", show_siginfo), /* shared signals */ FD_ENTRY(SIGNAL, "signal-s-%d", show_siginfo), /* shared signals */
FD_ENTRY(PSIGNAL, "signal-p-%d", show_siginfo), /* private signals */ FD_ENTRY(PSIGNAL, "signal-p-%d", show_siginfo), /* private signals */
FD_ENTRY(TUNFILE, "tunfile", show_tunfile),
[CR_FD_STATS] = { [CR_FD_STATS] = {
.fmt = "stats-%s", .fmt = "stats-%s",
......
...@@ -51,5 +51,6 @@ extern void show_tcp_stream(int fd); ...@@ -51,5 +51,6 @@ extern void show_tcp_stream(int fd);
extern void show_mountpoints(int fd); extern void show_mountpoints(int fd);
extern void show_netdevices(int fd); extern void show_netdevices(int fd);
extern void show_stats(int fd); extern void show_stats(int fd);
extern void show_tunfile(int fd);
#endif /* __CR_SHOW_H__ */ #endif /* __CR_SHOW_H__ */
...@@ -72,6 +72,7 @@ enum { ...@@ -72,6 +72,7 @@ enum {
CR_FD_INOTIFY_WD, CR_FD_INOTIFY_WD,
CR_FD_FANOTIFY, CR_FD_FANOTIFY,
CR_FD_FANOTIFY_MARK, CR_FD_FANOTIFY_MARK,
CR_FD_TUNFILE,
_CR_FD_GLOB_TO, _CR_FD_GLOB_TO,
CR_FD_TMPFS, CR_FD_TMPFS,
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
#define PSIGNAL_MAGIC SIGNAL_MAGIC #define PSIGNAL_MAGIC SIGNAL_MAGIC
#define NETLINKSK_MAGIC 0x58005614 /* Perm */ #define NETLINKSK_MAGIC 0x58005614 /* Perm */
#define NS_FILES_MAGIC 0x61394011 /* Nyandoma */ #define NS_FILES_MAGIC 0x61394011 /* Nyandoma */
#define TUNFILE_MAGIC 0x57143751 /* Kalyazin */
#define IFADDR_MAGIC RAW_IMAGE_MAGIC #define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define ROUTE_MAGIC RAW_IMAGE_MAGIC #define ROUTE_MAGIC RAW_IMAGE_MAGIC
......
...@@ -54,6 +54,7 @@ enum { ...@@ -54,6 +54,7 @@ enum {
PB_PAGEMAP_HEAD, PB_PAGEMAP_HEAD,
PB_PAGEMAP, PB_PAGEMAP,
PB_SIGINFO, PB_SIGINFO,
PB_TUNFILE,
PB_MAX PB_MAX
}; };
......
#ifndef __CR_TUN_H__
#define __CR_TUN_H__
#ifndef TUN_MINOR
#define TUN_MINOR 200
#endif
#endif
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "protobuf/siginfo.pb-c.h" #include "protobuf/siginfo.pb-c.h"
#include "protobuf/sk-netlink.pb-c.h" #include "protobuf/sk-netlink.pb-c.h"
#include "protobuf/vma.pb-c.h" #include "protobuf/vma.pb-c.h"
#include "protobuf/tun.pb-c.h"
struct cr_pb_message_desc cr_pb_descs[PB_MAX]; struct cr_pb_message_desc cr_pb_descs[PB_MAX];
...@@ -137,4 +138,6 @@ void cr_pb_init(void) ...@@ -137,4 +138,6 @@ void cr_pb_init(void)
CR_PB_DESC(PAGEMAP, Pagemap, pagemap); CR_PB_DESC(PAGEMAP, Pagemap, pagemap);
CR_PB_DESC(SIGINFO, Siginfo, siginfo); CR_PB_DESC(SIGINFO, Siginfo, siginfo);
CR_PB_DESC(NETLINKSK, NetlinkSk, netlink_sk); CR_PB_DESC(NETLINKSK, NetlinkSk, netlink_sk);
CR_PB_DESC(TUNFILE, Tunfile, tunfile);
} }
...@@ -39,6 +39,7 @@ proto-obj-y += mm.o ...@@ -39,6 +39,7 @@ proto-obj-y += mm.o
proto-obj-y += sk-opts.o proto-obj-y += sk-opts.o
proto-obj-y += sk-unix.o proto-obj-y += sk-unix.o
proto-obj-y += sk-inet.o proto-obj-y += sk-inet.o
proto-obj-y += tun.o
proto-obj-y += sk-netlink.o proto-obj-y += sk-netlink.o
proto-obj-y += packet-sock.o proto-obj-y += packet-sock.o
proto-obj-y += ipc-var.o proto-obj-y += ipc-var.o
......
...@@ -14,6 +14,7 @@ enum fd_types { ...@@ -14,6 +14,7 @@ enum fd_types {
FANOTIFY = 12; FANOTIFY = 12;
NETLINKSK = 13; NETLINKSK = 13;
NS = 14; NS = 14;
TUN = 15;
} }
message fdinfo_entry { message fdinfo_entry {
......
import "tun.proto";
enum nd_type { enum nd_type {
LOOPBACK = 1; LOOPBACK = 1;
VETH = 2; VETH = 2;
TUN = 3;
} }
message net_device_entry { message net_device_entry {
...@@ -9,4 +12,6 @@ message net_device_entry { ...@@ -9,4 +12,6 @@ message net_device_entry {
required uint32 mtu = 3; required uint32 mtu = 3;
required uint32 flags = 4; required uint32 flags = 4;
required string name = 5; required string name = 5;
optional tun_link_entry tun = 6;
} }
import "fown.proto";
message tunfile_entry {
required uint32 id = 1;
optional string netdev = 2;
optional bool detached = 3;
};
message tun_link_entry {
required uint32 flags = 1;
required int32 owner = 2;
required int32 group = 3;
required uint32 vnethdr = 4;
required uint32 sndbuf = 5;
};
#include <unistd.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include "crtools.h"
#include "protobuf.h"
#include "cr-show.h"
#include "files.h"
#include "files-reg.h"
#include "tun.h"
#include "net.h"
#include "protobuf/tun.pb-c.h"
#ifndef IFF_PERSIST
#define IFF_PERSIST 0x0800
#endif
#ifndef IFF_NOFILTER
#define IFF_NOFILTER 0x1000
#endif
#ifndef TUNSETQUEUE
#define TUNSETQUEUE _IOW('T', 217, int)
#define IFF_ATTACH_QUEUE 0x0200
#define IFF_DETACH_QUEUE 0x0400
#endif
/*
* Absense of the 1st ioctl means we cannot restore tun link. But
* since the 2nd one appeared at the same time, we'll "check" this
* by trying to dump filter and abort dump if it's not there.
*/
#ifndef TUNSETIFINDEX
#define TUNSETIFINDEX _IOW('T', 218, unsigned int)
#endif
#ifndef TUNGETFILTER
#define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
#endif
#define TUN_DEV_GEN_PATH "/dev/net/tun"
void show_tunfile(int fd)
{
pb_show_plain(fd, PB_TUNFILE);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment