23 #define MAX_HASH_ENTRIES 25000 118 printf(
" Disconnect received - conn: %d to %s@%s\n", conn_id,
128 printf(
" Connection request received - conn: %d\n", conn_id);
143 printf(
" conn: %d to %s@%s, Bad packet\n", conn_id,
145 printf(
"packet->size = %d\n", vtohl(packet->
size));
146 printf(
"packet->src_type = %d\n", vtohl(packet->
src_type));
147 printf(
"closing the connection.\n" );
157 printf(
" - DIM panic: recv_rout(): Bad switch, exiting...\n");
182 char *ptr, *ptr1, *ptrt;
197 int name_too_long = 0;
207 if((
unsigned)service_id & 0x80000000)
240 for(i = 0; i < 4; i++)
258 if(strcmp(
Dns_conns[conn_id].task_name,
"DIS_DNS"))
270 ptr1 = strchr(ptr,
',');
279 ptr1 += (int)strlen(ptr);
281 if(strstr(
Dns_conns[conn_id].node_name,ptr))
295 printf(
" Stop Server: Couldn't write, releasing %d\n",conn_id);
299 printf(
" Connection from %s refused, stopping server %s\n",
311 if(strcmp(
Dns_conns[conn_id].task_name,
"DIS_DNS"))
328 if( (
Dns_conns[conn_id].n_services == -1) &&
331 if(strcmp(
Dns_conns[conn_id].task_name,
"DIS_DNS"))
334 printf(
" Server %s out of error\n",
343 for( i = 0; i < n_services; i++ )
373 format = vtohl(packet->
format);
380 printf(
" Couldn't write, releasing %d\n",servp->
conn_id);
384 printf(
" Service %s already declared, killing server %s\n",
387 release_client(servp->
conn_id);
397 printf(
" Service %s already declared by conn %d - %s@%s:%d (PID %d), Redeclared by conn %d - %s@%s:%d (PID %d)(same server) - Closing both conns %d %d\n",
425 printf(
" Kill Server: Couldn't write, releasing %d\n",conn_id);
429 printf(
" Service %s already declared by conn %d - %s@%s:%d (PID %d), killing server conn %d - %s@%s:%d (PID %d) \n",
450 else if( servp->
state != -1 )
479 if((
unsigned)service_id & 0x80000000)
491 printf(
" Conn %3d : Server %s@%s unregistered All services, releasing it.\n",
530 ptrt = strstr(
Dns_conns[conn_id].long_task_name,
"/CLIENT_LIST");
561 printf(
" Conn %3d : Server %s@%s (PID %d) registered %d services\n",
589 int n_services, old_n_services;
597 if(old_n_services != n_services)
600 if((old_n_services <= 0) || (n_services == 0) || (n_services == -1))
622 printf(
" Server %s (%s@%s) has been set in error\n",
641 printf(
" Conn %3d : Server %s@%s Registration Requested\n",
649 printf(
" Server Validity: Couldn't write, releasing Conn %3d : Server %s@%s\n",conn_id,
670 void tcpip_get_addresses();
678 printf(
" Conn %3d : Client %s@%s requested %s\n",
695 ptr1 = strchr(ptr,
',');
704 ptr1 += (int)strlen(ptr);
722 printf(
" Connection from %s refused, stopping client pid=%s\n",
729 printf(
" Stop Client: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id,
741 if( service_id == -1 )
745 printf(
"\tRemoving Request\n");
754 (
DLL *) red_nodep)) )
756 if( red_nodep->
conn_id == conn_id )
759 ptr = (
char *)red_nodep - (2 *
sizeof(
void *));
762 red_nodep = red_nodep->
prev;
771 printf(
"\tand Removing Service\n");
781 if( (
unsigned)service_id & 0x80000000 )
783 service_id &= 0x7fffffff;
786 printf(
"\tRemoving Request\n");
795 (
DLL *) red_nodep)) )
797 if(( red_nodep->
conn_id == conn_id ) &&
801 ptr = (
char *)red_nodep - (2 *
sizeof(
void *));
804 red_nodep = red_nodep->
prev;
813 printf(
"\tand Removing Service\n");
836 printf(
"\tService does not exist, queueing request\n");
866 if( servp->
state == 1 )
879 for(i = 0; i < 4; i++)
889 printf(
"\tService exists in %s@%s, port = %d\n",
899 if(servp->
state == -1)
901 printf(
"\tService exists in BAD state, queueing request\n");
906 printf(
"\tService does not exist (other client(s) waiting), queueing request\n");
932 printf(
" Client Request: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id,
964 if( servp->
state != -1 )
970 if(n_informed == 1000)
990 int i, to_release = 0;
1000 for(i = 0; i < 4; i++)
1016 printf(
" Inform Client: Couldn't write, releasing Conn %3d : Client %s@%s\n",nodep->
conn_id,
1030 ptr = (
char *)nodep - (2 *
sizeof(
void *));
1031 full_nodep = (
NODE *)ptr;
1033 nodep = nodep->
prev;
1045 static release_client(
int conn_id)
1055 if( (!strcmp(
Net_conns[i].task,ptr_task)) &&
1065 printf(
" Releasing client on conn %d - %s@%s\n",
1080 NODE *nodep, *old_nodep;
1090 printf(
" Conn %3d : Server %s@%s died\n",
1100 printf(
" Conn %3d : Server %s@%s died\n",
1154 printf(
" Conn %3d : Client %s@%s died\n",
1164 servp = nodep->
servp;
1189 printf(
" Conn %3d : Undefined Type %s@%s died\n",
1205 if(strcmp(
Dns_conns[conn_id].task_name,
"DIS_DNS"))
1241 static int curr_allocated_size = 0;
1242 static DNS_DID *dns_info_buffer;
1252 if(connp->src_type !=
SRC_DIS)
1258 if(n_services == -1)
1262 if(!curr_allocated_size)
1265 curr_allocated_size = max_size;
1267 else if (max_size > curr_allocated_size)
1269 free(dns_info_buffer);
1271 curr_allocated_size = max_size;
1273 dns_server_info = &dns_info_buffer->
server;
1274 dns_service_info = dns_info_buffer->
services;
1277 dns_server_info->
pid = htovl(connp->pid);
1278 dns_server_info->
n_services = htovl(connp->n_services);
1284 dns_service_info->
status = htovl(1);
1285 if(servp->
serv_id & 0x10000000)
1286 dns_service_info->
type = htovl(1);
1288 dns_service_info->
type = htovl(0);
1291 *bufp = (
int *)dns_info_buffer;
1298 static int curr_allocated_size = 0;
1299 static char *info_buffer;
1300 static int *pid_buffer, pid_size;
1303 int i, max_size, max_pid_size;
1305 char server[
MAX_NAME], *info_buffer_ptr;
1321 max_pid_size = (int)
sizeof(
int) * n_server;
1322 if(!curr_allocated_size)
1324 info_buffer = (
char *)
malloc((
size_t)max_size);
1325 curr_allocated_size = max_size;
1326 pid_buffer = (
int *)
malloc((
size_t)max_pid_size);
1328 else if (max_size > curr_allocated_size)
1331 info_buffer = (
char *)
malloc((
size_t)max_size);
1332 curr_allocated_size = max_size;
1334 pid_buffer = (
int *)
malloc((
size_t)max_pid_size);
1336 info_buffer[0] =
'\0';
1339 info_buffer_ptr = info_buffer;
1378 strcpy(info_buffer_ptr, server);
1379 info_buffer_ptr += (int)strlen(server);
1380 pid_buffer[pid_index] = connp->
pid;
1389 strcat(info_buffer,
"+");
1391 strcat(info_buffer,
"!");
1393 strcat(info_buffer,
"-");
1395 strcat(info_buffer,
"@");
1397 strcat(info_buffer,
"|");
1398 pid_buffer[pid_index] = connp->
pid;
1401 info_buffer[(int)strlen(info_buffer) - 1] =
'\0';
1402 info_buffer_ptr = &info_buffer[(int)strlen(info_buffer)+1];
1404 for(i = 0; i < pid_index; i++)
1406 if(i != (pid_index -1))
1407 sprintf(server,
"%d|",pid_buffer[i]);
1409 sprintf(server,
"%d",pid_buffer[i]);
1410 strcpy(info_buffer_ptr, server);
1411 info_buffer_ptr += (int)strlen(server);
1412 pid_size += (int)strlen(server);
1414 *bufp = (
int *)info_buffer;
1415 *size = (int)strlen(info_buffer)+1+pid_size+1;
1421 int i, protocol, dns_port;
1431 if(!strcmp(argv[1],
"-d"))
1435 printf(
"Parameters: -d Debug On\n");
1508 printf(
" Connection Statistics :\n");
1514 printf(
"%d - Server %s@%s (PID %d) %d services\n",
1524 printf(
"%d - Client %s@%s\n",
1534 printf(
"%d - Undefined %s@%s\n",
1538 printf(
"%d - Undefined\n", i);
1544 printf(
"%d - Empty\n", i);
1549 printf(
"Number of Connections = %d : %d servers, %d clients\n", n_conns,
1550 n_servers, n_clients);
1551 printf(
"Number of Services = %d\n", n_services);
1572 int soft_code = 0, soft_size = 0;
1588 if(!strcmp(
Dns_conns[i].task_name,
"DIS_DNS"))
1595 type |= (soft_code << (int)16) & (int)0xFFFF0000;
1597 printf(
" Killing server %s@%s with exit code %d\n",
1603 printf(
" Killing server %s@%s\n",
1606 dis_packet.
type = htovl(type);
1611 printf(
" Kill Server: Couldn't write, releasing %d\n",i);
1657 (
DLL *) Service_hash_table[index],
1658 name, (
int)strlen(name)+1)) )
1660 ptr = (
char *)servp - (2 *
sizeof(
void *));
1671 int n_entries, max_entry_index = 0;
1672 int max_entries = 0;
1675 if( (
foutptr = fopen(
"scratch$week:[cp_operator]dim_dns.log",
"w" )
1678 printf(
"Cannot open: scratch$week:[cp_operator]dim_dns.log for writing\n");
1688 fprintf(
foutptr,
"HASH[%d] : \n",i);
1690 servp = Service_hash_table[
i];
1692 (
DLL *) Service_hash_table[i],
1704 printf(
"HASH[%d] - %d entries\n", i, n_entries);
1705 if(n_entries > max_entries)
1707 max_entries = n_entries;
1708 max_entry_index =
i;
1714 printf(
"Maximum : HASH[%d] - %d entries\n", max_entry_index, max_entries);
1724 char tmp[
MAX_NAME], *ptr, *ptr1, *dptr, *dptr1;
1725 int match,
count = 0;
1730 if(!strchr(wild_name,
'*'))
1735 if(servp1->
state == 1)
1746 servp = Service_hash_table[
i];
1748 (
DLL *) Service_hash_table[i],
1755 while( (ptr1 = strchr(ptr,
'*')) )
1766 if( (ptr1 = strchr(ptr,
'*')) )
1768 tmp[ptr1-ptr] =
'\0';
1770 if( (dptr1 = strstr(dptr, tmp)) )
1777 dptr1 += (int)strlen(tmp);
1790 tmp[ptr1-ptr] =
'\0';
1791 if(!strncmp(dptr, tmp, strlen(tmp)))
1793 dptr += (int)strlen(tmp);
1803 if(strcmp(dptr, ptr))
1806 strcat(tmp,
"/RpcIn");
1807 if(strcmp(dptr, tmp))
1812 if(servp->
state == 1)
1814 ptr = (
char *)servp - (2 *
sizeof(
void *));
1836 printf(
" Got Browse Request <%s> from conn: %d %s@%s\n", buffer, conn_id,
1844 printf(
" Browse Request <%s> found %d services\n", buffer, n);
1859 for(i = 0; i < n; i++)
1862 servp = Service_info_list[
i];
1866 if( (ptr = strstr(aux,
"/RpcIn")) )
1870 if( (ptr = strstr(Rpc_info, aux)) )
1872 ptr += (int)strlen(aux);
1877 if( (ptr = strstr(aux,
"/RpcOut")) )
1881 if( (ptr = strstr(Rpc_info, aux)) )
1883 ptr += (int)strlen(aux);
1890 strcpy(rpcaux, aux);
1892 strcat(aux,
"/RpcIn");
1895 strcat(rpcaux, aux_servp->
serv_def);
1897 ptr = strstr(aux,
"/RpcIn");
1899 strcat(aux,
"/RpcOut");
1902 strcat(rpcaux,aux_servp->
serv_def);
1903 strcat(rpcaux,
"|RPC\n");
1904 strcpy(rpcptr, rpcaux);
1905 rpcptr += (int)strlen(rpcaux);
1915 if(servp->
serv_id & 0x10000000)
1916 strcat(rpcaux,
"|CMD\n");
1918 strcat(rpcaux,
"|\n");
1919 strcpy(rpcptr, rpcaux);
1920 rpcptr += (int)strlen(rpcaux);
1927 free(Service_info_list);
char node_name[MAX_NODE_NAME]
struct node * client_next
#define MAX_REGISTRATION_UNIT
void kill_servers(int *tag, int *code, int *size)
static void release_conn(int conn_id)
int dim_get_keepalive_timeout()
void do_inform_clients(int conn_id)
void dna_test_write(int conn_id)
void inform_clients(DNS_SERVICE *servp)
DllExp DIM_NOSHARE int Curr_N_Conns
int handle_registration(int conn_id, DIS_DNS_PACKET *packet, int tmout_flag)
int dna_write(int conn_id, void *buffer, int size)
#define dis_selective_update_service
DllExp DIM_NOSHARE DNS_CONNECTION * Dns_conns
static char DNS_accepted_domains[1024]
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
static int Server_info_id
void * id_get_ptr(int id, SRC_TYPES type)
void set_rpc_info(int *tag, char *buffer, int *size)
void dll_insert_queue(DLL *head, DLL *item)
static char DNS_accepted_nodes[1024]
int dna_close(int conn_id)
void dna_rem_test_write(int conn_id)
void get_new_dns_server_info(int *tag, int **bufp, int *size, int *first_time)
char service_def[MAX_NAME]
void do_update_did(int conn_id)
char task_name[MAX_TASK_NAME-4]
void dna_set_test_write(int conn_id, int time)
void set_in_error(int conn_id)
_DIM_PROTO(DNS_SERVICE *service_exists,(char *name))
int main(int argc, char **argv)
char node_name[MAX_NODE_NAME]
char service_name[MAX_NAME]
void dll_remove(DLL *item)
static int Curr_n_servers
struct red_serv RED_DNS_SERVICE
void service_remove(RED_DNS_SERVICE *servp)
char node_name[MAX_NODE_NAME]
void conn_arr_create(SRC_TYPES type)
void check_validity(int conn_id)
char task_name[MAX_TASK_NAME-4]
void dim_set_listen_backlog(int size)
struct node * client_prev
void dtq_start_timer(int time, void(*user_routine)(), dim_long tag)
static void error_handler(int conn_id, int severity, int errcode, char *reason)
static void recv_rout(int conn_id, DIC_DNS_PACKET *packet, int size, int status)
int dtq_rem_entry(int queue_id, TIMR_ENT *entry)
struct serv * server_next
#define dis_start_serving
#define dis_update_service
char service_def[MAX_NAME]
int find_services(char *wild_name)
int get_dns_accepted_nodes(char *nodes)
void dim_set_write_timeout(int secs)
void service_insert(RED_DNS_SERVICE *servp)
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
struct serv * server_prev
static int Server_new_info_id
#define WATCHDOG_TMOUT_MAX
DNS_SERVICE * service_exists(char *name)
int dna_write_nowait(int conn_id, void *buffer, int size)
int handle_client_request(int conn_id, DIC_DNS_PACKET *packet)
int get_dns_port_number()
void dim_set_keepalive_timeout(int secs)
int dna_open_server(char *task, void(*read_ast)(), int *protocol, int *port, void(*error_ast)())
void id_free(int id, SRC_TYPES type)
TIMR_ENT * dtq_add_entry(int queue_id, int time, void(*user_routine)(), dim_long tag)
DllExp DIM_NOSHARE DNA_CONNECTION * Dna_conns
DLL * dll_get_next(DLL *head, DLL *item)
int dim_set_write_buffer_size(int size)
void dim_print_date_time()
void dim_print_msg(char *msg, int severity)
int HashFunction(char *name, int max)
#define DIM_VERSION_NUMBER
static RED_DNS_SERVICE * Service_hash_table[MAX_HASH_ENTRIES]
SERVICE_REG services[MAX_SERVICE_UNIT]
char task_name[MAX_TASK_NAME-4]
int get_node_name(char *node_name)
static DNS_SERVICE ** Service_info_list
DNS_SERVICE_INFO services[1]
static int Curr_n_services
char long_task_name[MAX_NAME]
sprintf(name1,"NewService%d", i)
void get_rpc_info(int *tag, char **buffer, int *size)
int get_dns_accepted_domains(char *domains)
DLL * dll_search(DLL *head, char *data, int size)
void get_dns_server_info(int *tag, int **bufp, int *size, int *first_time)
int dim_set_read_buffer_size(int size)
void send_dns_server_info(int conn_id, int **bufp, int *size)