diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -785,7 +785,7 @@ int op_flags, struct rib_cmd_info *rc) { struct route_nhop_data rnd_orig; - struct nhop_object *nh; + struct nhop_object *nh, *nh_orig; struct rtentry *rt_orig; int error = 0; @@ -829,6 +829,23 @@ goto out; } + nh_orig = rt_orig->rt_nhop; + /* + * For append or create, if both rt have gateway flag and they gw addrs + * are the same, they actually are the same route. We can either return + * existing erro or change to do replace that can save the new property. + * Here we prefer to return error and ignore the property change, + * because it can inform the caller error, if he want to change the + * existing route propery, he should select RTM_REPLACE op_flag + */ + if ((nh->nh_flags & NHF_GATEWAY) && + (nh_orig->nh_flags & NHF_GATEWAY) && + match_nhop_gw(nh, &rt_orig->rt_nhop->gw_sa)) { + RIB_WUNLOCK(rnh); + error = EEXIST; + goto out; + } + RIB_WUNLOCK(rnh); #ifdef ROUTE_MPATH