1 /* Kernel communication using routing socket.
2 * Copyright (C) 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra 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
11 * GNU Zebra 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.
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
25 #include <net/if_types.h>
27 #include <netmpls/mpls.h>
32 #include "sockunion.h"
33 #include "connected.h"
35 #include "zebra_memory.h"
42 #include "lib_errors.h"
45 #include "zebra/interface.h"
46 #include "zebra/zserv.h"
47 #include "zebra/debug.h"
48 #include "zebra/kernel_socket.h"
49 #include "zebra/rib.h"
50 #include "zebra/zebra_errors.h"
52 extern struct zebra_privs_t zserv_privs
;
55 * Historically, the BSD routing socket has aligned data following a
56 * struct sockaddr to sizeof(long), which was 4 bytes on some
57 * platforms, and 8 bytes on others. NetBSD 6 changed the routing
58 * socket to align to sizeof(uint64_t), which is 8 bytes. OS X
59 * appears to align to sizeof(int), which is 4 bytes.
61 * Alignment of zero-sized sockaddrs is nonsensical, but historically
62 * BSD defines RT_ROUNDUP(0) to be the alignment interval (rather than
63 * 0). We follow this practice without questioning it, but it is a
64 * bug if quagga calls ROUNDUP with 0.
68 * Because of these varying conventions, the only sane approach is for
69 * the <net/route.h> header to define some flavor of ROUNDUP macro.
73 /* SAROUNDUP is the only thing we need, and SA_SIZE provides that */
74 #define SAROUNDUP(a) SA_SIZE(a)
77 #if defined(RT_ROUNDUP)
78 #define ROUNDUP(a) RT_ROUNDUP(a)
79 #endif /* defined(RT_ROUNDUP) */
82 /* Solaris has struct sockaddr_in[6] definitions at 16 / 32 bytes size,
83 * so the whole concept doesn't really apply. */
84 #define ROUNDUP(a) (a)
88 * If ROUNDUP has not yet been defined in terms of platform-provided
89 * defines, attempt to cope with heuristics.
94 * If you're porting to a platform that changed RT_ROUNDUP but doesn't
95 * have it in its headers, this will break rather obviously and you'll
96 * have to fix it here.
99 /* OS X (Xcode as of 2014-12) is known not to define RT_ROUNDUP */
101 #define ROUNDUP_TYPE int
103 #define ROUNDUP_TYPE long
107 ((a) > 0 ? (1 + (((a)-1) | (sizeof(ROUNDUP_TYPE) - 1))) \
108 : sizeof(ROUNDUP_TYPE))
110 #endif /* defined(ROUNDUP) */
113 * Given a pointer (sockaddr or void *), return the number of bytes
114 * taken up by the sockaddr and any padding needed for alignment.
116 #if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
117 #define SAROUNDUP(X) ROUNDUP(((struct sockaddr *)(X))->sa_len)
120 * One would hope all fixed-size structure definitions are aligned,
121 * but round them up nonetheless.
123 #define SAROUNDUP(X) \
124 (((struct sockaddr *)(X))->sa_family == AF_INET \
125 ? ROUNDUP(sizeof(struct sockaddr_in)) \
126 : (((struct sockaddr *)(X))->sa_family == AF_INET6 \
127 ? ROUNDUP(sizeof(struct sockaddr_in6)) \
128 : (((struct sockaddr *)(X))->sa_family == AF_LINK \
129 ? ROUNDUP(sizeof(struct sockaddr_dl)) \
130 : sizeof(struct sockaddr))))
131 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
133 #endif /* !SA_SIZE */
136 * We use a call to an inline function to copy (PNT) to (DEST)
137 * 1. Calculating the length of the copy requires an #ifdef to determine
138 * if sa_len is a field and can't be used directly inside a #define
139 * 2. So the compiler doesn't complain when DEST is NULL, which is only true
140 * when we are skipping the copy and incrementing to the next SA
142 static inline void rta_copy(union sockunion
*dest
, caddr_t src
)
147 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
148 len
= (((struct sockaddr
*)src
)->sa_len
> sizeof(*dest
))
150 : ((struct sockaddr
*)src
)->sa_len
;
152 len
= (SAROUNDUP(src
) > sizeof(*dest
)) ? sizeof(*dest
) : SAROUNDUP(src
);
154 memcpy(dest
, src
, len
);
157 #define RTA_ADDR_GET(DEST, RTA, RTMADDRS, PNT) \
158 if ((RTMADDRS) & (RTA)) { \
159 int len = SAROUNDUP((PNT)); \
160 if (af_check(((struct sockaddr *)(PNT))->sa_family)) \
161 rta_copy((DEST), (PNT)); \
164 #define RTA_ATTR_GET(DEST, RTA, RTMADDRS, PNT) \
165 if ((RTMADDRS) & (RTA)) { \
166 int len = SAROUNDUP((PNT)); \
167 rta_copy((DEST), (PNT)); \
171 #define RTA_NAME_GET(DEST, RTA, RTMADDRS, PNT, LEN) \
172 if ((RTMADDRS) & (RTA)) { \
173 uint8_t *pdest = (uint8_t *)(DEST); \
174 int len = SAROUNDUP((PNT)); \
175 struct sockaddr_dl *sdl = (struct sockaddr_dl *)(PNT); \
176 if (IS_ZEBRA_DEBUG_KERNEL) \
177 zlog_debug("%s: RTA_SDL_GET nlen %d, alen %d", \
178 __func__, sdl->sdl_nlen, sdl->sdl_alen); \
179 if (((DEST) != NULL) && (sdl->sdl_family == AF_LINK) \
180 && (sdl->sdl_nlen < IFNAMSIZ) && (sdl->sdl_nlen <= len)) { \
181 memcpy(pdest, sdl->sdl_data, sdl->sdl_nlen); \
182 pdest[sdl->sdl_nlen] = '\0'; \
183 (LEN) = sdl->sdl_nlen; \
189 /* Routing socket message types. */
190 const struct message rtm_type_str
[] = {{RTM_ADD
, "RTM_ADD"},
191 {RTM_DELETE
, "RTM_DELETE"},
192 {RTM_CHANGE
, "RTM_CHANGE"},
193 {RTM_GET
, "RTM_GET"},
194 {RTM_LOSING
, "RTM_LOSING"},
195 {RTM_REDIRECT
, "RTM_REDIRECT"},
196 {RTM_MISS
, "RTM_MISS"},
197 {RTM_LOCK
, "RTM_LOCK"},
199 {RTM_OLDADD
, "RTM_OLDADD"},
200 #endif /* RTM_OLDADD */
202 {RTM_OLDDEL
, "RTM_OLDDEL"},
203 #endif /* RTM_OLDDEL */
204 {RTM_RESOLVE
, "RTM_RESOLVE"},
205 {RTM_NEWADDR
, "RTM_NEWADDR"},
206 {RTM_DELADDR
, "RTM_DELADDR"},
207 {RTM_IFINFO
, "RTM_IFINFO"},
209 {RTM_OIFINFO
, "RTM_OIFINFO"},
210 #endif /* RTM_OIFINFO */
212 {RTM_NEWMADDR
, "RTM_NEWMADDR"},
213 #endif /* RTM_NEWMADDR */
215 {RTM_DELMADDR
, "RTM_DELMADDR"},
216 #endif /* RTM_DELMADDR */
217 #ifdef RTM_IFANNOUNCE
218 {RTM_IFANNOUNCE
, "RTM_IFANNOUNCE"},
219 #endif /* RTM_IFANNOUNCE */
222 static const struct message rtm_flag_str
[] = {{RTF_UP
, "UP"},
223 {RTF_GATEWAY
, "GATEWAY"},
225 {RTF_REJECT
, "REJECT"},
226 {RTF_DYNAMIC
, "DYNAMIC"},
227 {RTF_MODIFIED
, "MODIFIED"},
231 #endif /* RTF_MASK */
233 {RTF_CLONING
, "CLONING"},
234 #endif /* RTF_CLONING */
236 {RTF_XRESOLVE
, "XRESOLVE"},
237 #endif /* RTF_XRESOLVE */
239 {RTF_LLINFO
, "LLINFO"},
240 #endif /* RTF_LLINFO */
241 {RTF_STATIC
, "STATIC"},
242 {RTF_BLACKHOLE
, "BLACKHOLE"},
244 {RTF_PRIVATE
, "PRIVATE"},
245 #endif /* RTF_PRIVATE */
246 {RTF_PROTO1
, "PROTO1"},
247 {RTF_PROTO2
, "PROTO2"},
249 {RTF_PRCLONING
, "PRCLONING"},
250 #endif /* RTF_PRCLONING */
252 {RTF_WASCLONED
, "WASCLONED"},
253 #endif /* RTF_WASCLONED */
255 {RTF_PROTO3
, "PROTO3"},
256 #endif /* RTF_PROTO3 */
258 {RTF_PINNED
, "PINNED"},
259 #endif /* RTF_PINNED */
261 {RTF_LOCAL
, "LOCAL"},
262 #endif /* RTF_LOCAL */
264 {RTF_BROADCAST
, "BROADCAST"},
265 #endif /* RTF_BROADCAST */
267 {RTF_MULTICAST
, "MULTICAST"},
268 #endif /* RTF_MULTICAST */
270 {RTF_MULTIRT
, "MULTIRT"},
271 #endif /* RTF_MULTIRT */
273 {RTF_SETSRC
, "SETSRC"},
274 #endif /* RTF_SETSRC */
277 /* Kernel routing update socket. */
278 int routing_sock
= -1;
280 /* Yes I'm checking ugly routing socket behavior. */
283 /* Supported address family check. */
284 static inline int af_check(int family
)
286 if (family
== AF_INET
)
288 if (family
== AF_INET6
)
293 /* Dump routing table flag for debug purpose. */
294 static void rtm_flag_dump(int flag
)
296 const struct message
*mes
;
297 static char buf
[BUFSIZ
];
300 for (mes
= rtm_flag_str
; mes
->key
!= 0; mes
++) {
301 if (mes
->key
& flag
) {
302 strlcat(buf
, mes
->str
, BUFSIZ
);
303 strlcat(buf
, " ", BUFSIZ
);
306 zlog_debug("Kernel: %s", buf
);
309 #ifdef RTM_IFANNOUNCE
310 /* Interface adding function */
311 static int ifan_read(struct if_announcemsghdr
*ifan
)
313 struct interface
*ifp
;
315 ifp
= if_lookup_by_index(ifan
->ifan_index
, VRF_DEFAULT
);
318 assert((ifp
->ifindex
== ifan
->ifan_index
)
319 || (ifp
->ifindex
== IFINDEX_INTERNAL
));
321 if ((ifp
== NULL
) || ((ifp
->ifindex
== IFINDEX_INTERNAL
)
322 && (ifan
->ifan_what
== IFAN_ARRIVAL
))) {
323 if (IS_ZEBRA_DEBUG_KERNEL
)
325 "%s: creating interface for ifindex %d, name %s",
326 __func__
, ifan
->ifan_index
, ifan
->ifan_name
);
328 /* Create Interface */
329 ifp
= if_get_by_name(ifan
->ifan_name
, VRF_DEFAULT
, 0);
330 if_set_index(ifp
, ifan
->ifan_index
);
334 } else if (ifp
!= NULL
&& ifan
->ifan_what
== IFAN_DEPARTURE
)
335 if_delete_update(ifp
);
341 if (IS_ZEBRA_DEBUG_KERNEL
)
342 zlog_debug("%s: interface %s index %d", __func__
,
343 ifan
->ifan_name
, ifan
->ifan_index
);
347 #endif /* RTM_IFANNOUNCE */
349 #ifdef HAVE_BSD_IFI_LINK_STATE
350 /* BSD link detect translation */
351 static void bsd_linkdetect_translate(struct if_msghdr
*ifm
)
353 if ((ifm
->ifm_data
.ifi_link_state
>= LINK_STATE_UP
)
354 || (ifm
->ifm_data
.ifi_link_state
== LINK_STATE_UNKNOWN
))
355 SET_FLAG(ifm
->ifm_flags
, IFF_RUNNING
);
357 UNSET_FLAG(ifm
->ifm_flags
, IFF_RUNNING
);
359 #endif /* HAVE_BSD_IFI_LINK_STATE */
361 static enum zebra_link_type
sdl_to_zebra_link_type(unsigned int sdlt
)
365 return ZEBRA_LLT_ETHER
;
367 return ZEBRA_LLT_X25
;
369 return ZEBRA_LLT_FDDI
;
371 return ZEBRA_LLT_PPP
;
373 return ZEBRA_LLT_LOOPBACK
;
375 return ZEBRA_LLT_SLIP
;
377 return ZEBRA_LLT_ARCNET
;
379 return ZEBRA_LLT_ATM
;
381 return ZEBRA_LLT_LOCALTLK
;
383 return ZEBRA_LLT_HIPPI
;
386 return ZEBRA_LLT_IEEE1394
;
390 return ZEBRA_LLT_UNKNOWN
;
395 * Handle struct if_msghdr obtained from reading routing socket or
396 * sysctl (from interface_list). There may or may not be sockaddrs
397 * present after the header.
399 int ifm_read(struct if_msghdr
*ifm
)
401 struct interface
*ifp
= NULL
;
402 struct sockaddr_dl
*sdl
;
403 char ifname
[IFNAMSIZ
];
407 /* terminate ifname at head (for strnlen) and tail (for safety) */
408 ifname
[IFNAMSIZ
- 1] = '\0';
410 /* paranoia: sanity check structure */
411 if (ifm
->ifm_msglen
< sizeof(struct if_msghdr
)) {
412 flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR
,
413 "ifm_read: ifm->ifm_msglen %d too short\n",
419 * Check for a sockaddr_dl following the message. First, point to
420 * where a socakddr might be if one follows the message.
422 cp
= (void *)(ifm
+ 1);
426 * XXX This behavior should be narrowed to only the kernel versions
427 * for which the structures returned do not match the headers.
429 * if_msghdr_t on 64 bit kernels in Solaris 9 and earlier versions
430 * is 12 bytes larger than the 32 bit version.
432 if (((struct sockaddr
*)cp
)->sa_family
== AF_UNSPEC
)
436 RTA_ADDR_GET(NULL
, RTA_DST
, ifm
->ifm_addrs
, cp
);
437 RTA_ADDR_GET(NULL
, RTA_GATEWAY
, ifm
->ifm_addrs
, cp
);
438 RTA_ATTR_GET(NULL
, RTA_NETMASK
, ifm
->ifm_addrs
, cp
);
439 RTA_ADDR_GET(NULL
, RTA_GENMASK
, ifm
->ifm_addrs
, cp
);
440 sdl
= (struct sockaddr_dl
*)cp
;
441 RTA_NAME_GET(ifname
, RTA_IFP
, ifm
->ifm_addrs
, cp
, ifnlen
);
442 RTA_ADDR_GET(NULL
, RTA_IFA
, ifm
->ifm_addrs
, cp
);
443 RTA_ADDR_GET(NULL
, RTA_AUTHOR
, ifm
->ifm_addrs
, cp
);
444 RTA_ADDR_GET(NULL
, RTA_BRD
, ifm
->ifm_addrs
, cp
);
446 RTA_ATTR_GET(NULL
, RTA_LABEL
, ifm
->ifm_addrs
, cp
);
449 RTA_ADDR_GET(NULL
, RTA_SRC
, ifm
->ifm_addrs
, cp
);
452 if (IS_ZEBRA_DEBUG_KERNEL
)
453 zlog_debug("%s: sdl ifname %s", __func__
,
454 (ifnlen
? ifname
: "(nil)"));
457 * Look up on ifindex first, because ifindices are the primary handle
459 * interfaces across the user/kernel boundary, for most systems. (Some
460 * messages, such as up/down status changes on NetBSD, do not include a
463 if ((ifp
= if_lookup_by_index(ifm
->ifm_index
, VRF_DEFAULT
)) != NULL
) {
464 /* we have an ifp, verify that the name matches as some systems,
465 * eg Solaris, have a 1:many association of ifindex:ifname
466 * if they dont match, we dont have the correct ifp and should
467 * set it back to NULL to let next check do lookup by name
469 if (ifnlen
&& (strncmp(ifp
->name
, ifname
, IFNAMSIZ
) != 0)) {
470 if (IS_ZEBRA_DEBUG_KERNEL
)
472 "%s: ifp name %s doesnt match sdl name %s",
473 __func__
, ifp
->name
, ifname
);
479 * If we dont have an ifp, try looking up by name. Particularly as some
480 * systems (Solaris) have a 1:many mapping of ifindex:ifname - the
482 * is therefore our unique handle to that interface.
484 * Interfaces specified in the configuration file for which the ifindex
485 * has not been determined will have ifindex == IFINDEX_INTERNAL, and
487 * interfaces are found by this search, and then their ifindex values
491 if ((ifp
== NULL
) && ifnlen
)
492 ifp
= if_lookup_by_name(ifname
, VRF_DEFAULT
);
495 * If ifp still does not exist or has an invalid index
496 * (IFINDEX_INTERNAL),
497 * create or fill in an interface.
499 if ((ifp
== NULL
) || (ifp
->ifindex
== IFINDEX_INTERNAL
)) {
501 * To create or fill in an interface, a sockaddr_dl (via
502 * RTA_IFP) is required.
505 zlog_warn("Interface index %d (new) missing ifname\n",
510 #ifndef RTM_IFANNOUNCE
511 /* Down->Down interface should be ignored here.
512 * See further comment below.
514 if (!CHECK_FLAG(ifm
->ifm_flags
, IFF_UP
))
516 #endif /* !RTM_IFANNOUNCE */
519 /* Interface that zebra was not previously aware of, so
521 ifp
= if_create(ifname
, VRF_DEFAULT
);
522 if (IS_ZEBRA_DEBUG_KERNEL
)
523 zlog_debug("%s: creating ifp for ifindex %d",
524 __func__
, ifm
->ifm_index
);
527 if (IS_ZEBRA_DEBUG_KERNEL
)
529 "%s: updated/created ifp, ifname %s, ifindex %d",
530 __func__
, ifp
->name
, ifp
->ifindex
);
532 * Fill in newly created interface structure, or larval
533 * structure with ifindex IFINDEX_INTERNAL.
535 if_set_index(ifp
, ifm
->ifm_index
);
537 #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
538 bsd_linkdetect_translate(ifm
);
539 #endif /* HAVE_BSD_IFI_LINK_STATE */
541 if_flags_update(ifp
, ifm
->ifm_flags
);
542 #if defined(__bsdi__)
546 #endif /* __bsdi__ */
550 * XXX sockaddr_dl contents can be larger than the structure
551 * definition. There are 2 big families here:
552 * - BSD has sdl_len + sdl_data[16] + overruns sdl_data
553 * we MUST use sdl_len here or we'll truncate data.
554 * - Solaris has no sdl_len, but sdl_data[244]
555 * presumably, it's not going to run past that, so sizeof()
557 * a nonzero ifnlen from RTA_NAME_GET() means sdl is valid
559 ifp
->ll_type
= ZEBRA_LLT_UNKNOWN
;
560 ifp
->hw_addr_len
= 0;
562 #ifdef HAVE_STRUCT_SOCKADDR_DL_SDL_LEN
563 memcpy(&((struct zebra_if
*)ifp
->info
)->sdl
, sdl
,
566 memcpy(&((struct zebra_if
*)ifp
->info
)->sdl
, sdl
,
567 sizeof(struct sockaddr_dl
));
568 #endif /* HAVE_STRUCT_SOCKADDR_DL_SDL_LEN */
570 ifp
->ll_type
= sdl_to_zebra_link_type(sdl
->sdl_type
);
571 if (sdl
->sdl_alen
<= sizeof(ifp
->hw_addr
)) {
572 memcpy(ifp
->hw_addr
, LLADDR(sdl
),
574 ifp
->hw_addr_len
= sdl
->sdl_alen
;
581 * Interface structure exists. Adjust stored flags from
582 * notification. If interface has up->down or down->up
583 * transition, call state change routines (to adjust routes,
584 * notify routing daemons, etc.). (Other flag changes are stored
585 * but apparently do not trigger action.)
588 if (ifp
->ifindex
!= ifm
->ifm_index
) {
590 "%s: index mismatch, ifname %s, ifp index %d, "
592 __func__
, ifp
->name
, ifp
->ifindex
,
597 #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
598 bsd_linkdetect_translate(ifm
);
599 #endif /* HAVE_BSD_IFI_LINK_STATE */
601 /* update flags and handle operative->inoperative transition, if
603 if_flags_update(ifp
, ifm
->ifm_flags
);
605 #ifndef RTM_IFANNOUNCE
606 if (!if_is_up(ifp
)) {
607 /* No RTM_IFANNOUNCE on this platform, so we can never
608 * distinguish between ~IFF_UP and delete. We must
610 * it has been deleted.
611 * Eg, Solaris will not notify us of unplumb.
613 * XXX: Fixme - this should be runtime detected
614 * So that a binary compiled on a system with IFANNOUNCE
615 * will still behave correctly if run on a platform
618 if_delete_update(ifp
);
620 #endif /* RTM_IFANNOUNCE */
622 #if defined(__bsdi__)
626 #endif /* __bsdi__ */
631 #ifdef HAVE_NET_RT_IFLIST
632 ifp
->stats
= ifm
->ifm_data
;
633 #endif /* HAVE_NET_RT_IFLIST */
634 ifp
->speed
= ifm
->ifm_data
.ifi_baudrate
/ 1000000;
636 if (IS_ZEBRA_DEBUG_KERNEL
)
637 zlog_debug("%s: interface %s index %d", __func__
, ifp
->name
,
643 /* Address read from struct ifa_msghdr. */
644 static void ifam_read_mesg(struct ifa_msghdr
*ifm
, union sockunion
*addr
,
645 union sockunion
*mask
, union sockunion
*brd
,
646 char *ifname
, short *ifnlen
)
650 union sockunion gateway
;
652 pnt
= (caddr_t
)(ifm
+ 1);
653 end
= ((caddr_t
)ifm
) + ifm
->ifam_msglen
;
655 /* Be sure structure is cleared */
656 memset(mask
, 0, sizeof(union sockunion
));
657 memset(addr
, 0, sizeof(union sockunion
));
658 memset(brd
, 0, sizeof(union sockunion
));
659 memset(&dst
, 0, sizeof(union sockunion
));
660 memset(&gateway
, 0, sizeof(union sockunion
));
662 /* We fetch each socket variable into sockunion. */
663 RTA_ADDR_GET(&dst
, RTA_DST
, ifm
->ifam_addrs
, pnt
);
664 RTA_ADDR_GET(&gateway
, RTA_GATEWAY
, ifm
->ifam_addrs
, pnt
);
665 RTA_ATTR_GET(mask
, RTA_NETMASK
, ifm
->ifam_addrs
, pnt
);
666 RTA_ADDR_GET(NULL
, RTA_GENMASK
, ifm
->ifam_addrs
, pnt
);
667 RTA_NAME_GET(ifname
, RTA_IFP
, ifm
->ifam_addrs
, pnt
, *ifnlen
);
668 RTA_ADDR_GET(addr
, RTA_IFA
, ifm
->ifam_addrs
, pnt
);
669 RTA_ADDR_GET(NULL
, RTA_AUTHOR
, ifm
->ifam_addrs
, pnt
);
670 RTA_ADDR_GET(brd
, RTA_BRD
, ifm
->ifam_addrs
, pnt
);
672 RTA_ATTR_GET(NULL
, RTA_LABEL
, ifm
->ifam_addrs
, pnt
);
675 RTA_ADDR_GET(NULL
, RTA_SRC
, ifm
->ifam_addrs
, pnt
);
678 if (IS_ZEBRA_DEBUG_KERNEL
) {
679 int family
= sockunion_family(addr
);
683 char buf
[4][INET6_ADDRSTRLEN
];
685 "%s: ifindex %d, ifname %s, ifam_addrs 0x%x, "
686 "ifam_flags 0x%x, addr %s/%d broad %s dst %s "
688 __func__
, ifm
->ifam_index
,
689 (ifnlen
? ifname
: "(nil)"), ifm
->ifam_addrs
,
691 inet_ntop(family
, &addr
->sin
.sin_addr
, buf
[0],
693 ip_masklen(mask
->sin
.sin_addr
),
694 inet_ntop(family
, &brd
->sin
.sin_addr
, buf
[1],
696 inet_ntop(family
, &dst
.sin
.sin_addr
, buf
[2],
698 inet_ntop(family
, &gateway
.sin
.sin_addr
, buf
[3],
702 zlog_debug("%s: ifindex %d, ifname %s, ifam_addrs 0x%x",
703 __func__
, ifm
->ifam_index
,
704 (ifnlen
? ifname
: "(nil)"),
710 /* Assert read up end point matches to end point */
712 zlog_warn("ifam_read() doesn't read all socket data");
715 /* Interface's address information get. */
716 int ifam_read(struct ifa_msghdr
*ifam
)
718 struct interface
*ifp
= NULL
;
719 union sockunion addr
, mask
, brd
;
720 char ifname
[INTERFACE_NAMSIZ
];
725 ifname
[0] = ifname
[INTERFACE_NAMSIZ
- 1] = '\0';
727 /* Allocate and read address information. */
728 ifam_read_mesg(ifam
, &addr
, &mask
, &brd
, ifname
, &ifnlen
);
730 if ((ifp
= if_lookup_by_index(ifam
->ifam_index
, VRF_DEFAULT
)) == NULL
) {
731 zlog_warn("%s: no interface for ifname %s, index %d", __func__
,
732 ifname
, ifam
->ifam_index
);
736 if (ifnlen
&& strncmp(ifp
->name
, ifname
, INTERFACE_NAMSIZ
))
739 /* N.B. The info in ifa_msghdr does not tell us whether the RTA_BRD
740 field contains a broadcast address or a peer address, so we are
742 rely upon the interface type. */
743 if (if_is_pointopoint(ifp
))
744 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
747 /* it might seem cute to grab the interface metric here, however
748 * we're processing an address update message, and so some systems
749 * (e.g. FBSD) dont bother to fill in ifam_metric. Disabled, but left
750 * in deliberately, as comment.
752 ifp
->metric
= ifam
->ifam_metric
;
755 /* Add connected address. */
756 switch (sockunion_family(&addr
)) {
758 if (ifam
->ifam_type
== RTM_NEWADDR
)
759 connected_add_ipv4(ifp
, flags
, &addr
.sin
.sin_addr
,
760 ip_masklen(mask
.sin
.sin_addr
),
762 (isalias
? ifname
: NULL
));
764 connected_delete_ipv4(ifp
, flags
, &addr
.sin
.sin_addr
,
765 ip_masklen(mask
.sin
.sin_addr
),
769 /* Unset interface index from link-local address when IPv6 stack
771 if (IN6_IS_ADDR_LINKLOCAL(&addr
.sin6
.sin6_addr
)) {
772 SET_IN6_LINKLOCAL_IFINDEX(addr
.sin6
.sin6_addr
, 0);
775 if (ifam
->ifam_type
== RTM_NEWADDR
)
776 connected_add_ipv6(ifp
, flags
, &addr
.sin6
.sin6_addr
,
778 ip6_masklen(mask
.sin6
.sin6_addr
),
779 (isalias
? ifname
: NULL
));
781 connected_delete_ipv6(ifp
, &addr
.sin6
.sin6_addr
, NULL
,
782 ip6_masklen(mask
.sin6
.sin6_addr
));
785 /* Unsupported family silently ignore... */
789 /* Check interface flag for implicit up of the interface. */
793 /* In addition to lacking IFANNOUNCE, on SUNOS IFF_UP is strange.
794 * See comments for SUNOS_5 in interface.c::if_flags_mangle.
796 * Here we take care of case where the real IFF_UP was previously
797 * unset (as kept in struct zebra_if.primary_state) and the mangled
798 * IFF_UP (ie IFF_UP set || listcount(connected) has now transitioned
799 * to unset due to the lost non-primary address having DELADDR'd.
801 * we must delete the interface, because in between here and next
802 * event for this interface-name the administrator could unplumb
803 * and replumb the interface.
806 if_delete_update(ifp
);
812 /* Interface function for reading kernel routing table information. */
813 static int rtm_read_mesg(struct rt_msghdr
*rtm
, union sockunion
*dest
,
814 union sockunion
*mask
, union sockunion
*gate
,
815 char *ifname
, short *ifnlen
)
819 /* Pnt points out socket data start point. */
820 pnt
= (caddr_t
)(rtm
+ 1);
821 end
= ((caddr_t
)rtm
) + rtm
->rtm_msglen
;
823 /* rt_msghdr version check. */
824 if (rtm
->rtm_version
!= RTM_VERSION
)
826 "Routing message version different %d should be %d."
827 "This may cause problem\n",
828 rtm
->rtm_version
, RTM_VERSION
);
830 /* Be sure structure is cleared */
831 memset(dest
, 0, sizeof(union sockunion
));
832 memset(gate
, 0, sizeof(union sockunion
));
833 memset(mask
, 0, sizeof(union sockunion
));
835 /* We fetch each socket variable into sockunion. */
836 RTA_ADDR_GET(dest
, RTA_DST
, rtm
->rtm_addrs
, pnt
);
837 RTA_ADDR_GET(gate
, RTA_GATEWAY
, rtm
->rtm_addrs
, pnt
);
838 RTA_ATTR_GET(mask
, RTA_NETMASK
, rtm
->rtm_addrs
, pnt
);
839 RTA_ADDR_GET(NULL
, RTA_GENMASK
, rtm
->rtm_addrs
, pnt
);
840 RTA_NAME_GET(ifname
, RTA_IFP
, rtm
->rtm_addrs
, pnt
, *ifnlen
);
841 RTA_ADDR_GET(NULL
, RTA_IFA
, rtm
->rtm_addrs
, pnt
);
842 RTA_ADDR_GET(NULL
, RTA_AUTHOR
, rtm
->rtm_addrs
, pnt
);
843 RTA_ADDR_GET(NULL
, RTA_BRD
, rtm
->rtm_addrs
, pnt
);
846 union sockunion label
;
847 memset(&label
, 0, sizeof(label
));
848 RTA_ATTR_GET(&label
, RTA_LABEL
, rtm
->rtm_addrs
, pnt
);
850 RTA_ATTR_GET(NULL
, RTA_LABEL
, rtm
->rtm_addrs
, pnt
);
853 RTA_ADDR_GET(NULL
, RTA_SRC
, rtm
->rtm_addrs
, pnt
);
856 /* If there is netmask information set it's family same as
858 if (rtm
->rtm_addrs
& RTA_NETMASK
)
859 mask
->sa
.sa_family
= dest
->sa
.sa_family
;
861 /* Assert read up to the end of pointer. */
863 zlog_warn("rtm_read() doesn't read all socket data.");
865 return rtm
->rtm_flags
;
868 void rtm_read(struct rt_msghdr
*rtm
)
872 union sockunion dest
, mask
, gate
;
873 char ifname
[INTERFACE_NAMSIZ
+ 1];
879 /* Read destination and netmask and gateway from rtm message
881 flags
= rtm_read_mesg(rtm
, &dest
, &mask
, &gate
, ifname
, &ifnlen
);
882 if (!(flags
& RTF_DONE
))
884 if (IS_ZEBRA_DEBUG_KERNEL
)
885 zlog_debug("%s: got rtm of type %d (%s)", __func__
,
887 lookup_msg(rtm_type_str
, rtm
->rtm_type
, NULL
));
889 #ifdef RTF_CLONED /*bsdi, netbsd 1.6*/
890 if (flags
& RTF_CLONED
)
893 #ifdef RTF_WASCLONED /*freebsd*/
894 if (flags
& RTF_WASCLONED
)
898 if ((rtm
->rtm_type
== RTM_ADD
|| rtm
->rtm_type
== RTM_CHANGE
)
899 && !(flags
& RTF_UP
))
902 /* This is connected route. */
903 if (!(flags
& RTF_GATEWAY
))
906 if (flags
& RTF_PROTO1
)
907 SET_FLAG(zebra_flags
, ZEBRA_FLAG_SELFROUTE
);
909 /* This is persistent route. */
910 if (flags
& RTF_STATIC
)
911 SET_FLAG(zebra_flags
, ZEBRA_FLAG_STATIC
);
913 memset(&nh
, 0, sizeof(nh
));
915 nh
.vrf_id
= VRF_DEFAULT
;
916 /* This is a reject or blackhole route */
917 if (flags
& RTF_REJECT
) {
918 nh
.type
= NEXTHOP_TYPE_BLACKHOLE
;
919 nh
.bh_type
= BLACKHOLE_REJECT
;
920 } else if (flags
& RTF_BLACKHOLE
) {
921 nh
.type
= NEXTHOP_TYPE_BLACKHOLE
;
922 nh
.bh_type
= BLACKHOLE_NULL
;
925 if (dest
.sa
.sa_family
== AF_INET
) {
929 p
.u
.prefix4
= dest
.sin
.sin_addr
;
930 if (flags
& RTF_HOST
)
931 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
933 p
.prefixlen
= ip_masklen(mask
.sin
.sin_addr
);
935 /* Catch self originated messages and match them against our
937 * At the same time, ignore unconfirmed messages, they should be
939 * by rtm_write() and kernel_rtm_ipv4().
941 if (rtm
->rtm_type
!= RTM_GET
&& rtm
->rtm_pid
== pid
) {
942 char buf
[PREFIX_STRLEN
], gate_buf
[INET_ADDRSTRLEN
];
944 if (!IS_ZEBRA_DEBUG_RIB
)
946 ret
= rib_lookup_ipv4_route((struct prefix_ipv4
*)&p
,
948 prefix2str(&p
, buf
, sizeof(buf
));
949 switch (rtm
->rtm_type
) {
953 /* The kernel notifies us about a new route in
955 Do we have a correspondent entry in our RIB?
958 case ZEBRA_RIB_NOTFOUND
:
960 "%s: %s %s: desync: RR isn't yet in RIB, while already in FIB",
962 lookup_msg(rtm_type_str
,
963 rtm
->rtm_type
, NULL
),
966 case ZEBRA_RIB_FOUND_CONNECTED
:
967 case ZEBRA_RIB_FOUND_NOGATE
:
968 inet_ntop(AF_INET
, &gate
.sin
.sin_addr
,
969 gate_buf
, INET_ADDRSTRLEN
);
971 "%s: %s %s: desync: RR is in RIB, but gate differs (ours is %s)",
973 lookup_msg(rtm_type_str
,
974 rtm
->rtm_type
, NULL
),
977 case ZEBRA_RIB_FOUND_EXACT
: /* RIB RR == FIB RR
980 "%s: %s %s: done Ok", __func__
,
981 lookup_msg(rtm_type_str
,
982 rtm
->rtm_type
, NULL
),
985 (struct prefix_ipv4
*)&p
,
992 /* The kernel notifies us about a route deleted
994 have it in the RIB? Do we have anything
997 case ZEBRA_RIB_FOUND_EXACT
:
999 "%s: %s %s: desync: RR is still in RIB, while already not in FIB",
1001 lookup_msg(rtm_type_str
,
1002 rtm
->rtm_type
, NULL
),
1004 rib_lookup_and_dump(
1005 (struct prefix_ipv4
*)&p
,
1008 case ZEBRA_RIB_FOUND_CONNECTED
:
1009 case ZEBRA_RIB_FOUND_NOGATE
:
1011 "%s: %s %s: desync: RR is still in RIB, plus gate differs",
1013 lookup_msg(rtm_type_str
,
1014 rtm
->rtm_type
, NULL
),
1016 rib_lookup_and_dump(
1017 (struct prefix_ipv4
*)&p
,
1020 case ZEBRA_RIB_NOTFOUND
: /* RIB RR == FIB RR */
1022 "%s: %s %s: done Ok", __func__
,
1023 lookup_msg(rtm_type_str
,
1024 rtm
->rtm_type
, NULL
),
1026 rib_lookup_and_dump(
1027 (struct prefix_ipv4
*)&p
,
1035 "%s: %s: warning: loopback RTM of type %s received",
1037 lookup_msg(rtm_type_str
, rtm
->rtm_type
,
1043 /* Change, delete the old prefix, we have no further information
1044 * to specify the route really
1046 if (rtm
->rtm_type
== RTM_CHANGE
)
1047 rib_delete(AFI_IP
, SAFI_UNICAST
, VRF_DEFAULT
,
1048 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1049 NULL
, 0, 0, 0, true);
1052 nh
.type
= NEXTHOP_TYPE_IPV4
;
1053 nh
.gate
.ipv4
= gate
.sin
.sin_addr
;
1056 if (rtm
->rtm_type
== RTM_GET
|| rtm
->rtm_type
== RTM_ADD
1057 || rtm
->rtm_type
== RTM_CHANGE
)
1058 rib_add(AFI_IP
, SAFI_UNICAST
, VRF_DEFAULT
,
1059 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1060 &nh
, 0, 0, 0, 0, 0);
1062 rib_delete(AFI_IP
, SAFI_UNICAST
, VRF_DEFAULT
,
1063 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1064 &nh
, 0, 0, 0, true);
1066 if (dest
.sa
.sa_family
== AF_INET6
) {
1067 /* One day we might have a debug section here like one in the
1068 * IPv4 case above. Just ignore own messages at the moment.
1070 if (rtm
->rtm_type
!= RTM_GET
&& rtm
->rtm_pid
== pid
)
1073 ifindex_t ifindex
= 0;
1075 p
.family
= AF_INET6
;
1076 p
.u
.prefix6
= dest
.sin6
.sin6_addr
;
1077 if (flags
& RTF_HOST
)
1078 p
.prefixlen
= IPV6_MAX_PREFIXLEN
;
1080 p
.prefixlen
= ip6_masklen(mask
.sin6
.sin6_addr
);
1083 if (IN6_IS_ADDR_LINKLOCAL(&gate
.sin6
.sin6_addr
)) {
1084 ifindex
= IN6_LINKLOCAL_IFINDEX(gate
.sin6
.sin6_addr
);
1085 SET_IN6_LINKLOCAL_IFINDEX(gate
.sin6
.sin6_addr
, 0);
1089 /* CHANGE: delete the old prefix, we have no further information
1090 * to specify the route really
1092 if (rtm
->rtm_type
== RTM_CHANGE
)
1093 rib_delete(AFI_IP6
, SAFI_UNICAST
, VRF_DEFAULT
,
1094 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1095 NULL
, 0, 0, 0, true);
1098 nh
.type
= ifindex
? NEXTHOP_TYPE_IPV6_IFINDEX
1099 : NEXTHOP_TYPE_IPV6
;
1100 nh
.gate
.ipv6
= gate
.sin6
.sin6_addr
;
1101 nh
.ifindex
= ifindex
;
1104 if (rtm
->rtm_type
== RTM_GET
|| rtm
->rtm_type
== RTM_ADD
1105 || rtm
->rtm_type
== RTM_CHANGE
)
1106 rib_add(AFI_IP6
, SAFI_UNICAST
, VRF_DEFAULT
,
1107 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1108 &nh
, 0, 0, 0, 0, 0);
1110 rib_delete(AFI_IP6
, SAFI_UNICAST
, VRF_DEFAULT
,
1111 ZEBRA_ROUTE_KERNEL
, 0, zebra_flags
, &p
, NULL
,
1112 &nh
, 0, 0, 0, true);
1116 /* Interface function for the kernel routing table updates. Support
1117 * for RTM_CHANGE will be needed.
1118 * Exported only for rt_socket.c
1120 int rtm_write(int message
, union sockunion
*dest
, union sockunion
*mask
,
1121 union sockunion
*gate
, union sockunion
*mpls
, unsigned int index
,
1122 enum blackhole_type bh_type
, int metric
)
1126 struct interface
*ifp
;
1128 /* Sequencial number of routing message. */
1129 static int msg_seq
= 0;
1131 /* Struct of rt_msghdr and buffer for storing socket's data. */
1133 struct rt_msghdr rtm
;
1137 if (routing_sock
< 0)
1138 return ZEBRA_ERR_EPERM
;
1140 /* Clear and set rt_msghdr values */
1141 memset(&msg
, 0, sizeof(struct rt_msghdr
));
1142 msg
.rtm
.rtm_version
= RTM_VERSION
;
1143 msg
.rtm
.rtm_type
= message
;
1144 msg
.rtm
.rtm_seq
= msg_seq
++;
1145 msg
.rtm
.rtm_addrs
= RTA_DST
;
1146 msg
.rtm
.rtm_addrs
|= RTA_GATEWAY
;
1147 msg
.rtm
.rtm_flags
= RTF_UP
;
1149 msg
.rtm
.rtm_flags
|= RTF_MPATH
;
1150 msg
.rtm
.rtm_fmask
= RTF_MPLS
;
1152 msg
.rtm
.rtm_index
= index
;
1155 msg
.rtm
.rtm_rmx
.rmx_hopcount
= metric
;
1156 msg
.rtm
.rtm_inits
|= RTV_HOPCOUNT
;
1159 ifp
= if_lookup_by_index(index
, VRF_DEFAULT
);
1161 if (gate
&& (message
== RTM_ADD
|| message
== RTM_CHANGE
))
1162 msg
.rtm
.rtm_flags
|= RTF_GATEWAY
;
1164 /* When RTF_CLONING is unavailable on BSD, should we set some
1165 * other flag instead?
1168 if (!gate
&& (message
== RTM_ADD
|| message
== RTM_CHANGE
) && ifp
1169 && (ifp
->flags
& IFF_POINTOPOINT
) == 0)
1170 msg
.rtm
.rtm_flags
|= RTF_CLONING
;
1171 #endif /* RTF_CLONING */
1173 /* If no protocol specific gateway is specified, use link
1174 address for gateway. */
1177 char dest_buf
[INET_ADDRSTRLEN
] = "NULL",
1178 mask_buf
[INET_ADDRSTRLEN
] = "255.255.255.255";
1180 inet_ntop(AF_INET
, &dest
->sin
.sin_addr
,
1181 dest_buf
, INET_ADDRSTRLEN
);
1183 inet_ntop(AF_INET
, &mask
->sin
.sin_addr
,
1184 mask_buf
, INET_ADDRSTRLEN
);
1186 "%s: %s/%s: gate == NULL and no gateway found for ifindex %d",
1187 __func__
, dest_buf
, mask_buf
, index
);
1190 gate
= (union sockunion
*)&((struct zebra_if
*)ifp
->info
)->sdl
;
1194 msg
.rtm
.rtm_addrs
|= RTA_NETMASK
;
1195 else if (message
== RTM_ADD
|| message
== RTM_CHANGE
)
1196 msg
.rtm
.rtm_flags
|= RTF_HOST
;
1200 msg
.rtm
.rtm_addrs
|= RTA_SRC
;
1201 msg
.rtm
.rtm_flags
|= RTF_MPLS
;
1203 if (mpls
->smpls
.smpls_label
1204 != htonl(MPLS_LABEL_IMPLICIT_NULL
<< MPLS_LABEL_OFFSET
))
1205 msg
.rtm
.rtm_mpls
= MPLS_OP_PUSH
;
1209 /* Tagging route with flags */
1210 msg
.rtm
.rtm_flags
|= (RTF_PROTO1
);
1213 case BLACKHOLE_UNSPEC
:
1215 case BLACKHOLE_REJECT
:
1216 msg
.rtm
.rtm_flags
|= RTF_REJECT
;
1219 msg
.rtm
.rtm_flags
|= RTF_BLACKHOLE
;
1224 #define SOCKADDRSET(X, R) \
1225 if (msg.rtm.rtm_addrs & (R)) { \
1226 int len = SAROUNDUP(X); \
1227 memcpy(pnt, (caddr_t)(X), len); \
1231 pnt
= (caddr_t
)msg
.buf
;
1233 /* Write each socket data into rtm message buffer */
1234 SOCKADDRSET(dest
, RTA_DST
);
1235 SOCKADDRSET(gate
, RTA_GATEWAY
);
1236 SOCKADDRSET(mask
, RTA_NETMASK
);
1238 SOCKADDRSET(mpls
, RTA_SRC
);
1241 msg
.rtm
.rtm_msglen
= pnt
- (caddr_t
)&msg
;
1243 ret
= write(routing_sock
, &msg
, msg
.rtm
.rtm_msglen
);
1245 if (ret
!= msg
.rtm
.rtm_msglen
) {
1246 if (errno
== EEXIST
)
1247 return ZEBRA_ERR_RTEXIST
;
1248 if (errno
== ENETUNREACH
)
1249 return ZEBRA_ERR_RTUNREACH
;
1251 return ZEBRA_ERR_RTNOEXIST
;
1253 zlog_warn("%s: write : %s (%d)", __func__
, safe_strerror(errno
),
1255 return ZEBRA_ERR_KERNEL
;
1257 return ZEBRA_ERR_NOERROR
;
1262 #include "zebra/zserv.h"
1264 /* For debug purpose. */
1265 static void rtmsg_debug(struct rt_msghdr
*rtm
)
1267 zlog_debug("Kernel: Len: %d Type: %s", rtm
->rtm_msglen
,
1268 lookup_msg(rtm_type_str
, rtm
->rtm_type
, NULL
));
1269 rtm_flag_dump(rtm
->rtm_flags
);
1270 zlog_debug("Kernel: message seq %d", rtm
->rtm_seq
);
1271 zlog_debug("Kernel: pid %lld, rtm_addrs 0x%x", (long long)rtm
->rtm_pid
,
1275 /* This is pretty gross, better suggestions welcome -- mhandler */
1278 #define RTAX_MAX RTA_NUMBITS
1281 #endif /* RTA_NUMBITS */
1282 #endif /* RTAX_MAX */
1284 /* Kernel routing table and interface updates via routing socket. */
1285 static int kernel_read(struct thread
*thread
)
1289 struct rt_msghdr
*rtm
;
1292 * This must be big enough for any message the kernel might send.
1293 * Rather than determining how many sockaddrs of what size might be
1294 * in each particular message, just use RTAX_MAX of sockaddr_storage
1295 * for each. Note that the sockaddrs must be after each message
1296 * definition, or rather after whichever happens to be the largest,
1297 * since the buffer needs to be big enough for a message and the
1298 * sockaddrs together.
1301 /* Routing information. */
1303 struct rt_msghdr rtm
;
1304 struct sockaddr_storage addr
[RTAX_MAX
];
1307 /* Interface information. */
1309 struct if_msghdr ifm
;
1310 struct sockaddr_storage addr
[RTAX_MAX
];
1313 /* Interface address information. */
1315 struct ifa_msghdr ifa
;
1316 struct sockaddr_storage addr
[RTAX_MAX
];
1319 #ifdef RTM_IFANNOUNCE
1320 /* Interface arrival/departure */
1322 struct if_announcemsghdr ifan
;
1323 struct sockaddr_storage addr
[RTAX_MAX
];
1325 #endif /* RTM_IFANNOUNCE */
1329 /* Fetch routing socket. */
1330 sock
= THREAD_FD(thread
);
1332 nbytes
= read(sock
, &buf
, sizeof buf
);
1335 if (nbytes
< 0 && errno
!= EWOULDBLOCK
&& errno
!= EAGAIN
)
1336 zlog_warn("routing socket error: %s",
1337 safe_strerror(errno
));
1341 thread_add_read(zebrad
.master
, kernel_read
, NULL
, sock
, NULL
);
1343 if (IS_ZEBRA_DEBUG_KERNEL
)
1344 rtmsg_debug(&buf
.r
.rtm
);
1349 * Ensure that we didn't drop any data, so that processing routines
1350 * can assume they have the whole message.
1352 if (rtm
->rtm_msglen
!= nbytes
) {
1354 "kernel_read: rtm->rtm_msglen %d, nbytes %d, type %d\n",
1355 rtm
->rtm_msglen
, nbytes
, rtm
->rtm_type
);
1359 switch (rtm
->rtm_type
) {
1366 ifm_read(&buf
.im
.ifm
);
1370 ifam_read(&buf
.ia
.ifa
);
1372 #ifdef RTM_IFANNOUNCE
1373 case RTM_IFANNOUNCE
:
1374 ifan_read(&buf
.ian
.ifan
);
1376 #endif /* RTM_IFANNOUNCE */
1378 if (IS_ZEBRA_DEBUG_KERNEL
)
1379 zlog_debug("Unprocessed RTM_type: %d", rtm
->rtm_type
);
1385 /* Make routing socket. */
1386 static void routing_socket(struct zebra_ns
*zns
)
1388 frr_elevate_privs(&zserv_privs
) {
1389 routing_sock
= ns_socket(AF_ROUTE
, SOCK_RAW
, 0, zns
->ns_id
);
1392 if (routing_sock
< 0) {
1393 zlog_warn("Can't init kernel routing socket");
1397 /* XXX: Socket should be NONBLOCK, however as we currently
1398 * discard failed writes, this will lead to inconsistencies.
1399 * For now, socket must be blocking.
1401 /*if (fcntl (routing_sock, F_SETFL, O_NONBLOCK) < 0)
1402 zlog_warn ("Can't set O_NONBLOCK to routing socket");*/
1404 /* kernel_read needs rewrite. */
1405 thread_add_read(zebrad
.master
, kernel_read
, NULL
, routing_sock
, NULL
);
1408 /* Exported interface function. This function simply calls
1409 routing_socket (). */
1410 void kernel_init(struct zebra_ns
*zns
)
1412 routing_socket(zns
);
1415 void kernel_terminate(struct zebra_ns
*zns
)
1420 #endif /* !HAVE_NETLINK */