aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/base.c29
-rw-r--r--lib/src/ops.c6
-rw-r--r--lib/src/ops.h119
-rw-r--r--lib/src/packet.c72
-rw-r--r--lib/src/protocol/ah.c6
-rw-r--r--lib/src/protocol/icmp.c6
-rw-r--r--lib/src/protocol/ipv4.c46
-rw-r--r--lib/src/protocol/ipv6.c47
-rw-r--r--lib/src/protocol/new.c14
-rw-r--r--lib/src/protocol/tcp.c37
-rw-r--r--lib/src/protocol/udp.c38
-rw-r--r--lib/src/test/test_name.cc3
-rw-r--r--lib/src/test/test_udp_header.cc4
13 files changed, 58 insertions, 369 deletions
diff --git a/lib/src/base.c b/lib/src/base.c
index a15d55938..8c689da50 100644
--- a/lib/src/base.c
+++ b/lib/src/base.c
@@ -32,21 +32,20 @@ hicn_packet_format_snprintf (char *s, size_t size, hicn_packet_format_t format)
{
char *cur = s;
int rc;
- for (unsigned i = 0; i < 4; i++)
- {
- if (i > 0)
- {
- rc = snprintf (cur, size - (cur - s), " %s ", "/");
- if (rc < 0 || rc >= size - (cur - s))
- return rc;
- cur += rc;
- }
- rc = snprintf (cur, size - (cur - s), "%s",
- hicn_ops_vft[format.as_u8[i]]->name);
- if (rc < 0 || rc >= size - (cur - s))
- return rc;
- cur += rc;
- }
+ HICN_PACKET_FORMAT_ENUMERATE (format, i, protocol, {
+ if (i > 1)
+ {
+ rc = snprintf (cur, size - (cur - s), " %s ", "/");
+ if (rc < 0 || rc >= size - (cur - s))
+ return rc;
+ cur += rc;
+ }
+
+ rc = snprintf (cur, size - (cur - s), "%s", hicn_ops_vft[protocol]->name);
+ if (rc < 0 || rc >= size - (cur - s))
+ return rc;
+ cur += rc;
+ });
return (int) (cur - s);
}
diff --git a/lib/src/ops.c b/lib/src/ops.c
index 0174a3902..2c38b5374 100644
--- a/lib/src/ops.c
+++ b/lib/src/ops.c
@@ -86,12 +86,6 @@ DECLARE_get_signature_padding (none, NONE);
DECLARE_set_signature_padding (none, NONE);
DECLARE_is_last_data (none, NONE);
DECLARE_set_last_data (none, NONE);
-DECLARE_get_ttl (none, NONE);
-DECLARE_set_ttl (none, NONE);
-DECLARE_get_src_port (none, NONE);
-DECLARE_set_src_port (none, NONE);
-DECLARE_get_dst_port (none, NONE);
-DECLARE_set_dst_port (none, NONE);
DECLARE_HICN_OPS (none, 0);
/**
diff --git a/lib/src/ops.h b/lib/src/ops.h
index 886d75cd5..843945690 100644
--- a/lib/src/ops.h
+++ b/lib/src/ops.h
@@ -554,65 +554,6 @@ typedef struct hicn_ops_s
*/
int (*set_last_data) (const hicn_packet_buffer_t *pkbuf, size_t pos);
- /**
- * @brief Returns the packet TTL
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] hops - Pointer to the variable receiving the TTL value
- * @return hICN error code
- */
- int (*get_ttl) (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops);
-
- /**
- * @brief Returns the packet source port
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] hops - The TTL value to set
- * @return hICN error code
- */
- int (*set_ttl) (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops);
-
- /**
- * @brief Returns the packet source port
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] port - Pointer to the variable that will receive the port
- * number
- * @return hICN error code
- */
- int (*get_src_port) (const hicn_packet_buffer_t *pkbuf, size_t pos,
- u16 *port);
-
- /**
- * @brief Sets the packet source port
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] port - The port number to set
- * @return hICN error code
- */
- int (*set_src_port) (const hicn_packet_buffer_t *pkbuf, size_t pos,
- u16 port);
-
- /**
- * @brief Returns the packet source port
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] port - Pointer to the variable that will receive the port
- * number
- * @return hICN error code
- */
- int (*get_dst_port) (const hicn_packet_buffer_t *pkbuf, size_t pos,
- u16 *port);
-
- /**
- * @brief Sets the packet source port
- * @param [in] pkbuf - hICN packet buffer
- * @param [in, out] pos - Current position in the sequence of headers while
- * @param [out] port - The port number to set
- * @return hICN error code
- */
- int (*set_dst_port) (const hicn_packet_buffer_t *pkbuf, size_t pos,
- u16 port);
} hicn_ops_t;
#define DECLARE_HICN_OPS(protocol, len) \
@@ -667,12 +608,6 @@ typedef struct hicn_ops_s
ATTR_INIT (set_signature_size, protocol##_set_signature_size), \
ATTR_INIT (get_signature_padding, protocol##_get_signature_padding), \
ATTR_INIT (is_last_data, protocol##_is_last_data), \
- ATTR_INIT (get_ttl, protocol##_get_ttl), \
- ATTR_INIT (set_ttl, protocol##_set_ttl), \
- ATTR_INIT (get_src_port, protocol##_get_src_port), \
- ATTR_INIT (set_src_port, protocol##_set_src_port), \
- ATTR_INIT (get_dst_port, protocol##_get_dst_port), \
- ATTR_INIT (set_dst_port, protocol##_set_dst_port), \
}
/**
@@ -681,10 +616,14 @@ typedef struct hicn_ops_s
*/
extern const hicn_ops_t *const hicn_ops_vft[];
-#define PROT(pkbuf, pos) \
- ((pos < (HICN_FORMAT_LEN - 1)) ? \
- hicn_packet_get_format (pkbuf).as_u8[(pos) + 1] : \
- IPPROTO_NONE)
+static inline uint8_t
+PROT (const hicn_packet_buffer_t *pkbuf, int pos)
+{
+ if (pos < -1 || pos >= HICN_PACKET_FORMAT_SIZE - 1)
+ return IPPROTO_NONE;
+ hicn_packet_format_t format = hicn_packet_get_format (pkbuf);
+ return HICN_PACKET_FORMAT_GET (format, pos + 1);
+}
#define CALL_CHILD(method, pkbuf, pos, ...) \
hicn_ops_vft[PROT (pkbuf, (pos))]->method (pkbuf, (pos) + 1, ##__VA_ARGS__);
@@ -1029,48 +968,6 @@ extern const hicn_ops_t *const hicn_ops_vft[];
return HICN_LIB_ERROR_##error; \
}
-#define DECLARE_get_ttl(protocol, error) \
- int protocol##_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u8 *hops) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
-#define DECLARE_set_ttl(protocol, error) \
- int protocol##_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u8 hops) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
-#define DECLARE_get_src_port(protocol, error) \
- int protocol##_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u16 *port) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
-#define DECLARE_set_src_port(protocol, error) \
- int protocol##_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u16 port) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
-#define DECLARE_get_dst_port(protocol, error) \
- int protocol##_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u16 *port) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
-#define DECLARE_set_dst_port(protocol, error) \
- int protocol##_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \
- u16 port) \
- { \
- return HICN_LIB_ERROR_##error; \
- }
-
#endif /* HICN_OPS_H */
/*
diff --git a/lib/src/packet.c b/lib/src/packet.c
index f020e099c..bebfad23e 100644
--- a/lib/src/packet.c
+++ b/lib/src/packet.c
@@ -55,6 +55,15 @@ hicn_packet_get_type (const hicn_packet_buffer_t *pkbuf)
}
void
+hicn_packet_initialize_type (hicn_packet_buffer_t *pkbuf,
+ hicn_packet_type_t type)
+{
+ assert (pkbuf->format != HICN_PACKET_FORMAT_NONE);
+ pkbuf->type = type;
+ CALL (set_type, pkbuf, type);
+}
+
+void
hicn_packet_set_type (hicn_packet_buffer_t *pkbuf, hicn_packet_type_t type)
{
pkbuf->type = type;
@@ -84,7 +93,7 @@ hicn_packet_init_header (hicn_packet_buffer_t *pkbuf,
{
if (hicn_packet_is_undefined (pkbuf))
return HICN_LIB_ERROR_UNEXPECTED;
- if (hicn_packet_get_format (pkbuf).as_u32 == HICN_PACKET_FORMAT_NONE.as_u32)
+ if (hicn_packet_get_format (pkbuf) == HICN_PACKET_FORMAT_NONE)
return HICN_LIB_ERROR_UNEXPECTED;
if (!pkbuf_get_header (pkbuf))
return HICN_LIB_ERROR_UNEXPECTED;
@@ -124,8 +133,6 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf)
size_t signature_size;
int rc;
- hicn_packet_format_t *format = &pkbuf->format;
-
/* Bootstrap: assume IP packet, and get version from header */
switch (HICN_IP_VERSION (pkbuf_get_header (pkbuf)))
{
@@ -135,14 +142,17 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf)
case 6:
protocol = IPPROTO_IPV6;
break;
+ case 9:
+ protocol = IPPROTO_ENCAP; // new
+ break;
default:
goto ERR;
}
- format->as_u32 = 0;
- for (unsigned i = 0; i < HICN_FORMAT_LEN; i++)
+ hicn_packet_format_t *format = &pkbuf->format;
+ for (unsigned i = 0; i < HICN_PACKET_FORMAT_SIZE; i++)
{
- format->as_u8[i] = protocol;
+ HICN_PACKET_FORMAT_SET (*format, i, protocol);
/* Next protocol + increment offset */
switch (protocol)
@@ -257,7 +267,7 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf)
return HICN_LIB_ERROR_NONE;
ERR:
- *format = HICN_PACKET_FORMAT_NONE;
+ pkbuf->format = HICN_PACKET_FORMAT_NONE;
pkbuf->type = HICN_PACKET_TYPE_UNDEFINED;
return HICN_LIB_ERROR_UNEXPECTED;
}
@@ -346,10 +356,9 @@ hicn_packet_get_header_length_from_format (hicn_packet_format_t format,
size_t *header_length)
{
*header_length = 0;
- for (unsigned i = 0; i < HICN_FORMAT_LEN; i++)
- {
- *header_length += hicn_ops_vft[format.as_u8[i]]->header_len;
- }
+ HICN_PACKET_FORMAT_ENUMERATE (format, i, protocol, {
+ *header_length += hicn_ops_vft[protocol]->header_len;
+ });
return HICN_LIB_ERROR_NONE;
}
@@ -385,11 +394,10 @@ int
hicn_packet_compare (const hicn_packet_buffer_t *pkbuf1,
const hicn_packet_buffer_t *pkbuf2)
{
-
hicn_packet_format_t format1 = hicn_packet_get_format (pkbuf1);
hicn_packet_format_t format2 = hicn_packet_get_format (pkbuf2);
- if (format1.as_u32 != format2.as_u32)
+ if (format1 != format2)
return HICN_LIB_ERROR_UNEXPECTED;
size_t len1 = hicn_packet_get_len (pkbuf1);
@@ -563,7 +571,7 @@ hicn_packet_save_header (const hicn_packet_buffer_t *pkbuf, u8 *header,
size_t *header_len, bool copy_ah)
{
hicn_packet_format_t format = hicn_packet_get_format (pkbuf);
- if (copy_ah || !_is_ah (format))
+ if (copy_ah || !HICN_PACKET_FORMAT_IS_AH (format))
{
int rc = hicn_packet_get_header_len (pkbuf, header_len);
if (HICN_LIB_IS_ERROR (rc))
@@ -773,42 +781,6 @@ hicn_packet_get_signature (const hicn_packet_buffer_t *pkbuf,
}
int
-hicn_packet_get_ttl (const hicn_packet_buffer_t *pkbuf, u8 *hops)
-{
- return CALL (get_ttl, pkbuf, hops);
-}
-
-int
-hicn_packet_set_ttl (const hicn_packet_buffer_t *pkbuf, u8 hops)
-{
- return CALL (set_ttl, pkbuf, hops);
-}
-
-int
-hicn_packet_get_src_port (const hicn_packet_buffer_t *pkbuf, u16 *port)
-{
- return CALL (get_src_port, pkbuf, port);
-}
-
-int
-hicn_packet_set_src_port (const hicn_packet_buffer_t *pkbuf, u16 port)
-{
- return CALL (set_src_port, pkbuf, port);
-}
-
-int
-hicn_packet_get_dst_port (const hicn_packet_buffer_t *pkbuf, u16 *port)
-{
- return CALL (get_dst_port, pkbuf, port);
-}
-
-int
-hicn_packet_set_dst_port (const hicn_packet_buffer_t *pkbuf, u16 port)
-{
- return CALL (set_dst_port, pkbuf, port);
-}
-
-int
hicn_interest_rewrite (const hicn_packet_buffer_t *pkbuf,
const hicn_ip_address_t *addr_new,
hicn_ip_address_t *addr_old)
diff --git a/lib/src/protocol/ah.c b/lib/src/protocol/ah.c
index 645b0482b..ea028d559 100644
--- a/lib/src/protocol/ah.c
+++ b/lib/src/protocol/ah.c
@@ -50,12 +50,6 @@ DECLARE_get_payload_type (ah, UNEXPECTED);
DECLARE_set_payload_type (ah, UNEXPECTED);
DECLARE_is_last_data (ah, UNEXPECTED);
DECLARE_set_last_data (ah, UNEXPECTED);
-DECLARE_get_ttl (ah, UNEXPECTED);
-DECLARE_set_ttl (ah, UNEXPECTED);
-DECLARE_get_src_port (ah, UNEXPECTED);
-DECLARE_set_src_port (ah, UNEXPECTED);
-DECLARE_get_dst_port (ah, UNEXPECTED);
-DECLARE_set_dst_port (ah, UNEXPECTED);
int
ah_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
diff --git a/lib/src/protocol/icmp.c b/lib/src/protocol/icmp.c
index 71417a4e0..5ee70f088 100644
--- a/lib/src/protocol/icmp.c
+++ b/lib/src/protocol/icmp.c
@@ -44,12 +44,6 @@ DECLARE_get_signature (icmp, UNEXPECTED);
DECLARE_has_signature (icmp, UNEXPECTED);
DECLARE_is_last_data (icmp, UNEXPECTED);
DECLARE_set_last_data (icmp, UNEXPECTED);
-DECLARE_get_ttl (icmp, UNEXPECTED);
-DECLARE_set_ttl (icmp, UNEXPECTED);
-DECLARE_get_src_port (icmp, UNEXPECTED);
-DECLARE_set_src_port (icmp, UNEXPECTED);
-DECLARE_get_dst_port (icmp, UNEXPECTED);
-DECLARE_set_dst_port (icmp, UNEXPECTED);
int
icmp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c
index a13728d04..daa5a706a 100644
--- a/lib/src/protocol/ipv4.c
+++ b/lib/src/protocol/ipv4.c
@@ -60,7 +60,7 @@ ipv4_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
.id = htons (IPV4_DEFAULT_ID),
.frag_off = htons (IPV4_DEFAULT_FRAG_OFF),
.ttl = HICN_DEFAULT_TTL,
- .protocol = format.as_u8[pos + 1],
+ .protocol = HICN_PACKET_FORMAT_GET (format, pos + 1),
.csum = 0,
.saddr.as_u32 = 0,
.daddr.as_u32 = 0,
@@ -530,50 +530,6 @@ ipv4_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos)
return CALL_CHILD (set_last_data, pkbuf, pos);
}
-int
-ipv4_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops)
-{
- _ipv4_header_t *ipv4 = pkbuf_get_ipv4 (pkbuf);
-
- *hops = ipv4->ttl;
-
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-ipv4_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops)
-{
- _ipv4_header_t *ipv4 = pkbuf_get_ipv4 (pkbuf);
-
- ipv4->ttl = hops;
-
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-ipv4_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- return CALL_CHILD (get_src_port, pkbuf, pos, port);
-}
-
-int
-ipv4_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- return CALL_CHILD (set_src_port, pkbuf, pos, port);
-}
-
-int
-ipv4_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- return CALL_CHILD (get_dst_port, pkbuf, pos, port);
-}
-
-int
-ipv4_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- return CALL_CHILD (set_dst_port, pkbuf, pos, port);
-}
-
DECLARE_HICN_OPS (ipv4, IPV4_HDRLEN);
/*
diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c
index aec521afc..c5fa643aa 100644
--- a/lib/src/protocol/ipv6.c
+++ b/lib/src/protocol/ipv6.c
@@ -53,7 +53,7 @@ ipv6_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
(IPV6_DEFAULT_TRAFFIC_CLASS << 20) |
(IPV6_DEFAULT_FLOW_LABEL & 0xfffff)),
.len = htons(header_len - IPV6_HDRLEN),
- .nxt = format.as_u8[pos + 1],
+ .nxt = HICN_PACKET_FORMAT_GET(format, pos+1),
.hlim = HICN_DEFAULT_TTL,
};
/* clang-format on */
@@ -468,51 +468,6 @@ ipv6_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos)
return CALL_CHILD (set_last_data, pkbuf, pos);
}
-int
-ipv6_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops)
-{
- _ipv6_header_t *ipv6 = pkbuf_get_ipv6 (pkbuf);
-
- *hops = ipv6->hlim;
-
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-ipv6_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops)
-{
-
- _ipv6_header_t *ipv6 = pkbuf_get_ipv6 (pkbuf);
-
- ipv6->hlim = hops;
-
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-ipv6_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- return CALL_CHILD (get_src_port, pkbuf, pos, port);
-}
-
-int
-ipv6_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- return CALL_CHILD (set_src_port, pkbuf, pos, port);
-}
-
-int
-ipv6_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- return CALL_CHILD (get_dst_port, pkbuf, pos, port);
-}
-
-int
-ipv6_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- return CALL_CHILD (set_dst_port, pkbuf, pos, port);
-}
-
DECLARE_HICN_OPS (ipv6, IPV6_HDRLEN);
/*
diff --git a/lib/src/protocol/new.c b/lib/src/protocol/new.c
index 5308e8c0a..e86ce4753 100644
--- a/lib/src/protocol/new.c
+++ b/lib/src/protocol/new.c
@@ -24,13 +24,6 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
-DECLARE_get_ttl (new, UNEXPECTED);
-DECLARE_set_ttl (new, UNEXPECTED);
-DECLARE_get_src_port (new, UNEXPECTED);
-DECLARE_set_src_port (new, UNEXPECTED);
-DECLARE_get_dst_port (new, UNEXPECTED);
-DECLARE_set_dst_port (new, UNEXPECTED);
-
int
new_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
{
@@ -45,8 +38,9 @@ new_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
memset (new, 0, sizeof (_new_header_t));
_set_new_header_version (new);
- uint8_t ah_flag =
- format.as_u8[pos + 1] == IPPROTO_AH ? HICN_NEW_FLAG_SIG : 0;
+ uint8_t ah_flag = (HICN_PACKET_FORMAT_GET (format, pos + 1) == IPPROTO_AH) ?
+ HICN_NEW_FLAG_SIG :
+ 0;
new->flags |= ah_flag;
return CALL_CHILD (init_packet_header, pkbuf, pos);
@@ -128,6 +122,8 @@ new_get_interest_name (const hicn_packet_buffer_t *pkbuf, size_t pos,
return HICN_LIB_ERROR_NONE;
}
+// XXX never called and thus packet is never initialized as interest
+// DECLARE_set_interest_name (udp, UNEXPECTED);
int
new_set_interest_name (const hicn_packet_buffer_t *pkbuf, size_t pos,
const hicn_name_t *name)
diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c
index 822bd3e0c..e09495ecd 100644
--- a/lib/src/protocol/tcp.c
+++ b/lib/src/protocol/tcp.c
@@ -46,8 +46,6 @@ DECLARE_set_data_locator (tcp, UNEXPECTED);
DECLARE_get_data_name (tcp, UNEXPECTED);
DECLARE_set_data_name (tcp, UNEXPECTED);
DECLARE_set_payload_len (tcp, UNEXPECTED);
-DECLARE_get_ttl (tcp, UNEXPECTED);
-DECLARE_set_ttl (tcp, UNEXPECTED);
int tcp_update_checksums_incremental (const hicn_packet_buffer_t *pkbuf,
size_t pos, u16 *old_val, u16 *new_val,
@@ -115,7 +113,8 @@ tcp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
.urg_ptr = 65000,
};
- uint8_t ah_flag = ((format.as_u8[pos + 1] == IPPROTO_AH) ? AH_FLAG : 0);
+ uint8_t ah_flag =
+ (HICN_PACKET_FORMAT_GET (format, pos + 1) == IPPROTO_AH) ? AH_FLAG : 0;
tcp->flags |= ah_flag;
@@ -590,38 +589,6 @@ tcp_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos)
return HICN_LIB_ERROR_NONE;
}
-int
-tcp_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf);
- *port = ntohs (tcp->sport);
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-tcp_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf);
- tcp->sport = htons (port);
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-tcp_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf);
- *port = ntohs (tcp->dport);
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-tcp_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf);
- tcp->dport = htons (port);
- return HICN_LIB_ERROR_NONE;
-}
-
DECLARE_HICN_OPS (tcp, TCP_HDRLEN);
/*
diff --git a/lib/src/protocol/udp.c b/lib/src/protocol/udp.c
index ff2355b0c..56de0065f 100644
--- a/lib/src/protocol/udp.c
+++ b/lib/src/protocol/udp.c
@@ -30,8 +30,6 @@ DECLARE_set_data_locator (udp, UNEXPECTED);
DECLARE_get_data_name (udp, UNEXPECTED);
DECLARE_set_data_name (udp, UNEXPECTED);
DECLARE_set_payload_len (udp, UNEXPECTED);
-DECLARE_get_ttl (udp, UNEXPECTED);
-DECLARE_set_ttl (udp, UNEXPECTED);
int
udp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos)
@@ -299,42 +297,6 @@ udp_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos)
return CALL_CHILD (set_last_data, pkbuf, pos);
}
-int
-udp_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- _udp_header_t *udp = pkbuf_get_udp (pkbuf);
-
- *port = udp->src_port;
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-udp_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- _udp_header_t *udp = pkbuf_get_udp (pkbuf);
-
- udp->src_port = port;
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-udp_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port)
-{
- _udp_header_t *udp = pkbuf_get_udp (pkbuf);
-
- *port = udp->dst_port;
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-udp_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port)
-{
- _udp_header_t *udp = pkbuf_get_udp (pkbuf);
-
- udp->dst_port = port;
- return HICN_LIB_ERROR_NONE;
-}
-
DECLARE_HICN_OPS (udp, UDP_HDRLEN);
/*
diff --git a/lib/src/test/test_name.cc b/lib/src/test/test_name.cc
index cd9ff2d4d..0cf160f70 100644
--- a/lib/src/test/test_name.cc
+++ b/lib/src/test/test_name.cc
@@ -395,4 +395,7 @@ TEST_F (PrefixTest, PrefixLPM)
HICN_PREFIX (b009, "b009::/64");
EXPECT_EQ (hicn_prefix_lpm (&b007, &b009), (uint32_t) 12);
+
+ HICN_PREFIX (pfx, "1122:3344:5566:7788:9900:aabb:ccdd:eeff/128");
+ EXPECT_EQ (hicn_prefix_lpm (&pfx, &pfx), (uint32_t) 128);
}
diff --git a/lib/src/test/test_udp_header.cc b/lib/src/test/test_udp_header.cc
index 2853ee31b..2856c8ebf 100644
--- a/lib/src/test/test_udp_header.cc
+++ b/lib/src/test/test_udp_header.cc
@@ -125,7 +125,7 @@ protected:
TEST_F (UdpHeaderTest, GetFormat)
{
hicn_packet_format_t format = hicn_packet_get_format (&pkbuf_);
- EXPECT_EQ (format.as_u32, HICN_PACKET_FORMAT_IPV6_UDP.as_u32);
+ EXPECT_EQ (format, HICN_PACKET_FORMAT_IPV6_UDP);
}
TEST_F (UdpHeaderAHTest, GetFormat)
@@ -134,7 +134,7 @@ TEST_F (UdpHeaderAHTest, GetFormat)
hicn_packet_format_t format = hicn_packet_get_format (&pkbuf_);
// Check it corresponds to the new header format
- EXPECT_EQ (format.as_u32, HICN_PACKET_FORMAT_IPV6_UDP_AH.as_u32);
+ EXPECT_EQ (format, HICN_PACKET_FORMAT_IPV6_UDP_AH);
}
#if 0