]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
e5c83d9b DS |
2 | /* |
3 | * PBR - main code | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * Donald Sharp | |
e5c83d9b DS |
6 | */ |
7 | #include <zebra.h> | |
8 | ||
9 | #include <lib/version.h> | |
10 | #include "getopt.h" | |
11 | #include "thread.h" | |
12 | #include "prefix.h" | |
13 | #include "linklist.h" | |
14 | #include "if.h" | |
15 | #include "vector.h" | |
16 | #include "vty.h" | |
17 | #include "command.h" | |
18 | #include "filter.h" | |
19 | #include "plist.h" | |
20 | #include "stream.h" | |
21 | #include "log.h" | |
22 | #include "memory.h" | |
23 | #include "privs.h" | |
24 | #include "sigevent.h" | |
25 | #include "zclient.h" | |
26 | #include "keychain.h" | |
27 | #include "distribute.h" | |
28 | #include "libfrr.h" | |
29 | #include "routemap.h" | |
30 | #include "nexthop.h" | |
31 | #include "nexthop_group.h" | |
32 | ||
33 | #include "pbr_nht.h" | |
34 | #include "pbr_map.h" | |
35 | #include "pbr_zebra.h" | |
e5c83d9b DS |
36 | #include "pbr_vty.h" |
37 | #include "pbr_debug.h" | |
be3b67b5 | 38 | #include "pbr_vrf.h" |
e5c83d9b DS |
39 | |
40 | zebra_capabilities_t _caps_p[] = { | |
41 | ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, | |
42 | }; | |
43 | ||
44 | struct zebra_privs_t pbr_privs = { | |
45 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
46 | .user = FRR_USER, | |
47 | .group = FRR_GROUP, | |
48 | #endif | |
49 | #if defined(VTY_GROUP) | |
50 | .vty_group = VTY_GROUP, | |
51 | #endif | |
52 | .caps_p = _caps_p, | |
53 | .cap_num_p = array_size(_caps_p), | |
54 | .cap_num_i = 0}; | |
55 | ||
d3765386 | 56 | struct option longopts[] = { { 0 } }; |
e5c83d9b DS |
57 | |
58 | /* Master of threads. */ | |
59 | struct thread_master *master; | |
60 | ||
61 | /* SIGHUP handler. */ | |
62 | static void sighup(void) | |
63 | { | |
64 | zlog_info("SIGHUP received"); | |
65 | } | |
66 | ||
67 | /* SIGINT / SIGTERM handler. */ | |
68 | static void sigint(void) | |
69 | { | |
70 | zlog_notice("Terminating on signal"); | |
71 | ||
0e7d7358 DS |
72 | pbr_vrf_terminate(); |
73 | ||
41b21bfa MS |
74 | frr_fini(); |
75 | ||
e5c83d9b DS |
76 | exit(0); |
77 | } | |
78 | ||
79 | /* SIGUSR1 handler. */ | |
80 | static void sigusr1(void) | |
81 | { | |
82 | zlog_rotate(); | |
83 | } | |
84 | ||
7cc91e67 | 85 | struct frr_signal_t pbr_signals[] = { |
e5c83d9b DS |
86 | { |
87 | .signal = SIGHUP, | |
88 | .handler = &sighup, | |
89 | }, | |
90 | { | |
91 | .signal = SIGUSR1, | |
92 | .handler = &sigusr1, | |
93 | }, | |
94 | { | |
95 | .signal = SIGINT, | |
96 | .handler = &sigint, | |
97 | }, | |
98 | { | |
99 | .signal = SIGTERM, | |
100 | .handler = &sigint, | |
101 | }, | |
102 | }; | |
103 | ||
104 | #define PBR_VTY_PORT 2615 | |
105 | ||
0d8c7a26 | 106 | static const struct frr_yang_module_info *const pbrd_yang_modules[] = { |
fb7f5aa8 | 107 | &frr_filter_info, |
a4bed468 | 108 | &frr_interface_info, |
f5eef2d5 | 109 | &frr_vrf_info, |
8fcdd0d6 RW |
110 | }; |
111 | ||
e5c83d9b DS |
112 | FRR_DAEMON_INFO(pbrd, PBR, .vty_port = PBR_VTY_PORT, |
113 | ||
114 | .proghelp = "Implementation of PBR.", | |
115 | ||
116 | .signals = pbr_signals, | |
117 | .n_signals = array_size(pbr_signals), | |
118 | ||
8fcdd0d6 RW |
119 | .privs = &pbr_privs, |
120 | ||
121 | .yang_modules = pbrd_yang_modules, | |
80413c20 DL |
122 | .n_yang_modules = array_size(pbrd_yang_modules), |
123 | ); | |
e5c83d9b DS |
124 | |
125 | int main(int argc, char **argv, char **envp) | |
126 | { | |
127 | frr_preinit(&pbrd_di, argc, argv); | |
128 | frr_opt_add("", longopts, ""); | |
129 | ||
130 | while (1) { | |
131 | int opt; | |
132 | ||
133 | opt = frr_getopt(argc, argv, NULL); | |
134 | ||
135 | if (opt == EOF) | |
136 | break; | |
137 | ||
138 | switch (opt) { | |
139 | case 0: | |
140 | break; | |
141 | default: | |
142 | frr_help_exit(1); | |
e5c83d9b DS |
143 | } |
144 | } | |
145 | ||
146 | master = frr_init(); | |
147 | ||
148 | pbr_debug_init(); | |
149 | ||
f3c6dd49 | 150 | nexthop_group_init(pbr_nhgroup_add_cb, pbr_nhgroup_modify_cb, |
e5c83d9b | 151 | pbr_nhgroup_add_nexthop_cb, |
f3c6dd49 | 152 | pbr_nhgroup_del_nexthop_cb, pbr_nhgroup_delete_cb); |
e5c83d9b | 153 | |
ad1dabd5 DS |
154 | /* |
155 | * So we safely ignore these commands since | |
156 | * we are getting them at this point in time | |
157 | */ | |
158 | access_list_init(); | |
e5c83d9b DS |
159 | pbr_nht_init(); |
160 | pbr_map_init(); | |
138c5a74 DS |
161 | if_zapi_callbacks(pbr_ifp_create, pbr_ifp_up, |
162 | pbr_ifp_down, pbr_ifp_destroy); | |
e5c83d9b | 163 | pbr_zebra_init(); |
be3b67b5 | 164 | pbr_vrf_init(); |
e5c83d9b DS |
165 | pbr_vty_init(); |
166 | ||
167 | frr_config_fork(); | |
168 | frr_run(master); | |
169 | ||
170 | /* Not reached. */ | |
171 | return 0; | |
172 | } |