Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 7, 2024
1 parent c96f9bd commit b014989
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
37 changes: 17 additions & 20 deletions tunnels/adapters/device/tun/tun_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ typedef struct tun_device_state_s
{
tun_device_t *tdev;
line_t **thread_lines;

char *name;
char *ip_subnet;
char *ip_present;
unsigned int subnet_mask;
char *name;
char *ip_subnet;
char *ip_present;
unsigned int subnet_mask;

} tun_device_state_t;

static void upStream(tunnel_t *self, context_t *c)
{
(void) (self);
(void) (c);
assert(false);
tun_device_state_t *state = TSTATE((tunnel_t *) self);

if (c->payload)
{
dropContexPayload(c);
}
tun_device_t *tdev = state->tdev;
writeToTunDevce(tdev,c->payload);

dropContexPayload(c);
destroyContext(c);
}

Expand All @@ -48,18 +45,17 @@ static void downStream(tunnel_t *self, context_t *c)
static void onIPPacketReceived(struct tun_device_s *tdev, void *userdata, shift_buffer_t *buf, tid_t tid)
{
(void) tdev;
tunnel_t* self = userdata;
tun_device_state_t *state = TSTATE((tunnel_t*)self);

tunnel_t *self = userdata;
tun_device_state_t *state = TSTATE((tunnel_t *) self);

#if LOG_PACKET_INFO
printIPPacketInfo(tdev->name, rawBuf(buf));
#endif

// reuseBuffer(getWorkerBufferPool(tid), buf);

context_t* ctx = newContext(state->thread_lines[tid]);
ctx->payload = buf;
context_t *ctx = newContext(state->thread_lines[tid]);
ctx->payload = buf;
self->up->upStream(self->up, ctx);
}

Expand Down Expand Up @@ -102,11 +98,12 @@ tunnel_t *newTunDevice(node_instance_context_t *instance_info)
state->thread_lines[i] = newLine(i);
}

state->tdev = createTunDevice(state->name, false, state, onIPPacketReceived);
tunnel_t *t = newTunnel();

state->tdev = createTunDevice(state->name, false, t, onIPPacketReceived);
assignIpToTunDevice(state->tdev, state->ip_present, state->subnet_mask);
bringTunDeviceUP(state->tdev);

tunnel_t *t = newTunnel();
t->state = state;
t->upStream = &upStream;
t->downStream = &downStream;
Expand All @@ -129,5 +126,5 @@ tunnel_t *destroyTunDevice(tunnel_t *self)

tunnel_metadata_t getMetadataTunDevice(void)
{
return (tunnel_metadata_t) {.version = 0001, .flags = kNodeFlagChainHead};
return (tunnel_metadata_t) {.version = 0001, .flags = 0x0};
}
6 changes: 5 additions & 1 deletion tunnels/layer3/receiver/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

typedef struct layer3_receiver_state_s
{
char *tundevice_name;
char *tundevice_name;
tunnel_t *tun_device_tunnel;

} layer3_receiver_state_t;

Expand Down Expand Up @@ -93,6 +94,8 @@ tunnel_t *newLayer3Receiver(node_instance_context_t *instance_info)
return NULL;
}

state->tun_device_tunnel = tundevice_node->instance;

tunnel_t *t = newTunnel();

t->state = state;
Expand All @@ -103,6 +106,7 @@ tunnel_t *newLayer3Receiver(node_instance_context_t *instance_info)

return t;
}

api_result_t apiLayer3Receiver(tunnel_t *self, const char *msg)
{
(void) (self);
Expand Down

0 comments on commit b014989

Please sign in to comment.