aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWojciech Drewek <wojciech.drewek@intel.com>2022-07-29 10:50:34 +0200
committerDavid Ahern <dsahern@kernel.org>2022-07-29 11:22:42 -0600
commit5a56804ce1d4539d14f8fb44178e499a7ae2aa74 (patch)
treee7e01d6befffb62968d41bfaa1858cd240ae4f52
parent653c7517fd0853870eef78bec43f87b75771f4b7 (diff)
downloadiproute2-5a56804ce1d4539d14f8fb44178e499a7ae2aa74.tar.gz
lib: Introduce ppp protocols
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 <wojciech.drewek@intel.com> Acked-by: Guillaume Nault <gnault@redhat.com> Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--include/rt_names.h3
-rw-r--r--lib/Makefile2
-rw-r--r--lib/ppp_proto.c52
3 files changed, 56 insertions, 1 deletions
diff --git a/include/rt_names.h b/include/rt_names.h
index 1835f3be2..6358650db 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/lib/Makefile b/lib/Makefile
index 6c98f9a61..ddedd37fe 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 000000000..a63466432
--- /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 <wojciech.drewek@intel.com>
+ */
+
+#include <linux/ppp_defs.h>
+#include <linux/if_ether.h>
+#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);
+}