diff options
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r-- | hicn-light/src/hicn/core/connection.c | 14 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection.h | 14 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/messageHandler.h | 81 |
3 files changed, 104 insertions, 5 deletions
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index 36fb20ec9..61db61ba7 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -45,6 +45,7 @@ struct connection { // file/hicnLightControl) this value is set to false so // that a base station can not disable wldr at the client Wldr *wldr; + }; Connection *connection_Create(IoOperations *ops) { @@ -112,11 +113,12 @@ bool connection_Send(const Connection *conn, Message *message) { return false; } -bool connection_SendCommandResponse(const Connection *conn, struct iovec *msg){ +bool connection_SendIOVBuffer(const Connection *conn, struct iovec *msg, + size_t size) { parcAssertNotNull(conn, "Parameter conn must be non-null"); parcAssertNotNull(msg, "Parameter message must be non-null"); - return ioOperations_SendCommandResponse(conn->ops, msg); + return ioOperations_SendIOVBuffer(conn->ops, msg, size); } static void _sendProbe(Connection *conn, unsigned probeType, uint8_t *message) { @@ -132,6 +134,14 @@ static void _sendProbe(Connection *conn, unsigned probeType, uint8_t *message) { } } +bool connection_SendBuffer(const Connection *conn, u8 * buffer, size_t length) +{ + struct iovec iov[1]; + iov[0].iov_base = buffer; + iov[0].iov_len = length; + return connection_SendIOVBuffer(conn, iov, 1); +} + void connection_Probe(Connection *conn) { _sendProbe(conn, PACKET_TYPE_PROBE_REQUEST, NULL); } diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h index efe8a66b9..9d7cd7c93 100644 --- a/hicn-light/src/hicn/core/connection.h +++ b/hicn-light/src/hicn/core/connection.h @@ -65,10 +65,17 @@ Connection *connection_Acquire(Connection *connection); bool connection_Send(const Connection *conn, Message *message); /** - * @function connection_SendCommandResponse - * @abstract Sends a response (ack/nack) for a command + * @function connection_SendIOVBuffer + * @abstract Sends an IOV buffer */ -bool connection_SendCommandResponse(const Connection *conn, struct iovec *msg); +bool connection_SendIOVBuffer(const Connection *conn, struct iovec *msg, + size_t size); + +/** + * @function connection_SendBuffer + * @abstract Sends a buffer + */ +bool connection_SendBuffer(const Connection *conn, u8 * buffer, size_t length); /** * Return the `IoOperations` instance associated with the specified `Connection` @@ -151,4 +158,5 @@ bool connection_WldrAutoStartAllowed(const Connection *conn); void connection_DetectLosses(Connection *conn, Message *message); void connection_HandleWldrNotification(Connection *conn, Message *message); + #endif // connection_h diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h index 56f75c113..c1fc0481a 100644 --- a/hicn-light/src/hicn/core/messageHandler.h +++ b/hicn-light/src/hicn/core/messageHandler.h @@ -53,6 +53,10 @@ #define expected_lbl wldr_notification_lbl.expected_lbl #define received_lbl wldr_notification_lbl.received_lbl +#include <hicn/core/forwarder.h> + +#define CONNECTION_ID_UNDEFINED -1 + static inline uint8_t messageHandler_GetIPPacketType(const uint8_t *message) { return HICN_IP_VERSION(message); } @@ -162,6 +166,83 @@ static inline uint8_t messageHandler_NextHeaderType(const uint8_t *message) { } } +/* Forward declarations */ +static inline void * messageHandler_GetSource(const uint8_t *message); + +/* Helpers */ + +// NOTE: this function is generalized from the one in hICN listener and takes a +// forwarder as parameter +static inline +const Connection * +_getConnectionFromPacket(Forwarder * forwarder, Address * localAddress, Address *packetSourceAddress) +{ + if (!packetSourceAddress) + return NULL; + + AddressPair *pair = addressPair_Create(localAddress, + packetSourceAddress); + const Connection * conn = connectionTable_FindByAddressPair( + forwarder_GetConnectionTable(forwarder), pair); + addressPair_Release(&pair); + + return conn; +} + +static inline +Address * +_createAddressFromPacket(const uint8_t *msgBuffer) +{ + Address *packetAddr = NULL; + 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); + packetAddr = addressCreateFromInet6(&addr_in6); + } 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); + packetAddr = addressCreateFromInet(&addr_in); + } + return packetAddr; +} + +/* Hooks */ + +/* ... */ + +/* Main hook handler */ + +/** + * \brief Handle incoming messages + * \param [in] forwarder - Reference to the Forwarder instance + * \param [in] connection_id - A hint on the connection ID on which the packet + * was received, CONNECTION_ID_UNDEFINED (-1) otherwise. + * \param [in] localAddress - Local listener address + * \param [in] messsage - Buffer possibly containing a hooked message + * \return Flag indicating whether the packet matched a hook and was + * (successfully or not) processed. + */ +static inline bool messageHandler_handleHooks(Forwarder * forwarder, + int connection_id, Address * localAddress, const uint8_t * message) +{ + /* ... */ + + return false; + +#if 0 // Enable and jump here when a handler has successfully processed the packet +END: + return true; +#endif +} + static inline bool messageHandler_IsTCP(const uint8_t *message) { if (messageHandler_NextHeaderType(message) != IPPROTO_TCP) return false; return true; |