diff options
author | brian <brian@cvs.openbsd.org> | 1997-12-30 02:45:08 +0000 |
---|---|---|
committer | brian <brian@cvs.openbsd.org> | 1997-12-30 02:45:08 +0000 |
commit | 2ef1dd7773d62204dd537b55c3b54c4cea9c9286 (patch) | |
tree | a18177fbfe998614449f75f629103c0848dc1fd3 /usr.sbin | |
parent | d2e4c03c9afa5edab347e7b8547f8394e284bab4 (diff) |
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/command.c | 14 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 24 | ||||
-rw-r--r-- | usr.sbin/ppp/route.c | 46 | ||||
-rw-r--r-- | usr.sbin/ppp/route.h | 4 |
4 files changed, 59 insertions, 29 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 64eca882eb5..e06e457f7b1 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -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.16 1997/12/29 22:23:04 brian Exp $ + * $Id: command.c,v 1.17 1997/12/30 02:45:05 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; diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index af5f19c2777..770dccfb3fd 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.11 1997/12/27 07:22:17 brian Exp $ +.\" $Id: ppp.8,v 1.12 1997/12/30 02:45:06 brian Exp $ .Dd 20 September 1995 .Os OpenBSD .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 , diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c index 1c796a6d5ac..97b2f717909 100644 --- a/usr.sbin/ppp/route.c +++ b/usr.sbin/ppp/route.c @@ -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.10 1997/12/27 19:22:28 brian Exp $ + * $Id: route.c,v 1.11 1997/12/30 02:45:06 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 diff --git a/usr.sbin/ppp/route.h b/usr.sbin/ppp/route.h index 407ec1307ee..7d12f2ff428 100644 --- a/usr.sbin/ppp/route.h +++ b/usr.sbin/ppp/route.h @@ -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.2 1997/12/15 22:44:58 brian Exp $ + * $Id: route.h,v 1.3 1997/12/30 02:45:07 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); |