📄 ppp_dhcp.c
字号:
/*
* FILENAME: ppp_dhcp.c
*
* Copyright 1997- 2001 By InterNiche Technologies Inc. All rights reserved
*
* Routines for running DHCP over PPP
*
* MODULE: PPP
*
* PORTABLE: yes
*/
#include "ipport.h"
#ifdef USE_PPP /* ifdef whole file */
#include "ppp_port.h"
#include "mppp.h"
#ifdef PPP_DHCP_CLIENT
#include "dhcpclnt.h"
int dhc_port_ipset(int iface, int state); /* prototype success callback */
void dhcp_timeout(M_PPP mppp, long arg); /* time expired callback */
#ifndef PPP_DHCP_TMO
#define PPP_DHCP_TMO 10 /* dhcp client timeout, in seconds */
#endif
/* FUNCTION: ppp_start_dhcp()
*
* ppp_start_dhcp() - start client DHCP on the interface
* corresponding to the PPP unit. This is called from ipcp_up in
* ipcp.c. Note that the IP address, which may have already been
* either negotiated as part of IPCP or pre-configured from NVRAM, is
* replaced with 0.0.0.0 while DHCP packets exchange. Although
* technically up, only DHCP client packets are allowed in and out the
* PPP interface until DHCP has completed.
*
*
* PARAM1: int unit; a PPP unit number
*
* RETURNS: void
*/
void
ppp_start_dhcp(M_PPP mppp)
{
int iface;
iface = net_num(mppp->ifp);
dhc_states[iface].state = DHCS_INIT; /* set up for DHCP activity */
dhc_set_callback(iface, dhc_port_ipset); /* set callback routine */
dhc_discover(iface); /* send 1st DHCP discovery */
/* set timer for DHCP completion */
ppp_settimer(mppp, dhcp_timeout, PPP_DHCP_TMO, (long)iface);
//ConPrintf("ppp_start_dhcp: ppp_timeout in %d secs\n", PPP_DHCP_TMO);
}
/* FUNCTION: dhcp_timeout()
*
* PARAM1: void * arg
*
* RETURNS:
*/
void
dhcp_timeout(M_PPP mppp, long arg)
{
int iface = (int)arg;
NET ifp;
PACKET pkt;
ifp = if_getbynum(iface);
//ConPrintf("dhcp_timeout: iface %d\n", iface);
#ifdef NOTDEF
dhc_states[iface].state = DHCS_TIMEOUT;
#endif
/* restore default IP from NV - may be 0.0.0.0 */
ifp->n_ipaddr = mppp->default_ip;
dhc_halt(iface); /* stop dhcp client retrys for this net */
/* clean up any traffic we queued */
while(mppp->dataq.q_head)
{
pkt = (PACKET)getq(&mppp->dataq);
LOCK_NET_RESOURCE(FREEQ_RESID);
pk_free(pkt);
UNLOCK_NET_RESOURCE(FREEQ_RESID);
}
}
/* FUNCTION: dhc_port_ipset()
*
* dhc_port_ipset() is called directly from dhcpclnt.c when the DHCP
* client changes state; DHCS_BOUND corresponds to receipt of
*
*
* PARAM1: int iface
* PARAM2: int state
*
* RETURNS:
*/
int
dhc_port_ipset(int iface, int state)
{
NET ifp;
M_PPP mppp;
ifp = if_getbynum(iface);
mppp = (M_PPP)ifp->n_local;
if (state == DHCS_BOUND)
{
//ConPrintf("DHCP assigned PPP link IP=%u.%u.%u.%u\n",
//PUSH_IPADDR(ifp->n_ipaddr));
ppp_cleartimer(mppp); /* kill timer */
ppp_allpktsend(mppp); /* move along any traffic we queued */
}
return 0;
}
#endif /* PPP_DHCP_CLIENT */
#endif /* USE_PPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -