u16 as_u16[8];
u32 as_u32[4];
u64 as_u64[2];
+ u64x2 as_u128;
uword as_uword[16 / sizeof (uword)];
}
-ip6_address_t;
+__clib_packed ip6_address_t;
+
+STATIC_ASSERT_SIZEOF (ip6_address_t, 16);
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
return result;
}
+/*
+ * walk extension headers, looking for a specific extension header and last
+ * extension header, calculating length of all extension headers
+ *
+ * @param vm
+ * @param b buffer to limit search to
+ * @param ip6_header ipv6 header
+ * @param find_hdr extension header to look for (ignored if ext_hdr is NULL)
+ * @param length[out] length of all extension headers
+ * @param ext_hdr[out] extension header of type find_hdr (may be NULL)
+ * @param last_ext_hdr[out] last extension header (may be NULL)
+ *
+ * @return 0 on success, -1 on failure (ext headers crossing buffer boundary)
+ */
+always_inline int
+ip6_walk_ext_hdr (vlib_main_t * vm, vlib_buffer_t * b,
+ const ip6_header_t * ip6_header, u8 find_hdr, u32 * length,
+ ip6_ext_header_t ** ext_hdr,
+ ip6_ext_header_t ** last_ext_hdr)
+{
+ if (!ip6_ext_hdr (ip6_header->protocol))
+ {
+ *length = 0;
+ *ext_hdr = NULL;
+ *last_ext_hdr = NULL;
+ return 0;
+ }
+ *length = 0;
+ ip6_ext_header_t *h = (void *) (ip6_header + 1);
+ if (!vlib_object_within_buffer_data (vm, b, h, ip6_ext_header_len (h)))
+ {
+ return -1;
+ }
+ *length += ip6_ext_header_len (h);
+ *last_ext_hdr = h;
+ *ext_hdr = NULL;
+ if (ip6_header->protocol == find_hdr)
+ {
+ *ext_hdr = h;
+ }
+ while (ip6_ext_hdr (h->next_hdr))
+ {
+ if (h->next_hdr == find_hdr)
+ {
+ h = ip6_ext_next_header (h);
+ *ext_hdr = h;
+ }
+ else
+ {
+ h = ip6_ext_next_header (h);
+ }
+ if (!vlib_object_within_buffer_data (vm, b, h, ip6_ext_header_len (h)))
+ {
+ return -1;
+ }
+ *length += ip6_ext_header_len (h);
+ *last_ext_hdr = h;
+ }
+ return 0;
+}
+
/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
u8 next_hdr;