Example #1
0
	filter(bool block, uint except_value_type)
	{
		if (block) {
			ICMP6_FILTER_SETBLOCKALL(&_filter);
			ICMP6_FILTER_SETPASS(except_value_type, &_filter);
		} else {
			ICMP6_FILTER_SETPASSALL(&_filter);
			ICMP6_FILTER_SETBLOCK(except_value_type, &_filter);
		}
	}
Example #2
0
	void block(uint type_value)
	{
		ICMP6_FILTER_SETBLOCK(type_value, &_filter);
	}
Example #3
0
/* functional tests */
void icmp6_ft(void)
{
	struct icmp6_filter i6f;
	int sall, sf;
	int i;

	sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
	if (sall < 0) {
		tst_resm(TBROK | TERRNO,
			 "icmp6_ft socket: can't create sall socket");
		return;
	}
	ICMP6_FILTER_SETPASSALL(&i6f);
	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
		       sizeof(i6f)) < 0) {
		tst_resm(TBROK | TERRNO,
			 "setsockopt pass all ICMP6_FILTER failed");
	}

	sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
	if (sf < 0) {
		tst_resm(TBROK | TERRNO,
			 "icmp6_ft socket: can't create test socket");
		return;
	}

	int rv;

	for (i = 0; i < FTCOUNT; ++i) {

		rv = -1;

		switch (ftab[i].ft_test) {
		case T_SETPASS:
			ICMP6_FILTER_SETBLOCKALL(&i6f);
			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
			break;
		case T_SETPASSALL:
			ICMP6_FILTER_SETPASSALL(&i6f);
			break;
		case T_SETBLOCK:
			ICMP6_FILTER_SETPASSALL(&i6f);
			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
			break;
		case T_SETBLOCKALL:
			ICMP6_FILTER_SETBLOCKALL(&i6f);
			break;
		case T_WILLBLOCK:
			ICMP6_FILTER_SETPASSALL(&i6f);
			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
			rv = ICMP6_FILTER_WILLBLOCK(ftab[i].ft_sndtype, &i6f);
			break;
		case T_WILLPASS:
			ICMP6_FILTER_SETBLOCKALL(&i6f);
			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
			break;
		default:
			tst_resm(TBROK, "%s: unknown test type %d",
				 ftab[i].ft_tname, ftab[i].ft_test);
			continue;
		}
		if (ftab[i].ft_test != T_WILLBLOCK &&
		    ftab[i].ft_test != T_WILLPASS) {
			if (setsockopt(sf, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
				       sizeof(i6f)) < 0) {
				tst_resm(TFAIL | TERRNO,
					 "setsockopt ICMP6_FILTER");
				continue;
			}
			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
				continue;
			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
		} else
			rv = -1;

		if (rv < 0)
			continue;
		if (rv != ftab[i].ft_expected)
			tst_resm(TFAIL, "%s: rv %d != expected %d",
				 ftab[i].ft_tname, rv, ftab[i].ft_expected);
		else
			tst_resm(TPASS, ftab[i].ft_tname);
	}
}