From patchwork Thu Sep 7 14:26:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadi Sharshevsky X-Patchwork-Id: 811052 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xp2l55J5lz9sPm for ; Fri, 8 Sep 2017 00:24:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755419AbdIGOYP (ORCPT ); Thu, 7 Sep 2017 10:24:15 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:40364 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755309AbdIGOYH (ORCPT ); Thu, 7 Sep 2017 10:24:07 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from arkadis@mellanox.com) with ESMTPS (AES256-SHA encrypted); 7 Sep 2017 17:24:02 +0300 Received: from dev-r-vrt-156.mtr.labs.mlnx (dev-r-vrt-156.mtr.labs.mlnx [10.212.156.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v87EO1oE010674; Thu, 7 Sep 2017 17:24:02 +0300 From: Arkadi Sharshevsky To: netdev@vger.kernel.org Cc: davem@davemloft.net, stephen@networkplumber.org, jiri@resnulli.us, mlxsw@mellanox.com, andrew@lunn.ch, Arkadi Sharshevsky , Jiri Pirko Subject: [PATCH iproute2 4/4] devlink: Add support for protocol IPv4/IPv6/Ethernet special formats Date: Thu, 7 Sep 2017 17:26:43 +0300 Message-Id: <1504794403-45690-5-git-send-email-arkadis@mellanox.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1504794403-45690-1-git-send-email-arkadis@mellanox.com> References: <1504794403-45690-1-git-send-email-arkadis@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for protocol IPv4/IPv6/Ethernet special formats. Signed-off-by: Arkadi Sharshevsky Signed-off-by: Jiri Pirko --- devlink/devlink.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index b87de38..39cda06 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "SNAPSHOT.h" #include "list.h" @@ -3401,7 +3402,79 @@ struct dpipe_header_printer { unsigned int header_id; }; -static struct dpipe_header_printer *dpipe_header_printers[] = {}; +static void dpipe_field_printer_ipv4_addr(struct dpipe_ctx *ctx, + enum dpipe_value_type type, + void *value) +{ + struct in_addr ip_addr; + + ip_addr.s_addr = htonl(*(uint32_t *)value); + pr_out_str(ctx->dl, dpipe_value_type_e2s(type), inet_ntoa(ip_addr)); +} + +static void +dpipe_field_printer_ethernet_addr(struct dpipe_ctx *ctx, + enum dpipe_value_type type, + void *value) +{ + pr_out_str(ctx->dl, dpipe_value_type_e2s(type), + ether_ntoa((struct ether_addr *)value)); +} + +static void dpipe_field_printer_ipv6_addr(struct dpipe_ctx *ctx, + enum dpipe_value_type type, + void *value) +{ + char str[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET6, value, str, INET6_ADDRSTRLEN); + pr_out_str(ctx->dl, dpipe_value_type_e2s(type), str); +} + +static struct dpipe_field_printer dpipe_field_printers_ipv4[] = { + { + .printer = dpipe_field_printer_ipv4_addr, + .field_id = DEVLINK_DPIPE_FIELD_IPV4_DST_IP, + } +}; + +static struct dpipe_header_printer dpipe_header_printer_ipv4 = { + .printers = dpipe_field_printers_ipv4, + .printers_count = ARRAY_SIZE(dpipe_field_printers_ipv4), + .header_id = DEVLINK_DPIPE_HEADER_IPV4, +}; + +static struct dpipe_field_printer dpipe_field_printers_ethernet[] = { + { + .printer = dpipe_field_printer_ethernet_addr, + .field_id = DEVLINK_DPIPE_FIELD_ETHERNET_DST_MAC, + }, +}; + +static struct dpipe_header_printer dpipe_header_printer_ethernet = { + .printers = dpipe_field_printers_ethernet, + .printers_count = ARRAY_SIZE(dpipe_field_printers_ethernet), + .header_id = DEVLINK_DPIPE_HEADER_ETHERNET, +}; + +static struct dpipe_field_printer dpipe_field_printers_ipv6[] = { + { + .printer = dpipe_field_printer_ipv6_addr, + .field_id = DEVLINK_DPIPE_FIELD_IPV6_DST_IP, + } +}; + +static struct dpipe_header_printer dpipe_header_printer_ipv6 = { + .printers = dpipe_field_printers_ipv6, + .printers_count = ARRAY_SIZE(dpipe_field_printers_ipv6), + .header_id = DEVLINK_DPIPE_HEADER_IPV6, +}; + +static struct dpipe_header_printer *dpipe_header_printers[] = { + &dpipe_header_printer_ipv4, + &dpipe_header_printer_ethernet, + &dpipe_header_printer_ipv6, +}; static int dpipe_print_prot_header(struct dpipe_ctx *ctx, struct dpipe_op_info *info,