| 1 |
/* |
| 2 |
* Template MIB group implementation - at.c |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* Portions of this file are subject to the following copyright(s). See |
| 7 |
* the Net-SNMP's COPYING file for more details and other copyrights |
| 8 |
* that may apply: |
| 9 |
*/ |
| 10 |
/* |
| 11 |
* Portions of this file are copyrighted by: |
| 12 |
* Copyright © 2003 Sun Microsystems, Inc. All rights reserved. |
| 13 |
* Use is subject to license terms specified in the COPYING file |
| 14 |
* distributed with the Net-SNMP package. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <net-snmp/net-snmp-config.h> |
| 18 |
#include <net-snmp/net-snmp-includes.h> |
| 19 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 20 |
#include <net-snmp/data_access/interface.h> |
| 21 |
#include "../at.h" |
| 22 |
|
| 23 |
/* |
| 24 |
* var_atEntry(... |
| 25 |
* Arguments: |
| 26 |
* vp IN - pointer to variable entry that points here |
| 27 |
* name IN/OUT - IN/name requested, OUT/name found |
| 28 |
* length IN/OUT - length of IN/OUT oid's |
| 29 |
* exact IN - TRUE if an exact match was requested |
| 30 |
* var_len OUT - length of variable or 0 if function returned |
| 31 |
* write_method |
| 32 |
* |
| 33 |
*/ |
| 34 |
|
| 35 |
u_char * |
| 36 |
var_atEntry(struct variable *vp, |
| 37 |
oid * name, |
| 38 |
size_t * length, |
| 39 |
int exact, size_t * var_len, WriteMethod ** write_method) |
| 40 |
{ |
| 41 |
/* |
| 42 |
* Address Translation table object identifier is of form: |
| 43 |
* 1.3.6.1.2.1.3.1.1.1.interface.1.A.B.C.D, where A.B.C.D is IP address. |
| 44 |
* Interface is at offset 10, |
| 45 |
* IPADDR starts at offset 12. |
| 46 |
* |
| 47 |
* IP Net to Media table object identifier is of form: |
| 48 |
* 1.3.6.1.2.1.4.22.1.1.1.interface.A.B.C.D, where A.B.C.D is IP address. |
| 49 |
* Interface is at offset 10, |
| 50 |
* IPADDR starts at offset 11. |
| 51 |
*/ |
| 52 |
u_char *cp; |
| 53 |
oid *op; |
| 54 |
oid lowest[16]; |
| 55 |
oid current[16]; |
| 56 |
static char PhysAddr[MAX_MAC_ADDR_LEN], LowPhysAddr[MAX_MAC_ADDR_LEN]; |
| 57 |
static int PhysAddrLen, LowPhysAddrLen; |
| 58 |
in_addr_t Addr, LowAddr; |
| 59 |
int foundone; |
| 60 |
static in_addr_t addr_ret; |
| 61 |
u_short ifIndex, lowIfIndex = 0; |
| 62 |
u_long ifType, lowIfType = 0; |
| 63 |
|
| 64 |
int oid_length; |
| 65 |
|
| 66 |
/* |
| 67 |
* fill in object part of name for current (less sizeof instance part) |
| 68 |
*/ |
| 69 |
memcpy(current, vp->name, vp->namelen * sizeof(oid)); |
| 70 |
|
| 71 |
if (current[6] == 3) { /* AT group oid */ |
| 72 |
oid_length = 16; |
| 73 |
} else { /* IP NetToMedia group oid */ |
| 74 |
oid_length = 15; |
| 75 |
} |
| 76 |
|
| 77 |
LowAddr = 0; /* Don't have one yet */ |
| 78 |
foundone = 0; |
| 79 |
ARP_Scan_Init(); |
| 80 |
for (;;) { |
| 81 |
if (ARP_Scan_Next(&Addr, PhysAddr, &PhysAddrLen, &ifType, &ifIndex) == 0) |
| 82 |
break; |
| 83 |
current[10] = ifIndex; |
| 84 |
|
| 85 |
if (current[6] == 3) { /* AT group oid */ |
| 86 |
current[11] = 1; |
| 87 |
op = current + 12; |
| 88 |
} else { /* IP NetToMedia group oid */ |
| 89 |
op = current + 11; |
| 90 |
} |
| 91 |
cp = (u_char *) & Addr; |
| 92 |
*op++ = *cp++; |
| 93 |
*op++ = *cp++; |
| 94 |
*op++ = *cp++; |
| 95 |
*op++ = *cp++; |
| 96 |
|
| 97 |
if (exact) { |
| 98 |
if (snmp_oid_compare(current, oid_length, name, *length) == 0) { |
| 99 |
memcpy((char *) lowest, (char *) current, |
| 100 |
oid_length * sizeof(oid)); |
| 101 |
LowAddr = Addr; |
| 102 |
foundone = 1; |
| 103 |
lowIfIndex = ifIndex; |
| 104 |
memcpy(LowPhysAddr, PhysAddr, sizeof(PhysAddr)); |
| 105 |
LowPhysAddrLen = PhysAddrLen; |
| 106 |
lowIfType = ifType; |
| 107 |
break; /* no need to search further */ |
| 108 |
} |
| 109 |
} else { |
| 110 |
if ((snmp_oid_compare(current, oid_length, name, *length) > 0) |
| 111 |
&& ((foundone == 0) |
| 112 |
|| |
| 113 |
(snmp_oid_compare |
| 114 |
(current, oid_length, lowest, oid_length) < 0))) { |
| 115 |
/* |
| 116 |
* if new one is greater than input and closer to input than |
| 117 |
* previous lowest, save this one as the "next" one. |
| 118 |
*/ |
| 119 |
memcpy(lowest, current, oid_length * sizeof(oid)); |
| 120 |
LowAddr = Addr; |
| 121 |
foundone = 1; |
| 122 |
lowIfIndex = ifIndex; |
| 123 |
memcpy(LowPhysAddr, PhysAddr, sizeof(PhysAddr)); |
| 124 |
LowPhysAddrLen = PhysAddrLen; |
| 125 |
lowIfType = ifType; |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
if (foundone == 0) |
| 130 |
return NULL; |
| 131 |
|
| 132 |
memcpy(name, lowest, oid_length * sizeof(oid)); |
| 133 |
*length = oid_length; |
| 134 |
*write_method = NULL; |
| 135 |
switch (vp->magic) { |
| 136 |
case IPMEDIAIFINDEX: /* also ATIFINDEX */ |
| 137 |
*var_len = sizeof long_return; |
| 138 |
long_return = lowIfIndex ? lowIfIndex : 1; |
| 139 |
#ifdef NETSNMP_NO_DUMMY_VALUES |
| 140 |
if (lowIfIndex == 0) |
| 141 |
return NULL; |
| 142 |
#endif |
| 143 |
return (u_char *) & long_return; |
| 144 |
case IPMEDIAPHYSADDRESS: /* also ATPHYSADDRESS */ |
| 145 |
*var_len = LowPhysAddrLen; |
| 146 |
return (u_char *) LowPhysAddr; |
| 147 |
case IPMEDIANETADDRESS: /* also ATNETADDRESS */ |
| 148 |
*var_len = sizeof(addr_ret); |
| 149 |
addr_ret = LowAddr; |
| 150 |
return (u_char *) & addr_ret; |
| 151 |
case IPMEDIATYPE: |
| 152 |
*var_len = sizeof long_return; |
| 153 |
long_return = lowIfType; |
| 154 |
return (u_char *) & long_return; |
| 155 |
default: |
| 156 |
DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_atEntry\n", |
| 157 |
vp->magic)); |
| 158 |
} |
| 159 |
return NULL; |
| 160 |
} |