]> git.proxmox.com Git - mirror_frr.git/blame - pbrd/pbr_main.c
Merge pull request #3452 from opensourcerouting/reprobuild-master
[mirror_frr.git] / pbrd / pbr_main.c
CommitLineData
e5c83d9b
DS
1/*
2 * PBR - main code
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <zebra.h>
21
22#include <lib/version.h>
23#include "getopt.h"
24#include "thread.h"
25#include "prefix.h"
26#include "linklist.h"
27#include "if.h"
28#include "vector.h"
29#include "vty.h"
30#include "command.h"
31#include "filter.h"
32#include "plist.h"
33#include "stream.h"
34#include "log.h"
35#include "memory.h"
36#include "privs.h"
37#include "sigevent.h"
38#include "zclient.h"
39#include "keychain.h"
40#include "distribute.h"
41#include "libfrr.h"
42#include "routemap.h"
43#include "nexthop.h"
44#include "nexthop_group.h"
45
46#include "pbr_nht.h"
47#include "pbr_map.h"
48#include "pbr_zebra.h"
e5c83d9b
DS
49#include "pbr_vty.h"
50#include "pbr_debug.h"
51
52zebra_capabilities_t _caps_p[] = {
53 ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
54};
55
56struct zebra_privs_t pbr_privs = {
57#if defined(FRR_USER) && defined(FRR_GROUP)
58 .user = FRR_USER,
59 .group = FRR_GROUP,
60#endif
61#if defined(VTY_GROUP)
62 .vty_group = VTY_GROUP,
63#endif
64 .caps_p = _caps_p,
65 .cap_num_p = array_size(_caps_p),
66 .cap_num_i = 0};
67
d3765386 68struct option longopts[] = { { 0 } };
e5c83d9b
DS
69
70/* Master of threads. */
71struct thread_master *master;
72
73/* SIGHUP handler. */
74static void sighup(void)
75{
76 zlog_info("SIGHUP received");
77}
78
79/* SIGINT / SIGTERM handler. */
80static void sigint(void)
81{
82 zlog_notice("Terminating on signal");
83
e5c83d9b
DS
84 exit(0);
85}
86
87/* SIGUSR1 handler. */
88static void sigusr1(void)
89{
90 zlog_rotate();
91}
92
93struct quagga_signal_t pbr_signals[] = {
94 {
95 .signal = SIGHUP,
96 .handler = &sighup,
97 },
98 {
99 .signal = SIGUSR1,
100 .handler = &sigusr1,
101 },
102 {
103 .signal = SIGINT,
104 .handler = &sigint,
105 },
106 {
107 .signal = SIGTERM,
108 .handler = &sigint,
109 },
110};
111
112#define PBR_VTY_PORT 2615
113
8fcdd0d6 114static const struct frr_yang_module_info *pbrd_yang_modules[] = {
a4bed468 115 &frr_interface_info,
8fcdd0d6
RW
116};
117
e5c83d9b
DS
118FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT,
119
120 .proghelp = "Implementation of PBR.",
121
122 .signals = pbr_signals,
123 .n_signals = array_size(pbr_signals),
124
8fcdd0d6
RW
125 .privs = &pbr_privs,
126
127 .yang_modules = pbrd_yang_modules,
128 .n_yang_modules = array_size(pbrd_yang_modules), )
e5c83d9b
DS
129
130int main(int argc, char **argv, char **envp)
131{
132 frr_preinit(&pbrd_di, argc, argv);
133 frr_opt_add("", longopts, "");
134
135 while (1) {
136 int opt;
137
138 opt = frr_getopt(argc, argv, NULL);
139
140 if (opt == EOF)
141 break;
142
143 switch (opt) {
144 case 0:
145 break;
146 default:
147 frr_help_exit(1);
148 break;
149 }
150 }
151
152 master = frr_init();
153
154 pbr_debug_init();
155
ecbc5a37 156 vrf_init(NULL, NULL, NULL, NULL, NULL);
e5c83d9b
DS
157 nexthop_group_init(pbr_nhgroup_add_cb,
158 pbr_nhgroup_add_nexthop_cb,
159 pbr_nhgroup_del_nexthop_cb,
160 pbr_nhgroup_delete_cb);
161
ad1dabd5
DS
162 /*
163 * So we safely ignore these commands since
164 * we are getting them at this point in time
165 */
166 access_list_init();
e5c83d9b
DS
167 pbr_nht_init();
168 pbr_map_init();
169 pbr_zebra_init();
170 pbr_vty_init();
171
172 frr_config_fork();
173 frr_run(master);
174
175 /* Not reached. */
176 return 0;
177}