]> git.proxmox.com Git - mirror_frr.git/blame - zebra/rt_socket.c
zebra: remove unused functions
[mirror_frr.git] / zebra / rt_socket.c
CommitLineData
718e3744 1/*
2 * Kernel routing table updates by routing socket.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#include <zebra.h>
ddfeb486
DL
23
24#ifndef HAVE_NETLINK
25
fe6c7157 26#ifdef __OpenBSD__
d3e2c74a
RW
27#include <netmpls/mpls.h>
28#endif
718e3744 29
30#include "if.h"
31#include "prefix.h"
32#include "sockunion.h"
33#include "log.h"
edd7c245 34#include "privs.h"
13d60d35 35#include "vxlan.h"
174482ef 36#include "lib_errors.h"
718e3744 37
38#include "zebra/debug.h"
39#include "zebra/rib.h"
6621ca86 40#include "zebra/rt.h"
dc95824a 41#include "zebra/kernel_socket.h"
d3e2c74a 42#include "zebra/zebra_mpls.h"
364fed6b 43#include "zebra/zebra_errors.h"
718e3744 44
edd7c245 45extern struct zebra_privs_t zserv_privs;
46
5e8c8947 47#ifdef __OpenBSD__
8ecdb26e 48static int kernel_rtm_add_labels(struct mpls_label_stack *nh_label,
5e8c8947
RW
49 struct sockaddr_mpls *smpls)
50{
51 if (nh_label->num_labels > 1) {
e914ccbe 52 flog_warn(EC_ZEBRA_MAX_LABELS_PUSH,
9df414fe
QY
53 "%s: can't push %u labels at "
54 "once (maximum is 1)",
55 __func__, nh_label->num_labels);
5e8c8947
RW
56 return -1;
57 }
58
59 memset(smpls, 0, sizeof(*smpls));
60 smpls->smpls_len = sizeof(*smpls);
61 smpls->smpls_family = AF_MPLS;
62 smpls->smpls_label = htonl(nh_label->label[0] << MPLS_LABEL_OFFSET);
63
64 return 0;
65}
66#endif
67
718e3744 68/* Interface between zebra message and rtm message. */
08ea27d1
DS
69static int kernel_rtm(int cmd, const struct prefix *p,
70 const struct nexthop_group *ng, uint32_t metric)
718e3744 71
72{
ca2c70bd 73 union sockunion sin_dest, sin_mask, sin_gate;
fe6c7157 74#ifdef __OpenBSD__
d62a17ae 75 struct sockaddr_mpls smpls;
d3e2c74a 76#endif
d62a17ae 77 union sockunion *smplsp = NULL;
78 struct nexthop *nexthop;
79 int nexthop_num = 0;
80 ifindex_t ifindex = 0;
4dd39a0e 81 bool gate = false;
d62a17ae 82 int error;
981dc13f 83 char gate_buf[INET6_BUFSIZ];
d62a17ae 84 char prefix_buf[PREFIX_STRLEN];
a8309422 85 enum blackhole_type bh_type = BLACKHOLE_UNSPEC;
d62a17ae 86
31be7dbb 87 if (IS_ZEBRA_DEBUG_RIB || IS_ZEBRA_DEBUG_KERNEL)
d62a17ae 88 prefix2str(p, prefix_buf, sizeof(prefix_buf));
718e3744 89
86afd529
DS
90 /*
91 * We only have the ability to ADD or DELETE at this point
92 * in time.
93 */
94 if (cmd != RTM_ADD && cmd != RTM_DELETE) {
95 if (IS_ZEBRA_DEBUG_KERNEL)
96 zlog_debug("%s: %s odd command %s for flags %d",
97 __func__, prefix_buf,
98 lookup_msg(rtm_type_str, cmd, NULL),
99 nexthop->flags);
100 return 0;
101 }
102
08ea27d1
DS
103 memset(&sin_dest, 0, sizeof(sin_dest));
104 memset(&sin_gate, 0, sizeof(sin_gate));
ca2c70bd 105 memset(&sin_mask, 0, sizeof(sin_mask));
718e3744 106
08ea27d1
DS
107 switch (p->family) {
108 case AF_INET:
109 sin_dest.sin.sin_family = AF_INET;
08ea27d1
DS
110 sin_dest.sin.sin_addr = p->u.prefix4;
111 sin_gate.sin.sin_family = AF_INET;
0413dd75
RZ
112#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
113 sin_dest.sin.sin_len = sizeof(struct sockaddr_in);
114 sin_gate.sin.sin_len = sizeof(struct sockaddr_in);
115#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
08ea27d1
DS
116 break;
117 case AF_INET6:
118 sin_dest.sin6.sin6_family = AF_INET6;
08ea27d1
DS
119 sin_dest.sin6.sin6_addr = p->u.prefix6;
120 sin_gate.sin6.sin6_family = AF_INET6;
0413dd75
RZ
121#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
122 sin_dest.sin6.sin6_len = sizeof(struct sockaddr_in6);
123 sin_gate.sin6.sin6_len = sizeof(struct sockaddr_in6);
124#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
08ea27d1
DS
125 break;
126 }
718e3744 127
d62a17ae 128 /* Make gateway. */
01ce7cba 129 for (ALL_NEXTHOPS_PTR(ng, nexthop)) {
86afd529
DS
130 /*
131 * We only want to use the actual good nexthops
132 */
133 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE) ||
134 !CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
d62a17ae 135 continue;
136
c2519893 137 smplsp = NULL;
4dd39a0e 138 gate = false;
981dc13f 139 snprintf(gate_buf, sizeof(gate_buf), "NULL");
d62a17ae 140
86afd529
DS
141 switch (nexthop->type) {
142 case NEXTHOP_TYPE_IPV4:
143 case NEXTHOP_TYPE_IPV4_IFINDEX:
144 sin_gate.sin.sin_addr = nexthop->gate.ipv4;
145 sin_gate.sin.sin_family = AF_INET;
0413dd75
RZ
146#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
147 sin_gate.sin.sin_len = sizeof(struct sockaddr_in);
148#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
86afd529 149 ifindex = nexthop->ifindex;
4dd39a0e 150 gate = true;
86afd529
DS
151 break;
152 case NEXTHOP_TYPE_IPV6:
153 case NEXTHOP_TYPE_IPV6_IFINDEX:
154 sin_gate.sin6.sin6_addr = nexthop->gate.ipv6;
155 sin_gate.sin6.sin6_family = AF_INET6;
0413dd75
RZ
156#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
157 sin_gate.sin6.sin6_len = sizeof(struct sockaddr_in6);
158#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
86afd529 159 ifindex = nexthop->ifindex;
08ea27d1
DS
160/* Under kame set interface index to link local address */
161#ifdef KAME
162
163#define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
c9277ebb
DS
164 do { \
165 (a).s6_addr[2] = ((i) >> 8) & 0xff; \
166 (a).s6_addr[3] = (i)&0xff; \
167 } while (0)
08ea27d1 168
86afd529
DS
169 if (IN6_IS_ADDR_LINKLOCAL(&sin_gate.sin6.sin6_addr))
170 SET_IN6_LINKLOCAL_IFINDEX(
171 sin_gate.sin6.sin6_addr,
172 ifindex);
08ea27d1
DS
173#endif /* KAME */
174
4dd39a0e 175 gate = true;
86afd529
DS
176 break;
177 case NEXTHOP_TYPE_IFINDEX:
178 ifindex = nexthop->ifindex;
179 break;
180 case NEXTHOP_TYPE_BLACKHOLE:
181 bh_type = nexthop->bh_type;
182 switch (p->family) {
183 case AFI_IP: {
184 struct in_addr loopback;
185 loopback.s_addr = htonl(INADDR_LOOPBACK);
186 sin_gate.sin.sin_addr = loopback;
0413dd75
RZ
187#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
188 sin_gate.sin.sin_len =
189 sizeof(struct sockaddr_in);
190#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
4dd39a0e 191 gate = true;
86afd529 192 }
08ea27d1 193 break;
86afd529 194 case AFI_IP6:
08ea27d1 195 break;
d62a17ae 196 }
86afd529
DS
197 }
198
199 switch (p->family) {
200 case AF_INET:
18d10d88
DS
201 masklen2ip(p->prefixlen, &sin_mask.sin.sin_addr);
202 sin_mask.sin.sin_family = AF_INET;
0413dd75
RZ
203#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
204 sin_mask.sin.sin_len = sizeof(struct sockaddr_in);
205#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
86afd529
DS
206 break;
207 case AF_INET6:
18d10d88
DS
208 masklen2ip6(p->prefixlen, &sin_mask.sin6.sin6_addr);
209 sin_mask.sin6.sin6_family = AF_INET6;
0413dd75
RZ
210#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
211 sin_mask.sin6.sin6_len = sizeof(struct sockaddr_in6);
212#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
86afd529
DS
213 break;
214 }
718e3744 215
fe6c7157 216#ifdef __OpenBSD__
86afd529
DS
217 if (nexthop->nh_label
218 && !kernel_rtm_add_labels(nexthop->nh_label, &smpls))
219 continue;
220 smplsp = (union sockunion *)&smpls;
d3e2c74a 221#endif
18d10d88 222 error = rtm_write(cmd, &sin_dest, &sin_mask,
86afd529
DS
223 gate ? &sin_gate : NULL, smplsp,
224 ifindex, bh_type, metric);
225
226 if (IS_ZEBRA_DEBUG_KERNEL) {
227 if (!gate) {
981dc13f
RZ
228 zlog_debug(
229 "%s: %s: attention! gate not found for re",
230 __func__, prefix_buf);
231 } else {
232 switch (p->family) {
233 case AFI_IP:
234 inet_ntop(AF_INET,
235 &sin_gate.sin.sin_addr,
236 gate_buf, sizeof(gate_buf));
237 break;
238
239 case AFI_IP6:
240 inet_ntop(AF_INET6,
241 &sin_gate.sin6.sin6_addr,
242 gate_buf, sizeof(gate_buf));
243 break;
244
245 default:
246 snprintf(gate_buf, sizeof(gate_buf),
247 "(invalid-af)");
248 break;
249 }
250 }
86afd529
DS
251 }
252 switch (error) {
253 /* We only flag nexthops as being in FIB if
254 * rtm_write() did its work. */
255 case ZEBRA_ERR_NOERROR:
256 nexthop_num++;
257 if (IS_ZEBRA_DEBUG_KERNEL)
258 zlog_debug("%s: %s: successfully did NH %s",
259 __func__, prefix_buf, gate_buf);
260 if (cmd == RTM_ADD)
261 SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
262 break;
263
264 /* The only valid case for this error is
265 * kernel's failure to install a multipath
266 * route, which is common for FreeBSD. This
267 * should be ignored silently, but logged as an error
268 * otherwise.
269 */
270 case ZEBRA_ERR_RTEXIST:
271 if (cmd != RTM_ADD)
272 flog_err(EC_LIB_SYSTEM_CALL,
273 "%s: rtm_write() returned %d for command %d",
274 __func__, error, cmd);
275 continue;
d62a17ae 276
86afd529
DS
277 /* Note any unexpected status returns */
278 default:
31be7dbb
RZ
279 flog_err(
280 EC_LIB_SYSTEM_CALL,
281 "%s: %s: rtm_write() unexpectedly returned %d for command %s",
282 __func__, prefix_buf, error,
283 lookup_msg(rtm_type_str, cmd, NULL));
86afd529
DS
284 break;
285 }
d62a17ae 286 } /* for (ALL_NEXTHOPS(...))*/
287
288 /* If there was no useful nexthop, then complain. */
560e3136
DS
289 if (nexthop_num == 0) {
290 if (IS_ZEBRA_DEBUG_KERNEL)
31be7dbb
RZ
291 zlog_debug(
292 "%s: No useful nexthops were found in RIB prefix %s",
293 __func__, prefix_buf);
560e3136
DS
294 return 1;
295 }
d62a17ae 296
297 return 0; /*XXX*/
718e3744 298}
299
01ce7cba
MS
300/*
301 * Update or delete a prefix from the kernel,
302 * using info from a dataplane context struct.
303 */
25779064 304enum zebra_dplane_result kernel_route_update(struct zebra_dplane_ctx *ctx)
01ce7cba
MS
305{
306 enum zebra_dplane_result res = ZEBRA_DPLANE_REQUEST_SUCCESS;
307
308 if (dplane_ctx_get_src(ctx) != NULL) {
309 zlog_err("route add: IPv6 sourcedest routes unsupported!");
310 res = ZEBRA_DPLANE_REQUEST_FAILURE;
311 goto done;
312 }
313
49ddb66a 314 frr_elevate_privs(&zserv_privs) {
f183e380
MS
315
316 if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_DELETE)
317 kernel_rtm(RTM_DELETE, dplane_ctx_get_dest(ctx),
318 dplane_ctx_get_ng(ctx),
319 dplane_ctx_get_metric(ctx));
320 else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_INSTALL)
321 kernel_rtm(RTM_ADD, dplane_ctx_get_dest(ctx),
322 dplane_ctx_get_ng(ctx),
323 dplane_ctx_get_metric(ctx));
324 else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_UPDATE) {
325 /* Must do delete and add separately -
326 * no update available
327 */
328 kernel_rtm(RTM_DELETE, dplane_ctx_get_dest(ctx),
329 dplane_ctx_get_old_ng(ctx),
330 dplane_ctx_get_old_metric(ctx));
331
332 kernel_rtm(RTM_ADD, dplane_ctx_get_dest(ctx),
333 dplane_ctx_get_ng(ctx),
334 dplane_ctx_get_metric(ctx));
335 } else {
336 zlog_err("Invalid routing socket update op %s (%u)",
337 dplane_op2str(dplane_ctx_get_op(ctx)),
338 dplane_ctx_get_op(ctx));
339 res = ZEBRA_DPLANE_REQUEST_FAILURE;
340 }
341 } /* Elevated privs */
01ce7cba
MS
342
343done:
344
345 return res;
346}
347
d62a17ae 348int kernel_neigh_update(int add, int ifindex, uint32_t addr, char *lla,
5895d33f 349 int llalen, ns_id_t ns_id)
6b8a5694 350{
d62a17ae 351 /* TODO */
352 return 0;
6b8a5694 353}
1498c059 354
43b5cc5e 355extern int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *mroute)
1498c059 356{
d62a17ae 357 return 0;
1498c059 358}
13d60d35 359
d62a17ae 360int kernel_add_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip)
13d60d35 361{
d62a17ae 362 return 0;
13d60d35 363}
364
d62a17ae 365int kernel_del_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip)
13d60d35 366{
d62a17ae 367 return 0;
13d60d35 368}
2232a77c 369
d62a17ae 370int kernel_add_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac,
a37f4598 371 struct in_addr vtep_ip, bool sticky)
2232a77c 372{
d62a17ae 373 return 0;
2232a77c 374}
375
d62a17ae 376int kernel_del_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac,
d63c1b18 377 struct in_addr vtep_ip)
2232a77c 378{
d62a17ae 379 return 0;
2232a77c 380}
381
d62a17ae 382int kernel_add_neigh(struct interface *ifp, struct ipaddr *ip,
68e33151 383 struct ethaddr *mac, uint8_t flags)
2232a77c 384{
d62a17ae 385 return 0;
2232a77c 386}
387
d62a17ae 388int kernel_del_neigh(struct interface *ifp, struct ipaddr *ip)
2232a77c 389{
d62a17ae 390 return 0;
2232a77c 391}
e0ae31b8
DS
392
393extern int kernel_interface_set_master(struct interface *master,
394 struct interface *slave)
395{
396 return 0;
397}
0ecfe5bf 398
dc7b3cae
DS
399uint32_t kernel_get_speed(struct interface *ifp)
400{
401 return ifp->speed;
402}
403
ddfeb486 404#endif /* !HAVE_NETLINK */