From patchwork Mon Apr 10 14:36:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Shearman X-Patchwork-Id: 749045 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 3w1t780Yy4z9s8Q for ; Tue, 11 Apr 2017 00:37:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753584AbdDJOhG (ORCPT ); Mon, 10 Apr 2017 10:37:06 -0400 Received: from mx0b-000f0801.pphosted.com ([67.231.152.113]:35968 "EHLO mx0a-000f0801.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753539AbdDJOhE (ORCPT ); Mon, 10 Apr 2017 10:37:04 -0400 Received: from pps.filterd (m0000700.ppops.net [127.0.0.1]) by mx0b-000f0801.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3AEariC022234; Mon, 10 Apr 2017 07:37:02 -0700 Received: from brmwp-exmb12.corp.brocade.com ([208.47.132.227]) by mx0b-000f0801.pphosted.com with ESMTP id 29pwg1erfh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 10 Apr 2017 07:37:02 -0700 Received: from EMEAWP-EXMB11.corp.brocade.com (172.29.11.85) by BRMWP-EXMB12.corp.brocade.com (172.16.59.130) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 10 Apr 2017 08:37:00 -0600 Received: from BRA-2XN4P12.vyatta.com (172.29.196.111) by EMEAWP-EXMB11.corp.brocade.com (172.29.11.85) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 10 Apr 2017 16:36:58 +0200 From: Robert Shearman To: CC: , Robert Shearman Subject: [PATCH iproute2 net-next 2/2] iproute: Add support for MPLS LWT ttl attribute Date: Mon, 10 Apr 2017 15:36:12 +0100 Message-ID: <1491834972-26668-3-git-send-email-rshearma@brocade.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1491834972-26668-1-git-send-email-rshearma@brocade.com> References: <1491834972-26668-1-git-send-email-rshearma@brocade.com> MIME-Version: 1.0 X-Originating-IP: [172.29.196.111] X-ClientProxiedBy: hq1wp-excas14.corp.brocade.com (10.70.38.103) To EMEAWP-EXMB11.corp.brocade.com (172.29.11.85) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-10_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=15 phishscore=0 bulkscore=0 spamscore=0 clxscore=1031 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704100114 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for setting and displaying the ttl attribute for MPLS IP lighweight tunnels. Signed-off-by: Robert Shearman --- ip/iproute_lwtunnel.c | 31 +++++++++++++++++++++++++++++-- man/man8/ip-route.8.in | 9 ++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index 0fa1cab0a790..845a115e9e41 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -84,6 +84,9 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap) if (tb[MPLS_IPTUNNEL_DST]) fprintf(fp, " %s ", format_host_rta(AF_MPLS, tb[MPLS_IPTUNNEL_DST])); + if (tb[MPLS_IPTUNNEL_TTL]) + fprintf(fp, "ttl %u ", + rta_getattr_u8(tb[MPLS_IPTUNNEL_TTL])); } static void print_encap_ip(FILE *fp, struct rtattr *encap) @@ -247,6 +250,7 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len, inet_prefix addr; int argc = *argcp; char **argv = *argvp; + int ttl_ok = 0; if (get_addr(&addr, *argv, AF_MPLS)) { fprintf(stderr, @@ -258,8 +262,31 @@ static int parse_encap_mpls(struct rtattr *rta, size_t len, rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &addr.data, addr.bytelen); - *argcp = argc; - *argvp = argv; + argc--; + argv++; + + while (argc > 0) { + if (strcmp(*argv, "ttl") == 0) { + __u8 ttl; + + NEXT_ARG(); + if (ttl_ok++) + duparg2("ttl", *argv); + if (get_u8(&ttl, *argv, 0)) + invarg("\"ttl\" value is invalid\n", *argv); + rta_addattr8(rta, len, MPLS_IPTUNNEL_TTL, ttl); + } else { + break; + } + argc--; argv++; + } + + /* argv is currently the first unparsed argument, + * but the lwt_parse_encap() caller will move to the next, + * so step back + */ + *argcp = argc + 1; + *argvp = argv - 1; return 0; } diff --git a/man/man8/ip-route.8.in b/man/man8/ip-route.8.in index fbe2711a4301..d2a44acf2793 100644 --- a/man/man8/ip-route.8.in +++ b/man/man8/ip-route.8.in @@ -181,7 +181,9 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]" .ti -8 .IR ENCAP_MPLS " := " .BR mpls " [ " -.IR LABEL " ]" +.IR LABEL " ] [" +.B ttl +.IR TTL " ]" .ti -8 .IR ENCAP_IP " := " @@ -666,6 +668,11 @@ is a set of encapsulation attributes specific to the .I MPLSLABEL - mpls label stack with labels separated by .I "/" +.sp + +.B ttl +.I TTL +- TTL to use for MPLS header or 0 to inherit from IP header .in -2 .sp