| 1 |
/* |
| 2 |
* Interface MIB architecture support |
| 3 |
* |
| 4 |
* $Id$ |
| 5 |
*/ |
| 6 |
#include <net-snmp/net-snmp-config.h> |
| 7 |
#include <net-snmp/net-snmp-includes.h> |
| 8 |
#include "mibII/mibII_common.h" |
| 9 |
|
| 10 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 11 |
#include <net-snmp/data_access/interface.h> |
| 12 |
#include <net-snmp/data_access/route.h> |
| 13 |
#include <net-snmp/data_access/ipaddress.h> |
| 14 |
|
| 15 |
#include <inet/ip.h> |
| 16 |
#include <inet/mib2.h> |
| 17 |
|
| 18 |
#include "ip-forward-mib/data_access/route_ioctl.h" |
| 19 |
#include "ip-forward-mib/inetCidrRouteTable/inetCidrRouteTable_constants.h" |
| 20 |
#include "if-mib/data_access/interface_ioctl.h" |
| 21 |
#include "route_private.h" |
| 22 |
|
| 23 |
static int _load_v4(netsnmp_container *container); |
| 24 |
static int _load_v6(netsnmp_container *container); |
| 25 |
|
| 26 |
/** arch specific load |
| 27 |
* @internal |
| 28 |
* |
| 29 |
* @retval 0 success |
| 30 |
* @retval -1 no container specified |
| 31 |
* @retval -2 could not open data file |
| 32 |
*/ |
| 33 |
int |
| 34 |
netsnmp_access_route_container_arch_load(netsnmp_container* container, |
| 35 |
u_int load_flags) |
| 36 |
{ |
| 37 |
int rc; |
| 38 |
|
| 39 |
DEBUGMSGTL(("access:route:container", |
| 40 |
"route_container_arch_load (flags %x)\n", load_flags)); |
| 41 |
|
| 42 |
if (NULL == container) { |
| 43 |
snmp_log(LOG_ERR, "no container specified/found for access_route\n"); |
| 44 |
return -1; |
| 45 |
} |
| 46 |
|
| 47 |
rc = _load_v4(container); |
| 48 |
|
| 49 |
#ifdef NETSNMP_ENABLE_IPV6 |
| 50 |
if((0 != rc) || (load_flags & NETSNMP_ACCESS_ROUTE_LOAD_IPV4_ONLY)) |
| 51 |
return rc; |
| 52 |
|
| 53 |
/* |
| 54 |
* load ipv6. ipv6 module might not be loaded, |
| 55 |
* so ignore -2 err (file not found) |
| 56 |
*/ |
| 57 |
rc = _load_v6(container); |
| 58 |
if (-2 == rc) |
| 59 |
rc = 0; |
| 60 |
#endif |
| 61 |
|
| 62 |
return rc; |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* create a new entry |
| 67 |
*/ |
| 68 |
int |
| 69 |
netsnmp_arch_route_create(netsnmp_route_entry *entry) |
| 70 |
{ |
| 71 |
if (NULL == entry) |
| 72 |
return -1; |
| 73 |
|
| 74 |
if (4 != entry->rt_dest_len) { |
| 75 |
DEBUGMSGT(("access:route:create", "only ipv4 supported\n")); |
| 76 |
return -2; |
| 77 |
} |
| 78 |
|
| 79 |
/* return _netsnmp_ioctl_route_set_v4(entry); */ |
| 80 |
return -2; |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* create a new entry |
| 85 |
*/ |
| 86 |
int |
| 87 |
netsnmp_arch_route_delete(netsnmp_route_entry *entry) |
| 88 |
{ |
| 89 |
if (NULL == entry) |
| 90 |
return -1; |
| 91 |
|
| 92 |
if (4 != entry->rt_dest_len) { |
| 93 |
DEBUGMSGT(("access:route:create", "only ipv4 supported\n")); |
| 94 |
return -2; |
| 95 |
} |
| 96 |
|
| 97 |
/* return _netsnmp_ioctl_route_delete_v4(entry); */ |
| 98 |
return -2; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
static int |
| 103 |
IP_Cmp_Route(void *addr, void *ep) |
| 104 |
{ |
| 105 |
mib2_ipRouteEntry_t *Ep = ep, *Addr = addr; |
| 106 |
|
| 107 |
if ((Ep->ipRouteDest == Addr->ipRouteDest) && |
| 108 |
(Ep->ipRouteNextHop == Addr->ipRouteNextHop) && |
| 109 |
(Ep->ipRouteType == Addr->ipRouteType) && |
| 110 |
(Ep->ipRouteProto == Addr->ipRouteProto) && |
| 111 |
(Ep->ipRouteMask == Addr->ipRouteMask) && |
| 112 |
(Ep->ipRouteInfo.re_max_frag == Addr->ipRouteInfo.re_max_frag) && |
| 113 |
(Ep->ipRouteInfo.re_rtt == Addr->ipRouteInfo.re_rtt) && |
| 114 |
(Ep->ipRouteInfo.re_ref == Addr->ipRouteInfo.re_ref) && |
| 115 |
(Ep->ipRouteInfo.re_frag_flag == Addr->ipRouteInfo.re_frag_flag) && |
| 116 |
(Ep->ipRouteInfo.re_src_addr == Addr->ipRouteInfo.re_src_addr) && |
| 117 |
(Ep->ipRouteInfo.re_ire_type == Addr->ipRouteInfo.re_ire_type) && |
| 118 |
(Ep->ipRouteInfo.re_obpkt == Addr->ipRouteInfo.re_obpkt) && |
| 119 |
(Ep->ipRouteInfo.re_ibpkt == Addr->ipRouteInfo.re_ibpkt) |
| 120 |
) |
| 121 |
return (0); |
| 122 |
else |
| 123 |
return (1); /* Not found */ |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
static int |
| 128 |
IP6_Cmp_Route(void *addr, void *ep) |
| 129 |
{ |
| 130 |
mib2_ipv6RouteEntry_t *Ep = ep, *Addr = addr; |
| 131 |
|
| 132 |
if ((memcmp(&Ep->ipv6RouteDest, &Addr->ipv6RouteDest, 16) == 0) && |
| 133 |
(memcmp(&Ep->ipv6RouteNextHop, &Addr->ipv6RouteNextHop, 16) == 0) && |
| 134 |
(Ep->ipv6RouteType == Addr->ipv6RouteType) && |
| 135 |
(Ep->ipv6RouteInfo.re_max_frag == Addr->ipv6RouteInfo.re_max_frag) && |
| 136 |
(Ep->ipv6RouteInfo.re_rtt == Addr->ipv6RouteInfo.re_rtt) && |
| 137 |
(Ep->ipv6RouteInfo.re_ref == Addr->ipv6RouteInfo.re_ref) && |
| 138 |
(Ep->ipv6RouteInfo.re_frag_flag == Addr->ipv6RouteInfo.re_frag_flag) && |
| 139 |
(memcmp(&Ep->ipv6RouteInfo.re_src_addr, &Addr->ipv6RouteInfo.re_src_addr, 16) == 0) && |
| 140 |
(Ep->ipv6RouteInfo.re_ire_type == Addr->ipv6RouteInfo.re_ire_type) && |
| 141 |
(Ep->ipv6RouteInfo.re_obpkt == Addr->ipv6RouteInfo.re_obpkt) && |
| 142 |
(Ep->ipv6RouteInfo.re_ibpkt == Addr->ipv6RouteInfo.re_ibpkt) |
| 143 |
) |
| 144 |
return (0); |
| 145 |
else |
| 146 |
return (1); /* Not found */ |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
static int _load_v4(netsnmp_container *container) |
| 151 |
{ |
| 152 |
netsnmp_route_entry *entry; |
| 153 |
mib2_ipRouteEntry_t Curentry, Nextentry; |
| 154 |
int req_type; |
| 155 |
|
| 156 |
for (Nextentry.ipRouteDest = (u_long) -2, req_type = GET_FIRST;; |
| 157 |
Nextentry = Curentry, req_type = GET_NEXT) { |
| 158 |
if (getMibstat(MIB_IP_ROUTE, &Curentry, sizeof(mib2_ipRouteEntry_t), |
| 159 |
req_type, &IP_Cmp_Route, &Nextentry) != 0) |
| 160 |
break; |
| 161 |
#ifdef HAVE_DEFINED_IRE_CACHE |
| 162 |
if (Curentry.ipRouteInfo.re_ire_type & IRE_CACHE) |
| 163 |
continue; |
| 164 |
#endif /* HAVE_DEFINED_IRE_CACHE */ |
| 165 |
if (Curentry.ipRouteInfo.re_ire_type & IRE_BROADCAST) |
| 166 |
continue; |
| 167 |
entry = netsnmp_access_route_entry_create(); |
| 168 |
Curentry.ipRouteIfIndex.o_bytes[Curentry.ipRouteIfIndex.o_length] = '\0'; |
| 169 |
entry->if_index = netsnmp_access_interface_index_find( |
| 170 |
Curentry.ipRouteIfIndex.o_bytes); |
| 171 |
entry->ns_rt_index = entry->if_index; |
| 172 |
|
| 173 |
entry->rt_dest_type = INETADDRESSTYPE_IPV4; |
| 174 |
entry->rt_dest_len = 4; |
| 175 |
memcpy(entry->rt_dest, &Curentry.ipRouteDest, 4); |
| 176 |
memcpy(&entry->rt_mask, &Curentry.ipRouteMask, 4); |
| 177 |
|
| 178 |
entry->rt_nexthop_type = INETADDRESSTYPE_IPV4; |
| 179 |
entry->rt_nexthop_len = 4; |
| 180 |
memcpy(entry->rt_nexthop, &Curentry.ipRouteNextHop, 4); |
| 181 |
|
| 182 |
entry->rt_pfx_len = netsnmp_ipaddress_ipv4_prefix_len(Curentry.ipRouteMask); |
| 183 |
entry->rt_type = Curentry.ipRouteType; |
| 184 |
entry->rt_proto = Curentry.ipRouteProto; |
| 185 |
entry->rt_age = Curentry.ipRouteAge; |
| 186 |
entry->rt_metric1 = Curentry.ipRouteMetric1; |
| 187 |
entry->rt_metric2 = Curentry.ipRouteMetric2; |
| 188 |
entry->rt_metric3 = Curentry.ipRouteMetric3; |
| 189 |
entry->rt_metric4 = Curentry.ipRouteMetric4; |
| 190 |
|
| 191 |
/* |
| 192 |
* insert into container |
| 193 |
*/ |
| 194 |
if (CONTAINER_INSERT(container, entry) < 0) { |
| 195 |
DEBUGMSGTL(("access:route:container", "error with route_entry: insert into container failed.\n")); |
| 196 |
netsnmp_access_route_entry_free(entry); |
| 197 |
continue; |
| 198 |
} |
| 199 |
} |
| 200 |
return 0; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
static int _load_v6(netsnmp_container *container) |
| 205 |
{ |
| 206 |
netsnmp_route_entry *entry; |
| 207 |
mib2_ipv6RouteEntry_t Curentry, Nextentry; |
| 208 |
int req_type; |
| 209 |
|
| 210 |
memset(&Nextentry, 0, sizeof(Nextentry)); |
| 211 |
for (req_type = GET_FIRST;; |
| 212 |
Nextentry = Curentry, req_type = GET_NEXT) { |
| 213 |
if (getMibstat(MIB_IP6_ROUTE, &Curentry, sizeof(mib2_ipv6RouteEntry_t), |
| 214 |
req_type, &IP6_Cmp_Route, &Nextentry) != 0) |
| 215 |
break; |
| 216 |
#ifdef HAVE_DEFINED_IRE_CACHE |
| 217 |
if (Curentry.ipv6RouteInfo.re_ire_type & IRE_CACHE) |
| 218 |
continue; |
| 219 |
#endif /* HAVE_DEFINED_IRE_CACHE */ |
| 220 |
if (Curentry.ipv6RouteInfo.re_ire_type & IRE_BROADCAST) |
| 221 |
continue; |
| 222 |
entry = netsnmp_access_route_entry_create(); |
| 223 |
Curentry.ipv6RouteIfIndex.o_bytes[Curentry.ipv6RouteIfIndex.o_length] = '\0'; |
| 224 |
entry->if_index = netsnmp_access_interface_index_find( |
| 225 |
Curentry.ipv6RouteIfIndex.o_bytes); |
| 226 |
entry->ns_rt_index = entry->if_index; |
| 227 |
|
| 228 |
entry->rt_dest_type = INETADDRESSTYPE_IPV6; |
| 229 |
entry->rt_dest_len = 16; |
| 230 |
memcpy(entry->rt_dest, &Curentry.ipv6RouteDest, 16); |
| 231 |
|
| 232 |
entry->rt_nexthop_type = INETADDRESSTYPE_IPV6; |
| 233 |
entry->rt_nexthop_len = 16; |
| 234 |
memcpy(entry->rt_nexthop, &Curentry.ipv6RouteNextHop, 16); |
| 235 |
|
| 236 |
entry->rt_pfx_len = Curentry.ipv6RoutePfxLength; |
| 237 |
entry->rt_type = Curentry.ipv6RouteType; |
| 238 |
entry->rt_proto = Curentry.ipv6RouteProtocol; |
| 239 |
entry->rt_age = Curentry.ipv6RouteAge; |
| 240 |
entry->rt_policy = calloc(3, sizeof(oid)); |
| 241 |
entry->rt_policy_len = 3; |
| 242 |
entry->rt_policy[2] = Curentry.ipv6RoutePolicy; |
| 243 |
entry->rt_metric1 = Curentry.ipv6RouteMetric; |
| 244 |
entry->rt_metric2 = Curentry.ipv6RouteWeight; |
| 245 |
|
| 246 |
/* |
| 247 |
* insert into container |
| 248 |
*/ |
| 249 |
if (CONTAINER_INSERT(container, entry) < 0) { |
| 250 |
DEBUGMSGTL(("access:route:container", "error with route_entry: insert into container failed.\n")); |
| 251 |
netsnmp_access_route_entry_free(entry); |
| 252 |
continue; |
| 253 |
} |
| 254 |
} |
| 255 |
return 0; |
| 256 |
} |