| 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 "kernel_sunos5.h" |
| 22 |
#include "../at.h" |
| 23 |
|
| 24 |
typedef struct if_ip { |
| 25 |
int ifIdx; |
| 26 |
IpAddress ipAddr; |
| 27 |
} if_ip_t; |
| 28 |
|
| 29 |
static int |
| 30 |
AT_Cmp(void *addr, void *ep) |
| 31 |
{ |
| 32 |
mib2_ipNetToMediaEntry_t *mp = (mib2_ipNetToMediaEntry_t *) ep; |
| 33 |
int ret = -1; |
| 34 |
oid index; |
| 35 |
|
| 36 |
mp->ipNetToMediaIfIndex.o_bytes[mp->ipNetToMediaIfIndex.o_length] = '\0'; |
| 37 |
index = netsnmp_access_interface_index_find( |
| 38 |
mp->ipNetToMediaIfIndex.o_bytes); |
| 39 |
DEBUGMSGTL(("mibII/at", "......... AT_Cmp %lx<>%lx %d<>%" NETSNMP_PRIo "d (%.5s)\n", |
| 40 |
(unsigned long)mp->ipNetToMediaNetAddress, |
| 41 |
(unsigned long)((if_ip_t *) addr)->ipAddr, |
| 42 |
((if_ip_t *) addr)->ifIdx, index, |
| 43 |
mp->ipNetToMediaIfIndex.o_bytes)); |
| 44 |
if (mp->ipNetToMediaNetAddress != ((if_ip_t *) addr)->ipAddr) |
| 45 |
ret = 1; |
| 46 |
else if (((if_ip_t *) addr)->ifIdx != index) |
| 47 |
ret = 1; |
| 48 |
else |
| 49 |
ret = 0; |
| 50 |
DEBUGMSGTL(("mibII/at", "......... AT_Cmp returns %d\n", ret)); |
| 51 |
return ret; |
| 52 |
} |
| 53 |
|
| 54 |
u_char * |
| 55 |
var_atEntry(struct variable * vp, |
| 56 |
oid * name, |
| 57 |
size_t * length, |
| 58 |
int exact, size_t * var_len, WriteMethod ** write_method) |
| 59 |
{ |
| 60 |
/* |
| 61 |
* object identifier is of form: |
| 62 |
* 1.3.6.1.2.1.3.1.1.1.interface.1.A.B.C.D, where A.B.C.D is IP address. |
| 63 |
* Interface is at offset 10, |
| 64 |
* IPADDR starts at offset 12. |
| 65 |
*/ |
| 66 |
#define AT_MAX_NAME_LENGTH 16 |
| 67 |
#define AT_IFINDEX_OFF 10 |
| 68 |
u_char *cp; |
| 69 |
oid *op; |
| 70 |
oid lowest[AT_MAX_NAME_LENGTH]; |
| 71 |
oid current[AT_MAX_NAME_LENGTH]; |
| 72 |
if_ip_t NextAddr; |
| 73 |
mib2_ipNetToMediaEntry_t entry; |
| 74 |
static mib2_ipNetToMediaEntry_t Lowentry; |
| 75 |
int Found = 0; |
| 76 |
req_e req_type; |
| 77 |
int offset, olength = 0; |
| 78 |
static in_addr_t addr_ret; |
| 79 |
|
| 80 |
/* |
| 81 |
* fill in object part of name for current (less sizeof instance part) |
| 82 |
*/ |
| 83 |
|
| 84 |
DEBUGMSGTL(("mibII/at", "var_atEntry: ")); |
| 85 |
DEBUGMSGOID(("mibII/at", vp->name, vp->namelen)); |
| 86 |
DEBUGMSG(("mibII/at", " %d\n", exact)); |
| 87 |
|
| 88 |
memset(&Lowentry, 0, sizeof(Lowentry)); |
| 89 |
memcpy((char *) current, (char *) vp->name, vp->namelen * sizeof(oid)); |
| 90 |
lowest[0] = 1024; |
| 91 |
for (NextAddr.ipAddr = (u_long) - 1, NextAddr.ifIdx = 255, req_type = |
| 92 |
GET_FIRST;; |
| 93 |
NextAddr.ipAddr = entry.ipNetToMediaNetAddress, NextAddr.ifIdx = |
| 94 |
current[AT_IFINDEX_OFF], req_type = GET_NEXT) { |
| 95 |
if (getMibstat |
| 96 |
(MIB_IP_NET, &entry, sizeof(mib2_ipNetToMediaEntry_t), |
| 97 |
req_type, &AT_Cmp, &NextAddr) != 0) |
| 98 |
break; |
| 99 |
entry.ipNetToMediaIfIndex.o_bytes[entry.ipNetToMediaIfIndex.o_length] = '\0'; |
| 100 |
current[AT_IFINDEX_OFF] = netsnmp_access_interface_index_find( |
| 101 |
entry.ipNetToMediaIfIndex.o_bytes); |
| 102 |
if (current[6] == 3) { /* AT group oid */ |
| 103 |
current[AT_IFINDEX_OFF + 1] = 1; |
| 104 |
offset = AT_IFINDEX_OFF + 2; |
| 105 |
olength = AT_IFINDEX_OFF + 6; |
| 106 |
} else { |
| 107 |
offset = AT_IFINDEX_OFF + 1; |
| 108 |
olength = AT_IFINDEX_OFF + 5; |
| 109 |
} |
| 110 |
COPY_IPADDR(cp, (u_char *) & entry.ipNetToMediaNetAddress, op, |
| 111 |
current + offset); |
| 112 |
if (exact) { |
| 113 |
if (snmp_oid_compare(current, olength, name, *length) == 0) { |
| 114 |
memcpy((char *) lowest, (char *) current, |
| 115 |
olength * sizeof(oid)); |
| 116 |
Lowentry = entry; |
| 117 |
Found++; |
| 118 |
break; /* no need to search further */ |
| 119 |
} |
| 120 |
} else { |
| 121 |
if (snmp_oid_compare(current, olength, name, *length) > 0 && |
| 122 |
(Found == 0 || |
| 123 |
snmp_oid_compare(current, olength, lowest, olength) < 0)) { |
| 124 |
/* |
| 125 |
* if new one is greater than input and closer to input than |
| 126 |
* previous lowest, and is not equal to it, save this one as the "next" one. |
| 127 |
*/ |
| 128 |
memcpy((char *) lowest, (char *) current, |
| 129 |
olength * sizeof(oid)); |
| 130 |
Lowentry = entry; |
| 131 |
Found++; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
DEBUGMSGTL(("mibII/at", "... Found = %d\n", Found)); |
| 136 |
if (Found == 0) |
| 137 |
return (NULL); |
| 138 |
memcpy((char *) name, (char *) lowest, olength * sizeof(oid)); |
| 139 |
*length = olength; |
| 140 |
*write_method = 0; |
| 141 |
switch (vp->magic) { |
| 142 |
case IPMEDIAIFINDEX: |
| 143 |
*var_len = sizeof long_return; |
| 144 |
Lowentry.ipNetToMediaIfIndex.o_bytes[ |
| 145 |
Lowentry.ipNetToMediaIfIndex.o_length] = '\0'; |
| 146 |
long_return = netsnmp_access_interface_index_find( |
| 147 |
Lowentry.ipNetToMediaIfIndex.o_bytes); |
| 148 |
return (u_char *) & long_return; |
| 149 |
case IPMEDIAPHYSADDRESS: |
| 150 |
*var_len = Lowentry.ipNetToMediaPhysAddress.o_length; |
| 151 |
return (u_char *) Lowentry.ipNetToMediaPhysAddress.o_bytes; |
| 152 |
case IPMEDIANETADDRESS: |
| 153 |
*var_len = sizeof(addr_ret); |
| 154 |
addr_ret = Lowentry.ipNetToMediaNetAddress; |
| 155 |
return (u_char *) &addr_ret; |
| 156 |
case IPMEDIATYPE: |
| 157 |
*var_len = sizeof long_return; |
| 158 |
long_return = Lowentry.ipNetToMediaType; |
| 159 |
return (u_char *) & long_return; |
| 160 |
default: |
| 161 |
DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_atEntry\n", |
| 162 |
vp->magic)); |
| 163 |
} |
| 164 |
return NULL; |
| 165 |
} |