Skip to content

Commit

Permalink
new node: ip manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 17, 2024
1 parent 41cdce8 commit cecfe12
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ option(INCLUDE_LAYER3_RECEIVER "link Layer3Receiver staticly to the core" TRUE)
option(INCLUDE_LAYER3_SENDER "link Layer3Sender staticly to the core" TRUE)
option(INCLUDE_LAYER3_IP_ROUTING_TABLE "link Layer3IpRoutingTable staticly to the core" TRUE)
option(INCLUDE_LAYER3_IP_OVERRIDER "link Layer3IpOverrider staticly to the core" TRUE)
option(INCLUDE_LAYER3_IP_MANIPULATOR "link Layer3IPManipulator staticly to the core" TRUE)
option(INCLUDE_LAYER3_TCP_MANIPULATOR "link Layer3TcpManipulator staticly to the core" TRUE)

option(INCLUDE_TCP_LISTENER "link TcpListener staticly to the core" TRUE)
Expand Down Expand Up @@ -193,6 +194,14 @@ target_link_directories(Waterwall PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tunnels/lay
target_link_libraries(Waterwall Layer3IpOverrider)
endif()

#layer3 ip manipulator
if (INCLUDE_LAYER3_IP_MANIPULATOR)
target_compile_definitions(Waterwall PUBLIC INCLUDE_LAYER3_IP_MANIPULATOR=1)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tunnels/layer3/ip/manipulator)
target_link_directories(Waterwall PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tunnels/layer3/ip/manipulator)
target_link_libraries(Waterwall Layer3IpManipulator)
endif()

#layer3 tcp manipulator
if (INCLUDE_LAYER3_TCP_MANIPULATOR)
target_compile_definitions(Waterwall PUBLIC INCLUDE_LAYER3_TCP_MANIPULATOR=1)
Expand Down
9 changes: 9 additions & 0 deletions core/static_tunnels.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
#include "tunnels/layer3/ip/overrider/ip_overrider.h"
#endif

#ifdef INCLUDE_LAYER3_IP_MANIPULATOR
#include "tunnels/layer3/ip/manipulator/ip_manipulator.h"
#endif


#ifdef INCLUDE_LAYER3_TCP_MANIPULATOR
#include "tunnels/layer3/tcp/manipulator/tcp_manipulator.h"
#endif
Expand Down Expand Up @@ -212,6 +217,10 @@ void loadStaticTunnelsIntoCore(void)
USING(Layer3IpOverrider);
#endif

#ifdef INCLUDE_LAYER3_IP_MANIPULATOR
USING(Layer3IpManipulator);
#endif

#ifdef INCLUDE_LAYER3_TCP_MANIPULATOR
USING(Layer3TcpManipulator);
#endif
Expand Down
8 changes: 4 additions & 4 deletions tunnels/layer3/ip/manipulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@


add_library(Layer3IPManipulator STATIC
add_library(Layer3IpManipulator STATIC
ip_manipulator.c

)

target_link_libraries(Layer3IPManipulator ww)
target_link_libraries(Layer3IpManipulator ww)

# add dependencies
include(${CMAKE_BINARY_DIR}/cmake/CPM.cmake)

target_include_directories(Layer3IPManipulator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../shared/layer3)
target_include_directories(Layer3IpManipulator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../shared/layer3)


target_compile_definitions(Layer3IPManipulator PRIVATE Layer3IPManipulator_VERSION=0.1)
target_compile_definitions(Layer3IpManipulator PRIVATE Layer3IpManipulator_VERSION=0.1)
20 changes: 10 additions & 10 deletions tunnels/layer3/ip/manipulator/ip_manipulator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "ip_manipulator.h"
#include "frand.h"
#include "hsocket.h"
#include "loggers/network_logger.h"
#include "packet_types.h"
#include "utils/jsonutils.h"
Expand Down Expand Up @@ -78,6 +76,7 @@ static inline void handleProtocolAction4(struct ipv4header *ip_header, dynamic_v
ip_header->protocol = protocol_action->value;
}
}

static inline void handleProtocolAction6(struct ipv6header *ip_header, dynamic_value_t *protocol_action)
{
if (protocol_action->status != kDvsEmpty)
Expand Down Expand Up @@ -122,22 +121,22 @@ static void downStream(tunnel_t *self, context_t *c)
destroyContext(c);
}

tunnel_t *newLayer3IPManipulator(node_instance_context_t *instance_info)
tunnel_t *newLayer3IpManipulator(node_instance_context_t *instance_info)
{
layer3_ip_manipulator_state_t *state = globalMalloc(sizeof(layer3_ip_manipulator_state_t));
memset(state, 0, sizeof(layer3_ip_manipulator_state_t));
cJSON *settings = instance_info->node_settings_json;

if (! (cJSON_IsObject(settings) && settings->child != NULL))
{
LOGF("JSON Error: Layer3IPManipulator->settings (object field) : The object was empty or invalid");
LOGF("JSON Error: Layer3IpManipulator->settings (object field) : The object was empty or invalid");
return NULL;
}

state->protocol_action = parseDynamicNumericValueFromJsonObject(
settings, "bit-reset", 36, "ICMP", "IGMP", "TCP", "EGP", "UDP", "RDP", "DCCP", "IPv6", "IPv6-Frag", "RSVP",
"GRE", "ESP", "AH", "ICMPv6", "NoNext", "DestOpts", "EIGRP", "OSPF", "IPIP", "PIM", "PCAP", "VRRP", "L2TP",
"ISIS", "SCTP", "FC", "UDPLite", "MPLS", "MANET", "HIP", "Shim6", "WESP", "ROHC", "Test1", "Test2", "Reserved");
settings, "bit-reset", 36, "icmp", "igmp", "tcp", "egp", "udp", "rdp", "dccp", "ipv6", "ipv6-frag", "rsvp",
"gre", "esp", "ah", "icmpv6", "nonext", "destopts", "eigrp", "ospf", "ipip", "pim", "pcap", "vrrp", "l2tp",
"isis", "sctp", "fc", "udplite", "mpls", "manet", "hip", "shim6", "wesp", "rohc", "test1", "test2", "reserved");

int map_array[36] = {1, 2, 6, 8, 17, 27, 33, 41, 43, 44, 47, 50, 51, 58, 59, 60, 88, 89,
94, 103, 108, 112, 115, 124, 132, 133, 136, 137, 138, 139, 140, 141, 142, 253, 254, 255};
Expand All @@ -146,6 +145,7 @@ tunnel_t *newLayer3IPManipulator(node_instance_context_t *instance_info)
{
state->protocol_action.value = map_array[state->protocol_action.status];
}

tunnel_t *t = newTunnel();

t->state = state;
Expand All @@ -155,20 +155,20 @@ tunnel_t *newLayer3IPManipulator(node_instance_context_t *instance_info)
return t;
}

api_result_t apiLayer3IPManipulator(tunnel_t *self, const char *msg)
api_result_t apiLayer3IpManipulator(tunnel_t *self, const char *msg)
{
(void) (self);
(void) (msg);
return (api_result_t) {0};
}

tunnel_t *destroyLayer3IPManipulator(tunnel_t *self)
tunnel_t *destroyLayer3IpManipulator(tunnel_t *self)
{
(void) (self);
return NULL;
}

tunnel_metadata_t getMetadataLayer3IPManipulator(void)
tunnel_metadata_t getMetadataLayer3IpManipulator(void)
{
return (tunnel_metadata_t) {.version = 0001, .flags = 0x0};
}
8 changes: 4 additions & 4 deletions tunnels/layer3/ip/manipulator/ip_manipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// Layer3Packet ------> manipulate ip header ------> Layer3Packet

tunnel_t * newLayer3IPManipulator(node_instance_context_t *instance_info);
api_result_t apiLayer3IPManipulator(tunnel_t *self, const char *msg);
tunnel_t * destroyLayer3IPManipulator(tunnel_t *self);
tunnel_metadata_t getMetadataLayer3IPManipulator(void);
tunnel_t * newLayer3IpManipulator(node_instance_context_t *instance_info);
api_result_t apiLayer3IpManipulator(tunnel_t *self, const char *msg);
tunnel_t * destroyLayer3IpManipulator(tunnel_t *self);
tunnel_metadata_t getMetadataLayer3IpManipulator(void);

0 comments on commit cecfe12

Please sign in to comment.