📄 ppp.c
字号:
/* Add a route to this new node on the network. */
RTAB_Add_Route (dev_ptr,
IP_ADDR (link_layer->ipcp.assigned_peer_ip_address),
IP_ADDR ((unsigned char *)subnet_mask),
IP_ADDR (server_ip_addr),
(RT_UP | RT_HOST));
/* Add the remote IP address to the device structure. */
dev_ptr->dev_addr.dev_dst_ip_addr =
IP_ADDR (link_layer->ipcp.assigned_peer_ip_address);
NU_Release_Semaphore(&TCP_Resource);
}
else
{
/* Stop any PPP timer that may still be running */
PPP_Stop_All_Timers(dev_ptr);
/* Hangup the modem in case it is still off hook. */
link_layer->disconnect(link_layer, NU_TRUE);
}
}
} /* end while a client is not connected. */
if (ret_status != NU_SUCCESS)
{
link_layer->lcp.state = INITIAL;
link_layer->ipcp.state = INITIAL;
}
}
else
ret_status = NU_INVALID_LINK;
return (ret_status);
}
/************************************************************************
* FUNCTION
*
* PPP_Abort_Wait_For_Client
*
* DESCRIPTION
*
* This routine aborts the wait for a client to connect. If PPP
* negotiation has started for the link, this function returns
* an error.
*
* AUTHOR
*
* Rick Gonchar
*
* INPUTS
*
* CHAR *link_name Pointer to the PPP link name.
*
* OUTPUTS
*
* NU_SUCCESS The wait for a client was aborted.
* NU_INVALID_LINK The link_name specified is not a valid
* PPP link.
* NU_BUSY A client is currently connecting.
*
************************************************************************/
STATUS PPP_Abort_Wait_For_Client (CHAR *link_name)
{
STATUS ret_status;
DV_DEVICE_ENTRY *dev_ptr;
/* Get the device for the link name. */
dev_ptr = DEV_Get_Dev_By_Name (link_name);
/* Make sure we got a device and that it is a PPP device. */
if ((dev_ptr) && (dev_ptr->dev_type == DVT_PPP))
{
if (((PPP_LAYER *)dev_ptr->link_layer)->connection_status == NU_PPP_WAITING)
{
/* Set the flag which will cause the modem layer to abort the wait for a client */
((PPP_LAYER *)dev_ptr->link_layer)->connection_status = NU_PPP_WAITING_ABORTED;
ret_status = NU_SUCCESS;
}
else
ret_status = NU_BUSY;
}
else
ret_status = NU_INVALID_LINK;
return (ret_status);
}
/************************************************************************
* FUNCTION
*
* PPP_Set_Link_Options
*
* DESCRIPTION
*
* Initializes the LCP configuration options to be used for a
* particular PPP link.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* CHAR *link_name Pointer to the name of the PPP
* link to which the options will
* be applied.
*
* NU_LCP_OPTIONS *lcp_opts Pointer to the LCP options
* structure that will be applied
* to the PPP link.
*
* NU_NCP_OPTIONS *ncp_opts Pointer to the NCP options
* structure that will be applied
* to the PPP link.
*
* OUTPUTS
*
* STATUS NU_SUCCESS if the options are
* successfully applied, otherwise
* NU_INVALID_LINK is returned
*
************************************************************************/
STATUS PPP_Set_Link_Options (CHAR *link_name, NU_LCP_OPTIONS *lcp_opts,
NU_NCP_OPTIONS *ncp_opts)
{
DV_DEVICE_ENTRY *dev_ptr;
LCP_LAYER *lcp;
IPCP_LAYER *ipcp;
STATUS ret_status;
/* Init */
ret_status = NU_INVALID_PARM;
/* Find the device for this link name. */
dev_ptr = DEV_Get_Dev_By_Name (link_name);
/* Make sure the device was found and that it is a PPP device. */
if ((dev_ptr) && (dev_ptr->dev_type == DVT_PPP))
{
/* Make sure the options pointer is valid */
if (lcp_opts)
{
/* Get a pointer to the LCP structure for this link. */
lcp = &((LINK_LAYER *)dev_ptr->link_layer)->lcp;
/* Copy the new options over. */
memcpy (&lcp->local_options, lcp_opts, sizeof (NU_LCP_OPTIONS));
/* Set the return value. */
ret_status = NU_SUCCESS;
}
/* Make sure the options pointer is valid */
if (ncp_opts)
{
/* Get a pointer to the LCP structure for this link. */
ipcp = &((LINK_LAYER *)dev_ptr->link_layer)->ipcp;
/* Copy the new options over. */
memcpy (&ipcp->network_options, ncp_opts, sizeof (NU_NCP_OPTIONS));
/* Set the return value. */
ret_status = NU_SUCCESS;
}
}
else
ret_status = NU_INVALID_LINK;
return (ret_status);
}
/************************************************************************
* FUNCTION
*
* PPP_Clean_Up_Link
*
* DESCRIPTION
*
* This function removes all routes that were added when a PPP device
* became active. It will also remove any DNS servers added by the PPP
* device. This is used when the link is going down.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* DV_DEVICE_ENTRY *dev_ptr Pointer to device structure
*
* OUTPUTS
*
* STATUS NU_SUCCESS
*
************************************************************************/
VOID PPP_Clean_Up_Link (DV_DEVICE_ENTRY *dev_ptr)
{
ROUTE_NODE *rt;
SCK_SOCKADDR_IP device_ip_num;
LINK_LAYER *link_layer;
/* Get a pointer to the PPP structure. */
link_layer = (LINK_LAYER*)dev_ptr->dev_ppp_layer;
/* Remove the route to the other end of the PPP link. */
/* Store the IP address in this socket structure. This will be used
below to remove the route associated with this IP address. */
memcpy (&device_ip_num.sck_addr, (CHAR *)&dev_ptr->dev_addr.dev_dst_ip_addr, IP_ADDR_LEN);
/* Find the node that contains this route and remove it. Note that the
device_ip_num structure only has the IP address filled in. The
RTAB_Find_Route function only uses the IP address. */
rt = RTAB_Find_Route(&device_ip_num);
/* Make sure a route was found. */
if (rt)
{
/* The refernece count was incremented by RTAB_Find_Route. We are not
using the route so decrement the refernce count. */
rt->rt_refcnt--;
/* Before we delete it make sure it is the route we want to delete
and not the default route. Note: this code will eventually
be change to a NU_Delete_Route. */
if (IP_ADDR(rt->rt_rip2->ip_addr) == dev_ptr->dev_addr.dev_dst_ip_addr)
/* Delete the route. */
RTAB_Delete_Node (rt);
}
/* Remove primary DNS server entry and the route to it. */
/* Make sure there is a primary DNS server. */
if (IP_ADDR (link_layer->ipcp.primary_dns_server) != NU_NULL)
{
NU_Delete_DNS_Server (link_layer->ipcp.primary_dns_server);
/* Store the IP address in this socket structure. This will be used
below to remove the route associated with this IP address. */
device_ip_num.sck_addr = IP_ADDR (link_layer->ipcp.primary_dns_server);
/* Find the node that contains this route and remove it. Note that the
device_ip_num structure only has the IP address filled in. The
RTAB_Find_Route function only uses the IP address. */
rt = RTAB_Find_Route(&device_ip_num);
/* Make sure a route was found. */
if (rt)
{
/* The refernece count was incremented by RTAB_Find_Route. We are not
using the route so decrement the refernce count. */
rt->rt_refcnt--;
/* Before we delete it make sure it is the route we want to delete
and not the default route. Note: this code will eventually
be change to a NU_Delete_Route. */
if (IP_ADDR(rt->rt_rip2->ip_addr) == IP_ADDR (link_layer->ipcp.primary_dns_server))
/* Delete the route. */
RTAB_Delete_Node (rt);
}
}
/* Remove secondary DNS server entry and the route to it. */
/* Make sure there is a secondary DNS server. */
if (IP_ADDR (link_layer->ipcp.secondary_dns_server) != NU_NULL)
{
NU_Delete_DNS_Server (link_layer->ipcp.secondary_dns_server);
/* Store the IP address in this socket structure. This will be used
below to remove the route associated with this IP address. */
device_ip_num.sck_addr = IP_ADDR (link_layer->ipcp.secondary_dns_server);
/* Find the node that contains this route and remove it. Note that the
device_ip_num structure only has the IP address filled in. The
RTAB_Find_Route function only uses the IP address. */
rt = RTAB_Find_Route(&device_ip_num);
/* Make sure a route was found. */
if (rt)
{
/* The refernece count was incremented by RTAB_Find_Route. We are not
using the route so decrement the refernce count. */
rt->rt_refcnt--;
/* Before we delete it make sure it is the route we want to delete
and not the default route. Note: this code will eventually
be change to a NU_Delete_Route. */
if (IP_ADDR(rt->rt_rip2->ip_addr) == IP_ADDR (link_layer->ipcp.secondary_dns_server))
/* Delete the route. */
RTAB_Delete_Node (rt);
}
}
} /* PPP_Clean_Up_Link */
/************************************************************************
* FUNCTION
*
* PPP_Event_Handler
*
* DESCRIPTION
*
* Handles processing of all PPP events.
*
* AUTHOR
*
* Uriah Pollock
*
* INPUTS
*
* DV_DEVICE_ENTRY *dev_ptr Pointer to PPP device structure.
* UNSIGNED ppp_event PPP event to be serviced.
*
* OUTPUTS
*
* STATUS NU_SUCCESS
*
************************************************************************/
STATUS PPP_Event_Handler (DV_DEVICE_ENTRY *dev_ptr, UNSIGNED ppp_event)
{
LCP_LAYER *lcp;
IPCP_LAYER *ipcp;
AUTHENTICATION_LAYER *auth;
LINK_LAYER *link_layer;
link_layer = (LINK_LAYER*)dev_ptr->dev_ppp_layer;
/* Switch on the event and do the appropriate processing. */
switch (ppp_event)
{
case LCP_RESEND :
/* Get a pointer to the LCP structure. */
lcp = &link_layer->lcp;
/* Remove the PPP header that was added the first time
this packet was sent. */
lcp->negotiation_pkt->data_ptr += PPP_HEADER_SIZE;
lcp->negotiation_pkt->data_len -= PPP_HEADER_SIZE;
lcp->negotiation_pkt->mem_total_data_len -= PPP_HEADER_SIZE;
/* Send the packet again. */
dev_ptr->dev_output (lcp->negotiation_pkt, dev_ptr,
NU_NULL, NU_NULL);
break;
case LCP_SEND_CONFIG :
/* Send a new configure request packet */
LCP_Send_Config_Req (dev_ptr);
break;
case MDM_HANGUP :
link_layer->disconnect(link_layer, NU_FALSE);
break;
case LCP_ECHO_REQ :
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -