Bug 258447

Summary: add! no longer works in PPP the way its described
Product: Base System Reporter: mike
Component: binAssignee: Alexander V. Chernikov <melifaro>
Status: New ---    
Severity: Affects Some People CC: avg, freebsd, melifaro, pi, zlei
Priority: ---    
Version: 13.0-STABLE   
Hardware: Any   
OS: Any   

Description mike 2021-09-12 11:54:10 UTC
With multipath enabled in RELENG_13 by default, I noticed that using my ppp scripts from previous releases no longer work as expected. In the past and according to the documentation, 

         If the add! command is used (note the trailing “!”), then if the
         route already exists, it will be updated as with the ‘route change’
         command (see route(8) for further details).

This instead adds an additional route to the FIB instead of overwriting the old one

eg
default            10.255.255.1       UGS         6   1500       igb0
default            10.1.0.1           UGS        17   1500      tun10 

setting 
net.route.multipath=0
restores the behaviour as described in the man pages
Comment 1 Zhenlei Huang freebsd_committer freebsd_triage 2023-02-24 15:51:44 UTC
Looked into the code usr.sbin/ppp/route.c, the `add! default HISADDR` logic relies on errno EEXIST when adding routes.

> 818 failed:
> 819     if (cmd == RTM_ADD && (rtmes.m_rtm.rtm_errno == EEXIST ||
> 820                            (rtmes.m_rtm.rtm_errno == 0 && errno == EEXIST))) {
> 821       if (!bang) {
> 822         log_Printf(LogWARN, "Add route failed: %s already exists\n",
> 823                    ncprange_ntoa(dst));
> 824         result = 0;     /* Don't add to our dynamic list */
> 825       } else {
> 826         rtmes.m_rtm.rtm_type = cmd = RTM_CHANGE;
> 827         if ((wb = ID0write(s, &rtmes, nb)) < 0)
> 828           goto failed;
> 829       }
> 830     }

When multipath is enabled, `RTM_ADD` will succeed even there's already existing route entry.
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2023-02-24 15:55:07 UTC
I wonder if there is a way to preserve the historic behavior for ppp without disabling multipath globally.
Comment 3 mike 2023-02-24 15:58:19 UTC
(In reply to Andriy Gapon from comment #2)

Not sure how as multipath really changes things. To be honest, with multipath available, its reasonable to expect a little POLA violation here. I think updating the documentation to reflect the new reality and maybe an UPDATING entry as well. I think ultimately adding ppp documentation to show how to get the old behavior with and without disabling multipath is the best way forward