FreeBSD/sys/netpfil/ipfw/ip_fw_sockopt.c
/*
 * Copies rule @krule from kernel to FreeBSD8 userland format (v0)
 */
Copies rule @krule from kernel to FreeBSD8 userland format (v0)
Copies rule @krule from kernel to FreeBSD8 userland format ( v0 )
static void
export_rule0(struct ip_fw *krule, struct ip_fw_rule0 *urule, int len)
{
	int cmdlen, l;
	ipfw_insn *cmd;
	ipfw_insn_limit *lcmd;
	ipfw_insn_if *cmdif;
	memset(urule, 0, len);
	urule->act_ofs = krule->act_ofs;
	urule->cmd_len = krule->cmd_len;
	urule->rulenum = krule->rulenum;
	urule->set = krule->set;
	if ((krule->flags & IPFW_RULE_NOOPT) != 0)
		urule->_pad |= 1;
	memcpy(urule->cmd, krule->cmd, krule->cmd_len * sizeof(uint32_t));
	export_cntr0_base(krule, (struct ip_fw_bcounter0 *)&urule->pcnt);
	l = urule->cmd_len;
	cmd = urule->cmd;
	cmdlen = 0;
	for ( ;	l > 0 ; l -= cmdlen, cmd += cmdlen) {
		cmdlen = F_LEN(cmd);
		switch (cmd->opcode) {
		case O_TAG:
		case O_TAGGED:
		case O_PIPE:
		case O_QUEUE:
		case O_DIVERT:
		case O_TEE:
		case O_SKIPTO:
		case O_CALLRETURN:
		case O_NETGRAPH:
		case O_NGTEE:
		case O_NAT:
			if (cmd->arg1 == IP_FW_TARG)
				cmd->arg1 = IP_FW_TABLEARG;
			else if (cmd->arg1 == IP_FW_NAT44_GLOBAL)
				cmd->arg1 = 0;
			break;
		case O_SETFIB:
		case O_SETDSCP:
			if (cmd->arg1 == IP_FW_TARG)
				cmd->arg1 = IP_FW_TABLEARG;
			else
				cmd->arg1 &= ~0x8000;
			break;
		case O_LIMIT:
			lcmd = (ipfw_insn_limit *)cmd;
			if (lcmd->conn_limit == IP_FW_TARG)
				lcmd->conn_limit = IP_FW_TABLEARG;
			break;
		case O_XMIT:
		case O_RECV:
		case O_VIA:
			cmdif = (ipfw_insn_if *)cmd;
			if (cmdif->name[0] != '\1')
				break;
			cmdif->p.glob = cmdif->p.kidx;
			break;
		}
	}
}
static void export_rule0 ( struct ip_fw * krule , struct ip_fw_rule0 * urule , int len ) { int cmdlen , l ; ipfw_insn * cmd ; ipfw_insn_limit * lcmd ; ipfw_insn_if * cmdif ; memset ( urule , 0 , len ) ; urule -> act_ofs = krule -> act_ofs ; urule -> cmd_len = krule -> cmd_len ; urule -> rulenum = krule -> rulenum ; urule -> set = krule -> set ; if ( ( krule -> flags & IPFW_RULE_NOOPT ) != 0 ) urule -> _pad |= 1 ; memcpy ( urule -> cmd , krule -> cmd , krule -> cmd_len * sizeof ( uint32_t ) ) ; export_cntr0_base ( krule , ( struct ip_fw_bcounter0 * ) & urule -> pcnt ) ; l = urule -> cmd_len ; cmd = urule -> cmd ; cmdlen = 0 ; for ( ; l > 0 ; l -= cmdlen , cmd += cmdlen ) { cmdlen = F_LEN ( cmd ) ; switch ( cmd -> opcode ) { case O_TAG : case O_TAGGED : case O_PIPE : case O_QUEUE : case O_DIVERT : case O_TEE : case O_SKIPTO : case O_CALLRETURN : case O_NETGRAPH : case O_NGTEE : case O_NAT : if ( cmd -> arg1 == IP_FW_TARG ) cmd -> arg1 = IP_FW_TABLEARG ; else if ( cmd -> arg1 == IP_FW_NAT44_GLOBAL ) cmd -> arg1 = 0 ; break ; case O_SETFIB : case O_SETDSCP : if ( cmd -> arg1 == IP_FW_TARG ) cmd -> arg1 = IP_FW_TABLEARG ; else cmd -> arg1 &= ~ 0x8000 ; break ; case O_LIMIT : lcmd = ( ipfw_insn_limit * ) cmd ; if ( lcmd -> conn_limit == IP_FW_TARG ) lcmd -> conn_limit = IP_FW_TABLEARG ; break ; case O_XMIT : case O_RECV : case O_VIA : cmdif = ( ipfw_insn_if * ) cmd ; if ( cmdif -> name [ 0 ] != ' \1 ' ) break ; cmdif -> p . glob = cmdif -> p . kidx ; break ; } } }
Copies rule @krule from kernel to FreeBSD8 userland format (v0)
Copies rule @krule from kernel to FreeBSD8 userland format ( v0 )
/* copy header */ /* Copy opcodes */ /* Export counters */ /*
	 * Alter opcodes:
	 * 1) convert tablearg value from 0 to 65535
	 * 2) Remove highest bit from O_SETFIB/O_SETDSCP values.
	 * 3) convert table number in iface opcodes to int
	 */ /* Opcodes supporting tablearg */ /* Interface tables */ /* Interface table, possibly */