-
Notifications
You must be signed in to change notification settings - Fork 2
/
dbmon.c
119 lines (93 loc) · 2.66 KB
/
dbmon.c
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
/*
* dvpn, a multipoint vpn implementation
* Copyright (C) 2016 Lennert Buytenhek
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version
* 2.1 as published by the Free Software Foundation.
*
* This library 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 Lesser General Public License version 2.1 for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License version 2.1 along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <gnutls/abstract.h>
#include <gnutls/x509.h>
#include <iv.h>
#include <iv_signal.h>
#include <string.h>
#include "conf.h"
#include "dgp_connect.h"
#include "loc_rib.h"
#include "loc_rib_print.h"
#include "rib_listener_debug.h"
#include "x509.h"
static uint8_t myid[NODE_ID_LEN];
static struct loc_rib loc_rib;
static struct rib_listener_debug debug_listener;
static struct dgp_connect dc;
static struct iv_signal sigint;
static struct iv_signal sigusr1;
static void got_sigint(void *_dummy)
{
fprintf(stderr, "SIGINT received, shutting down\n");
loc_rib_listener_unregister(&loc_rib, &debug_listener.rl);
dgp_connect_stop(&dc);
iv_signal_unregister(&sigint);
iv_signal_unregister(&sigusr1);
}
static void got_sigusr1(void *_dummy)
{
loc_rib_print(stderr, &loc_rib);
}
int dbmon(const char *config)
{
struct conf *conf;
gnutls_pubkey_t pubkey;
conf = parse_config(config);
if (conf == NULL)
return 1;
gnutls_global_init();
if (read_pubkey(&pubkey, conf->public_key) < 0)
return 1;
free_config(conf);
get_pubkey_id(myid, pubkey);
gnutls_pubkey_deinit(pubkey);
gnutls_global_deinit();
iv_init();
loc_rib.myid = NULL;
loc_rib_init(&loc_rib);
debug_listener.name = NULL;
debug_listener.name_hints = &loc_rib;
rib_listener_debug_init(&debug_listener);
loc_rib_listener_register(&loc_rib, &debug_listener.rl);
dc.myid = NULL;
dc.remoteid = myid;
dc.ifindex = 0;
dc.loc_rib = &loc_rib;
dgp_connect_start(&dc);
IV_SIGNAL_INIT(&sigint);
sigint.signum = SIGINT;
sigint.flags = 0;
sigint.cookie = NULL;
sigint.handler = got_sigint;
iv_signal_register(&sigint);
IV_SIGNAL_INIT(&sigusr1);
sigusr1.signum = SIGUSR1;
sigusr1.flags = 0;
sigusr1.cookie = NULL;
sigusr1.handler = got_sigusr1;
iv_signal_register(&sigusr1);
iv_main();
loc_rib_deinit(&loc_rib);
rib_listener_debug_deinit(&debug_listener);
iv_deinit();
return 0;
}