📄 ppp.c
字号:
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 :
/* Send a echo request packet */
LCP_Send_Echo_Req (dev_ptr);
break;
case NCP_RESEND :
/* Get a pointer to the IPCP structure. */
ipcp = &link_layer->ipcp;
/* Remove the PPP header that was added the first time
this packet was sent. */
ipcp->negotiation_pkt->data_ptr += PPP_HEADER_SIZE;
ipcp->negotiation_pkt->data_len -= PPP_HEADER_SIZE;
ipcp->negotiation_pkt->mem_total_data_len -= PPP_HEADER_SIZE;
/* Send the packet again. */
dev_ptr->dev_output (ipcp->negotiation_pkt, dev_ptr,
NU_NULL, NU_NULL);
break;
case NCP_SEND_CONFIG :
/* Get a pointer to the IPCP structure. */
ipcp = &link_layer->ipcp;
/* Send it to the host */
NCP_IP_Send_Config_Req (ipcp->local_ip_address, dev_ptr);
break;
case LCP_CLOSE_LINK :
/* Get a pointer to the LCP structure. */
lcp = &link_layer->lcp;
/* Close the network down. */
SCK_Kill_All_Open_Sockets(dev_ptr);
/* Clean up routes, etc. */
PPP_Clean_Up_Link (dev_ptr);
/* Detach the IP address from this device. */
DEV_Detach_IP_From_Device (dev_ptr->dev_net_if_name);
/* Send a terminate request */
LCP_Send_Terminate_Req(dev_ptr);
/* Start the timer */
NU_Reset_Timer (&lcp->restart_timer, LCP_Timer_Expire,
LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_ENABLE_TIMER);
break;
case PAP_SEND_AUTH:
/* Retransmit the authentication pkt */
PAP_Send_Authentication(dev_ptr);
break;
case CHAP_RESEND:
/* Get a pointer to the authentication structure. */
auth = &link_layer->authentication;
/* Remove the PPP header that was added the first time
this packet was sent. */
auth->negotiation_pkt->data_ptr += PPP_HEADER_SIZE;
auth->negotiation_pkt->data_len -= PPP_HEADER_SIZE;
auth->negotiation_pkt->mem_total_data_len -= PPP_HEADER_SIZE;
/* Resend the last sent chap packet */
dev_ptr->dev_output (auth->negotiation_pkt, dev_ptr,
NU_NULL, NU_NULL);
break;
case CHAP_CHALL:
/* Send the CHAP challenge */
CHAP_Send_Challenge(dev_ptr);
break;
case PPP_STOP_NEGOTIATION:
/* Get a pointer to the IPCP structure. */
ipcp = &((LINK_LAYER *)dev_ptr->link_layer)->ipcp;
/* Get a pointer to the authentication structure. */
auth = &((LINK_LAYER *)dev_ptr->link_layer)->authentication;
/* Get a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -