1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Kernel communication using routing socket.
3 * Copyright (C) 1999 Kunihiro Ishiguro
10 #include <net/if_types.h>
12 #include <netmpls/mpls.h>
17 #include "sockunion.h"
18 #include "connected.h"
26 #include "lib_errors.h"
29 #include "zebra/interface.h"
30 #include "zebra/zebra_router.h"
31 #include "zebra/debug.h"
32 #include "zebra/kernel_socket.h"
33 #include "zebra/rib.h"
34 #include "zebra/zebra_errors.h"
35 #include "zebra/zebra_ptm.h"
37 extern struct zebra_privs_t zserv_privs
;
40 * Historically, the BSD routing socket has aligned data following a
41 * struct sockaddr to sizeof(long), which was 4 bytes on some
42 * platforms, and 8 bytes on others. NetBSD 6 changed the routing
43 * socket to align to sizeof(uint64_t), which is 8 bytes. OS X
44 * appears to align to sizeof(int), which is 4 bytes.
46 * Alignment of zero-sized sockaddrs is nonsensical, but historically
47 * BSD defines RT_ROUNDUP(0) to be the alignment interval (rather than
48 * 0). We follow this practice without questioning it, but it is a
49 * bug if frr calls ROUNDUP with 0.
52 #define ROUNDUP_TYPE int
54 #define ROUNDUP_TYPE long
58 * Because of these varying conventions, the only sane approach is for
59 * the <net/route.h> header to define some flavor of ROUNDUP macro.
62 /* OS X (Xcode as of 2014-12) is known not to define RT_ROUNDUP */
63 #if defined(RT_ROUNDUP)
64 #define ROUNDUP(a) RT_ROUNDUP(a)
65 #endif /* defined(RT_ROUNDUP) */
68 * If ROUNDUP has not yet been defined in terms of platform-provided
69 * defines, attempt to cope with heuristics.
74 * If you're porting to a platform that changed RT_ROUNDUP but doesn't
75 * have it in its headers, this will break rather obviously and you'll
76 * have to fix it here.
79 ((a) > 0 ? (1 + (((a)-1) | (sizeof(ROUNDUP_TYPE) - 1))) \
80 : sizeof(ROUNDUP_TYPE))
82 #endif /* defined(ROUNDUP) */
86 /* SAROUNDUP is the only thing we need, and SA_SIZE provides that */
87 #define SAROUNDUP(a) SA_SIZE(a)
90 * Given a pointer (sockaddr or void *), return the number of bytes
91 * taken up by the sockaddr and any padding needed for alignment.
93 #if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
94 #define SAROUNDUP(X) ROUNDUP(((struct sockaddr *)(X))->sa_len)
97 * One would hope all fixed-size structure definitions are aligned,
98 * but round them up nonetheless.
100 #define SAROUNDUP(X) \
101 (((struct sockaddr *)(X))->sa_family == AF_INET \
102 ? ROUNDUP(sizeof(struct sockaddr_in)) \
103 : (((struct sockaddr *)(X))->sa_family == AF_INET6 \
104 ? ROUNDUP(sizeof(struct sockaddr_in6)) \
105 : (((struct sockaddr *)(X))->sa_family == AF_LINK \
106 ? ROUNDUP(sizeof(struct sockaddr_dl)) \
107 : sizeof(struct sockaddr))))
108 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
110 #endif /* !SA_SIZE */
112 /* Routing socket message types. */
113 const struct message rtm_type_str
[] = {{RTM_ADD
, "RTM_ADD"},
114 {RTM_DELETE
, "RTM_DELETE"},
115 {RTM_CHANGE
, "RTM_CHANGE"},
116 {RTM_GET
, "RTM_GET"},
117 {RTM_LOSING
, "RTM_LOSING"},
118 {RTM_REDIRECT
, "RTM_REDIRECT"},
119 {RTM_MISS
, "RTM_MISS"},
121 {RTM_LOCK
, "RTM_LOCK"},
122 #endif /* RTM_LOCK */
124 {RTM_OLDADD
, "RTM_OLDADD"},
125 #endif /* RTM_OLDADD */
127 {RTM_OLDDEL
, "RTM_OLDDEL"},
128 #endif /* RTM_OLDDEL */
130 {RTM_RESOLVE
, "RTM_RESOLVE"},
131 #endif /* RTM_RESOLVE */
132 {RTM_NEWADDR
, "RTM_NEWADDR"},
133 {RTM_DELADDR
, "RTM_DELADDR"},
134 {RTM_IFINFO
, "RTM_IFINFO"},
136 {RTM_OIFINFO
, "RTM_OIFINFO"},
137 #endif /* RTM_OIFINFO */
139 {RTM_NEWMADDR
, "RTM_NEWMADDR"},
140 #endif /* RTM_NEWMADDR */
142 {RTM_DELMADDR
, "RTM_DELMADDR"},
143 #endif /* RTM_DELMADDR */
144 #ifdef RTM_IFANNOUNCE
145 {RTM_IFANNOUNCE
, "RTM_IFANNOUNCE"},
146 #endif /* RTM_IFANNOUNCE */
148 {RTM_IEEE80211
, "RTM_IEEE80211"},
152 static const struct message rtm_flag_str
[] = {{RTF_UP
, "UP"},
153 {RTF_GATEWAY
, "GATEWAY"},
155 {RTF_REJECT
, "REJECT"},
156 {RTF_DYNAMIC
, "DYNAMIC"},
157 {RTF_MODIFIED
, "MODIFIED"},
161 #endif /* RTF_MASK */
163 {RTF_CLONING
, "CLONING"},
164 #endif /* RTF_CLONING */
166 {RTF_XRESOLVE
, "XRESOLVE"},
167 #endif /* RTF_XRESOLVE */
169 {RTF_LLINFO
, "LLINFO"},
170 #endif /* RTF_LLINFO */
171 {RTF_STATIC
, "STATIC"},
172 {RTF_BLACKHOLE
, "BLACKHOLE"},
174 {RTF_PRIVATE
, "PRIVATE"},
175 #endif /* RTF_PRIVATE */
176 {RTF_PROTO1
, "PROTO1"},
177 {RTF_PROTO2
, "PROTO2"},
179 {RTF_PRCLONING
, "PRCLONING"},
180 #endif /* RTF_PRCLONING */
182 {RTF_WASCLONED
, "WASCLONED"},
183 #endif /* RTF_WASCLONED */
185 {RTF_PROTO3
, "PROTO3"},
186 #endif /* RTF_PROTO3 */
188 {RTF_PINNED
, "PINNED"},
189 #endif /* RTF_PINNED */
191 {RTF_LOCAL
, "LOCAL"},
192 #endif /* RTF_LOCAL */
194 {RTF_BROADCAST
, "BROADCAST"},
195 #endif /* RTF_BROADCAST */
197 {RTF_MULTICAST
, "MULTICAST"},
198 #endif /* RTF_MULTICAST */
200 {RTF_MULTIRT
, "MULTIRT"},
201 #endif /* RTF_MULTIRT */
203 {RTF_SETSRC
, "SETSRC"},
204 #endif /* RTF_SETSRC */
207 /* Kernel routing update socket. */
208 int routing_sock
= -1;
210 /* Kernel dataplane routing update socket, used in the dataplane pthread
213 int dplane_routing_sock
= -1;
215 /* Yes I'm checking ugly routing socket behavior. */
218 size_t _rta_get(caddr_t sap
, void *destp
, size_t destlen
, bool checkaf
);
219 size_t rta_get(caddr_t sap
, void *dest
, size_t destlen
);
220 size_t rta_getattr(caddr_t sap
, void *destp
, size_t destlen
);
221 size_t rta_getsdlname(caddr_t sap
, void *dest
, short *destlen
);
222 const char *rtatostr(unsigned int flags
, char *buf
, size_t buflen
);
224 /* Supported address family check. */
225 static inline int af_check(int family
)
227 if (family
== AF_INET
)
229 if (family
== AF_INET6
)
234 size_t _rta_get(caddr_t sap
, void *destp
, size_t destlen
, bool checkaf
)
236 struct sockaddr
*sa
= (struct sockaddr
*)sap
;
237 struct sockaddr_dl
*sdl
;
238 uint8_t *dest
= destp
;
239 size_t tlen
, copylen
;
241 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
242 copylen
= sa
->sa_len
;
243 tlen
= (copylen
== 0) ? sizeof(ROUNDUP_TYPE
) : ROUNDUP(copylen
);
244 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
245 copylen
= tlen
= SAROUNDUP(sap
);
246 #endif /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
248 if (copylen
> 0 && dest
!= NULL
) {
249 if (checkaf
&& af_check(sa
->sa_family
) == 0)
252 * Handle sockaddr_dl corner case:
253 * RTA_NETMASK might be AF_LINK, but it doesn't anything
254 * relevant (e.g. zeroed out fields). Check for this
255 * case and avoid warning log message.
257 if (sa
->sa_family
== AF_LINK
) {
258 sdl
= (struct sockaddr_dl
*)sa
;
259 if (sdl
->sdl_index
== 0 || sdl
->sdl_nlen
== 0)
263 if (copylen
> destlen
) {
265 "%s: destination buffer too small (%zu vs %zu)",
266 __func__
, copylen
, destlen
);
267 memcpy(dest
, sap
, destlen
);
269 memcpy(dest
, sap
, copylen
);
275 size_t rta_get(caddr_t sap
, void *destp
, size_t destlen
)
277 return _rta_get(sap
, destp
, destlen
, true);
280 size_t rta_getattr(caddr_t sap
, void *destp
, size_t destlen
)
282 return _rta_get(sap
, destp
, destlen
, false);
285 size_t rta_getsdlname(caddr_t sap
, void *destp
, short *destlen
)
287 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)sap
;
288 uint8_t *dest
= destp
;
289 size_t tlen
, copylen
;
291 copylen
= sdl
->sdl_nlen
;
292 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
293 struct sockaddr
*sa
= (struct sockaddr
*)sap
;
295 tlen
= (sa
->sa_len
== 0) ? sizeof(ROUNDUP_TYPE
) : ROUNDUP(sa
->sa_len
);
296 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
297 tlen
= SAROUNDUP(sap
);
298 #endif /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
300 if (copylen
> 0 && dest
!= NULL
&& sdl
->sdl_family
== AF_LINK
) {
301 if (copylen
> IFNAMSIZ
) {
303 "%s: destination buffer too small (%zu vs %d)",
304 __func__
, copylen
, IFNAMSIZ
);
305 memcpy(dest
, sdl
->sdl_data
, IFNAMSIZ
);
309 memcpy(dest
, sdl
->sdl_data
, copylen
);
319 const char *rtatostr(unsigned int flags
, char *buf
, size_t buflen
)
321 const char *flagstr
, *bufstart
;
325 /* Hold the pointer to the buffer beginning. */
328 for (bit
= 1; bit
; bit
<<= 1) {
329 if ((flags
& bit
) == 0)
346 #endif /* RTA_GENMASK */
357 #endif /* RTA_AUTHOR */
370 #endif /* RTA_SRCMASK */
375 #endif /* RTA_LABEL */
378 snprintf(ustr
, sizeof(ustr
), "0x%x", bit
);
383 wlen
= snprintf(buf
, buflen
, "%s,", flagstr
);
388 /* Check for empty buffer. */
392 /* Remove the last comma. */
398 /* Dump routing table flag for debug purpose. */
399 static void rtm_flag_dump(int flag
)
401 const struct message
*mes
;
402 static char buf
[BUFSIZ
];
405 for (mes
= rtm_flag_str
; mes
->key
!= 0; mes
++) {
406 if (mes
->key
& flag
) {
407 strlcat(buf
, mes
->str
, BUFSIZ
);
408 strlcat(buf
, " ", BUFSIZ
);
411 zlog_debug("Kernel: %s", buf
);
414 #ifdef RTM_IFANNOUNCE
415 /* Interface adding function */
416 static int ifan_read(struct if_announcemsghdr
*ifan
)
418 struct interface
*ifp
;
420 ifp
= if_lookup_by_index(ifan
->ifan_index
, VRF_DEFAULT
);
423 assert((ifp
->ifindex
== ifan
->ifan_index
)
424 || (ifp
->ifindex
== IFINDEX_INTERNAL
));
426 if ((ifp
== NULL
) || ((ifp
->ifindex
== IFINDEX_INTERNAL
)
427 && (ifan
->ifan_what
== IFAN_ARRIVAL
))) {
428 if (IS_ZEBRA_DEBUG_KERNEL
)
430 "%s: creating interface for ifindex %d, name %s",
431 __func__
, ifan
->ifan_index
, ifan
->ifan_name
);
433 /* Create Interface */
434 ifp
= if_get_by_name(ifan
->ifan_name
, VRF_DEFAULT
,
436 if_set_index(ifp
, ifan
->ifan_index
);
440 } else if (ifp
!= NULL
&& ifan
->ifan_what
== IFAN_DEPARTURE
)
441 if_delete_update(&ifp
);
448 if (IS_ZEBRA_DEBUG_KERNEL
)
449 zlog_debug("%s: interface %s index %d", __func__
,
450 ifan
->ifan_name
, ifan
->ifan_index
);
454 #endif /* RTM_IFANNOUNCE */
456 #ifdef HAVE_BSD_IFI_LINK_STATE
457 /* BSD link detect translation */
458 static void bsd_linkdetect_translate(struct if_msghdr
*ifm
)
460 if ((ifm
->ifm_data
.ifi_link_state
>= LINK_STATE_UP
)
461 || (ifm
->ifm_data
.ifi_link_state
== LINK_STATE_UNKNOWN
))
462 SET_FLAG(ifm
->ifm_flags
, IFF_RUNNING
);
464 UNSET_FLAG(ifm
->ifm_flags
, IFF_RUNNING
);
466 #endif /* HAVE_BSD_IFI_LINK_STATE */
468 static enum zebra_link_type
sdl_to_zebra_link_type(unsigned int sdlt
)
472 return ZEBRA_LLT_ETHER
;
474 return ZEBRA_LLT_X25
;
476 return ZEBRA_LLT_FDDI
;
478 return ZEBRA_LLT_PPP
;
480 return ZEBRA_LLT_LOOPBACK
;
482 return ZEBRA_LLT_SLIP
;
484 return ZEBRA_LLT_ARCNET
;
486 return ZEBRA_LLT_ATM
;
488 return ZEBRA_LLT_LOCALTLK
;
490 return ZEBRA_LLT_HIPPI
;
493 return ZEBRA_LLT_IEEE1394
;
497 return ZEBRA_LLT_UNKNOWN
;
502 * Handle struct if_msghdr obtained from reading routing socket or
503 * sysctl (from interface_list). There may or may not be sockaddrs
504 * present after the header.
506 int ifm_read(struct if_msghdr
*ifm
)
508 struct interface
*ifp
= NULL
;
509 struct sockaddr_dl
*sdl
= NULL
;
510 char ifname
[IFNAMSIZ
];
516 /* terminate ifname at head (for strnlen) and tail (for safety) */
517 ifname
[IFNAMSIZ
- 1] = '\0';
519 /* paranoia: sanity check structure */
520 if (ifm
->ifm_msglen
< sizeof(struct if_msghdr
)) {
521 flog_err(EC_ZEBRA_NETLINK_LENGTH_ERROR
,
522 "%s: ifm->ifm_msglen %d too short", __func__
,
528 * Check for a sockaddr_dl following the message. First, point to
529 * where a socakddr might be if one follows the message.
531 cp
= (void *)(ifm
+ 1);
533 /* Look up for RTA_IFP and skip others. */
534 for (maskbit
= 1; maskbit
; maskbit
<<= 1) {
535 if ((maskbit
& ifm
->ifm_addrs
) == 0)
537 if (maskbit
!= RTA_IFP
) {
538 cp
+= rta_get(cp
, NULL
, 0);
542 /* Save the pointer to the structure. */
543 sdl
= (struct sockaddr_dl
*)cp
;
544 cp
+= rta_getsdlname(cp
, ifname
, &ifnlen
);
547 if (IS_ZEBRA_DEBUG_KERNEL
)
548 zlog_debug("%s: sdl ifname %s addrs {%s}", __func__
,
549 (ifnlen
? ifname
: "(nil)"),
550 rtatostr(ifm
->ifm_addrs
, fbuf
, sizeof(fbuf
)));
553 * Look up on ifindex first, because ifindices are the primary handle
555 * interfaces across the user/kernel boundary, for most systems. (Some
556 * messages, such as up/down status changes on NetBSD, do not include a
559 if ((ifp
= if_lookup_by_index(ifm
->ifm_index
, VRF_DEFAULT
)) != NULL
) {
560 /* we have an ifp, verify that the name matches as some systems,
561 * eg Solaris, have a 1:many association of ifindex:ifname
562 * if they dont match, we dont have the correct ifp and should
563 * set it back to NULL to let next check do lookup by name
565 if (ifnlen
&& (strncmp(ifp
->name
, ifname
, IFNAMSIZ
) != 0)) {
566 if (IS_ZEBRA_DEBUG_KERNEL
)
568 "%s: ifp name %s doesn't match sdl name %s",
569 __func__
, ifp
->name
, ifname
);
575 * If we dont have an ifp, try looking up by name. Particularly as some
576 * systems (Solaris) have a 1:many mapping of ifindex:ifname - the
578 * is therefore our unique handle to that interface.
580 * Interfaces specified in the configuration file for which the ifindex
581 * has not been determined will have ifindex == IFINDEX_INTERNAL, and
583 * interfaces are found by this search, and then their ifindex values
587 if ((ifp
== NULL
) && ifnlen
)
588 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
591 * If ifp still does not exist or has an invalid index
592 * (IFINDEX_INTERNAL),
593 * create or fill in an interface.
595 if ((ifp
== NULL
) || (ifp
->ifindex
== IFINDEX_INTERNAL
)) {
597 * To create or fill in an interface, a sockaddr_dl (via
598 * RTA_IFP) is required.
601 zlog_debug("Interface index %d (new) missing ifname",
606 #ifndef RTM_IFANNOUNCE
607 /* Down->Down interface should be ignored here.
608 * See further comment below.
610 if (!CHECK_FLAG(ifm
->ifm_flags
, IFF_UP
))
612 #endif /* !RTM_IFANNOUNCE */
615 /* Interface that zebra was not previously aware of, so
617 ifp
= if_get_by_name(ifname
, VRF_DEFAULT
,
619 if (IS_ZEBRA_DEBUG_KERNEL
)
620 zlog_debug("%s: creating ifp for ifindex %d",
621 __func__
, ifm
->ifm_index
);
624 if (IS_ZEBRA_DEBUG_KERNEL
)
626 "%s: updated/created ifp, ifname %s, ifindex %d",
627 __func__
, ifp
->name
, ifp
->ifindex
);
629 * Fill in newly created interface structure, or larval
630 * structure with ifindex IFINDEX_INTERNAL.
632 if_set_index(ifp
, ifm
->ifm_index
);
634 #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
635 bsd_linkdetect_translate(ifm
);
636 #endif /* HAVE_BSD_IFI_LINK_STATE */
638 if_flags_update(ifp
, ifm
->ifm_flags
);
639 #if defined(__bsdi__)
643 #endif /* __bsdi__ */
647 * XXX sockaddr_dl contents can be larger than the structure
648 * definition. There are 2 big families here:
649 * - BSD has sdl_len + sdl_data[16] + overruns sdl_data
650 * we MUST use sdl_len here or we'll truncate data.
651 * - Solaris has no sdl_len, but sdl_data[244]
652 * presumably, it's not going to run past that, so sizeof()
654 * a nonzero ifnlen from rta_getsdlname() means sdl is valid
656 ifp
->ll_type
= ZEBRA_LLT_UNKNOWN
;
657 ifp
->hw_addr_len
= 0;
659 #ifdef HAVE_STRUCT_SOCKADDR_DL_SDL_LEN
660 memcpy(&((struct zebra_if
*)ifp
->info
)->sdl
, sdl
,
663 memcpy(&((struct zebra_if
*)ifp
->info
)->sdl
, sdl
,
664 sizeof(struct sockaddr_dl
));
665 #endif /* HAVE_STRUCT_SOCKADDR_DL_SDL_LEN */
667 ifp
->ll_type
= sdl_to_zebra_link_type(sdl
->sdl_type
);
668 if (sdl
->sdl_alen
<= sizeof(ifp
->hw_addr
)) {
669 memcpy(ifp
->hw_addr
, LLADDR(sdl
),
671 ifp
->hw_addr_len
= sdl
->sdl_alen
;
678 * Interface structure exists. Adjust stored flags from
679 * notification. If interface has up->down or down->up
680 * transition, call state change routines (to adjust routes,
681 * notify routing daemons, etc.). (Other flag changes are stored
682 * but apparently do not trigger action.)
685 if (ifp
->ifindex
!= ifm
->ifm_index
) {
687 "%s: index mismatch, ifname %s, ifp index %d, ifm index %d",
688 __func__
, ifp
->name
, ifp
->ifindex
,
693 #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
694 bsd_linkdetect_translate(ifm
);
695 #endif /* HAVE_BSD_IFI_LINK_STATE */
697 /* update flags and handle operative->inoperative transition, if
699 if_flags_update(ifp
, ifm
->ifm_flags
);
701 #ifndef RTM_IFANNOUNCE
702 if (!if_is_up(ifp
)) {
703 /* No RTM_IFANNOUNCE on this platform, so we can never
704 * distinguish between ~IFF_UP and delete. We must
706 * it has been deleted.
707 * Eg, Solaris will not notify us of unplumb.
709 * XXX: Fixme - this should be runtime detected
710 * So that a binary compiled on a system with IFANNOUNCE
711 * will still behave correctly if run on a platform
714 if_delete_update(&ifp
);
716 #endif /* RTM_IFANNOUNCE */
717 if (ifp
&& if_is_up(ifp
)) {
718 #if defined(__bsdi__)
722 #endif /* __bsdi__ */
728 #ifdef HAVE_NET_RT_IFLIST
729 ifp
->stats
= ifm
->ifm_data
;
730 #endif /* HAVE_NET_RT_IFLIST */
731 ifp
->speed
= ifm
->ifm_data
.ifi_baudrate
/ 1000000;
733 if (IS_ZEBRA_DEBUG_KERNEL
)
734 zlog_debug("%s: interface %s index %d", __func__
,
735 ifp
->name
, ifp
->ifindex
);
741 /* Address read from struct ifa_msghdr. */
742 static void ifam_read_mesg(struct ifa_msghdr
*ifm
, union sockunion
*addr
,
743 union sockunion
*mask
, union sockunion
*brd
,
744 char *ifname
, short *ifnlen
)
748 union sockunion gateway
;
752 pnt
= (caddr_t
)(ifm
+ 1);
753 end
= ((caddr_t
)ifm
) + ifm
->ifam_msglen
;
755 /* Be sure structure is cleared */
756 memset(mask
, 0, sizeof(union sockunion
));
757 memset(addr
, 0, sizeof(union sockunion
));
758 memset(brd
, 0, sizeof(union sockunion
));
759 memset(&dst
, 0, sizeof(union sockunion
));
760 memset(&gateway
, 0, sizeof(union sockunion
));
762 /* We fetch each socket variable into sockunion. */
763 for (maskbit
= 1; maskbit
; maskbit
<<= 1) {
764 if ((maskbit
& ifm
->ifam_addrs
) == 0)
769 pnt
+= rta_get(pnt
, &dst
, sizeof(dst
));
772 pnt
+= rta_get(pnt
, &gateway
, sizeof(gateway
));
775 pnt
+= rta_getattr(pnt
, mask
, sizeof(*mask
));
778 pnt
+= rta_getsdlname(pnt
, ifname
, ifnlen
);
781 pnt
+= rta_get(pnt
, addr
, sizeof(*addr
));
784 pnt
+= rta_get(pnt
, brd
, sizeof(*brd
));
788 pnt
+= rta_get(pnt
, NULL
, 0);
793 zlog_warn("%s: overflow detected (pnt:%p end:%p)",
799 if (IS_ZEBRA_DEBUG_KERNEL
) {
800 switch (sockunion_family(addr
)) {
804 (sockunion_family(addr
) == AF_INET
)
805 ? ip_masklen(mask
->sin
.sin_addr
)
806 : ip6_masklen(mask
->sin6
.sin6_addr
);
808 "%s: ifindex %d, ifname %s, ifam_addrs {%s}, ifam_flags 0x%x, addr %pSU/%d broad %pSU dst %pSU gateway %pSU",
809 __func__
, ifm
->ifam_index
,
810 (ifnlen
? ifname
: "(nil)"),
811 rtatostr(ifm
->ifam_addrs
, fbuf
, sizeof(fbuf
)),
812 ifm
->ifam_flags
, addr
, masklen
, brd
, &dst
,
816 zlog_debug("%s: ifindex %d, ifname %s, ifam_addrs {%s}",
817 __func__
, ifm
->ifam_index
,
818 (ifnlen
? ifname
: "(nil)"),
819 rtatostr(ifm
->ifam_addrs
, fbuf
,
825 /* Assert read up end point matches to end point */
826 pnt
= (caddr_t
)ROUNDUP((size_t)pnt
);
827 if (pnt
!= (caddr_t
)ROUNDUP((size_t)end
))
828 zlog_debug("ifam_read() doesn't read all socket data");
831 /* Interface's address information get. */
832 int ifam_read(struct ifa_msghdr
*ifam
)
834 struct interface
*ifp
= NULL
;
835 union sockunion addr
, mask
, brd
;
836 bool dest_same
= false;
837 char ifname
[INTERFACE_NAMSIZ
];
839 bool isalias
= false;
842 ifname
[0] = ifname
[INTERFACE_NAMSIZ
- 1] = '\0';
844 /* Allocate and read address information. */
845 ifam_read_mesg(ifam
, &addr
, &mask
, &brd
, ifname
, &ifnlen
);
847 if ((ifp
= if_lookup_by_index(ifam
->ifam_index
, VRF_DEFAULT
)) == NULL
) {
848 flog_warn(EC_ZEBRA_UNKNOWN_INTERFACE
,
849 "%s: no interface for ifname %s, index %d", __func__
,
850 ifname
, ifam
->ifam_index
);
854 if (ifnlen
&& strncmp(ifp
->name
, ifname
, INTERFACE_NAMSIZ
))
858 * Mark the alias prefixes as secondary
861 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
863 /* N.B. The info in ifa_msghdr does not tell us whether the RTA_BRD
864 field contains a broadcast address or a peer address, so we are
866 rely upon the interface type. */
867 if (if_is_pointopoint(ifp
))
868 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
870 if (memcmp(&addr
, &brd
, sizeof(addr
)) == 0)
875 /* it might seem cute to grab the interface metric here, however
876 * we're processing an address update message, and so some systems
877 * (e.g. FBSD) dont bother to fill in ifam_metric. Disabled, but left
878 * in deliberately, as comment.
880 ifp
->metric
= ifam
->ifam_metric
;
883 /* Add connected address. */
884 switch (sockunion_family(&addr
)) {
886 if (ifam
->ifam_type
== RTM_NEWADDR
)
887 connected_add_ipv4(ifp
, flags
, &addr
.sin
.sin_addr
,
888 ip_masklen(mask
.sin
.sin_addr
),
889 dest_same
? NULL
: &brd
.sin
.sin_addr
,
890 (isalias
? ifname
: NULL
),
893 connected_delete_ipv4(ifp
, flags
, &addr
.sin
.sin_addr
,
894 ip_masklen(mask
.sin
.sin_addr
),
896 : &brd
.sin
.sin_addr
);
899 /* Unset interface index from link-local address when IPv6 stack
901 if (IN6_IS_ADDR_LINKLOCAL(&addr
.sin6
.sin6_addr
)) {
902 SET_IN6_LINKLOCAL_IFINDEX(addr
.sin6
.sin6_addr
, 0);
905 if (ifam
->ifam_type
== RTM_NEWADDR
)
906 connected_add_ipv6(ifp
, flags
, &addr
.sin6
.sin6_addr
,
908 ip6_masklen(mask
.sin6
.sin6_addr
),
909 (isalias
? ifname
: NULL
),
912 connected_delete_ipv6(ifp
, &addr
.sin6
.sin6_addr
, NULL
,
913 ip6_masklen(mask
.sin6
.sin6_addr
));
916 /* Unsupported family silently ignore... */
920 /* Check interface flag for implicit up of the interface. */
926 /* Interface function for reading kernel routing table information. */
927 static int rtm_read_mesg(struct rt_msghdr
*rtm
, union sockunion
*dest
,
928 union sockunion
*mask
, union sockunion
*gate
,
929 char *ifname
, short *ifnlen
)
934 /* Pnt points out socket data start point. */
935 pnt
= (caddr_t
)(rtm
+ 1);
936 end
= ((caddr_t
)rtm
) + rtm
->rtm_msglen
;
938 /* rt_msghdr version check. */
939 if (rtm
->rtm_version
!= RTM_VERSION
)
940 flog_warn(EC_ZEBRA_RTM_VERSION_MISMATCH
,
941 "Routing message version different %d should be %d.This may cause problem",
942 rtm
->rtm_version
, RTM_VERSION
);
944 /* Be sure structure is cleared */
945 memset(dest
, 0, sizeof(union sockunion
));
946 memset(gate
, 0, sizeof(union sockunion
));
947 memset(mask
, 0, sizeof(union sockunion
));
949 /* We fetch each socket variable into sockunion. */
950 /* We fetch each socket variable into sockunion. */
951 for (maskbit
= 1; maskbit
; maskbit
<<= 1) {
952 if ((maskbit
& rtm
->rtm_addrs
) == 0)
957 pnt
+= rta_get(pnt
, dest
, sizeof(*dest
));
960 pnt
+= rta_get(pnt
, gate
, sizeof(*gate
));
963 pnt
+= rta_getattr(pnt
, mask
, sizeof(*mask
));
966 pnt
+= rta_getsdlname(pnt
, ifname
, ifnlen
);
970 pnt
+= rta_get(pnt
, NULL
, 0);
975 zlog_warn("%s: overflow detected (pnt:%p end:%p)",
981 /* If there is netmask information set it's family same as
983 if (rtm
->rtm_addrs
& RTA_NETMASK
)
984 mask
->sa
.sa_family
= dest
->sa
.sa_family
;
986 /* Assert read up to the end of pointer. */
988 zlog_debug("rtm_read() doesn't read all socket data.");
990 return rtm
->rtm_flags
;
993 void rtm_read(struct rt_msghdr
*rtm
)
996 uint32_t zebra_flags
;
997 union sockunion dest
, mask
, gate
;
998 char ifname
[INTERFACE_NAMSIZ
+ 1];
1002 ifindex_t ifindex
= 0;
1005 int32_t proto
= ZEBRA_ROUTE_KERNEL
;
1006 uint8_t distance
= 0;
1010 /* Read destination and netmask and gateway from rtm message
1012 flags
= rtm_read_mesg(rtm
, &dest
, &mask
, &gate
, ifname
, &ifnlen
);
1013 if (!(flags
& RTF_DONE
))
1015 if (IS_ZEBRA_DEBUG_KERNEL
)
1016 zlog_debug("%s: got rtm of type %d (%s) addrs {%s}", __func__
,
1018 lookup_msg(rtm_type_str
, rtm
->rtm_type
, NULL
),
1019 rtatostr(rtm
->rtm_addrs
, fbuf
, sizeof(fbuf
)));
1021 #ifdef RTF_CLONED /*bsdi, netbsd 1.6*/
1022 if (flags
& RTF_CLONED
)
1025 #ifdef RTF_WASCLONED /*freebsd*/
1026 if (flags
& RTF_WASCLONED
)
1030 if ((rtm
->rtm_type
== RTM_ADD
|| rtm
->rtm_type
== RTM_CHANGE
)
1031 && !(flags
& RTF_UP
))
1034 /* This is connected route. */
1035 if (!(flags
& RTF_GATEWAY
))
1038 if (flags
& RTF_PROTO1
) {
1039 SET_FLAG(zebra_flags
, ZEBRA_FLAG_SELFROUTE
);
1040 proto
= ZEBRA_ROUTE_STATIC
;
1044 memset(&nh
, 0, sizeof(nh
));
1046 nh
.vrf_id
= VRF_DEFAULT
;
1047 /* This is a reject or blackhole route */
1048 if (flags
& RTF_REJECT
) {
1049 nh
.type
= NEXTHOP_TYPE_BLACKHOLE
;
1050 nh
.bh_type
= BLACKHOLE_REJECT
;
1051 } else if (flags
& RTF_BLACKHOLE
) {
1052 nh
.type
= NEXTHOP_TYPE_BLACKHOLE
;
1053 nh
.bh_type
= BLACKHOLE_NULL
;
1057 * Ignore our own messages.
1059 if (rtm
->rtm_type
!= RTM_GET
&& rtm
->rtm_pid
== pid
)
1062 if (dest
.sa
.sa_family
== AF_INET
) {
1065 p
.u
.prefix4
= dest
.sin
.sin_addr
;
1066 if (flags
& RTF_HOST
)
1067 p
.prefixlen
= IPV4_MAX_BITLEN
;
1069 p
.prefixlen
= ip_masklen(mask
.sin
.sin_addr
);
1072 nh
.type
= NEXTHOP_TYPE_IPV4
;
1073 nh
.gate
.ipv4
= gate
.sin
.sin_addr
;
1075 } else if (dest
.sa
.sa_family
== AF_INET6
) {
1077 p
.family
= AF_INET6
;
1078 p
.u
.prefix6
= dest
.sin6
.sin6_addr
;
1079 if (flags
& RTF_HOST
)
1080 p
.prefixlen
= IPV6_MAX_BITLEN
;
1082 p
.prefixlen
= ip6_masklen(mask
.sin6
.sin6_addr
);
1085 if (IN6_IS_ADDR_LINKLOCAL(&gate
.sin6
.sin6_addr
)) {
1086 ifindex
= IN6_LINKLOCAL_IFINDEX(gate
.sin6
.sin6_addr
);
1087 SET_IN6_LINKLOCAL_IFINDEX(gate
.sin6
.sin6_addr
, 0);
1092 nh
.type
= ifindex
? NEXTHOP_TYPE_IPV6_IFINDEX
1093 : NEXTHOP_TYPE_IPV6
;
1094 nh
.gate
.ipv6
= gate
.sin6
.sin6_addr
;
1095 nh
.ifindex
= ifindex
;
1100 if (rtm
->rtm_type
== RTM_GET
|| rtm
->rtm_type
== RTM_ADD
1101 || rtm
->rtm_type
== RTM_CHANGE
)
1102 rib_add(afi
, SAFI_UNICAST
, VRF_DEFAULT
, proto
, 0, zebra_flags
,
1103 &p
, NULL
, &nh
, 0, RT_TABLE_MAIN
, 0, 0, distance
, 0,
1106 rib_delete(afi
, SAFI_UNICAST
, VRF_DEFAULT
, proto
, 0,
1107 zebra_flags
, &p
, NULL
, &nh
, 0, RT_TABLE_MAIN
, 0,
1111 /* Interface function for the kernel routing table updates. Support
1112 * for RTM_CHANGE will be needed.
1113 * Exported only for rt_socket.c
1115 int rtm_write(int message
, union sockunion
*dest
, union sockunion
*mask
,
1116 union sockunion
*gate
, union sockunion
*mpls
, unsigned int index
,
1117 enum blackhole_type bh_type
, int metric
)
1121 struct interface
*ifp
;
1123 /* Sequencial number of routing message. */
1124 static int msg_seq
= 0;
1126 /* Struct of rt_msghdr and buffer for storing socket's data. */
1128 struct rt_msghdr rtm
;
1132 if (dplane_routing_sock
< 0)
1133 return ZEBRA_ERR_EPERM
;
1135 /* Clear and set rt_msghdr values */
1136 memset(&msg
, 0, sizeof(msg
));
1137 msg
.rtm
.rtm_version
= RTM_VERSION
;
1138 msg
.rtm
.rtm_type
= message
;
1139 msg
.rtm
.rtm_seq
= msg_seq
++;
1140 msg
.rtm
.rtm_addrs
= RTA_DST
;
1141 msg
.rtm
.rtm_addrs
|= RTA_GATEWAY
;
1142 msg
.rtm
.rtm_flags
= RTF_UP
;
1144 msg
.rtm
.rtm_flags
|= RTF_MPATH
;
1145 msg
.rtm
.rtm_fmask
= RTF_MPLS
;
1147 msg
.rtm
.rtm_index
= index
;
1150 msg
.rtm
.rtm_rmx
.rmx_hopcount
= metric
;
1151 msg
.rtm
.rtm_inits
|= RTV_HOPCOUNT
;
1154 ifp
= if_lookup_by_index(index
, VRF_DEFAULT
);
1156 if (gate
&& (message
== RTM_ADD
|| message
== RTM_CHANGE
))
1157 msg
.rtm
.rtm_flags
|= RTF_GATEWAY
;
1159 /* When RTF_CLONING is unavailable on BSD, should we set some
1160 * other flag instead?
1163 if (!gate
&& (message
== RTM_ADD
|| message
== RTM_CHANGE
) && ifp
1164 && (ifp
->flags
& IFF_POINTOPOINT
) == 0)
1165 msg
.rtm
.rtm_flags
|= RTF_CLONING
;
1166 #endif /* RTF_CLONING */
1168 /* If no protocol specific gateway is specified, use link
1169 address for gateway. */
1172 char dest_buf
[INET_ADDRSTRLEN
] = "NULL",
1173 mask_buf
[INET_ADDRSTRLEN
] = "255.255.255.255";
1175 inet_ntop(AF_INET
, &dest
->sin
.sin_addr
,
1176 dest_buf
, INET_ADDRSTRLEN
);
1178 inet_ntop(AF_INET
, &mask
->sin
.sin_addr
,
1179 mask_buf
, INET_ADDRSTRLEN
);
1181 EC_ZEBRA_RTM_NO_GATEWAY
,
1182 "%s: %s/%s: gate == NULL and no gateway found for ifindex %d",
1183 __func__
, dest_buf
, mask_buf
, index
);
1186 gate
= (union sockunion
*)&((struct zebra_if
*)ifp
->info
)->sdl
;
1190 msg
.rtm
.rtm_addrs
|= RTA_NETMASK
;
1191 else if (message
== RTM_ADD
|| message
== RTM_CHANGE
)
1192 msg
.rtm
.rtm_flags
|= RTF_HOST
;
1196 msg
.rtm
.rtm_addrs
|= RTA_SRC
;
1197 msg
.rtm
.rtm_flags
|= RTF_MPLS
;
1199 if (mpls
->smpls
.smpls_label
1200 != htonl(MPLS_LABEL_IMPLICIT_NULL
<< MPLS_LABEL_OFFSET
))
1201 msg
.rtm
.rtm_mpls
= MPLS_OP_PUSH
;
1205 /* Tagging route with flags */
1206 msg
.rtm
.rtm_flags
|= (RTF_PROTO1
);
1209 case BLACKHOLE_UNSPEC
:
1211 case BLACKHOLE_REJECT
:
1212 msg
.rtm
.rtm_flags
|= RTF_REJECT
;
1214 case BLACKHOLE_NULL
:
1215 case BLACKHOLE_ADMINPROHIB
:
1216 msg
.rtm
.rtm_flags
|= RTF_BLACKHOLE
;
1221 #define SOCKADDRSET(X, R) \
1222 if (msg.rtm.rtm_addrs & (R)) { \
1223 int len = SAROUNDUP(X); \
1224 memcpy(pnt, (caddr_t)(X), len); \
1228 pnt
= (caddr_t
)msg
.buf
;
1230 /* Write each socket data into rtm message buffer */
1231 SOCKADDRSET(dest
, RTA_DST
);
1232 SOCKADDRSET(gate
, RTA_GATEWAY
);
1233 SOCKADDRSET(mask
, RTA_NETMASK
);
1235 SOCKADDRSET(mpls
, RTA_SRC
);
1238 msg
.rtm
.rtm_msglen
= pnt
- (caddr_t
)&msg
;
1240 ret
= write(dplane_routing_sock
, &msg
, msg
.rtm
.rtm_msglen
);
1242 if (ret
!= msg
.rtm
.rtm_msglen
) {
1243 if (errno
== EEXIST
)
1244 return ZEBRA_ERR_RTEXIST
;
1245 if (errno
== ENETUNREACH
)
1246 return ZEBRA_ERR_RTUNREACH
;
1248 return ZEBRA_ERR_RTNOEXIST
;
1250 flog_err_sys(EC_LIB_SOCKET
, "%s: write : %s (%d)", __func__
,
1251 safe_strerror(errno
), errno
);
1252 return ZEBRA_ERR_KERNEL
;
1254 return ZEBRA_ERR_NOERROR
;
1258 #include "frrevent.h"
1259 #include "zebra/zserv.h"
1261 /* For debug purpose. */
1262 static void rtmsg_debug(struct rt_msghdr
*rtm
)
1266 zlog_debug("Kernel: Len: %d Type: %s", rtm
->rtm_msglen
,
1267 lookup_msg(rtm_type_str
, rtm
->rtm_type
, NULL
));
1268 rtm_flag_dump(rtm
->rtm_flags
);
1269 zlog_debug("Kernel: message seq %d", rtm
->rtm_seq
);
1270 zlog_debug("Kernel: pid %lld, rtm_addrs {%s}", (long long)rtm
->rtm_pid
,
1271 rtatostr(rtm
->rtm_addrs
, fbuf
, sizeof(fbuf
)));
1274 /* This is pretty gross, better suggestions welcome -- mhandler */
1277 #define RTAX_MAX RTA_NUMBITS
1280 #endif /* RTA_NUMBITS */
1281 #endif /* RTAX_MAX */
1283 /* Kernel routing table and interface updates via routing socket. */
1284 static void kernel_read(struct event
*thread
)
1288 struct rt_msghdr
*rtm
;
1291 * This must be big enough for any message the kernel might send.
1292 * Rather than determining how many sockaddrs of what size might be
1293 * in each particular message, just use RTAX_MAX of sockaddr_storage
1294 * for each. Note that the sockaddrs must be after each message
1295 * definition, or rather after whichever happens to be the largest,
1296 * since the buffer needs to be big enough for a message and the
1297 * sockaddrs together.
1300 /* Routing information. */
1302 struct rt_msghdr rtm
;
1303 struct sockaddr_storage addr
[RTAX_MAX
];
1306 /* Interface information. */
1308 struct if_msghdr ifm
;
1309 struct sockaddr_storage addr
[RTAX_MAX
];
1312 /* Interface address information. */
1314 struct ifa_msghdr ifa
;
1315 struct sockaddr_storage addr
[RTAX_MAX
];
1318 #ifdef RTM_IFANNOUNCE
1319 /* Interface arrival/departure */
1321 struct if_announcemsghdr ifan
;
1322 struct sockaddr_storage addr
[RTAX_MAX
];
1324 #endif /* RTM_IFANNOUNCE */
1328 /* Fetch routing socket. */
1329 sock
= EVENT_FD(thread
);
1331 nbytes
= read(sock
, &buf
, sizeof(buf
));
1334 if (errno
== ENOBUFS
) {
1337 * ENOBUFS indicates a temporary resource
1338 * shortage and is not harmful for consistency of
1339 * reading the routing socket. Ignore it.
1341 event_add_read(zrouter
.master
, kernel_read
, NULL
, sock
,
1345 flog_err(EC_ZEBRA_RECVMSG_OVERRUN
,
1346 "routing socket overrun: %s",
1347 safe_strerror(errno
));
1349 * In this case we are screwed.
1350 * There is no good way to
1351 * recover zebra at this point.
1356 if (errno
!= EAGAIN
&& errno
!= EWOULDBLOCK
)
1357 flog_err_sys(EC_LIB_SOCKET
, "routing socket error: %s",
1358 safe_strerror(errno
));
1365 event_add_read(zrouter
.master
, kernel_read
, NULL
, sock
, NULL
);
1367 if (IS_ZEBRA_DEBUG_KERNEL
)
1368 rtmsg_debug(&buf
.r
.rtm
);
1373 * Ensure that we didn't drop any data, so that processing routines
1374 * can assume they have the whole message.
1376 if (rtm
->rtm_msglen
!= nbytes
) {
1377 zlog_debug("%s: rtm->rtm_msglen %d, nbytes %d, type %d",
1378 __func__
, rtm
->rtm_msglen
, nbytes
, rtm
->rtm_type
);
1382 switch (rtm
->rtm_type
) {
1389 ifm_read(&buf
.im
.ifm
);
1393 ifam_read(&buf
.ia
.ifa
);
1395 #ifdef RTM_IFANNOUNCE
1396 case RTM_IFANNOUNCE
:
1397 ifan_read(&buf
.ian
.ifan
);
1399 #endif /* RTM_IFANNOUNCE */
1401 if (IS_ZEBRA_DEBUG_KERNEL
)
1403 "Unprocessed RTM_type: %s(%d)",
1404 lookup_msg(rtm_type_str
, rtm
->rtm_type
, NULL
),
1410 /* Make routing socket. */
1411 static void routing_socket(struct zebra_ns
*zns
)
1413 uint32_t default_rcvbuf
;
1416 frr_with_privs(&zserv_privs
) {
1417 routing_sock
= ns_socket(AF_ROUTE
, SOCK_RAW
, 0, zns
->ns_id
);
1419 dplane_routing_sock
=
1420 ns_socket(AF_ROUTE
, SOCK_RAW
, 0, zns
->ns_id
);
1423 if (routing_sock
< 0) {
1424 flog_err_sys(EC_LIB_SOCKET
, "Can't init kernel routing socket");
1428 if (dplane_routing_sock
< 0) {
1429 flog_err_sys(EC_LIB_SOCKET
,
1430 "Can't init kernel dataplane routing socket");
1435 /* Allow reporting of route(4) buffer overflow errors */
1438 if (setsockopt(routing_sock
, SOL_SOCKET
, SO_RERROR
, &n
, sizeof(n
)) < 0)
1439 flog_err_sys(EC_LIB_SOCKET
,
1440 "Can't set SO_RERROR on routing socket");
1443 /* XXX: Socket should be NONBLOCK, however as we currently
1444 * discard failed writes, this will lead to inconsistencies.
1445 * For now, socket must be blocking.
1447 /*if (fcntl (routing_sock, F_SETFL, O_NONBLOCK) < 0)
1448 zlog_warn ("Can't set O_NONBLOCK to routing socket");*/
1451 * Attempt to set a more useful receive buffer size
1453 optlen
= sizeof(default_rcvbuf
);
1454 if (getsockopt(routing_sock
, SOL_SOCKET
, SO_RCVBUF
, &default_rcvbuf
,
1456 flog_err_sys(EC_LIB_SOCKET
,
1457 "routing_sock sockopt SOL_SOCKET SO_RCVBUF");
1459 for (; rcvbufsize
> default_rcvbuf
&&
1460 setsockopt(routing_sock
, SOL_SOCKET
, SO_RCVBUF
,
1461 &rcvbufsize
, sizeof(rcvbufsize
)) == -1 &&
1467 /* kernel_read needs rewrite. */
1468 event_add_read(zrouter
.master
, kernel_read
, NULL
, routing_sock
, NULL
);
1471 /* Exported interface function. This function simply calls
1472 routing_socket (). */
1473 void kernel_init(struct zebra_ns
*zns
)
1475 routing_socket(zns
);
1478 void kernel_terminate(struct zebra_ns
*zns
, bool complete
)
1484 * Global init for platform-/OS-specific things
1486 void kernel_router_init(void)
1491 * Global deinit for platform-/OS-specific things
1493 void kernel_router_terminate(void)
1498 * Called by the dplane pthread to read incoming OS messages and dispatch them.
1500 int kernel_dplane_read(struct zebra_dplane_info
*info
)
1505 void kernel_update_multi(struct dplane_ctx_list_head
*ctx_list
)
1507 struct zebra_dplane_ctx
*ctx
;
1508 struct dplane_ctx_list_head handled_list
;
1509 enum zebra_dplane_result res
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1511 dplane_ctx_q_init(&handled_list
);
1514 ctx
= dplane_ctx_dequeue(ctx_list
);
1519 * A previous provider plugin may have asked to skip the
1522 if (dplane_ctx_is_skip_kernel(ctx
)) {
1523 res
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1527 switch (dplane_ctx_get_op(ctx
)) {
1529 case DPLANE_OP_ROUTE_INSTALL
:
1530 case DPLANE_OP_ROUTE_UPDATE
:
1531 case DPLANE_OP_ROUTE_DELETE
:
1532 res
= kernel_route_update(ctx
);
1535 case DPLANE_OP_NH_INSTALL
:
1536 case DPLANE_OP_NH_UPDATE
:
1537 case DPLANE_OP_NH_DELETE
:
1538 res
= kernel_nexthop_update(ctx
);
1541 case DPLANE_OP_LSP_INSTALL
:
1542 case DPLANE_OP_LSP_UPDATE
:
1543 case DPLANE_OP_LSP_DELETE
:
1544 res
= kernel_lsp_update(ctx
);
1547 case DPLANE_OP_PW_INSTALL
:
1548 case DPLANE_OP_PW_UNINSTALL
:
1549 res
= kernel_pw_update(ctx
);
1552 case DPLANE_OP_ADDR_INSTALL
:
1553 case DPLANE_OP_ADDR_UNINSTALL
:
1554 res
= kernel_address_update_ctx(ctx
);
1557 case DPLANE_OP_MAC_INSTALL
:
1558 case DPLANE_OP_MAC_DELETE
:
1559 res
= kernel_mac_update_ctx(ctx
);
1562 case DPLANE_OP_NEIGH_INSTALL
:
1563 case DPLANE_OP_NEIGH_UPDATE
:
1564 case DPLANE_OP_NEIGH_DELETE
:
1565 case DPLANE_OP_VTEP_ADD
:
1566 case DPLANE_OP_VTEP_DELETE
:
1567 case DPLANE_OP_NEIGH_DISCOVER
:
1568 res
= kernel_neigh_update_ctx(ctx
);
1571 case DPLANE_OP_RULE_ADD
:
1572 case DPLANE_OP_RULE_DELETE
:
1573 case DPLANE_OP_RULE_UPDATE
:
1574 res
= kernel_pbr_rule_update(ctx
);
1577 case DPLANE_OP_INTF_INSTALL
:
1578 case DPLANE_OP_INTF_UPDATE
:
1579 case DPLANE_OP_INTF_DELETE
:
1580 res
= kernel_intf_update(ctx
);
1583 case DPLANE_OP_TC_QDISC_INSTALL
:
1584 case DPLANE_OP_TC_QDISC_UNINSTALL
:
1585 case DPLANE_OP_TC_CLASS_ADD
:
1586 case DPLANE_OP_TC_CLASS_DELETE
:
1587 case DPLANE_OP_TC_CLASS_UPDATE
:
1588 case DPLANE_OP_TC_FILTER_ADD
:
1589 case DPLANE_OP_TC_FILTER_DELETE
:
1590 case DPLANE_OP_TC_FILTER_UPDATE
:
1591 res
= kernel_tc_update(ctx
);
1594 /* Ignore 'notifications' - no-op */
1595 case DPLANE_OP_SYS_ROUTE_ADD
:
1596 case DPLANE_OP_SYS_ROUTE_DELETE
:
1597 case DPLANE_OP_ROUTE_NOTIFY
:
1598 case DPLANE_OP_LSP_NOTIFY
:
1599 res
= ZEBRA_DPLANE_REQUEST_SUCCESS
;
1602 case DPLANE_OP_INTF_NETCONFIG
:
1603 res
= kernel_intf_netconf_update(ctx
);
1606 case DPLANE_OP_NONE
:
1607 case DPLANE_OP_BR_PORT_UPDATE
:
1608 case DPLANE_OP_IPTABLE_ADD
:
1609 case DPLANE_OP_IPTABLE_DELETE
:
1610 case DPLANE_OP_IPSET_ADD
:
1611 case DPLANE_OP_IPSET_DELETE
:
1612 case DPLANE_OP_IPSET_ENTRY_ADD
:
1613 case DPLANE_OP_IPSET_ENTRY_DELETE
:
1614 case DPLANE_OP_NEIGH_IP_INSTALL
:
1615 case DPLANE_OP_NEIGH_IP_DELETE
:
1616 case DPLANE_OP_NEIGH_TABLE_UPDATE
:
1617 case DPLANE_OP_GRE_SET
:
1618 case DPLANE_OP_INTF_ADDR_ADD
:
1619 case DPLANE_OP_INTF_ADDR_DEL
:
1620 zlog_err("Unhandled dplane data for %s",
1621 dplane_op2str(dplane_ctx_get_op(ctx
)));
1622 res
= ZEBRA_DPLANE_REQUEST_FAILURE
;
1626 dplane_ctx_set_status(ctx
, res
);
1628 dplane_ctx_enqueue_tail(&handled_list
, ctx
);
1631 dplane_ctx_q_init(ctx_list
);
1632 dplane_ctx_list_append(ctx_list
, &handled_list
);
1635 #endif /* !HAVE_NETLINK */