All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Herbert <tom@quantonium.net>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, rohit@quantonium.net,
	Tom Herbert <tom@quantonium.net>
Subject: [PATCH iproute 5/5] ila: create ila_common.h
Date: Wed, 22 Nov 2017 12:05:37 -0800	[thread overview]
Message-ID: <20171122200537.26703-6-tom@quantonium.net> (raw)
In-Reply-To: <20171122200537.26703-1-tom@quantonium.net>

Move common functions related to checksum, identifier and hook-type
parsing to a common include file.

Signed-off-by: Tom Herbert <tom@quantonium.net>
---
 ip/ila_common.h       | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ip/ipila.c            |  77 +-----------------------------------
 ip/iproute_lwtunnel.c |  97 +---------------------------------------------
 3 files changed, 107 insertions(+), 172 deletions(-)
 create mode 100644 ip/ila_common.h

diff --git a/ip/ila_common.h b/ip/ila_common.h
new file mode 100644
index 00000000..04c6c2ed
--- /dev/null
+++ b/ip/ila_common.h
@@ -0,0 +1,105 @@
+#ifndef _ILA_COMMON_H_
+#define _ILA_COMMON_H_
+
+#include <linux/ila.h>
+#include <string.h>
+
+static inline char *ila_csum_mode2name(__u8 csum_mode)
+{
+	switch (csum_mode) {
+	case ILA_CSUM_ADJUST_TRANSPORT:
+		return "adj-transport";
+	case ILA_CSUM_NEUTRAL_MAP:
+		return "neutral-map";
+	case ILA_CSUM_NO_ACTION:
+		return "no-action";
+	case ILA_CSUM_NEUTRAL_MAP_AUTO:
+		return "neutral-map-auto";
+	default:
+		return "unknown";
+	}
+}
+
+static inline int ila_csum_name2mode(char *name)
+{
+	if (strcmp(name, "adj-transport") == 0)
+		return ILA_CSUM_ADJUST_TRANSPORT;
+	else if (strcmp(name, "neutral-map") == 0)
+		return ILA_CSUM_NEUTRAL_MAP;
+	else if (strcmp(name, "neutral-map-auto") == 0)
+		return ILA_CSUM_NEUTRAL_MAP_AUTO;
+	else if (strcmp(name, "no-action") == 0)
+		return ILA_CSUM_NO_ACTION;
+	else if (strcmp(name, "neutral-map-auto") == 0)
+		return ILA_CSUM_NEUTRAL_MAP_AUTO;
+	else
+		return -1;
+}
+
+static inline char *ila_ident_type2name(__u8 ident_type)
+{
+	switch (ident_type) {
+	case ILA_ATYPE_IID:
+		return "iid";
+	case ILA_ATYPE_LUID:
+		return "luid";
+	case ILA_ATYPE_VIRT_V4:
+		return "virt-v4";
+	case ILA_ATYPE_VIRT_UNI_V6:
+		return "virt-uni-v6";
+	case ILA_ATYPE_VIRT_MULTI_V6:
+		return "virt-multi-v6";
+	case ILA_ATYPE_NONLOCAL_ADDR:
+		return "nonlocal-addr";
+	case ILA_ATYPE_USE_FORMAT:
+		return "use-format";
+	default:
+		return "unknown";
+	}
+}
+
+static inline int ila_ident_name2type(char *name)
+{
+	if (!strcmp(name, "luid"))
+		return ILA_ATYPE_LUID;
+	else if (!strcmp(name, "use-format"))
+		return ILA_ATYPE_USE_FORMAT;
+#if 0 /* No kernel support for configuring these yet */
+	else if (!strcmp(name, "iid"))
+		return ILA_ATYPE_IID;
+	else if (!strcmp(name, "virt-v4"))
+		return ILA_ATYPE_VIRT_V4;
+	else if (!strcmp(name, "virt-uni-v6"))
+		return ILA_ATYPE_VIRT_UNI_V6;
+	else if (!strcmp(name, "virt-multi-v6"))
+		return ILA_ATYPE_VIRT_MULTI_V6;
+	else if (!strcmp(name, "nonlocal-addr"))
+		return ILA_ATYPE_NONLOCAL_ADDR;
+#endif
+	else
+		return -1;
+}
+
+static inline char *ila_hook_type2name(__u8 hook_type)
+{
+	switch (hook_type) {
+	case ILA_HOOK_ROUTE_OUTPUT:
+		return "output";
+	case ILA_HOOK_ROUTE_INPUT:
+		return "input";
+	default:
+		return "unknown";
+	}
+}
+
+static inline int ila_hook_name2type(char *name)
+{
+	if (!strcmp(name, "output"))
+		return ILA_HOOK_ROUTE_OUTPUT;
+	else if (!strcmp(name, "input"))
+		return ILA_HOOK_ROUTE_INPUT;
+	else
+		return -1;
+}
+
+#endif /* _ILA_COMMON_H_ */
diff --git a/ip/ipila.c b/ip/ipila.c
index c7a8ede8..fcc20bf7 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -22,6 +22,7 @@
 #include "libgenl.h"
 #include "utils.h"
 #include "ip_common.h"
+#include "ila_common.h"
 
 static void usage(void)
 {
@@ -51,82 +52,6 @@ static int genl_family = -1;
 
 #define ADDR_BUF_SIZE sizeof("xxxx:xxxx:xxxx:xxxx")
 
-static char *ila_csum_mode2name(__u8 csum_mode)
-{
-	switch (csum_mode) {
-	case ILA_CSUM_ADJUST_TRANSPORT:
-		return "adj-transport";
-	case ILA_CSUM_NEUTRAL_MAP:
-		return "neutral-map";
-	case ILA_CSUM_NO_ACTION:
-		return "no-action";
-	case ILA_CSUM_NEUTRAL_MAP_AUTO:
-		return "neutral-map-auto";
-	default:
-		return "unknown";
-	}
-}
-
-static int ila_csum_name2mode(char *name)
-{
-	if (strcmp(name, "adj-transport") == 0)
-		return ILA_CSUM_ADJUST_TRANSPORT;
-	else if (strcmp(name, "neutral-map") == 0)
-		return ILA_CSUM_NEUTRAL_MAP;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
-	else if (strcmp(name, "no-action") == 0)
-		return ILA_CSUM_NO_ACTION;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
-	else
-		return -1;
-}
-
-static char *ila_ident_type2name(__u8 ident_type)
-{
-	switch (ident_type) {
-	case ILA_ATYPE_IID:
-		return "iid";
-	case ILA_ATYPE_LUID:
-		return "luid";
-	case ILA_ATYPE_VIRT_V4:
-		return "virt-v4";
-	case ILA_ATYPE_VIRT_UNI_V6:
-		return "virt-uni-v6";
-	case ILA_ATYPE_VIRT_MULTI_V6:
-		return "virt-multi-v6";
-	case ILA_ATYPE_NONLOCAL_ADDR:
-		return "nonlocal-addr";
-	case ILA_ATYPE_USE_FORMAT:
-		return "use-format";
-	default:
-		return "unknown";
-	}
-}
-
-static int ila_ident_name2type(char *name)
-{
-	if (!strcmp(name, "luid"))
-		return ILA_ATYPE_LUID;
-	else if (!strcmp(name, "use-format"))
-		return ILA_ATYPE_USE_FORMAT;
-#if 0 /* No kernel support for configuring these yet */
-	else if (!strcmp(name, "iid"))
-		return ILA_ATYPE_IID;
-	else if (!strcmp(name, "virt-v4"))
-		return ILA_ATYPE_VIRT_V4;
-	else if (!strcmp(name, "virt-uni-v6"))
-		return ILA_ATYPE_VIRT_UNI_V6;
-	else if (!strcmp(name, "virt-multi-v6"))
-		return ILA_ATYPE_VIRT_MULTI_V6;
-	else if (!strcmp(name, "nonlocal-addr"))
-		return ILA_ATYPE_NONLOCAL_ADDR;
-#endif
-	else
-		return -1;
-}
-
 static int print_addr64(__u64 addr, char *buff, size_t len)
 {
 	__u16 *words = (__u16 *)&addr;
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index e57cc9f3..27266171 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -25,6 +25,7 @@
 #include "utils.h"
 #include "iproute_lwtunnel.h"
 #include "bpf_util.h"
+#include "ila_common.h"
 
 #include <linux/seg6.h>
 #include <linux/seg6_iptunnel.h>
@@ -279,102 +280,6 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)
 		fprintf(fp, "tos %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TOS]));
 }
 
-static char *ila_csum_mode2name(__u8 csum_mode)
-{
-	switch (csum_mode) {
-	case ILA_CSUM_ADJUST_TRANSPORT:
-		return "adj-transport";
-	case ILA_CSUM_NEUTRAL_MAP:
-		return "neutral-map";
-	case ILA_CSUM_NO_ACTION:
-		return "no-action";
-	case ILA_CSUM_NEUTRAL_MAP_AUTO:
-		return "neutral-map-auto";
-	default:
-		return "unknown";
-	}
-}
-
-static int ila_csum_name2mode(char *name)
-{
-	if (strcmp(name, "adj-transport") == 0)
-		return ILA_CSUM_ADJUST_TRANSPORT;
-	else if (strcmp(name, "neutral-map") == 0)
-		return ILA_CSUM_NEUTRAL_MAP;
-	else if (strcmp(name, "no-action") == 0)
-		return ILA_CSUM_NO_ACTION;
-	else if (strcmp(name, "neutral-map-auto") == 0)
-		return ILA_CSUM_NEUTRAL_MAP_AUTO;
-	else
-		return -1;
-}
-
-static char *ila_ident_type2name(__u8 ident_type)
-{
-	switch (ident_type) {
-	case ILA_ATYPE_IID:
-		return "iid";
-	case ILA_ATYPE_LUID:
-		return "luid";
-	case ILA_ATYPE_VIRT_V4:
-		return "virt-v4";
-	case ILA_ATYPE_VIRT_UNI_V6:
-		return "virt-uni-v6";
-	case ILA_ATYPE_VIRT_MULTI_V6:
-		return "virt-multi-v6";
-	case ILA_ATYPE_NONLOCAL_ADDR:
-		return "nonlocal-addr";
-	case ILA_ATYPE_USE_FORMAT:
-		return "use-format";
-	default:
-		return "unknown";
-	}
-}
-
-static int ila_ident_name2type(char *name)
-{
-	if (!strcmp(name, "luid"))
-		return ILA_ATYPE_LUID;
-	else if (!strcmp(name, "use-format"))
-		return ILA_ATYPE_USE_FORMAT;
-#if 0 /* No kernel support for configuring these yet */
-	else if (!strcmp(name, "iid"))
-		return ILA_ATYPE_IID;
-	else if (!strcmp(name, "virt-v4"))
-		return ILA_ATYPE_VIRT_V4;
-	else if (!strcmp(name, "virt-uni-v6"))
-		return ILA_ATYPE_VIRT_UNI_V6;
-	else if (!strcmp(name, "virt-multi-v6"))
-		return ILA_ATYPE_VIRT_MULTI_V6;
-	else if (!strcmp(name, "nonlocal-addr"))
-		return ILA_ATYPE_NONLOCAL_ADDR;
-#endif
-	else
-		return -1;
-}
-
-static char *ila_hook_type2name(__u8 hook_type)
-{
-	switch (hook_type) {
-	case ILA_HOOK_ROUTE_OUTPUT:
-		return "output";
-	case ILA_HOOK_ROUTE_INPUT:
-		return "input";
-	default:
-		return "unknown";
-	}
-}
-
-static int ila_hook_name2type(char *name)
-{
-	if (!strcmp(name, "output"))
-		return ILA_HOOK_ROUTE_OUTPUT;
-	else if (!strcmp(name, "input"))
-		return ILA_HOOK_ROUTE_INPUT;
-	else
-		return -1;
-}
-
 static void print_encap_ila(FILE *fp, struct rtattr *encap)
 {
 	struct rtattr *tb[ILA_ATTR_MAX+1];
-- 
2.11.0

  parent reply	other threads:[~2017-11-22 20:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 20:05 [PATCH iproute 0/5] ila: additional configuratio support Tom Herbert
2017-11-22 20:05 ` [PATCH iproute 1/5] ila: Fix reporting of ILA locators and locator match Tom Herbert
2017-11-22 20:05 ` [PATCH iproute 2/5] ila: added csum neutral support to ipila Tom Herbert
2017-11-22 20:05 ` [PATCH iproute 3/5] ila: support to configure checksum neutral-map-auto Tom Herbert
2017-11-22 20:05 ` [PATCH iproute 4/5] ila: support for configuring identifier and hook types Tom Herbert
2017-11-22 20:05 ` Tom Herbert [this message]
2017-11-24 17:26 ` [PATCH iproute 0/5] ila: additional configuratio support Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171122200537.26703-6-tom@quantonium.net \
    --to=tom@quantonium.net \
    --cc=netdev@vger.kernel.org \
    --cc=rohit@quantonium.net \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.