示例#1
0
struct ipt_entry_target *
get_dnat_target(const char *input, unsigned int *nfcache) {
	struct ipt_entry_target *target;
	struct ipt_natinfo *info;
	struct ip_nat_range range;

	char *buffer;
	size_t size;

	/* Can't cache this */
	*nfcache |= NFC_UNKNOWN;

	buffer = strdup(input);
	size = IPT_ALIGN(sizeof(*target)) + IPT_ALIGN(sizeof(struct ip_nat_multi_range));
	target = calloc(1, size);
	target->u.target_size = size;
	strncpy(target->u.user.name, "DNAT", IPT_FUNCTION_MAXNAMELEN);

	info = (void *)target;
	parse_range(buffer, &range);
	target = &(append_range(info, &range)->t);
	free(buffer);

	return target;
}
示例#2
0
void solution::move_vertices( const std::list< std::pair<size_t,size_t> > & move_list )
{
    std::list<std::pair<page_iterator_t,edge_t> > all_touching_edges;

    for( auto i= move_list.begin(); i!= move_list.end(); ++i )
    {
        size_t index1= i->first;
        size_t to_pos= i->second;

        if( index1 >= spine_order.size() ||
            to_pos > spine_order.size() )
        {
            throw std::out_of_range("move vertices outside of index range");
        }


        std::list<std::pair<page_iterator_t,edge_t> > touching_edges;

        // collect touching edges
        for( auto p= pages.begin(); p != pages.end(); ++p )
            for( auto e= p->edges.begin(); e != p->edges.end(); ++e )
                if( e->first == spine_order[index1] || 
                    e->second == spine_order[index1]  )
                {
                    touching_edges.push_back( make_pair(p,*e) );
                    all_touching_edges.push_back( make_pair(p,*e) );
                }

        // remove touching edges
        for( auto i= touching_edges.begin(); i != touching_edges.end(); ++i )
            remove_edge( * i->first, i->second );

        // 
        // moving spine order

        if( to_pos < spine_order.size() )
            move_range( index1, 1, to_pos, spine_order );
        else
            append_range( index1, 1, spine_order );

    }

    // new order map
    int order_count= 0;
    for( auto v=spine_order.begin(); v!= spine_order.end(); ++v  )
    {
        spine_order_map[ *v ]= order_count++;
    }


    // re -add edges
    for( auto i= all_touching_edges.begin(); i != all_touching_edges.end(); ++i )
        add_edge( * i->first, i->second );
    
}
示例#3
0
static struct ipt_natinfo *parse_to(char *arg,struct ipt_natinfo *info)
{
    struct nat_nf_nat_range range;
    char *dash;
    struct in_addr *ip = (struct in_addr*)malloc(sizeof(struct in_addr));
    char *addr,*addr1;

    memset(&range, 0, sizeof(range));

    range.flags |= IP_NAT_RANGE_MAP_IPS;// | IP_NAT_RANGE_PROTO_SPECIFIED;
    dash = strchr(arg, '-');
    if (dash) {
        addr = strdup(strtok(arg,"-"));
        addr1 = strdup(strtok(NULL,"\0"));
    } else
        addr = strdup(arg);

    ip->s_addr =inet_addr(addr);
    if (!ip)
        printf("Wrong source address\n");
    range.min_ip = ip->s_addr;
    if (dash) {
        ip->s_addr = inet_addr(addr1);
        if (!ip)
            printf("Wrong source address\n");
        range.max_ip = ip->s_addr;
    } else
        range.max_ip = range.min_ip;

    free(addr);
    if (dash)
        free(addr1);

    range.min = htons(0);
    range.max = htons(65535);

    return append_range(info, &range);
}
示例#4
0
/* Ranges expected in network order. */
static struct xt_entry_target *
parse_to(char *arg, int portok, struct ipt_natinfo *info)
{
	struct nf_nat_range range;
	char *colon, *dash, *error;
	const struct in_addr *ip;

	memset(&range, 0, sizeof(range));
	colon = strchr(arg, ':');

	if (colon) {
		int port;

		if (!portok)
			xtables_error(PARAMETER_PROBLEM,
				   "Need TCP, UDP, SCTP or DCCP with port specification");

		range.flags |= IP_NAT_RANGE_PROTO_SPECIFIED;

		port = atoi(colon+1);
		if (port <= 0 || port > 65535)
			xtables_error(PARAMETER_PROBLEM,
				   "Port `%s' not valid\n", colon+1);

		error = strchr(colon+1, ':');
		if (error)
			xtables_error(PARAMETER_PROBLEM,
				   "Invalid port:port syntax - use dash\n");

		dash = strchr(colon, '-');
		if (!dash) {
			range.min.tcp.port
				= range.max.tcp.port
				= htons(port);
		} else {
			int maxport;

			maxport = atoi(dash + 1);
			if (maxport <= 0 || maxport > 65535)
				xtables_error(PARAMETER_PROBLEM,
					   "Port `%s' not valid\n", dash+1);
			if (maxport < port)
				/* People are stupid. */
				xtables_error(PARAMETER_PROBLEM,
					   "Port range `%s' funky\n", colon+1);
			range.min.tcp.port = htons(port);
			range.max.tcp.port = htons(maxport);
		}
		/* Starts with a colon? No IP info...*/
		if (colon == arg)
			return &(append_range(info, &range)->t);
		*colon = '\0';
	}

	range.flags |= IP_NAT_RANGE_MAP_IPS;
	dash = strchr(arg, '-');
	if (colon && dash && dash > colon)
		dash = NULL;

	if (dash)
		*dash = '\0';

	ip = xtables_numeric_to_ipaddr(arg);
	if (!ip)
		xtables_error(PARAMETER_PROBLEM, "Bad IP address \"%s\"\n",
			   arg);
	range.min_ip = ip->s_addr;
	if (dash) {
		ip = xtables_numeric_to_ipaddr(dash+1);
		if (!ip)
			xtables_error(PARAMETER_PROBLEM, "Bad IP address \"%s\"\n",
				   dash+1);
		range.max_ip = ip->s_addr;
	} else
		range.max_ip = range.min_ip;

	return &(append_range(info, &range)->t);
}