| 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/route.h> |
| 12 |
#include "route.h" |
| 13 |
#include "route_private.h" |
| 14 |
|
| 15 |
/**---------------------------------------------------------------------*/ |
| 16 |
/* |
| 17 |
* local static prototypes |
| 18 |
*/ |
| 19 |
static void _access_route_entry_release(void *entry, void *unused); |
| 20 |
|
| 21 |
/**---------------------------------------------------------------------*/ |
| 22 |
/* |
| 23 |
* container functions |
| 24 |
*/ |
| 25 |
|
| 26 |
/** |
| 27 |
* @retval NULL error |
| 28 |
* @retval !NULL pointer to container |
| 29 |
*/ |
| 30 |
netsnmp_container* |
| 31 |
netsnmp_access_route_container_load(netsnmp_container* container, u_int load_flags) |
| 32 |
{ |
| 33 |
int rc; |
| 34 |
|
| 35 |
DEBUGMSGTL(("access:route:container", "load\n")); |
| 36 |
|
| 37 |
if (NULL == container) { |
| 38 |
container = netsnmp_container_find("access:_route:fifo"); |
| 39 |
if (NULL == container) { |
| 40 |
snmp_log(LOG_ERR, "no container specified/found for access_route\n"); |
| 41 |
return NULL; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
container->container_name = strdup("_route"); |
| 46 |
|
| 47 |
rc = netsnmp_access_route_container_arch_load(container, load_flags); |
| 48 |
if (0 != rc) { |
| 49 |
netsnmp_access_route_container_free(container, NETSNMP_ACCESS_ROUTE_FREE_NOFLAGS); |
| 50 |
container = NULL; |
| 51 |
} |
| 52 |
|
| 53 |
return container; |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
netsnmp_access_route_container_free(netsnmp_container *container, u_int free_flags) |
| 58 |
{ |
| 59 |
DEBUGMSGTL(("access:route:container", "free\n")); |
| 60 |
|
| 61 |
if (NULL == container) { |
| 62 |
snmp_log(LOG_ERR, "invalid container for netsnmp_access_route_free\n"); |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
if(! (free_flags & NETSNMP_ACCESS_ROUTE_FREE_DONT_CLEAR)) { |
| 67 |
/* |
| 68 |
* free all items. |
| 69 |
*/ |
| 70 |
CONTAINER_CLEAR(container, _access_route_entry_release, NULL); |
| 71 |
} |
| 72 |
else { |
| 73 |
/* |
| 74 |
* free the CONTAINER's sl_nodes, but not their data |
| 75 |
*/ |
| 76 |
CONTAINER_CLEAR(container, NULL, NULL); |
| 77 |
} |
| 78 |
|
| 79 |
if(! (free_flags & NETSNMP_ACCESS_ROUTE_FREE_KEEP_CONTAINER)) |
| 80 |
CONTAINER_FREE(container); |
| 81 |
} |
| 82 |
|
| 83 |
/**---------------------------------------------------------------------*/ |
| 84 |
/* |
| 85 |
* ifentry functions |
| 86 |
*/ |
| 87 |
/** create route entry |
| 88 |
* |
| 89 |
* @note: |
| 90 |
* if you create a route for entry into a container of your own, you |
| 91 |
* must set ns_rt_index to a unique index for your container. |
| 92 |
*/ |
| 93 |
netsnmp_route_entry * |
| 94 |
netsnmp_access_route_entry_create(void) |
| 95 |
{ |
| 96 |
netsnmp_route_entry *entry = SNMP_MALLOC_TYPEDEF(netsnmp_route_entry); |
| 97 |
if(NULL == entry) { |
| 98 |
snmp_log(LOG_ERR, "could not allocate route entry\n"); |
| 99 |
return NULL; |
| 100 |
} |
| 101 |
|
| 102 |
entry->oid_index.oids = &entry->ns_rt_index; |
| 103 |
entry->oid_index.len = 1; |
| 104 |
|
| 105 |
entry->rt_metric1 = -1; |
| 106 |
entry->rt_metric2 = -1; |
| 107 |
entry->rt_metric3 = -1; |
| 108 |
entry->rt_metric4 = -1; |
| 109 |
entry->rt_metric5 = -1; |
| 110 |
|
| 111 |
/** entry->row_status? */ |
| 112 |
|
| 113 |
return entry; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
*/ |
| 118 |
void |
| 119 |
netsnmp_access_route_entry_free(netsnmp_route_entry * entry) |
| 120 |
{ |
| 121 |
if (NULL == entry) |
| 122 |
return; |
| 123 |
|
| 124 |
#ifdef USING_IP_FORWARD_MIB_INETCIDRROUTETABLE_INETCIDRROUTETABLE_MODULE |
| 125 |
if ((NULL != entry->rt_policy) && |
| 126 |
!(entry->flags & NETSNMP_ACCESS_ROUTE_POLICY_STATIC)) |
| 127 |
free(entry->rt_policy); |
| 128 |
#endif |
| 129 |
#ifdef USING_IP_FORWARD_MIB_IPCIDRROUTETABLE_IPCIDRROUTETABLE_MODULE |
| 130 |
if (NULL != entry->rt_info) |
| 131 |
free(entry->rt_info); |
| 132 |
#endif |
| 133 |
|
| 134 |
free(entry); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* update underlying data store (kernel) for entry |
| 140 |
* |
| 141 |
* @retval 0 : success |
| 142 |
* @retval -1 : error |
| 143 |
*/ |
| 144 |
int |
| 145 |
netsnmp_access_route_entry_set(netsnmp_route_entry * entry) |
| 146 |
{ |
| 147 |
int rc = SNMP_ERR_NOERROR; |
| 148 |
|
| 149 |
if (NULL == entry) { |
| 150 |
netsnmp_assert(NULL != entry); |
| 151 |
return -1; |
| 152 |
} |
| 153 |
|
| 154 |
/* |
| 155 |
* |
| 156 |
*/ |
| 157 |
if (entry->flags & NETSNMP_ACCESS_ROUTE_CREATE) { |
| 158 |
rc = netsnmp_arch_route_create(entry); |
| 159 |
} |
| 160 |
else if (entry->flags & NETSNMP_ACCESS_ROUTE_CHANGE) { |
| 161 |
/** xxx-rks:9 route change not implemented */ |
| 162 |
snmp_log(LOG_ERR,"netsnmp_access_route_entry_set change not supported yet\n"); |
| 163 |
rc = -1; |
| 164 |
} |
| 165 |
else if (entry->flags & NETSNMP_ACCESS_ROUTE_DELETE) { |
| 166 |
rc = netsnmp_arch_route_delete(entry); |
| 167 |
} |
| 168 |
else { |
| 169 |
snmp_log(LOG_ERR,"netsnmp_access_route_entry_set with no mode\n"); |
| 170 |
netsnmp_assert(!"route_entry_set == unknown mode"); /* always false */ |
| 171 |
rc = -1; |
| 172 |
} |
| 173 |
|
| 174 |
return rc; |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* copy an route_entry |
| 179 |
* |
| 180 |
* @retval -1 : error |
| 181 |
* @retval 0 : no error |
| 182 |
*/ |
| 183 |
int |
| 184 |
netsnmp_access_route_entry_copy(netsnmp_route_entry *lhs, |
| 185 |
netsnmp_route_entry *rhs) |
| 186 |
{ |
| 187 |
#if 0 /* no arch stuff in route (yet) */ |
| 188 |
int rc; |
| 189 |
|
| 190 |
/* |
| 191 |
* copy arch stuff. we don't care if it changed |
| 192 |
*/ |
| 193 |
rc = netsnmp_arch_route_entry_copy(lhs,rhs); |
| 194 |
if (0 != rc) { |
| 195 |
snmp_log(LOG_ERR,"arch route copy failed\n"); |
| 196 |
return -1; |
| 197 |
} |
| 198 |
#endif |
| 199 |
|
| 200 |
lhs->if_index = rhs->if_index; |
| 201 |
|
| 202 |
lhs->rt_dest_len = rhs->rt_dest_len; |
| 203 |
memcpy(lhs->rt_dest, rhs->rt_dest, rhs->rt_dest_len); |
| 204 |
lhs->rt_dest_type = rhs->rt_dest_type; |
| 205 |
|
| 206 |
lhs->rt_nexthop_len = rhs->rt_nexthop_len; |
| 207 |
memcpy(lhs->rt_nexthop, rhs->rt_nexthop, rhs->rt_nexthop_len); |
| 208 |
lhs->rt_nexthop_type = rhs->rt_nexthop_type; |
| 209 |
|
| 210 |
#ifdef USING_IP_FORWARD_MIB_INETCIDRROUTETABLE_INETCIDRROUTETABLE_MODULE |
| 211 |
if (NULL != lhs->rt_policy) { |
| 212 |
if (NETSNMP_ACCESS_ROUTE_POLICY_STATIC & lhs->flags) |
| 213 |
lhs->rt_policy = NULL; |
| 214 |
else { |
| 215 |
SNMP_FREE(lhs->rt_policy); |
| 216 |
} |
| 217 |
} |
| 218 |
if (NULL != rhs->rt_policy) { |
| 219 |
if ((NETSNMP_ACCESS_ROUTE_POLICY_STATIC & rhs->flags) && |
| 220 |
! (NETSNMP_ACCESS_ROUTE_POLICY_DEEP_COPY & rhs->flags)) { |
| 221 |
lhs->rt_policy = rhs->rt_policy; |
| 222 |
} |
| 223 |
else { |
| 224 |
snmp_clone_mem((void **) &lhs->rt_policy, rhs->rt_policy, |
| 225 |
rhs->rt_policy_len * sizeof(oid)); |
| 226 |
} |
| 227 |
} |
| 228 |
lhs->rt_policy_len = rhs->rt_policy_len; |
| 229 |
#endif |
| 230 |
|
| 231 |
lhs->rt_pfx_len = rhs->rt_pfx_len; |
| 232 |
lhs->rt_type = rhs->rt_type; |
| 233 |
lhs->rt_proto = rhs->rt_proto; |
| 234 |
|
| 235 |
#ifdef USING_IP_FORWARD_MIB_IPCIDRROUTETABLE_IPCIDRROUTETABLE_MODULE |
| 236 |
SNMP_FREE(lhs->rt_info); |
| 237 |
if (NULL != rhs->rt_info) |
| 238 |
snmp_clone_mem((void **) &lhs->rt_info, rhs->rt_info, |
| 239 |
rhs->rt_info_len * sizeof(oid)); |
| 240 |
lhs->rt_info_len = rhs->rt_info_len; |
| 241 |
|
| 242 |
lhs->rt_mask = rhs->rt_mask; |
| 243 |
lhs->rt_tos = rhs->rt_tos; |
| 244 |
#endif |
| 245 |
|
| 246 |
lhs->rt_age = rhs->rt_age; |
| 247 |
lhs->rt_nexthop_as = rhs->rt_nexthop_as; |
| 248 |
|
| 249 |
lhs->rt_metric1 = rhs->rt_metric1; |
| 250 |
lhs->rt_metric2 = rhs->rt_metric2; |
| 251 |
lhs->rt_metric3 = rhs->rt_metric3; |
| 252 |
lhs->rt_metric4 = rhs->rt_metric4; |
| 253 |
lhs->rt_metric5 = rhs->rt_metric5; |
| 254 |
|
| 255 |
lhs->flags = rhs->flags; |
| 256 |
|
| 257 |
return 0; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
/**---------------------------------------------------------------------*/ |
| 262 |
/* |
| 263 |
* Utility routines |
| 264 |
*/ |
| 265 |
|
| 266 |
/** |
| 267 |
*/ |
| 268 |
void |
| 269 |
_access_route_entry_release(void *entry, void *context) |
| 270 |
{ |
| 271 |
netsnmp_access_route_entry_free(entry); |
| 272 |
} |