aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
authorndnops <manangel@cisco.com>2019-08-20 16:08:26 +0000
committerndnops <manangel@cisco.com>2019-08-20 16:10:14 +0000
commitae1a51414080f89e5dcf2d0c1bf8cd51b38abf63 (patch)
treee05c01506138c0ba6fa14c5cfdd9c25998e1fe28 /hicn-light/src
parent1d896a7f11998346b7ceb0385b1c94ecb5c90c2e (diff)
[HICN-261] Incorrect handling of IPv6 link-local addresses / connections should not be created unless strictly needed.
Signed-off-by: ndnops <manangel@cisco.com> Change-Id: I10722996a6bf8868f50a5ac2aff6a937d3f87837
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/hicn/core/messageHandler.h133
-rw-r--r--hicn-light/src/hicn/io/hicnListener.c100
-rw-r--r--hicn-light/src/hicn/io/udpListener.c16
3 files changed, 136 insertions, 113 deletions
diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h
index 74535d80f..f1f91bc40 100644
--- a/hicn-light/src/hicn/core/messageHandler.h
+++ b/hicn-light/src/hicn/core/messageHandler.h
@@ -17,6 +17,7 @@
#define messageHandler
#include <stdlib.h>
+#include <unistd.h> // close
#include <hicn/hicn.h>
#include <hicn/core/messagePacketType.h>
@@ -175,6 +176,85 @@ static inline uint8_t messageHandler_NextHeaderType(const uint8_t *message) {
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 = 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 = 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 */
/**
@@ -187,21 +267,58 @@ static inline void *messageHandler_GetDestination(const uint8_t *message);
* (successfully or not) processed.
*/
static inline bool messageHandler_handleHooks(Forwarder * forwarder,
- const uint8_t * packet, int conn_id)
+ const uint8_t * packet, ListenerOps * listener, int fd, AddressPair * pair)
{
+ bool is_matched = false;
+
+ /* BEGIN Match */
+
#ifdef WITH_MAPME
- if (mapMe_isMapMe(packet)) {
- forwarder_ProcessMapMe(forwarder, packet, conn_id);
- goto END;
+ 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 */
- return false;
+ /* ... */
+
+ /* END Process */
-#if 1 // 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) {
diff --git a/hicn-light/src/hicn/io/hicnListener.c b/hicn-light/src/hicn/io/hicnListener.c
index e8cab9aca..d13dc5b4d 100644
--- a/hicn-light/src/hicn/io/hicnListener.c
+++ b/hicn-light/src/hicn/io/hicnListener.c
@@ -19,7 +19,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <unistd.h>
@@ -579,84 +578,6 @@ static void _handleWldrNotification(ListenerOps *listener, uint8_t *msgBuffer) {
message_Release(&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 = 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 = 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;
-}
static Message *_readMessage(ListenerOps * listener, int fd, uint8_t *msgBuffer) {
HicnListener * hicn = (HicnListener*)listener->context;
@@ -721,25 +642,8 @@ static Message *_readMessage(ListenerOps * listener, int fd, uint8_t *msgBuffer)
} else if (messageHandler_IsLoadBalancerProbe(msgBuffer)) {
_handleProbeMessage(listener, msgBuffer);
} else {
- const AddressPair * pair = _createRecvAddressPairFromPacket(msgBuffer);
- if (!pair)
- goto ERR;
-
- /* Find connection and eventually create it */
- const Connection * conn = connectionTable_FindByAddressPair(
- forwarder_GetConnectionTable(hicn->forwarder), pair);
- unsigned conn_id;
- if (conn == NULL) {
- conn_id = listener->createConnection(listener, fd, pair);
- } else {
- conn_id = connection_GetConnectionId(conn);
- }
-
- messageHandler_handleHooks(hicn->forwarder, msgBuffer, conn_id);
-
-ERR:
- parcMemory_Deallocate((void **)&msgBuffer);
-
+ messageHandler_handleHooks(hicn->forwarder, msgBuffer, listener, fd, NULL);
+ parcMemory_Deallocate((void **)&msgBuffer);
}
return message;
diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c
index 32f633984..02deb49d1 100644
--- a/hicn-light/src/hicn/io/udpListener.c
+++ b/hicn-light/src/hicn/io/udpListener.c
@@ -418,16 +418,16 @@ static void _handleWldrNotification(UdpListener *udp, unsigned connId,
message_Release(&message);
}
-static Message *_readMessage(ListenerOps * ops, int fd,
+static Message *_readMessage(ListenerOps * listener, int fd,
AddressPair *pair, uint8_t * packet, bool * processed) {
- UdpListener * udp = (UdpListener *)ops->context;
+ UdpListener * udp = (UdpListener *)listener->context;
Message *message = NULL;
unsigned connid;
bool foundConnection;
- const Connection *conn = _lookupConnection(ops, pair);
+ const Connection *conn = _lookupConnection(listener, pair);
if (conn) {
connid = connection_GetConnectionId(conn);
foundConnection = true;
@@ -449,7 +449,7 @@ static Message *_readMessage(ListenerOps * ops, int fd,
} else if (messageHandler_IsInterest(packet)) {
pktType = MessagePacketType_Interest;
if (!foundConnection) {
- connid = _createNewConnection(ops, fd, pair);
+ connid = _createNewConnection(listener, fd, pair);
}
} else {
printf("Got a packet that is not a data nor an interest, drop it!\n");
@@ -471,11 +471,13 @@ static Message *_readMessage(ListenerOps * ops, int fd,
*processed = true;
_handleProbeMessage(udp, packet);
} else {
- /* Generic hook handler */
+
+#if 0
if (!foundConnection)
- connid = _createNewConnection(ops, fd, pair);
+ connid = _createNewConnection(listener, fd, pair);
+#endif
- *processed = messageHandler_handleHooks(udp->forwarder, packet, connid);
+ *processed = messageHandler_handleHooks(udp->forwarder, packet, listener, fd, pair);
}
return message;