route warning

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

route warning

Julien Dhaille
Hi,

when a default gateway is not set :

# route get 4.4.4.4
route: writing to routing socket: No such process

this small patch uses oerrno translation :

# route get 4.4.4.4
get host 4.4.4.4: not in table

Index: route.c
===================================================================
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.203
diff -u -p -r1.203 route.c
--- route.c     6 Sep 2017 20:21:22 -0000       1.203
+++ route.c     11 Oct 2017 22:05:22 -0000
@@ -676,8 +676,7 @@ newroute(int argc, char **argv)
        }
        if (*cmd == 'g') {
                if (ret != 0 && qflag == 0)
-                       warn("writing to routing socket");
-               exit(0);
+                       oerrno = ESRCH;
        }
        oerrno = errno;
        if (!qflag) {

Reply | Threaded
Open this post in threaded view
|

Re: route warning

Martin Pieuchot
On 12/10/17(Thu) 00:22, Julien Dhaille wrote:

> Hi,
>
> when a default gateway is not set :
>
> # route get 4.4.4.4
> route: writing to routing socket: No such process
>
> this small patch uses oerrno translation :
>
> # route get 4.4.4.4
> get host 4.4.4.4: not in table

Nice, but there's no need to set oerrno, the line just below will do it.

Removing the if () block should do it.  It introduces a small change in
behavior, route(8) now exists with an error code if an entry doesn't
exist in the table.  That's a good thing, because one can now test if a
route is reachable by doing:

route -nq get 4.4.4.4 && echo "present"

Index: route.c
===================================================================
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.203
diff -u -p -r1.203 route.c
--- route.c 6 Sep 2017 20:21:22 -0000 1.203
+++ route.c 16 Oct 2017 11:14:49 -0000
@@ -674,11 +674,6 @@ newroute(int argc, char **argv)
  } else
  break;
  }
- if (*cmd == 'g') {
- if (ret != 0 && qflag == 0)
- warn("writing to routing socket");
- exit(0);
- }
  oerrno = errno;
  if (!qflag) {
  printf("%s %s %s", cmd, ishost ? "host" : "net", dest);

Reply | Threaded
Open this post in threaded view
|

Re: route warning

Alexander Bluhm
On Mon, Oct 16, 2017 at 01:18:27PM +0200, Martin Pieuchot wrote:
> Removing the if () block should do it.  It introduces a small change in
> behavior, route(8) now exists with an error code if an entry doesn't
> exist in the table.  That's a good thing, because one can now test if a
> route is reachable by doing:
>
> route -nq get 4.4.4.4 && echo "present"

OK bluhm@

> Index: route.c
> ===================================================================
> RCS file: /cvs/src/sbin/route/route.c,v
> retrieving revision 1.203
> diff -u -p -r1.203 route.c
> --- route.c 6 Sep 2017 20:21:22 -0000 1.203
> +++ route.c 16 Oct 2017 11:14:49 -0000
> @@ -674,11 +674,6 @@ newroute(int argc, char **argv)
>   } else
>   break;
>   }
> - if (*cmd == 'g') {
> - if (ret != 0 && qflag == 0)
> - warn("writing to routing socket");
> - exit(0);
> - }
>   oerrno = errno;
>   if (!qflag) {
>   printf("%s %s %s", cmd, ishost ? "host" : "net", dest);

Reply | Threaded
Open this post in threaded view
|

Re: route warning

Alexander Bluhm
In reply to this post by Martin Pieuchot
On Mon, Oct 16, 2017 at 01:18:27PM +0200, Martin Pieuchot wrote:
> Removing the if () block should do it.

This diff is not quite right.  /usr/src/regress/sbin/route rttest20
shows that there is an additional

+get net 2001:ee0:2001:c0::/64

each time you call route get.  You only want such a line in case of
an error.

ok?

bluhm

Index: route.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sbin/route/route.c,v
retrieving revision 1.204
diff -u -p -r1.204 route.c
--- route.c 16 Oct 2017 13:28:33 -0000 1.204
+++ route.c 17 Oct 2017 18:01:18 -0000
@@ -675,7 +675,7 @@ newroute(int argc, char **argv)
  break;
  }
  oerrno = errno;
- if (!qflag) {
+ if (!qflag && (*cmd != 'g' || oerrno)) {
  printf("%s %s %s", cmd, ishost ? "host" : "net", dest);
  if (*gateway) {
  printf(": gateway %s", gateway);