void prepare_alter_schema_version_session() {
    // Create a new session for altering node2 and node3 system tables
    std::string ip_prefix = inst.ccm->get_ip_prefix();
    std::stringstream whitelist_hosts;
    whitelist_hosts << ip_prefix << "2," << ip_prefix << "3";
    cass_cluster_set_whitelist_filtering(inst.cluster, whitelist_hosts.str().c_str());
    schema_alter_session = cass_session_new();
    test_utils::CassFuturePtr connect_future(cass_session_connect(schema_alter_session, inst.cluster));
    test_utils::wait_and_check_error(connect_future.get());

    std::string update_peer("UPDATE system.peers SET schema_version=? WHERE peer='" + ip_prefix + "1'");
    test_utils::CassFuturePtr prepared_future(cass_session_prepare_n(schema_alter_session, update_peer.data(), update_peer.size()));
    test_utils::wait_and_check_error(prepared_future.get());
    schema_alter_prepared = test_utils::CassPreparedPtr(cass_future_get_prepared(prepared_future.get()));
  }
static void
process_netflow_v7(struct flow_packet *fp, struct flowd_config *conf,
    struct peer_state *peer, struct peers *peers, int log_fd, int log_socket)
{
	struct NF7_HEADER *nf7_hdr = (struct NF7_HEADER *)fp->packet;
	struct NF7_FLOW *nf7_flow;
	struct store_flow_complete flow;
	size_t offset;
	u_int i, nflows;
	if (fp->len < sizeof(*nf7_hdr)) {
		peer->ninvalid++;
		logit(LOG_WARNING, "short netflow v.7 packet %d bytes from %s",
		    fp->len, addr_ntop_buf(&fp->flow_source));
		return;
	}
	nflows = ntohs(nf7_hdr->c.flows);
	if (nflows == 0 || nflows > NF7_MAXFLOWS) {
		peer->ninvalid++;
		logit(LOG_WARNING, "Invalid number of flows (%u) in netflow "
		    "v.7 packet from %s", nflows,
		    addr_ntop_buf(&fp->flow_source));
		return;
	}
	if (fp->len != NF7_PACKET_SIZE(nflows)) {
		peer->ninvalid++;
		logit(LOG_WARNING, "Inconsistent Netflow v.7 packet from %s: "
		    "len %u expected %u", addr_ntop_buf(&fp->flow_source),
		    fp->len, NF7_PACKET_SIZE(nflows));
		return;
	}

	logit(LOG_DEBUG, "Valid netflow v.7 packet %d flows", nflows);
	update_peer(peers, peer, nflows, 7);

	for (i = 0; i < nflows; i++) {
		offset = NF7_PACKET_SIZE(i);
		nf7_flow = (struct NF7_FLOW *)(fp->packet + offset);

		bzero(&flow, sizeof(flow));

		/* NB. These are converted to network byte order later */
		flow.hdr.fields = STORE_FIELD_ALL;
		/* flow.hdr.tag is set later */
		flow.hdr.fields &= ~STORE_FIELD_TAG;
		flow.hdr.fields &= ~STORE_FIELD_SRC_ADDR6;
		flow.hdr.fields &= ~STORE_FIELD_DST_ADDR6;
		flow.hdr.fields &= ~STORE_FIELD_GATEWAY_ADDR6;

		/*
		 * XXX: we can parse the (undocumented) flags1 and flags2
		 * fields of the packet to disable flow fields not set by
		 * the Cat5k (e.g. destination-only mls nde mode)
		 */

		flow.recv_time.recv_sec = fp->recv_time.tv_sec;
		flow.recv_time.recv_usec = fp->recv_time.tv_usec;

		flow.pft.tcp_flags = nf7_flow->tcp_flags;
		flow.pft.protocol = nf7_flow->protocol;
		flow.pft.tos = nf7_flow->tos;

		memcpy(&flow.agent_addr, &fp->flow_source,
		    sizeof(flow.agent_addr));

		flow.src_addr.v4.s_addr = nf7_flow->src_ip;
		flow.src_addr.af = AF_INET;
		flow.dst_addr.v4.s_addr = nf7_flow->dest_ip;
		flow.dst_addr.af = AF_INET;
		flow.gateway_addr.v4.s_addr = nf7_flow->nexthop_ip;
		flow.gateway_addr.af = AF_INET;

		flow.ports.src_port = nf7_flow->src_port;
		flow.ports.dst_port = nf7_flow->dest_port;

#define NTO64(a) (store_htonll(ntohl(a)))
		flow.octets.flow_octets = NTO64(nf7_flow->flow_octets);
		flow.packets.flow_packets = NTO64(nf7_flow->flow_packets);
#undef NTO64

		flow.ifndx.if_index_in = htonl(ntohs(nf7_flow->if_index_in));
		flow.ifndx.if_index_out = htonl(ntohs(nf7_flow->if_index_out));

		flow.ainfo.sys_uptime_ms = nf7_hdr->uptime_ms;
		flow.ainfo.time_sec = nf7_hdr->time_sec;
		flow.ainfo.time_nanosec = nf7_hdr->time_nanosec;
		flow.ainfo.netflow_version = nf7_hdr->c.version;

		flow.ftimes.flow_start = nf7_flow->flow_start;
		flow.ftimes.flow_finish = nf7_flow->flow_finish;

		flow.asinf.src_as = htonl(ntohs(nf7_flow->src_as));
		flow.asinf.dst_as = htonl(ntohs(nf7_flow->dest_as));
		flow.asinf.src_mask = nf7_flow->src_mask;
		flow.asinf.dst_mask = nf7_flow->dst_mask;

		flow.finf.flow_sequence = nf7_hdr->flow_sequence;



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                          ADD IMED

/*sem_wait (&semFlows);

Add_flow(&flow);

sem_post (&semFlows);
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




		process_flow(&flow, conf, log_fd, log_socket);
	}
}
Beispiel #3
0
void process_netflow_v5(struct flow_packet* fp, struct peer_state* peer)
{
    struct NF5_HEADER* nf5_hdr = (struct NF5_HEADER*)fp->packet;
    struct NF5_FLOW* nf5_flow;
    struct store_flow_complete flow;
    size_t offset;
    u_int i, nflows;

    if (fp->len < sizeof(*nf5_hdr)) {
        peer->ninvalid++;
        logit(LOG_WARNING, "short netflow v.5 packet %d bytes from %s",
            fp->len, addr_ntop_buf(&fp->flow_source));
        return;
    }
    nflows = ntohs(nf5_hdr->c.flows);
    if (nflows == 0 || nflows > NF5_MAXFLOWS) {
        peer->ninvalid++;
        logit(LOG_WARNING, "Invalid number of flows (%u) in netflow "
            "v.5 packet from %s", nflows,
            addr_ntop_buf(&fp->flow_source));
        return;
    }
    if (fp->len != NF5_PACKET_SIZE(nflows)) {
        peer->ninvalid++;
        logit(LOG_WARNING, "Inconsistent Netflow v.5 packet from %s: "
            "len %u expected %zu", addr_ntop_buf(&fp->flow_source),
            fp->len, NF5_PACKET_SIZE(nflows));
        return;
    }

    logit(LOG_DEBUG, "Valid netflow v.5 packet %d flows", nflows);
    update_peer(peer, nflows, 5);

    for (i = 0; i < nflows; i++) {
        offset = NF5_PACKET_SIZE(i);
        nf5_flow = (struct NF5_FLOW*)(fp->packet + offset);

        bzero(&flow, sizeof(flow));

        /* NB. These are converted to network byte order later */
        flow.hdr.fields = STORE_FIELD_ALL;
        /* flow.hdr.tag is set later */
        flow.hdr.fields &= ~STORE_FIELD_TAG;
        flow.hdr.fields &= ~STORE_FIELD_SRC_ADDR6;
        flow.hdr.fields &= ~STORE_FIELD_DST_ADDR6;
        flow.hdr.fields &= ~STORE_FIELD_GATEWAY_ADDR6;

        flow.recv_time.recv_sec = fp->recv_time.tv_sec;
        flow.recv_time.recv_usec = fp->recv_time.tv_usec;

        flow.pft.tcp_flags = nf5_flow->tcp_flags;
        flow.pft.protocol = nf5_flow->protocol;
        flow.pft.tos = nf5_flow->tos;

        rte_memcpy(&flow.agent_addr, &fp->flow_source,
            sizeof(flow.agent_addr));

        flow.src_addr.v4.s_addr = nf5_flow->src_ip;
        flow.src_addr.af = AF_INET;
        flow.dst_addr.v4.s_addr = nf5_flow->dest_ip;
        flow.dst_addr.af = AF_INET;
        flow.gateway_addr.v4.s_addr = nf5_flow->nexthop_ip;
        flow.gateway_addr.af = AF_INET;

        flow.ports.src_port = nf5_flow->src_port;
        flow.ports.dst_port = nf5_flow->dest_port;

#define NTO64(a) (netflow_htonll(ntohl(a)))
        flow.octets.flow_octets = NTO64(nf5_flow->flow_octets);
        flow.packets.flow_packets = NTO64(nf5_flow->flow_packets);
#undef NTO64

        flow.ifndx.if_index_in = htonl(ntohs(nf5_flow->if_index_in));
        flow.ifndx.if_index_out = htonl(ntohs(nf5_flow->if_index_out));

        flow.ainfo.sys_uptime_ms = nf5_hdr->uptime_ms;
        flow.ainfo.time_sec = nf5_hdr->time_sec;
        flow.ainfo.time_nanosec = nf5_hdr->time_nanosec;
        flow.ainfo.netflow_version = nf5_hdr->c.version;

        flow.ftimes.flow_start = nf5_flow->flow_start;
        flow.ftimes.flow_finish = nf5_flow->flow_finish;

        flow.asinf.src_as = htonl(ntohs(nf5_flow->src_as));
        flow.asinf.dst_as = htonl(ntohs(nf5_flow->dest_as));
        flow.asinf.src_mask = nf5_flow->src_mask;
        flow.asinf.dst_mask = nf5_flow->dst_mask;

        flow.finf.engine_type = nf5_hdr->engine_type;
        flow.finf.engine_id = nf5_hdr->engine_id;
        flow.finf.flow_sequence = nf5_hdr->flow_sequence;

        process_flow(&flow);
    }
}