]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/if_sysctl.c
2 * Get interface's address and mask information by sysctl() function.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
25 #include "sockunion.h"
27 #include "connected.h"
29 #include "zebra_memory.h"
32 #include "interface.h"
36 #include "zebra/kernel_socket.h"
37 #include "zebra/rib.h"
40 ifstat_update_sysctl (void)
42 caddr_t ref
, buf
, end
;
44 struct if_msghdr
*ifm
;
45 struct interface
*ifp
;
53 0, /* AF_INET & AF_INET6 */
58 /* Query buffer size. */
59 if (sysctl (mib
, MIBSIZ
, NULL
, &bufsiz
, NULL
, 0) < 0)
61 zlog_warn ("sysctl() error by %s", safe_strerror (errno
));
65 /* We free this memory at the end of this function. */
66 ref
= buf
= XMALLOC (MTYPE_TMP
, bufsiz
);
68 /* Fetch interface informations into allocated buffer. */
69 if (sysctl (mib
, MIBSIZ
, buf
, &bufsiz
, NULL
, 0) < 0)
71 zlog_warn("sysctl error by %s", safe_strerror(errno
));
72 XFREE(MTYPE_TMP
, ref
);
76 /* Parse both interfaces and addresses. */
77 for (end
= buf
+ bufsiz
; buf
< end
; buf
+= ifm
->ifm_msglen
)
79 ifm
= (struct if_msghdr
*) buf
;
80 if (ifm
->ifm_type
== RTM_IFINFO
)
82 ifp
= if_lookup_by_index (ifm
->ifm_index
, VRF_DEFAULT
);
84 ifp
->stats
= ifm
->ifm_data
;
88 /* Free sysctl buffer. */
89 XFREE (MTYPE_TMP
, ref
);
94 /* Interface listing up function using sysctl(). */
96 interface_list (struct zebra_ns
*zns
)
98 caddr_t ref
, buf
, end
;
100 struct if_msghdr
*ifm
;
108 0, /* AF_INET & AF_INET6 */
113 if (zns
->ns_id
!= NS_DEFAULT
)
115 zlog_warn ("interface_list: ignore NS %u", zns
->ns_id
);
119 /* Query buffer size. */
120 if (sysctl (mib
, MIBSIZ
, NULL
, &bufsiz
, NULL
, 0) < 0)
122 zlog_warn("sysctl() error by %s", safe_strerror(errno
));
126 /* We free this memory at the end of this function. */
127 ref
= buf
= XMALLOC (MTYPE_TMP
, bufsiz
);
129 /* Fetch interface informations into allocated buffer. */
130 if (sysctl (mib
, MIBSIZ
, buf
, &bufsiz
, NULL
, 0) < 0)
132 zlog_warn("sysctl error by %s", safe_strerror(errno
));
136 /* Parse both interfaces and addresses. */
137 for (end
= buf
+ bufsiz
; buf
< end
; buf
+= ifm
->ifm_msglen
)
139 ifm
= (struct if_msghdr
*) buf
;
141 switch (ifm
->ifm_type
)
147 ifam_read ((struct ifa_msghdr
*) ifm
);
150 zlog_info ("interfaces_list(): unexpected message type");
151 XFREE (MTYPE_TMP
, ref
);
157 /* Free sysctl buffer. */
158 XFREE (MTYPE_TMP
, ref
);