aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/config/configuration.c8
-rw-r--r--hicn-light/src/config/configurationListeners.c70
-rw-r--r--hicn-light/src/config/configurationListeners.h9
-rw-r--r--hicn-light/src/config/controlAddListener.c2
-rw-r--r--hicn-light/src/utils/address.c30
-rw-r--r--hicn-light/src/utils/address.h24
-rw-r--r--hicn-light/src/utils/utils.c24
-rw-r--r--hicn-light/src/utils/utils.h12
8 files changed, 128 insertions, 51 deletions
diff --git a/hicn-light/src/config/configuration.c b/hicn-light/src/config/configuration.c
index 48c26b4a2..3d25e425d 100644
--- a/hicn-light/src/config/configuration.c
+++ b/hicn-light/src/config/configuration.c
@@ -330,14 +330,14 @@ struct iovec *configuration_ProcessCreateTunnel(Configuration *config,
if (!symbolicNameTable_Exists(config->symbolicNameTable, symbolicName)) {
if (control->ipType == ADDR_INET) {
source =
- utils_AddressFromInet(&control->localIp.ipv4, &control->localPort);
+ addressFromInaddr4Port(&control->localIp.ipv4, &control->localPort);
destination =
- utils_AddressFromInet(&control->remoteIp.ipv4, &control->remotePort);
+ addressFromInaddr4Port(&control->remoteIp.ipv4, &control->remotePort);
} else if (control->ipType == ADDR_INET6) {
source =
- utils_AddressFromInet6(&control->localIp.ipv6, &control->localPort);
+ addressFromInaddr6Port(&control->localIp.ipv6, &control->localPort);
destination =
- utils_AddressFromInet6(&control->remoteIp.ipv6, &control->remotePort);
+ addressFromInaddr6Port(&control->remoteIp.ipv6, &control->remotePort);
} else {
printf("Invalid IP type.\n"); // will generate a Nack
}
diff --git a/hicn-light/src/config/configurationListeners.c b/hicn-light/src/config/configurationListeners.c
index 3024d7bba..8a3ecddfc 100644
--- a/hicn-light/src/config/configurationListeners.c
+++ b/hicn-light/src/config/configurationListeners.c
@@ -35,6 +35,7 @@
#include <src/io/tcpListener.h>
#include <src/io/udpListener.h>
+#include <src/utils/address.h>
#include <src/utils/addressList.h>
#include <src/utils/commands.h>
#include <src/utils/utils.h>
@@ -210,6 +211,15 @@ static bool _addEther(Configuration *config, add_listener_command *control,
return false;
}
+/*
+ * Create a new IPV4/TCP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr4 The ipv4 address in network byte order
+ * @param [in] port The port number in network byte order
+ *
+ * return true if success, false otherwise
+ */
static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
uint16_t *port) {
bool success = false;
@@ -217,7 +227,7 @@ static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons(*port);
+ addr.sin_port = *port;
addr.sin_addr.s_addr = *addr4;
ListenerOps *ops = tcpListener_CreateInet(forwarder, addr);
@@ -229,6 +239,15 @@ static bool _setupTcpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
return success;
}
+/*
+ * Create a new IPV4/UDP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr4 The ipv4 address in network byte order
+ * @param [in] port The port number in network byte order
+ *
+ * return true if success, false otherwise
+ */
static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
uint16_t *port) {
bool success = false;
@@ -236,7 +255,7 @@ static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons(*port);
+ addr.sin_port = *port;
addr.sin_addr.s_addr = *addr4;
ListenerOps *ops = udpListener_CreateInet(forwarder, addr);
@@ -248,6 +267,15 @@ static bool _setupUdpListenerOnInet(Forwarder *forwarder, ipv4_addr_t *addr4,
return success;
}
+/*
+ * Create a new IPV6/TCP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr6 The ipv6 address in network byte order
+ * @param [in] port The port number in network byte order
+ *
+ * return true if success, false otherwise
+ */
static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
ipv6_addr_t *addr6, uint16_t *port,
uint32_t scopeId) {
@@ -256,7 +284,7 @@ static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
- addr.sin6_port = htons(*port);
+ addr.sin6_port = *port;
addr.sin6_addr = *addr6;
addr.sin6_scope_id = scopeId;
@@ -269,6 +297,15 @@ static bool _setupTcpListenerOnInet6Light(Forwarder *forwarder,
return success;
}
+/*
+ * Create a new IPV6/UDP listener.
+ *
+ * @param [in,out] forwarder The hicn-light forwarder instance
+ * @param [in] addr6 The ipv6 address in network byte order
+ * @param [in] port The port number in network byte order
+ *
+ * return true if success, false otherwise
+ */
static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
ipv6_addr_t *addr6, uint16_t *port) {
bool success = false;
@@ -276,7 +313,7 @@ static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
addr.sin6_family = AF_INET6;
- addr.sin6_port = htons(*port);
+ addr.sin6_port = *port;
addr.sin6_addr = *addr6;
addr.sin6_scope_id = 0;
@@ -289,6 +326,15 @@ static bool _setupUdpListenerOnInet6Light(Forwarder *forwarder,
return success;
}
+/*
+ * Create a new HICN listener.
+ *
+ * @param [in] config The configuration
+ * @param [in] control The control command
+ * @param [in] port The connection id of the command
+ *
+ * return true if success, false otherwise
+ */
bool _addHicn(Configuration *config, add_listener_command *control,
unsigned ingressId) {
bool success = false;
@@ -298,7 +344,7 @@ bool _addHicn(Configuration *config, add_listener_command *control,
switch (control->addressType) {
case ADDR_INET: {
localAddress =
- utils_AddressFromInet(&control->address.ipv4, &control->port);
+ addressFromInaddr4Port(&control->address.ipv4, &control->port);
success = _setupHicnListenerOnInet4(configuration_GetForwarder(config),
symbolic, localAddress);
break;
@@ -306,7 +352,7 @@ bool _addHicn(Configuration *config, add_listener_command *control,
case ADDR_INET6: {
localAddress =
- utils_AddressFromInet6(&control->address.ipv6, &control->port);
+ addressFromInaddr6Port(&control->address.ipv6, &control->port);
success = _setupHicnListenerOnInet6(configuration_GetForwarder(config),
symbolic, localAddress);
break;
@@ -449,12 +495,12 @@ struct iovec *configurationListeners_AddPunting(Configuration *config,
bool success = false;
if (control->addressType == ADDR_INET) {
- Address *address = utils_AddressFromInet(&control->address.ipv4, &port);
+ Address *address = addressFromInaddr4Port(&control->address.ipv4, &port);
Punting *punting = puntingCreate(symbolicOrConnid, address, len);
success = _AddPuntingInet(config, punting, ingressId);
addressDestroy(&address);
} else if (control->addressType == ADDR_INET6) {
- Address *address = utils_AddressFromInet6(&control->address.ipv6, &port);
+ Address *address = addressFromInaddr6Port(&control->address.ipv6, &port);
Punting *punting = puntingCreate(symbolicOrConnid, address, len);
success = _AddPuntingInet6(config, punting, ingressId);
addressDestroy(&address);
@@ -536,6 +582,10 @@ void configurationListeners_SetutpLocalIPv4(const Configuration *config,
uint16_t port) {
Forwarder *forwarder = configuration_GetForwarder(config);
in_addr_t addr = inet_addr("127.0.0.1");
- _setupUdpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr), &port);
- _setupTcpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr), &port);
+ uint16_t network_byte_order_port = htons(port);
+
+ _setupUdpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
+ &network_byte_order_port);
+ _setupTcpListenerOnInet(forwarder, (ipv4_addr_t *)&(addr),
+ &network_byte_order_port);
}
diff --git a/hicn-light/src/config/configurationListeners.h b/hicn-light/src/config/configurationListeners.h
index c97617d81..25d40e27e 100644
--- a/hicn-light/src/config/configurationListeners.h
+++ b/hicn-light/src/config/configurationListeners.h
@@ -54,6 +54,15 @@ bool configurationListeners_Remove(const Configuration *config);
// light functions
+/**
+ * Add new listener.
+ *
+ * @param request The request coming from hicnLightControl or the
+ * configuration file. The bytes in the request are
+ * ordered following the network byte order convention.
+ *
+ * @param ingressId The connection id of the incoming request.
+ */
struct iovec *configurationListeners_Add(Configuration *config,
struct iovec *request,
unsigned ingressId);
diff --git a/hicn-light/src/config/controlAddListener.c b/hicn-light/src/config/controlAddListener.c
index 03900a861..2cabfd035 100644
--- a/hicn-light/src/config/controlAddListener.c
+++ b/hicn-light/src/config/controlAddListener.c
@@ -111,7 +111,7 @@ static CommandReturn _CreateListener(CommandParser *parser, CommandOps *ops,
// Fill remaining payload fields
addListenerCommand->listenerMode = mode;
addListenerCommand->connectionType = type;
- addListenerCommand->port = (uint16_t)atoi(port);
+ addListenerCommand->port = htons((uint16_t)atoi(port));
strcpy(addListenerCommand->symbolic, symbolic);
// send message and receive response
diff --git a/hicn-light/src/utils/address.c b/hicn-light/src/utils/address.c
index ee1167de0..a59c6a59d 100644
--- a/hicn-light/src/utils/address.c
+++ b/hicn-light/src/utils/address.c
@@ -119,6 +119,36 @@ Address *addressCreateFromInet6(struct sockaddr_in6 *addr_in6) {
return result;
}
+Address *addressFromInaddr4Port(in_addr_t *addr4, in_port_t *port) {
+ struct sockaddr_in addr;
+ memset(&addr, 0, sizeof(addr));
+
+ // We assume address and port are already written in memory in network byte
+ // order
+ addr.sin_family = AF_INET;
+ addr.sin_port = *port;
+ addr.sin_addr.s_addr = *addr4;
+
+ Address *result = addressCreateFromInet(&addr);
+ return result;
+}
+
+Address *addressFromInaddr6Port(struct in6_addr *addr6, in_port_t *port) {
+ struct sockaddr_in6 addr;
+ memset(&addr, 0, sizeof(addr));
+ addr.sin6_family = AF_INET6;
+
+ // We assume address and port are already written in memory in network byte
+ // order
+ addr.sin6_port = *port;
+ addr.sin6_addr = *addr6;
+ addr.sin6_scope_id = 0;
+ // Other 2 fields: scope_id and flowinfo, do not know what to put inside.
+
+ Address *result = addressCreateFromInet6(&addr);
+ return result;
+}
+
Address *addressCreateFromLink(const uint8_t *linkaddr, size_t length) {
parcAssertNotNull(linkaddr, "Parameter must be non-null");
diff --git a/hicn-light/src/utils/address.h b/hicn-light/src/utils/address.h
index d8b0efcab..ca3141ede 100644
--- a/hicn-light/src/utils/address.h
+++ b/hicn-light/src/utils/address.h
@@ -144,6 +144,30 @@ Address *addressCreateFromInet(struct sockaddr_in *addr_in);
Address *addressCreateFromInet6(struct sockaddr_in6 *addr_in6);
/**
+ * Convert an internet address family (IPv4) to the address format used by the
+ * Fwd.
+ *
+ * @param [in] addr4 IPV4 address in *Network byte order*
+ * @param [in] port Port number in *Network byte order*
+ *
+ * @return A new instance of `Address` that must eventually be destroyed by
+ * calling {@link addressDestroy}()
+ */
+Address *addressFromInaddr4Port(in_addr_t *addr4, in_port_t *port);
+
+/**
+ * Convert an internet address family (IPv6) to the address format used by the
+ * Fwd
+ *
+ * @param [in] addr6 IPV4 address in *Network byte order*
+ * @param [in] port Port number in *Network byte order*
+ *
+ * @return A new instance of `Address` that must eventually be destroyed by
+ * calling {@link addressDestroy}()
+ */
+Address *addressFromInaddr6Port(struct in6_addr *addr6, in_port_t *port);
+
+/**
* Create a new `Address` instance, initialized from a Link address.
*
* User must know the link address format (i.e. token ring vs ethernet) and have
diff --git a/hicn-light/src/utils/utils.c b/hicn-light/src/utils/utils.c
index 3ab837eeb..e40b219fb 100644
--- a/hicn-light/src/utils/utils.c
+++ b/hicn-light/src/utils/utils.c
@@ -69,30 +69,6 @@ bool utils_ValidateSymbolicName(const char *symbolic) {
return success;
}
-Address *utils_AddressFromInet(in_addr_t *addr4, in_port_t *port) {
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = *port;
- addr.sin_addr.s_addr = *addr4;
-
- Address *result = addressCreateFromInet(&addr);
- return result;
-}
-
-Address *utils_AddressFromInet6(struct in6_addr *addr6, in_port_t *port) {
- struct sockaddr_in6 addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = *port;
- addr.sin6_addr = *addr6;
- addr.sin6_scope_id = 0;
- // Other 2 fields: scope_id and flowinfo, do not know what to put inside.
-
- Address *result = addressCreateFromInet6(&addr);
- return result;
-}
-
struct iovec *utils_CreateAck(header_control_message *header, void *payload,
size_t payloadLen) {
struct iovec *response =
diff --git a/hicn-light/src/utils/utils.h b/hicn-light/src/utils/utils.h
index 1d2616941..2c4efa965 100644
--- a/hicn-light/src/utils/utils.h
+++ b/hicn-light/src/utils/utils.h
@@ -32,18 +32,6 @@ bool utils_IsNumber(const char *string);
bool utils_ValidateSymbolicName(const char *symbolic);
/**
- * Convert an internet address family (IPv4) to the address format used by the
- * Fwd
- */
-Address *utils_AddressFromInet(in_addr_t *addr4, in_port_t *port);
-
-/**
- * Convert an internet address family (IPv6) to the address format used by the
- * Fwd
- */
-Address *utils_AddressFromInet6(struct in6_addr *addr6, in_port_t *port);
-
-/**
*Create an Ack message instance as a response of a control successfully
*completed.
*/