-#define ip6_ext_header_find_t(i, p, m, t) \
-if ((i)->protocol == t) \
-{ \
- (m) = (void *)((i)+1); \
- (p) = NULL; \
-} \
-else \
-{ \
- (m) = NULL; \
- (p) = (void *)((i)+1); \
- while (ip6_ext_hdr((p)->next_hdr) && \
- ((ip6_ext_header_t *)(p))->next_hdr != (t)) \
- { \
- (p) = ip6_ext_next_header((p)); \
- } \
- if ( ((p)->next_hdr) == (t)) \
- { \
- (m) = (void *)(ip6_ext_next_header((p))); \
- } \
+always_inline void *
+ip6_ext_header_find (vlib_main_t * vm, vlib_buffer_t * b,
+ ip6_header_t * ip6_header, u8 header_type,
+ ip6_ext_header_t ** prev_ext_header)
+{
+ ip6_ext_header_t *prev = NULL;
+ ip6_ext_header_t *result = NULL;
+ if ((ip6_header)->protocol == header_type)
+ {
+ result = (void *) (ip6_header + 1);
+ if (!vlib_object_within_buffer_data (vm, b, result,
+ ip6_ext_header_len (result)))
+ {
+ result = NULL;
+ }
+ }
+ else
+ {
+ result = NULL;
+ prev = (void *) (ip6_header + 1);
+ while (ip6_ext_hdr (prev->next_hdr) && prev->next_hdr != header_type)
+ {
+ prev = ip6_ext_next_header (prev);
+ if (!vlib_object_within_buffer_data (vm, b, prev,
+ ip6_ext_header_len (prev)))
+ {
+ prev = NULL;
+ break;
+ }
+ }
+ if (prev && (prev->next_hdr == header_type))
+ {
+ result = ip6_ext_next_header (prev);
+ if (!vlib_object_within_buffer_data (vm, b, result,
+ ip6_ext_header_len (result)))
+ {
+ result = NULL;
+ }
+ }
+ }
+ if (prev_ext_header)
+ {
+ *prev_ext_header = prev;
+ }
+ return result;