From patchwork Tue Jun 14 20:59:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 635574 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rThqB61jRz9t0l for ; Wed, 15 Jun 2016 06:59:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b=U6mkKc+x; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932224AbcFNU7r (ORCPT ); Tue, 14 Jun 2016 16:59:47 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35593 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932328AbcFNU7o (ORCPT ); Tue, 14 Jun 2016 16:59:44 -0400 Received: by mail-pa0-f50.google.com with SMTP id hl6so616605pac.2 for ; Tue, 14 Jun 2016 13:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BCuzGIvol5fxbwXeLrT+FiKaJOJybBYzcAcciDttRr0=; b=U6mkKc+xXnBvEdprUtKzGMPh3rnSSEuO17D58WpgtOMGumw6hXgn0Y0+W6OZPP/sJZ SYQDQfwEwZKaVOMI5VUIK8s2aSq9FZzFgI/DDObUAYe8EuyE/YWcJ670bauNxAaE8XS9 dEwIU0M2C3QljaK0TNoMyU9iI8qgycn99QKL4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BCuzGIvol5fxbwXeLrT+FiKaJOJybBYzcAcciDttRr0=; b=CI8ETdKFVOOEJWnJCVKVkwlJzNTJV2af4im3ibK9sodRJ7GZJGlYWZW24FbbO/Q91a OgXdhcs9/O05SXf2g3zsyxrd4x4T0Vt56JaHhHZiaAckU3vu7SCtRwXXCVG34IRoQQSz uBsRQy1t9KYA54is28mjIOqdG7Gme6tLoA4sj+53lbpNLdD/1km2y4oYntTez60v0WYf cQEgijv/rQSZQJ3+lM2lPnaDb+6uKU8PwWGqIVWnn9o+ilxunHKxRdHpqry62l45yb72 sk02CQ51SpU/BQgF4GZ0OMBdJH43dhVXZ136/kpPgKGantZGMsgTE4MlAVudtKQfNlSR 8Ihw== X-Gm-Message-State: ALyK8tLEp5PDzKOpKVEg+GVisWGisgYfkysWc8DNOoTKhUr5abSkZ3f3KdM0tFe2IsdUCNXv X-Received: by 10.66.237.175 with SMTP id vd15mr29991314pac.139.1465937983455; Tue, 14 Jun 2016 13:59:43 -0700 (PDT) Received: from kenny.cumulusnetworks.com. ([216.129.126.126]) by smtp.googlemail.com with ESMTPSA id 20sm14474311pfw.92.2016.06.14.13.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jun 2016 13:59:43 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org Cc: David Ahern Subject: [PATCH iproute2 6/6] ip route: Add support for vrf keyword Date: Tue, 14 Jun 2016 13:59:32 -0700 Message-Id: <1465937972-25011-7-git-send-email-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465937972-25011-1-git-send-email-dsa@cumulusnetworks.com> References: <1465937972-25011-1-git-send-email-dsa@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add vrf keyword to 'ip route' commands. Allows: 1. Users can list routes by VRF name: $ ip route show vrf NAME VRF tables have all routes including local and broadcast routes. The VRF keyword filters LOCAL and BROADCAST routes; to see all routes the table option can be used. Or to see local routes only for a VRF: $ ip route show vrf NAME type local Contrast with current syntax: $ ip route show table ID where the user needs to find the vrf to table ID or maintain a text file in /etc/iproute2/rt_tables.d. 2. Add or delete a route for a VRF: $ ip route {add|delete} vrf NAME Similarly for this command, users currently need to use table option and know the table id or maintain a mapping. 3. Do a route lookup for a VRF: $ ip route get vrf NAME ADDRESS Contrast with current syntax: $ ip route get oif DEV ADDRESS (specifying table id for route get does not work kernel side). Signed-off-by: David Ahern --- ip/iproute.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ip/iproute.c b/ip/iproute.c index aae693d17be8..bd661c16cb46 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -67,10 +67,10 @@ static void usage(void) fprintf(stderr, " ip route showdump\n"); fprintf(stderr, " ip route get ADDRESS [ from ADDRESS iif STRING ]\n"); fprintf(stderr, " [ oif STRING ] [ tos TOS ]\n"); - fprintf(stderr, " [ mark NUMBER ]\n"); + fprintf(stderr, " [ mark NUMBER ] [ vrf NAME ]\n"); fprintf(stderr, " ip route { add | del | change | append | replace } ROUTE\n"); fprintf(stderr, "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n"); - fprintf(stderr, " [ table TABLE_ID ] [ proto RTPROTO ]\n"); + fprintf(stderr, " [ table TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ]\n"); fprintf(stderr, " [ type TYPE ] [ scope SCOPE ]\n"); fprintf(stderr, "ROUTE := NODE_SPEC [ INFO_SPEC ]\n"); fprintf(stderr, "NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ]\n"); @@ -1141,6 +1141,20 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv) addattr32(&req.n, sizeof(req), RTA_TABLE, tid); } table_ok = 1; + } else if (matches(*argv, "vrf") == 0) { + __u32 tid; + + NEXT_ARG(); + tid = ipvrf_get_table(*argv); + if (tid == 0) + invarg("Invalid VRF\n", *argv); + if (tid < 256) + req.r.rtm_table = tid; + else { + req.r.rtm_table = RT_TABLE_UNSPEC; + addattr32(&req.n, sizeof(req), RTA_TABLE, tid); + } + table_ok = 1; } else if (strcmp(*argv, "dev") == 0 || strcmp(*argv, "oif") == 0) { NEXT_ARG(); @@ -1395,6 +1409,15 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) } } else filter.tb = tid; + } else if (matches(*argv, "vrf") == 0) { + __u32 tid; + + NEXT_ARG(); + tid = ipvrf_get_table(*argv); + if (tid == 0) + invarg("Invalid VRF\n", *argv); + filter.tb = tid; + filter.typemask = ~(1 << RTN_LOCAL | 1<