summaryrefslogtreecommitdiffstats
path: root/src/vnet/unix/tuntap.c
AgeCommit message (Expand)AuthorFilesLines
2022-04-04vppinfra: make _vec_len() read-onlyDamjan Marion1-3/+3
2022-01-07ethernet: new interface registration functionDamjan Marion1-6/+6
2021-05-01vlib: refactor trajectory trace debug featureBenoît Ganne1-8/+0
2020-12-28vlib: add missing file template descriptionsPaul Vinciguerra1-0/+1
2020-11-09vlib: fix trace number accountingBenoît Ganne1-5/+3
2019-09-24vlib: add flag to explicitelly mark nodes which can init per-node packet traceDamjan Marion1-0/+1
2019-05-16init / exit function orderingDave Barach1-6/+6
2019-02-09buffers: fix typoDamjan Marion1-2/+2
2019-02-06buffers: make buffer data size configurable from startup configDamjan Marion1-2/+2
2018-11-14Remove c-11 memcpy checks from perf-critical codeDave Barach1-7/+8
2018-11-13vlib rename vlib_frame_args(...) to vlib_frame_scalar_args(..)Damjan Marion1-3/+3
2018-10-23c11 safe string handling supportDave Barach1-9/+9
2018-09-24Trivial: Clean up some typos.Paul Vinciguerra1-3/+3
2018-07-11avoid using thread local storage for thread indexDamjan Marion1-2/+2
2017-12-11VPP-273 Coding standards cleanup - vnet/vnet/unixsharath reddy1-194/+205
2017-10-06tuntap: Introduce per thread structure to suport multi-threadsSteven1-31/+43
2017-09-28tun/tap: Bad packets sent to kernel via tun/tap interfaceSteven1-11/+15
2017-09-09move unix_file_* code to vppinfraDamjan Marion1-5/+5
2017-08-11the automatic addition of IP address to the magic TAP interface should only h...Neale Ranns1-0/+21
2017-04-06Use thread local storage for thread indexDamjan Marion1-2/+2
2017-03-06features: take device-input buffer advance value directlyDamjan Marion1-1/+1
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion1-0/+1000
span class="cm"> * 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. */ /** * @file * @brief Functions to convert PCAP file format to VPP PG (Packet Generator) * */ #include <vnet/unix/pcap.h> #include <vnet/ethernet/packet.h> #include <stdio.h> pcap_main_t pcap_main; /** * @brief char * to seed a PG file */ static char * pg_fmt = "packet-generator new {\n" " name s%d\n" " limit 1\n" " size %d-%d\n" " node ethernet-input\n"; /** * @brief Packet Generator Stream boilerplate * * @param *ofp - FILE * @param i - int * @param *pkt - u8 */ void stream_boilerplate (FILE *ofp, int i, u8 * pkt) { fformat(ofp, pg_fmt, i, vec_len(pkt), vec_len(pkt)); } /** * @brief Conversion of PCAP file to PG file format * * @param *pm - pcap_main_t * @param *ofp - FILE * * @return rc - int * */ int pcap2pg (pcap_main_t * pm, FILE *ofp) { int i, j; u8 *pkt; for (i = 0; i < vec_len (pm->packets_read); i++) { int offset; ethernet_header_t * h; u64 ethertype; pkt = pm->packets_read[i]; h = (ethernet_header_t *)pkt; stream_boilerplate (ofp, i, pkt); fformat (ofp, " data {\n"); ethertype = clib_net_to_host_u16 (h->type); /** * In vnet terms, packet generator interfaces are not ethernets. * They don't have vlan tables. * This transforms captured 802.1q VLAN packets into * regular Ethernet packets. */ if (ethertype == 0x8100 /* 802.1q vlan */) { u16 * vlan_ethertype = (u16 *)(h+1); ethertype = clib_net_to_host_u16(vlan_ethertype[0]); offset = 18; } else offset = 14; fformat (ofp, " 0x%04x: %02x%02x.%02x%02x.%02x%02x" " -> %02x%02x.%02x%02x.%02x%02x\n", ethertype, h->src_address[0], h->src_address[1], h->src_address[2], h->src_address[3], h->src_address[4], h->src_address[5], h->dst_address[0], h->dst_address[1], h->dst_address[2], h->dst_address[3], h->dst_address[4], h->dst_address[5]); fformat (ofp, " hex 0x"); for (j = offset; j < vec_len (pkt); j++) fformat (ofp, "%02x", pkt[j]); fformat (ofp, " }\n"); fformat (ofp, "}\n\n"); } return 0; } /** * @brief pcap2pg. * usage: pcap2pg -i <input-file> [-o <output-file>] */ int main (int argc, char **argv) { unformat_input_t input; pcap_main_t * pm = &pcap_main; u8 * input_file = 0, * output_file = 0; FILE * ofp; clib_error_t * error; unformat_init_command_line (&input, argv); while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) { if (unformat(&input, "-i %s", &input_file) || unformat (&input, "input %s", &input_file)) ; else if (unformat (&input, "-o %s", &output_file) || unformat (&input, "output %s", &output_file)) ; else { usage: fformat(stderr, "usage: pcap2pg -i <input-file> [-o <output-file>]\n"); exit (1); } } if (input_file == 0) goto usage; pm->file_name = (char *)input_file; error = pcap_read (pm); if (error) { clib_error_report (error); exit (1); } if (output_file) { ofp = fopen ((char *)output_file, "rw"); if (ofp == NULL) clib_unix_warning ("Couldn't create '%s'", output_file); exit (1); } else { ofp = stdout; } pcap2pg (pm, ofp); fclose (ofp); exit (0); }