示例#1
0
文件: conf.c 项目: Oryon/pimbd
static int conf_rpa_mod(conf conf, char *data, size_t len, __unused struct blob_buf *reply, bool del)
{
	struct blob_attr *tb[CONF_RPA_MAX];
	struct in6_addr rpa;
	struct in6_addr gr;
	uint8_t plen;

	if(blobmsg_parse(conf_rpa_attrs, CONF_RPA_MAX, tb, data, len) ||
			!tb[CONF_RPA_RPA] || !addr_pton(&rpa, blobmsg_get_string(tb[CONF_RPA_RPA])) ||
			!tb[CONF_RPA_GROUPS] || !prefix_pton(&gr, &plen, blobmsg_get_string(tb[CONF_RPA_GROUPS])) ||
			!addr_is_multicast(&gr) || tb[CONF_RPA_RPL_JP])
		return -EINVAL;

	if(del)
		pim_rpa_del(conf->pim, &rpa, &gr, plen);
	else
		pim_rpa_add(conf->pim, &rpa, &gr, plen);
	return 0;
}
示例#2
0
void prefix_pton_t(void)
{
	struct prefix p;
	struct prefix p4_1 = {
			.prefix = { .s6_addr = {
					0x00,0x00, 0x00,0x00,  0x00,0x00, 0x00,0x00,
					0x00,0x00, 0xff,0xff,  0x0a }},
					.plen = 104 };

	struct prefix p4_2 = {
			.prefix = { .s6_addr = {
					0x00,0x00, 0x00,0x00,  0x00,0x00, 0x00,0x00,
					0x00,0x00, 0xff,0xff,  0xc0,0xa8, 0x00,0x01 }},
					.plen = 128 };

	sput_fail_unless(prefix_pton(p_allones_67_s, &p) == 1, "Parse 1");
	sput_fail_unless(!prefix_cmp(&p, &p_allones_67), "Parse value 1");

	sput_fail_unless(prefix_pton(p1_s, &p) == 1, "Parse 2");
	sput_fail_unless(!prefix_cmp(&p, &p1), "Parse value 2");

	sput_fail_unless(prefix_pton(px_s, &p) == 1, "Parse 3");
	sput_fail_unless(!prefix_cmp(&p, &px), "Parse value 3");

	sput_fail_unless(prefix_pton("10::/rrx", &p) == 0, "Parse error 1");
	sput_fail_unless(prefix_pton("10::/129", &p) == 0, "Parse error 2");
	sput_fail_unless(prefix_pton("10::/-1", &p) == 0, "Parse error 3");
	sput_fail_unless(prefix_pton("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255./10", &px) == 0, "Parse error 4");
	sput_fail_unless(prefix_pton("10.0.0.0/64", &px) == 0, "Parse error 5");
	sput_fail_unless(prefix_pton("blah-chombier/64", &px) == 0, "Parse error 6");

	/* Parsing IPv4 */
	sput_fail_unless(prefix_pton("10.0.0.0/8", &p) == 1, "Parse v4 1");
	sput_fail_unless(!prefix_cmp(&p, &p4_1), "Parse v4 value 1");

	sput_fail_unless(prefix_pton("192.168.0.1/32", &p) == 1, "Parse v4 2");
	sput_fail_unless(!prefix_cmp(&p, &p4_2), "Parse v4 value 2");

	/* Parsing without slash */
	sput_fail_unless(prefix_pton("192.168.0.1", &p) == 1, "Parse v4 without /");
	sput_fail_unless(!prefix_cmp(&p, &p4_2), "Parse v4 without /");

	sput_fail_unless(prefix_pton("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &p) == 1, "Parse v6 without /");
	sput_fail_unless(!prefix_cmp(&p, &p_allones_128), "Parse v6 without /");
}