summaryrefslogtreecommitdiffstats
path: root/src/vnet/vxlan/decap.c
AgeCommit message (Expand)AuthorFilesLines
2019-03-28Typos. A bunch of typos I've been collecting.Paul Vinciguerra1-1/+1
2018-10-23c11 safe string handling supportDave Barach1-2/+2
2018-10-17vxlan:decap caching error (VPP-1462)Eyal Bari1-1/+1
2018-10-05vxlan:ip4 decap:remove access to tunnel objectEyal Bari1-163/+142
2018-09-24Trivial: Clean up some typos.Paul Vinciguerra1-3/+3
2018-08-28vxlan: decap use vlib_buffer_enqueue_to_nextEyal Bari1-254/+220
2018-08-01vxlan:optimize cached entry compareEyal Bari1-9/+5
2018-07-31vxlan:decap.c conform coding styleEyal Bari1-620/+690
2018-07-19Remove unused argument to vlib_feature_nextDamjan Marion1-3/+3
2018-07-09vxlan:use bihash_16_8 for ipv4 lookupEyal Bari1-27/+22
2018-07-05vxlan:use bihash_24_8 for ipv6 lookupEyal Bari1-41/+47
2018-06-14vxlan:use VLIB_NODE_FN for multiarch selectionEyal Bari1-17/+1
2018-06-13vxlan:offload RX floweyal bari1-0/+372
2018-04-17vxlan:remove counters writeback cacheEyal Bari1-466/+236
2017-10-23VXLAN:small refactor to vxlan inputEyal Bari1-235/+175
2017-07-14vnet_buffer_t flags cleanupDamjan Marion1-9/+9
2017-04-06Use thread local storage for thread indexDamjan Marion1-5/+5
2017-02-02VXLAN: further unify ip4/ip6 ctl plane handlingEyal Bari1-2/+2
2017-01-31Add vxlan-bypass feature to IP6 forwarding pathJohn Lo1-173/+282
2016-12-28Reorganize source tree to use single autotools instanceDamjan Marion1-0/+1130
Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * pcap2pg.c: convert pcap input to pg input
 *
 * Copyright (c) 2013 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.
 */
/**
 * @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);
}