diff options
Diffstat (limited to 'vnet/vnet/ip/ip4_forward.c')
-rw-r--r-- | vnet/vnet/ip/ip4_forward.c | 279 |
1 files changed, 81 insertions, 198 deletions
diff --git a/vnet/vnet/ip/ip4_forward.c b/vnet/vnet/ip/ip4_forward.c index 632925a4a59..6d3dd88b176 100644 --- a/vnet/vnet/ip/ip4_forward.c +++ b/vnet/vnet/ip/ip4_forward.c @@ -709,11 +709,7 @@ void ip4_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable) { - vlib_main_t * vm = vlib_get_main(); ip4_main_t * im = &ip4_main; - ip_lookup_main_t * lm = &im->lookup_main; - u32 ci, cast; - u32 lookup_feature_index; vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0); @@ -731,34 +727,12 @@ ip4_sw_interface_enable_disable (u32 sw_if_index, if (0 != --im->ip_enabled_by_sw_if_index[sw_if_index]) return; } + vnet_feature_enable_disable ("ip4-unicast", "ip4-lookup", sw_if_index, + is_enable, 0, 0); - for (cast = 0; cast <= VNET_IP_RX_MULTICAST_FEAT; cast++) - { - vnet_feature_config_main_t * cm = &lm->feature_config_mains[cast]; - vnet_config_main_t * vcm = &cm->config_main; - - vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0); - ci = cm->config_index_by_sw_if_index[sw_if_index]; + vnet_feature_enable_disable ("ip4-multicast", "ip4-lookup-multicast", sw_if_index, + is_enable, 0, 0); - if (cast == VNET_IP_RX_UNICAST_FEAT) - lookup_feature_index = im->ip4_unicast_rx_feature_lookup; - else - lookup_feature_index = im->ip4_multicast_rx_feature_lookup; - - if (is_enable) - ci = vnet_config_add_feature (vm, vcm, - ci, - lookup_feature_index, - /* config data */ 0, - /* # bytes of config data */ 0); - else - ci = vnet_config_del_feature (vm, vcm, - ci, - lookup_feature_index, - /* config data */ 0, - /* # bytes of config data */ 0); - cm->config_index_by_sw_if_index[sw_if_index] = ci; - } } static clib_error_t * @@ -854,202 +828,140 @@ ip4_add_del_interface_address (vlib_main_t * vm, u32 sw_if_index, } /* Built-in ip4 unicast rx feature path definition */ -VNET_IP4_UNICAST_FEATURE_INIT (ip4_flow_classify, static) = { +VNET_FEATURE_ARC_INIT (ip4_unicast, static) = +{ + .arc_name = "ip4-unicast", + .start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"), + .arc_index_ptr = &ip4_main.lookup_main.ucast_feature_arc_index, +}; + +VNET_FEATURE_INIT (ip4_flow_classify, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-flow-classify", - .runs_before = ORDER_CONSTRAINTS {"ip4-inacl", 0}, - .feature_index = &ip4_main.ip4_unicast_rx_feature_flow_classify, + .runs_before = VNET_FEATURES ("ip4-inacl"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_inacl, static) = { +VNET_FEATURE_INIT (ip4_inacl, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-inacl", - .runs_before = ORDER_CONSTRAINTS {"ip4-source-check-via-rx", 0}, - .feature_index = &ip4_main.ip4_unicast_rx_feature_check_access, + .runs_before = VNET_FEATURES ("ip4-source-check-via-rx"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_source_check_1, static) = { +VNET_FEATURE_INIT (ip4_source_check_1, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-source-check-via-rx", - .runs_before = ORDER_CONSTRAINTS {"ip4-source-check-via-any", 0}, - .feature_index = - &ip4_main.ip4_unicast_rx_feature_source_reachable_via_rx, + .runs_before = VNET_FEATURES ("ip4-source-check-via-any"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_source_check_2, static) = { +VNET_FEATURE_INIT (ip4_source_check_2, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-source-check-via-any", - .runs_before = ORDER_CONSTRAINTS {"ip4-policer-classify", 0}, - .feature_index = - &ip4_main.ip4_unicast_rx_feature_source_reachable_via_any, + .runs_before = VNET_FEATURES ("ip4-policer-classify"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_source_and_port_range_check_rx, static) = { +VNET_FEATURE_INIT (ip4_source_and_port_range_check_rx, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-source-and-port-range-check-rx", - .runs_before = ORDER_CONSTRAINTS {"ip4-policer-classify", 0}, - .feature_index = - &ip4_main.ip4_unicast_rx_feature_source_and_port_range_check, + .runs_before = VNET_FEATURES ("ip4-policer-classify"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_policer_classify, static) = { +VNET_FEATURE_INIT (ip4_policer_classify, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-policer-classify", - .runs_before = ORDER_CONSTRAINTS {"ipsec-input-ip4", 0}, - .feature_index = - &ip4_main.ip4_unicast_rx_feature_policer_classify, + .runs_before = VNET_FEATURES ("ipsec-input-ip4"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_ipsec, static) = { +VNET_FEATURE_INIT (ip4_ipsec, static) = { + .arc_name = "ip4-unicast", .node_name = "ipsec-input-ip4", - .runs_before = ORDER_CONSTRAINTS {"vpath-input-ip4", 0}, - .feature_index = &ip4_main.ip4_unicast_rx_feature_ipsec, + .runs_before = VNET_FEATURES ("vpath-input-ip4"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_vpath, static) = { +VNET_FEATURE_INIT (ip4_vpath, static) = { + .arc_name = "ip4-unicast", .node_name = "vpath-input-ip4", - .runs_before = ORDER_CONSTRAINTS {"ip4-lookup", 0}, - .feature_index = &ip4_main.ip4_unicast_rx_feature_vpath, + .runs_before = VNET_FEATURES ("ip4-lookup"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_lookup, static) = { +VNET_FEATURE_INIT (ip4_lookup, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-lookup", - .runs_before = ORDER_CONSTRAINTS {"ip4-drop", 0}, - .feature_index = &ip4_main.ip4_unicast_rx_feature_lookup, + .runs_before = VNET_FEATURES ("ip4-drop"), }; -VNET_IP4_UNICAST_FEATURE_INIT (ip4_drop, static) = { +VNET_FEATURE_INIT (ip4_drop, static) = { + .arc_name = "ip4-unicast", .node_name = "ip4-drop", .runs_before = 0, /* not before any other features */ - .feature_index = &ip4_main.ip4_unicast_rx_feature_drop, }; /* Built-in ip4 multicast rx feature path definition */ -VNET_IP4_MULTICAST_FEATURE_INIT (ip4_vpath_mc, static) = { +VNET_FEATURE_ARC_INIT (ip4_multicast, static) = +{ + .arc_name = "ip4-multicast", + .start_nodes = VNET_FEATURES ("ip4-input", "ip4-input-no-checksum"), + .arc_index_ptr = &ip4_main.lookup_main.mcast_feature_arc_index, +}; + +VNET_FEATURE_INIT (ip4_vpath_mc, static) = { + .arc_name = "ip4-multicast", .node_name = "vpath-input-ip4", - .runs_before = ORDER_CONSTRAINTS {"ip4-lookup-multicast", 0}, - .feature_index = &ip4_main.ip4_multicast_rx_feature_vpath, + .runs_before = VNET_FEATURES ("ip4-lookup-multicast"), }; -VNET_IP4_MULTICAST_FEATURE_INIT (ip4_lookup_mc, static) = { +VNET_FEATURE_INIT (ip4_lookup_mc, static) = { + .arc_name = "ip4-multicast", .node_name = "ip4-lookup-multicast", - .runs_before = ORDER_CONSTRAINTS {"ip4-drop", 0}, - .feature_index = &ip4_main.ip4_multicast_rx_feature_lookup, + .runs_before = VNET_FEATURES ("ip4-drop"), }; -VNET_IP4_MULTICAST_FEATURE_INIT (ip4_mc_drop, static) = { +VNET_FEATURE_INIT (ip4_mc_drop, static) = { + .arc_name = "ip4-multicast", .node_name = "ip4-drop", .runs_before = 0, /* last feature */ - .feature_index = &ip4_main.ip4_multicast_rx_feature_drop, }; -static char * rx_feature_start_nodes[] = - { "ip4-input", "ip4-input-no-checksum"}; - -static char * tx_feature_start_nodes[] = +/* Source and port-range check ip4 tx feature path definition */ +VNET_FEATURE_ARC_INIT (ip4_output, static) = { - "ip4-rewrite-transit", - "ip4-midchain", + .arc_name = "ip4-output", + .start_nodes = VNET_FEATURES ("ip4-rewrite-transit", "ip4-midchain"), + .arc_index_ptr = &ip4_main.lookup_main.output_feature_arc_index, }; -/* Source and port-range check ip4 tx feature path definition */ -VNET_IP4_TX_FEATURE_INIT (ip4_source_and_port_range_check_tx, static) = { +VNET_FEATURE_INIT (ip4_source_and_port_range_check_tx, static) = { + .arc_name = "ip4-output", .node_name = "ip4-source-and-port-range-check-tx", - .runs_before = ORDER_CONSTRAINTS {"interface-output", 0}, - .feature_index = - &ip4_main.ip4_unicast_tx_feature_source_and_port_range_check, - + .runs_before = VNET_FEATURES ("interface-output"), }; /* Built-in ip4 tx feature path definition */ -VNET_IP4_TX_FEATURE_INIT (interface_output, static) = { +VNET_FEATURE_INIT (ip4_interface_output, static) = { + .arc_name = "ip4-output", .node_name = "interface-output", .runs_before = 0, /* not before any other features */ - .feature_index = &ip4_main.ip4_tx_feature_interface_output, }; -static clib_error_t * -ip4_feature_init (vlib_main_t * vm, ip4_main_t * im) -{ - ip_lookup_main_t * lm = &im->lookup_main; - clib_error_t * error; - vnet_cast_t cast; - vnet_feature_config_main_t * cm; - vnet_config_main_t * vcm; - char **feature_start_nodes; - int feature_start_len; - - for (cast = 0; cast < VNET_N_IP_FEAT; cast++) - { - cm = &lm->feature_config_mains[cast]; - vcm = &cm->config_main; - - if (cast < VNET_IP_TX_FEAT) - { - feature_start_nodes = rx_feature_start_nodes; - feature_start_len = ARRAY_LEN(rx_feature_start_nodes); - } - else - { - feature_start_nodes = tx_feature_start_nodes; - feature_start_len = ARRAY_LEN(tx_feature_start_nodes); - } - - if ((error = vnet_feature_arc_init (vm, vcm, - feature_start_nodes, - feature_start_len, - im->next_feature[cast], - &im->feature_nodes[cast]))) - return error; - } - - return 0; -} static clib_error_t * ip4_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) { - vlib_main_t * vm = vnm->vlib_main; ip4_main_t * im = &ip4_main; - ip_lookup_main_t * lm = &im->lookup_main; - u32 ci, cast; - u32 feature_index; /* Fill in lookup tables with default table (0). */ vec_validate (im->fib_index_by_sw_if_index, sw_if_index); - for (cast = 0; cast < VNET_N_IP_FEAT; cast++) - { - vnet_feature_config_main_t * cm = &lm->feature_config_mains[cast]; - vnet_config_main_t * vcm = &cm->config_main; + vnet_feature_enable_disable ("ip4-unicast", "ip4-drop", sw_if_index, + is_add, 0, 0); - vec_validate_init_empty (cm->config_index_by_sw_if_index, sw_if_index, ~0); - ci = cm->config_index_by_sw_if_index[sw_if_index]; + vnet_feature_enable_disable ("ip4-multicast", "ip4-drop", sw_if_index, + is_add, 0, 0); - if (cast == VNET_IP_RX_UNICAST_FEAT) - feature_index = im->ip4_unicast_rx_feature_drop; - else if (cast == VNET_IP_RX_MULTICAST_FEAT) - feature_index = im->ip4_multicast_rx_feature_drop; - else - feature_index = im->ip4_tx_feature_interface_output; - - if (is_add) - ci = vnet_config_add_feature (vm, vcm, - ci, - feature_index, - /* config data */ 0, - /* # bytes of config data */ 0); - else - { - ci = vnet_config_del_feature (vm, vcm, ci, - feature_index, - /* config data */ 0, - /* # bytes of config data */ 0); - if (vec_len(im->ip_enabled_by_sw_if_index) > sw_if_index) - im->ip_enabled_by_sw_if_index[sw_if_index] = 0; - } - cm->config_index_by_sw_if_index[sw_if_index] = ci; - /* - * note: do not update the tx feature count here. - */ - } + vnet_feature_enable_disable ("ip4-output", "interface-output", sw_if_index, + is_add, 0, 0); return /* no error */ 0; } @@ -1066,6 +978,9 @@ ip4_lookup_init (vlib_main_t * vm) clib_error_t * error; uword i; + if ((error = vlib_call_init_function (vm, vnet_feature_init))) + return error; + for (i = 0; i < ARRAY_LEN (im->fib_masks); i++) { u32 m; @@ -1114,8 +1029,6 @@ ip4_lookup_init (vlib_main_t * vm) "ip4 arp"); } - error = ip4_feature_init (vm, im); - return error; } @@ -2184,7 +2097,6 @@ ip4_rewrite_inline (vlib_main_t * vm, u32 n_left_from, n_left_to_next, * to_next, next_index; vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip4_input_node.index); vlib_rx_or_tx_t adj_rx_tx = rewrite_for_locally_received_packets ? VLIB_RX : VLIB_TX; - vnet_feature_config_main_t * cm = &lm->feature_config_mains[VNET_IP_TX_FEAT]; n_left_from = frame->n_vectors; next_index = node->cached_next_index; @@ -2362,18 +2274,8 @@ ip4_rewrite_inline (vlib_main_t * vm, vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0; - if (PREDICT_FALSE - (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features, - tx_sw_if_index0))) - { - p0->current_config_index = - vec_elt (cm->config_index_by_sw_if_index, - tx_sw_if_index0); - vnet_get_config_data (&cm->config_main, - &p0->current_config_index, - &next0, - /* # bytes of config data */ 0); - } + vnet_feature_arc_start(lm->output_feature_arc_index, + tx_sw_if_index0, &next0, p0); } if (PREDICT_TRUE(error1 == IP4_ERROR_NONE)) { @@ -2384,18 +2286,8 @@ ip4_rewrite_inline (vlib_main_t * vm, vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1; - if (PREDICT_FALSE - (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features, - tx_sw_if_index1))) - { - p1->current_config_index = - vec_elt (cm->config_index_by_sw_if_index, - tx_sw_if_index1); - vnet_get_config_data (&cm->config_main, - &p1->current_config_index, - &next1, - /* # bytes of config data */ 0); - } + vnet_feature_arc_start(lm->output_feature_arc_index, + tx_sw_if_index1, &next1, p1); } /* Guess we are only writing on simple Ethernet header. */ @@ -2525,18 +2417,9 @@ ip4_rewrite_inline (vlib_main_t * vm, adj0->sub_type.midchain.fixup_func(vm, adj0, p0); } - if (PREDICT_FALSE - (clib_bitmap_get (lm->tx_sw_if_has_ip_output_features, - tx_sw_if_index0))) - { - p0->current_config_index = - vec_elt (cm->config_index_by_sw_if_index, - tx_sw_if_index0); - vnet_get_config_data (&cm->config_main, - &p0->current_config_index, - &next0, - /* # bytes of config data */ 0); - } + vnet_feature_arc_start(lm->output_feature_arc_index, + tx_sw_if_index0, &next0, p0); + } if (rewrite_for_locally_received_packets) |