blob: e39d8cb153447e3a9b30eb5d3cb4756b71d351b2 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Kernel routing table read by sysctl function.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "memory.h"
26#include "log.h"
27
paul6621ca82005-11-23 13:02:08 +000028#include "zebra/zserv.h"
29#include "zebra/rt.h"
30
paul718e3742002-12-13 20:15:29 +000031/* Kernel routing table read up by sysctl function. */
paul6621ca82005-11-23 13:02:08 +000032void
33route_read (void)
paul718e3742002-12-13 20:15:29 +000034{
35 caddr_t buf, end, ref;
36 size_t bufsiz;
37 struct rt_msghdr *rtm;
38 void rtm_read (struct rt_msghdr *);
39
40#define MIBSIZ 6
41 int mib[MIBSIZ] =
42 {
43 CTL_NET,
44 PF_ROUTE,
45 0,
46 0,
47 NET_RT_DUMP,
48 0
49 };
50
51 /* Get buffer size. */
52 if (sysctl (mib, MIBSIZ, NULL, &bufsiz, NULL, 0) < 0)
53 {
ajs6099b3b2004-11-20 02:06:59 +000054 zlog_warn ("sysctl fail: %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +000055 return -1;
56 }
57
58 /* Allocate buffer. */
59 ref = buf = XMALLOC (MTYPE_TMP, bufsiz);
60
61 /* Read routing table information by calling sysctl(). */
62 if (sysctl (mib, MIBSIZ, buf, &bufsiz, NULL, 0) < 0)
63 {
ajs6099b3b2004-11-20 02:06:59 +000064 zlog_warn ("sysctl() fail by %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +000065 return -1;
66 }
67
68 for (end = buf + bufsiz; buf < end; buf += rtm->rtm_msglen)
69 {
70 rtm = (struct rt_msghdr *) buf;
71 rtm_read (rtm);
72 }
73
74 /* Free buffer. */
75 XFREE (MTYPE_TMP, ref);
76
77 return 0;
78}