aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/messageHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/core/messageHandler.h')
-rw-r--r--hicn-light/src/hicn/core/messageHandler.h302
1 files changed, 102 insertions, 200 deletions
diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h
index b41c9a7f0..fe26d0579 100644
--- a/hicn-light/src/hicn/core/messageHandler.h
+++ b/hicn-light/src/hicn/core/messageHandler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -13,16 +13,17 @@
* limitations under the License.
*/
-#ifndef messageHandler
-#define messageHandler
+#ifndef HICNLIGHT_MESSAGE_HANDLER_H
+#define HICNLIGHT_MESSAGE_HANDLER_H
#include <stdlib.h>
#ifndef _WIN32
-#include <unistd.h> // close
-#endif
+#include <unistd.h> // close
+#endif /* _WIN32 */
#include <hicn/hicn.h>
-#include <hicn/core/messagePacketType.h>
+
+//#include <hicn/core/connection_table.h>
#define H(packet) ((hicn_header_t *)packet)
#define H6(packet) (H(packet)->v6.ip)
@@ -49,21 +50,21 @@
#define CONTROL_PORT 9695
#define HTTP_PORT 8080
+#define MIN_PROBE_SUFFIX 0xefffffff
+#define MAX_PROBE_SUFFIX 0xffffffff - 1
+
+// XXX Hardcoded packet format HF_INET6_TCP
+
#define IPV6_DEFAULT_VERSION 6
#define IPV6_DEFAULT_TRAFFIC_CLASS 0
#define IPV6_DEFAULT_FLOW_LABEL 0
-#define expected_lbl wldr_notification_lbl.expected_lbl
-#define received_lbl wldr_notification_lbl.received_lbl
+//#include <hicn/core/forwarder.h>
-#include <hicn/core/forwarder.h>
-
-#ifdef WITH_MAPME
-#include <hicn/core/mapme.h>
-#include <hicn/socket/api.h>
-#endif /* WITH_MAPME */
-
-#define CONNECTION_ID_UNDEFINED -1
+//#ifdef WITH_MAPME
+//#include <hicn/core/mapme.h>
+//#include <hicn/socket/api.h>
+//#endif /* WITH_MAPME */
#define BFD_PORT 3784
@@ -157,6 +158,7 @@ static inline size_t messageHandler_GetIPHeaderLength(unsigned ipVersion) {
return 0;
}
+#if 0
static inline bool messageHandler_IsValidHicnPacket(const uint8_t *message) {
uint8_t version = messageHandler_GetIPPacketType(message);
if (version == IPv6_TYPE || version == IPv4_TYPE) {
@@ -164,6 +166,7 @@ static inline bool messageHandler_IsValidHicnPacket(const uint8_t *message) {
}
return false;
}
+#endif
static inline uint8_t messageHandler_NextHeaderType(const uint8_t *message) {
switch (messageHandler_GetIPPacketType(message)) {
@@ -176,155 +179,6 @@ static inline uint8_t messageHandler_NextHeaderType(const uint8_t *message) {
}
}
-/* Forward declarations */
-static inline void * messageHandler_GetSource(const uint8_t *message);
-static inline void *messageHandler_GetDestination(const uint8_t *message);
-
-static const
-AddressPair *
-_createRecvAddressPairFromPacket(const uint8_t *msgBuffer) {
- Address *packetSrcAddr = NULL; /* This one is in the packet */
- Address *localAddr = NULL; /* This one is to be determined */
-
- if (messageHandler_GetIPPacketType(msgBuffer) == IPv6_TYPE) {
- struct sockaddr_in6 addr_in6;
- addr_in6.sin6_family = AF_INET6;
- addr_in6.sin6_port = htons(1234);
- addr_in6.sin6_flowinfo = 0;
- addr_in6.sin6_scope_id = 0;
- memcpy(&addr_in6.sin6_addr,
- (struct in6_addr *)messageHandler_GetSource(msgBuffer), 16);
- packetSrcAddr = addressCreateFromInet6(&addr_in6);
-
- /* We now determine the local address used to reach the packet src address */
- int sock = (int)socket (AF_INET6, SOCK_DGRAM, 0);
- if (sock < 0)
- goto ERR;
-
- struct sockaddr_in6 remote, local;
- memset(&remote, 0, sizeof(remote));
- remote.sin6_family = AF_INET6;
- remote.sin6_addr = addr_in6.sin6_addr;
- remote.sin6_port = htons(1234);
-
- socklen_t locallen = sizeof(local);
- if (connect(sock, (const struct sockaddr*)&remote, sizeof(remote)) == -1)
- goto ERR;
- if (getsockname(sock, (struct sockaddr*) &local, &locallen) == -1)
- goto ERR;
-
- local.sin6_port = htons(1234);
- localAddr = addressCreateFromInet6(&local);
-
- close(sock);
-
- } else if (messageHandler_GetIPPacketType(msgBuffer) == IPv4_TYPE) {
- struct sockaddr_in addr_in;
- addr_in.sin_family = AF_INET;
- addr_in.sin_port = htons(1234);
- memcpy(&addr_in.sin_addr,
- (struct in_addr *)messageHandler_GetSource(msgBuffer), 4);
- packetSrcAddr = addressCreateFromInet(&addr_in);
-
- /* We now determine the local address used to reach the packet src address */
-
- int sock = (int)socket (AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- perror("Socket error");
- goto ERR;
- }
-
- struct sockaddr_in remote, local;
- memset(&remote, 0, sizeof(remote));
- remote.sin_family = AF_INET;
- remote.sin_addr = addr_in.sin_addr;
- remote.sin_port = htons(1234);
-
- socklen_t locallen = sizeof(local);
- if (connect(sock, (const struct sockaddr*)&remote, sizeof(remote)) == -1)
- goto ERR;
- if (getsockname(sock, (struct sockaddr*) &local, &locallen) == -1)
- goto ERR;
-
- local.sin_port = htons(1234);
- localAddr = addressCreateFromInet(&local);
-
- close(sock);
- }
- /* As this is a receive pair, we swap src and dst */
- return addressPair_Create(localAddr, packetSrcAddr);
-
-ERR:
- perror("Socket error");
- return NULL;
-}
-
-/* Main hook handler */
-
-/**
- * \brief Handle incoming messages
- * \param [in] forwarder - Reference to the Forwarder instance
- * \param [in] packet - Packet buffer
- * \param [in] conn_id - A hint on the connection ID on which the packet
- * was received
- * \return Flag indicating whether the packet matched a hook and was
- * (successfully or not) processed.
- */
-static inline bool messageHandler_handleHooks(Forwarder * forwarder,
- const uint8_t * packet, ListenerOps * listener, int fd, AddressPair * pair)
-{
- bool is_matched = false;
-
- /* BEGIN Match */
-
-#ifdef WITH_MAPME
- bool is_mapme = mapme_isMapMe(packet);
- is_matched |= is_mapme;
-#endif /* WITH_MAPME */
-
- /* ... */
-
- /* END Match */
-
- if (!is_matched)
- return false;
-
- /*
- * Find existing connection or create a new one (we assume all processing
- * requires a valid connection.
- */
-
- if (!pair) {
- /* The hICN listener does not provide any address pair while UDP does */
- const AddressPair * pair = _createRecvAddressPairFromPacket(packet);
- if (!pair)
- return false;
- }
-
- /* Find connection and eventually create it */
- const Connection * conn = connectionTable_FindByAddressPair(
- forwarder_GetConnectionTable(forwarder), pair);
- unsigned conn_id;
- if (conn == NULL) {
- conn_id = listener->createConnection(listener, fd, pair);
- } else {
- conn_id = connection_GetConnectionId(conn);
- }
-
- /* BEGIN Process */
-
-#ifdef WITH_MAPME
- if (mapme_isMapMe(packet))
- forwarder_ProcessMapMe(forwarder, packet, conn_id);
-#endif /* WITH_MAPME */
-
- /* ... */
-
- /* END Process */
- parcMemory_Deallocate((void **)&packet);
- return true;
-}
-
static inline bool messageHandler_IsTCP(const uint8_t *message) {
if (messageHandler_NextHeaderType(message) != IPPROTO_TCP) return false;
return true;
@@ -432,7 +286,8 @@ static inline uint16_t messageHandler_GetExpectedWldrLabel(
return 0;
}
- return ntohs(((_icmp_wldr_header_t *)icmp_ptr)->expected_lbl);
+ return ntohs(
+ ((_icmp_wldr_header_t *)icmp_ptr)->wldr_notification_lbl.expected_lbl);
}
static inline uint16_t messageHandler_GetWldrLastReceived(
@@ -449,7 +304,8 @@ static inline uint16_t messageHandler_GetWldrLastReceived(
return 0;
}
- return ntohs(((_icmp_wldr_header_t *)icmp_ptr)->received_lbl);
+ return ntohs(
+ ((_icmp_wldr_header_t *)icmp_ptr)->wldr_notification_lbl.received_lbl);
}
static inline uint16_t messageHandler_GetWldrLabel(const uint8_t *message) {
@@ -524,6 +380,7 @@ static inline void messageHandler_UpdatePathLabel(uint8_t *message,
uint32_t pl_new_32bit =
(uint32_t)((((pl_old_8bit << 1) | (pl_old_8bit >> 7)) ^ outFace) << 24UL);
+ // XXX path label should be 8 bits now ?
messageHandler_SetPathLabel(message, pl_old_32bit, pl_new_32bit);
}
@@ -531,7 +388,7 @@ static inline void messageHandler_ResetPathLabel(uint8_t *message) {
messageHandler_SetPathLabel(message, messageHandler_GetPathLabel(message), 0);
}
-static inline uint16_t messageHandler_GetInterestLifetime(
+static inline uint32_t messageHandler_GetInterestLifetime(
const uint8_t *message) {
if (!messageHandler_IsTCP(message)) return 0;
@@ -541,6 +398,24 @@ static inline uint16_t messageHandler_GetInterestLifetime(
return lifetime;
}
+static inline bool messageHandler_SetInterestLifetime(uint8_t *message,
+ u32 lifetime) {
+ if (!messageHandler_IsTCP(message)) return false;
+
+ int res = hicn_interest_set_lifetime((hicn_header_t *)message, lifetime);
+ if (res < 0) return false;
+ return true;
+}
+
+static inline bool messageHandler_SetDataExpiryTime(uint8_t *message,
+ u32 lifetime) {
+ if (!messageHandler_IsTCP(message)) return false;
+
+ int res = hicn_data_set_expiry_time((hicn_header_t *)message, lifetime);
+ if (res < 0) return false;
+ return true;
+}
+
static inline bool messageHandler_HasInterestLifetime(const uint8_t *message) {
if (!messageHandler_IsTCP(message)) return false;
@@ -650,7 +525,7 @@ static inline void messageHandler_SetWldrNotification(uint8_t *notification,
case IPv6_TYPE: {
*h = (hicn_header_t){.v6 = {
.ip =
- {
+ (_ipv6_header_t){
.version_class_flow = htonl(
(IPV6_DEFAULT_VERSION << 28) |
(IPV6_DEFAULT_TRAFFIC_CLASS << 20) |
@@ -659,13 +534,17 @@ static inline void messageHandler_SetWldrNotification(uint8_t *notification,
.nxt = IPPROTO_ICMPV6,
.hlim = 5,
},
+ /*
.wldr =
{
.type = ICMP_WLDR_TYPE,
.code = ICMP_WLDR_CODE,
- .expected_lbl = htons(expected),
- .received_lbl = htons(received),
- },
+ .wldr_notification_lbl =
+ {
+ .expected_lbl = htons(expected),
+ .received_lbl = htons(received),
+ },
+ },*/
}};
messageHandler_SetSource_IPv6(
notification,
@@ -682,56 +561,78 @@ static inline void messageHandler_SetWldrNotification(uint8_t *notification,
}
}
-static inline uint8_t * messageHandler_CreateProbePacket(hicn_format_t format,
- uint32_t probe_lifetime){
+static inline void messageHandler_ModifySuffix(uint8_t *packet,
+ uint32_t new_suffix) {
+ hicn_format_t format;
+ hicn_name_t name;
+ hicn_packet_get_format((hicn_header_t *)packet, &format);
+ hicn_interest_get_name(format, (hicn_header_t *)packet, &name);
+ hicn_name_set_seq_number(&name, new_suffix);
+ hicn_interest_set_name(format, (hicn_header_t *)packet, &name);
+}
+
+static inline uint8_t *messageHandler_CreateProbePacket(
+ hicn_format_t format, uint32_t probe_lifetime) {
size_t header_length;
hicn_packet_get_header_length_from_format(format, &header_length);
- uint8_t *pkt = parcMemory_AllocateAndClear(header_length);
+ uint8_t *pkt = (uint8_t *)calloc(header_length, 1);
- hicn_packet_init_header(format, (hicn_header_t *) pkt);
+ hicn_packet_init_header(format, (hicn_header_t *)pkt);
- hicn_packet_set_dst_port(format, (hicn_header_t *) pkt, BFD_PORT);
- hicn_interest_set_lifetime ((hicn_header_t *) pkt, probe_lifetime);
+ hicn_packet_set_dst_port(format, (hicn_header_t *)pkt, BFD_PORT);
+ hicn_interest_set_lifetime((hicn_header_t *)pkt, probe_lifetime);
return pkt;
}
-static inline void messageHandler_CreateProbeReply(uint8_t * probe,
- hicn_format_t format){
-
+static inline void messageHandler_CreateProbeReply(uint8_t *probe,
+ hicn_format_t format) {
hicn_name_t probe_name;
- hicn_interest_get_name (format,
- (const hicn_header_t *) probe, &probe_name);
+ hicn_interest_get_name(format, (const hicn_header_t *)probe, &probe_name);
ip_address_t probe_locator;
- hicn_interest_get_locator (format,
- (const hicn_header_t *) probe, &probe_locator);
+ hicn_interest_get_locator(format, (const hicn_header_t *)probe,
+ &probe_locator);
uint16_t src_prt;
uint16_t dst_prt;
- hicn_packet_get_src_port(format, (const hicn_header_t *) probe, &src_prt);
- hicn_packet_get_dst_port(format, (const hicn_header_t *) probe, &dst_prt);
- hicn_packet_set_src_port(format, (hicn_header_t *) probe, dst_prt);
- hicn_packet_set_dst_port(format, (hicn_header_t *) probe, src_prt);
+ hicn_packet_get_src_port(format, (const hicn_header_t *)probe, &src_prt);
+ hicn_packet_get_dst_port(format, (const hicn_header_t *)probe, &dst_prt);
+ hicn_packet_set_src_port(format, (hicn_header_t *)probe, dst_prt);
+ hicn_packet_set_dst_port(format, (hicn_header_t *)probe, src_prt);
- hicn_data_set_name (format, (hicn_header_t *) probe, &probe_name);
- hicn_data_set_locator (format, (hicn_header_t *) probe, &probe_locator);
- hicn_data_set_expiry_time ((hicn_header_t *) probe, 0);
+ hicn_data_set_name(format, (hicn_header_t *)probe, &probe_name);
+ hicn_data_set_locator(format, (hicn_header_t *)probe, &probe_locator);
+ hicn_data_set_expiry_time((hicn_header_t *)probe, 0);
}
-static inline hicn_name_t * messageHandler_CreateProbeName(const ip_prefix_t *address){
- hicn_name_t * name = parcMemory_AllocateAndClear(sizeof(hicn_name_t));
+static inline hicn_name_t *messageHandler_CreateProbeName(
+ const ip_prefix_t *address) {
+ hicn_name_t *name = (hicn_name_t *)calloc(sizeof(hicn_name_t), 1);
hicn_name_create_from_ip_prefix(address, 0, name);
return name;
}
-static inline void messageHandler_SetProbeName(uint8_t * probe, hicn_format_t format,
- hicn_name_t * name, uint32_t seq){
- hicn_name_set_seq_number (name, seq);
- hicn_interest_set_name(format, (hicn_header_t *) probe, name);
+static inline void messageHandler_SetProbeName(uint8_t *probe,
+ hicn_format_t format,
+ hicn_name_t *name,
+ uint32_t seq) {
+ hicn_name_set_seq_number(name, seq);
+ hicn_interest_set_name(format, (hicn_header_t *)probe, name);
}
-static inline bool messageHandler_IsAProbe(const uint8_t *packet){
+static inline bool messageHandler_IsAProbe(const uint8_t *packet) {
+ hicn_format_t format;
+ hicn_name_t name;
+ uint32_t seq;
+ hicn_packet_get_format((hicn_header_t *)packet, &format);
+ hicn_data_get_name(format, (hicn_header_t *)packet, &name);
+ hicn_name_get_seq_number(&name, &seq);
+ if (seq >= MIN_PROBE_SUFFIX && seq <= MAX_PROBE_SUFFIX) return true;
+ return false;
+
+#if 0
+ // old probe version
uint16_t src_prt;
uint16_t dst_prt;
hicn_packet_get_src_port (HF_INET6_TCP, (const hicn_header_t *) packet, &src_prt);
@@ -753,6 +654,7 @@ static inline bool messageHandler_IsAProbe(const uint8_t *packet){
}
return false;
+#endif
}
-#endif // Metis_metis_MessageHandler
+#endif /* HICNLIGHT_MESSAGE_HANDLER_H */