# Copyright (c) 2015 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. lib_LTLIBRARIES += libvnet.la libvnet_la_SOURCES = libvnet_la_DEPENDENCIES = \ libvppinfra.la \ libvlib.la \ libsvmdb.la \ libsvm.la \ libvlibmemory.la libvnet_la_LIBADD = $(libvnet_la_DEPENDENCIES) -lm -lpthread -ldl -lrt if WITH_LIBSSL libvnet_la_LIBADD += -lcrypto endif ######################################## # Generic stuff ######################################## libvnet_la_SOURCES += \ vnet/config.c \ vnet/devices/devices.c \ vnet/handoff.c \ vnet/interface.c \ vnet/interface_api.c \ vnet/interface_cli.c \ vnet/interface_format.c \ vnet/interface_output.c \ vnet/misc.c \ vnet/replication.c nobase_include_HEADERS += \ vnet/api_errno.h \ vnet/buffer.h \ vnet/config.h \ vnet/devices/devices.h \ vnet/global_funcs.h \ vnet/handoff.h \ vnet/interface.h \ vnet/interface.api.h \ vnet/interface_funcs.h \ vnet/ip/ip4_to_ip6.h \ vnet/ip/ip6_to_ip4.h \ vnet/l3_types.h \ vnet/pipeline.h \ vnet/replication.h \ vnet/vnet.h \ vnet/vnet_all_api_h.h \ vnet/vnet_msg_enum.h \ vnet/util/radix.h API_FILES += vnet/interface.api ######################################## # Policer infra ######################################## libvnet_la_SOURCES += \ vnet/policer/node_funcs.c \ vnet/policer/policer.c \ vnet/policer/xlate.c \ vnet/policer/policer_api.c nobase_include_HEADERS += \ vnet/policer/police.h \ vnet/policer/policer.h \ vnet/policer/xlate.h \ vnet/policer/policer.api.h API_FILES += vnet/policer/policer.api ######################################## # Cop - junk filter ######################################## libvnet_la_SOURCES += \ vnet/cop/cop.c \ vnet/cop/node1.c \ vnet/cop/ip4_whitelist.c \ vnet/cop/ip6_whitelist.c \ vnet/cop/cop_api.c nobase_include_HEADERS += \ vnet/cop/cop.h \ vnet/cop/cop.api.h API_FILES += vnet/cop/cop.api ######################################## # Layer 2 protocols go here ######################################## ######################################## # Layer 2 protocol: Ethernet ######################################## libvnet_la_SOURCES += \ vnet/ethernet/arp.c \ vnet/ethernet/format.c \ vnet/ethernet/init.c \ vnet/ethernet/interface.c \ vnet/ethernet/node.c \ vnet/ethernet/pg.c \ vnet/ethernet/sfp.c \ vnet/ethernet/p2p_ethernet.c \ vnet/ethernet/p2p_ethernet_input.c \ vnet/ethernet/p2p_ethernet_api.c nobase_include_HEADERS += \ vnet/ethernet/arp_packet.h \ vnet/ethernet/error.def \ vnet/ethernet/ethernet.h \ vnet/ethernet/packet.h \ vnet/ethernet/types.def \ vnet/ethernet/sfp.h \ vnet/ethernet/p2p_ethernet.api.h \ vnet/ethernet/p2p_ethernet.h API_FILES += vnet/ethernet/p2p_ethernet.api ######################################## # Layer 2 protocol: Ethernet bridging ######################################## libvnet_la_SOURCES += \ vnet/l2/feat_bitmap.c \ vnet/l2/l2_api.c \ vnet/l2/l2_bd.c \ vnet/l2/l2_bvi.c \ vnet/l2/l2_input_classify.c \ vnet/l2/l2_output_classify.c \ vnet/l2/l2_efp_filter.c \ vnet/l2/l2_fib.c \ vnet/l2/l2_flood.c \ vnet/l2/l2_fwd.c \ vnet/l2/l2_input_acl.c \ vnet/l2/l2_input.c \ vnet/l2/l2_input_vtr.c \ vnet/l2/l2_learn.c \ vnet/l2/l2_output_acl.c \ vnet/l2/l2_output.c \ vnet/l2/l2_patch.c \ vnet/l2/l2_rw.c \ vnet/l2/l2_vtr.c \ vnet/l2/l2_xcrw.c nobase_include_HEADERS += \ vnet/l2/feat_bitmap.h \ vnet/l2/l2_input.h \ vnet/l2/l2_output.h \ vnet/l2/l2_vtr.h \ vnet/l2/l2_input_vtr.h \ vnet/l2/l2_efp_filter.h \ vnet/l2/l2_fwd.h \ vnet/l2/l2_bd.h \ vnet/l2/l2_bvi.h \ vnet/l2/l2_flood.h \ vnet/l2/l2_fib.h \ vnet/l2/l2_rw.h \ vnet/l2/l2_xcrw.h \ vnet/l2/l2_classify.h \ vnet/l2/l2.api.h API_FILES += vnet/l2/l2.api ######################################## # Layer 2 protocol: SRP ######################################## libvnet_la_SOURCES += \ vnet/srp/format.c \ vnet/srp/interface.c \ vnet/srp/node.c \ vnet/srp/pg.c nobase_include_HEADERS += \ vnet/srp/packet.h \ vnet/srp/srp.h ######################################## # Layer 2 protocol: PPP ######################################## libvnet_la_SOURCES += \ vnet/ppp/node.c \ vnet/ppp/pg.c \ vnet/ppp/ppp.c nobase_include_HEADERS += \ vnet/ppp/error.def \ vnet/ppp/ppp.h \ vnet/ppp/packet.h ######################################## # Layer 2 protocol: HDLC ######################################## libvnet_la_SOURCES += \ vnet/hdlc/node.c \ vnet/hdlc/pg.c \ vnet/hdlc/hdlc.c nobase_include_HEADERS += \ vnet/hdlc/error.def \ vnet/hdlc/hdlc.h \ vnet/hdlc/packet.h ######################################## # Layer 2 protocol: LLC ######################################## libvnet_la_SOURCES += \ vnet/llc/llc.c \ vnet/llc/node.c \ vnet/llc/pg.c nobase_include_HEADERS += \ vnet/llc/llc.h ######################################## # Layer 2 protocol: SNAP ######################################## libvnet_la_SOURCES += \ vnet/snap/snap.c \ vnet/snap/node.c \ vnet/snap/pg.c nobase_include_HEADERS += \ vnet/snap/snap.h ######################################## # Layer 2 / vxlan ######################################## libvnet_la_SOURCES += \ vnet/vxlan/vxlan.c \ vnet/vxlan/encap.c \ vnet/vxlan/decap.c \ vnet/vxlan/vxlan_api.c nobase_include_HEADERS += \ vnet/vxlan/vxlan.h \ vnet/vxlan/vxlan_packet.h \ vnet/vxlan/vxlan_error.def \ vnet/vxlan/vxlan.api.h API_FILES += vnet/vxlan/vxlan.api ######################################## # Layer 2 / Geneve ######################################## libvnet_la_SOURCES += \ vnet/geneve/geneve.c \ vnet/geneve/encap.c \ vnet/geneve/decap.c \ vnet/geneve/geneve_api.c nobase_include_HEADERS += \ vnet/geneve/geneve.h \ vnet/geneve/geneve_packet.h \ vnet/geneve/geneve_error.def \ vnet/geneve/geneve.api.h API_FILES += vnet/geneve/geneve.api ######################################## # Layer 2 / CDP ######################################## libvnet_la_SOURCES += \ vnet/cdp/cdp_input.c \ vnet/cdp/cdp_node.c \ vnet/cdp/cdp_periodic.c nobase_include_HEADERS += \ vnet/cdp/cdp_protocol.h ######################################## # Layer 2 / LLDP ######################################## libvnet_la_SOURCES += \ vnet/lldp/lldp_input.c \ vnet/lldp/lldp_node.c \ vnet/lldp/lldp_output.c \ vnet/lldp/lldp_cli.c \ vnet/lldp/lldp_api.c nobase_include_HEADERS += \ vnet/lldp/lldp_protocol.h \ vnet/lldp/lldp.h \ vnet/lldp/lldp.api.h API_FILES += vnet/lldp/lldp.api ######################################## # Layer 2/3 "classify" ######################################## libvnet_la_SOURCES += \ vnet/classify/vnet_classify.c \ vnet/classify/ip_classify.c \ vnet/classify/input_acl.c \ vnet/classify/policer
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef included_vppinfra_pcap_funcs_h
#define included_vppinfra_pcap_funcs_h
/** Write out data to output file. */
clib_error_t *pcap_write (pcap_main_t * pm);
/** Read data from file. */
clib_error_t *pcap_read (pcap_main_t * pm);
/**
* @brief Add packet
*
* @param *pm - pcap_main_t
* @param time_now - f64
* @param n_bytes_in_trace - u32
* @param n_bytes_in_packet - u32
*
* @return Packet Data
*
*/
static inline void *
pcap_add_packet (pcap_main_t * pm,
f64 time_now, u32 n_bytes_in_trace, u32 n_bytes_in_packet)
{
pcap_packet_header_t *h;
u8 *d;
vec_add2 (pm->pcap_data, d, sizeof (h[0]) + n_bytes_in_trace);
h = (void *) (d);
h->time_in_sec = time_now;
h->time_in_usec = 1e6 * (time_now - h->time_in_sec);
h->n_packet_bytes_stored_in_file = n_bytes_in_trace;
h->n_bytes_in_packet = n_bytes_in_packet;
pm->n_packets_captured++;
return h->data;
}
/**
* @brief Add buffer (vlib_buffer_t) to the trace
*
* @param *pm - pcap_main_t
* @param *vm - vlib_main_t
* @param buffer_index - u32
* @param n_bytes_in_trace - u32
*
*/
static inline void
pcap_add_buffer (pcap_main_t * pm,
struct vlib_main_t *vm, u32 buffer_index,
u32 n_bytes_in_trace)
{
vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index);
u32 n = vlib_buffer_length_in_chain (vm, b);
i32 n_left = clib_min (n_bytes_in_trace, n);
f64 time_now = vlib_time_now (vm);
void *d;
if (PREDICT_TRUE (pm->n_packets_captured < pm->n_packets_to_capture))
{
clib_spinlock_lock_if_init (&pm->lock);
d = pcap_add_packet (pm, time_now, n_left, n);
while (1)
{
u32 copy_length = clib_min ((u32) n_left, b->current_length);
clib_memcpy_fast (d, b->data + b->current_data, copy_length);
n_left -= b->current_length;
if (n_left <= 0)
break;
d += b->current_length;
ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
b = vlib_get_buffer (vm, b->next_buffer);
}
clib_spinlock_unlock_if_init (&pm->lock);
}
}
#endif /* included_vppinfra_pcap_funcs_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/