Пример #1
0
/**
 * Main function for register standalone
 */
void register_main(const char *exename, int argc, const char * const *argv)
{
  struct sockaddr_in saddr;
  const char *stream_name;

  if (argc < 2)
    usage(exename);

  saddr = parseIp(argv[0]);
  stream_name = argv[1];

  register_stream(saddr, stream_name);
}
Пример #2
0
/**
 * Main function for store standalone
 */
void store_main(const char *exename, int argc, const char * const *argv)
{
  struct sockaddr_in saddr;
  const char *stream_name;
  const char *filename;

  if (argc < 3)
    usage(exename);

  saddr = parseIp(argv[0]);
  stream_name = argv[1];
  filename = argv[2];

  store(saddr, stream_name, filename);
}
/*
 *    LASIpBuild
 *    INPUT
 *    attr_pattern    A comma-separated list of IP addresses and netmasks
 *            in dotted-decimal form.  Netmasks are optionally
 *            prepended to the IP address using a plus sign.  E.g.
 *            255.255.255.0+123.45.67.89.  Any byte in the IP address
 *            (but not the netmask) can be wildcarded using "*"
 *    context         A pointer to the IP LAS context structure.
 *    buildOnlyIpVersion       int will determine the size of the tree to build
 *    RETURNS
 *    ret code    The usual LAS return codes. In case of SUCCESS, IP address
 *                version (PR_AF_INET or PR_AF_INET6 or PR_AF_INET+PR_AF_INET6).
 */
static int
LASIpBuild(NSErr_t *errp, char *attr_pattern, LASIpTree_t **treetop, 
           int buildOnlyIpVersion)
{
    unsigned int delimiter;                /* length of valid token     */
    char        token[1024], token2[1024];    /* a single ip[+netmask]     */
    char        *curptr;                /* current place in attr_pattern */
    PRNetAddr   netmask;
    PRNetAddr   ip;
    char        *plusptr;
    int            retcode;
    int currIpVersion = -1;
    int count=0;

    /* ip address can be delimited by space, tab, comma, or carriage return
     * only.
     */
    curptr = attr_pattern;
    do {
        delimiter    = strcspn(curptr, ", \t");
        delimiter    = (delimiter <= strlen(curptr)) ? delimiter : strlen(curptr);
        strncpy(token, curptr, delimiter);
        token[delimiter] = '\0';
        /* skip all the white space after the token */
        curptr = strpbrk((curptr+delimiter), VALID_CHARS_IN_PATTERN);

        /* Is there a netmask?    */
        plusptr    = strchr(token, '+');
        if (plusptr == NULL) {
            if (curptr && (*curptr == '+')) {
                /* There was a space before (and possibly after) the plus sign*/
                curptr = strpbrk((++curptr), VALID_CHARS_IN_IP);
                delimiter    = strcspn(curptr, ", \t");
                delimiter    = (delimiter <= strlen(curptr)) ? delimiter : strlen(curptr);
                strncpy(token2, curptr, delimiter);
                token2[delimiter] = '\0';
                currIpVersion = parseIp(token, token2, &ip, &netmask);
                // When ip=* return PR_AF_INET6+PR_AF_INET, so that calling
                // function can skip some processing like comparing bits
                if (currIpVersion == SUM_PR_AF_INET_AND_INET6) {
                    return (currIpVersion);
                }
                curptr = strpbrk((++curptr), VALID_CHARS_IN_PATTERN);
            } else {
                currIpVersion = parseIp(token, NULL, &ip, &netmask);
                // When ip=* return PR_AF_INET6+PR_AF_INET, so that calling
                // function can skip some processing like comparing bits
                if (currIpVersion == SUM_PR_AF_INET_AND_INET6) {
                    return (currIpVersion);
                }
            }
        } else {
            /* token is the IP addr string in both cases */
            *plusptr ='\0';    /* truncate the string */
            currIpVersion = parseIp(token, ++plusptr, &ip, &netmask);
            // When ip=* return PR_AF_INET6+PR_AF_INET, so that calling
            // function can skip some processing like comparing bits
            if (currIpVersion == SUM_PR_AF_INET_AND_INET6) {
                return (currIpVersion);
            }
        }

        if ((currIpVersion == PR_AF_INET6) || (currIpVersion == PR_AF_INET))
           count++;
        if (currIpVersion == buildOnlyIpVersion) {
            retcode = LASIpAddPattern(errp, netmask, ip, treetop, currIpVersion);
            if (retcode) {
                return LAS_EVAL_INVALID;
            }
        }
    } while ((curptr != NULL) && (delimiter != (int)NULL));

    // Atleast one of the IP Addresses specified was a valid IP Address
    // Return the IP address version so that  32 bits or 128 bits are
    // compared in the tree.
    if (count)
        return buildOnlyIpVersion;
    else
        return LAS_EVAL_INVALID;
}
Пример #4
0
IDSLoadbalancerCfg::IDSLoadbalancerCfg(XMLElement* elem)
	: CfgHelper<IDSLoadbalancer, IDSLoadbalancerCfg>(elem, "IDSLoadbalancer"),
	selector(NULL),
	updateInterval(0)
{
	if (!elem) return;

	XMLNode::XMLSet<XMLElement*> set = elem->getElementChildren();
	for (XMLNode::XMLSet<XMLElement*>::iterator it = set.begin(); it != set.end(); it++) {
		XMLElement* e = *it;

		if (e->matches("updateinterval")) {
			updateInterval = getInt("updateinterval", 0, e);
		} else if (e->matches("PacketSelector")) {
			XMLAttribute *a = e->getAttribute("type");
			if (!a)
				THROWEXCEPTION("no PacketSelector specified");
			string _selector = a->getValue();

			if (_selector == "HashPacketSelector") {
				if (!selector) {
					selector = new HashPacketSelector();
				} else
					THROWEXCEPTION("IDSLoadBalancerCfg: multiple packet selectors specified! This is not allowed.");
			} else if (_selector == "IpPacketSelector") {
				msg(MSG_DEBUG, "IpPacketSelector");
				XMLNode::XMLSet<XMLElement*> set = e->getElementChildren();
				for (XMLNode::XMLSet<XMLElement*>::iterator it = set.begin(); it != set.end(); it++) {
					XMLElement* e = *it;
					if (e->matches("DestinationIp")){
						XMLAttribute *a = e->getAttribute("queueno");
						if (!a)
							THROWEXCEPTION("No queue number specified");
						int queueno = 0;
						std::string tmp = a->getValue();
						try {
							queueno = boost::lexical_cast<int>(tmp);
						}catch (boost::bad_lexical_cast &){
							THROWEXCEPTION("bad value for queue number: %s", tmp.c_str());
						}
						std::string ip = e->getFirstText();
						dst[parseIp(ip)] = queueno;
					}else if (e->matches("SourceIp")){
						XMLElement* e = *it;
						XMLAttribute *a = e->getAttribute("queueno");
						if (!a)
							THROWEXCEPTION("No queue number specified");
						int queueno = 0;
						std::string tmp = a->getValue();
						try {
							queueno = boost::lexical_cast<int>(tmp);
						}catch (boost::bad_lexical_cast &){
							THROWEXCEPTION("bad value for queue number: %s", tmp.c_str());
						}
						std::string ip = e->getFirstText();
						src[parseIp(ip)] = queueno;
					}
				}
				if (!selector) {
					selector = new IpPacketSelector();
					if (src.empty() && dst.empty())
						THROWEXCEPTION("IDSLoadBalancerCfg: packet selector IpPacketSelector was defined, but no source or destination IPs!");
				} else
					THROWEXCEPTION("IDSLoadBalancerCfg: multiple packet selectors specified! This is not allowed.");

			} else if (_selector == "PriorityPacketSelector") {
				float startprio = getDouble("startPriority", 1.0, e);
				uint32_t minmontime = getInt("minimumMonitoringTime", 10000, e);
				uint32_t maxspeed = getInt("maxSpeed", 0, e);
				list<PriorityNetConfig> config;
				list<WeightModifierConfig> weightmods;
				XMLNode::XMLSet<XMLElement*> set = e->getElementChildren();
				for (XMLNode::XMLSet<XMLElement*>::iterator it = set.begin(); it != set.end(); it++) {
					XMLElement* e = *it;
					if (e->matches("networks")) {
						XMLNode::XMLSet<XMLElement*> netset = e->getElementChildren();
						for (XMLNode::XMLSet<XMLElement*>::iterator nit = netset.begin(); nit != netset.end(); nit++) {
							XMLElement* e = *nit;
							if (e->matches("network")) {
								XMLAttribute* a = e->getAttribute("address");
								if (!a) THROWEXCEPTION("IDSLoadBalancerCfg: no attribute 'address' in configuration element 'network'!");
								string cidr = a->getFirstText();
								size_t pos = cidr.find("/");
								string ip = cidr.substr(0, pos);
								string sbits = cidr.substr(pos+1);
								int maskbits = atoi(sbits.c_str());
								if (maskbits<0 || maskbits>32)
									THROWEXCEPTION("IDSLoadBalancerCfg: attribute 'address' has invalid number of mask bits in configuration (%s)!", sbits.c_str());
								in_addr_t ipaddr = inet_addr(ip.c_str());
								if (ipaddr==(in_addr_t)-1)
									THROWEXCEPTION("IDSLoadBalancerCfg: attribute 'address' has invalid ip subnet in configuration (%s)!", ip.c_str());
								a = e->getAttribute("weight");
								if (!a) THROWEXCEPTION("IDSLoadBalancerCfg: no attribute 'weight' in configuration element 'network'!");
								char* res;
								float weight = strtof(a->getFirstText().c_str(), &res);
								if (weight<=0 || res==a->getFirstText().c_str())
									THROWEXCEPTION("IDSLoadBalancerCfg: attribute 'weight' in configuration element 'network' contains invalid value (%s)!", a->getFirstText().c_str());
								config.push_back(PriorityNetConfig(ntohl((uint32_t)ipaddr), ((1<<(32-maskbits))-1)^0xFFFFFFFF, maskbits, weight));
							}
						}
					}
					if (e->matches("weightModifiers")) {
						XMLNode::XMLSet<XMLElement*> netset = e->getElementChildren();
						for (XMLNode::XMLSet<XMLElement*>::iterator nit = netset.begin(); nit != netset.end(); nit++) {
							XMLElement* e = *nit;
							if (e->matches("traffic")) {
								XMLAttribute* a = e->getAttribute("quantile");
								if (!a) THROWEXCEPTION("IDSLoadBalancerCfg: no attribute 'quantile' in configuration element 'traffic'!");
								char* res;
								float quantile = strtof(a->getFirstText().c_str(), &res);
								if (quantile<=0 || quantile>1 || res==a->getFirstText().c_str())
									THROWEXCEPTION("IDSLoadBalancerCfg: attribute 'quantile' is not in expected range (0<x<=1): %s", a->getFirstText().c_str());
								a = e->getAttribute("weightModifier");
								if (!a) THROWEXCEPTION("IDSLoadBalancerCfg: no attribute 'weightModifier' in configuration element 'traffic'!");
								float weightmod = strtof(a->getFirstText().c_str(), &res);
								if (weightmod<=0 || res==a->getFirstText().c_str())
									THROWEXCEPTION("IDSLoadBalancerCfg: attribute 'weightModifier' is not in expected range (0<x): %s", a->getFirstText().c_str());
								weightmods.push_back(WeightModifierConfig(quantile, weightmod));
							}
						}
					}
				}

				if (!selector) {
					struct timeval tv;
					tv.tv_sec = minmontime/1000;
					tv.tv_usec = (minmontime%1000)*1000;

					// sort the network configuration by decreasing maskbits
					config.sort(compareDecrMask);
					selector = new PriorityPacketSelector(config, startprio, tv, maxspeed, weightmods);
				} else
					THROWEXCEPTION("IDSLoadBalancerCfg: multiple packet selectors specified! This is not allowed.");
			} else {
				THROWEXCEPTION("Invalid selector: %s", _selector.c_str());
			}
		}
	}
	if (!selector)
		THROWEXCEPTION("IDSLoadBalancerCfg: No packet selector specified, this is compulsory");
}