aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-11-25 13:04:44 +0000
committerOle Trøan <otroan@employees.org>2019-12-03 19:36:26 +0000
commit9534696b4637185c9f296375e63c50d8976d153d (patch)
tree7e5bce5d492b6b376e42f9df175e18202f93af68 /src/vnet/ip
parentc8972fe506c78530a3e4085453e86a0b85b245ef (diff)
ipip: Tunnel flags controlling copying data to/from payload/encap
Type: feature Signed-off-by: Neale Ranns <nranns@cisco.com> Change-Id: I9467f11775936754406892b8e9e275f989ac9b30
Diffstat (limited to 'src/vnet/ip')
-rw-r--r--src/vnet/ip/ip.c17
-rw-r--r--src/vnet/ip/ip4_format.c4
-rw-r--r--src/vnet/ip/ip4_packet.h64
-rw-r--r--src/vnet/ip/ip6_packet.h34
-rw-r--r--src/vnet/ip/ip_packet.h29
5 files changed, 146 insertions, 2 deletions
diff --git a/src/vnet/ip/ip.c b/src/vnet/ip/ip.c
index 785cd491b57..88eff4f4d59 100644
--- a/src/vnet/ip/ip.c
+++ b/src/vnet/ip/ip.c
@@ -312,6 +312,23 @@ format_ip_dscp (u8 * s, va_list * va)
return (format (s, "unknown"));
}
+u8 *
+format_ip_ecn (u8 * s, va_list * va)
+{
+ ip_ecn_t ecn = va_arg (*va, u32); // int promotion of u8
+
+ switch (ecn)
+ {
+#define _(n,v) \
+ case IP_ECN_##v: \
+ return (format (s, "%s", #v));
+ foreach_ip_ecn
+#undef _
+ }
+
+ return (format (s, "unknown"));
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/ip/ip4_format.c b/src/vnet/ip/ip4_format.c
index eebd5ad8bd3..786a01d396b 100644
--- a/src/vnet/ip/ip4_format.c
+++ b/src/vnet/ip/ip4_format.c
@@ -155,6 +155,10 @@ format_ip4_header (u8 * s, va_list * args)
s = format (s, " (should be 0x%04x)", clib_net_to_host_u16 (c));
}
+ s = format (s, " dscp %U ecn %U",
+ format_ip_dscp, ip4_header_get_dscp (ip),
+ format_ip_ecn, ip4_header_get_ecn (ip));
+
{
u32 f = clib_net_to_host_u16 (ip->flags_and_fragment_offset);
u32 o;
diff --git a/src/vnet/ip/ip4_packet.h b/src/vnet/ip/ip4_packet.h
index c1852fc3ff2..79cf22c4d70 100644
--- a/src/vnet/ip/ip4_packet.h
+++ b/src/vnet/ip/ip4_packet.h
@@ -264,6 +264,70 @@ ip4_header_checksum (ip4_header_t * i)
return csum;
}
+always_inline void
+ip4_header_set_dscp (ip4_header_t * ip4, ip_dscp_t dscp)
+{
+ ip4->tos &= ~0xfc;
+ /* not masking the dscp value to save th instruction
+ * it shouldn't b necessary since the argument is an enum
+ * whose range is therefore constrained in the CP. in the
+ * DP it will have been taken from another packet, so again
+ * constrained in value */
+ ip4->tos |= dscp << IP_PACKET_TC_FIELD_DSCP_BIT_SHIFT;
+}
+
+always_inline void
+ip4_header_set_ecn (ip4_header_t * ip4, ip_ecn_t ecn)
+{
+ ip4->tos &= ~IP_PACKET_TC_FIELD_ECN_MASK;
+ ip4->tos |= ecn;
+}
+
+always_inline void
+ip4_header_set_ecn_w_chksum (ip4_header_t * ip4, ip_ecn_t ecn)
+{
+ ip_csum_t sum = ip4->checksum;
+ u8 old = ip4->tos;
+ u8 new = (old & ~IP_PACKET_TC_FIELD_ECN_MASK) | ecn;
+
+ sum = ip_csum_update (sum, old, new, ip4_header_t, tos);
+ ip4->checksum = ip_csum_fold (sum);
+ ip4->tos = new;
+}
+
+always_inline ip_dscp_t
+ip4_header_get_dscp (const ip4_header_t * ip4)
+{
+ return (ip4->tos >> IP_PACKET_TC_FIELD_DSCP_BIT_SHIFT);
+}
+
+always_inline ip_ecn_t
+ip4_header_get_ecn (const ip4_header_t * ip4)
+{
+ return (ip4->tos & IP_PACKET_TC_FIELD_ECN_MASK);
+}
+
+always_inline void
+ip4_header_set_df (ip4_header_t * ip4)
+{
+ ip4->flags_and_fragment_offset |=
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
+}
+
+always_inline void
+ip4_header_clear_df (ip4_header_t * ip4)
+{
+ ip4->flags_and_fragment_offset &=
+ ~clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
+}
+
+always_inline u8
+ip4_header_get_df (ip4_header_t * ip4)
+{
+ return (! !(ip4->flags_and_fragment_offset &
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT)));
+}
+
static inline uword
ip4_header_checksum_is_valid (ip4_header_t * i)
{
diff --git a/src/vnet/ip/ip6_packet.h b/src/vnet/ip/ip6_packet.h
index ed96ece1e7f..8c0698440e3 100644
--- a/src/vnet/ip/ip6_packet.h
+++ b/src/vnet/ip/ip6_packet.h
@@ -396,6 +396,20 @@ ip6_traffic_class_network_order (const ip6_header_t * ip6)
& 0x0ff00000) >> 20;
}
+static_always_inline ip_dscp_t
+ip6_dscp_network_order (const ip6_header_t * ip6)
+{
+ return (clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label)
+ & 0x0fc00000) >> 22;
+}
+
+static_always_inline ip_ecn_t
+ip6_ecn_network_order (const ip6_header_t * ip6)
+{
+ return (clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label)
+ & 0x00300000) >> 20;
+}
+
static_always_inline void
ip6_set_traffic_class_network_order (ip6_header_t * ip6, ip_dscp_t dscp)
{
@@ -406,6 +420,26 @@ ip6_set_traffic_class_network_order (ip6_header_t * ip6, ip_dscp_t dscp)
ip6->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (tmp);
}
+static_always_inline void
+ip6_set_dscp_network_order (ip6_header_t * ip6, ip_dscp_t dscp)
+{
+ u32 tmp =
+ clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label);
+ tmp &= 0xf03fffff;
+ tmp |= (dscp << 22);
+ ip6->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (tmp);
+}
+
+static_always_inline void
+ip6_set_ecn_network_order (ip6_header_t * ip6, ip_ecn_t ecn)
+{
+ u32 tmp =
+ clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label);
+ tmp &= 0xffcfffff;
+ tmp |= (ecn << 20);
+ ip6->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (tmp);
+}
+
always_inline void *
ip6_next_header (ip6_header_t * i)
{
diff --git a/src/vnet/ip/ip_packet.h b/src/vnet/ip/ip_packet.h
index 63a59f87668..9a55d5f644e 100644
--- a/src/vnet/ip/ip_packet.h
+++ b/src/vnet/ip/ip_packet.h
@@ -118,10 +118,35 @@ typedef enum ip_dscp_t_
#undef _
} __clib_packed ip_dscp_t;
-STATIC_ASSERT_SIZEOF (ip_dscp_t, 1);
-
extern u8 *format_ip_dscp (u8 * s, va_list * va);
+/**
+ * IP DSCP bit shift
+ * The ECN occupies the 2 least significant bits of the TC field
+ */
+#define IP_PACKET_TC_FIELD_DSCP_BIT_SHIFT 2
+#define IP_PACKET_TC_FIELD_ECN_MASK 0x03
+
+/**
+ * The set of RFC defined DSCP values.
+ */
+#define foreach_ip_ecn \
+ _(0, NON_ECN) \
+ _(1, ECT_0) \
+ _(2, ECT_1) \
+ _(3, CE)
+
+typedef enum ip_ecn_t_
+{
+#define _(n,f) IP_ECN_##f = n,
+ foreach_ip_ecn
+#undef _
+} __clib_packed ip_ecn_t;
+
+STATIC_ASSERT_SIZEOF (ip_ecn_t, 1);
+
+extern u8 *format_ip_ecn (u8 * s, va_list * va);
+
/* IP checksum support. */
static_always_inline u16