blob: cde36bd034447eeb6b683308dcc438b0cf2af42e [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Kernel communication using routing socket.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include "if.h"
25#include "prefix.h"
26#include "sockunion.h"
27#include "connected.h"
28#include "memory.h"
29#include "ioctl.h"
30#include "log.h"
31#include "str.h"
32#include "table.h"
33#include "rib.h"
pauledd7c242003-06-04 13:59:38 +000034#include "privs.h"
paul718e3742002-12-13 20:15:29 +000035
36#include "zebra/interface.h"
37#include "zebra/zserv.h"
38#include "zebra/debug.h"
paulec1a4282005-11-24 15:15:17 +000039#include "zebra/kernel_socket.h"
paul718e3742002-12-13 20:15:29 +000040
pauledd7c242003-06-04 13:59:38 +000041extern struct zebra_privs_t zserv_privs;
paul9bcdb632003-07-08 08:09:45 +000042extern struct zebra_t zebrad;
pauledd7c242003-06-04 13:59:38 +000043
gdt4bfbea82004-01-06 01:13:05 +000044/*
45 * Given a sockaddr length, round it up to include pad bytes following
46 * it. Assumes the kernel pads to sizeof(long).
47 *
48 * XXX: why is ROUNDUP(0) sizeof(long)? 0 is an illegal sockaddr
49 * length anyway (< sizeof (struct sockaddr)), so this shouldn't
50 * matter.
Doug VanLeuven3b33de62012-10-10 22:10:14 +000051 * On OS X, both 32, 64bit syatems align on 4 byte boundary
gdt4bfbea82004-01-06 01:13:05 +000052 */
Doug VanLeuven3b33de62012-10-10 22:10:14 +000053#ifdef __APPLE__
54#define ROUNDUP(a) \
55 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int) - 1))) : sizeof(int))
56#else
paul718e3742002-12-13 20:15:29 +000057#define ROUNDUP(a) \
58 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
Doug VanLeuven3b33de62012-10-10 22:10:14 +000059#endif
paul718e3742002-12-13 20:15:29 +000060
gdt4bfbea82004-01-06 01:13:05 +000061/*
62 * Given a pointer (sockaddr or void *), return the number of bytes
63 * taken up by the sockaddr and any padding needed for alignment.
64 */
Paul Jakma6f0e3f62007-05-10 02:38:51 +000065#if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
gdt4bfbea82004-01-06 01:13:05 +000066#define SAROUNDUP(X) ROUNDUP(((struct sockaddr *)(X))->sa_len)
paul30be8022003-10-22 02:51:38 +000067#elif defined(HAVE_IPV6)
gdt4bfbea82004-01-06 01:13:05 +000068/*
69 * One would hope all fixed-size structure definitions are aligned,
70 * but round them up nonetheless.
71 */
72#define SAROUNDUP(X) \
paul3e95a072003-09-24 00:05:45 +000073 (((struct sockaddr *)(X))->sa_family == AF_INET ? \
74 ROUNDUP(sizeof(struct sockaddr_in)):\
75 (((struct sockaddr *)(X))->sa_family == AF_INET6 ? \
76 ROUNDUP(sizeof(struct sockaddr_in6)) : \
77 (((struct sockaddr *)(X))->sa_family == AF_LINK ? \
paulc50ae8b2004-05-11 11:31:07 +000078 ROUNDUP(sizeof(struct sockaddr_dl)) : sizeof(struct sockaddr))))
paul30be8022003-10-22 02:51:38 +000079#else /* HAVE_IPV6 */
gdt4bfbea82004-01-06 01:13:05 +000080#define SAROUNDUP(X) \
paul30be8022003-10-22 02:51:38 +000081 (((struct sockaddr *)(X))->sa_family == AF_INET ? \
82 ROUNDUP(sizeof(struct sockaddr_in)):\
83 (((struct sockaddr *)(X))->sa_family == AF_LINK ? \
84 ROUNDUP(sizeof(struct sockaddr_dl)) : sizeof(struct sockaddr)))
Paul Jakma6f0e3f62007-05-10 02:38:51 +000085#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
paul718e3742002-12-13 20:15:29 +000086
Doug VanLeuvena05df8f2012-10-10 16:11:36 -070087/*
88 * We use a call to an inline function to copy (PNT) to (DEST)
89 * 1. Calculating the length of the copy requires an #ifdef to determine
90 * if sa_len is a field and can't be used directly inside a #define
91 * 2. So the compiler doesn't complain when DEST is NULL, which is only true
92 * when we are skipping the copy and incrementing to the next SA
paulec1a4282005-11-24 15:15:17 +000093 */
Doug VanLeuvena05df8f2012-10-10 16:11:36 -070094static void inline
95rta_copy (union sockunion *dest, caddr_t src) {
96 int len;
97#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
98 len = (((struct sockaddr *)src)->sa_len > sizeof (*dest)) ?
99 sizeof (*dest) : ((struct sockaddr *)src)->sa_len ;
100#else
101 len = (SAROUNDUP (src) > sizeof (*dest)) ?
102 sizeof (*dest) : SAROUNDUP (src) ;
103#endif
104 memcpy (dest, src, len);
105}
106
paul62debbb2005-06-14 14:07:07 +0000107#define RTA_ADDR_GET(DEST, RTA, RTMADDRS, PNT) \
108 if ((RTMADDRS) & (RTA)) \
109 { \
110 int len = SAROUNDUP ((PNT)); \
paulea6f82b2005-06-28 17:20:26 +0000111 if ( ((DEST) != NULL) && \
paul62debbb2005-06-14 14:07:07 +0000112 af_check (((struct sockaddr *)(PNT))->sa_family)) \
Doug VanLeuvena05df8f2012-10-10 16:11:36 -0700113 rta_copy((DEST), (PNT)); \
paul62debbb2005-06-14 14:07:07 +0000114 (PNT) += len; \
115 }
116#define RTA_ATTR_GET(DEST, RTA, RTMADDRS, PNT) \
117 if ((RTMADDRS) & (RTA)) \
118 { \
119 int len = SAROUNDUP ((PNT)); \
paulec1a4282005-11-24 15:15:17 +0000120 if ((DEST) != NULL) \
Doug VanLeuvena05df8f2012-10-10 16:11:36 -0700121 rta_copy((DEST), (PNT)); \
paul62debbb2005-06-14 14:07:07 +0000122 (PNT) += len; \
123 }
124
paul6fe70d12005-11-12 22:55:10 +0000125#define RTA_NAME_GET(DEST, RTA, RTMADDRS, PNT, LEN) \
126 if ((RTMADDRS) & (RTA)) \
127 { \
paulec1a4282005-11-24 15:15:17 +0000128 u_char *pdest = (u_char *) (DEST); \
paul6fe70d12005-11-12 22:55:10 +0000129 int len = SAROUNDUP ((PNT)); \
130 struct sockaddr_dl *sdl = (struct sockaddr_dl *)(PNT); \
131 if (IS_ZEBRA_DEBUG_KERNEL) \
132 zlog_debug ("%s: RTA_SDL_GET nlen %d, alen %d", \
133 __func__, sdl->sdl_nlen, sdl->sdl_alen); \
134 if ( ((DEST) != NULL) && (sdl->sdl_family == AF_LINK) \
135 && (sdl->sdl_nlen < IFNAMSIZ) && (sdl->sdl_nlen <= len) ) \
136 { \
paulec1a4282005-11-24 15:15:17 +0000137 memcpy (pdest, sdl->sdl_data, sdl->sdl_nlen); \
138 pdest[sdl->sdl_nlen] = '\0'; \
paul6fe70d12005-11-12 22:55:10 +0000139 (LEN) = sdl->sdl_nlen; \
140 } \
141 (PNT) += len; \
142 } \
143 else \
144 { \
145 (LEN) = 0; \
146 }
paul718e3742002-12-13 20:15:29 +0000147/* Routing socket message types. */
Stephen Hemminger1423c802008-08-14 17:59:25 +0100148const struct message rtm_type_str[] =
paul718e3742002-12-13 20:15:29 +0000149{
150 {RTM_ADD, "RTM_ADD"},
151 {RTM_DELETE, "RTM_DELETE"},
152 {RTM_CHANGE, "RTM_CHANGE"},
153 {RTM_GET, "RTM_GET"},
154 {RTM_LOSING, "RTM_LOSING"},
155 {RTM_REDIRECT, "RTM_REDIRECT"},
156 {RTM_MISS, "RTM_MISS"},
157 {RTM_LOCK, "RTM_LOCK"},
Greg Troxel9458b812006-09-13 12:13:08 +0000158#ifdef OLDADD
paul718e3742002-12-13 20:15:29 +0000159 {RTM_OLDADD, "RTM_OLDADD"},
Greg Troxel9458b812006-09-13 12:13:08 +0000160#endif /* RTM_OLDADD */
161#ifdef RTM_OLDDEL
paul718e3742002-12-13 20:15:29 +0000162 {RTM_OLDDEL, "RTM_OLDDEL"},
Greg Troxel9458b812006-09-13 12:13:08 +0000163#endif /* RTM_OLDDEL */
paul718e3742002-12-13 20:15:29 +0000164 {RTM_RESOLVE, "RTM_RESOLVE"},
165 {RTM_NEWADDR, "RTM_NEWADDR"},
166 {RTM_DELADDR, "RTM_DELADDR"},
167 {RTM_IFINFO, "RTM_IFINFO"},
168#ifdef RTM_OIFINFO
169 {RTM_OIFINFO, "RTM_OIFINFO"},
170#endif /* RTM_OIFINFO */
171#ifdef RTM_NEWMADDR
172 {RTM_NEWMADDR, "RTM_NEWMADDR"},
173#endif /* RTM_NEWMADDR */
174#ifdef RTM_DELMADDR
175 {RTM_DELMADDR, "RTM_DELMADDR"},
176#endif /* RTM_DELMADDR */
177#ifdef RTM_IFANNOUNCE
178 {RTM_IFANNOUNCE, "RTM_IFANNOUNCE"},
179#endif /* RTM_IFANNOUNCE */
180 {0, NULL}
181};
182
Stephen Hemmingerce0db9c2009-05-15 10:47:04 -0700183static const struct message rtm_flag_str[] =
paul718e3742002-12-13 20:15:29 +0000184{
185 {RTF_UP, "UP"},
186 {RTF_GATEWAY, "GATEWAY"},
187 {RTF_HOST, "HOST"},
188 {RTF_REJECT, "REJECT"},
189 {RTF_DYNAMIC, "DYNAMIC"},
190 {RTF_MODIFIED, "MODIFIED"},
191 {RTF_DONE, "DONE"},
192#ifdef RTF_MASK
193 {RTF_MASK, "MASK"},
194#endif /* RTF_MASK */
David Warde6f148e2009-12-03 21:43:11 +0300195#ifdef RTF_CLONING
paul718e3742002-12-13 20:15:29 +0000196 {RTF_CLONING, "CLONING"},
David Warde6f148e2009-12-03 21:43:11 +0300197#endif /* RTF_CLONING */
paul718e3742002-12-13 20:15:29 +0000198 {RTF_XRESOLVE, "XRESOLVE"},
199 {RTF_LLINFO, "LLINFO"},
200 {RTF_STATIC, "STATIC"},
201 {RTF_BLACKHOLE, "BLACKHOLE"},
paul6fe70d12005-11-12 22:55:10 +0000202#ifdef RTF_PRIVATE
203 {RTF_PRIVATE, "PRIVATE"},
204#endif /* RTF_PRIVATE */
paul718e3742002-12-13 20:15:29 +0000205 {RTF_PROTO1, "PROTO1"},
206 {RTF_PROTO2, "PROTO2"},
207#ifdef RTF_PRCLONING
208 {RTF_PRCLONING, "PRCLONING"},
209#endif /* RTF_PRCLONING */
210#ifdef RTF_WASCLONED
211 {RTF_WASCLONED, "WASCLONED"},
212#endif /* RTF_WASCLONED */
213#ifdef RTF_PROTO3
214 {RTF_PROTO3, "PROTO3"},
215#endif /* RTF_PROTO3 */
216#ifdef RTF_PINNED
217 {RTF_PINNED, "PINNED"},
218#endif /* RTF_PINNED */
219#ifdef RTF_LOCAL
220 {RTF_LOCAL, "LOCAL"},
221#endif /* RTF_LOCAL */
222#ifdef RTF_BROADCAST
223 {RTF_BROADCAST, "BROADCAST"},
224#endif /* RTF_BROADCAST */
225#ifdef RTF_MULTICAST
226 {RTF_MULTICAST, "MULTICAST"},
227#endif /* RTF_MULTICAST */
paul6fe70d12005-11-12 22:55:10 +0000228#ifdef RTF_MULTIRT
229 {RTF_MULTIRT, "MULTIRT"},
230#endif /* RTF_MULTIRT */
231#ifdef RTF_SETSRC
232 {RTF_SETSRC, "SETSRC"},
233#endif /* RTF_SETSRC */
paul718e3742002-12-13 20:15:29 +0000234 {0, NULL}
235};
236
237/* Kernel routing update socket. */
238int routing_sock = -1;
239
240/* Yes I'm checking ugly routing socket behavior. */
241/* #define DEBUG */
242
243/* Supported address family check. */
paul62debbb2005-06-14 14:07:07 +0000244static int inline
paul718e3742002-12-13 20:15:29 +0000245af_check (int family)
246{
247 if (family == AF_INET)
248 return 1;
249#ifdef HAVE_IPV6
250 if (family == AF_INET6)
251 return 1;
252#endif /* HAVE_IPV6 */
253 return 0;
254}
255
256/* Dump routing table flag for debug purpose. */
ajsb6178002004-12-07 21:12:56 +0000257static void
paul718e3742002-12-13 20:15:29 +0000258rtm_flag_dump (int flag)
259{
Tom Goff80b2a942009-12-03 14:53:15 +0300260 const struct message *mes;
paul718e3742002-12-13 20:15:29 +0000261 static char buf[BUFSIZ];
262
gdtcced60d2004-07-13 16:45:54 +0000263 buf[0] = '\0';
paul718e3742002-12-13 20:15:29 +0000264 for (mes = rtm_flag_str; mes->key != 0; mes++)
265 {
266 if (mes->key & flag)
267 {
268 strlcat (buf, mes->str, BUFSIZ);
269 strlcat (buf, " ", BUFSIZ);
270 }
271 }
ajsb6178002004-12-07 21:12:56 +0000272 zlog_debug ("Kernel: %s", buf);
paul718e3742002-12-13 20:15:29 +0000273}
274
275#ifdef RTM_IFANNOUNCE
276/* Interface adding function */
paul6621ca82005-11-23 13:02:08 +0000277static int
paul718e3742002-12-13 20:15:29 +0000278ifan_read (struct if_announcemsghdr *ifan)
279{
280 struct interface *ifp;
paul6fe70d12005-11-12 22:55:10 +0000281
paul718e3742002-12-13 20:15:29 +0000282 ifp = if_lookup_by_index (ifan->ifan_index);
paul6fe70d12005-11-12 22:55:10 +0000283
284 if (ifp)
285 assert ( (ifp->ifindex == ifan->ifan_index)
286 || (ifp->ifindex == IFINDEX_INTERNAL) );
287
paulec1a4282005-11-24 15:15:17 +0000288 if ( (ifp == NULL)
289 || ((ifp->ifindex == IFINDEX_INTERNAL)
290 && (ifan->ifan_what == IFAN_ARRIVAL)) )
paul718e3742002-12-13 20:15:29 +0000291 {
paul6fe70d12005-11-12 22:55:10 +0000292 if (IS_ZEBRA_DEBUG_KERNEL)
293 zlog_debug ("%s: creating interface for ifindex %d, name %s",
294 __func__, ifan->ifan_index, ifan->ifan_name);
295
paul718e3742002-12-13 20:15:29 +0000296 /* Create Interface */
ajs08dbfb62005-04-03 03:40:52 +0000297 ifp = if_get_by_name_len(ifan->ifan_name,
298 strnlen(ifan->ifan_name,
299 sizeof(ifan->ifan_name)));
paul718e3742002-12-13 20:15:29 +0000300 ifp->ifindex = ifan->ifan_index;
301
302 if_add_update (ifp);
303 }
304 else if (ifp != NULL && ifan->ifan_what == IFAN_DEPARTURE)
paul6eb88272005-07-29 14:36:00 +0000305 if_delete_update (ifp);
paul718e3742002-12-13 20:15:29 +0000306
307 if_get_flags (ifp);
308 if_get_mtu (ifp);
309 if_get_metric (ifp);
310
311 if (IS_ZEBRA_DEBUG_KERNEL)
paul6fe70d12005-11-12 22:55:10 +0000312 zlog_debug ("%s: interface %s index %d",
313 __func__, ifan->ifan_name, ifan->ifan_index);
paul718e3742002-12-13 20:15:29 +0000314
315 return 0;
316}
317#endif /* RTM_IFANNOUNCE */
318
Doug VanLeuven9234b382012-10-10 16:12:32 -0700319#ifdef HAVE_BSD_IFI_LINK_STATE
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000320/* BSD link detect translation */
321static void
322bsd_linkdetect_translate (struct if_msghdr *ifm)
323{
Andrew J. Schorr55edb0d2008-01-11 15:57:13 +0000324 if ((ifm->ifm_data.ifi_link_state >= LINK_STATE_UP) ||
325 (ifm->ifm_data.ifi_link_state == LINK_STATE_UNKNOWN))
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000326 SET_FLAG(ifm->ifm_flags, IFF_RUNNING);
327 else
328 UNSET_FLAG(ifm->ifm_flags, IFF_RUNNING);
329}
Doug VanLeuven9234b382012-10-10 16:12:32 -0700330#endif /* HAVE_BSD_IFI_LINK_STATE */
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000331
gdtda26e3b2004-01-05 17:20:59 +0000332/*
333 * Handle struct if_msghdr obtained from reading routing socket or
334 * sysctl (from interface_list). There may or may not be sockaddrs
335 * present after the header.
336 */
paulec1a4282005-11-24 15:15:17 +0000337int
paul718e3742002-12-13 20:15:29 +0000338ifm_read (struct if_msghdr *ifm)
339{
paul3e95a072003-09-24 00:05:45 +0000340 struct interface *ifp = NULL;
Tom Goffa34eb362009-11-25 20:36:06 +0000341 struct sockaddr_dl *sdl;
paul6fe70d12005-11-12 22:55:10 +0000342 char ifname[IFNAMSIZ];
343 short ifnlen = 0;
Doug VanLeuvena05df8f2012-10-10 16:11:36 -0700344 caddr_t cp;
paul6fe70d12005-11-12 22:55:10 +0000345
346 /* terminate ifname at head (for strnlen) and tail (for safety) */
347 ifname[IFNAMSIZ - 1] = '\0';
348
gdtda26e3b2004-01-05 17:20:59 +0000349 /* paranoia: sanity check structure */
350 if (ifm->ifm_msglen < sizeof(struct if_msghdr))
351 {
352 zlog_err ("ifm_read: ifm->ifm_msglen %d too short\n",
353 ifm->ifm_msglen);
354 return -1;
355 }
356
357 /*
gdt4bfbea82004-01-06 01:13:05 +0000358 * Check for a sockaddr_dl following the message. First, point to
359 * where a socakddr might be if one follows the message.
gdtda26e3b2004-01-05 17:20:59 +0000360 */
gdt4bfbea82004-01-06 01:13:05 +0000361 cp = (void *)(ifm + 1);
362
paul3e95a072003-09-24 00:05:45 +0000363#ifdef SUNOS_5
paul3e95a072003-09-24 00:05:45 +0000364 /*
gdt4bfbea82004-01-06 01:13:05 +0000365 * XXX This behavior should be narrowed to only the kernel versions
366 * for which the structures returned do not match the headers.
367 *
paul3e95a072003-09-24 00:05:45 +0000368 * if_msghdr_t on 64 bit kernels in Solaris 9 and earlier versions
gdt4bfbea82004-01-06 01:13:05 +0000369 * is 12 bytes larger than the 32 bit version.
paul3e95a072003-09-24 00:05:45 +0000370 */
gdt4bfbea82004-01-06 01:13:05 +0000371 if (((struct sockaddr *) cp)->sa_family == AF_UNSPEC)
paul3e95a072003-09-24 00:05:45 +0000372 cp = cp + 12;
paul3e95a072003-09-24 00:05:45 +0000373#endif
paul718e3742002-12-13 20:15:29 +0000374
paul6fe70d12005-11-12 22:55:10 +0000375 RTA_ADDR_GET (NULL, RTA_DST, ifm->ifm_addrs, cp);
376 RTA_ADDR_GET (NULL, RTA_GATEWAY, ifm->ifm_addrs, cp);
377 RTA_ATTR_GET (NULL, RTA_NETMASK, ifm->ifm_addrs, cp);
378 RTA_ADDR_GET (NULL, RTA_GENMASK, ifm->ifm_addrs, cp);
Tom Goffa34eb362009-11-25 20:36:06 +0000379 sdl = (struct sockaddr_dl *)cp;
paul6fe70d12005-11-12 22:55:10 +0000380 RTA_NAME_GET (ifname, RTA_IFP, ifm->ifm_addrs, cp, ifnlen);
381 RTA_ADDR_GET (NULL, RTA_IFA, ifm->ifm_addrs, cp);
382 RTA_ADDR_GET (NULL, RTA_AUTHOR, ifm->ifm_addrs, cp);
383 RTA_ADDR_GET (NULL, RTA_BRD, ifm->ifm_addrs, cp);
384
385 if (IS_ZEBRA_DEBUG_KERNEL)
386 zlog_debug ("%s: sdl ifname %s", __func__, (ifnlen ? ifname : "(nil)"));
387
gdt4bfbea82004-01-06 01:13:05 +0000388 /*
paul6fe70d12005-11-12 22:55:10 +0000389 * Look up on ifindex first, because ifindices are the primary handle for
390 * interfaces across the user/kernel boundary, for most systems. (Some
391 * messages, such as up/down status changes on NetBSD, do not include a
392 * sockaddr_dl).
gdt4bfbea82004-01-06 01:13:05 +0000393 */
paul6fe70d12005-11-12 22:55:10 +0000394 if ( (ifp = if_lookup_by_index (ifm->ifm_index)) != NULL )
gdt4bfbea82004-01-06 01:13:05 +0000395 {
paul6fe70d12005-11-12 22:55:10 +0000396 /* we have an ifp, verify that the name matches as some systems,
397 * eg Solaris, have a 1:many association of ifindex:ifname
398 * if they dont match, we dont have the correct ifp and should
399 * set it back to NULL to let next check do lookup by name
400 */
401 if (ifnlen && (strncmp (ifp->name, ifname, IFNAMSIZ) != 0) )
gdt4bfbea82004-01-06 01:13:05 +0000402 {
paul6fe70d12005-11-12 22:55:10 +0000403 if (IS_ZEBRA_DEBUG_KERNEL)
404 zlog_debug ("%s: ifp name %s doesnt match sdl name %s",
405 __func__, ifp->name, ifname);
406 ifp = NULL;
gdt4bfbea82004-01-06 01:13:05 +0000407 }
408 }
paul6fe70d12005-11-12 22:55:10 +0000409
gdtda26e3b2004-01-05 17:20:59 +0000410 /*
paul6fe70d12005-11-12 22:55:10 +0000411 * If we dont have an ifp, try looking up by name. Particularly as some
412 * systems (Solaris) have a 1:many mapping of ifindex:ifname - the ifname
413 * is therefore our unique handle to that interface.
414 *
415 * Interfaces specified in the configuration file for which the ifindex
416 * has not been determined will have ifindex == IFINDEX_INTERNAL, and such
417 * interfaces are found by this search, and then their ifindex values can
418 * be filled in.
gdtda26e3b2004-01-05 17:20:59 +0000419 */
paul6fe70d12005-11-12 22:55:10 +0000420 if ( (ifp == NULL) && ifnlen)
421 ifp = if_lookup_by_name (ifname);
paul718e3742002-12-13 20:15:29 +0000422
gdtda26e3b2004-01-05 17:20:59 +0000423 /*
paul6fe70d12005-11-12 22:55:10 +0000424 * If ifp still does not exist or has an invalid index (IFINDEX_INTERNAL),
425 * create or fill in an interface.
gdtda26e3b2004-01-05 17:20:59 +0000426 */
ajsd2fc8892005-04-02 18:38:43 +0000427 if ((ifp == NULL) || (ifp->ifindex == IFINDEX_INTERNAL))
paul718e3742002-12-13 20:15:29 +0000428 {
gdt4bfbea82004-01-06 01:13:05 +0000429 /*
430 * To create or fill in an interface, a sockaddr_dl (via
431 * RTA_IFP) is required.
432 */
paul6fe70d12005-11-12 22:55:10 +0000433 if (!ifnlen)
paul718e3742002-12-13 20:15:29 +0000434 {
paul6fe70d12005-11-12 22:55:10 +0000435 zlog_warn ("Interface index %d (new) missing ifname\n",
paul718e3742002-12-13 20:15:29 +0000436 ifm->ifm_index);
437 return -1;
438 }
paul5c78b3d2006-01-25 04:31:40 +0000439
440#ifndef RTM_IFANNOUNCE
441 /* Down->Down interface should be ignored here.
442 * See further comment below.
443 */
444 if (!CHECK_FLAG (ifm->ifm_flags, IFF_UP))
445 return 0;
446#endif /* !RTM_IFANNOUNCE */
paul6fe70d12005-11-12 22:55:10 +0000447
paul3e95a072003-09-24 00:05:45 +0000448 if (ifp == NULL)
paul6fe70d12005-11-12 22:55:10 +0000449 {
450 /* Interface that zebra was not previously aware of, so create. */
451 ifp = if_create (ifname, ifnlen);
452 if (IS_ZEBRA_DEBUG_KERNEL)
453 zlog_debug ("%s: creating ifp for ifindex %d",
454 __func__, ifm->ifm_index);
455 }
paul718e3742002-12-13 20:15:29 +0000456
paul6fe70d12005-11-12 22:55:10 +0000457 if (IS_ZEBRA_DEBUG_KERNEL)
458 zlog_debug ("%s: updated/created ifp, ifname %s, ifindex %d",
459 __func__, ifp->name, ifp->ifindex);
gdt4bfbea82004-01-06 01:13:05 +0000460 /*
461 * Fill in newly created interface structure, or larval
ajsd2fc8892005-04-02 18:38:43 +0000462 * structure with ifindex IFINDEX_INTERNAL.
gdt4bfbea82004-01-06 01:13:05 +0000463 */
paul718e3742002-12-13 20:15:29 +0000464 ifp->ifindex = ifm->ifm_index;
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000465
Doug VanLeuven9234b382012-10-10 16:12:32 -0700466#ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000467 bsd_linkdetect_translate(ifm);
Doug VanLeuven9234b382012-10-10 16:12:32 -0700468#endif /* HAVE_BSD_IFI_LINK_STATE */
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000469
paul5c78b3d2006-01-25 04:31:40 +0000470 if_flags_update (ifp, ifm->ifm_flags);
paul718e3742002-12-13 20:15:29 +0000471#if defined(__bsdi__)
472 if_kvm_get_mtu (ifp);
473#else
474 if_get_mtu (ifp);
475#endif /* __bsdi__ */
476 if_get_metric (ifp);
477
Tom Goffa34eb362009-11-25 20:36:06 +0000478 /*
479 * XXX sockaddr_dl contents can be larger than the structure
480 * definition, so the user of the stored structure must be
481 * careful not to read off the end.
482 *
483 * a nonzero ifnlen from RTA_NAME_GET() means sdl is valid
484 */
485 if (ifnlen)
486 memcpy (&ifp->sdl, sdl, sizeof (struct sockaddr_dl));
487
paul718e3742002-12-13 20:15:29 +0000488 if_add_update (ifp);
489 }
490 else
gdtda26e3b2004-01-05 17:20:59 +0000491 /*
492 * Interface structure exists. Adjust stored flags from
493 * notification. If interface has up->down or down->up
494 * transition, call state change routines (to adjust routes,
495 * notify routing daemons, etc.). (Other flag changes are stored
496 * but apparently do not trigger action.)
497 */
paul718e3742002-12-13 20:15:29 +0000498 {
paul6fe70d12005-11-12 22:55:10 +0000499 if (ifp->ifindex != ifm->ifm_index)
500 {
501 zlog_warn ("%s: index mismatch, ifname %s, ifp index %d, "
502 "ifm index %d",
503 __func__, ifp->name, ifp->ifindex, ifm->ifm_index);
504 return -1;
505 }
506
Doug VanLeuven9234b382012-10-10 16:12:32 -0700507#ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000508 bsd_linkdetect_translate(ifm);
Doug VanLeuven9234b382012-10-10 16:12:32 -0700509#endif /* HAVE_BSD_IFI_LINK_STATE */
Andrew J. Schorrc543a172008-01-10 15:24:32 +0000510
paul5c78b3d2006-01-25 04:31:40 +0000511 /* update flags and handle operative->inoperative transition, if any */
512 if_flags_update (ifp, ifm->ifm_flags);
513
paul6eb88272005-07-29 14:36:00 +0000514#ifndef RTM_IFANNOUNCE
paul5c78b3d2006-01-25 04:31:40 +0000515 if (!if_is_up (ifp))
516 {
517 /* No RTM_IFANNOUNCE on this platform, so we can never
518 * distinguish between ~IFF_UP and delete. We must presume
519 * it has been deleted.
520 * Eg, Solaris will not notify us of unplumb.
521 *
522 * XXX: Fixme - this should be runtime detected
523 * So that a binary compiled on a system with IFANNOUNCE
524 * will still behave correctly if run on a platform without
525 */
526 if_delete_update (ifp);
527 }
paul6eb88272005-07-29 14:36:00 +0000528#endif /* RTM_IFANNOUNCE */
Denis Ovsienko1ba27562007-08-21 16:15:39 +0000529 if (if_is_up (ifp))
530 {
531#if defined(__bsdi__)
532 if_kvm_get_mtu (ifp);
533#else
534 if_get_mtu (ifp);
535#endif /* __bsdi__ */
536 if_get_metric (ifp);
537 }
paul718e3742002-12-13 20:15:29 +0000538 }
paul5c78b3d2006-01-25 04:31:40 +0000539
paul718e3742002-12-13 20:15:29 +0000540#ifdef HAVE_NET_RT_IFLIST
541 ifp->stats = ifm->ifm_data;
542#endif /* HAVE_NET_RT_IFLIST */
543
544 if (IS_ZEBRA_DEBUG_KERNEL)
paul6fe70d12005-11-12 22:55:10 +0000545 zlog_debug ("%s: interface %s index %d",
546 __func__, ifp->name, ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000547
548 return 0;
549}
550
551/* Address read from struct ifa_msghdr. */
paul6621ca82005-11-23 13:02:08 +0000552static void
paul718e3742002-12-13 20:15:29 +0000553ifam_read_mesg (struct ifa_msghdr *ifm,
554 union sockunion *addr,
555 union sockunion *mask,
paul6fe70d12005-11-12 22:55:10 +0000556 union sockunion *brd,
557 char *ifname,
558 short *ifnlen)
paul718e3742002-12-13 20:15:29 +0000559{
560 caddr_t pnt, end;
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000561 union sockunion dst;
562 union sockunion gateway;
paul718e3742002-12-13 20:15:29 +0000563
564 pnt = (caddr_t)(ifm + 1);
565 end = ((caddr_t)ifm) + ifm->ifam_msglen;
566
paul718e3742002-12-13 20:15:29 +0000567 /* Be sure structure is cleared */
568 memset (mask, 0, sizeof (union sockunion));
569 memset (addr, 0, sizeof (union sockunion));
paul6621ca82005-11-23 13:02:08 +0000570 memset (brd, 0, sizeof (union sockunion));
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000571 memset (&dst, 0, sizeof (union sockunion));
572 memset (&gateway, 0, sizeof (union sockunion));
paul718e3742002-12-13 20:15:29 +0000573
574 /* We fetch each socket variable into sockunion. */
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000575 RTA_ADDR_GET (&dst, RTA_DST, ifm->ifam_addrs, pnt);
576 RTA_ADDR_GET (&gateway, RTA_GATEWAY, ifm->ifam_addrs, pnt);
paul62debbb2005-06-14 14:07:07 +0000577 RTA_ATTR_GET (mask, RTA_NETMASK, ifm->ifam_addrs, pnt);
578 RTA_ADDR_GET (NULL, RTA_GENMASK, ifm->ifam_addrs, pnt);
paul6fe70d12005-11-12 22:55:10 +0000579 RTA_NAME_GET (ifname, RTA_IFP, ifm->ifam_addrs, pnt, *ifnlen);
paul62debbb2005-06-14 14:07:07 +0000580 RTA_ADDR_GET (addr, RTA_IFA, ifm->ifam_addrs, pnt);
581 RTA_ADDR_GET (NULL, RTA_AUTHOR, ifm->ifam_addrs, pnt);
paul6fe70d12005-11-12 22:55:10 +0000582 RTA_ADDR_GET (brd, RTA_BRD, ifm->ifam_addrs, pnt);
paul718e3742002-12-13 20:15:29 +0000583
paul6fe70d12005-11-12 22:55:10 +0000584 if (IS_ZEBRA_DEBUG_KERNEL)
Andrew J. Schorr55196042006-05-17 15:04:59 +0000585 {
586 switch (sockunion_family(addr))
587 {
588 case AF_INET:
589 {
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000590 char buf[4][INET_ADDRSTRLEN];
Andrew J. Schorr55196042006-05-17 15:04:59 +0000591 zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, "
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000592 "ifam_flags 0x%x, addr %s/%d broad %s dst %s "
593 "gateway %s",
594 __func__, ifm->ifam_index,
Andrew J. Schorr55196042006-05-17 15:04:59 +0000595 (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs,
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000596 ifm->ifam_flags,
Andrew J. Schorr55196042006-05-17 15:04:59 +0000597 inet_ntop(AF_INET,&addr->sin.sin_addr,
598 buf[0],sizeof(buf[0])),
599 ip_masklen(mask->sin.sin_addr),
600 inet_ntop(AF_INET,&brd->sin.sin_addr,
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000601 buf[1],sizeof(buf[1])),
602 inet_ntop(AF_INET,&dst.sin.sin_addr,
603 buf[2],sizeof(buf[2])),
604 inet_ntop(AF_INET,&gateway.sin.sin_addr,
605 buf[3],sizeof(buf[3])));
Andrew J. Schorr55196042006-05-17 15:04:59 +0000606 }
607 break;
608#ifdef HAVE_IPV6
609 case AF_INET6:
610 {
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000611 char buf[4][INET6_ADDRSTRLEN];
Andrew J. Schorr55196042006-05-17 15:04:59 +0000612 zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, "
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000613 "ifam_flags 0x%x, addr %s/%d broad %s dst %s "
614 "gateway %s",
Andrew J. Schorr55196042006-05-17 15:04:59 +0000615 __func__, ifm->ifam_index,
616 (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs,
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000617 ifm->ifam_flags,
Andrew J. Schorr55196042006-05-17 15:04:59 +0000618 inet_ntop(AF_INET6,&addr->sin6.sin6_addr,
619 buf[0],sizeof(buf[0])),
620 ip6_masklen(mask->sin6.sin6_addr),
621 inet_ntop(AF_INET6,&brd->sin6.sin6_addr,
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000622 buf[1],sizeof(buf[1])),
623 inet_ntop(AF_INET6,&dst.sin6.sin6_addr,
624 buf[2],sizeof(buf[2])),
625 inet_ntop(AF_INET6,&gateway.sin6.sin6_addr,
626 buf[3],sizeof(buf[3])));
Andrew J. Schorr55196042006-05-17 15:04:59 +0000627 }
628 break;
629#endif /* HAVE_IPV6 */
630 default:
631 zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x",
632 __func__, ifm->ifam_index,
633 (ifnlen ? ifname : "(nil)"), ifm->ifam_addrs);
634 break;
635 }
636 }
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000637
paul718e3742002-12-13 20:15:29 +0000638 /* Assert read up end point matches to end point */
639 if (pnt != end)
Denis Ovsienko85a2ebf2011-12-05 19:36:06 +0400640 zlog_warn ("ifam_read() doesn't read all socket data");
paul718e3742002-12-13 20:15:29 +0000641}
642
643/* Interface's address information get. */
paulec1a4282005-11-24 15:15:17 +0000644int
paul718e3742002-12-13 20:15:29 +0000645ifam_read (struct ifa_msghdr *ifam)
646{
paul6fe70d12005-11-12 22:55:10 +0000647 struct interface *ifp = NULL;
paul0752ef02005-11-03 12:35:21 +0000648 union sockunion addr, mask, brd;
paul6fe70d12005-11-12 22:55:10 +0000649 char ifname[INTERFACE_NAMSIZ];
650 short ifnlen = 0;
651 char isalias = 0;
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000652 int flags = 0;
paul6fe70d12005-11-12 22:55:10 +0000653
654 ifname[0] = ifname[INTERFACE_NAMSIZ - 1] = '\0';
655
656 /* Allocate and read address information. */
657 ifam_read_mesg (ifam, &addr, &mask, &brd, ifname, &ifnlen);
658
659 if ((ifp = if_lookup_by_index(ifam->ifam_index)) == NULL)
paul718e3742002-12-13 20:15:29 +0000660 {
paul6fe70d12005-11-12 22:55:10 +0000661 zlog_warn ("%s: no interface for ifname %s, index %d",
662 __func__, ifname, ifam->ifam_index);
paul718e3742002-12-13 20:15:29 +0000663 return -1;
664 }
paul6fe70d12005-11-12 22:55:10 +0000665
666 if (ifnlen && strncmp (ifp->name, ifname, INTERFACE_NAMSIZ))
667 isalias = 1;
668
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000669 /* N.B. The info in ifa_msghdr does not tell us whether the RTA_BRD
670 field contains a broadcast address or a peer address, so we are forced to
671 rely upon the interface type. */
672 if (if_is_pointopoint(ifp))
673 SET_FLAG(flags, ZEBRA_IFA_PEER);
674
Paul Jakma65022082007-03-06 13:43:05 +0000675#if 0
676 /* it might seem cute to grab the interface metric here, however
677 * we're processing an address update message, and so some systems
678 * (e.g. FBSD) dont bother to fill in ifam_metric. Disabled, but left
679 * in deliberately, as comment.
680 */
pauld34b8992006-01-17 18:03:04 +0000681 ifp->metric = ifam->ifam_metric;
Paul Jakma65022082007-03-06 13:43:05 +0000682#endif
683
paul718e3742002-12-13 20:15:29 +0000684 /* Add connected address. */
685 switch (sockunion_family (&addr))
686 {
687 case AF_INET:
688 if (ifam->ifam_type == RTM_NEWADDR)
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000689 connected_add_ipv4 (ifp, flags, &addr.sin.sin_addr,
paul718e3742002-12-13 20:15:29 +0000690 ip_masklen (mask.sin.sin_addr),
pauld34b8992006-01-17 18:03:04 +0000691 &brd.sin.sin_addr,
692 (isalias ? ifname : NULL));
paul718e3742002-12-13 20:15:29 +0000693 else
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000694 connected_delete_ipv4 (ifp, flags, &addr.sin.sin_addr,
paul718e3742002-12-13 20:15:29 +0000695 ip_masklen (mask.sin.sin_addr),
paul0752ef02005-11-03 12:35:21 +0000696 &brd.sin.sin_addr);
paul718e3742002-12-13 20:15:29 +0000697 break;
698#ifdef HAVE_IPV6
699 case AF_INET6:
700 /* Unset interface index from link-local address when IPv6 stack
701 is KAME. */
702 if (IN6_IS_ADDR_LINKLOCAL (&addr.sin6.sin6_addr))
703 SET_IN6_LINKLOCAL_IFINDEX (addr.sin6.sin6_addr, 0);
704
705 if (ifam->ifam_type == RTM_NEWADDR)
Andrew J. Schorr7ab62c52007-05-17 15:00:41 +0000706 connected_add_ipv6 (ifp, flags, &addr.sin6.sin6_addr,
paul718e3742002-12-13 20:15:29 +0000707 ip6_masklen (mask.sin6.sin6_addr),
pauld34b8992006-01-17 18:03:04 +0000708 &brd.sin6.sin6_addr,
709 (isalias ? ifname : NULL));
paul718e3742002-12-13 20:15:29 +0000710 else
711 connected_delete_ipv6 (ifp,
712 &addr.sin6.sin6_addr,
713 ip6_masklen (mask.sin6.sin6_addr),
paul0752ef02005-11-03 12:35:21 +0000714 &brd.sin6.sin6_addr);
paul718e3742002-12-13 20:15:29 +0000715 break;
716#endif /* HAVE_IPV6 */
717 default:
718 /* Unsupported family silently ignore... */
719 break;
720 }
paul5c78b3d2006-01-25 04:31:40 +0000721
722 /* Check interface flag for implicit up of the interface. */
723 if_refresh (ifp);
724
725#ifdef SUNOS_5
726 /* In addition to lacking IFANNOUNCE, on SUNOS IFF_UP is strange.
727 * See comments for SUNOS_5 in interface.c::if_flags_mangle.
728 *
729 * Here we take care of case where the real IFF_UP was previously
730 * unset (as kept in struct zebra_if.primary_state) and the mangled
731 * IFF_UP (ie IFF_UP set || listcount(connected) has now transitioned
732 * to unset due to the lost non-primary address having DELADDR'd.
733 *
734 * we must delete the interface, because in between here and next
735 * event for this interface-name the administrator could unplumb
736 * and replumb the interface.
737 */
738 if (!if_is_up (ifp))
739 if_delete_update (ifp);
740#endif /* SUNOS_5 */
741
paul718e3742002-12-13 20:15:29 +0000742 return 0;
743}
744
745/* Interface function for reading kernel routing table information. */
paul6621ca82005-11-23 13:02:08 +0000746static int
paul718e3742002-12-13 20:15:29 +0000747rtm_read_mesg (struct rt_msghdr *rtm,
748 union sockunion *dest,
749 union sockunion *mask,
paul6fe70d12005-11-12 22:55:10 +0000750 union sockunion *gate,
751 char *ifname,
752 short *ifnlen)
paul718e3742002-12-13 20:15:29 +0000753{
754 caddr_t pnt, end;
755
756 /* Pnt points out socket data start point. */
757 pnt = (caddr_t)(rtm + 1);
758 end = ((caddr_t)rtm) + rtm->rtm_msglen;
759
760 /* rt_msghdr version check. */
761 if (rtm->rtm_version != RTM_VERSION)
762 zlog (NULL, LOG_WARNING,
763 "Routing message version different %d should be %d."
764 "This may cause problem\n", rtm->rtm_version, RTM_VERSION);
paul62debbb2005-06-14 14:07:07 +0000765
paul718e3742002-12-13 20:15:29 +0000766 /* Be sure structure is cleared */
767 memset (dest, 0, sizeof (union sockunion));
768 memset (gate, 0, sizeof (union sockunion));
769 memset (mask, 0, sizeof (union sockunion));
770
771 /* We fetch each socket variable into sockunion. */
paul62debbb2005-06-14 14:07:07 +0000772 RTA_ADDR_GET (dest, RTA_DST, rtm->rtm_addrs, pnt);
773 RTA_ADDR_GET (gate, RTA_GATEWAY, rtm->rtm_addrs, pnt);
774 RTA_ATTR_GET (mask, RTA_NETMASK, rtm->rtm_addrs, pnt);
775 RTA_ADDR_GET (NULL, RTA_GENMASK, rtm->rtm_addrs, pnt);
paul6fe70d12005-11-12 22:55:10 +0000776 RTA_NAME_GET (ifname, RTA_IFP, rtm->rtm_addrs, pnt, *ifnlen);
paul62debbb2005-06-14 14:07:07 +0000777 RTA_ADDR_GET (NULL, RTA_IFA, rtm->rtm_addrs, pnt);
778 RTA_ADDR_GET (NULL, RTA_AUTHOR, rtm->rtm_addrs, pnt);
779 RTA_ADDR_GET (NULL, RTA_BRD, rtm->rtm_addrs, pnt);
paul718e3742002-12-13 20:15:29 +0000780
781 /* If there is netmask information set it's family same as
782 destination family*/
783 if (rtm->rtm_addrs & RTA_NETMASK)
784 mask->sa.sa_family = dest->sa.sa_family;
785
786 /* Assert read up to the end of pointer. */
787 if (pnt != end)
Denis Ovsienko85a2ebf2011-12-05 19:36:06 +0400788 zlog (NULL, LOG_WARNING, "rtm_read() doesn't read all socket data.");
paul718e3742002-12-13 20:15:29 +0000789
790 return rtm->rtm_flags;
791}
792
paulec1a4282005-11-24 15:15:17 +0000793void
paul718e3742002-12-13 20:15:29 +0000794rtm_read (struct rt_msghdr *rtm)
795{
796 int flags;
797 u_char zebra_flags;
798 union sockunion dest, mask, gate;
paul6fe70d12005-11-12 22:55:10 +0000799 char ifname[INTERFACE_NAMSIZ + 1];
800 short ifnlen = 0;
paul718e3742002-12-13 20:15:29 +0000801
802 zebra_flags = 0;
803
paul718e3742002-12-13 20:15:29 +0000804 /* Read destination and netmask and gateway from rtm message
805 structure. */
paul6fe70d12005-11-12 22:55:10 +0000806 flags = rtm_read_mesg (rtm, &dest, &mask, &gate, ifname, &ifnlen);
Denis Ovsienko6da59802007-08-17 14:16:30 +0000807 if (!(flags & RTF_DONE))
808 return;
Denis Ovsienkodc958242007-08-13 16:03:06 +0000809 if (IS_ZEBRA_DEBUG_KERNEL)
810 zlog_debug ("%s: got rtm of type %d (%s)", __func__, rtm->rtm_type,
Denis Ovsienko2d844522007-09-14 11:31:55 +0000811 lookup (rtm_type_str, rtm->rtm_type));
paul718e3742002-12-13 20:15:29 +0000812
813#ifdef RTF_CLONED /*bsdi, netbsd 1.6*/
814 if (flags & RTF_CLONED)
815 return;
816#endif
817#ifdef RTF_WASCLONED /*freebsd*/
818 if (flags & RTF_WASCLONED)
819 return;
820#endif
821
822 if ((rtm->rtm_type == RTM_ADD) && ! (flags & RTF_UP))
823 return;
824
825 /* This is connected route. */
826 if (! (flags & RTF_GATEWAY))
827 return;
828
829 if (flags & RTF_PROTO1)
830 SET_FLAG (zebra_flags, ZEBRA_FLAG_SELFROUTE);
831
832 /* This is persistent route. */
833 if (flags & RTF_STATIC)
834 SET_FLAG (zebra_flags, ZEBRA_FLAG_STATIC);
835
hasso81dfcaa2003-05-25 19:21:25 +0000836 /* This is a reject or blackhole route */
837 if (flags & RTF_REJECT)
838 SET_FLAG (zebra_flags, ZEBRA_FLAG_REJECT);
839 if (flags & RTF_BLACKHOLE)
840 SET_FLAG (zebra_flags, ZEBRA_FLAG_BLACKHOLE);
841
paul718e3742002-12-13 20:15:29 +0000842 if (dest.sa.sa_family == AF_INET)
843 {
844 struct prefix_ipv4 p;
845
846 p.family = AF_INET;
847 p.prefix = dest.sin.sin_addr;
848 if (flags & RTF_HOST)
849 p.prefixlen = IPV4_MAX_PREFIXLEN;
850 else
851 p.prefixlen = ip_masklen (mask.sin.sin_addr);
paulca162182005-09-12 16:58:52 +0000852
Denis Ovsienkodc958242007-08-13 16:03:06 +0000853 /* Catch self originated messages and match them against our current RIB.
854 * At the same time, ignore unconfirmed messages, they should be tracked
855 * by rtm_write() and kernel_rtm_ipv4().
856 */
Denis Ovsienko96934e62007-09-14 14:56:28 +0000857 if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid)
Denis Ovsienkodc958242007-08-13 16:03:06 +0000858 {
859 char buf[INET_ADDRSTRLEN], gate_buf[INET_ADDRSTRLEN];
860 int ret;
Denis Ovsienkodc958242007-08-13 16:03:06 +0000861 if (! IS_ZEBRA_DEBUG_RIB)
862 return;
863 ret = rib_lookup_ipv4_route (&p, &gate);
864 inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN);
865 switch (rtm->rtm_type)
866 {
867 case RTM_ADD:
868 case RTM_GET:
869 case RTM_CHANGE:
870 /* The kernel notifies us about a new route in FIB created by us.
871 Do we have a correspondent entry in our RIB? */
872 switch (ret)
873 {
874 case ZEBRA_RIB_NOTFOUND:
875 zlog_debug ("%s: %s %s/%d: desync: RR isn't yet in RIB, while already in FIB",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000876 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000877 break;
878 case ZEBRA_RIB_FOUND_CONNECTED:
879 case ZEBRA_RIB_FOUND_NOGATE:
880 inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN);
881 zlog_debug ("%s: %s %s/%d: desync: RR is in RIB, but gate differs (ours is %s)",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000882 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen, gate_buf);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000883 break;
884 case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */
885 zlog_debug ("%s: %s %s/%d: done Ok",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000886 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000887 rib_lookup_and_dump (&p);
888 return;
889 break;
890 }
891 break;
892 case RTM_DELETE:
893 /* The kernel notifies us about a route deleted by us. Do we still
894 have it in the RIB? Do we have anything instead? */
895 switch (ret)
896 {
897 case ZEBRA_RIB_FOUND_EXACT:
898 zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, while already not in FIB",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000899 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000900 rib_lookup_and_dump (&p);
901 break;
902 case ZEBRA_RIB_FOUND_CONNECTED:
903 case ZEBRA_RIB_FOUND_NOGATE:
904 zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, plus gate differs",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000905 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000906 rib_lookup_and_dump (&p);
907 break;
908 case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */
909 zlog_debug ("%s: %s %s/%d: done Ok",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000910 __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
Denis Ovsienkodc958242007-08-13 16:03:06 +0000911 rib_lookup_and_dump (&p);
912 return;
913 break;
914 }
915 break;
916 default:
917 zlog_debug ("%s: %s/%d: warning: loopback RTM of type %s received",
Denis Ovsienko2d844522007-09-14 11:31:55 +0000918 __func__, buf, p.prefixlen, lookup (rtm_type_str, rtm->rtm_type));
Denis Ovsienkodc958242007-08-13 16:03:06 +0000919 }
920 return;
921 }
922
paulca162182005-09-12 16:58:52 +0000923 /* Change, delete the old prefix, we have no further information
924 * to specify the route really
925 */
926 if (rtm->rtm_type == RTM_CHANGE)
927 rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, zebra_flags, &p,
Denis Ovsienko6eac79a2011-12-05 13:43:18 +0400928 NULL, 0, 0, SAFI_UNICAST);
paulca162182005-09-12 16:58:52 +0000929
930 if (rtm->rtm_type == RTM_GET
931 || rtm->rtm_type == RTM_ADD
932 || rtm->rtm_type == RTM_CHANGE)
paul718e3742002-12-13 20:15:29 +0000933 rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, zebra_flags,
G.Balajicddf3912011-11-26 21:59:32 +0400934 &p, &gate.sin.sin_addr, NULL, 0, 0, 0, 0, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +0000935 else
936 rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, zebra_flags,
Denis Ovsienko6eac79a2011-12-05 13:43:18 +0400937 &p, &gate.sin.sin_addr, 0, 0, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +0000938 }
939#ifdef HAVE_IPV6
940 if (dest.sa.sa_family == AF_INET6)
941 {
Denis Ovsienko5619f562007-10-24 13:13:21 +0000942 /* One day we might have a debug section here like one in the
943 * IPv4 case above. Just ignore own messages at the moment.
944 */
945 if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid)
946 return;
paul718e3742002-12-13 20:15:29 +0000947 struct prefix_ipv6 p;
948 unsigned int ifindex = 0;
949
950 p.family = AF_INET6;
951 p.prefix = dest.sin6.sin6_addr;
952 if (flags & RTF_HOST)
953 p.prefixlen = IPV6_MAX_PREFIXLEN;
954 else
955 p.prefixlen = ip6_masklen (mask.sin6.sin6_addr);
956
957#ifdef KAME
958 if (IN6_IS_ADDR_LINKLOCAL (&gate.sin6.sin6_addr))
959 {
960 ifindex = IN6_LINKLOCAL_IFINDEX (gate.sin6.sin6_addr);
961 SET_IN6_LINKLOCAL_IFINDEX (gate.sin6.sin6_addr, 0);
962 }
963#endif /* KAME */
964
paulca162182005-09-12 16:58:52 +0000965 /* CHANGE: delete the old prefix, we have no further information
966 * to specify the route really
967 */
968 if (rtm->rtm_type == RTM_CHANGE)
paul6621ca82005-11-23 13:02:08 +0000969 rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, zebra_flags, &p,
Denis Ovsienko6eac79a2011-12-05 13:43:18 +0400970 NULL, 0, 0, SAFI_UNICAST);
paulca162182005-09-12 16:58:52 +0000971
972 if (rtm->rtm_type == RTM_GET
973 || rtm->rtm_type == RTM_ADD
974 || rtm->rtm_type == RTM_CHANGE)
paul718e3742002-12-13 20:15:29 +0000975 rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, zebra_flags,
Denis Ovsienko6eac79a2011-12-05 13:43:18 +0400976 &p, &gate.sin6.sin6_addr, ifindex, 0, 0, 0, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +0000977 else
978 rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, zebra_flags,
Denis Ovsienko6eac79a2011-12-05 13:43:18 +0400979 &p, &gate.sin6.sin6_addr, ifindex, 0, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +0000980 }
981#endif /* HAVE_IPV6 */
982}
983
984/* Interface function for the kernel routing table updates. Support
paul6621ca82005-11-23 13:02:08 +0000985 * for RTM_CHANGE will be needed.
986 * Exported only for rt_socket.c
987 */
paul718e3742002-12-13 20:15:29 +0000988int
989rtm_write (int message,
990 union sockunion *dest,
991 union sockunion *mask,
992 union sockunion *gate,
993 unsigned int index,
994 int zebra_flags,
995 int metric)
996{
997 int ret;
998 caddr_t pnt;
999 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +00001000
1001 /* Sequencial number of routing message. */
1002 static int msg_seq = 0;
1003
1004 /* Struct of rt_msghdr and buffer for storing socket's data. */
1005 struct
1006 {
1007 struct rt_msghdr rtm;
1008 char buf[512];
1009 } msg;
1010
paul718e3742002-12-13 20:15:29 +00001011 if (routing_sock < 0)
1012 return ZEBRA_ERR_EPERM;
1013
1014 /* Clear and set rt_msghdr values */
1015 memset (&msg, 0, sizeof (struct rt_msghdr));
1016 msg.rtm.rtm_version = RTM_VERSION;
1017 msg.rtm.rtm_type = message;
1018 msg.rtm.rtm_seq = msg_seq++;
1019 msg.rtm.rtm_addrs = RTA_DST;
1020 msg.rtm.rtm_addrs |= RTA_GATEWAY;
1021 msg.rtm.rtm_flags = RTF_UP;
1022 msg.rtm.rtm_index = index;
1023
1024 if (metric != 0)
1025 {
1026 msg.rtm.rtm_rmx.rmx_hopcount = metric;
1027 msg.rtm.rtm_inits |= RTV_HOPCOUNT;
1028 }
1029
1030 ifp = if_lookup_by_index (index);
1031
1032 if (gate && message == RTM_ADD)
1033 msg.rtm.rtm_flags |= RTF_GATEWAY;
1034
David Warde6f148e2009-12-03 21:43:11 +03001035 /* When RTF_CLONING is unavailable on BSD, should we set some
1036 * other flag instead?
1037 */
1038#ifdef RTF_CLONING
paul718e3742002-12-13 20:15:29 +00001039 if (! gate && message == RTM_ADD && ifp &&
1040 (ifp->flags & IFF_POINTOPOINT) == 0)
1041 msg.rtm.rtm_flags |= RTF_CLONING;
David Warde6f148e2009-12-03 21:43:11 +03001042#endif /* RTF_CLONING */
paul718e3742002-12-13 20:15:29 +00001043
1044 /* If no protocol specific gateway is specified, use link
1045 address for gateway. */
1046 if (! gate)
1047 {
1048 if (!ifp)
1049 {
Denis Ovsienkodc958242007-08-13 16:03:06 +00001050 char dest_buf[INET_ADDRSTRLEN] = "NULL", mask_buf[INET_ADDRSTRLEN] = "255.255.255.255";
1051 if (dest)
1052 inet_ntop (AF_INET, &dest->sin.sin_addr, dest_buf, INET_ADDRSTRLEN);
1053 if (mask)
1054 inet_ntop (AF_INET, &mask->sin.sin_addr, mask_buf, INET_ADDRSTRLEN);
1055 zlog_warn ("%s: %s/%s: gate == NULL and no gateway found for ifindex %d",
1056 __func__, dest_buf, mask_buf, index);
paul718e3742002-12-13 20:15:29 +00001057 return -1;
1058 }
1059 gate = (union sockunion *) & ifp->sdl;
1060 }
1061
1062 if (mask)
1063 msg.rtm.rtm_addrs |= RTA_NETMASK;
1064 else if (message == RTM_ADD)
1065 msg.rtm.rtm_flags |= RTF_HOST;
1066
1067 /* Tagging route with flags */
1068 msg.rtm.rtm_flags |= (RTF_PROTO1);
1069
1070 /* Additional flags. */
1071 if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
1072 msg.rtm.rtm_flags |= RTF_BLACKHOLE;
hasso81dfcaa2003-05-25 19:21:25 +00001073 if (zebra_flags & ZEBRA_FLAG_REJECT)
1074 msg.rtm.rtm_flags |= RTF_REJECT;
1075
paul718e3742002-12-13 20:15:29 +00001076
Paul Jakma6f0e3f62007-05-10 02:38:51 +00001077#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
paul718e3742002-12-13 20:15:29 +00001078#define SOCKADDRSET(X,R) \
1079 if (msg.rtm.rtm_addrs & (R)) \
1080 { \
1081 int len = ROUNDUP ((X)->sa.sa_len); \
1082 memcpy (pnt, (caddr_t)(X), len); \
1083 pnt += len; \
1084 }
1085#else
1086#define SOCKADDRSET(X,R) \
1087 if (msg.rtm.rtm_addrs & (R)) \
1088 { \
paul6fe70d12005-11-12 22:55:10 +00001089 int len = SAROUNDUP (X); \
paul718e3742002-12-13 20:15:29 +00001090 memcpy (pnt, (caddr_t)(X), len); \
1091 pnt += len; \
1092 }
Paul Jakma6f0e3f62007-05-10 02:38:51 +00001093#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
paul718e3742002-12-13 20:15:29 +00001094
1095 pnt = (caddr_t) msg.buf;
1096
1097 /* Write each socket data into rtm message buffer */
1098 SOCKADDRSET (dest, RTA_DST);
1099 SOCKADDRSET (gate, RTA_GATEWAY);
1100 SOCKADDRSET (mask, RTA_NETMASK);
1101
1102 msg.rtm.rtm_msglen = pnt - (caddr_t) &msg;
1103
1104 ret = write (routing_sock, &msg, msg.rtm.rtm_msglen);
1105
1106 if (ret != msg.rtm.rtm_msglen)
1107 {
1108 if (errno == EEXIST)
1109 return ZEBRA_ERR_RTEXIST;
1110 if (errno == ENETUNREACH)
1111 return ZEBRA_ERR_RTUNREACH;
Denis Ovsienkodc958242007-08-13 16:03:06 +00001112 if (errno == ESRCH)
1113 return ZEBRA_ERR_RTNOEXIST;
paul718e3742002-12-13 20:15:29 +00001114
Denis Ovsienkodc958242007-08-13 16:03:06 +00001115 zlog_warn ("%s: write : %s (%d)", __func__, safe_strerror (errno), errno);
1116 return ZEBRA_ERR_KERNEL;
paul718e3742002-12-13 20:15:29 +00001117 }
Denis Ovsienkodc958242007-08-13 16:03:06 +00001118 return ZEBRA_ERR_NOERROR;
paul718e3742002-12-13 20:15:29 +00001119}
1120
1121
1122#include "thread.h"
1123#include "zebra/zserv.h"
1124
paul718e3742002-12-13 20:15:29 +00001125/* For debug purpose. */
ajsb6178002004-12-07 21:12:56 +00001126static void
paul718e3742002-12-13 20:15:29 +00001127rtmsg_debug (struct rt_msghdr *rtm)
1128{
Denis Ovsienko2d844522007-09-14 11:31:55 +00001129 zlog_debug ("Kernel: Len: %d Type: %s", rtm->rtm_msglen, lookup (rtm_type_str, rtm->rtm_type));
paul718e3742002-12-13 20:15:29 +00001130 rtm_flag_dump (rtm->rtm_flags);
ajsb6178002004-12-07 21:12:56 +00001131 zlog_debug ("Kernel: message seq %d", rtm->rtm_seq);
paul6fe70d12005-11-12 22:55:10 +00001132 zlog_debug ("Kernel: pid %d, rtm_addrs 0x%x", rtm->rtm_pid, rtm->rtm_addrs);
paul718e3742002-12-13 20:15:29 +00001133}
1134
1135/* This is pretty gross, better suggestions welcome -- mhandler */
1136#ifndef RTAX_MAX
1137#ifdef RTA_NUMBITS
1138#define RTAX_MAX RTA_NUMBITS
1139#else
1140#define RTAX_MAX 8
1141#endif /* RTA_NUMBITS */
1142#endif /* RTAX_MAX */
1143
1144/* Kernel routing table and interface updates via routing socket. */
paul6621ca82005-11-23 13:02:08 +00001145static int
paul718e3742002-12-13 20:15:29 +00001146kernel_read (struct thread *thread)
1147{
1148 int sock;
1149 int nbytes;
1150 struct rt_msghdr *rtm;
1151
gdtdbee01f2004-01-06 00:36:51 +00001152 /*
1153 * This must be big enough for any message the kernel might send.
gdtb27900b2004-01-08 15:44:29 +00001154 * Rather than determining how many sockaddrs of what size might be
1155 * in each particular message, just use RTAX_MAX of sockaddr_storage
1156 * for each. Note that the sockaddrs must be after each message
1157 * definition, or rather after whichever happens to be the largest,
1158 * since the buffer needs to be big enough for a message and the
1159 * sockaddrs together.
gdtdbee01f2004-01-06 00:36:51 +00001160 */
paul718e3742002-12-13 20:15:29 +00001161 union
1162 {
1163 /* Routing information. */
1164 struct
1165 {
1166 struct rt_msghdr rtm;
gdtb27900b2004-01-08 15:44:29 +00001167 struct sockaddr_storage addr[RTAX_MAX];
paul718e3742002-12-13 20:15:29 +00001168 } r;
1169
1170 /* Interface information. */
1171 struct
1172 {
1173 struct if_msghdr ifm;
gdtb27900b2004-01-08 15:44:29 +00001174 struct sockaddr_storage addr[RTAX_MAX];
paul718e3742002-12-13 20:15:29 +00001175 } im;
1176
1177 /* Interface address information. */
1178 struct
1179 {
1180 struct ifa_msghdr ifa;
gdtb27900b2004-01-08 15:44:29 +00001181 struct sockaddr_storage addr[RTAX_MAX];
paul718e3742002-12-13 20:15:29 +00001182 } ia;
1183
1184#ifdef RTM_IFANNOUNCE
1185 /* Interface arrival/departure */
1186 struct
1187 {
1188 struct if_announcemsghdr ifan;
gdtb27900b2004-01-08 15:44:29 +00001189 struct sockaddr_storage addr[RTAX_MAX];
paul718e3742002-12-13 20:15:29 +00001190 } ian;
1191#endif /* RTM_IFANNOUNCE */
1192
1193 } buf;
1194
1195 /* Fetch routing socket. */
1196 sock = THREAD_FD (thread);
1197
1198 nbytes= read (sock, &buf, sizeof buf);
1199
1200 if (nbytes <= 0)
1201 {
1202 if (nbytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN)
ajs6099b3b2004-11-20 02:06:59 +00001203 zlog_warn ("routing socket error: %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001204 return 0;
1205 }
1206
paul9bcdb632003-07-08 08:09:45 +00001207 thread_add_read (zebrad.master, kernel_read, NULL, sock);
paul718e3742002-12-13 20:15:29 +00001208
hasso726f9b22003-05-25 21:04:54 +00001209 if (IS_ZEBRA_DEBUG_KERNEL)
1210 rtmsg_debug (&buf.r.rtm);
paul718e3742002-12-13 20:15:29 +00001211
1212 rtm = &buf.r.rtm;
1213
gdtb27900b2004-01-08 15:44:29 +00001214 /*
1215 * Ensure that we didn't drop any data, so that processing routines
1216 * can assume they have the whole message.
1217 */
gdtda26e3b2004-01-05 17:20:59 +00001218 if (rtm->rtm_msglen != nbytes)
1219 {
1220 zlog_warn ("kernel_read: rtm->rtm_msglen %d, nbytes %d, type %d\n",
1221 rtm->rtm_msglen, nbytes, rtm->rtm_type);
1222 return -1;
1223 }
1224
paul718e3742002-12-13 20:15:29 +00001225 switch (rtm->rtm_type)
1226 {
1227 case RTM_ADD:
1228 case RTM_DELETE:
paulca162182005-09-12 16:58:52 +00001229 case RTM_CHANGE:
paul718e3742002-12-13 20:15:29 +00001230 rtm_read (rtm);
1231 break;
1232 case RTM_IFINFO:
1233 ifm_read (&buf.im.ifm);
1234 break;
1235 case RTM_NEWADDR:
1236 case RTM_DELADDR:
1237 ifam_read (&buf.ia.ifa);
1238 break;
1239#ifdef RTM_IFANNOUNCE
1240 case RTM_IFANNOUNCE:
1241 ifan_read (&buf.ian.ifan);
1242 break;
1243#endif /* RTM_IFANNOUNCE */
1244 default:
hasso726f9b22003-05-25 21:04:54 +00001245 if (IS_ZEBRA_DEBUG_KERNEL)
ajsb6178002004-12-07 21:12:56 +00001246 zlog_debug("Unprocessed RTM_type: %d", rtm->rtm_type);
paul718e3742002-12-13 20:15:29 +00001247 break;
1248 }
1249 return 0;
1250}
1251
1252/* Make routing socket. */
paul6621ca82005-11-23 13:02:08 +00001253static void
1254routing_socket (void)
paul718e3742002-12-13 20:15:29 +00001255{
pauledd7c242003-06-04 13:59:38 +00001256 if ( zserv_privs.change (ZPRIVS_RAISE) )
1257 zlog_err ("routing_socket: Can't raise privileges");
1258
paul718e3742002-12-13 20:15:29 +00001259 routing_sock = socket (AF_ROUTE, SOCK_RAW, 0);
1260
1261 if (routing_sock < 0)
1262 {
pauledd7c242003-06-04 13:59:38 +00001263 if ( zserv_privs.change (ZPRIVS_LOWER) )
1264 zlog_err ("routing_socket: Can't lower privileges");
paul718e3742002-12-13 20:15:29 +00001265 zlog_warn ("Can't init kernel routing socket");
1266 return;
1267 }
1268
paul865b8522005-01-05 08:30:35 +00001269 /* XXX: Socket should be NONBLOCK, however as we currently
1270 * discard failed writes, this will lead to inconsistencies.
1271 * For now, socket must be blocking.
1272 */
1273 /*if (fcntl (routing_sock, F_SETFL, O_NONBLOCK) < 0)
1274 zlog_warn ("Can't set O_NONBLOCK to routing socket");*/
1275
pauledd7c242003-06-04 13:59:38 +00001276 if ( zserv_privs.change (ZPRIVS_LOWER) )
1277 zlog_err ("routing_socket: Can't lower privileges");
paul718e3742002-12-13 20:15:29 +00001278
1279 /* kernel_read needs rewrite. */
paul9bcdb632003-07-08 08:09:45 +00001280 thread_add_read (zebrad.master, kernel_read, NULL, routing_sock);
paul718e3742002-12-13 20:15:29 +00001281}
1282
1283/* Exported interface function. This function simply calls
1284 routing_socket (). */
1285void
paul6621ca82005-11-23 13:02:08 +00001286kernel_init (void)
paul718e3742002-12-13 20:15:29 +00001287{
1288 routing_socket ();
1289}