char* typeid2string(int i) { const struct ipfix_identifier *ix; ix=ipfix_id_lookup(i); if(!ix) { return NULL; } return ix->name; }
void AnonymizerCfg::initInstance(CfgBase* c, AnonModule* module, XMLNode::XMLSet<XMLElement*> set) { for (XMLNode::XMLSet<XMLElement*>::iterator it = set.begin(); it != set.end(); it++) { XMLElement* e = *it; if (e->matches("anonField")) { InfoElementCfg* cfg = NULL; std::string method; std::string method_parameter; XMLNode::XMLSet<XMLElement*> set = e->getElementChildren(); for (XMLNode::XMLSet<XMLElement*>::iterator jt = set.begin(); jt != set.end(); ++jt) { XMLElement* e = *jt; if (e->matches("anonIE")) { if(cfg) { THROWEXCEPTION("Only on anonIE tag per anonField tag allowed"); } cfg = new InfoElementCfg(*jt); } else if (e->matches("anonMethod")) { method = c->get("anonMethod", e); } else if (e->matches("anonParam")) { method_parameter = c->get("anonParam", e); } else { msg(MSG_ERROR, "Unknown field in anonField"); continue; } } if (!cfg) { msg(MSG_FATAL, "Missing information element in anonField"); THROWEXCEPTION("Missing information element in anonField"); } if (method.empty()) { msg(MSG_FATAL, "Missing anonymization method in anonField"); THROWEXCEPTION("Missing anonymization method in anonField"); } if (cfg->getIeLength()==0) THROWEXCEPTION("Information element specified in anonField, but length==0"); module->addAnonymization(cfg->getIeId(), cfg->getIeLength(), AnonMethod::stringToMethod(method), method_parameter); const ipfix_identifier* id = ipfix_id_lookup(cfg->getIeId()); msg(MSG_INFO, "Added anonymization %s for field %i (%s) with length %i", method.c_str(), cfg->getIeId(), id->name, cfg->getIeLength()); delete cfg; } else if (e->matches("next") || e->matches("copyMode")) { // ignore next and copyMode (see createInstance) } else { msg(MSG_FATAL, "Unkown anonymization field %s\n", e->getName().c_str()); continue; } } }
/** * @returns true if given ie exists in the reverse direction */ bool IeInfo::existsReverseDirection() { // check if type was declared in ipfix.h if (ipfix_id_lookup(id, enterprise | IPFIX_PEN_reverse)==0) return false; return true; //if ((enterprise == 0) && (ipfix_id_lookup(id, IPFIX_PEN_reverse) != 0)) return true; //if ((enterprise == IPFIX_PEN_reverse) && (ipfix_id_lookup(id, 0) != 0)) return true; //if ((enterprise == IPFIX_PEN_vermont) && (ipfix_id_lookup(id^IPFIX_ETYPE_reverse_bit, IPFIX_PEN_vermont) != 0)) return true; //return false; }
int string2typelength(const char *s) { const struct ipfix_identifier *ix; ix=ipfix_id_lookup(ipfix_name_lookup(s)); if(!ix) { return 0; } return ix->length; }
IeInfo(IeId id, IeEnterpriseNumber enterprise, IeLength length = 0) : id(id), enterprise(enterprise), length(length) { if (length==0) { const ipfix_identifier* ipfixid = ipfix_id_lookup(id, enterprise); if (ipfixid) length = ipfixid->length; else { msg(MSG_INFO, "WARNING: received unknown IE type id: %s", toString().c_str()); } } }
/** * Returns IE ID of reverse direction (ATTENTION: direction change from reverse -> normal is NOT possible). * ATTENTION: this method stops Vermont if no field was found in the opposite direction * @returns IeId of IE in opposite direction */ IeInfo IeInfo::getReverseDirection() { if (enterprise & IPFIX_PEN_reverse) THROWEXCEPTION("requested reverse direction of enterprise type id %s", toString().c_str()); // check if type was declared in ipfix.h if (ipfix_id_lookup(id, enterprise | IPFIX_PEN_reverse)==0) THROWEXCEPTION("did not find reverse element for %s", toString().c_str()); return IeInfo(id, enterprise | IPFIX_PEN_reverse, length); //ipfix_identifier* id; //if ((enterprise == 0) && ((id = ipfix_id_lookup(id, IPFIX_PEN_reverse)) != 0)) return IeInfo(id); //if ((enterprise == IPFIX_PEN_reverse) && ((id = ipfix_id_lookup(id, 0)) != 0)) return IeInfo(id); //if ((enterprise == IPFIX_PEN_vermont) && ((id = ipfix_id_lookup(id^IPFIX_ETYPE_reverse_bit, IPFIX_PEN_vermont)) != 0)) return IeInfo(id); //THROWEXCEPTION("did not find reverse element for %s", toString().c_str()); }
Template* PacketReportingCfg::getTemplate() { msg(MSG_DEBUG, "Creating template"); if (t) return t; t = new Template(templateId); for (size_t i = 0; i != exportedFields.size(); ++i) { int tmpId = exportedFields[i]->getIeId(); if (!ipfix_id_rangecheck(tmpId)) { msg(MSG_ERROR, "Template: ignoring template field %s -> %d - rangecheck not ok", exportedFields[i]->getName().c_str(), tmpId); continue; } const ipfix_identifier *id = ipfix_id_lookup(tmpId); if ((tmpId == -1) || (id == NULL)) { msg(MSG_ERROR, "Template: ignoring unknown template field %s", exportedFields[i]->getName().c_str()); continue; } uint16_t fieldLength = id->length; if (exportedFields[i]->hasOptionalLength()) { // field length 65535 indicates variable length encoding // we allow configuring a fixed length for IEs with variabel length (and length=0) if ((fieldLength == 0) || (fieldLength == 65535)) { fieldLength = exportedFields[i]->getIeLength(); } else { msg(MSG_ERROR, "Template: this is not a variable length field, ignoring optional length"); } } if (fieldLength == 65535) recordVLFields++; else recordLength += fieldLength; msg(MSG_FATAL, "Template: adding %s -> ID %d with size %d", exportedFields[i]->getName().c_str(), id->id, fieldLength); t->addField((uint16_t)id->id, fieldLength); } msg(MSG_DEBUG, "Template: got %d fields, record length is %u +%u * capture_len", t->getFieldCount(), recordLength,recordVLFields); return t; }
string IeInfo::toString() const { char buffer[100]; const ipfix_identifier* ipfixid = ipfix_id_lookup(id, enterprise); if (enterprise == 0) snprintf(buffer, ARRAY_SIZE(buffer), "%s (id=%hu, length=%hu)", ipfixid ? ipfixid->name : "unknown", id, length); else if (enterprise == IPFIX_PEN_reverse) snprintf(buffer, ARRAY_SIZE(buffer), "%s (id=%hu, pen=%u [reverse], length=%hu)", ipfixid ? ipfixid->name : "unknown", id, enterprise, length); else if (enterprise == IPFIX_PEN_vermont) snprintf(buffer, ARRAY_SIZE(buffer), "%s (id=%hu, pen=%u [vermont], length=%hu)", ipfixid ? ipfixid->name : "unknown", id, enterprise, length); else snprintf(buffer, ARRAY_SIZE(buffer), "%s (id=%hu, pen=%u, length=%hu)", ipfixid ? ipfixid->name : "unknown", id, enterprise, length); return buffer; }
void AnonModule::addAnonymization(uint16_t id, int len, AnonMethod::Method methodName, const std::string& parameter) { static const struct ipfix_identifier* ident; AnonPrimitive* a = createPrimitive(methodName, parameter); if (methods.find(id) != methods.end()) { methods[id].primitive.push_back(a); } else { AnonIE ie; if (len == -1) { if (!(ident = ipfix_id_lookup(id))) { msg(MSG_ERROR, "Unknown or unsupported id %i detected.", id); return; } len = ident->length; } ie.offset = ie.header = ie.packetClass = 0; ie.len = len; ie.primitive.push_back(a); methods[id] = ie; } }
void AnonModule::addAnonymization(InformationElement::IeInfo id, int len, AnonMethod::Method methodName, std::vector<map_info> mapping, const std::string& parameter) { static const struct ipfix_identifier* ident; AnonPrimitive* a = createPrimitive(methodName, parameter, mapping); if (methods.find(id) != methods.end()) { methods[id].primitive.push_back(a); } else { AnonIE ie; if (len == -1) { if (!(ident = ipfix_id_lookup(id.id, id.enterprise))) { msg(MSG_ERROR, "Unknown or unsupported id %s detected.", id.toString().c_str()); return; } len = ident->length; } ie.offset = ie.header = ie.packetClass = 0; // attention: if ie.len==0, anonField() assumes that it is a variable length field and the whole information element will be processed ie.len = len; ie.primitive.push_back(a); methods[id] = ie; } }