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

📄 ppplib.c

📁 vxworks的tcpip协议栈源码
💻 C
📖 第 1 页 / 共 4 页
字号:
** CONFIGURATION OPTIONS FILE:* The optional parameter <fOptions> specifies configuration options for* the PPP link.  If NULL, this parameter is ignored, otherwise it* is assumed to be the name of a configuration options file.  The format* of the options file is one option per line; comment lines start with "#".* The following options are recognized:* .iP "no_all"* Do not request/allow any options.* .iP "passive_mode"* Set passive mode.* .iP "silent_mode"* Set silent mode.* .iP "defaultroute"* Add default route.* .iP "proxyarp"* Add proxy ARP entry.* .iP "ipcp_accept_local"* Accept peer's idea of the local IP address.* .iP "ipcp_accept_remote"* Accept peer's idea of the remote IP address.* .iP "no_ip"* Disable IP address negotiation.* .iP "no_acc"* Disable address/control compression.* .iP "no_pc"* Disable protocol field compression.* .iP "no_vj"* Disable VJ (Van Jacobson) compression.* .iP "no_vjccomp"* Disable VJ (Van Jacobson) connnection ID compression.* .iP "no_asyncmap"* Disable async map negotiation.* .iP "no_mn"* Disable magic number negotiation.* .iP "no_mru"* Disable MRU (Maximum Receive Unit) negotiation.* .iP "no_pap"* Do not allow PAP authentication with peer.* .iP "no_chap"* Do not allow CHAP authentication with peer.* .iP "require_pap"* Require PAP authentication with peer.* .iP "require_chap"* Require CHAP authentication with peer.* .iP "login"* Use the login password database for PAP authentication of peer.* .iP "debug"* Enable PPP daemon debug mode.* .iP "driver_debug"* Enable PPP driver debug mode.* .iP "asyncmap <value>"* Set the desired async map to the specified value.* .iP "escape_chars <value>"* Set the chars to escape on transmission to the specified value.* .iP "vj_max_slots <value>"* Set maximum number of VJ compression header slots to the specified value.* .iP "netmask <value>"* Set netmask value for negotiation to the specified value.* .iP "mru <value>"* Set MRU value for negotiation to the specified value.* .iP "mtu <value>"* Set MTU value for negotiation to the specified value.* .iP "lcp_echo_failure <value>"* Set the maximum consecutive LCP echo failures to the specified value.* .iP "lcp_echo_interval <value>"* Set the interval in seconds between LCP echo requests to the specified value.* .iP "lcp_restart <value>"* Set the timeout in seconds for the LCP negotiation to the specified value.* .iP "lcp_max_terminate <value>"* Set the maximum number of transmissions for LCP termination requests* to the specified value.* .iP "lcp_max_configure <value>"* Set the maximum number of transmissions for LCP configuration* requests to the specified value.* .iP "lcp_max_failure <value>"* Set the maximum number of LCP configuration NAKs to the specified value.* .iP "ipcp_restart <value>"* Set the timeout in seconds for IPCP negotiation to the specified value.* .iP "ipcp_max_terminate <value>"* Set the maximum number of transmissions for IPCP termination requests* to the specified value.* .iP "ipcp_max_configure <value>"* Set the maximum number of transmissions for IPCP configuration requests* to the specified value.* .iP "ipcp_max_failure <value>"* Set the maximum number of IPCP configuration NAKs to the specified value.* .iP "local_auth_name <name>"* Set the local name for authentication to the specified name.* .iP "remote_auth_name <name>"* Set the remote name for authentication to the specified name.* .iP "pap_file <file>"* Get PAP secrets from the specified file.  This option is necessary* if either peer requires PAP authentication.* .iP "pap_user_name <name>"* Set the user name for PAP authentication with the peer to the specified name.* .iP "pap_passwd <password>* Set the password for PAP authentication with the peer to the specified* password.* .iP "pap_restart <value>"* Set the timeout in seconds for PAP negotiation to the specified value.* .iP "pap_max_authreq <value>"* Set the maximum number of transmissions for PAP authentication* requests to the specified value.* .iP "chap_file <file>"* Get CHAP secrets from the specified file.  This option is necessary* if either peer requires CHAP authentication.* .iP "chap_restart <value>"* Set the timeout in seconds for CHAP negotiation to the specified value.* .iP "chap_interval <value>"* Set the interval in seconds for CHAP rechallenge to the specified value.* .iP "chap_max_challenge <value>"* Set the maximum number of transmissions for CHAP challenge to the* specified value.** AUTHENTICATION:* The VxWorks PPP implementation supports two separate user authentication* protocols: the Password Authentication Protocol (PAP) and the* Challenge-Handshake Authentication Protocol (CHAP).  If authentication is* required by either peer, it must be satisfactorily completed before the* PPP link becomes fully operational.  If authentication fails, the link* will be automatically terminated.** EXAMPLES:* The following routine initializes a PPP interface that uses the* target's second serial port (`/tyCo/1').  The local IP address is* 90.0.0.1; the IP address of the remote peer is 90.0.0.10.  The baud* rate is the default rate for the <tty> device.  VJ compression* and authentication have been disabled, and LCP echo requests have been* enabled.** .CS* PPP_OPTIONS pppOpt;	/@ PPP configuration options @/** void routine ()*     {*     pppOpt.flags = OPT_PASSIVE_MODE | OPT_NO_PAP | OPT_NO_CHAP | OPT_NO_VJ;*     pppOpt.lcp_echo_interval = "30";*     pppOpt.lcp_echo_failure = "10";**     pppInit (0, "/tyCo/1", "90.0.0.1", "90.0.0.10", 0, &pppOpt, NULL);*     }* .CE** The following routine generates the same results as the previous example.* The difference is that the configuration options are obtained from* a file rather than a structure.* * .CS* pppFile = "phobos:/tmp/ppp_options";	/@ PPP configuration options file @/** void routine ()*     {*     pppInit (0, "/tyCo/1", "90.0.0.1", "90.0.0.10", 0, NULL, pppFile);*     }* .CE* where phobos:/tmp/ppp_options contains:** .CS*     passive*     no_pap*     no_chap*     no_vj*     lcp_echo_interval 30*     lcp_echo_failure 10* .CE** RETURNS:* OK, or ERROR if the PPP interface cannot be initialized because the* daemon task cannot be spawned or memory is insufficient.** SEE ALSO: pppShow, pppDelete(),* .pG "Network"*/int pppInit    (    int unit,			/* PPP interface unit number to initialize */    char *devname,		/* name of the <tty> device to be used */    char *local_addr,		/* local IP address of the PPP interface */    char *remote_addr,		/* remote peer IP address of the PPP link */    int baud,			/* baud rate of <tty>; NULL = default */    PPP_OPTIONS *pOptions,	/* PPP options structure pointer */    char *fOptions		/* PPP options file name */    )    {    int status;    if (ppp_if[unit] != NULL) {        fprintf(stderr, "PPP Unit %d already in use\r\n", unit);        return(ERROR);    }    if ((ppp_parms[unit] = (PPP_PARMS *)calloc(1, sizeof(PPP_PARMS))) == NULL) {	fprintf(stderr, "Unable to allocate memory for ppp parmeters\r\n");	return(ERROR);    }    /* Save parameters in case they're local variables */    ppp_parms[unit]->unit = unit;    ppp_parms[unit]->baud = baud;    if (devname)        ppp_parms[unit]->devname = (char *)stringdup(devname);    else        ppp_parms[unit]->devname = (char *)stringdup("");    if (local_addr)        ppp_parms[unit]->local_addr = (char *)stringdup(local_addr);    else        ppp_parms[unit]->local_addr = (char *)stringdup("");    if (remote_addr)        ppp_parms[unit]->remote_addr = (char *)stringdup(remote_addr);    else        ppp_parms[unit]->remote_addr = (char *)stringdup("");    if (fOptions)        ppp_parms[unit]->filename = (char *)stringdup(fOptions);    ppp_parms[unit]->task_name = (char *)malloc(strlen(ppp_task_name) + 2);    sprintf(ppp_parms[unit]->task_name, "%s%x", ppp_task_name, unit);    if (pOptions)        bcopy((char *)pOptions, (char *)&ppp_parms[unit]->options,	      sizeof(PPP_OPTIONS));    status = taskSpawn(ppp_parms[unit]->task_name,		       ppp_task_priority,		       ppp_task_options,                       ppp_task_stack_size, (FUNCPTR)ppp_task,		       ppp_parms[unit]->unit,		       (int)ppp_parms[unit]->devname,		       (int)ppp_parms[unit]->local_addr,		       (int)ppp_parms[unit]->remote_addr,		       ppp_parms[unit]->baud,		       (int)&ppp_parms[unit]->options,		       (int)ppp_parms[unit]->filename,		       0, 0, 0);    if (status == ERROR)        return(ERROR);    else        return(OK);    }/********************************************************************************* ppp_task - PPP daemon task** This is the entry point for the PPP daemon task.** NOMANUAL*/void ppp_task(unit, devname, local_addr, remote_addr, baud, pOptions, fOptions)    int unit;    char *devname;    char *local_addr;    char *remote_addr;    int baud;    PPP_OPTIONS *pOptions;    char *fOptions;{    sigset_t mask;    struct sigaction sa;    int i;    char user[MAXNAMELEN];    if ((ppp_if[unit] = (PPP_TASK_VARS *)calloc(1, sizeof(PPP_TASK_VARS))) == NULL) {	fprintf(stderr, "Unable to allocate memory for ppp task\r\n");	return;    }    if (taskVarAdd(0, (int *)&ppp_unit) != OK) {        fprintf(stderr, "Unable to add task variable\r\n");	ppp_if[unit] = NULL;        return;    }    /* Initialize ppp task variables */    ppp_unit = ppp_if[unit]->ifunit = unit;    ppp_if[unit]->debug = 0;    ppp_if[unit]->unknownProto = 0;    ppp_if[unit]->fd = ERROR;    ppp_if[unit]->s = ERROR;    ppp_if[unit]->options = pOptions;    ppp_if[unit]->task_id = taskIdSelf();    ppp_if[unit]->hungup = 0;    strcpy(ppp_if[unit]->devname, devname);#ifdef	VXW5_1    ppp_if[unit]->timer_id = timer_create (CLOCK_REALTIME, NULL);#else	/* VXW5_1 */    timer_create (CLOCK_REALTIME, NULL, &ppp_if[unit]->timer_id);#endif	/* VXW5_1 */    if (ppp_if[unit]->timer_id < (timer_t)0) {        fprintf(stderr, "timer_create failed\r\n");	ppp_if[unit] = NULL;        return;    }    if (timer_connect(ppp_if[unit]->timer_id, alrm, 0) < 0) {        fprintf(stderr, "timer_connect failed\r\n");	ppp_if[unit] = NULL;        return;    }    if (gethostname(ppp_if[unit]->hostname, MAXNAMELEN) < 0 ) {        fprintf(stderr, "couldn't get hostname\r\n");	ppp_if[unit] = NULL;        return;    }    ppp_if[unit]->hostname[MAXNAMELEN-1] = 0;    /*     * Open the serial device and set it up to be the ppp interface.     */    if (pppopen(unit, devname) == ERROR) {        fprintf(stderr, "ppp%d: error openning the %s interface\r\n",	    unit, devname);	ppp_if[unit] = NULL;        return;    }    /* initialize the authentication secrets table (vxWorks) */    (void) pppSecretLibInit ();    /*     * Initialize to the standard option set, then parse, in order,     * the system options file, the user's options file, and the command     * line arguments.     */    for (i = 0; i < N_PROTO; i++)        (*prottbl[i].init)(unit);    if (!parse_args(unit, devname, local_addr, remote_addr, baud, ppp_if[unit]->options, fOptions))        die(unit, 1);    /* set up the serial device as a ppp interface */    establish_ppp();    check_auth_options();    setipdefault();        magic_init();    remCurIdGet(user, NULL);    syslog (LOG_NOTICE, "ppp %s.%d started by %s", VERSION, PATCHLEVEL, user);    /* Get an internet socket for doing socket ioctl's on. */    if ((ppp_if[unit]->s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {        syslog(LOG_NOTICE, "socket error");        die(unit, 1);    }    /*     * Compute mask of all interesting signals and install signal handlers     * for each.  Only one signal handler may be active at a time.  Therefore,     * all other signals should be masked when any handler is executing.     */    sigemptyset(&mask);    sigaddset(&mask, SIGHUP);    sigaddset(&mask, SIGINT);    sigaddset(&mask, SIGALRM);    sigaddset(&mask, SIGIO);#define SIGNAL(s, handler)      { \        sa.sa_handler = (void (*)())handler; \        if (sigaction(s, &sa, NULL) < 0) { \            syslog(LOG_ERR, "sigaction(%d) error", s); \            die(unit, 1); \        } \    }    sa.sa_mask = mask;    sa.sa_flags = 0;    SIGNAL(SIGHUP, hup);		/* Hangup */    SIGNAL(SIGINT, intr);		/* Interrupt */    SIGNAL(SIGTERM, term);		/* Terminate */    SIGNAL(SIGALRM, alrm);		/* Timeout */    SIGNAL(SIGIO, io);			/* Input available */    signal(SIGUSR1, incdebug);		/* Increment debug flag */    signal(SIGUSR2, nodebug);		/* Reset debug flag */    /*     * Block SIGIOs and SIGPOLLs for now     */    sigemptyset(&mask);    sigaddset(&mask, SIGIO);    sigprocmask(SIG_BLOCK, &mask, NULL);    /* set line speed, flow control, etc. */    set_up_tty(ppp_if[unit]->fd);    /* run connection hook routine */    if ((pppHookRtns[unit] != NULL) && 	(pppHookRtns[unit]->connectHook != NULL))	{        if (((*pppHookRtns[unit]->connectHook) (unit, ppp_if[unit]->fd)) 	    == ERROR)	    {            syslog(LOG_ERR, "connect hook failed");

⌨️ 快捷键说明

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