aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-plugin/src/parser.h')
-rw-r--r--hicn-plugin/src/parser.h81
1 files changed, 30 insertions, 51 deletions
diff --git a/hicn-plugin/src/parser.h b/hicn-plugin/src/parser.h
index 3c21a33f8..1d297e510 100644
--- a/hicn-plugin/src/parser.h
+++ b/hicn-plugin/src/parser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -26,62 +26,26 @@
* @file parser.h
*/
-#define PARSE(PACKET_TYPE) \
+#define PARSE(PACKET_TYPE, SIZE) \
do \
{ \
if (pkt == NULL) \
return HICN_ERROR_PARSER_PKT_INVAL; \
\
- int ret = HICN_LIB_ERROR_NONE; \
+ int ret = HICN_ERROR_NONE; \
\
- hicn_header_t *pkt_hdr; \
- u8 *ip_pkt; \
- u8 ip_proto; \
- int isv6; \
- u8 next_proto_offset; \
- hicn_type_t type; \
- hicn_name_t *name; \
u16 *port; \
hicn_lifetime_t *lifetime; \
\
- /* start parsing first fields to get the protocols */ \
- pkt_hdr = vlib_buffer_get_current (pkt); \
- isv6 = hicn_is_v6 (pkt_hdr); \
- \
- ip_pkt = vlib_buffer_get_current (pkt); \
- ip_proto = (1 - isv6) * IPPROTO_IP + (isv6) *IPPROTO_IPV6; \
- \
- /* in the ipv6 header the next header field is at byte 6 in the ipv4*/ \
- /* header the protocol field is at byte 9*/ \
- next_proto_offset = 6 + (1 - isv6) * 3; \
- \
- /* get type info*/ \
- type.l4 = IPPROTO_NONE; \
- type.l3 = ip_pkt[next_proto_offset] == IPPROTO_UDP ? IPPROTO_ENCAP : \
- IPPROTO_NONE; \
- type.l2 = ip_pkt[next_proto_offset]; \
- type.l1 = ip_proto; \
+ hicn_packet_buffer_t *pkbuf = &hicn_get_buffer (pkt)->pkbuf; \
\
- /* cache hicn packet type in opaque2*/ \
- hicn_get_buffer (pkt)->type = type; \
- \
- /* get name and name length*/ \
- name = &hicn_get_buffer (pkt)->name; \
- ret = hicn_ops_vft[type.l1]->get_##PACKET_TYPE##_name ( \
- type, &pkt_hdr->protocol, name); \
- if (PREDICT_FALSE (ret)) \
- { \
- if (type.l2 == IPPROTO_ICMPV4 || type.l2 == IPPROTO_ICMPV6) \
- { \
- return HICN_ERROR_PARSER_MAPME_PACKET; \
- } \
- return HICN_ERROR_PARSER_PKT_INVAL; \
- } \
+ hicn_packet_set_buffer (pkbuf, vlib_buffer_get_current (pkt), (SIZE), \
+ (SIZE)); \
+ hicn_packet_analyze (&hicn_get_buffer (pkt)->pkbuf); \
\
/* get source port*/ \
port = &hicn_get_buffer (pkt)->port; \
- hicn_ops_vft[type.l1]->get_source_port (type, &pkt_hdr->protocol, \
- port); \
+ hicn_packet_get_src_port (pkbuf, port); \
if (PREDICT_FALSE (ret)) \
{ \
return HICN_ERROR_PARSER_PKT_INVAL; \
@@ -89,8 +53,7 @@
\
/* get lifetime*/ \
lifetime = &hicn_get_buffer (pkt)->lifetime; \
- hicn_ops_vft[type.l1]->get_lifetime (type, &pkt_hdr->protocol, \
- lifetime); \
+ hicn_packet_get_lifetime (pkbuf, lifetime); \
\
if (*lifetime > hicn_main.pit_lifetime_max_ms) \
*lifetime = hicn_main.pit_lifetime_max_ms; \
@@ -99,6 +62,22 @@
} \
while (0)
+#if 0
+ hicn_name_t *name; \
+
+ /* get name and name length*/
+ name = &hicn_get_buffer (pkt)->name;
+ ret = hicn_##PACKET_TYPE##_get_name (pkbuf, name);
+ if (PREDICT_FALSE (ret))
+ {
+ if (type.l2 == IPPROTO_ICMPV4 || type.l2 == IPPROTO_ICMPV6)
+ {
+ return HICN_ERROR_PARSER_MAPME_PACKET;
+ }
+ return HICN_ERROR_PARSER_PKT_INVAL;
+ }
+#endif
+
/**
* @brief Parse a interest packet
*
@@ -111,9 +90,9 @@
* ipv6
*/
always_inline int
-hicn_interest_parse_pkt (vlib_buffer_t *pkt)
+hicn_interest_parse_pkt (vlib_buffer_t *pkt, uword size)
{
- PARSE (interest);
+ PARSE (interest, size);
}
/**
@@ -128,9 +107,9 @@ hicn_interest_parse_pkt (vlib_buffer_t *pkt)
* ipv6
*/
always_inline int
-hicn_data_parse_pkt (vlib_buffer_t *pkt)
+hicn_data_parse_pkt (vlib_buffer_t *pkt, uword size)
{
- PARSE (data);
+ PARSE (data, size);
}
#endif /* __HICN_PARSER_H__ */
@@ -139,4 +118,4 @@ hicn_data_parse_pkt (vlib_buffer_t *pkt)
* fd.io coding-style-patch-verification: ON
*
* Local Variables: eval: (c-set-style "gnu") End:
- */ \ No newline at end of file
+ */