static int writeRemoteAddress(int action, unsigned char *var_val, unsigned char var_val_type, size_t var_val_len, unsigned char *statP, oid * name, size_t name_len) { static struct tunnel *tunnel; struct ip_tunnel_parm *parm; switch (action) { case RESERVE1: if (var_val_type != ASN_IPADDRESS) { return SNMP_ERR_WRONGTYPE; } if (var_val_len != 4) { return SNMP_ERR_WRONGLENGTH; } case RESERVE2: tunnel = getTunnelByIfIndex((int) name[name_len - 1]); if (!tunnel) { return SNMP_ERR_NOSUCHNAME; } case FREE: break; case ACTION: break; case UNDO: break; case COMMIT: if (!tunnel) { return SNMP_ERR_NOSUCHNAME; } parm = getTunnelParm(tunnel->ifname); if (!parm) { return SNMP_ERR_NOSUCHNAME; } parm->iph.daddr = *(unsigned long *) var_val; setTunnelParm(tunnel->ifname, parm); break; } return SNMP_ERR_NOERROR; }
unsigned char * var_tunnelIfEntry(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { static unsigned long ret_addr; static long ret_int; struct tunnel *tunnel; DEBUGMSGTL(("tunnel", "var_tunnelIfEntry: ")); DEBUGMSGOID(("tunnel", name, *length)); DEBUGMSG(("tunnel", " %d\n", exact)); updateTunnels(); if (exact) { if (*length != tunnel_len + 3 + 1) { return NULL; } tunnel = getTunnelByIfIndex((int) name[*length - 1]); } else { if ((*length) < tunnel_len) { memcpy((char *) name, (char *) tunnel_variables_oid, tunnel_len * sizeof(oid)); } if ((*length) < tunnel_len + 1) { name[tunnel_len] = 1; } if ((*length) < tunnel_len + 2) { name[tunnel_len + 1] = 1; } if ((*length) < tunnel_len + 3) { name[tunnel_len + 2] = 1; } if ((*length) < tunnel_len + 4) { name[tunnel_len + 3] = 0; } *length = tunnel_len + 4; tunnel = getNextTunnelByIfIndex(name[*length - 1]); if (!tunnel) { /* * end of column, continue with first row of next column */ tunnel = tunnels; name[tunnel_len + 2]++; if (name[tunnel_len + 2] > 6) { /* * there is no next column */ return NULL; } if (!tunnel) { /* * there is no (next) row */ return NULL; } } } if (!tunnel) { return NULL; } name[*length - 1] = tunnel->ifindex; DEBUGMSGTL(("tunnel", "var_tunnelIfEntry: using")); DEBUGMSGOID(("tunnel", name, *length)); DEBUGMSG(("tunnel", "\n")); switch (name[tunnel_len + 2]) { case 1: /* tunnelIfLocalAddress */ ret_addr = tunnel->local; *var_len = 4; vp->type = ASN_IPADDRESS; *write_method = writeLocalAddress; return (u_char *) & ret_addr; case 2: /* tunnelIfRemoteAddress */ ret_addr = tunnel->remote; *var_len = 4; vp->type = ASN_IPADDRESS; *write_method = writeRemoteAddress; return (u_char *) & ret_addr; case 3: /* tunnelIfEncapsMethod */ ret_int = tunnel->encaps; *var_len = sizeof(ret_int); vp->type = ASN_INTEGER; return (u_char *) & ret_int; case 4: /* tunnelIfHopLimit */ ret_int = tunnel->hoplimit; *var_len = sizeof(ret_int); vp->type = ASN_INTEGER; *write_method = writeHopLimit; return (u_char *) & ret_int; case 5: /* tunnelIfSecurity */ ret_int = tunnel->security; *var_len = sizeof(ret_int); vp->type = ASN_INTEGER; return (u_char *) & ret_int; case 6: /* tunnelIfTOS */ ret_int = tunnel->tos; *var_len = sizeof(ret_int); vp->type = ASN_INTEGER; *write_method = writeTOS; return (u_char *) & ret_int; default: return 0; } return NULL; }