-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunns.h
91 lines (77 loc) · 1.84 KB
/
runns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* vim:et:sw=2:
*
* Copyright (c) 2019-2025 Nikita (sh1r4s3) Ermakov <[email protected]>
* SPDX-License-Identifier: MIT
*/
#ifndef RUNNS_H
#define RUNNS_H
#define __USE_GNU
#define _XOPEN_SOURCE
#define __USE_XOPEN_EXTENDED
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <termios.h>
#include <netinet/in.h>
#include <fcntl.h>
#define STR_TOKEN(x) #x
// Linux socket default file.
#define DEFAULT_RUNNS_SOCKET "/var/run/runns/runns.socket"
#define RUNNS_MAXLEN sizeof(((struct sockaddr_un *)0)->sun_path)
// Maximum number of childs
#define MAX_CHILDS 1024
// librunns
#define ENV_SEPARATOR ':'
// Definitions of the flag bits:
// RUNNS_STOP -- wait for childs to exit and then exit.
// RUNNS_LIST -- list childs runned by runns.
// RUNNS_NPTS -- create control terminal for forked process.
#define RUNNS_STOP (int)1 << 1
#define RUNNS_LIST (int)1 << 2
#define RUNNS_NPTMS (int)1 << 3
typedef enum {
OP_MODE_UNK = 0,
OP_MODE_NETNS,
OP_MODE_FWD_PORT
} OP_MODES;
// common header for server and client
struct runns_header {
size_t prog_sz;
size_t netns_sz;
size_t resolv_sz;
size_t env_sz;
size_t args_sz;
unsigned int flag;
struct termios tmode;
OP_MODES op_mode;
};
struct runns_child {
uid_t uid;
pid_t pid;
};
// Structures for librunns
typedef enum {
L4_PROTOCOL_UNK = 0,
L4_PROTOCOL_TCP,
L4_PROTOCOL_UDP
} L4_PROTOCOLS;
struct netns {
unsigned char ip[sizeof(struct in6_addr)];
int fd; // File descriptor to clone a netns from
sa_family_t family; // AF_INET or AF_INET6
L4_PROTOCOLS proto; // TCP, UDP or unknown
in_port_t port;
};
struct netns_list {
struct netns node;
struct netns_list *pnext;
};
#endif