aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ip')
-rw-r--r--src/vnet/ip/ip.c18
-rw-r--r--src/vnet/ip/ip6_packet.h13
-rw-r--r--src/vnet/ip/ip_packet.h2
3 files changed, 29 insertions, 4 deletions
diff --git a/src/vnet/ip/ip.c b/src/vnet/ip/ip.c
index bceb529ee6f..062f5e7a4ef 100644
--- a/src/vnet/ip/ip.c
+++ b/src/vnet/ip/ip.c
@@ -155,6 +155,24 @@ format_ip_dscp (u8 * s, va_list * va)
return (format (s, "unknown"));
}
+uword
+unformat_ip_dscp (unformat_input_t * input, va_list * args)
+{
+ ip_dscp_t *dscp = va_arg (*args, ip_dscp_t *);
+
+ if (0)
+ ;
+#define _(n,v) \
+ else if (unformat (input, #v)) \
+ *dscp = IP_DSCP_##v;
+ foreach_ip_dscp
+#undef _
+ else
+ return 0;
+
+ return 1;
+}
+
u8 *
format_ip_ecn (u8 * s, va_list * va)
{
diff --git a/src/vnet/ip/ip6_packet.h b/src/vnet/ip/ip6_packet.h
index 7bbdd197f2f..34bc7a8ec1a 100644
--- a/src/vnet/ip/ip6_packet.h
+++ b/src/vnet/ip/ip6_packet.h
@@ -310,31 +310,36 @@ typedef struct
ip6_address_t src_address, dst_address;
} ip6_header_t;
+#define IP6_PACKET_TC_MASK 0x0FF00000
+#define IP6_PACKET_DSCP_MASK 0x0FC00000
+#define IP6_PACKET_ECN_MASK 0x00300000
+
always_inline ip_dscp_t
ip6_traffic_class (const ip6_header_t * i)
{
- return (i->ip_version_traffic_class_and_flow_label & 0x0FF00000) >> 20;
+ return (i->ip_version_traffic_class_and_flow_label & IP6_PACKET_TC_MASK) >>
+ 20;
}
static_always_inline ip_dscp_t
ip6_traffic_class_network_order (const ip6_header_t * ip6)
{
return (clib_net_to_host_u32 (ip6->ip_version_traffic_class_and_flow_label)
- & 0x0ff00000) >> 20;
+ & IP6_PACKET_TC_MASK) >> 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;
+ & IP6_PACKET_DSCP_MASK) >> 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;
+ & IP6_PACKET_ECN_MASK) >> 20;
}
static_always_inline void
diff --git a/src/vnet/ip/ip_packet.h b/src/vnet/ip/ip_packet.h
index 52a65e78c24..e1089ec308e 100644
--- a/src/vnet/ip/ip_packet.h
+++ b/src/vnet/ip/ip_packet.h
@@ -42,6 +42,7 @@
#include <vppinfra/byte_order.h>
#include <vppinfra/error.h>
+#include <vppinfra/format.h>
typedef enum ip_protocol
{
@@ -119,6 +120,7 @@ typedef enum ip_dscp_t_
} __clib_packed ip_dscp_t;
extern u8 *format_ip_dscp (u8 * s, va_list * va);
+unformat_function_t unformat_ip_dscp;
/**
* IP DSCP bit shift