netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsa@cumulusnetworks.com>
To: netdev@vger.kernel.org, stephen@networkplumber.org
Cc: David Ahern <dsa@cumulusnetworks.com>
Subject: [PATCH iproute2] ip route: error out on multiple via without nexthop keyword
Date: Thu, 19 Jan 2017 09:08:21 -0800	[thread overview]
Message-ID: <1484845701-19354-1-git-send-email-dsa@cumulusnetworks.com> (raw)

To specify multiple nexthops in a route the user is expected to use the
"nexthop" keyword which ip route uses to create the RTA_MULTIPATH.
However, ip route always accepts multiple 'via' keywords where only the
last one is used in the route leading to confusion. For example, ip
accepts this syntax:
    $ ip ro add vrf red  1.1.1.0/24 via 10.100.1.18 via 10.100.2.18

but the route entered inserted by the kernel is just the last gateway:
    1.1.1.0/24 via 10.100.2.18 dev eth2

which is not the full request from the user. Detect the presense of
multiple 'via' and give the user a hint to add nexthop:

    $ ip ro add vrf red  1.1.1.0/24 via 10.100.1.18 via 10.100.2.18
    Error: argument "via" is wrong: use nexthop syntax to specify multiple via

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 ip/iproute.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ip/iproute.c b/ip/iproute.c
index e433de8be189..52dbdc7dea36 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -881,6 +881,10 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 			inet_prefix addr;
 			int family;
 
+			if (gw_ok) {
+				invarg("use nexthop syntax to specify multiple via\n",
+				       *argv);
+			}
 			gw_ok = 1;
 			NEXT_ARG();
 			family = read_family(*argv);
-- 
2.1.4

             reply	other threads:[~2017-01-19 17:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 17:08 David Ahern [this message]
2017-01-20 17:38 ` [PATCH iproute2] ip route: error out on multiple via without nexthop keyword Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484845701-19354-1-git-send-email-dsa@cumulusnetworks.com \
    --to=dsa@cumulusnetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).