mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Allow "add! dst mask gw" (note the ``!'') to do an
RTM_CHANGE if the RTM_ADD fails with an EEXIST. Allow "delete! dst" (note the ``!'') to silently fail if the RTM_DELETE fails with an ESRCH. Also, make the ESRCH and EEXIST error conditions more understandable to the casual observer.
This commit is contained in:
parent
0e604e984a
commit
65eea2e0fa
5 changed files with 80 additions and 32 deletions
|
|
@ -17,7 +17,7 @@
|
|||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.c,v 1.120 1997/12/27 13:45:45 brian Exp $
|
||||
* $Id: command.c,v 1.121 1997/12/29 22:23:10 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
|
|
@ -345,7 +345,9 @@ static struct cmdtab const Commands[] = {
|
|||
{"accept", NULL, AcceptCommand, LOCAL_AUTH,
|
||||
"accept option request", "accept option .."},
|
||||
{"add", NULL, AddCommand, LOCAL_AUTH,
|
||||
"add route", "add dest mask gateway"},
|
||||
"add route", "add dest mask gateway", NULL},
|
||||
{"add!", NULL, AddCommand, LOCAL_AUTH,
|
||||
"add or change route", "add! dest mask gateway", (void *)1},
|
||||
{"allow", "auth", AllowCommand, LOCAL_AUTH,
|
||||
"Allow ppp access", "allow users|modes ...."},
|
||||
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
|
||||
|
|
@ -353,7 +355,9 @@ static struct cmdtab const Commands[] = {
|
|||
{"close", NULL, CloseCommand, LOCAL_AUTH,
|
||||
"Close connection", "close"},
|
||||
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
|
||||
"delete route", "delete dest"},
|
||||
"delete route", "delete dest", NULL},
|
||||
{"delete!", NULL, DeleteCommand, LOCAL_AUTH,
|
||||
"delete a route if it exists", "delete! dest", (void *)1},
|
||||
{"deny", NULL, DenyCommand, LOCAL_AUTH,
|
||||
"Deny option request", "deny option .."},
|
||||
{"dial", "call", DialCommand, LOCAL_AUTH,
|
||||
|
|
@ -1528,7 +1532,7 @@ AddCommand(struct cmdargs const *arg)
|
|||
gateway.s_addr = INADDR_ANY;
|
||||
else
|
||||
gateway = GetIpAddr(arg->argv[gw]);
|
||||
OsSetRoute(RTM_ADD, dest, gateway, netmask);
|
||||
OsSetRoute(RTM_ADD, dest, gateway, netmask, arg->data ? 1 : 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1548,7 +1552,7 @@ DeleteCommand(struct cmdargs const *arg)
|
|||
else
|
||||
dest = GetIpAddr(arg->argv[0]);
|
||||
none.s_addr = INADDR_ANY;
|
||||
OsSetRoute(RTM_DELETE, dest, none, none);
|
||||
OsSetRoute(RTM_DELETE, dest, none, none, arg->data ? 1 : 0);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
.\" $Id: ppp.8,v 1.90 1997/12/21 03:16:14 brian Exp $
|
||||
.\" $Id: ppp.8,v 1.91 1997/12/27 07:22:12 brian Exp $
|
||||
.Dd 20 September 1995
|
||||
.Os FreeBSD
|
||||
.Dt PPP 8
|
||||
|
|
@ -1557,7 +1557,7 @@ not to make any utmp or wtmp entries. This is usually only necessary if
|
|||
you require the user to both login and authenticate themselves.
|
||||
.El
|
||||
.Pp
|
||||
.It add dest mask gateway
|
||||
.It add[!] dest mask gateway
|
||||
.Ar Dest
|
||||
is the destination IP address and
|
||||
.Ar mask
|
||||
|
|
@ -1586,6 +1586,16 @@ is replaced with the current interface address. If the current interface
|
|||
address has not yet been assigned, the current
|
||||
.Sq INTERFACE
|
||||
is used instead.
|
||||
.Pp
|
||||
If the
|
||||
.Ar add!
|
||||
command is used
|
||||
.Pq note the following Dq \&! ,
|
||||
then if the route already exists, it will be updated as with the
|
||||
.Sq route change
|
||||
command (see
|
||||
.Xr route 8
|
||||
for further details).
|
||||
.It allow .....
|
||||
This command controls access to
|
||||
.Nm
|
||||
|
|
@ -1717,7 +1727,7 @@ while the command executes, use the
|
|||
command instead.
|
||||
.It close
|
||||
Close the current connection (but don't quit).
|
||||
.It delete dest
|
||||
.It delete[!] dest
|
||||
This command deletes the route with the given
|
||||
.Ar dest
|
||||
IP address. If
|
||||
|
|
@ -1732,6 +1742,13 @@ representing the actual link. If
|
|||
is specified as
|
||||
.Sq default ,
|
||||
the default route is deleted.
|
||||
.Pp
|
||||
If the
|
||||
.Ar delete!
|
||||
command is used
|
||||
.Pq note the following Dq \&! ,
|
||||
.Nm
|
||||
will not complain if the route does not already exist.
|
||||
.It dial|call [remote]
|
||||
If
|
||||
.Dq remote
|
||||
|
|
@ -2403,6 +2420,7 @@ Get port number if port number is using service name.
|
|||
.Xr ping 8 ,
|
||||
.Xr pppctl 8 ,
|
||||
.Xr pppd 8 ,
|
||||
.Xr route 8 ,
|
||||
.Xr syslog 3 ,
|
||||
.Xr syslog.conf 5 ,
|
||||
.Xr syslogd 8 ,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
.\" $Id: ppp.8,v 1.90 1997/12/21 03:16:14 brian Exp $
|
||||
.\" $Id: ppp.8,v 1.91 1997/12/27 07:22:12 brian Exp $
|
||||
.Dd 20 September 1995
|
||||
.Os FreeBSD
|
||||
.Dt PPP 8
|
||||
|
|
@ -1557,7 +1557,7 @@ not to make any utmp or wtmp entries. This is usually only necessary if
|
|||
you require the user to both login and authenticate themselves.
|
||||
.El
|
||||
.Pp
|
||||
.It add dest mask gateway
|
||||
.It add[!] dest mask gateway
|
||||
.Ar Dest
|
||||
is the destination IP address and
|
||||
.Ar mask
|
||||
|
|
@ -1586,6 +1586,16 @@ is replaced with the current interface address. If the current interface
|
|||
address has not yet been assigned, the current
|
||||
.Sq INTERFACE
|
||||
is used instead.
|
||||
.Pp
|
||||
If the
|
||||
.Ar add!
|
||||
command is used
|
||||
.Pq note the following Dq \&! ,
|
||||
then if the route already exists, it will be updated as with the
|
||||
.Sq route change
|
||||
command (see
|
||||
.Xr route 8
|
||||
for further details).
|
||||
.It allow .....
|
||||
This command controls access to
|
||||
.Nm
|
||||
|
|
@ -1717,7 +1727,7 @@ while the command executes, use the
|
|||
command instead.
|
||||
.It close
|
||||
Close the current connection (but don't quit).
|
||||
.It delete dest
|
||||
.It delete[!] dest
|
||||
This command deletes the route with the given
|
||||
.Ar dest
|
||||
IP address. If
|
||||
|
|
@ -1732,6 +1742,13 @@ representing the actual link. If
|
|||
is specified as
|
||||
.Sq default ,
|
||||
the default route is deleted.
|
||||
.Pp
|
||||
If the
|
||||
.Ar delete!
|
||||
command is used
|
||||
.Pq note the following Dq \&! ,
|
||||
.Nm
|
||||
will not complain if the route does not already exist.
|
||||
.It dial|call [remote]
|
||||
If
|
||||
.Dq remote
|
||||
|
|
@ -2403,6 +2420,7 @@ Get port number if port number is using service name.
|
|||
.Xr ping 8 ,
|
||||
.Xr pppctl 8 ,
|
||||
.Xr pppd 8 ,
|
||||
.Xr route 8 ,
|
||||
.Xr syslog 3 ,
|
||||
.Xr syslog.conf 5 ,
|
||||
.Xr syslogd 8 ,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.c,v 1.36 1997/12/27 13:45:57 brian Exp $
|
||||
* $Id: route.c,v 1.37 1997/12/27 19:23:13 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
@ -67,7 +67,8 @@ void
|
|||
OsSetRoute(int cmd,
|
||||
struct in_addr dst,
|
||||
struct in_addr gateway,
|
||||
struct in_addr mask)
|
||||
struct in_addr mask,
|
||||
int bang)
|
||||
{
|
||||
struct rtmsg rtmes;
|
||||
int s, nb, wb;
|
||||
|
|
@ -75,7 +76,10 @@ OsSetRoute(int cmd,
|
|||
const char *cmdstr;
|
||||
struct sockaddr_in rtdata;
|
||||
|
||||
cmdstr = (cmd == RTM_ADD ? "Add" : "Delete");
|
||||
if (bang)
|
||||
cmdstr = (cmd == RTM_ADD ? "Add!" : "Delete!");
|
||||
else
|
||||
cmdstr = (cmd == RTM_ADD ? "Add" : "Delete");
|
||||
s = ID0socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OsSetRoute: socket(): %s\n", strerror(errno));
|
||||
|
|
@ -145,25 +149,29 @@ OsSetRoute(int cmd,
|
|||
LogPrintf(LogTCPIP, "OsSetRoute: Dst = %s\n", inet_ntoa(dst));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Gateway = %s\n", inet_ntoa(gateway));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Mask = %s\n", inet_ntoa(mask));
|
||||
switch (rtmes.m_rtm.rtm_errno) {
|
||||
case EEXIST:
|
||||
LogPrintf(LogWARN, "Add route failed: %s already exists\n",
|
||||
inet_ntoa(dst));
|
||||
break;
|
||||
case ESRCH:
|
||||
LogPrintf(LogWARN, "Del route failed: %s: Non-existent\n",
|
||||
inet_ntoa(dst));
|
||||
break;
|
||||
case 0:
|
||||
failed:
|
||||
if (cmd == RTM_ADD && (rtmes.m_rtm.rtm_errno == EEXIST ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == EEXIST)))
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Add route failed: %s already exists\n",
|
||||
inet_ntoa(dst));
|
||||
else {
|
||||
rtmes.m_rtm.rtm_type = cmd = RTM_CHANGE;
|
||||
if ((wb = ID0write(s, &rtmes, nb)) < 0)
|
||||
goto failed;
|
||||
}
|
||||
else if (cmd == RTM_DELETE &&
|
||||
(rtmes.m_rtm.rtm_errno == ESRCH ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == ESRCH))) {
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Del route failed: %s: Non-existent\n",
|
||||
inet_ntoa(dst));
|
||||
} else if (rtmes.m_rtm.rtm_errno == 0)
|
||||
LogPrintf(LogWARN, "%s route failed: %s: errno: %s\n", cmdstr,
|
||||
inet_ntoa(dst), strerror(errno));
|
||||
break;
|
||||
case ENOBUFS:
|
||||
default:
|
||||
else
|
||||
LogPrintf(LogWARN, "%s route failed: %s: %s\n",
|
||||
cmdstr, inet_ntoa(dst), strerror(rtmes.m_rtm.rtm_errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
LogPrintf(LogDEBUG, "wrote %d: cmd = %s, dst = %x, gateway = %x\n",
|
||||
wb, cmdstr, dst.s_addr, gateway.s_addr);
|
||||
|
|
@ -502,7 +510,7 @@ DeleteIfRoutes(int all)
|
|||
if ((pass == 0 && (rtm->rtm_flags & RTF_WASCLONED)) ||
|
||||
(pass == 1 && !(rtm->rtm_flags & RTF_WASCLONED))) {
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Remove it (pass %d)\n", pass);
|
||||
OsSetRoute(RTM_DELETE, sa_dst, sa_none, sa_none);
|
||||
OsSetRoute(RTM_DELETE, sa_dst, sa_none, sa_none, 0);
|
||||
} else
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Skip it (pass %d)\n", pass);
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@
|
|||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.h,v 1.7 1997/11/22 03:37:45 brian Exp $
|
||||
* $Id: route.h,v 1.8 1997/12/13 02:37:32 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
extern int GetIfIndex(char *);
|
||||
extern int ShowRoute(struct cmdargs const *);
|
||||
extern void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr);
|
||||
extern void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr,int);
|
||||
extern void DeleteIfRoutes(int);
|
||||
extern struct in_addr ChooseHisAddr(const struct in_addr);
|
||||
|
|
|
|||
Loading…
Reference in a new issue