void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index) { vlib_thread_main_t *tm = vlib_get_thread_main (); int i; vec_validate (cm->minis, tm->n_vlib_mains - 1); for (i = 0; i < tm->n_vlib_mains; i++) vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); }
static replicate_t * replicate_create_i (u32 num_buckets, dpo_proto_t rep_proto) { replicate_t *rep; rep = replicate_alloc_i(); rep->rep_n_buckets = num_buckets; rep->rep_proto = rep_proto; if (!REP_HAS_INLINE_BUCKETS(rep)) { vec_validate_aligned(rep->rep_buckets, rep->rep_n_buckets - 1, CLIB_CACHE_LINE_BYTES); } REP_DBG(rep, "create"); return (rep); }
static int lisp_gpe_rewrite (lisp_gpe_tunnel_t * t) { u8 *rw = 0; lisp_gpe_header_t * lisp0; int len; if (ip_addr_version(&t->src) == IP4) { ip4_header_t * ip0; ip4_udp_lisp_gpe_header_t * h0; len = sizeof(*h0); vec_validate_aligned(rw, len - 1, CLIB_CACHE_LINE_BYTES); h0 = (ip4_udp_lisp_gpe_header_t *) rw; /* Fixed portion of the (outer) ip4 header */ ip0 = &h0->ip4; ip0->ip_version_and_header_length = 0x45; ip0->ttl = 254; ip0->protocol = IP_PROTOCOL_UDP; /* we fix up the ip4 header length and checksum after-the-fact */ ip_address_copy_addr(&ip0->src_address, &t->src); ip_address_copy_addr(&ip0->dst_address, &t->dst); ip0->checksum = ip4_header_checksum (ip0); /* UDP header, randomize src port on something, maybe? */ h0->udp.src_port = clib_host_to_net_u16 (4341); h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); /* LISP-gpe header */ lisp0 = &h0->lisp; } else { ip6_header_t * ip0; ip6_udp_lisp_gpe_header_t * h0; len = sizeof(*h0); vec_validate_aligned(rw, len - 1, CLIB_CACHE_LINE_BYTES); h0 = (ip6_udp_lisp_gpe_header_t *) rw; /* Fixed portion of the (outer) ip6 header */ ip0 = &h0->ip6; ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28); ip0->hop_limit = 254; ip0->protocol = IP_PROTOCOL_UDP; /* we fix up the ip6 header length after-the-fact */ ip_address_copy_addr(&ip0->src_address, &t->src); ip_address_copy_addr(&ip0->dst_address, &t->dst); /* UDP header, randomize src port on something, maybe? */ h0->udp.src_port = clib_host_to_net_u16 (4341); h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); /* LISP-gpe header */ lisp0 = &h0->lisp; } lisp0->flags = t->flags; lisp0->ver_res = t->ver_res; lisp0->res = t->res; lisp0->next_protocol = t->next_protocol; lisp0->iid = clib_host_to_net_u32 (t->vni); t->rewrite = rw; return 0; }
/** * @brief Create an IPFIX template packet rewrite string * @param frm flow_report_main_t * * @param fr flow_report_t * * @param collector_address ip4_address_t * the IPFIX collector address * @param src_address ip4_address_t * the source address we should use * @param collector_port u16 the collector port we should use, host byte order * @returns u8 * vector containing the indicated IPFIX template packet */ static inline u8 * flowprobe_template_rewrite_inline (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, u16 collector_port, flowprobe_variant_t which) { ip4_header_t *ip; udp_header_t *udp; ipfix_message_header_t *h; ipfix_set_header_t *s; ipfix_template_header_t *t; ipfix_field_specifier_t *f; ipfix_field_specifier_t *first_field; u8 *rewrite = 0; ip4_ipfix_template_packet_t *tp; u32 field_count = 0; flow_report_stream_t *stream; flowprobe_main_t *fm = &flowprobe_main; flowprobe_record_t flags = fr->opaque.as_uword; bool collect_ip4 = false, collect_ip6 = false; stream = &frm->streams[fr->stream_index]; if (flags & FLOW_RECORD_L3) { collect_ip4 = which == FLOW_VARIANT_L2_IP4 || which == FLOW_VARIANT_IP4; collect_ip6 = which == FLOW_VARIANT_L2_IP6 || which == FLOW_VARIANT_IP6; if (which == FLOW_VARIANT_L2_IP4) flags |= FLOW_RECORD_L2_IP4; if (which == FLOW_VARIANT_L2_IP6) flags |= FLOW_RECORD_L2_IP6; } field_count += flowprobe_template_common_field_count (); if (flags & FLOW_RECORD_L2) field_count += flowprobe_template_l2_field_count (); if (collect_ip4) field_count += flowprobe_template_ip4_field_count (); if (collect_ip6) field_count += flowprobe_template_ip6_field_count (); if (flags & FLOW_RECORD_L4) field_count += flowprobe_template_l4_field_count (); /* allocate rewrite space */ vec_validate_aligned (rewrite, sizeof (ip4_ipfix_template_packet_t) + field_count * sizeof (ipfix_field_specifier_t) - 1, CLIB_CACHE_LINE_BYTES); tp = (ip4_ipfix_template_packet_t *) rewrite; ip = (ip4_header_t *) & tp->ip4; udp = (udp_header_t *) (ip + 1); h = (ipfix_message_header_t *) (udp + 1); s = (ipfix_set_header_t *) (h + 1); t = (ipfix_template_header_t *) (s + 1); first_field = f = (ipfix_field_specifier_t *) (t + 1); ip->ip_version_and_header_length = 0x45; ip->ttl = 254; ip->protocol = IP_PROTOCOL_UDP; ip->src_address.as_u32 = src_address->as_u32; ip->dst_address.as_u32 = collector_address->as_u32; udp->src_port = clib_host_to_net_u16 (stream->src_port); udp->dst_port = clib_host_to_net_u16 (collector_port); udp->length = clib_host_to_net_u16 (vec_len (rewrite) - sizeof (*ip)); /* FIXUP: message header export_time */ /* FIXUP: message header sequence_number */ h->domain_id = clib_host_to_net_u32 (stream->domain_id); /* Add TLVs to the template */ f = flowprobe_template_common_fields (f); if (flags & FLOW_RECORD_L2) f = flowprobe_template_l2_fields (f); if (collect_ip4) f = flowprobe_template_ip4_fields (f); if (collect_ip6) f = flowprobe_template_ip6_fields (f); if (flags & FLOW_RECORD_L4) f = flowprobe_template_l4_fields (f); /* Back to the template packet... */ ip = (ip4_header_t *) & tp->ip4; udp = (udp_header_t *) (ip + 1); ASSERT (f - first_field); /* Field count in this template */ t->id_count = ipfix_id_count (fr->template_id, f - first_field); fm->template_size[flags] = (u8 *) f - (u8 *) s; /* set length in octets */ s->set_id_length = ipfix_set_id_length (2 /* set_id */ , (u8 *) f - (u8 *) s); /* message length in octets */ h->version_length = version_length ((u8 *) f - (u8 *) h); ip->length = clib_host_to_net_u16 ((u8 *) f - (u8 *) ip); ip->checksum = ip4_header_checksum (ip); return rewrite; }
int ssvm_eth_create (ssvm_eth_main_t * em, u8 * name, int is_master) { // ssvm_eth_main_t * em = &ssvm_eth_main; ssvm_private_t * intfc; void * oldheap; clib_error_t * e; unix_shared_memory_queue_t * q; ssvm_shared_header_t * sh; ssvm_eth_queue_elt_t * elts; u32 * elt_indices; u8 enet_addr[6]; int i, rv; vec_add2 (em->intfcs, intfc, 1); intfc->ssvm_size = em->segment_size; intfc->i_am_master = 1; intfc->name = name; intfc->my_pid = getpid(); if (is_master == 0) { rv = ssvm_slave_init (intfc, 20 /* timeout in seconds */); if (rv < 0) return rv; goto create_vnet_interface; } intfc->requested_va = em->next_base_va; em->next_base_va += em->segment_size; rv = ssvm_master_init (intfc, intfc - em->intfcs /* master index */); if (rv < 0) return rv; /* OK, segment created, set up queues and so forth. */ sh = intfc->sh; oldheap = ssvm_push_heap (sh); q = unix_shared_memory_queue_init (em->queue_elts, sizeof (u32), 0 /* consumer pid not interesting */, 0 /* signal not sent */); sh->opaque [TO_MASTER_Q_INDEX] = (void *)q; q = unix_shared_memory_queue_init (em->queue_elts, sizeof (u32), 0 /* consumer pid not interesting */, 0 /* signal not sent */); sh->opaque [TO_SLAVE_Q_INDEX] = (void *)q; /* * Preallocate the requested number of buffer chunks * There must be a better way to do this, etc. * Add some slop to avoid pool reallocation, which will not go well */ elts = 0; elt_indices = 0; vec_validate_aligned (elts, em->nbuffers - 1, CLIB_CACHE_LINE_BYTES); vec_validate_aligned (elt_indices, em->nbuffers - 1, CLIB_CACHE_LINE_BYTES); for (i = 0; i < em->nbuffers; i++) elt_indices[i] = i; sh->opaque [CHUNK_POOL_INDEX] = (void *) elts; sh->opaque [CHUNK_POOL_FREELIST_INDEX] = (void *) elt_indices; sh->opaque [CHUNK_POOL_NFREE] = (void *)(uword) em->nbuffers; ssvm_pop_heap (oldheap); create_vnet_interface: sh = intfc->sh; memset (enet_addr, 0, sizeof (enet_addr)); enet_addr[0] = 2; enet_addr[1] = 0xFE; enet_addr[2] = is_master; enet_addr[5] = sh->master_index; /* Let the games begin... */ if (is_master) sh->ready = 1; return 0; }