]> git.proxmox.com Git - mirror_frr.git/blame - zebra/if_sysctl.c
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / if_sysctl.c
CommitLineData
718e3744 1/*
2 * Get interface's address and mask information 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 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#include <zebra.h>
23
ddfeb486
DL
24#if !defined(GNU_LINUX) && !defined(OPEN_BSD) && !defined(SUNOS_5)
25
718e3744 26#include "if.h"
27#include "sockunion.h"
28#include "prefix.h"
29#include "connected.h"
30#include "memory.h"
4a1ab8e4 31#include "zebra_memory.h"
718e3744 32#include "ioctl.h"
33#include "log.h"
8f7d9fc0
FL
34#include "interface.h"
35#include "vrf.h"
718e3744 36
ec1a4283 37#include "zebra/rt.h"
38#include "zebra/kernel_socket.h"
8f7d9fc0 39#include "zebra/rib.h"
364fed6b 40#include "zebra/zebra_errors.h"
ec1a4283 41
d62a17ae 42void ifstat_update_sysctl(void)
718e3744 43{
d62a17ae 44 caddr_t ref, buf, end;
45 size_t bufsiz;
46 struct if_msghdr *ifm;
47 struct interface *ifp;
718e3744 48
49#define MIBSIZ 6
d62a17ae 50 int mib[MIBSIZ] = {
51 CTL_NET, PF_ROUTE, 0, 0, /* AF_INET & AF_INET6 */
52 NET_RT_IFLIST, 0};
53
54 /* Query buffer size. */
55 if (sysctl(mib, MIBSIZ, NULL, &bufsiz, NULL, 0) < 0) {
e914ccbe 56 flog_warn(EC_ZEBRA_SYSCTL_FAILED, "sysctl() error by %s",
9df414fe 57 safe_strerror(errno));
d62a17ae 58 return;
718e3744 59 }
718e3744 60
d62a17ae 61 /* We free this memory at the end of this function. */
62 ref = buf = XMALLOC(MTYPE_TMP, bufsiz);
718e3744 63
0437e105 64 /* Fetch interface information into allocated buffer. */
d62a17ae 65 if (sysctl(mib, MIBSIZ, buf, &bufsiz, NULL, 0) < 0) {
e914ccbe 66 flog_warn(EC_ZEBRA_SYSCTL_FAILED, "sysctl error by %s",
9df414fe 67 safe_strerror(errno));
d62a17ae 68 XFREE(MTYPE_TMP, ref);
69 return;
70 }
71
72 /* Parse both interfaces and addresses. */
73 for (end = buf + bufsiz; buf < end; buf += ifm->ifm_msglen) {
74 ifm = (struct if_msghdr *)buf;
75 if (ifm->ifm_type == RTM_IFINFO) {
76 ifp = if_lookup_by_index(ifm->ifm_index, VRF_DEFAULT);
77 if (ifp)
78 ifp->stats = ifm->ifm_data;
79 }
80 }
81
82 /* Free sysctl buffer. */
83 XFREE(MTYPE_TMP, ref);
84
85 return;
718e3744 86}
87
88/* Interface listing up function using sysctl(). */
d62a17ae 89void interface_list(struct zebra_ns *zns)
718e3744 90{
d62a17ae 91 caddr_t ref, buf, end;
92 size_t bufsiz;
93 struct if_msghdr *ifm;
718e3744 94
95#define MIBSIZ 6
d62a17ae 96 int mib[MIBSIZ] = {
97 CTL_NET, PF_ROUTE, 0, 0, /* AF_INET & AF_INET6 */
98 NET_RT_IFLIST, 0};
99
100 if (zns->ns_id != NS_DEFAULT) {
9df414fe 101 zlog_debug("interface_list: ignore NS %u", zns->ns_id);
d62a17ae 102 return;
103 }
104
105 /* Query buffer size. */
106 if (sysctl(mib, MIBSIZ, NULL, &bufsiz, NULL, 0) < 0) {
e914ccbe 107 flog_err_sys(EC_ZEBRA_IFLIST_FAILED,
9df414fe
QY
108 "Could not enumerate interfaces: %s",
109 safe_strerror(errno));
d62a17ae 110 return;
111 }
112
113 /* We free this memory at the end of this function. */
114 ref = buf = XMALLOC(MTYPE_TMP, bufsiz);
115
0437e105 116 /* Fetch interface information into allocated buffer. */
d62a17ae 117 if (sysctl(mib, MIBSIZ, buf, &bufsiz, NULL, 0) < 0) {
e914ccbe 118 flog_err_sys(EC_ZEBRA_IFLIST_FAILED,
9df414fe
QY
119 "Could not enumerate interfaces: %s",
120 safe_strerror(errno));
d62a17ae 121 return;
122 }
123
124 /* Parse both interfaces and addresses. */
125 for (end = buf + bufsiz; buf < end; buf += ifm->ifm_msglen) {
126 ifm = (struct if_msghdr *)buf;
127
128 switch (ifm->ifm_type) {
129 case RTM_IFINFO:
130 ifm_read(ifm);
131 break;
132 case RTM_NEWADDR:
133 ifam_read((struct ifa_msghdr *)ifm);
134 break;
135 default:
136 zlog_info("interfaces_list(): unexpected message type");
137 XFREE(MTYPE_TMP, ref);
138 return;
139 break;
140 }
718e3744 141 }
718e3744 142
d62a17ae 143 /* Free sysctl buffer. */
144 XFREE(MTYPE_TMP, ref);
718e3744 145}
ddfeb486
DL
146
147#endif /* !defined(GNU_LINUX) && !defined(OPEN_BSD) && !defined(SUNOS_5) */