Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap-chain-net-srv-vpn
1 result
Show changes
Commits on Source (6)
......@@ -325,6 +325,7 @@ static int s_callback_response_success(dap_chain_net_srv_t * a_srv, uint32_t a_u
HASH_ADD(hh, s_clients,usage_id,sizeof(a_usage_id),l_usage_client);
l_srv_session->usage_active = l_usage_active;
l_srv_session->usage_active->is_active = true;
log_it(L_NOTICE,"Enable VPN service");
if ( l_srv_ch_vpn ){ // If channel is already opened
......@@ -514,6 +515,7 @@ void srv_ch_vpn_delete(dap_stream_ch_t* ch, void* arg)
}
if ( l_is_unleased ){ // If unleased
log_it(L_DEBUG, "Unlease address %s and store in treshold", inet_ntoa(l_ch_vpn->addr_ipv4));
dap_chain_net_srv_vpn_item_ipv4_t * l_item_unleased = DAP_NEW_Z(dap_chain_net_srv_vpn_item_ipv4_t);
l_item_unleased->addr.s_addr = l_ch_vpn->addr_ipv4.s_addr;
l_item_unleased->next = l_srv_vpn->ipv4_unleased;
......@@ -611,7 +613,7 @@ static void s_ch_packet_out(dap_stream_ch_t* a_ch, void* a_arg)
dap_stream_ch_pkt_write( l_usage->clients->ch , DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_NOTIFY_STOPPED , NULL, 0 );
return;
}
if ( ! l_usage->receipt ){
if ( (! l_usage->is_free) && (! l_usage->receipt) ){
log_it(L_WARNING, "No active receipt, switching off");
dap_stream_ch_set_ready_to_write(a_ch,false);
dap_stream_ch_set_ready_to_read(a_ch,false);
......@@ -840,7 +842,8 @@ void s_ch_packet_in(dap_stream_ch_t* a_ch, void* arg)
}
dap_chain_net_srv_vpn_item_ipv4_t * l_item_ipv4 = l_srv_vpn->ipv4_unleased;
if ( l_item_ipv4){
l_ch_vpn->addr_ipv4.s_addr = l_item_ipv4->addr.s_addr;
log_it(L_WARNING,"We have unleased ip address");
l_ch_vpn->addr_ipv4.s_addr = htonl(l_item_ipv4->addr.s_addr);
pthread_rwlock_wrlock( &s_clients_rwlock );
HASH_ADD(hh, s_ch_vpn_addrs, addr_ipv4, sizeof (l_ch_vpn->addr_ipv4), l_ch_vpn);
......@@ -856,22 +859,38 @@ void s_ch_packet_in(dap_stream_ch_t* a_ch, void* arg)
memcpy(l_pkt_out->data, &l_ch_vpn->addr_ipv4, sizeof(l_ch_vpn->addr_ipv4));
memcpy(l_pkt_out->data + sizeof(l_ch_vpn->addr_ipv4), &s_raw_server->ipv4_host,
sizeof(s_raw_server->ipv4_host));
dap_stream_ch_pkt_write(a_ch, DAP_STREAM_CH_PKT_TYPE_NET_SRV_VPN_DATA, l_pkt_out,
dap_stream_ch_pkt_write(a_ch, DAP_STREAM_CH_PKT_TYPE_NET_SRV_VPN_DATA , l_pkt_out,
l_pkt_out->header.op_data.data_size + sizeof(l_pkt_out->header));
dap_stream_ch_set_ready_to_write(a_ch, true);
log_it(L_NOTICE, "VPN client address %s leased", inet_ntoa(l_ch_vpn->addr_ipv4));
log_it(L_INFO, "\tgateway %s", inet_ntoa(s_raw_server->ipv4_host));
log_it(L_INFO, "\tmask %s", inet_ntoa(s_raw_server->ipv4_network_mask));
log_it(L_INFO, "\taddr %s", inet_ntoa(s_raw_server->ipv4_network_addr));
log_it(L_INFO, "\tlast_addr %s", inet_ntoa(s_raw_server->ipv4_lease_last));
//dap_stream_ch_set_ready_to_write(a_ch, true);
l_srv_vpn->ipv4_unleased = l_item_ipv4->next;
DAP_DELETE(l_item_ipv4);
}else{
struct in_addr n_addr={0};
struct in_addr n_addr = { 0 }, n_addr_max;
n_addr.s_addr = ntohl(s_raw_server->ipv4_lease_last.s_addr);
n_addr.s_addr++;
if( (uint32_t)n_addr.s_addr >= (uint32_t)(ntohl(s_raw_server->ipv4_network_addr.s_addr)|
~(ntohl(s_raw_server->ipv4_network_mask.s_addr))) ) { // If the addres still in the network
n_addr.s_addr = ntohl(n_addr.s_addr);
l_ch_vpn->addr_ipv4.s_addr = n_addr.s_addr;
s_raw_server->ipv4_lease_last.s_addr = n_addr.s_addr;
n_addr_max.s_addr = (ntohl(s_raw_server->ipv4_network_addr.s_addr)
| ~ntohl(s_raw_server->ipv4_network_mask.s_addr));
// Just for log output we revert it back and forward
n_addr.s_addr = htonl(n_addr.s_addr);
n_addr_max.s_addr = htonl(n_addr_max.s_addr);
log_it(L_DEBUG, "Check if is address is lesser than");
log_it(L_DEBUG," new_address = %s", inet_ntoa(n_addr));
log_it(L_DEBUG," new_address_max = %s", inet_ntoa(n_addr_max));
n_addr.s_addr = ntohl(n_addr.s_addr);
n_addr_max.s_addr = ntohl(n_addr_max.s_addr);
if(n_addr.s_addr <= n_addr_max.s_addr ) {
n_addr.s_addr = htonl(n_addr.s_addr);
n_addr_max.s_addr = htonl(n_addr_max.s_addr);
s_raw_server->ipv4_lease_last.s_addr =n_addr.s_addr;
a_ch->stream->session->tun_client_addr.s_addr = n_addr.s_addr;
l_ch_vpn->addr_ipv4.s_addr = n_addr.s_addr;
log_it(L_NOTICE, "VPN client address %s leased", inet_ntoa(n_addr));
log_it(L_INFO, "\tgateway %s", inet_ntoa(s_raw_server->ipv4_host));
......@@ -892,9 +911,11 @@ void s_ch_packet_in(dap_stream_ch_t* a_ch, void* arg)
memcpy(pkt_out->data, &l_ch_vpn->addr_ipv4, sizeof(l_ch_vpn->addr_ipv4));
memcpy(pkt_out->data + sizeof(l_ch_vpn->addr_ipv4), &s_raw_server->ipv4_host,
sizeof(s_raw_server->ipv4_host));
dap_stream_ch_pkt_write(a_ch, DAP_STREAM_CH_PKT_TYPE_NET_SRV_VPN_DATA, pkt_out,
pkt_out->header.op_data.data_size + sizeof(pkt_out->header));
dap_stream_ch_set_ready_to_write(a_ch, true);
if(dap_stream_ch_pkt_write(a_ch, DAP_STREAM_CH_PKT_TYPE_NET_SRV_VPN_DATA, pkt_out,
pkt_out->header.op_data.data_size + sizeof(pkt_out->header))) {
dap_stream_ch_set_ready_to_write(a_ch, true);
}
//ch_sf_raw_write(n_addr.s_addr,STREAM_SF_PACKET_OP_CODE_RAW_L3_ADDR_REPLY,&n_addr,sizeof(n_addr));
} else { // All the network is filled with clients, can't lease a new address
......@@ -1348,7 +1369,6 @@ void* srv_ch_sf_thread_raw(void *arg)
memcpy(l_pkt_out->data, l_tmp_buf, l_read_ret);
dap_stream_ch_pkt_write(l_ch_vpn->ch, DAP_STREAM_CH_PKT_TYPE_NET_SRV_VPN_DATA, l_pkt_out,
l_pkt_out->header.op_data.data_size + sizeof(l_pkt_out->header));
dap_stream_ch_set_ready_to_write(l_ch_vpn->ch, true);
s_update_limits(l_ch_vpn->ch,l_srv_session,l_usage, l_read_ret);
}
}
......