|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Microsoft 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 | + * sonic_fib_init: remove built-in FIB_SOURCE_SPECIAL drop entries that |
| 18 | + * conflict with SONiC datapath expectations. |
| 19 | + * |
| 20 | + * Background |
| 21 | + * ---------- |
| 22 | + * VPP installs hard-coded drop entries into every IPv4 FIB at creation |
| 23 | + * time (see src/vnet/fib/ip4_fib.c :: ip4_specials[]). One of them is |
| 24 | + * 240.0.0.0/4 (the IPv4 "class E reserved" range) installed with |
| 25 | + * FIB_SOURCE_SPECIAL + FIB_ENTRY_FLAG_DROP. FIB_SOURCE_SPECIAL is the |
| 26 | + * highest-priority FIB source (FIB_SOURCE_FIRST in fib_source.h) and |
| 27 | + * cannot be overridden via the FIB API or `ip route` CLI. |
| 28 | + * |
| 29 | + * Forwarding decisions for these address ranges should be governed by |
| 30 | + * the routes SONiC programs into the FIB, not by a hard-coded drop in |
| 31 | + * VPP. Other SONiC platforms (BCM, MLNX) do not impose this filter, so |
| 32 | + * we strip the SPECIAL drop here to maintain cross-platform parity and |
| 33 | + * let SONiC-installed routes win the longest-prefix match. |
| 34 | + * |
| 35 | + * Implementation |
| 36 | + * -------------- |
| 37 | + * fib_table_entry_special_remove() is C-only (not exposed by VPP's |
| 38 | + * built-in binary API), so the cleanup must run from inside VPP. |
| 39 | + * |
| 40 | + * - The default VRF (fib 0) is created during VPP startup before any |
| 41 | + * external client connects, so we strip its SPECIAL drop once via |
| 42 | + * VLIB_MAIN_LOOP_ENTER_FUNCTION (after all VLIB_INIT_FUNCTIONs, so |
| 43 | + * the FIB and its SPECIAL entry are already in place). |
| 44 | + * |
| 45 | + * - For VRFs created at runtime (SAI virtual_router create routed |
| 46 | + * through the SAI shim's `ip_table_add_del`), the shim invokes our |
| 47 | + * `sonic_fib_strip_specials` binary API immediately after the table |
| 48 | + * is created. The handler looks up the fib_index for the requested |
| 49 | + * table_id and removes the SPECIAL drop. |
| 50 | + * |
| 51 | + * Note on 224.0.0.0/4: the matching multicast drop entry is left |
| 52 | + * intact intentionally; SONiC does not currently require forwarding |
| 53 | + * into that range and removing it could affect IGMP/PIM behaviour. |
| 54 | + */ |
| 55 | + |
| 56 | +#include <vnet/vnet.h> |
| 57 | +#include <vnet/plugin/plugin.h> |
| 58 | +#include <vnet/fib/fib_table.h> |
| 59 | +#include <vpp/app/version.h> |
| 60 | + |
| 61 | +#include <sonic_fib_init/sonic_fib_init.h> |
| 62 | + |
| 63 | +#include <vlibapi/api.h> |
| 64 | +#include <vlibmemory/api.h> |
| 65 | + |
| 66 | +#include <sonic_fib_init/sonic_fib_init.api_enum.h> |
| 67 | +#include <sonic_fib_init/sonic_fib_init.api_types.h> |
| 68 | + |
| 69 | +#define REPLY_MSG_ID_BASE sm->msg_id_base |
| 70 | +#include <vlibapi/api_helper_macros.h> |
| 71 | + |
| 72 | +VLIB_PLUGIN_REGISTER () = { |
| 73 | + .version = SONIC_FIB_INIT_PLUGIN_BUILD_VER, |
| 74 | + .description = "SONiC FIB init: remove implicit class-E drop", |
| 75 | +}; |
| 76 | + |
| 77 | +sonic_fib_init_main_t sonic_fib_init_main; |
| 78 | + |
| 79 | +static void |
| 80 | +sonic_fib_init_strip_v4 (u32 fib_index) |
| 81 | +{ |
| 82 | + fib_prefix_t pfx; |
| 83 | + |
| 84 | + /* IPv4: 240.0.0.0/4 (class E reserved) -- drop installed by |
| 85 | + * ip4_fib_hash_load_specials() with FIB_SOURCE_SPECIAL. */ |
| 86 | + clib_memset (&pfx, 0, sizeof (pfx)); |
| 87 | + pfx.fp_proto = FIB_PROTOCOL_IP4; |
| 88 | + pfx.fp_len = 4; |
| 89 | + pfx.fp_addr.ip4.data_u32 = clib_host_to_net_u32 (0xf0000000); |
| 90 | + fib_table_entry_special_remove (fib_index, &pfx, FIB_SOURCE_SPECIAL); |
| 91 | +} |
| 92 | + |
| 93 | +static void |
| 94 | +vl_api_sonic_fib_strip_specials_t_handler ( |
| 95 | + vl_api_sonic_fib_strip_specials_t *mp) |
| 96 | +{ |
| 97 | + sonic_fib_init_main_t *sm = &sonic_fib_init_main; |
| 98 | + vl_api_sonic_fib_strip_specials_reply_t *rmp; |
| 99 | + int rv = 0; |
| 100 | + u32 vrf_id = ntohl (mp->vrf_id); |
| 101 | + u32 fib_index; |
| 102 | + |
| 103 | + fib_index = fib_table_find (FIB_PROTOCOL_IP4, vrf_id); |
| 104 | + if (fib_index == ~0) |
| 105 | + { |
| 106 | + rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 107 | + goto done; |
| 108 | + } |
| 109 | + |
| 110 | + sonic_fib_init_strip_v4 (fib_index); |
| 111 | + |
| 112 | +done: |
| 113 | + REPLY_MACRO (VL_API_SONIC_FIB_STRIP_SPECIALS_REPLY); |
| 114 | +} |
| 115 | + |
| 116 | +/* API definitions */ |
| 117 | +#include <sonic_fib_init/sonic_fib_init.api.c> |
| 118 | + |
| 119 | +static clib_error_t * |
| 120 | +sonic_fib_init_init (vlib_main_t *vm) |
| 121 | +{ |
| 122 | + sonic_fib_init_main_t *sm = &sonic_fib_init_main; |
| 123 | + |
| 124 | + sm->msg_id_base = setup_message_id_table (); |
| 125 | + |
| 126 | + return 0; |
| 127 | +} |
| 128 | + |
| 129 | +VLIB_INIT_FUNCTION (sonic_fib_init_init); |
| 130 | + |
| 131 | +static clib_error_t * |
| 132 | +sonic_fib_init_main_loop_enter (vlib_main_t *vm) |
| 133 | +{ |
| 134 | + /* fib 0 is the default VRF, created during VPP startup. Additional |
| 135 | + * VRFs are handled via the sonic_fib_strip_specials API. */ |
| 136 | + sonic_fib_init_strip_v4 (0); |
| 137 | + return 0; |
| 138 | +} |
| 139 | + |
| 140 | +VLIB_MAIN_LOOP_ENTER_FUNCTION (sonic_fib_init_main_loop_enter); |
0 commit comments