]> git.proxmox.com Git - mirror_frr.git/blame - zebra/mtu_kvm.c
babeld: Initial import, for Babel routing protocol.
[mirror_frr.git] / zebra / mtu_kvm.c
CommitLineData
718e3744 1/* MTU get using kvm_read.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include <kvm.h>
25#include <limits.h>
26#include <fcntl.h>
27
28#include "if.h"
29
30/* get interface MTU to use kvm_read */
31void
32if_kvm_get_mtu (struct interface *ifp)
33{
34 kvm_t *kvmd;
35 struct ifnet ifnet;
36 unsigned long ifnetaddr;
37 int len;
38
39 char ifname[IFNAMSIZ];
40 char tname[INTERFACE_NAMSIZ + 1];
41 char buf[_POSIX2_LINE_MAX];
42
43 struct nlist nl[] =
44 {
45 {"_ifnet"},
46 {""}
47 };
48
44145db3 49 ifp->mtu6 = ifp->mtu = -1;
718e3744 50
51 kvmd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, buf);
52
53 if (kvmd == NULL)
54 return ;
55
56 kvm_nlist(kvmd, nl);
57
58 ifnetaddr = nl[0].n_value;
59
60 if (kvm_read(kvmd, ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr) < 0)
61 {
62 kvm_close (kvmd);
63 return ;
64 }
65
66 while(ifnetaddr != 0)
67 {
68 if (kvm_read (kvmd, ifnetaddr, (char *)&ifnet, sizeof ifnet) < 0)
69 {
70 kvm_close (kvmd);
71 return ;
72 }
73
74 if (kvm_read (kvmd, (u_long)ifnet.if_name, ifname, IFNAMSIZ) < 0)
75 {
76 kvm_close (kvmd);
77 return ;
78 }
79
80 len = snprintf (tname, INTERFACE_NAMSIZ + 1,
81 "%s%d", ifname, ifnet.if_unit);
82
83 if (strncmp (tname, ifp->name, len) == 0)
84 break;
85
86 ifnetaddr = (u_long)ifnet.if_next;
87 }
88
89 kvm_close (kvmd);
90
91 if (ifnetaddr == 0)
92 {
93 return ;
94 }
95
44145db3 96 ifp->mtu6 = ifp->mtu = ifnet.if_mtu;
718e3744 97}