Adjust sourceaddr argument parser.
authorclaudio <claudio@openbsd.org>
Fri, 17 Mar 2023 16:11:09 +0000 (16:11 +0000)
committerclaudio <claudio@openbsd.org>
Fri, 17 Mar 2023 16:11:09 +0000 (16:11 +0000)
Only print the sourceaddrs if no argument was passed. If arguemnts
are set make sure that either and address is present or that an ifp
was given. This make the command behave a more like other route commands.
OK deraadt@

sbin/route/route.c

index 49b675f..755e548 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: route.c,v 1.264 2023/03/15 08:43:51 claudio Exp $     */
+/*     $OpenBSD: route.c,v 1.265 2023/03/17 16:11:09 claudio Exp $     */
 /*     $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $   */
 
 /*
@@ -487,6 +487,10 @@ setsource(int argc, char **argv)
        unsigned int ifindex = 0;
 
        cmd = argv[0];
+
+       if (argc == 1)
+               printsource(AF_UNSPEC, tableid);
+
        while (--argc > 0) {
                if (**(++argv)== '-') {
                        switch (key = keyword(1 + *argv)) {
@@ -505,14 +509,14 @@ setsource(int argc, char **argv)
                                if (ifindex == 0)
                                        errx(1, "no such interface %s", *argv);
                                break;
+                       default:
+                               usage(NULL);
                        }
                } else
                        break;
        }
 
-       if (argc <= 0 && ifindex == 0)
-               printsource(AF_UNSPEC, tableid);
-       if (argc > 1 && ifindex == 0)
+       if (!(argc == 1 && ifindex == 0) && !(argc == 0 && ifindex != 0))
                usage(NULL);
 
        if (uid)