-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvty_server.c
168 lines (133 loc) · 2.85 KB
/
vty_server.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
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
#include <vty_comm.h>
#include <vty.h>
#include <thread.h>
#include <command.h>
#include <memory.h>
#include <log.h>
#define BGP_VTY_PORT 2222
/* Process ID saved for use by init system */
static const char *pid_file = PATH_BGPD_PID;
/* Manually specified configuration file name. */
char *config_file = NULL;
/* VTY port number and address. */
int vty_port = BGP_VTY_PORT;
char *vty_addr = NULL;
/* privileges */
static zebra_capabilities_t _caps_p [] =
{
ZCAP_BIND,
ZCAP_NET_RAW,
ZCAP_NET_ADMIN,
};
struct zebra_privs_t vtyserver_privs = {
#if defined(QUAGGA_USER)
.user = QUAGGA_USER,
#endif
#if defined QUAGGA_GROUP
.group = QUAGGA_GROUP,
#endif
#ifdef VTY_GROUP
.vty_group = VTY_GROUP,
#endif
.caps_p = _caps_p,
.cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
.cap_num_i = 0
};
void
reload ()
{
zlog_debug ("Reload");
/* FIXME: Clean up func call here */
vty_reset ();
(void) isisd_privs.change (ZPRIVS_RAISE);
execve (_progpath, _argv, _envp);
zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
safe_strerror (errno));
}
static void
terminate (int i)
{
exit (i);
}
/* SIGHUP handler. */
static void
sighup (void)
{
zlog_info ("SIGHUP received");
/* Reload of config file. */
;
}
/* SIGINT handler. */
static void
sigint (void)
{
zlog_notice ("Terminating on signal");
/*
* if (!retain_mode)
* rib_close ();
*#ifdef HAVE_IRDP
* irdp_finish();
*#endif
*/
exit (0);
}
/* SIGUSR1 handler. */
static void
sigusr1 (void)
{
zlog_rotate (NULL);
}
struct quagga_signal_t zebra_signals[] =
{
{
.signal = SIGHUP,
.handler = &sighup,
},
{
.signal = SIGUSR1,
.handler = &sigusr1,
},
{
.signal = SIGINT,
.handler = &sigint,
},
{
.signal = SIGTERM,
.handler = &sigint,
},
};
static void vty_do_exit(void)
{
printf ("\nend.\n");
exit (0);
}
int
main(int argc, char **argv)
{
/* thread master */
master = thread_master_create ();
/* random seed from time */
srandom (time (NULL));
zlog_default = openzlog ("common-cli", ZLOG_NONE,
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG);
/*
* initializations
*/
/*zprivs_init (&vtyserver_privs);*/
/* Vty related initialize. */
signal_init (master, array_size(zebra_signals), zebra_signals);
cmd_init(1);
vty_init(master);
memory_init();
/* cli related initialization. */
cli_init ();
vty_read_config(config_file, config_default);
/* Process ID file creation. */
pid_output (pid_file);
vty_serv_sock(vty_addr, vty_port ,BGP_VTYSH_PATH);
vty_stdio (vty_do_exit);
thread_main(master);
}