@@ -29,6 +29,8 @@ typedef struct {
2929 const struct sockaddr * sa_remote ;
3030 int if_index ;
3131 int found ;
32+ int allow_default_gw ; /* Allow matching default
33+ gateway routes */
3234} ucs_netlink_route_info_t ;
3335
3436
@@ -248,6 +250,7 @@ static void ucs_netlink_lookup_route(ucs_netlink_route_info_t *info)
248250{
249251 ucs_netlink_rt_rules_t * iface_rules ;
250252 ucs_netlink_route_entry_t * curr_entry ;
253+ int is_default_gw ;
251254 khiter_t iter ;
252255
253256 iter = kh_get (ucs_netlink_rt_cache , & ucs_netlink_routing_table_cache ,
@@ -259,8 +262,17 @@ static void ucs_netlink_lookup_route(ucs_netlink_route_info_t *info)
259262
260263 iface_rules = & kh_val (& ucs_netlink_routing_table_cache , iter );
261264 ucs_array_for_each (curr_entry , iface_rules ) {
262- if ((curr_entry -> subnet_prefix_len == 0 ) ||
263- ucs_sockaddr_is_same_subnet (
265+ is_default_gw = (curr_entry -> subnet_prefix_len == 0 );
266+
267+ /* Skip default gateway routes if not allowed (e.g., for
268+ IPoIB remote devices) */
269+ if (is_default_gw && !info -> allow_default_gw ) {
270+ ucs_trace ("iface_index=%d: skipping default gateway route" ,
271+ info -> if_index );
272+ continue ;
273+ }
274+
275+ if (is_default_gw || ucs_sockaddr_is_same_subnet (
264276 info -> sa_remote ,
265277 (const struct sockaddr * )& curr_entry -> dest ,
266278 curr_entry -> subnet_prefix_len )) {
@@ -270,7 +282,8 @@ static void ucs_netlink_lookup_route(ucs_netlink_route_info_t *info)
270282 }
271283}
272284
273- int ucs_netlink_route_exists (int if_index , const struct sockaddr * sa_remote )
285+ int ucs_netlink_route_exists (int if_index , const struct sockaddr * sa_remote ,
286+ int allow_default_gw )
274287{
275288 static ucs_init_once_t init_once = UCS_INIT_ONCE_INITIALIZER ;
276289 struct rtmsg rtm = {0 };
@@ -289,10 +302,18 @@ int ucs_netlink_route_exists(int if_index, const struct sockaddr *sa_remote)
289302 NULL );
290303 }
291304
292- info .if_index = if_index ;
293- info .sa_remote = sa_remote ;
294- info .found = 0 ;
305+ info .if_index = if_index ;
306+ info .sa_remote = sa_remote ;
307+ info .found = 0 ;
308+ info .allow_default_gw = allow_default_gw ;
309+
295310 ucs_netlink_lookup_route (& info );
296311
297312 return info .found ;
298313}
314+
315+ int ucs_netlink_ethernet_device_route_exists (int if_index ,
316+ const struct sockaddr * sa_remote )
317+ {
318+ return ucs_netlink_route_exists (if_index , sa_remote , 1 );
319+ }
0 commit comments