From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E47B0C04A68 for ; Thu, 28 Jul 2022 08:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234573AbiG1Iqj (ORCPT ); Thu, 28 Jul 2022 04:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234548AbiG1Iqg (ORCPT ); Thu, 28 Jul 2022 04:46:36 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843832A94A for ; Thu, 28 Jul 2022 01:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658997995; x=1690533995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vHudSdfbzLoWz2xvjVWL3GUMNljbDeXqmvmF+Vn4YBg=; b=JkB9kvFSzm/nQMvGCwa/Z8ut6CHVxUDf9qLQ2q6YI5NUi+IS8JgcWL/T yYDpupSan5NBHUeBfB+g8z6Kt81aJMyNe+LyC+vxfXRCQ1IjDiDCTbJv7 eyPy28fyE4/Tg4keW5Ketg4btKKJChJYIQMULmSeN+6YxD24JeUfVRUP3 D7mCSNRshgSN0UJhYfUYIg0xK18WBfVVLNff5LDBNlPVqYQC9dDlKygdT hPnSbIROLLfHrNUK1j2gkJHTfb0/h1DOl330C4OyWkZbRhCHJmePEVerd eCBFAQ0gCO0dlGfRrhbN51O9CfdEvBLVzFqqoUZzF9y4KeajZEa3X1HFt A==; X-IronPort-AV: E=McAfee;i="6400,9594,10421"; a="271500177" X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="271500177" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2022 01:46:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="846617284" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga006.fm.intel.com with ESMTP; 28 Jul 2022 01:46:33 -0700 Received: from switcheroo.igk.intel.com (switcheroo.igk.intel.com [172.22.229.137]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 26S8kWS2008698; Thu, 28 Jul 2022 09:46:33 +0100 From: Wojciech Drewek To: netdev@vger.kernel.org Cc: dsahern@gmail.com, stephen@networkplumber.org Subject: [PATCH iproute-next v2 2/3] lib: Introduce ppp protocols Date: Thu, 28 Jul 2022 10:44:36 +0200 Message-Id: <20220728084437.486187-3-wojciech.drewek@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220728084437.486187-1-wojciech.drewek@intel.com> References: <20220728084437.486187-1-wojciech.drewek@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org PPP protocol field uses different values than ethertype. Introduce utilities for translating PPP protocols from strings to values and vice versa. Use generic API from utils in order to get proto id and name. Signed-off-by: Wojciech Drewek --- v2: Helper functions moved to separate commit --- include/rt_names.h | 3 ++ include/uapi/linux/ppp_defs.h | 37 +++++++++++++++++++++++++ lib/Makefile | 2 +- lib/ppp_proto.c | 52 +++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/ppp_defs.h create mode 100644 lib/ppp_proto.c diff --git a/include/rt_names.h b/include/rt_names.h index 1835f3be2bed..6358650db404 100644 --- a/include/rt_names.h +++ b/include/rt_names.h @@ -31,6 +31,9 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg); const char * ll_proto_n2a(unsigned short id, char *buf, int len); int ll_proto_a2n(unsigned short *id, const char *buf); +const char *ppp_proto_n2a(unsigned short id, char *buf, int len); +int ppp_proto_a2n(unsigned short *id, const char *buf); + const char *nl_proto_n2a(int id, char *buf, int len); int nl_proto_a2n(__u32 *id, const char *arg); diff --git a/include/uapi/linux/ppp_defs.h b/include/uapi/linux/ppp_defs.h new file mode 100644 index 000000000000..0013dc77e3b9 --- /dev/null +++ b/include/uapi/linux/ppp_defs.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * ppp_defs.h - PPP definitions. + * + * Copyright 1994-2000 Paul Mackerras. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +/* + * Protocol field values. + */ +#define PPP_IP 0x21 /* Internet Protocol */ +#define PPP_AT 0x29 /* AppleTalk Protocol */ +#define PPP_IPX 0x2b /* IPX protocol */ +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#define PPP_MP 0x3d /* Multilink protocol */ +#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ +#define PPP_COMPFRAG 0xfb /* fragment compressed below bundle */ +#define PPP_COMP 0xfd /* compressed packet */ +#define PPP_MPLS_UC 0x0281 /* Multi Protocol Label Switching - Unicast */ +#define PPP_MPLS_MC 0x0283 /* Multi Protocol Label Switching - Multicast */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ +#define PPP_IPXCP 0x802b /* IPX Control Protocol */ +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#define PPP_CCPFRAG 0x80fb /* CCP at link level (below MP bundle) */ +#define PPP_CCP 0x80fd /* Compression Control Protocol */ +#define PPP_MPLSCP 0x80fd /* MPLS Control Protocol */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#define PPP_LQR 0xc025 /* Link Quality Report protocol */ +#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ +#define PPP_CBCP 0xc029 /* Callback Control Protocol */ diff --git a/lib/Makefile b/lib/Makefile index 6c98f9a61fdb..ddedd37feb32 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,7 +5,7 @@ CFLAGS += -fPIC UTILOBJ = utils.o utils_math.o rt_names.o ll_map.o ll_types.o ll_proto.o ll_addr.o \ inet_proto.o namespace.o json_writer.o json_print.o json_print_math.o \ - names.o color.o bpf_legacy.o bpf_glue.o exec.o fs.o cg_map.o + names.o color.o bpf_legacy.o bpf_glue.o exec.o fs.o cg_map.o ppp_proto.o ifeq ($(HAVE_ELF),y) ifeq ($(HAVE_LIBBPF),y) diff --git a/lib/ppp_proto.c b/lib/ppp_proto.c new file mode 100644 index 000000000000..a63466432888 --- /dev/null +++ b/lib/ppp_proto.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Utilities for translating PPP protocols from strings + * and vice versa. + * + * Authors: Wojciech Drewek + */ + +#include +#include +#include "utils.h" +#include "rt_names.h" + +static const struct proto ppp_proto_names[] = { + {PPP_IP, "ip"}, + {PPP_AT, "at"}, + {PPP_IPX, "ipx"}, + {PPP_VJC_COMP, "vjc_comp"}, + {PPP_VJC_UNCOMP, "vjc_uncomp"}, + {PPP_MP, "mp"}, + {PPP_IPV6, "ipv6"}, + {PPP_COMPFRAG, "compfrag"}, + {PPP_COMP, "comp"}, + {PPP_MPLS_UC, "mpls_uc"}, + {PPP_MPLS_MC, "mpls_mc"}, + {PPP_IPCP, "ipcp"}, + {PPP_ATCP, "atcp"}, + {PPP_IPXCP, "ipxcp"}, + {PPP_IPV6CP, "ipv6cp"}, + {PPP_CCPFRAG, "ccpfrag"}, + {PPP_CCP, "ccp"}, + {PPP_MPLSCP, "mplscp"}, + {PPP_LCP, "lcp"}, + {PPP_PAP, "pap"}, + {PPP_LQR, "lqr"}, + {PPP_CHAP, "chap"}, + {PPP_CBCP, "cbcp"}, +}; + +const char *ppp_proto_n2a(unsigned short id, char *buf, int len) +{ + size_t len_tb = ARRAY_SIZE(ppp_proto_names); + + return proto_n2a(id, buf, len, ppp_proto_names, len_tb); +} + +int ppp_proto_a2n(unsigned short *id, const char *buf) +{ + size_t len_tb = ARRAY_SIZE(ppp_proto_names); + + return proto_a2n(id, buf, ppp_proto_names, len_tb); +} -- 2.31.1