1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.15 2005/06/09 12:36:53 brandt_h Exp $ 30 * 31 * Implementation of the interfaces and IP groups of MIB-II. 32 */ 33#include <sys/param.h> 34#include <sys/sysctl.h> 35#include <sys/socket.h> 36#include <sys/sockio.h> 37#include <sys/syslog.h> 38#include <sys/time.h> 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <errno.h> 43#include <unistd.h> 44#include <err.h> 45#include <ctype.h> 46#include <net/if.h> 47#include <net/if_dl.h> 48#include <net/if_mib.h> 49#include <net/route.h> 50#include <netinet/in.h> 51#include <arpa/inet.h> 52 53#include "asn1.h" 54#include "snmp.h" 55#include "snmpmod.h" 56#include "snmp_mibII.h" 57#include "mibII_tree.h" 58
| 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.15 2005/06/09 12:36:53 brandt_h Exp $ 30 * 31 * Implementation of the interfaces and IP groups of MIB-II. 32 */ 33#include <sys/param.h> 34#include <sys/sysctl.h> 35#include <sys/socket.h> 36#include <sys/sockio.h> 37#include <sys/syslog.h> 38#include <sys/time.h> 39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <errno.h> 43#include <unistd.h> 44#include <err.h> 45#include <ctype.h> 46#include <net/if.h> 47#include <net/if_dl.h> 48#include <net/if_mib.h> 49#include <net/route.h> 50#include <netinet/in.h> 51#include <arpa/inet.h> 52 53#include "asn1.h" 54#include "snmp.h" 55#include "snmpmod.h" 56#include "snmp_mibII.h" 57#include "mibII_tree.h" 58
|
59
| |
60/* 61 * Interface list and flags. 62 */ 63TAILQ_HEAD(mibif_list, mibif); 64enum { 65 MIBIF_FOUND = 0x0001, 66 MIBIF_HIGHSPEED = 0x0002, 67 MIBIF_VERYHIGHSPEED = 0x0004, 68};
| 59/* 60 * Interface list and flags. 61 */ 62TAILQ_HEAD(mibif_list, mibif); 63enum { 64 MIBIF_FOUND = 0x0001, 65 MIBIF_HIGHSPEED = 0x0002, 66 MIBIF_VERYHIGHSPEED = 0x0004, 67};
|
69#define hc_inoctets mib.ifmd_data.ifi_ibytes 70#define hc_outoctets mib.ifmd_data.ifi_obytes 71#define hc_omcasts mib.ifmd_data.ifi_omcasts 72#define hc_opackets mib.ifmd_data.ifi_opackets 73#define hc_imcasts mib.ifmd_data.ifi_imcasts 74#define hc_ipackets mib.ifmd_data.ifi_ipackets
| |
75 76/*
| 68 69/*
|
| 70 * Private mibif data - hang off from the mibif. 71 */ 72struct mibif_private { 73 uint64_t hc_inoctets; 74 uint64_t hc_outoctets; 75 uint64_t hc_omcasts; 76 uint64_t hc_opackets; 77 uint64_t hc_imcasts; 78 uint64_t hc_ipackets; 79}; 80#define MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private)) 81 82/*
|
77 * Interface addresses. 78 */ 79TAILQ_HEAD(mibifa_list, mibifa); 80enum { 81 MIBIFA_FOUND = 0x0001, 82 MIBIFA_DESTROYED = 0x0002, 83}; 84 85/* 86 * Receive addresses 87 */ 88TAILQ_HEAD(mibrcvaddr_list, mibrcvaddr); 89enum { 90 MIBRCVADDR_FOUND = 0x00010000, 91}; 92 93/* 94 * Interface index mapping. The problem here is, that if the same interface 95 * is reinstantiated (for examble by unloading and loading the hardware driver) 96 * we must use the same index for this interface. For dynamic interfaces 97 * (clip, lane) we must use a fresh index, each time a new interface is created. 98 * To differentiate between these types of interfaces we use the following table 99 * which contains an entry for each dynamic interface type. All other interface 100 * types are supposed to be static. The mibindexmap contains an entry for 101 * all interfaces. The mibif pointer is NULL, if the interface doesn't exist 102 * anymore. 103 */ 104struct mibdynif { 105 SLIST_ENTRY(mibdynif) link; 106 char name[IFNAMSIZ]; 107}; 108SLIST_HEAD(mibdynif_list, mibdynif); 109 110struct mibindexmap { 111 STAILQ_ENTRY(mibindexmap) link; 112 u_short sysindex; 113 u_int ifindex; 114 struct mibif *mibif; /* may be NULL */ 115 char name[IFNAMSIZ]; 116}; 117STAILQ_HEAD(mibindexmap_list, mibindexmap); 118 119/* 120 * Interface stacking. The generic code cannot know how the interfaces stack. 121 * For this reason it instantiates only the x.0 and 0.x table elements. All 122 * others have to be instantiated by the interface specific modules. 123 * The table is read-only. 124 */ 125struct mibifstack { 126 TAILQ_ENTRY(mibifstack) link; 127 struct asn_oid index; 128}; 129TAILQ_HEAD(mibifstack_list, mibifstack); 130 131/* 132 * NetToMediaTable (ArpTable) 133 */ 134struct mibarp { 135 TAILQ_ENTRY(mibarp) link; 136 struct asn_oid index; /* contains both the ifindex and addr */ 137 u_char phys[128]; /* the physical address */ 138 u_int physlen; /* and its length */ 139 u_int flags; 140}; 141TAILQ_HEAD(mibarp_list, mibarp); 142enum { 143 MIBARP_FOUND = 0x00010000, 144 MIBARP_PERM = 0x00000001, 145}; 146 147/* 148 * New if registrations 149 */ 150struct newifreg { 151 TAILQ_ENTRY(newifreg) link; 152 const struct lmodule *mod; 153 int (*func)(struct mibif *); 154}; 155TAILQ_HEAD(newifreg_list, newifreg); 156 157/* list of all IP addresses */ 158extern struct mibifa_list mibifa_list; 159 160/* list of all interfaces */ 161extern struct mibif_list mibif_list; 162 163/* list of dynamic interface names */ 164extern struct mibdynif_list mibdynif_list; 165 166/* list of all interface index mappings */ 167extern struct mibindexmap_list mibindexmap_list; 168 169/* list of all stacking entries */ 170extern struct mibifstack_list mibifstack_list; 171 172/* list of all receive addresses */ 173extern struct mibrcvaddr_list mibrcvaddr_list; 174 175/* list of all NetToMedia entries */ 176extern struct mibarp_list mibarp_list; 177 178/* number of interfaces */ 179extern int32_t mib_if_number; 180 181/* last change of interface table */ 182extern uint64_t mib_iftable_last_change; 183 184/* last change of stack table */ 185extern uint64_t mib_ifstack_last_change; 186 187/* if this is set, one of our lists may be bad. refresh them when idle */ 188extern int mib_iflist_bad; 189 190/* last time refreshed */ 191extern uint64_t mibarpticks; 192 193/* info on system clocks */ 194extern struct clockinfo clockinfo; 195
| 83 * Interface addresses. 84 */ 85TAILQ_HEAD(mibifa_list, mibifa); 86enum { 87 MIBIFA_FOUND = 0x0001, 88 MIBIFA_DESTROYED = 0x0002, 89}; 90 91/* 92 * Receive addresses 93 */ 94TAILQ_HEAD(mibrcvaddr_list, mibrcvaddr); 95enum { 96 MIBRCVADDR_FOUND = 0x00010000, 97}; 98 99/* 100 * Interface index mapping. The problem here is, that if the same interface 101 * is reinstantiated (for examble by unloading and loading the hardware driver) 102 * we must use the same index for this interface. For dynamic interfaces 103 * (clip, lane) we must use a fresh index, each time a new interface is created. 104 * To differentiate between these types of interfaces we use the following table 105 * which contains an entry for each dynamic interface type. All other interface 106 * types are supposed to be static. The mibindexmap contains an entry for 107 * all interfaces. The mibif pointer is NULL, if the interface doesn't exist 108 * anymore. 109 */ 110struct mibdynif { 111 SLIST_ENTRY(mibdynif) link; 112 char name[IFNAMSIZ]; 113}; 114SLIST_HEAD(mibdynif_list, mibdynif); 115 116struct mibindexmap { 117 STAILQ_ENTRY(mibindexmap) link; 118 u_short sysindex; 119 u_int ifindex; 120 struct mibif *mibif; /* may be NULL */ 121 char name[IFNAMSIZ]; 122}; 123STAILQ_HEAD(mibindexmap_list, mibindexmap); 124 125/* 126 * Interface stacking. The generic code cannot know how the interfaces stack. 127 * For this reason it instantiates only the x.0 and 0.x table elements. All 128 * others have to be instantiated by the interface specific modules. 129 * The table is read-only. 130 */ 131struct mibifstack { 132 TAILQ_ENTRY(mibifstack) link; 133 struct asn_oid index; 134}; 135TAILQ_HEAD(mibifstack_list, mibifstack); 136 137/* 138 * NetToMediaTable (ArpTable) 139 */ 140struct mibarp { 141 TAILQ_ENTRY(mibarp) link; 142 struct asn_oid index; /* contains both the ifindex and addr */ 143 u_char phys[128]; /* the physical address */ 144 u_int physlen; /* and its length */ 145 u_int flags; 146}; 147TAILQ_HEAD(mibarp_list, mibarp); 148enum { 149 MIBARP_FOUND = 0x00010000, 150 MIBARP_PERM = 0x00000001, 151}; 152 153/* 154 * New if registrations 155 */ 156struct newifreg { 157 TAILQ_ENTRY(newifreg) link; 158 const struct lmodule *mod; 159 int (*func)(struct mibif *); 160}; 161TAILQ_HEAD(newifreg_list, newifreg); 162 163/* list of all IP addresses */ 164extern struct mibifa_list mibifa_list; 165 166/* list of all interfaces */ 167extern struct mibif_list mibif_list; 168 169/* list of dynamic interface names */ 170extern struct mibdynif_list mibdynif_list; 171 172/* list of all interface index mappings */ 173extern struct mibindexmap_list mibindexmap_list; 174 175/* list of all stacking entries */ 176extern struct mibifstack_list mibifstack_list; 177 178/* list of all receive addresses */ 179extern struct mibrcvaddr_list mibrcvaddr_list; 180 181/* list of all NetToMedia entries */ 182extern struct mibarp_list mibarp_list; 183 184/* number of interfaces */ 185extern int32_t mib_if_number; 186 187/* last change of interface table */ 188extern uint64_t mib_iftable_last_change; 189 190/* last change of stack table */ 191extern uint64_t mib_ifstack_last_change; 192 193/* if this is set, one of our lists may be bad. refresh them when idle */ 194extern int mib_iflist_bad; 195 196/* last time refreshed */ 197extern uint64_t mibarpticks; 198 199/* info on system clocks */ 200extern struct clockinfo clockinfo; 201
|
| 202/* baud rate of fastest interface */ 203extern uint64_t mibif_maxspeed; 204 205/* user-forced update interval */ 206extern u_int mibif_force_hc_update_interval; 207 208/* current update interval */ 209extern u_int mibif_hc_update_interval; 210 211/* re-compute update interval */ 212void mibif_reset_hc_timer(void); 213
|
196/* get interfaces and interface addresses. */ 197void mib_fetch_interfaces(void); 198 199/* check whether this interface(type) is dynamic */ 200int mib_if_is_dyn(const char *name); 201 202/* destroy an interface address */ 203int mib_destroy_ifa(struct mibifa *); 204 205/* restituate a deleted interface address */ 206void mib_undestroy_ifa(struct mibifa *); 207 208/* change interface address */ 209int mib_modify_ifa(struct mibifa *); 210 211/* undo if address modification */ 212void mib_unmodify_ifa(struct mibifa *); 213 214/* create an interface address */ 215struct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast); 216 217/* delete a freshly created address */ 218void mib_uncreate_ifa(struct mibifa *); 219 220/* create/delete arp entries */ 221struct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t); 222void mib_arp_delete(struct mibarp *); 223 224/* find arp entry */ 225struct mibarp *mib_find_arp(const struct mibif *, struct in_addr); 226 227/* update arp table */ 228void mib_arp_update(void); 229 230/* fetch routing table */ 231u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp); 232 233/* process routing message */ 234void mib_sroute_process(struct rt_msghdr *, struct sockaddr *, 235 struct sockaddr *, struct sockaddr *); 236 237/* send a routing message */ 238void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *, 239 struct sockaddr *, struct sockaddr *); 240 241/* extract addresses from routing message */ 242void mib_extract_addrs(int, u_char *, struct sockaddr **); 243 244/* fetch routing table */ 245int mib_fetch_route(void);
| 214/* get interfaces and interface addresses. */ 215void mib_fetch_interfaces(void); 216 217/* check whether this interface(type) is dynamic */ 218int mib_if_is_dyn(const char *name); 219 220/* destroy an interface address */ 221int mib_destroy_ifa(struct mibifa *); 222 223/* restituate a deleted interface address */ 224void mib_undestroy_ifa(struct mibifa *); 225 226/* change interface address */ 227int mib_modify_ifa(struct mibifa *); 228 229/* undo if address modification */ 230void mib_unmodify_ifa(struct mibifa *); 231 232/* create an interface address */ 233struct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast); 234 235/* delete a freshly created address */ 236void mib_uncreate_ifa(struct mibifa *); 237 238/* create/delete arp entries */ 239struct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t); 240void mib_arp_delete(struct mibarp *); 241 242/* find arp entry */ 243struct mibarp *mib_find_arp(const struct mibif *, struct in_addr); 244 245/* update arp table */ 246void mib_arp_update(void); 247 248/* fetch routing table */ 249u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp); 250 251/* process routing message */ 252void mib_sroute_process(struct rt_msghdr *, struct sockaddr *, 253 struct sockaddr *, struct sockaddr *); 254 255/* send a routing message */ 256void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *, 257 struct sockaddr *, struct sockaddr *); 258 259/* extract addresses from routing message */ 260void mib_extract_addrs(int, u_char *, struct sockaddr **); 261 262/* fetch routing table */ 263int mib_fetch_route(void);
|