]>
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
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
26 #include "sockunion.h"
28 #include "connected.h"
30 #include "zebra_memory.h"
33 #include "interface.h"
37 #include "zebra/kernel_socket.h"
38 #include "zebra/rib.h"
41 ifstat_update_sysctl (void)
43 caddr_t ref
, buf
, end
;
45 struct if_msghdr
*ifm
;
46 struct interface
*ifp
;
54 0, /* AF_INET & AF_INET6 */
59 /* Query buffer size. */
60 if (sysctl (mib
, MIBSIZ
, NULL
, &bufsiz
, NULL
, 0) < 0)
62 zlog_warn ("sysctl() error by %s", safe_strerror (errno
));
66 /* We free this memory at the end of this function. */
67 ref
= buf
= XMALLOC (MTYPE_TMP
, bufsiz
);
69 /* Fetch interface informations into allocated buffer. */
70 if (sysctl (mib
, MIBSIZ
, buf
, &bufsiz
, NULL
, 0) < 0)
72 zlog (NULL
, LOG_WARNING
, "sysctl error by %s", safe_strerror (errno
));
73 XFREE(MTYPE_TMP
, ref
);
77 /* Parse both interfaces and addresses. */
78 for (end
= buf
+ bufsiz
; buf
< end
; buf
+= ifm
->ifm_msglen
)
80 ifm
= (struct if_msghdr
*) buf
;
81 if (ifm
->ifm_type
== RTM_IFINFO
)
83 ifp
= if_lookup_by_index (ifm
->ifm_index
);
85 ifp
->stats
= ifm
->ifm_data
;
89 /* Free sysctl buffer. */
90 XFREE (MTYPE_TMP
, ref
);
95 /* Interface listing up function using sysctl(). */
97 interface_list (struct zebra_ns
*zns
)
99 caddr_t ref
, buf
, end
;
101 struct if_msghdr
*ifm
;
109 0, /* AF_INET & AF_INET6 */
114 if (zns
->ns_id
!= NS_DEFAULT
)
116 zlog_warn ("interface_list: ignore NS %u", zns
->ns_id
);
120 /* Query buffer size. */
121 if (sysctl (mib
, MIBSIZ
, NULL
, &bufsiz
, NULL
, 0) < 0)
123 zlog (NULL
, LOG_WARNING
, "sysctl() error by %s", safe_strerror (errno
));
127 /* We free this memory at the end of this function. */
128 ref
= buf
= XMALLOC (MTYPE_TMP
, bufsiz
);
130 /* Fetch interface informations into allocated buffer. */
131 if (sysctl (mib
, MIBSIZ
, buf
, &bufsiz
, NULL
, 0) < 0)
133 zlog (NULL
, LOG_WARNING
, "sysctl error by %s", safe_strerror (errno
));
137 /* Parse both interfaces and addresses. */
138 for (end
= buf
+ bufsiz
; buf
< end
; buf
+= ifm
->ifm_msglen
)
140 ifm
= (struct if_msghdr
*) buf
;
142 switch (ifm
->ifm_type
)
148 ifam_read ((struct ifa_msghdr
*) ifm
);
151 zlog_info ("interfaces_list(): unexpected message type");
152 XFREE (MTYPE_TMP
, ref
);
158 /* Free sysctl buffer. */
159 XFREE (MTYPE_TMP
, ref
);