/** * the actual filtering function * Expects Flow messages, otherwise it throws * @param m the message to be checked */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Flow)) throw std::runtime_error("FlowFilter: wrong message type"); const Flow* flow = static_cast<const Flow* > (m.get()); if(is_indirect(m_ip_src_mode)) { if(!go_ahead( (m_ip_src_address & m_ip_src_mask) == (flow->key().src_ip4 & m_ip_src_mask), m_ip_src_mode)) return; } if(is_indirect(m_ip_dst_mode)) { if(!go_ahead( (m_ip_dst_address & m_ip_dst_mask) == (flow->key().dst_ip4 & m_ip_dst_mask), m_ip_dst_mode)) return; } if(is_indirect(m_layer4_mode)) { if(!go_ahead(m_layer4_proto == flow->key().proto, m_layer4_mode)) return; } if( (flow->key().proto != Packet::kUDP) && (flow->key().proto != Packet::kTCP) ) flow_passed(std::move(m)); if(is_indirect(m_src_port_mode)) { if(!go_ahead(m_src_port == flow->key().src_port, m_src_port_mode)) return; } if(is_indirect(m_dst_port_mode)) { if(!go_ahead(m_dst_port == flow->key().dst_port, m_dst_port_mode)) return; } flow_passed(std::move(m)); }
int three_params_second_cut(t_data *data, t_instruc *inst, int *order) { if (is_register(inst->trim, data, inst, order) == 1) return (1); else if (is_direct(inst->trim, data, inst, order) == 1) return (1); else if (is_indirect(inst->trim, data, inst, order) == 1) return (1); else error_line(data, "Incorrect input parameters"); return (0); }
int my_st(t_corewar *core, t_champions *champions, t_instruction *instruction) { int value_to_store; int index; value_to_store = 0; if (is_good_register(instruction->params[0]) == 1) value_to_store = champions->reg[instruction->params[0]]; if (is_register(instruction->type, 2) == 1) { if (is_good_register(instruction->params[1]) == 1) champions->reg[instruction->params[1]] = value_to_store; } else if (is_indirect(instruction->type, 2) == 1) { index = champions->pc - 5 + (instruction->params[1] % IDX_MOD); write_arena_four(core, champions, value_to_store, index); } return (0); }
/** * decides whether filtering should go on or the packet should be discarded * @param[in] mode the filter mode. * @param[in] port_list port list. * @param[in] port port number. * @return false if the packet should be discarded, true otherwise */ static inline bool go_ahead(uint8_t mode, PORT_LIST& port_list, uint16_t port) { if(is_indirect(mode)) { PORT_LIST::iterator it = port_list.begin(); PORT_LIST::iterator it_end = port_list.end(); bool is_mode_discard = (0 != (mode & (1<<FILTER_OUT))); if (is_mode_discard) { while (it != it_end) { if (*it == port) { return false; } it++; } } else { while (it != it_end) { if (*it == port) { return true; } it++; } return false; } } return true; }
void three_params_first(int i, t_data *data, t_instruc *inst, int *order) { if (g_op[i].param_type[*order] == T_REG) { if (is_register(inst->trim, data, inst, order) == 1) return ; else error_line(data, "Incorrect input parameters"); } else if (g_op[i].param_type[*order] == (T_REG | T_DIR | T_IND)) { if (is_register(inst->trim, data, inst, order) == 1) return ; else if (is_direct(inst->trim, data, inst, order) == 1) return ; else if (is_indirect(inst->trim, data, inst, order) == 1) return ; else error_line(data, "Incorrect input parameters"); } else error_line(data, "Incorrect input parameters"); }
/** * the actual filtering function * Expects Packet messages, otherwise it throws * @param m the message to be checked */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Packet)) { throw std::runtime_error("PacketFiler: wrong message type"); } const Packet* packet = static_cast<const Packet* > (m.get()); if(is_indirect(m_layer3_mode)) { if(!go_ahead(m_layer3_proto == packet->l3_protocol(), m_layer3_mode)) { return; } } if( packet->l3_protocol() != Packet::kPktTypeIP4) { packet_passed(std::move(m)); return; } if(is_indirect(m_ip_src_mode)) { if(!go_ahead( (m_ip_src_address & m_ip_src_mask) == (packet->ip_src() & m_ip_src_mask), m_ip_src_mode)) { return; } } if(is_indirect(m_ip_dst_mode)) { if(!go_ahead( (m_ip_dst_address & m_ip_dst_mask) == (packet->ip_dst() & m_ip_dst_mask), m_ip_dst_mode)) { return; } } if(is_indirect(m_layer4_mode)) { if(!go_ahead(m_layer4_proto == packet->l4_protocol(), m_layer4_mode)) { return; } } if( (!packet->is_udp()) && (!packet->is_tcp()) ) { packet_passed(std::move(m)); return; } // checks source port. if (!go_ahead(m_src_port_mode, m_src_ports, packet->src_port())) { return; } // checks destination port. if (!go_ahead(m_dst_port_mode, m_dst_ports, packet->dst_port())) { return; } packet_passed(std::move(m)); }