2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * node.c: srp packet processing
18 * Copyright (c) 2011 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #include <vlib/vlib.h>
41 #include <vnet/ip/ip_packet.h> /* for ip_csum_fold */
42 #include <vnet/srp/srp.h>
43 #include <vnet/pg/pg.h>
51 static u8 * format_srp_input_trace (u8 * s, va_list * va)
53 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
54 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
55 srp_input_trace_t * t = va_arg (*va, srp_input_trace_t *);
57 s = format (s, "%U", format_srp_header, t->packet_data);
64 SRP_INPUT_NEXT_ETHERNET_INPUT,
65 SRP_INPUT_NEXT_CONTROL,
73 } srp_input_disposition_t;
75 static srp_input_disposition_t srp_input_disposition_by_mode[8] = {
76 [SRP_MODE_reserved0] = {
77 .next_index = SRP_INPUT_NEXT_ERROR,
78 .error = SRP_ERROR_UNKNOWN_MODE,
80 [SRP_MODE_reserved1] = {
81 .next_index = SRP_INPUT_NEXT_ERROR,
82 .error = SRP_ERROR_UNKNOWN_MODE,
84 [SRP_MODE_reserved2] = {
85 .next_index = SRP_INPUT_NEXT_ERROR,
86 .error = SRP_ERROR_UNKNOWN_MODE,
88 [SRP_MODE_reserved3] = {
89 .next_index = SRP_INPUT_NEXT_ERROR,
90 .error = SRP_ERROR_UNKNOWN_MODE,
92 [SRP_MODE_keep_alive] = {
93 .next_index = SRP_INPUT_NEXT_ERROR,
94 .error = SRP_ERROR_KEEP_ALIVE_DROPPED,
97 .next_index = SRP_INPUT_NEXT_ETHERNET_INPUT,
98 .buffer_advance = sizeof (srp_header_t),
100 [SRP_MODE_control_pass_to_host] = {
101 .next_index = SRP_INPUT_NEXT_CONTROL,
103 [SRP_MODE_control_locally_buffered_for_host] = {
104 .next_index = SRP_INPUT_NEXT_CONTROL,
109 srp_input (vlib_main_t * vm,
110 vlib_node_runtime_t * node,
111 vlib_frame_t * from_frame)
113 vnet_main_t * vnm = vnet_get_main();
114 srp_main_t * sm = &srp_main;
115 u32 n_left_from, next_index, * from, * to_next;
117 from = vlib_frame_vector_args (from_frame);
118 n_left_from = from_frame->n_vectors;
120 if (node->flags & VLIB_NODE_FLAG_TRACE)
121 vlib_trace_frame_buffers_only (vm, node,
125 sizeof (srp_input_trace_t));
127 next_index = node->cached_next_index;
129 while (n_left_from > 0)
133 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
135 while (n_left_from >= 4 && n_left_to_next >= 2)
137 u32 bi0, bi1, sw_if_index0, sw_if_index1;
138 vlib_buffer_t * b0, * b1;
139 u8 next0, next1, error0, error1;
140 srp_header_t * s0, * s1;
141 srp_input_disposition_t * d0, * d1;
142 vnet_hw_interface_t * hi0, * hi1;
143 srp_interface_t * si0, * si1;
145 /* Prefetch next iteration. */
147 vlib_buffer_t * b2, * b3;
149 b2 = vlib_get_buffer (vm, from[2]);
150 b3 = vlib_get_buffer (vm, from[3]);
152 vlib_prefetch_buffer_header (b2, LOAD);
153 vlib_prefetch_buffer_header (b3, LOAD);
155 CLIB_PREFETCH (b2->data, sizeof (srp_header_t), LOAD);
156 CLIB_PREFETCH (b3->data, sizeof (srp_header_t), LOAD);
168 b0 = vlib_get_buffer (vm, bi0);
169 b1 = vlib_get_buffer (vm, bi1);
171 s0 = vlib_buffer_get_current (b0);
172 s1 = vlib_buffer_get_current (b1);
174 /* Data packets are always assigned to side A (outer ring) interface. */
175 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
176 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
178 hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
179 hi1 = vnet_get_sup_hw_interface (vnm, sw_if_index1);
181 si0 = pool_elt_at_index (sm->interface_pool, hi0->hw_instance);
182 si1 = pool_elt_at_index (sm->interface_pool, hi1->hw_instance);
184 sw_if_index0 = (s0->mode == SRP_MODE_data
185 ? si0->rings[SRP_RING_OUTER].sw_if_index
187 sw_if_index1 = (s1->mode == SRP_MODE_data
188 ? si1->rings[SRP_RING_OUTER].sw_if_index
191 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
192 vnet_buffer (b1)->sw_if_index[VLIB_RX] = sw_if_index1;
194 d0 = srp_input_disposition_by_mode + s0->mode;
195 d1 = srp_input_disposition_by_mode + s1->mode;
197 next0 = d0->next_index;
198 next1 = d1->next_index;
203 vlib_buffer_advance (b0, d0->buffer_advance);
204 vlib_buffer_advance (b1, d1->buffer_advance);
206 b0->error = node->errors[error0];
207 b1->error = node->errors[error1];
209 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
210 to_next, n_left_to_next,
211 bi0, bi1, next0, next1);
214 while (n_left_from > 0 && n_left_to_next > 0)
216 u32 bi0, sw_if_index0;
220 srp_input_disposition_t * d0;
221 srp_interface_t * si0;
222 vnet_hw_interface_t * hi0;
231 b0 = vlib_get_buffer (vm, bi0);
233 s0 = vlib_buffer_get_current (b0);
235 /* Data packets are always assigned to side A (outer ring) interface. */
236 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
238 hi0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
240 si0 = pool_elt_at_index (sm->interface_pool, hi0->hw_instance);
242 sw_if_index0 = (s0->mode == SRP_MODE_data
243 ? si0->rings[SRP_RING_OUTER].sw_if_index
246 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
248 d0 = srp_input_disposition_by_mode + s0->mode;
250 next0 = d0->next_index;
254 vlib_buffer_advance (b0, d0->buffer_advance);
256 b0->error = node->errors[error0];
258 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
259 to_next, n_left_to_next,
263 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
266 return from_frame->n_vectors;
269 static char * srp_error_strings[] = {
275 static vlib_node_registration_t srp_input_node = {
276 .function = srp_input,
278 /* Takes a vector of packets. */
279 .vector_size = sizeof (u32),
281 .n_errors = SRP_N_ERROR,
282 .error_strings = srp_error_strings,
284 .n_next_nodes = SRP_INPUT_N_NEXT,
286 [SRP_INPUT_NEXT_ERROR] = "error-drop",
287 [SRP_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input",
288 [SRP_INPUT_NEXT_CONTROL] = "srp-control",
291 .format_buffer = format_srp_header_with_length,
292 .format_trace = format_srp_input_trace,
293 .unformat_buffer = unformat_srp_header,
297 srp_topology_packet (vlib_main_t * vm, u32 sw_if_index, u8 ** contents)
299 vnet_main_t * vnm = vnet_get_main();
300 vnet_hw_interface_t * hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
301 srp_topology_header_t * t;
302 srp_topology_mac_binding_t * mb;
305 t = (void *) *contents;
307 nb = clib_net_to_host_u16 (t->n_bytes_of_data_that_follows);
308 nmb = (nb - sizeof (t->originator_address)) / sizeof (mb[0]);
309 if (vec_len (*contents) < sizeof (t[0]) + nmb * sizeof (mb[0]))
310 return SRP_ERROR_TOPOLOGY_BAD_LENGTH;
312 /* Fill in our source MAC address. */
313 clib_memcpy_fast (t->ethernet.src_address, hi->hw_address, vec_len (hi->hw_address));
315 /* Make space for our MAC binding. */
316 vec_resize (*contents, sizeof (srp_topology_mac_binding_t));
317 t = (void *) *contents;
318 t->n_bytes_of_data_that_follows = clib_host_to_net_u16 (nb + sizeof (mb[0]));
320 mb = t->bindings + nmb;
323 ((t->srp.is_inner_ring ? SRP_TOPOLOGY_MAC_BINDING_FLAG_IS_INNER_RING : 0)
324 | (/* is wrapped FIXME */ 0));
325 clib_memcpy_fast (mb->address, hi->hw_address, vec_len (hi->hw_address));
328 = ~ip_csum_fold (ip_incremental_checksum (0, &t->control,
329 vec_len (*contents) - STRUCT_OFFSET_OF (srp_generic_control_header_t, control)));
337 if (vlib_buffer_add_data (vm, /* buffer to append to */ &bi,
338 *contents, vec_len (*contents)))
340 /* complete or partial buffer allocation failure */
342 vlib_buffer_free (vm, &bi, 1);
343 return SRP_ERROR_CONTROL_PACKETS_PROCESSED;
345 b = vlib_get_buffer (vm, bi);
346 vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
347 f = vlib_get_frame_to_node (vm, hi->output_node_index);
348 to_next = vlib_frame_vector_args (f);
351 vlib_put_frame_to_node (vm, hi->output_node_index, f);
354 return SRP_ERROR_CONTROL_PACKETS_PROCESSED;
357 typedef uword (srp_control_handler_function_t) (vlib_main_t * vm,
362 srp_control_input (vlib_main_t * vm,
363 vlib_node_runtime_t * node,
364 vlib_frame_t * from_frame)
366 u32 n_left_from, next_index, * from, * to_next;
367 vlib_node_runtime_t * error_node;
368 static u8 * contents;
370 error_node = vlib_node_get_runtime (vm, srp_input_node.index);
372 from = vlib_frame_vector_args (from_frame);
373 n_left_from = from_frame->n_vectors;
375 if (node->flags & VLIB_NODE_FLAG_TRACE)
376 vlib_trace_frame_buffers_only (vm, node,
380 sizeof (srp_input_trace_t));
382 next_index = node->cached_next_index;
384 while (n_left_from > 0)
388 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
390 while (n_left_from > 0 && n_left_to_next > 0)
392 u32 bi0, l2_len0, l3_len0;
395 srp_generic_control_header_t * s0;
404 b0 = vlib_get_buffer (vm, bi0);
406 s0 = vlib_buffer_get_current(b0);
407 l2_len0 = vlib_buffer_length_in_chain (vm, b0);
408 l3_len0 = l2_len0 - STRUCT_OFFSET_OF (srp_generic_control_header_t, control);
410 error0 = SRP_ERROR_CONTROL_PACKETS_PROCESSED;
412 error0 = s0->control.version != 0 ? SRP_ERROR_CONTROL_VERSION_NON_ZERO : error0;
415 u16 save0 = s0->control.checksum;
417 s0->control.checksum = 0;
418 computed0 = ~ip_csum_fold (ip_incremental_checksum (0, &s0->control, l3_len0));
419 error0 = save0 != computed0 ? SRP_ERROR_CONTROL_BAD_CHECKSUM : error0;
422 if (error0 == SRP_ERROR_CONTROL_PACKETS_PROCESSED)
424 static srp_control_handler_function_t * t[SRP_N_CONTROL_PACKET_TYPE] = {
425 [SRP_CONTROL_PACKET_TYPE_topology] = srp_topology_packet,
427 srp_control_handler_function_t * f;
430 if (s0->control.type < ARRAY_LEN (t))
431 f = t[s0->control.type];
435 vec_validate (contents, l2_len0 - 1);
436 vlib_buffer_contents (vm, bi0, contents);
437 error0 = f (vm, vnet_buffer (b0)->sw_if_index[VLIB_RX], &contents);
440 error0 = SRP_ERROR_UNKNOWN_CONTROL;
443 b0->error = error_node->errors[error0];
446 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
447 to_next, n_left_to_next,
451 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
454 return from_frame->n_vectors;
457 static vlib_node_registration_t srp_control_input_node = {
458 .function = srp_control_input,
459 .name = "srp-control",
460 /* Takes a vector of packets. */
461 .vector_size = sizeof (u32),
468 .format_buffer = format_srp_header_with_length,
469 .format_trace = format_srp_input_trace,
470 .unformat_buffer = unformat_srp_header,
473 static u8 * format_srp_ips_request_type (u8 * s, va_list * args)
475 u32 x = va_arg (*args, u32);
479 #define _(f,n) case SRP_IPS_REQUEST_##f: t = #f; break;
480 foreach_srp_ips_request_type
483 return format (s, "unknown 0x%x", x);
485 return format (s, "%U", format_c_identifier, t);
488 static u8 * format_srp_ips_status (u8 * s, va_list * args)
490 u32 x = va_arg (*args, u32);
494 #define _(f,n) case SRP_IPS_STATUS_##f: t = #f; break;
495 foreach_srp_ips_status
498 return format (s, "unknown 0x%x", x);
500 return format (s, "%U", format_c_identifier, t);
503 static u8 * format_srp_ips_state (u8 * s, va_list * args)
505 u32 x = va_arg (*args, u32);
509 #define _(f) case SRP_IPS_STATE_##f: t = #f; break;
510 foreach_srp_ips_state
513 return format (s, "unknown 0x%x", x);
515 return format (s, "%U", format_c_identifier, t);
518 static u8 * format_srp_ring (u8 * s, va_list * args)
520 u32 ring = va_arg (*args, u32);
521 return format (s, "%s", ring == SRP_RING_INNER ? "inner" : "outer");
524 static u8 * format_srp_ips_header (u8 * s, va_list * args)
526 srp_ips_header_t * h = va_arg (*args, srp_ips_header_t *);
528 s = format (s, "%U, %U, %U, %s-path",
529 format_srp_ips_request_type, h->request_type,
530 format_ethernet_address, h->originator_address,
531 format_srp_ips_status, h->status,
532 h->is_long_path ? "long" : "short");
537 static u8 * format_srp_interface (u8 * s, va_list * args)
539 srp_interface_t * si = va_arg (*args, srp_interface_t *);
540 srp_interface_ring_t * ir;
542 s = format (s, "address %U, IPS state %U",
543 format_ethernet_address, si->my_address,
544 format_srp_ips_state, si->current_ips_state);
545 for (ir = si->rings; ir < si->rings + SRP_N_RING; ir++)
546 if (ir->rx_neighbor_address_valid)
547 s = format (s, ", %U neighbor %U",
548 format_srp_ring, ir->ring,
549 format_ethernet_address, ir->rx_neighbor_address);
554 u8 * format_srp_device (u8 * s, va_list * args)
556 u32 hw_if_index = va_arg (*args, u32);
557 CLIB_UNUSED (int verbose) = va_arg (*args, int);
558 vnet_main_t * vnm = vnet_get_main();
559 srp_main_t * sm = &srp_main;
560 vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index);
561 srp_interface_t * si = pool_elt_at_index (sm->interface_pool, hi->hw_instance);
562 return format (s, "%U", format_srp_interface, si);
565 always_inline srp_interface_t *
566 srp_get_interface (u32 sw_if_index, srp_ring_type_t * ring)
568 vnet_main_t * vnm = vnet_get_main();
569 srp_main_t * sm = &srp_main;
570 vnet_hw_interface_t * hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
571 srp_interface_t * si;
573 ASSERT (hi->hw_class_index == srp_hw_interface_class.index);
574 si = pool_elt_at_index (sm->interface_pool, hi->hw_instance);
576 ASSERT (si->rings[SRP_RING_INNER].hw_if_index == hi->hw_if_index
577 || si->rings[SRP_RING_OUTER].hw_if_index == hi->hw_if_index);
580 (hi->hw_if_index == si->rings[SRP_RING_INNER].hw_if_index
587 static void init_ips_packet (srp_interface_t * si,
588 srp_ring_type_t tx_ring,
589 srp_ips_header_t * i)
591 clib_memset (i, 0, sizeof (i[0]));
594 i->srp.is_inner_ring = tx_ring;
596 i->srp.mode = SRP_MODE_control_locally_buffered_for_host;
597 srp_header_compute_parity (&i->srp);
599 clib_memcpy_fast (&i->ethernet.src_address, &si->my_address, sizeof (si->my_address));
600 i->ethernet.type = clib_host_to_net_u16 (ETHERNET_TYPE_SRP_CONTROL);
602 /* Checksum will be filled in later. */
603 i->control.version = 0;
604 i->control.type = SRP_CONTROL_PACKET_TYPE_ips;
605 i->control.ttl = 255;
607 clib_memcpy_fast (&i->originator_address, &si->my_address, sizeof (si->my_address));
610 static void tx_ips_packet (srp_interface_t * si,
611 srp_ring_type_t tx_ring,
612 srp_ips_header_t * i)
614 srp_main_t * sm = &srp_main;
615 vnet_main_t * vnm = vnet_get_main();
616 vlib_main_t * vm = sm->vlib_main;
617 vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, si->rings[tx_ring].hw_if_index);
620 u32 * to_next, bi = ~0;
622 if (! vnet_sw_interface_is_admin_up (vnm, hi->sw_if_index))
624 if (hi->hw_class_index != srp_hw_interface_class.index)
628 = ~ip_csum_fold (ip_incremental_checksum (0, &i->control,
629 sizeof (i[0]) - STRUCT_OFFSET_OF (srp_ips_header_t, control)));
631 if (vlib_buffer_add_data (vm, /* buffer to append to */ &bi, i,
634 /* complete or partial allocation failure */
636 vlib_buffer_free (vm, &bi, 1);
642 clib_warning ("%U %U",
643 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
644 format_srp_ips_header, i);
646 b = vlib_get_buffer (vm, bi);
647 vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = hi->sw_if_index;
649 f = vlib_get_frame_to_node (vm, hi->output_node_index);
650 to_next = vlib_frame_vector_args (f);
653 vlib_put_frame_to_node (vm, hi->output_node_index, f);
656 static int requests_switch (srp_ips_request_type_t r)
659 [SRP_IPS_REQUEST_forced_switch] = 1,
660 [SRP_IPS_REQUEST_manual_switch] = 1,
661 [SRP_IPS_REQUEST_signal_fail] = 1,
662 [SRP_IPS_REQUEST_signal_degrade] = 1,
664 return (int) r < ARRAY_LEN (t) ? t[r] : 0;
667 /* Called when an IPS control packet is received on given interface. */
668 void srp_ips_rx_packet (u32 sw_if_index, srp_ips_header_t * h)
670 vnet_main_t * vnm = vnet_get_main();
671 vlib_main_t * vm = srp_main.vlib_main;
672 srp_ring_type_t rx_ring;
673 srp_interface_t * si = srp_get_interface (sw_if_index, &rx_ring);
674 srp_interface_ring_t * ir = &si->rings[rx_ring];
678 clib_warning ("%U %U %U",
679 format_time_interval, "h:m:s:u", vlib_time_now (vm),
680 format_vnet_sw_if_index_name, vnm, sw_if_index,
681 format_srp_ips_header, h);
683 /* Ignore self-generated IPS packets. */
684 if (! memcmp (h->originator_address, si->my_address, sizeof (h->originator_address)))
687 /* Learn neighbor address from short path messages. */
688 if (! h->is_long_path)
690 if (ir->rx_neighbor_address_valid
691 && memcmp (ir->rx_neighbor_address, h->originator_address, sizeof (ir->rx_neighbor_address)))
695 ir->rx_neighbor_address_valid = 1;
696 clib_memcpy_fast (ir->rx_neighbor_address, h->originator_address, sizeof (ir->rx_neighbor_address));
699 switch (si->current_ips_state)
701 case SRP_IPS_STATE_idle:
702 /* Received {REQ,NEIGHBOR,W,S} in idle state: wrap. */
703 if (requests_switch (h->request_type)
705 && h->status == SRP_IPS_STATUS_wrapped)
707 srp_ips_header_t to_tx[2];
709 si->current_ips_state = SRP_IPS_STATE_wrapped;
710 si->hw_wrap_function (si->rings[SRP_SIDE_A].hw_if_index, /* enable_wrap */ 1);
711 si->hw_wrap_function (si->rings[SRP_SIDE_B].hw_if_index, /* enable_wrap */ 1);
713 init_ips_packet (si, rx_ring ^ 0, &to_tx[0]);
714 to_tx[0].request_type = SRP_IPS_REQUEST_idle;
715 to_tx[0].status = SRP_IPS_STATUS_wrapped;
716 to_tx[0].is_long_path = 0;
717 tx_ips_packet (si, rx_ring ^ 0, &to_tx[0]);
719 init_ips_packet (si, rx_ring ^ 1, &to_tx[1]);
720 to_tx[1].request_type = h->request_type;
721 to_tx[1].status = SRP_IPS_STATUS_wrapped;
722 to_tx[1].is_long_path = 1;
723 tx_ips_packet (si, rx_ring ^ 1, &to_tx[1]);
727 case SRP_IPS_STATE_wrapped:
728 if (! h->is_long_path
729 && h->request_type == SRP_IPS_REQUEST_idle
730 && h->status == SRP_IPS_STATUS_idle)
732 si->current_ips_state = SRP_IPS_STATE_idle;
733 si->hw_wrap_function (si->rings[SRP_SIDE_A].hw_if_index, /* enable_wrap */ 0);
734 si->hw_wrap_function (si->rings[SRP_SIDE_B].hw_if_index, /* enable_wrap */ 0);
738 case SRP_IPS_STATE_pass_thru:
750 /* Preform local IPS request on given interface. */
751 void srp_ips_local_request (u32 sw_if_index, srp_ips_request_type_t request)
753 vnet_main_t * vnm = vnet_get_main();
754 srp_main_t * sm = &srp_main;
755 srp_ring_type_t rx_ring;
756 srp_interface_t * si = srp_get_interface (sw_if_index, &rx_ring);
757 srp_interface_ring_t * ir = &si->rings[rx_ring];
759 if (request == SRP_IPS_REQUEST_wait_to_restore)
761 if (si->current_ips_state != SRP_IPS_STATE_wrapped)
763 if (! ir->waiting_to_restore)
765 ir->wait_to_restore_start_time = vlib_time_now (sm->vlib_main);
766 ir->waiting_to_restore = 1;
771 /* FIXME handle local signal fail. */
772 ir->wait_to_restore_start_time = 0;
773 ir->waiting_to_restore = 0;
778 clib_warning ("%U %U",
779 format_vnet_sw_if_index_name, vnm, sw_if_index,
780 format_srp_ips_request_type, request);
784 static void maybe_send_ips_message (srp_interface_t * si)
786 srp_main_t * sm = &srp_main;
787 srp_ips_header_t to_tx[2];
788 srp_ring_type_t rx_ring = SRP_RING_OUTER;
789 srp_interface_ring_t * r0 = &si->rings[rx_ring ^ 0];
790 srp_interface_ring_t * r1 = &si->rings[rx_ring ^ 1];
791 f64 now = vlib_time_now (sm->vlib_main);
793 if (! si->ips_process_enable)
796 if (si->current_ips_state == SRP_IPS_STATE_wrapped
797 && r0->waiting_to_restore
798 && r1->waiting_to_restore
799 && now >= r0->wait_to_restore_start_time + si->config.wait_to_restore_idle_delay
800 && now >= r1->wait_to_restore_start_time + si->config.wait_to_restore_idle_delay)
802 si->current_ips_state = SRP_IPS_STATE_idle;
803 r0->waiting_to_restore = r1->waiting_to_restore = 0;
804 r0->wait_to_restore_start_time = r1->wait_to_restore_start_time = 0;
807 if (si->current_ips_state != SRP_IPS_STATE_idle)
810 init_ips_packet (si, rx_ring ^ 0, &to_tx[0]);
811 init_ips_packet (si, rx_ring ^ 1, &to_tx[1]);
813 if (si->current_ips_state == SRP_IPS_STATE_idle)
815 to_tx[0].request_type = to_tx[1].request_type = SRP_IPS_REQUEST_idle;
816 to_tx[0].status = to_tx[1].status = SRP_IPS_STATUS_idle;
817 to_tx[0].is_long_path = to_tx[1].is_long_path = 0;
820 else if (si->current_ips_state == SRP_IPS_STATE_wrapped)
822 to_tx[0].request_type =
823 (si->rings[rx_ring ^ 0].waiting_to_restore
824 ? SRP_IPS_REQUEST_wait_to_restore
825 : SRP_IPS_REQUEST_signal_fail);
826 to_tx[1].request_type =
827 (si->rings[rx_ring ^ 1].waiting_to_restore
828 ? SRP_IPS_REQUEST_wait_to_restore
829 : SRP_IPS_REQUEST_signal_fail);
830 to_tx[0].status = to_tx[1].status = SRP_IPS_STATUS_wrapped;
831 to_tx[0].is_long_path = 0;
832 to_tx[1].is_long_path = 1;
835 tx_ips_packet (si, rx_ring ^ 0, &to_tx[0]);
836 tx_ips_packet (si, rx_ring ^ 1, &to_tx[1]);
840 srp_ips_process (vlib_main_t * vm,
841 vlib_node_runtime_t * rt,
844 srp_main_t * sm = &srp_main;
845 srp_interface_t * si;
849 pool_foreach (si, sm->interface_pool) {
850 maybe_send_ips_message (si);
852 vlib_process_suspend (vm, 1.0);
858 vlib_node_registration_t srp_ips_process_node = {
859 .function = srp_ips_process,
860 .type = VLIB_NODE_TYPE_PROCESS,
861 .name = "srp-ips-process",
862 .state = VLIB_NODE_STATE_DISABLED,
866 srp_setup_node (vlib_main_t *vm, u32 node_index)
868 vlib_node_t *n = vlib_get_node (vm, node_index);
869 pg_node_t *pn = pg_get_node (node_index);
870 n->format_buffer = format_srp_header_with_length;
871 n->unformat_buffer = unformat_srp_header;
872 pn->unformat_edit = unformat_pg_srp_header;
875 static clib_error_t * srp_init (vlib_main_t * vm)
877 srp_main_t * sm = &srp_main;
879 sm->default_data_ttl = 255;
881 vlib_register_node (vm, &srp_ips_process_node);
882 vlib_register_node (vm, &srp_input_node);
883 vlib_register_node (vm, &srp_control_input_node);
884 srp_setup_node (vm, srp_input_node.index);
889 VLIB_INIT_FUNCTION (srp_init);