summaryrefslogtreecommitdiff
path: root/src/irmd/reg/reg.h
blob: e0c64fed7b04e20448d7d794fe18d31cbb0dad11 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Ouroboros - Copyright (C) 2016 - 2026
 *
 * The IPC Resource Manager - Registry
 *
 *    Dimitri Staessens <dimitri@ouroboros.rocks>
 *    Sander Vrijders   <sander@ouroboros.rocks>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., http://www.fsf.org/about/contact/.
 */

#ifndef OUROBOROS_IRMD_REG_H
#define OUROBOROS_IRMD_REG_H

#include <ouroboros/flow.h>
#include <ouroboros/ipcp.h>
#include <ouroboros/name.h>
#include <ouroboros/proc.h>
#include <ouroboros/protobuf.h>
#include <ouroboros/time.h>
#include <ouroboros/utils.h>

#include "pool.h"

int   reg_init(void);

void  reg_clear(void);

void  reg_fini(void);

int   reg_create_flow(struct flow_info * info);

int   reg_destroy_flow(int flow_id);

bool  reg_has_flow(int flow_id);

int   reg_create_proc(const struct proc_info * info);

/* Use this for all processes, including ipcps */
int   reg_destroy_proc(pid_t pid);

bool  reg_has_proc(pid_t pid);

bool  reg_is_proc_privileged(pid_t pid);

int   reg_prepare_pool(uid_t uid,
                       gid_t gid);

uid_t reg_get_proc_uid(pid_t pid);

void  reg_kill_all_proc(int signal);

pid_t reg_get_dead_proc(void);

int   reg_create_spawned(pid_t pid);

bool  reg_has_spawned(pid_t pid);

void  reg_kill_all_spawned(int signal);

int   reg_first_spawned(void);

int   reg_bind_proc(const char * name,
                    pid_t        proc);

int   reg_unbind_proc(const char * name,
                      pid_t        proc);

int   reg_create_ipcp(const struct ipcp_info * info);

bool  reg_has_ipcp(pid_t pid);

int   reg_set_layer_for_ipcp(struct ipcp_info *        info,
                             const struct layer_info * layer);

int   reg_get_ipcp(struct ipcp_info *  info,
                   struct layer_info * layer);

int   reg_get_ipcp_by_layer(struct ipcp_info *  info,
                            struct layer_info * layer);

/* TODO don't rely on protobuf here */
int   reg_list_ipcps(ipcp_list_msg_t *** msg);

int   reg_create_name(const struct name_info * info);

int   reg_destroy_name(const char * name);

bool  reg_has_name(const char * name);

int   reg_get_name_info(const char *       name,
                        struct name_info * info);

int   reg_get_name_for_hash(char *          buf,
                            enum hash_algo  algo,
                            const uint8_t * hash);

int   reg_get_name_for_flow_id(char * buf,
                               int    flow_id);

/* TODO don't rely on protobuf here */
int   reg_list_names(name_info_msg_t *** names);

int   reg_create_prog(const struct prog_info * info);

int   reg_destroy_prog(const char * name);

bool  reg_has_prog(const char * name);

int   reg_get_exec(const char * name,
                   char ***     exec);

int   reg_bind_prog(const char * name,
                    char **      exec,
                    uint8_t      flags);

int   reg_unbind_prog(const char * name,
                      const char * prog);

int   reg_prepare_flow_alloc(struct flow_info * info);

int   reg_wait_flow_allocated(struct flow_info *      info,
                              buffer_t *              pbuf,
                              const struct timespec * abstime);

int   reg_respond_alloc(struct flow_info * info,
                        buffer_t *         pbuf,
                        int                response);

int   reg_prepare_flow_accept(struct flow_info * info);

int   reg_wait_flow_accepted(struct flow_info *      info,
                             buffer_t *              pbuf,
                             const struct timespec * abstime);

int   reg_wait_flow_accepting(const char *            name,
                              const struct timespec * abstime);

int   reg_respond_accept(struct flow_info * info,
                         buffer_t *         pbuf);

int   reg_prepare_flow_direct(struct flow_info * info,
                              buffer_t *         pbuf,
                              uid_t              alloc_uid);

int   reg_respond_flow_direct(int              flow_id,
                              buffer_t *       pbuf);

int   reg_wait_flow_direct(int                      flow_id,
                           buffer_t *               pbuf,
                           const struct timespec *  abstime);

bool  reg_flow_is_direct(int flow_id);

/* Per-flow snapshot for the re-key timer */
struct rekey_info {
        int     flow_id;
        pid_t   n_pid;
        pid_t   n_1_pid;
        char    name[NAME_SIZE + 1];
        uint8_t epoch;
};

void  reg_flow_set_rekey(int  flow_id,
                         bool initiator);

int   reg_flow_get_epoch(int flow_id);

bool  reg_flow_rekey_pending(int flow_id);

pid_t reg_flow_get_n_1_pid(int flow_id);

int   reg_flow_snapshot_rekey_due(struct rekey_info * snap,
                                  int                 max);

void  reg_flow_clear_in_flight(int flow_id);

int   reg_flow_store_pending(int             flow_id,
                             const uint8_t * seed,
                             uint8_t         epoch);

bool  reg_flow_take_pending(int       flow_id,
                            uint8_t * seed,
                            uint8_t * epoch);

void  reg_notify_flow(int flow_id,
                      int event);

void  reg_dealloc_flow(struct flow_info * info);

void  reg_dealloc_flow_resp(struct flow_info * info);

int   reg_wait_proc(pid_t                   pid,
                    const struct timespec * abstime);

int   reg_wait_ipcp_boot(struct ipcp_info *      ipcp,
                         const struct timespec * abstime);

int   reg_respond_ipcp(const struct ipcp_info * info);

#endif /* OUROBOROS_IRMD_REG_H */