FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip4_options.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @brief Handle IPv4 header options in the data-path
18  */
19 
20 #include <vnet/ip/ip.h>
21 
22 typedef enum ip4_options_next_t_
23 {
28 
29 typedef struct ip4_options_trace_t_
30 {
31  u8 option[4];
33 
37 {
38  uword n_left_from, n_left_to_next, next_index;
39  u32 *from, *to_next;
40 
42  n_left_from = frame->n_vectors;
43  next_index = 0;
44 
45  while (n_left_from > 0)
46  {
47  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
48 
49  /*
50  * IP options packets, when properly used, are very low rate,
51  * so this code is not dual-looped for extra performance.
52  */
53  while (n_left_from > 0 && n_left_to_next > 0)
54  {
58  u8 *options;
59  u32 bi;
60 
61  bi = from[0];
62  from += 1;
63  n_left_from -= 1;
64  to_next[0] = bi;
65  to_next += 1;
66  n_left_to_next -= 1;
67 
68  b = vlib_get_buffer (vm, bi);
71 
72  options = (u8 *) (ip4 + 1);
73 
74  /*
75  * mask out the copy flag to leave the option type
76  */
77  switch (options[0] & 0x7f)
78  {
80  /*
81  * if it's an IGMP packet, pass up the local stack
82  */
83  if (IP_PROTOCOL_IGMP == ip4->protocol)
84  {
86  }
87  break;
88  default:
89  break;
90  }
91 
92  if (b->flags & VLIB_BUFFER_IS_TRACED)
93  {
95  vlib_add_trace (vm, node, b, sizeof (*t));
96 
98  }
100  n_left_to_next, bi, next);
101 
102  }
103 
104  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
105  }
106  return frame->n_vectors;
107 }
108 
109 u8 *
110 format_ip4_options_trace (u8 * s, va_list * args)
111 {
112  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
113  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
114  ip4_options_trace_t *t = va_arg (*args, ip4_options_trace_t *);
115  u32 indent = format_get_indent (s);
116 
117  s = format (s, "%Uoption:[0x%x,0x%x,0x%x,0x%x]",
118  format_white_space, indent,
119  t->option[0], t->option[1], t->option[2], t->option[3]);
120  return s;
121 }
122 
123 /* *INDENT-OFF* */
125  .name = "ip4-options",
126  .vector_size = sizeof (u32),
127 
128  .n_next_nodes = IP4_OPTIONS_N_NEXT,
129  .next_nodes = {
130  [IP4_OPTIONS_NEXT_PUNT] = "ip4-punt",
131  [IP4_OPTIONS_NEXT_LOCAL] = "ip4-local",
132  },
133  .format_buffer = format_ip4_header,
134  .format_trace = format_ip4_options_trace,
135 };
136 /* *INDENT-ON* */
137 
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */
ip4_options_trace_t_::option
u8 option[4]
Definition: ip4_options.c:31
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
ip4_options_next_t
enum ip4_options_next_t_ ip4_options_next_t
Handle IPv4 header options in the data-path.
IP4_ROUTER_ALERT_OPTION
#define IP4_ROUTER_ALERT_OPTION
Definition: ip4_packet.h:152
next
u16 * next
Definition: nat44_ei_out2in.c:718
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
IP4_OPTIONS_NEXT_PUNT
@ IP4_OPTIONS_NEXT_PUNT
Definition: ip4_options.c:24
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_frame_t
Definition: node.h:372
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
ip4_header_t
Definition: ip4_packet.h:87
ip4_options_trace_t
struct ip4_options_trace_t_ ip4_options_trace_t
format_ip4_options_trace
u8 * format_ip4_options_trace(u8 *s, va_list *args)
Definition: ip4_options.c:110
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
IP4_OPTIONS_N_NEXT
@ IP4_OPTIONS_N_NEXT
Definition: ip4_options.c:26
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
ip4_options_trace_t_
Definition: ip4_options.c:29
uword
u64 uword
Definition: types.h:112
IP4_OPTIONS_NEXT_LOCAL
@ IP4_OPTIONS_NEXT_LOCAL
Definition: ip4_options.c:25
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
format
description fragment has unexpected format
Definition: map.api:433
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
ip.h
u32
unsigned int u32
Definition: types.h:88
options
static struct option options[]
Definition: main.c:52
ip4_options_node
vlib_node_registration_t ip4_options_node
(constructor) VLIB_REGISTER_NODE (ip4_options_node)
Definition: ip4_options.c:124
format_ip4_header
format_function_t format_ip4_header
Definition: format.h:81
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
ip4_options_next_t_
ip4_options_next_t_
Handle IPv4 header options in the data-path.
Definition: ip4_options.c:22
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169