]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
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" | |
4a1ab8e4 | 26 | #include "zebra_memory.h" |
718e3744 | 27 | #include "log.h" |
8f7d9fc0 | 28 | #include "vrf.h" |
718e3744 | 29 | |
6621ca86 | 30 | #include "zebra/zserv.h" |
31 | #include "zebra/rt.h" | |
ec1a4283 | 32 | #include "zebra/kernel_socket.h" |
6621ca86 | 33 | |
718e3744 | 34 | /* Kernel routing table read up by sysctl function. */ |
6621ca86 | 35 | void |
12f6fb97 | 36 | route_read (struct zebra_ns *zns) |
718e3744 | 37 | { |
38 | caddr_t buf, end, ref; | |
39 | size_t bufsiz; | |
40 | struct rt_msghdr *rtm; | |
718e3744 | 41 | |
42 | #define MIBSIZ 6 | |
43 | int mib[MIBSIZ] = | |
44 | { | |
45 | CTL_NET, | |
46 | PF_ROUTE, | |
47 | 0, | |
48 | 0, | |
49 | NET_RT_DUMP, | |
50 | 0 | |
51 | }; | |
8f7d9fc0 | 52 | |
12f6fb97 | 53 | if (zns->ns_id != NS_DEFAULT) |
8f7d9fc0 FL |
54 | return; |
55 | ||
718e3744 | 56 | /* Get buffer size. */ |
57 | if (sysctl (mib, MIBSIZ, NULL, &bufsiz, NULL, 0) < 0) | |
58 | { | |
6099b3b5 | 59 | zlog_warn ("sysctl fail: %s", safe_strerror (errno)); |
ec1a4283 | 60 | return; |
718e3744 | 61 | } |
62 | ||
63 | /* Allocate buffer. */ | |
64 | ref = buf = XMALLOC (MTYPE_TMP, bufsiz); | |
65 | ||
66 | /* Read routing table information by calling sysctl(). */ | |
67 | if (sysctl (mib, MIBSIZ, buf, &bufsiz, NULL, 0) < 0) | |
68 | { | |
6099b3b5 | 69 | zlog_warn ("sysctl() fail by %s", safe_strerror (errno)); |
495f0b13 | 70 | XFREE(MTYPE_TMP, ref); |
ec1a4283 | 71 | return; |
718e3744 | 72 | } |
73 | ||
74 | for (end = buf + bufsiz; buf < end; buf += rtm->rtm_msglen) | |
75 | { | |
76 | rtm = (struct rt_msghdr *) buf; | |
882968e0 DO |
77 | /* We must set RTF_DONE here, so rtm_read() doesn't ignore the message. */ |
78 | SET_FLAG (rtm->rtm_flags, RTF_DONE); | |
718e3744 | 79 | rtm_read (rtm); |
80 | } | |
81 | ||
82 | /* Free buffer. */ | |
83 | XFREE (MTYPE_TMP, ref); | |
84 | ||
ec1a4283 | 85 | return; |
718e3744 | 86 | } |