⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dns_relay_atmos.c

📁 DNS 的实现代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ############################################################################ (c) Copyright Virata Limited 1999## Virata Limited Confidential and Proprietary## The following software source code ("Software") is strictly confidential and# is proprietary to Virata Limited ("Virata").  It may only be read, used,# copied, adapted, modified or otherwise dealt with by you if you have# entered into a confidentiality agreement with Virata and then subject to the# terms of that confidentiality agreement and any other applicable agreement# between you and Virata.  If you are in any doubt as to whether you are# entitled to access, read, use, copy, adapt, modify or otherwise deal with# the Software or whether you are entitled to disclose the Software to any# other person you should contact Virata.  If you have not entered into a# confidentiality agreement with Virata granting access to this Software you# should forthwith return all media, copies and printed listings containing# the Software to Virata.## Virata reserves the right to take legal action against you should you breach# the above provisions.## If you are unsure, or to report violations, please contact# support@virata.com# ##########################################################################*//* File: dns_relay_process.c * * This file contains all general ATMOS process-related operations except for the * "main" function entry point, which is present in dns_relay_engine.c. * * All TELL command handlers are located here, and all configuration * handling functions. Since these are message handlers, this is all * specific to ATMOS. * * Portability functions are also defined here. This file is conditionally * compiled in only when doing an ATMOS build. For example, on VxWorks, * the file dns_relay_vxworks.c will be compiled instead. This leaves * the general DNS relay core, dns_relay_engine.c, completely generic. *//* Standard includes */#include "config/dns.h"#include "config.h"#include "command.h"#include "stdio.h"#include "string.h"#include "atypes.h"#include "stdlib.h"/* DNS includes */#include "dns_relay_process.h"#include "dns_relay_lib.h"#include "dns_trace.h"#include "dns_relay_landb.h"#include "dns_relay_cache.h"#include "dns_relay_localrr.h"#include "dns_relay_engine.h"/* OS-safe inet_aton, inet_ntoa */#include <platform.h>/***************************************************************************** * *    Console command handling prototypes * *****************************************************************************/typedef void (* DNS_COMMAND_HANDLER)( char *arg, FILE *fh );static void dns_relay_add_command(const char *name, const char *help_text, DNS_COMMAND_HANDLER handler);static void dns_relay_handle_tell( ATMOS_MESSAGE *msg );#ifdef AUTO_DISCOVERY_SUPPORTvoid    dns_relay_auto_command( char *arg, FILE *fh );#endifvoid dns_relay_config_command( char *arg, FILE *fh );void   dns_relay_help_command( char *arg, FILE *fh );void  dns_relay_retry_command( char *arg, FILE *fh );void dns_relay_server_command( char *arg, FILE *fh );void dns_relay_status_command( char *arg, FILE *fh );void  dns_relay_trace_command( char *arg, FILE *fh );void dns_relay_untrace_command( char *arg, FILE *fh );void dns_relay_version_command( char *arg, FILE *fh );void dns_relay_showdb_command(char *arg, FILE *fh);void dns_relay_bailout( void );extern BOOL dns_relay_prologue( int argc, char *argv[] );/* Prototypes to link to dns_relay_landb code */extern int            dns_set_local_domain(const char *dname);extern int            dns_set_local_ipaddress(unsigned long ip, unsigned long mask);extern const char     *dns_get_local_domain(void);extern unsigned long  dns_get_local_ipaddress(void);extern unsigned long  dns_get_local_ipaddress_mask(void);extern void           dump_lan_entries(void);extern int landb_insert_lanhost_alias(const char *hostName, const char *hostAlias, BOOL is_ipv6);extern int landb_insert_lanip_alias( const char *host_name, unsigned long *ip_alias, BOOL is_ipv6 );extern int listen_sock(int type, int sock_type, struct in6_addr *address, int intf, int sock_idx);#ifdef DNS_V6_FWDRextern int close_sock(int sock_idx);#endif/***************************************************************************** * *    Private data structures * *****************************************************************************//* Command handlers for TELL messages */#define MAX_COMMANDS  (12)static struct COMMANDStag{    int count;    const char *name[MAX_COMMANDS];    const char *help_text[MAX_COMMANDS];    void (*handler[MAX_COMMANDS]) (char *, FILE *);} commands;/***************************************************************************** * * DNS relay prologue * *****************************************************************************/BOOL dns_relay_prologue( int argc, char *argv[] ){    UNUSED(argc);    UNUSED(argv);    commands.count = 0;    /* Set up the DNS relay's TELL command handlers */#ifdef AUTO_DISCOVERY_SUPPORT    dns_relay_add_command( "auto",    "Attempt DNS server auto-discover via PPP",dns_relay_auto_command    );#endif    dns_relay_add_command( "config",  "Show DNS relay configuration",            dns_relay_config_command  );    dns_relay_add_command( "help",    "List help on available commands",         dns_relay_help_command    );    dns_relay_add_command( "retry",   "Set max number of connection/tx retries", dns_relay_retry_command   );    dns_relay_add_command( "server",  "Manually specify DNS server IP address",  dns_relay_server_command  );    dns_relay_add_command( "status",  "Show DNS relay connection status",        dns_relay_status_command  );    dns_relay_add_command( "showdb",  "Show contents of local LAN database",     dns_relay_showdb_command  );    dns_relay_add_command( "trace",   "Activate trace option(s)",                dns_relay_trace_command   );    dns_relay_add_command( "untrace", "Deactivate trace option(s)",              dns_relay_untrace_command );    dns_relay_add_command( "version", "Show DNS relay software version",         dns_relay_version_command );    return TRUE;}/***************************************************************************** * * dns_relay_message_handler * * Generic message handling function which invokes specific handlers. Will * be called whilst waiting in a call to the socket function select(). * * Messages sent to this process via external API calls generated by apigen * are handled here. * * Arguments: *   msg       Pointer to ATMOS message the DNS relay received * * Returns: *   Nothing * *****************************************************************************/void dns_relay_message_handler( ATMOS_MESSAGE *msg ){    switch (msg->code)    {    case MSG_N_TELL:        dns_relay_handle_tell( msg );        break;    case MSG_N_CONFIG_REQUEST:        foreground_output_begin();        ConfigRequest(msg, &configCommands);        foreground_output_end();        break;            /* apigen message handlers */#ifdef MSG_N_DNSRELAYLIB_CONFIG    case MSG_N_DNSRELAYLIB_CONFIG:        {            dns_relay_process_config( FALSE );            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_RETRY    case MSG_N_DNSRELAYLIB_RETRY:        {            MSG_D_DNSRELAYLIB_RETRY( data, msg );            data->result = dns_relay_process_retry( data->newRetryValue );            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_SERVERADD    case MSG_N_DNSRELAYLIB_SERVERADD:        {            MSG_D_DNSRELAYLIB_SERVERADD( data, msg );			/* Call function to add server based on whether it's an ipv6 or ipv4 server */#ifndef DNS_V6_FWDR           	data->result = dns_relay_process_server( data->serverAddr,data->serverType);#else			if( !data->is_ipv6) 			{            data->result = dns_relay_process_server( data->serverAddr,data->serverType );			}			else			{	            	data->result = dns_relay_process_server_v6( data->serverAddr );			}#endif            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_SERVERDELETE    case MSG_N_DNSRELAYLIB_SERVERDELETE:        {            MSG_D_DNSRELAYLIB_SERVERDELETE( data, msg );			/* Call function to delete server based on whether it's an ipv6 or ipv4 server */#ifndef DNS_V6_FWDR           	data->result = dns_relay_process_server_delete( data->serverAddr ,data->serverType);#else			if( !data->is_ipv6) 			{            data->result = dns_relay_process_server_delete( data->serverAddr,data->serverType);			}			else            {            	data->result = dns_relay_process_server_delete_v6( data->serverAddr );			}#endif            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_SERVEREDIT    case MSG_N_DNSRELAYLIB_SERVEREDIT:        {            MSG_D_DNSRELAYLIB_SERVEREDIT( data, msg );			/* Call function to update existing DNS server address */           	data->result = dns_relay_process_server_edit( data->index, data->serverAddr );            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_STATUS    case MSG_N_DNSRELAYLIB_STATUS:        {            dns_relay_process_status();            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_TRACE    case MSG_N_DNSRELAYLIB_TRACE:        {            MSG_D_DNSRELAYLIB_TRACE( data, msg );            dns_relay_process_trace( data->arg );            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_UNTRACE    case MSG_N_DNSRELAYLIB_UNTRACE:        {            MSG_D_DNSRELAYLIB_UNTRACE( data, msg );            dns_relay_process_untrace( data->arg );            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_VERSION    case MSG_N_DNSRELAYLIB_VERSION:        {            dns_relay_process_version();            sendreply( msg );            break;        }#endif#ifdef MSG_N_DNSRELAYLIB_CHECKHOSTISLOCAL    case MSG_N_DNSRELAYLIB_CHECKHOSTISLOCAL:        {            MSG_D_DNSRELAYLIB_CHECKHOSTISLOCAL( data, msg );            data->result = (int)dnsr_host_is_local(data->sock, data->hostname);            sendreply( msg );            break;        }#endif    /* Local LAN database message handlers */    case MSG_N_DNS_RELAY_SET_LOCAL_DOMAIN:        {            MSG_D_DNS_RELAY_SET_LOCAL_DOMAIN(data, msg);            if ( dns_set_local_domain(data->domain) < 0 )            {                data->error = EINVAL;            }            else            {                data->error = ESUCCESS;            }            set_configurable_local_fqdn();            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_GET_LOCAL_DOMAIN:        {            MSG_D_DNS_RELAY_GET_LOCAL_DOMAIN(data, msg);            data->domain = dns_get_local_domain();            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_SET_LOCAL_HOSTNAME:        {            MSG_D_DNS_RELAY_SET_LOCAL_HOSTNAME(data, msg);            strcpy(config.local_hostname, data->hostname);            set_configurable_local_fqdn();            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_LOAD_LANDB:        {            MSG_D_DNS_RELAY_LOAD_LANDB(data, msg);            data->error = dns_landb_load_dbfile(data->filename, data->dbreset);            sendreply(msg);            break;        }        case MSG_N_DNS_RELAY_INSERT_LANHOST:        {            MSG_D_DNS_RELAY_INSERT_LANHOST(data, msg);            data->error = dns_landb_insert_lanentry(data->dhost);            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_DELETE_LANHOST:        {            MSG_D_DNS_RELAY_DELETE_LANHOST(data, msg);            data->error = dns_landb_delete_lanentry(data->hname, data->is_ipv6);            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_DELETE_LANIP:        {            MSG_D_DNS_RELAY_DELETE_LANIP(data, msg);            data->error = dns_landb_delete_lanipentry(data->ipaddr, data->is_ipv6);            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_INSERT_LANIP_ALIAS:        {            MSG_D_DNS_RELAY_INSERT_LANIP_ALIAS(data, msg);            data->error = landb_insert_lanip_alias(data->host_name, data->ip_alias, data->is_ipv6 );            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_INSERT_LANHOST_ALIAS:        {            MSG_D_DNS_RELAY_INSERT_LANHOST_ALIAS(data, msg);            data->error = landb_insert_lanhost_alias(data->host_name, data->host_alias, data->is_ipv6);            sendreply(msg);            break;        }#ifdef DNS_V6_FWDR    case MSG_N_DNS_RELAY_ADD_WKSLU_ADDR:        {			/* Handling for addition of WKSLU address */            MSG_D_DNS_RELAY_ADD_WKSLU_ADDR(data, msg);            data->error = listen_sock(data->type, data->sock_type, 											data->addr, data->intf, data->sock_idx);            sendreply(msg);            break;        }    case MSG_N_DNS_RELAY_DELETE_WKSLU_ADDR:        {			/* Handling for deletion of WKSLU address */            MSG_D_DNS_RELAY_DELETE_WKSLU_ADDR(data, msg);            data->error = close_sock(data->sock_idx);             sendreply(msg);            break;        }#endif    case MSG_N_DNS_RELAY_FLUSH_LANDB:        dns_landb_flush();        sendreply(msg);        break;    case MSG_R_TIMER_MSWAIT:        dns_relay_cache_entry_timeout();        dns_relay_timeout();        break;    case MSG_N_DNS_RELAY_FLUSH_CACHE:        dns_relay_flush_cache();        sendreply(msg);        break;    case MSG_N_DNS_RELAY_ENABLE:        {            MSG_D_DNS_RELAY_ENABLE(data, msg);            config.enabled = data->enable;            sendreply(msg);        }        break;    default:        TRACE( TRACE_SOCKET, "Passing message %08x to socket layer", msg->code );                if( socket_handle_atmos_message(msg) == -1 )        {            TRACE( TRACE_SOCKET, "Warning - socket layer did not handle message");            if( !(msg->code & MSG_REPLY_BIT ))            sendreply( msg );        }        break;    }    return;}/***************************************************************************** * * dns_relay_handle_tell:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -