Skip to content

Commit e23a287

Browse files
committed
Add sonic_fib_init plugin
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
1 parent 6563036 commit e23a287

7 files changed

Lines changed: 241 additions & 0 deletions

File tree

docker-sonic-vpp/conf/startup.conf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ plugins {
247247
plugin vxlan_plugin.so { enable }
248248
plugin tunterm_acl_plugin.so { enable }
249249
plugin ip_validate_plugin.so { enable }
250+
plugin sonic_fib_init_plugin.so { enable }
250251
251252
## Enable all plugins by default and then selectively disable specific plugins
252253
# plugin dpdk_plugin.so { disable }

docker-syncd-vpp/conf/startup.conf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ plugins {
235235
plugin vxlan_plugin.so { enable }
236236
plugin tunterm_acl_plugin.so { enable }
237237
plugin ip_validate_plugin.so { enable }
238+
plugin sonic_fib_init_plugin.so { enable }
238239
239240
## Enable all plugins by default and then selectively disable specific plugins
240241
# plugin dpdk_plugin.so { disable }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2026 Microsoft and/or its affiliates.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at:
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
add_vpp_plugin(sonic_fib_init
15+
SOURCES
16+
sonic_fib_init.c
17+
18+
API_FILES
19+
sonic_fib_init.api
20+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: SONiC FIB Init
3+
maintainer: Longxiang Lyu <lolv@microsoft.com>
4+
features:
5+
- Removes the built-in FIB_SOURCE_SPECIAL drop entry for
6+
240.0.0.0/4 (IPv4 class E reserved range) from the default
7+
IPv4 FIB at VPP startup so that SONiC-installed routes win the
8+
longest-prefix match instead of the hard-coded VPP drop.
9+
- Exposes a `sonic_fib_strip_specials { vrf_id }` binary API for
10+
the SAI shim to invoke after creating additional IPv4 VRFs, so
11+
the same cleanup is applied to user-created tables.
12+
description: "SONiC-specific FIB initialization adjustments"
13+
state: experimental
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
option version = "1.0.0";
17+
18+
/** \brief Strip the built-in FIB_SOURCE_SPECIAL drop entries that the
19+
plugin manages from the IPv4 FIB identified by vrf_id (table_id).
20+
21+
This is intended to be called by the SAI shim immediately after
22+
creating a VPP IPv4 FIB table (SAI virtual_router create) so that
23+
SONiC-installed routes are not pre-empted by the hard-coded VPP
24+
drop entries (currently 240.0.0.0/4).
25+
26+
@param client_index - opaque cookie to identify the sender
27+
@param context - sender context, to match reply w/ request
28+
@param vrf_id - the IPv4 table_id whose specials should be
29+
stripped (0 == default VRF)
30+
*/
31+
autoreply define sonic_fib_strip_specials
32+
{
33+
u32 client_index;
34+
u32 context;
35+
u32 vrf_id;
36+
};
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
#ifndef __included_sonic_fib_init_h__
16+
#define __included_sonic_fib_init_h__
17+
18+
#include <vnet/vnet.h>
19+
20+
typedef struct
21+
{
22+
/* API message ID base */
23+
u16 msg_id_base;
24+
} sonic_fib_init_main_t;
25+
26+
extern sonic_fib_init_main_t sonic_fib_init_main;
27+
28+
#define SONIC_FIB_INIT_PLUGIN_BUILD_VER "1.0"
29+
30+
#endif /* __included_sonic_fib_init_h__ */

0 commit comments

Comments
 (0)