mibII.h revision 301663
1118611Snjl/* 2118611Snjl * Copyright (c) 2001-2003 3118611Snjl * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4118611Snjl * All rights reserved. 5118611Snjl * 6118611Snjl * Author: Harti Brandt <harti@freebsd.org> 7118611Snjl * 8217365Sjkim * Redistribution and use in source and binary forms, with or without 9217365Sjkim * modification, are permitted provided that the following conditions 10118611Snjl * are met: 11118611Snjl * 1. Redistributions of source code must retain the above copyright 12217365Sjkim * notice, this list of conditions and the following disclaimer. 13217365Sjkim * 2. Redistributions in binary form must reproduce the above copyright 14217365Sjkim * notice, this list of conditions and the following disclaimer in the 15217365Sjkim * documentation and/or other materials provided with the distribution. 16217365Sjkim * 17217365Sjkim * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18217365Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19217365Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20217365Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21217365Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25217365Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26118611Snjl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27217365Sjkim * SUCH DAMAGE. 28217365Sjkim * 29217365Sjkim * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.16 2006/02/14 09:04:19 brandt_h Exp $ 30118611Snjl * 31217365Sjkim * Implementation of the interfaces and IP groups of MIB-II. 32217365Sjkim */ 33217365Sjkim#include <sys/param.h> 34217365Sjkim#include <sys/sysctl.h> 35217365Sjkim#include <sys/socket.h> 36217365Sjkim#include <sys/sockio.h> 37217365Sjkim#include <sys/syslog.h> 38217365Sjkim#include <sys/time.h> 39217365Sjkim#include <stdint.h> 40217365Sjkim#include <stdio.h> 41217365Sjkim#include <stdlib.h> 42217365Sjkim#include <string.h> 43217365Sjkim#include <errno.h> 44118611Snjl#include <unistd.h> 45118611Snjl#include <err.h> 46151937Sjkim#include <ctype.h> 47118611Snjl#include <net/if.h> 48193529Sjkim#include <net/if_dl.h> 49118611Snjl#include <net/if_mib.h> 50193529Sjkim#include <net/route.h> 51193529Sjkim#include <netinet/in.h> 52118611Snjl#include <arpa/inet.h> 53118611Snjl 54118611Snjl#include "asn1.h" 55118611Snjl#include "snmp.h" 56151937Sjkim#include "snmpmod.h" 57118611Snjl#include "snmp_mibII.h" 58151937Sjkim#include "mibII_tree.h" 59151937Sjkim 60151937Sjkim/* maximum size of the interface alias */ 61151937Sjkim#define MIBIF_ALIAS_SIZE (64 + 1) 62151937Sjkim 63151937Sjkim/* 64151937Sjkim * Interface list and flags. 65151937Sjkim */ 66151937SjkimTAILQ_HEAD(mibif_list, mibif); 67151937Sjkimenum { 68151937Sjkim MIBIF_FOUND = 0x0001, 69151937Sjkim MIBIF_HIGHSPEED = 0x0002, 70151937Sjkim MIBIF_VERYHIGHSPEED = 0x0004, 71151937Sjkim}; 72151937Sjkim 73151937Sjkim/* 74151937Sjkim * Private mibif data - hang off from the mibif. 75151937Sjkim */ 76151937Sjkimstruct mibif_private { 77118611Snjl uint64_t hc_inoctets; 78118611Snjl uint64_t hc_outoctets; 79118611Snjl uint64_t hc_omcasts; 80118611Snjl uint64_t hc_opackets; 81118611Snjl uint64_t hc_imcasts; 82118611Snjl uint64_t hc_ipackets; 83118611Snjl 84118611Snjl /* this should be made public */ 85118611Snjl char alias[MIBIF_ALIAS_SIZE]; 86118611Snjl}; 87118611Snjl#define MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private)) 88118611Snjl 89151937Sjkim/* 90118611Snjl * Interface addresses. 91118611Snjl */ 92118611SnjlTAILQ_HEAD(mibifa_list, mibifa); 93118611Snjlenum { 94118611Snjl MIBIFA_FOUND = 0x0001, 95118611Snjl MIBIFA_DESTROYED = 0x0002, 96118611Snjl}; 97118611Snjl 98118611Snjl/* 99118611Snjl * Receive addresses 100118611Snjl */ 101118611SnjlTAILQ_HEAD(mibrcvaddr_list, mibrcvaddr); 102118611Snjlenum { 103118611Snjl MIBRCVADDR_FOUND = 0x00010000, 104118611Snjl}; 105118611Snjl 106118611Snjl/* 107118611Snjl * Interface index mapping. The problem here is, that if the same interface 108118611Snjl * is reinstantiated (for examble by unloading and loading the hardware driver) 109118611Snjl * we must use the same index for this interface. For dynamic interfaces 110118611Snjl * (clip, lane) we must use a fresh index, each time a new interface is created. 111118611Snjl * To differentiate between these types of interfaces we use the following table 112118611Snjl * which contains an entry for each dynamic interface type. All other interface 113118611Snjl * types are supposed to be static. The mibindexmap contains an entry for 114118611Snjl * all interfaces. The mibif pointer is NULL, if the interface doesn't exist 115118611Snjl * anymore. 116118611Snjl */ 117118611Snjlstruct mibdynif { 118118611Snjl SLIST_ENTRY(mibdynif) link; 119118611Snjl char name[IFNAMSIZ]; 120118611Snjl}; 121118611SnjlSLIST_HEAD(mibdynif_list, mibdynif); 122118611Snjl 123118611Snjlstruct mibindexmap { 124118611Snjl STAILQ_ENTRY(mibindexmap) link; 125118611Snjl u_short sysindex; 126118611Snjl u_int ifindex; 127118611Snjl struct mibif *mibif; /* may be NULL */ 128118611Snjl char name[IFNAMSIZ]; 129118611Snjl}; 130118611SnjlSTAILQ_HEAD(mibindexmap_list, mibindexmap); 131118611Snjl 132118611Snjl/* 133118611Snjl * Interface stacking. The generic code cannot know how the interfaces stack. 134118611Snjl * For this reason it instantiates only the x.0 and 0.x table elements. All 135118611Snjl * others have to be instantiated by the interface specific modules. 136151937Sjkim * The table is read-only. 137118611Snjl */ 138118611Snjlstruct mibifstack { 139118611Snjl TAILQ_ENTRY(mibifstack) link; 140118611Snjl struct asn_oid index; 141118611Snjl}; 142118611SnjlTAILQ_HEAD(mibifstack_list, mibifstack); 143118611Snjl 144118611Snjl/* 145118611Snjl * NetToMediaTable (ArpTable) 146118611Snjl */ 147118611Snjlstruct mibarp { 148118611Snjl TAILQ_ENTRY(mibarp) link; 149118611Snjl struct asn_oid index; /* contains both the ifindex and addr */ 150118611Snjl u_char phys[128]; /* the physical address */ 151118611Snjl u_int physlen; /* and its length */ 152118611Snjl u_int flags; 153118611Snjl}; 154118611SnjlTAILQ_HEAD(mibarp_list, mibarp); 155118611Snjlenum { 156118611Snjl MIBARP_FOUND = 0x00010000, 157118611Snjl MIBARP_PERM = 0x00000001, 158118611Snjl}; 159118611Snjl 160118611Snjl/* 161118611Snjl * New if registrations 162118611Snjl */ 163118611Snjlstruct newifreg { 164118611Snjl TAILQ_ENTRY(newifreg) link; 165118611Snjl const struct lmodule *mod; 166118611Snjl int (*func)(struct mibif *); 167118611Snjl}; 168118611SnjlTAILQ_HEAD(newifreg_list, newifreg); 169118611Snjl 170118611Snjl/* list of all IP addresses */ 171118611Snjlextern struct mibifa_list mibifa_list; 172118611Snjl 173118611Snjl/* list of all interfaces */ 174118611Snjlextern struct mibif_list mibif_list; 175118611Snjl 176118611Snjl/* list of dynamic interface names */ 177118611Snjlextern struct mibdynif_list mibdynif_list; 178118611Snjl 179118611Snjl/* list of all interface index mappings */ 180118611Snjlextern struct mibindexmap_list mibindexmap_list; 181118611Snjl 182151937Sjkim/* list of all stacking entries */ 183118611Snjlextern struct mibifstack_list mibifstack_list; 184118611Snjl 185118611Snjl/* list of all receive addresses */ 186118611Snjlextern struct mibrcvaddr_list mibrcvaddr_list; 187118611Snjl 188118611Snjl/* list of all NetToMedia entries */ 189118611Snjlextern struct mibarp_list mibarp_list; 190118611Snjl 191118611Snjl/* number of interfaces */ 192118611Snjlextern int32_t mib_if_number; 193118611Snjl 194118611Snjl/* last change of interface table */ 195118611Snjlextern uint64_t mib_iftable_last_change; 196118611Snjl 197118611Snjl/* last change of stack table */ 198118611Snjlextern uint64_t mib_ifstack_last_change; 199118611Snjl 200118611Snjl/* if this is set, one of our lists may be bad. refresh them when idle */ 201118611Snjlextern int mib_iflist_bad; 202118611Snjl 203118611Snjl/* last time refreshed */ 204151937Sjkimextern uint64_t mibarpticks; 205151937Sjkim 206118611Snjl/* info on system clocks */ 207118611Snjlextern struct clockinfo clockinfo; 208118611Snjl 209151937Sjkim/* baud rate of fastest interface */ 210151937Sjkimextern uint64_t mibif_maxspeed; 211118611Snjl 212118611Snjl/* user-forced update interval */ 213118611Snjlextern u_int mibif_force_hc_update_interval; 214118611Snjl 215118611Snjl/* current update interval */ 216118611Snjlextern u_int mibif_hc_update_interval; 217118611Snjl 218118611Snjl/* re-compute update interval */ 219118611Snjlvoid mibif_reset_hc_timer(void); 220118611Snjl 221118611Snjl/* interfaces' data poll interval */ 222118611Snjlextern u_int mibII_poll_ticks; 223118611Snjl 224118611Snjl/* restart the data poll timer */ 225118611Snjlvoid mibif_restart_mibII_poll_timer(void); 226118611Snjl 227118611Snjl#define MIBII_POLL_TICKS 100 228151937Sjkim 229151937Sjkim/* get interfaces and interface addresses. */ 230118611Snjlvoid mib_fetch_interfaces(void); 231118611Snjl 232118611Snjl/* check whether this interface(type) is dynamic */ 233151937Sjkimint mib_if_is_dyn(const char *name); 234151937Sjkim 235118611Snjl/* destroy an interface address */ 236118611Snjlint mib_destroy_ifa(struct mibifa *); 237118611Snjl 238118611Snjl/* restituate a deleted interface address */ 239118611Snjlvoid mib_undestroy_ifa(struct mibifa *); 240118611Snjl 241118611Snjl/* change interface address */ 242118611Snjlint mib_modify_ifa(struct mibifa *); 243118611Snjl 244118611Snjl/* undo if address modification */ 245118611Snjlvoid mib_unmodify_ifa(struct mibifa *); 246118611Snjl 247118611Snjl/* create an interface address */ 248118611Snjlstruct mibifa * mib_create_ifa(u_int ifindex, struct in_addr addr, struct in_addr mask, struct in_addr bcast); 249118611Snjl 250118611Snjl/* delete a freshly created address */ 251118611Snjlvoid mib_uncreate_ifa(struct mibifa *); 252118611Snjl 253118611Snjl/* create/delete arp entries */ 254118611Snjlstruct mibarp *mib_arp_create(const struct mibif *, struct in_addr, const u_char *, size_t); 255118611Snjlvoid mib_arp_delete(struct mibarp *); 256118611Snjl 257118611Snjl/* find arp entry */ 258118611Snjlstruct mibarp *mib_find_arp(const struct mibif *, struct in_addr); 259118611Snjl 260118611Snjl/* update arp table */ 261118611Snjlvoid mib_arp_update(void); 262118611Snjl 263118611Snjl/* fetch routing table */ 264118611Snjlu_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp); 265118611Snjl 266118611Snjl/* process routing message */ 267118611Snjlvoid mib_sroute_process(struct rt_msghdr *, struct sockaddr *, 268118611Snjl struct sockaddr *, struct sockaddr *); 269118611Snjl 270118611Snjl/* send a routing message */ 271118611Snjlvoid mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *, 272118611Snjl struct sockaddr *, struct sockaddr *); 273118611Snjl 274118611Snjl/* extract addresses from routing message */ 275118611Snjlvoid mib_extract_addrs(int, u_char *, struct sockaddr **); 276118611Snjl 277118611Snjl/* fetch routing table */ 278118611Snjlint mib_fetch_route(void); 279118611Snjl