/*
* Copyright (c) 2017 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.
*/
/*
* ip/ip6_input.c: IP v6 input node
*
* Copyright (c) 2008 Eliot Dresselhaus
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef included_ip6_input_h
#define included_ip6_input_h
#include <vnet/ip/ip.h>
#include <vnet/ip/icmp6.h>
extern char *ip6_error_strings[];
typedef enum
{
IP6_INPUT_NEXT_DROP,
IP6_INPUT_NEXT_LOOKUP,
IP6_INPUT_NEXT_LOOKUP_MULTICAST,
IP6_INPUT_NEXT_ICMP_ERROR/*
* replication.c : packet replication
*
* 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.
*/
#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vppinfra/error.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/replication.h>
replication_main_t replication_main;
replication_context_t *
replication_prep (vlib_main_t * vm,
vlib_buffer_t * b0, u32 recycle_node_index, u32 l2_packet)
{
replication_main_t *rm = &replication_main;
replication_context_t *ctx;
uword thread_index = vm->thread_index;
ip4_header_t *ip;
u32 ctx_id;
/* Allocate a context, reserve context 0 */
if (PREDICT_FALSE (rm->contexts[thread_index] == 0))
pool_get_aligned (rm->contexts[thread_index], ctx, CLIB_CACHE_LINE_BYTES);
pool_get_aligned (rm->contexts[thread_index], ctx, CLIB_CACHE_LINE_BYTES);
ctx_id = ctx - rm->contexts[thread_index];
/* Save state from vlib buffer */
ctx->saved_free_list_index = vlib_buffer_get_free_list_index (b0);
ctx->current_data = b0->current_data;
/* Set up vlib buffer hooks */
b0->recycle_count = ctx_id;
vlib_buffer_set_free_list_index (b0, rm->recycle_list_index);
b0->flags |= VLIB_BUFFER_RECYCLE;
/* Save feature state */
ctx->recycle_node_index = recycle_node_index;
/* Save vnet state */
clib_memcpy (ctx->vnet_buffer, vnet_buffer (b0),
sizeof (vnet_buffer_opaque_t));
/* Save packet contents */
ctx->l2_packet = l2_packet;
ip = (ip4_header_t *) vlib_buffer_get_current (b0);
if (l2_packet)
{
/* Save ethernet header */
ctx->l2_header[0] = ((u64 *) ip)[0];
ctx->l2_header[1] = ((u64 *) ip)[1];
ctx->l2_header[2] = ((u64 *) ip)[2];
/* set ip to the true ip header */
ip = (ip4_header_t *) (((u8 *) ip) + vnet_buffer (b0)->l2.l2_len);
}
/*
* Copy L3 fields.
* We need to save TOS for ip4 and ip6 packets.
* Fortunately the TOS field is
* in the first two bytes of both the ip4 and ip6 headers.
*/
ctx->ip_tos = *((u16 *) (ip));
/*
* Save the ip4 checksum as well. We just blindly save the corresponding two
* bytes even for ip6 packets.
*/
ctx->ip4_checksum = ip->checksum;
return ctx;
}
replication_context_t *
replication_recycle (vlib_main_t * vm, vlib_buffer_t * b0, u32 is_last)
{
replication_main_t *rm = &replication_main;
replication_context_t *ctx;
uword thread_index = vm->thread_index;
ip4_header_t *ip;
/* Get access to the replication context */
ctx = pool_elt_at_index (rm->contexts[thread_index], b0->recycle_count);