示例#1
0
int __build_expect(struct nfnl_subsys_handle *ssh,
		   struct nfnlhdr *req,
		   size_t size,
		   u_int16_t type,
		   u_int16_t flags,
		   const struct nf_expect *exp)
{
	u_int8_t l3num;

	if (test_bit(ATTR_ORIG_L3PROTO, exp->master.set))
		l3num = exp->master.orig.l3protonum;
	else if (test_bit(ATTR_ORIG_L3PROTO, exp->expected.set))
		l3num = exp->expected.orig.l3protonum;
	else
		return -1;

	memset(req, 0, size);

	nfnl_fill_hdr(ssh, &req->nlh, 0, l3num, 0, type, flags);

	if (test_bit(ATTR_EXP_EXPECTED, exp->set)) {
		__build_tuple(req, size, &exp->expected.orig, CTA_EXPECT_TUPLE);
	}

	if (test_bit(ATTR_EXP_MASTER, exp->set)) {
		__build_tuple(req, size, &exp->master.orig, CTA_EXPECT_MASTER);
	}

	if (test_bit(ATTR_EXP_MASK, exp->set)) {
		__build_tuple(req, size, &exp->mask.orig, CTA_EXPECT_MASK);
	}

	if (test_bit(ATTR_EXP_TIMEOUT, exp->set))
		__build_timeout(req, size, exp);
	if (test_bit(ATTR_EXP_FLAGS, exp->set))
		__build_flags(req, size, exp);
	if (test_bit(ATTR_EXP_ZONE, exp->set))
		__build_zone(req, size, exp);
	if (test_bit(ATTR_EXP_HELPER_NAME, exp->set))
		__build_helper_name(req, size, exp);

	return 0;
}
示例#2
0
int __build_conntrack(struct nfnl_subsys_handle *ssh,
		      struct nfnlhdr *req,
		      size_t size,
		      u_int16_t type,
		      u_int16_t flags,
		      const struct nf_conntrack *ct)
{
	u_int8_t l3num = ct->tuple[__DIR_ORIG].l3protonum;

	if (!test_bit(ATTR_ORIG_L3PROTO, ct->set)) {
		errno = EINVAL;
		return -1;
	}

	memset(req, 0, size);

	nfnl_fill_hdr(ssh, &req->nlh, 0, l3num, 0, type, flags);

	if (test_bit(ATTR_ORIG_IPV4_SRC, ct->set) ||
	    test_bit(ATTR_ORIG_IPV4_DST, ct->set) ||
	    test_bit(ATTR_ORIG_IPV6_SRC, ct->set) ||
	    test_bit(ATTR_ORIG_IPV6_DST, ct->set) ||
	    test_bit(ATTR_ORIG_PORT_SRC, ct->set) ||
	    test_bit(ATTR_ORIG_PORT_DST, ct->set) ||
	    test_bit(ATTR_ORIG_L3PROTO, ct->set)  ||
	    test_bit(ATTR_ORIG_L4PROTO, ct->set)  ||
	    test_bit(ATTR_ICMP_TYPE, ct->set) 	  ||
	    test_bit(ATTR_ICMP_CODE, ct->set)	  ||
	    test_bit(ATTR_ICMP_ID, ct->set))
		{
		__build_tuple(req, size,
			      &ct->tuple[__DIR_ORIG], 
			      CTA_TUPLE_ORIG);
		}

	if (test_bit(ATTR_REPL_IPV4_SRC, ct->set) ||
	    test_bit(ATTR_REPL_IPV4_DST, ct->set) ||
	    test_bit(ATTR_REPL_IPV6_SRC, ct->set) ||
	    test_bit(ATTR_REPL_IPV6_DST, ct->set) ||
	    test_bit(ATTR_REPL_PORT_SRC, ct->set) ||
	    test_bit(ATTR_REPL_PORT_DST, ct->set) ||
	    test_bit(ATTR_REPL_L3PROTO, ct->set)  ||
	    test_bit(ATTR_REPL_L4PROTO, ct->set)  ||
	    test_bit(ATTR_ICMP_TYPE, ct->set) 	  ||
	    test_bit(ATTR_ICMP_CODE, ct->set)	  ||
	    test_bit(ATTR_ICMP_ID, ct->set))
		{
		__build_tuple(req, size, 
			      &ct->tuple[__DIR_REPL],
			      CTA_TUPLE_REPLY);
		}

	if (test_bit(ATTR_MASTER_IPV4_SRC, ct->set) ||
	    test_bit(ATTR_MASTER_IPV4_DST, ct->set) ||
	    test_bit(ATTR_MASTER_IPV6_SRC, ct->set) ||
	    test_bit(ATTR_MASTER_IPV6_DST, ct->set) ||
	    test_bit(ATTR_MASTER_PORT_SRC, ct->set) ||
	    test_bit(ATTR_MASTER_PORT_DST, ct->set) ||
	    test_bit(ATTR_MASTER_L3PROTO, ct->set) ||
	    test_bit(ATTR_MASTER_L4PROTO, ct->set))
		{
	    	__build_tuple(req, size, 
			      &ct->tuple[__DIR_MASTER], CTA_TUPLE_MASTER);
		}

	if (test_bit(ATTR_STATUS, ct->set))
		{
		__build_status(req, size, ct);
		}
	else {
		/* build IPS_CONFIRMED if we're creating a new conntrack */
		if (type == IPCTNL_MSG_CT_NEW && flags & NLM_F_CREATE)
			__build_status(req, size, ct);
	}

	if (test_bit(ATTR_TIMEOUT, ct->set))
		{
		__build_timeout(req, size, ct);
		}

	if (test_bit(ATTR_MARK, ct->set))
		{
		__build_mark(req, size, ct);
		}

	if (test_bit(ATTR_SECMARK, ct->set))
		{
		__build_secmark(req, size, ct);
		}

	__build_protoinfo(req, size, ct);

	if (test_bit(ATTR_SNAT_IPV4, ct->set) && 
	    test_bit(ATTR_SNAT_PORT, ct->set))
		{
		__build_snat(req, size, ct);
		}
	else if (test_bit(ATTR_SNAT_IPV4, ct->set))
		{
		__build_snat_ipv4(req, size, ct);
		}
	else if (test_bit(ATTR_SNAT_PORT, ct->set))
		{
		__build_snat_port(req, size, ct);
		}

	if (test_bit(ATTR_DNAT_IPV4, ct->set) &&
	    test_bit(ATTR_DNAT_PORT, ct->set))
		{
		__build_dnat(req, size, ct);
		}
	else if (test_bit(ATTR_DNAT_IPV4, ct->set))
		{
		__build_dnat_ipv4(req, size, ct);
		}
	else if (test_bit(ATTR_DNAT_PORT, ct->set))
		{
		__build_dnat_port(req, size, ct);
		}

	if (test_bit(ATTR_ORIG_NAT_SEQ_CORRECTION_POS, ct->set) &&
	    test_bit(ATTR_ORIG_NAT_SEQ_OFFSET_BEFORE, ct->set) &&
	    test_bit(ATTR_ORIG_NAT_SEQ_OFFSET_AFTER, ct->set))
		{
	    	__build_nat_seq_adj(req, size, ct, __DIR_ORIG);
		}

	if (test_bit(ATTR_REPL_NAT_SEQ_CORRECTION_POS, ct->set) &&
	    test_bit(ATTR_REPL_NAT_SEQ_OFFSET_BEFORE, ct->set) &&
	    test_bit(ATTR_REPL_NAT_SEQ_OFFSET_AFTER, ct->set))
		{
	    	__build_nat_seq_adj(req, size, ct, __DIR_REPL);
		}

	if (test_bit(ATTR_HELPER_NAME, ct->set))
		{
		__build_helper_name(req, size, ct);
		}

	return 0;
}