示例#1
0
void mld_router::shutdown() {
	const mrd::interface_list &intflist = g_mrd->intflist();

	for (mrd::interface_list::const_iterator i = intflist.begin();
						i != intflist.end(); ++i) {
		mld_interface *mldintf =
			(mld_interface *)i->second->node_owned_by(this);
		if (mldintf) {
			mldintf->shutdown();
			delete mldintf;
		}
	}

	g_mrd->icmp().register_handler(MLD_LISTENER_REPORT, 0);
	g_mrd->icmp().register_handler(MLD_LISTENER_REDUCTION, 0);
	g_mrd->icmp().register_handler(MLD_LISTENER_QUERY, 0);
	g_mrd->icmp().register_handler(MLDv2_LISTENER_REPORT, 0);
	g_mrd->icmp().register_handler(MLDv2_LISTENER_REPORT_OLD, 0);

	in6_addr all_routers;
	in6_addr mld_all_routers;

	all_routers = inet6_addr("ff02::2").address();
	mld_all_routers = inet6_addr("ff02::16").address();

	g_mrd->icmp().require_mgroup(all_routers, false);
	g_mrd->icmp().require_mgroup(mld_all_routers, false);

	router::shutdown();
}
示例#2
0
bool mld_router::check_startup() {
	if (!m_stats.setup("MLD Statistics"))
		return false;

	m_stats.disable_counter(ReportCount, TX);
	m_stats.disable_counter(ReductionCount, TX);
	m_stats.disable_counter(ReportV2Count, TX);

	if (!router::check_startup())
		return false;

	import_methods(mld_router_methods);

	g_mrd->icmp().register_handler(MLD_LISTENER_REPORT, this);
	g_mrd->icmp().register_handler(MLD_LISTENER_REDUCTION, this);
	g_mrd->icmp().register_handler(MLD_LISTENER_QUERY, this);
	g_mrd->icmp().register_handler(MLDv2_LISTENER_REPORT, this);
	g_mrd->icmp().register_handler(MLDv2_LISTENER_REPORT_OLD, this);

	in6_addr all_routers;
	in6_addr mld_all_routers;

	all_routers = inet6_addr("ff02::2").address();
	mld_all_routers = inet6_addr("ff02::16").address();

	g_mrd->icmp().require_mgroup(all_routers, true);
	g_mrd->icmp().require_mgroup(mld_all_routers, true);

	return true;
}
示例#3
0
/* inet_pton substitute implementation
 * Uses inet_addr to convert an IP address in dotted decimal notation into 
 * unsigned long and copies the result to dst.
 * Only supports AF_INET.  Follows standard error return conventions of 
 * inet_pton.
 */
int
inet_pton (int af, const char *src, void *dst)
{
    u_long result;  

    if (af == AF_INET) {
	result = inet_addr(src);
	if (result == -1)
	    return 0;
	else {
			memcpy (dst, &result, 4);
	    return 1;
		}
	}
#ifdef NT
#ifdef HAVE_IPV6
	else if (af == AF_INET6) {
		struct in6_addr Address;
		return (inet6_addr(src, &Address));
	}
#endif /* HAVE_IPV6 */
#endif /* NT */
#ifndef NT
    else {

	errno = EAFNOSUPPORT;
	return -1;
    }
#endif /* NT */
}
示例#4
0
bool pim_groupconf_node::fill_defaults() {
	instantiate_property_a("rp", inet6_addr::any());
	instantiate_property_a("accept_rp", inet6_addr(in6addr_any, 0));
	instantiate_property_b("rp_adv", false);

	instantiate_property("rp-rejected-source-policy", new propval_enum(rp_rej_entries));

	instantiate_property_b("rp-embedded-auto-source-acl", false);

#if 0
	m_properties["use_spt"] = always_use;

	m_properties["rp_acl"] = rpa_any;
	m_properties["rp_acls"] = std::vector<inet6_addr>();

	std::vector<std::string> rp_pref;

	rp_pref.push_back("embedded");
	rp_pref.push_back("rp_set");
	rp_pref.push_back("static");

	m_properties["rp_pref"] = rp_pref;
#endif

	return m_properties.size() == 4;
}
示例#5
0
void pim_interface::elect_subnet_dr() {
	bool mayuseprio = true;

	for (neighbours_def::const_iterator i = neighbours.begin(); mayuseprio && i != neighbours.end(); ++i)
		mayuseprio = (*i)->has_dr_priority();

	pim_neighbour *bestneigh = 0;

	// elect DR between known neighbours
	if (!neighbours.empty()) {
		bestneigh = *neighbours.begin();

		neighbours_def::const_iterator i = neighbours.begin();
		i++;

		for (; i != neighbours.end(); i++) {
			if (!mayuseprio || (bestneigh->dr_priority() == (*i)->dr_priority())) {
				if (bestneigh->localaddr() < (*i)->localaddr()) {
					bestneigh = *i;
				}
			} else if (bestneigh->dr_priority() < (*i)->dr_priority()) {
				bestneigh = *i;
			}
		}
	}

	// match the elected neighbour against us
	if (bestneigh) {
		uint32_t my_dr_prio = conf()->dr_priority();

		if (!mayuseprio || (my_dr_prio == bestneigh->dr_priority())) {
			if (bestneigh->localaddr() < inet6_addr(*owner()->linklocal()))
				bestneigh = 0;
		} else {
			if (my_dr_prio > bestneigh->dr_priority())
				bestneigh = 0;
		}
	}

	/* We must set elected_dr before calling dr_changed */
	pim_neighbour *old = elected_dr;

	elected_dr = bestneigh;

	if (old != bestneigh) {
		if (bestneigh && !old) {
			if (should_log(NORMAL))
				log().xprintf("No longer the DR, new DR is %{Addr}\n", bestneigh->localaddr());
			pim->dr_changed(this, false);
		} else if (old && !bestneigh) {
			if (should_log(NORMAL))
				log().writeline("Im now the DR");
			pim->dr_changed(this, true);
		} else if (bestneigh) {
			if (should_log(NORMAL))
				log().xprintf("New DR is %{Addr}\n", bestneigh->localaddr());
		}
	}
}
示例#6
0
文件: ripng.cpp 项目: Distrotech/mrd6
ripng_router::ripng_router()
	: router("ripng"),
	  m_sock("ripng sock", this, std::mem_fun(&ripng_router::data_available)),
	  m_garbcol_timer("ripng garbage collector", this,
		std::mem_fun(&ripng_router::garbage_collect), 30000, true) {

	m_ripnggrp = inet6_addr("ff02::9").as_sockaddr();
	m_ripnggrp.sin6_port = htons(522);
}
示例#7
0
void mld_interface::handle_other_querier_present_timeout() {
	change_is_querier(conf()->querier());

	if (!mif_isquerier)
		mif_querier_addr = inet6_addr();

	if (should_log(NORMAL)) {
		base_stream &os = log().write("The other querier timed out");
		if (mif_isquerier)
			os.write(", switching to Querier mode.");
		os.newl();
	}
}
示例#8
0
pim_router::pim_router()
	: router("pim"), pim_sock("pim", this,
		std::mem_fun(&pim_router::data_available)),
	  m_gc("pim garbage collector", this,
		std::mem_fun(&pim_router::handle_garbage_collector), 5000, true)
#ifndef PIM_NO_BSR
	  , m_bsr(this)
#endif
	{

	pim_all_routers = inet6_addr("ff02::d").address();

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

	pim_all_routers_addr.sin6_family = AF_INET6;
	pim_all_routers_addr.sin6_addr = pim_all_routers;
}
示例#9
0
void linux_unicast_router::parse_prefix_rec(rtattr *tb[], int plen, int protocol,
        lookup_result &reply) const {
    reply.dst = inet6_addr(in6addr_any, plen);
    reply.dev = -1;
    reply.protocol = protocol;
    reply.metric = 0xffffffff;
    reply.nexthop = in6addr_any;
    reply.source = in6addr_any;

    if (tb[RTA_DST])
        reply.dst.addr = *(in6_addr *)RTA_DATA(tb[RTA_DST]);
    if (tb[RTA_OIF])
        reply.dev = *(int *)RTA_DATA(tb[RTA_OIF]);
    if (tb[RTA_GATEWAY])
        memcpy(&reply.nexthop, RTA_DATA(tb[RTA_GATEWAY]), sizeof(in6_addr));
    if (tb[RTA_PREFSRC])
        memcpy(&reply.source, RTA_DATA(tb[RTA_PREFSRC]), sizeof(in6_addr));
    if (tb[RTA_PRIORITY])
        reply.metric = *(uint32_t *)RTA_DATA(tb[RTA_PRIORITY]);
}
示例#10
0
bool console_module::deny_addr(const std::vector<std::string> &args) {
	if (args.empty())
		return false;

	std::string username = args[0];

	inet6_addr mask = inet6_addr(in6addr_any, 0);

	if (args.size() > 1) {
		if (!mask.set(args[1])) {
			return false;
		}
	}

	console_module::allow_local_def::iterator i = acl.begin();

	while (i != acl.end()) {
		allow_local_def::iterator m = i;
		++i;

		if (mask.matches(m->first)) {
			std::list<auth_desc>::iterator j = m->second.begin();

			while (j != m->second.end()) {
				std::list<auth_desc>::iterator k = j;
				++j;

				if (username.empty() || username == "*"
					|| username == j->username) {
					m->second.erase(k);
				}
			}

			if (m->second.empty()) {
				acl.erase(m);
			}
		}
	}

	return true;
}
示例#11
0
bool console_module::allow_addr(const std::vector<std::string> &args) {
	inet6_addr mask = inet6_addr(in6addr_any, 0);

	auth_desc desc;

	if (!args.empty()) {
		desc.username = args[0];
		if (args.size() > 1) {
			desc.password = args[1];
			if (args.size() > 2) {
				if (!mask.set(args[2]))
					return false;
			}
		}
	} else {
		return false;
	}

	acl[mask].push_back(desc);

	return true;
}
示例#12
0
void mld_group_interface::update_sources_timer(const address_set &sources,
						uint32_t interval) {
	if (interval == 0)
		interval = mali();

	for (address_set::const_iterator i = sources.begin(); i != sources.end(); ++i) {
		std::vector<source_timer>::iterator k = g_sources_timers.begin();

		for (; k != g_sources_timers.end() && !(k->argument() == *i); ++k);

		if (k == g_sources_timers.end()) {
			std::string tmp;
			tmp = "mld source timer (";
			tmp += inet6_addr(*i).as_string();
			tmp += ")";

			k = g_sources_timers.insert(g_sources_timers.end(),
					source_timer(tmp, this,
					std::mem_fun(&mld_group_interface::handle_source_timeout), *i));
		}

		k->start_or_update(interval, false);
	}
}
示例#13
0
文件: ripng.c 项目: OPSF/uClinux
bool do_opt(char *opt, char *arg, sendip_data *pack) {
	ripng_header *rippack = (ripng_header *)pack->data;
	ripng_entry *ripopt;
	char *p, *q;
	switch(opt[1]) {
	case 'v': /* version */
		rippack->version = (u_int8_t)strtoul(arg, (char **)0, 0);
		pack->modified |= RIPNG_MOD_VERSION;
		break;
	case 'c': /* command */
		rippack->command = (u_int8_t)strtoul(arg, (char **)0, 0);
		pack->modified |= RIPNG_MOD_COMMAND;
		break;
	case 'r': /* reserved */
		rippack->res = htons((u_int16_t)strtoul(arg, (char **)0, 0));
		pack->modified |= RIPNG_MOD_RESERVED;
		break;
		/*
	case 'a': / * authenticate * /
		if(RIPNG_NUM_ENTRIES(pack) != 0) {
			usage_error("Warning: a real RIP-2 packet only has authentication on the first entry.\n");
		}
		pack->modified |= RIP_IS_AUTH;
		pack->data = realloc(pack->data,pack->alloc_len+strlen(arg));
		strcpy(pack->data+pack->alloc_len,arg);
		pack->alloc_len += strlen(arg);
		break;
		*/
	case 'e': /* rip entry */
		RIPNG_ADD_ENTRY(pack);
		ripopt = RIPNG_ENTRY(pack);
		p=q=arg;
		/* TODO: if arg is malformed, this could segfault */
		while(*(q++)!='/') /* do nothing */; *(--q)='\0';
		ripopt->prefix = (p==q)?in6addr_any:inet6_addr(p);

		p=++q; while(*(q++)!='/') /* do nothing */; *(--q)='\0';
		ripopt->tag=htons( (p==q)?0:(u_int16_t)strtoul(p, (char **)0,0));

		p=++q; while(*(q++)!='/') /* do nothing */; *(--q)='\0';
		ripopt->len=(p==q)?(u_int8_t)128:(u_int8_t)strtoul(p, (char **)0,0);

		p=++q; while(*(q++)!='\0') /* do nothing */; *(--q)='\0';
		ripopt->metric=(p==q)?(u_int8_t)16:(u_int8_t)strtoul(p,(char **)0, 0);
		break;
	case 'd': /* default request */
		if(RIPNG_NUM_ENTRIES(pack) != 0) {
			usage_error("Warning: a real RIPng packet does not have any other entries in a default request.\n");
		}
		rippack->command = (u_int8_t)1;
		rippack->version = (u_int8_t)1;
		rippack->res = (u_int16_t)0;
		pack->modified|=RIPNG_MOD_COMMAND|RIPNG_MOD_VERSION|RIPNG_MOD_RESERVED;
		RIPNG_ADD_ENTRY(pack);
		ripopt=RIPNG_ENTRY(pack);
		ripopt->prefix=in6addr_any;
		ripopt->tag=(u_int16_t)0;
		ripopt->len=(u_int8_t)0;
		ripopt->metric=htons((u_int16_t)16);
		break;
	}
	return TRUE;

}
示例#14
0
/* ascii2prefix
 */
prefix_t *
ascii2prefix (int family, char *string)
{
    u_long bitlen, maxbitlen = 0;
    char *cp;
    struct in_addr sin;
#ifdef HAVE_IPV6
    struct in6_addr sin6;
#endif /* HAVE_IPV6 */
    int result;
    char save[MAXLINE];

    if (string == NULL)
		return (NULL);

    /* easy way to handle both families */
    if (family == 0) {
       family = AF_INET;
#ifdef HAVE_IPV6
       if (strchr (string, ':')) family = AF_INET6;
#endif /* HAVE_IPV6 */
    }

    if (family == AF_INET) {
		maxbitlen = 32;
    }
#ifdef HAVE_IPV6
    else if (family == AF_INET6) {
		maxbitlen = 128;
    }
#endif /* HAVE_IPV6 */

    if ((cp = strchr (string, '/')) != NULL) {
		bitlen = atol (cp + 1);
		/* *cp = '\0'; */
		/* copy the string to save. Avoid destroying the string */
		assert (cp - string < MAXLINE);
		memcpy (save, string, cp - string);
		save[cp - string] = '\0';
		string = save;
		if (bitlen < 0 || bitlen > maxbitlen)
			bitlen = maxbitlen;
		}
		else {
			bitlen = maxbitlen;
		}

		if (family == AF_INET) {
			if ((result = my_inet_pton (AF_INET, string, &sin)) <= 0)
				return (NULL);
			return (New_Prefix (AF_INET, &sin, bitlen));
		}

#ifdef HAVE_IPV6
		else if (family == AF_INET6) {
// Get rid of this with next IPv6 upgrade
#if defined(NT) && !defined(HAVE_INET_NTOP)
			inet6_addr(string, &sin6);
			return (New_Prefix (AF_INET6, &sin6, bitlen));
#else
			if ((result = inet_pton (AF_INET6, string, &sin6)) <= 0)
				return (NULL);
#endif /* NT */
			return (New_Prefix (AF_INET6, &sin6, bitlen));
		}
#endif /* HAVE_IPV6 */
		else
			return (NULL);
}
示例#15
0
mld_router::mld_router()
	: router("mld"),
	  m_stats(this, MessageCount, stats_descriptions) {

	in6addr_linkscope_allnodes = inet6_addr("ff02::1").address();
}
示例#16
0
文件: node.cpp 项目: NeoRaider/mrd6
	propval_address(const inet6_addr *a)
		: value(a ? *a : inet6_addr()) {}