forked from iqiyi/dpvs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfgfile.c
181 lines (152 loc) · 4.24 KB
/
cfgfile.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
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2017 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
*/
#include <unistd.h>
#include <signal.h>
#include "dpdk.h"
#include "common.h"
#include "parser/parser.h"
#include "cfgfile.h"
#include "global_conf.h"
#include "timer.h"
#include "neigh.h"
#include "ipv4.h"
#include "ipv4_frag.h"
#include "ipv6.h"
#include "ctrl.h"
#include "sa_pool.h"
#include "ipvs/conn.h"
#include "ipvs/proto_tcp.h"
#include "ipvs/proto_udp.h"
#include "ipvs/synproxy.h"
typedef void (*sighandler_t)(int);
static void keyword_value_init(void)
{
/* init keywords value here */
netif_keyword_value_init();
timer_keyword_value_init();
neigh_keyword_value_init();
ipv4_keyword_value_init();
ip4_frag_keyword_value_init();
control_keyword_value_init();
ipvs_conn_keyword_value_init();
udp_keyword_value_init();
tcp_keyword_value_init();
synproxy_keyword_value_init();
ipv6_keyword_value_init();
}
static vector_t install_keywords(void)
{
/* install configuration keywords here */
install_global_keywords();
install_netif_keywords();
install_timer_keywords();
install_neighbor_keywords();
install_sa_pool_keywords();
install_ipv4_keywords();
install_ip4_frag_keywords();
install_control_keywords();
install_keyword_root("ipvs_defs", NULL);
install_keyword("conn", NULL, KW_TYPE_NORMAL);
install_ipvs_conn_keywords();
install_keyword("tcp", NULL, KW_TYPE_NORMAL);
install_sublevel();
install_proto_tcp_keywords();
install_synproxy_keywords();
install_sublevel_end();
install_keyword("udp", NULL, KW_TYPE_NORMAL);
install_sublevel();
install_proto_udp_keywords();
install_sublevel_end();
install_ipv6_keywords();
return g_keywords;
}
static inline void load_conf_file(char *cfg_file)
{
keyword_value_init();
init_data(cfg_file, install_keywords);
}
static inline void sighup(void)
{
SET_RELOAD;
}
void try_reload(void)
{
if (unlikely(RELOAD_STATUS)) {
UNSET_RELOAD;
/* using default configuration file */
load_conf_file(NULL);
}
}
static void sig_callback(int sig)
{
switch(sig) {
case SIGHUP:
RTE_LOG(INFO, CFG_FILE, "Got signal SIGHUP.\n");
sighup();
break;
case SIGINT:
RTE_LOG(INFO, CFG_FILE, "Got signal SIGINT.\n");
break;
case SIGQUIT:
RTE_LOG(INFO, CFG_FILE, "Got signal SIGQUIT.\n");
break;
case SIGTERM:
RTE_LOG(INFO, CFG_FILE, "Got signal SIGTERM.\n");
break;
default:
RTE_LOG(INFO, CFG_FILE, "Unkown signal type %d.\n", sig);
break;
}
}
int cfgfile_init(void)
{
int ret;
struct sigaction sig;
netif_cfgfile_init();
/* register SIGHUP signal handler */
memset(&sig, 0, sizeof(struct sigaction));
sig.sa_handler = sig_callback;
sigemptyset(&sig.sa_mask);
sig.sa_flags = 0;
ret = sigaction(SIGHUP, &sig, NULL);
if (ret < 0) {
RTE_LOG(ERR, CFG_FILE, "%s: signal handler register failed\n", __func__);
return EDPVS_SYSCALL;
}
/* module initialization */
if ((ret = global_conf_init()) != EDPVS_OK) {
RTE_LOG(ERR, CFG_FILE, "%s: global configuration initialization failed\n",
__func__);
return ret;
}
/* load configuration file on start */
SET_RELOAD;
try_reload();
return EDPVS_OK;
}
int cfgfile_term(void)
{
int ret;
/* module termination */
if ((ret = global_conf_term()) != EDPVS_OK) {
RTE_LOG(ERR, CFG_FILE, "%s: global configuration termination failed\n",
__func__);
return ret;
}
return EDPVS_OK;
}