]> git.proxmox.com Git - mirror_frr.git/blame - pbrd/pbr_main.c
lib, vtysh: Add ability to specify resilient nhgs
[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"
be3b67b5 51#include "pbr_vrf.h"
e5c83d9b
DS
52
53zebra_capabilities_t _caps_p[] = {
54 ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
55};
56
57struct zebra_privs_t pbr_privs = {
58#if defined(FRR_USER) && defined(FRR_GROUP)
59 .user = FRR_USER,
60 .group = FRR_GROUP,
61#endif
62#if defined(VTY_GROUP)
63 .vty_group = VTY_GROUP,
64#endif
65 .caps_p = _caps_p,
66 .cap_num_p = array_size(_caps_p),
67 .cap_num_i = 0};
68
d3765386 69struct option longopts[] = { { 0 } };
e5c83d9b
DS
70
71/* Master of threads. */
72struct thread_master *master;
73
74/* SIGHUP handler. */
75static void sighup(void)
76{
77 zlog_info("SIGHUP received");
78}
79
80/* SIGINT / SIGTERM handler. */
81static void sigint(void)
82{
83 zlog_notice("Terminating on signal");
84
0e7d7358
DS
85 pbr_vrf_terminate();
86
41b21bfa
MS
87 frr_fini();
88
e5c83d9b
DS
89 exit(0);
90}
91
92/* SIGUSR1 handler. */
93static void sigusr1(void)
94{
95 zlog_rotate();
96}
97
7cc91e67 98struct frr_signal_t pbr_signals[] = {
e5c83d9b
DS
99 {
100 .signal = SIGHUP,
101 .handler = &sighup,
102 },
103 {
104 .signal = SIGUSR1,
105 .handler = &sigusr1,
106 },
107 {
108 .signal = SIGINT,
109 .handler = &sigint,
110 },
111 {
112 .signal = SIGTERM,
113 .handler = &sigint,
114 },
115};
116
117#define PBR_VTY_PORT 2615
118
0d8c7a26 119static const struct frr_yang_module_info *const pbrd_yang_modules[] = {
fb7f5aa8 120 &frr_filter_info,
a4bed468 121 &frr_interface_info,
f5eef2d5 122 &frr_vrf_info,
8fcdd0d6
RW
123};
124
e5c83d9b
DS
125FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT,
126
127 .proghelp = "Implementation of PBR.",
128
129 .signals = pbr_signals,
130 .n_signals = array_size(pbr_signals),
131
8fcdd0d6
RW
132 .privs = &pbr_privs,
133
134 .yang_modules = pbrd_yang_modules,
80413c20
DL
135 .n_yang_modules = array_size(pbrd_yang_modules),
136);
e5c83d9b
DS
137
138int main(int argc, char **argv, char **envp)
139{
140 frr_preinit(&pbrd_di, argc, argv);
141 frr_opt_add("", longopts, "");
142
143 while (1) {
144 int opt;
145
146 opt = frr_getopt(argc, argv, NULL);
147
148 if (opt == EOF)
149 break;
150
151 switch (opt) {
152 case 0:
153 break;
154 default:
155 frr_help_exit(1);
e5c83d9b
DS
156 }
157 }
158
159 master = frr_init();
160
161 pbr_debug_init();
162
e5c83d9b
DS
163 nexthop_group_init(pbr_nhgroup_add_cb,
164 pbr_nhgroup_add_nexthop_cb,
165 pbr_nhgroup_del_nexthop_cb,
166 pbr_nhgroup_delete_cb);
167
ad1dabd5
DS
168 /*
169 * So we safely ignore these commands since
170 * we are getting them at this point in time
171 */
172 access_list_init();
e5c83d9b
DS
173 pbr_nht_init();
174 pbr_map_init();
138c5a74
DS
175 if_zapi_callbacks(pbr_ifp_create, pbr_ifp_up,
176 pbr_ifp_down, pbr_ifp_destroy);
e5c83d9b 177 pbr_zebra_init();
be3b67b5 178 pbr_vrf_init();
e5c83d9b
DS
179 pbr_vty_init();
180
181 frr_config_fork();
182 frr_run(master);
183
184 /* Not reached. */
185 return 0;
186}