mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-08 00:23:39 +08:00
Merged from DEVEL into main tree.
This commit is contained in:
@@ -4,8 +4,10 @@
|
||||
*
|
||||
* Functionally, ARP is divided into two parts. The first maps an IP address
|
||||
* to a physical address when sending a packet, and the second part answers
|
||||
* requests from other machines.
|
||||
* requests from other machines for our physical address.
|
||||
*
|
||||
* This implementation complies with RFC 826 (Ethernet ARP) and supports
|
||||
* Gratuitious ARP from RFC3220 (IP Mobility Support for IPv4) section 4.6.
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -156,23 +158,16 @@ etharp_tmr(void)
|
||||
if ((arp_table[i].state == ETHARP_STATE_STABLE) &&
|
||||
(arp_table[i].ctime >= ARP_MAXAGE)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired stable entry %u.\n", i));
|
||||
arp_table[i].state = ETHARP_STATE_EMPTY;
|
||||
#if ARP_QUEUEING
|
||||
if (arp_table[i].p != NULL) {
|
||||
/* remove any queued packet */
|
||||
LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: freeing packet queue %p.\n", i, (void *)(arp_table[i].p)));
|
||||
pbuf_free(arp_table[i].p);
|
||||
arp_table[i].p = NULL;
|
||||
}
|
||||
#endif
|
||||
goto empty;
|
||||
} else if ((arp_table[i].state == ETHARP_STATE_PENDING) &&
|
||||
(arp_table[i].ctime >= ARP_MAXPENDING)) {
|
||||
arp_table[i].state = ETHARP_STATE_EMPTY;
|
||||
LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired pending entry %u.\n", i));
|
||||
empty:
|
||||
arp_table[i].state = ETHARP_STATE_EMPTY;
|
||||
#if ARP_QUEUEING
|
||||
if (arp_table[i].p != NULL) {
|
||||
/* remove any queued packet */
|
||||
LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: freeing packet queue %p.\n", i, (void *)(arp_table[i].p)));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: freeing entry %u, packet queue %p.\n", i, (void *)(arp_table[i].p)));
|
||||
pbuf_free(arp_table[i].p);
|
||||
arp_table[i].p = NULL;
|
||||
}
|
||||
@@ -292,6 +287,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
|
||||
ethhdr = p->payload;
|
||||
for (k = 0; k < netif->hwaddr_len; ++k) {
|
||||
ethhdr->dest.addr[k] = ethaddr->addr[k];
|
||||
ethhdr->src.addr[k] = netif->hwaddr[k];
|
||||
}
|
||||
ethhdr->type = htons(ETHTYPE_IP);
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet.\n"));
|
||||
@@ -390,7 +386,8 @@ etharp_ip_input(struct netif *netif, struct pbuf *p)
|
||||
|
||||
|
||||
/**
|
||||
* Responds to ARP requests, updates ARP entries and sends queued IP packets.
|
||||
* Responds to ARP requests to us. Upon ARP replies to us, add entry to cache
|
||||
* send out queued IP packets. Updates cache with snooped address pairs.
|
||||
*
|
||||
* Should be called for incoming ARP packets. The pbuf in the argument
|
||||
* is freed by this function.
|
||||
@@ -408,15 +405,24 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
{
|
||||
struct etharp_hdr *hdr;
|
||||
u8_t i;
|
||||
u8_t for_us;
|
||||
|
||||
/* drop short ARP packets */
|
||||
if (p->tot_len < sizeof(struct etharp_hdr)) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 1, ("etharp_arp_input: packet too short (%d/%d)\n", p->tot_len, sizeof(struct etharp_hdr)));
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 1, ("etharp_arp_input: packet dropped, too short (%d/%d)\n", p->tot_len, sizeof(struct etharp_hdr)));
|
||||
pbuf_free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdr = p->payload;
|
||||
|
||||
/* this interface is not configured? */
|
||||
if (netif->ip_addr.addr == 0) {
|
||||
for_us = 0;
|
||||
} else {
|
||||
/* ARP packet directed to us? */
|
||||
for_us = ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr));
|
||||
}
|
||||
|
||||
switch (htons(hdr->opcode)) {
|
||||
/* ARP request? */
|
||||
@@ -432,10 +438,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
pbuf_free(p);
|
||||
return NULL;
|
||||
}
|
||||
/* update the ARP cache */
|
||||
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);
|
||||
/* ARP request for our address? */
|
||||
if (ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) {
|
||||
if (for_us) {
|
||||
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: replying to ARP request for our IP address\n"));
|
||||
/* re-use pbuf to send ARP reply */
|
||||
@@ -454,41 +458,42 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
hdr->hwtype = htons(HWTYPE_ETHERNET);
|
||||
ARPH_HWLEN_SET(hdr, netif->hwaddr_len);
|
||||
|
||||
hdr->proto = htons(ETHTYPE_IP);
|
||||
hdr->proto = htons(ETHTYPE_IP);
|
||||
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
||||
|
||||
hdr->ethhdr.type = htons(ETHTYPE_ARP);
|
||||
hdr->ethhdr.type = htons(ETHTYPE_ARP);
|
||||
/* return ARP reply */
|
||||
netif->linkoutput(netif, p);
|
||||
|
||||
/* request was not directed to us */
|
||||
} else {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP request was not for us.\n"));
|
||||
}
|
||||
break;
|
||||
case ARP_REPLY:
|
||||
/* ARP reply. We insert or update the ARP table. */
|
||||
/* ARP reply. We insert or update the ARP table later. */
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n"));
|
||||
#if (LWIP_DHCP && DHCP_DOES_ARP_CHECK)
|
||||
/* DHCP needs to know about ARP replies */
|
||||
dhcp_arp_reply(netif, &hdr->sipaddr);
|
||||
/* DHCP needs to know about ARP replies to our address */
|
||||
if (for_us) dhcp_arp_reply(netif, &hdr->sipaddr);
|
||||
#endif
|
||||
/* ARP reply directed to us? */
|
||||
if (ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply is for us\n"));
|
||||
/* update_the ARP cache, ask to insert */
|
||||
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG);
|
||||
/* ARP reply not directed to us */
|
||||
} else {
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply is not for us\n"));
|
||||
/* update the destination address pair */
|
||||
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);
|
||||
/* update the destination address pair */
|
||||
update_arp_entry(netif, &(hdr->dipaddr), &(hdr->dhwaddr), 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: ARP unknown opcode type %d\n", htons(hdr->opcode)));
|
||||
break;
|
||||
}
|
||||
/* add or update entries in the ARP cache */
|
||||
if (for_us) {
|
||||
/* insert IP address in ARP cache (assume requester wants to talk to us)
|
||||
* we might even send out a queued packet to this host */
|
||||
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG);
|
||||
/* request was not directed to us, but snoop anyway */
|
||||
} else {
|
||||
/* update or insert the source IP address in the cache */
|
||||
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);
|
||||
/* update or insert the destination IP address pair in the cache */
|
||||
update_arp_entry(netif, &(hdr->dipaddr), &(hdr->dhwaddr), 0);
|
||||
}
|
||||
/* free ARP packet */
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
@@ -503,9 +508,9 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
* returned, ready to be sent.
|
||||
*
|
||||
* If ARP does not have the Ethernet address in cache the packet is
|
||||
* queued and a ARP request is sent (on a best-effort basis). This
|
||||
* ARP request is returned as a pbuf, which should be sent by the
|
||||
* caller.
|
||||
* queued (if enabled and space available) and a ARP request is sent.
|
||||
* This ARP request is returned as a pbuf, which should be sent by
|
||||
* the caller.
|
||||
*
|
||||
* If ARP failed to allocate resources, NULL is returned.
|
||||
*
|
||||
@@ -515,7 +520,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
* @param ipaddr The IP address of the packet destination.
|
||||
* @param pbuf The pbuf(s) containing the IP packet to be sent.
|
||||
*
|
||||
* @return If non-NULL, a packet ready to be sent.
|
||||
* @return If non-NULL, a packet ready to be sent by caller.
|
||||
*
|
||||
*/
|
||||
struct pbuf *
|
||||
etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
@@ -529,9 +535,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
/* The pbuf_header() call shouldn't fail, and we'll just bail
|
||||
out if it does.. */
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_output: could not allocate room for header.\n"));
|
||||
#ifdef LINK_STATS
|
||||
++lwip_stats.link.lenerr;
|
||||
#endif /* LINK_STATS */
|
||||
LINK_STATS_INC(link.lenerr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -541,9 +545,9 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
/* assume unresolved Ethernet address */
|
||||
dest = NULL;
|
||||
/* Construct Ethernet header. Start with looking up deciding which
|
||||
MAC address to use as a destination address. Broadcasts and
|
||||
multicasts are special, all other addresses are looked up in the
|
||||
ARP table. */
|
||||
MAC address to use as a destination address. Broadcasts and
|
||||
multicasts are special, all other addresses are looked up in the
|
||||
ARP table. */
|
||||
|
||||
/* destination IP address is an IP broadcast address? */
|
||||
if (ip_addr_isany(ipaddr) ||
|
||||
@@ -555,7 +559,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
else if (ip_addr_ismulticast(ipaddr)) {
|
||||
/* Hash IP multicast address to MAC address. */
|
||||
mcastaddr.addr[0] = 0x01;
|
||||
mcastaddr.addr[1] = 0x0;
|
||||
mcastaddr.addr[1] = 0x00;
|
||||
mcastaddr.addr[2] = 0x5e;
|
||||
mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f;
|
||||
mcastaddr.addr[4] = ip4_addr3(ipaddr);
|
||||
@@ -583,7 +587,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
}
|
||||
|
||||
/* Ethernet address for IP destination address is in ARP cache? */
|
||||
for(i = 0; i < ARP_TABLE_SIZE; ++i) {
|
||||
for (i = 0; i < ARP_TABLE_SIZE; ++i) {
|
||||
/* match found? */
|
||||
if (arp_table[i].state == ETHARP_STATE_STABLE &&
|
||||
ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) {
|
||||
@@ -594,6 +598,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
/* could not find the destination Ethernet address in ARP cache? */
|
||||
if (dest == NULL) {
|
||||
/* ARP query for the IP address, submit this IP packet for queueing */
|
||||
/* TODO: How do we handle netif->ipaddr == ipaddr? */
|
||||
etharp_query(netif, ipaddr, q);
|
||||
/* return nothing */
|
||||
return NULL;
|
||||
@@ -736,10 +741,12 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: sending ARP request.\n"));
|
||||
hdr = p->payload;
|
||||
hdr->opcode = htons(ARP_REQUEST);
|
||||
for(j = 0; j < netif->hwaddr_len; ++j)
|
||||
for (j = 0; j < netif->hwaddr_len; ++j)
|
||||
{
|
||||
hdr->dhwaddr.addr[j] = 0x00;
|
||||
hdr->shwaddr.addr[j] = srcaddr->addr[j];
|
||||
/* the hardware address is what we ask for, in
|
||||
* a request it is a don't-care, we use 0's */
|
||||
hdr->dhwaddr.addr[j] = 0x00;
|
||||
}
|
||||
ip_addr_set(&(hdr->dipaddr), ipaddr);
|
||||
ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr));
|
||||
@@ -749,7 +756,7 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
||||
|
||||
hdr->proto = htons(ETHTYPE_IP);
|
||||
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
||||
for(j = 0; j < netif->hwaddr_len; ++j)
|
||||
for (j = 0; j < netif->hwaddr_len; ++j)
|
||||
{
|
||||
hdr->ethhdr.dest.addr[j] = 0xff;
|
||||
hdr->ethhdr.src.addr[j] = srcaddr->addr[j];
|
||||
|
||||
@@ -63,7 +63,7 @@ static void ethernetif_input(struct netif *netif);
|
||||
static err_t ethernetif_output(struct netif *netif, struct pbuf *p,
|
||||
struct ip_addr *ipaddr);
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
low_level_init(struct netif *netif)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ low_level_init(struct netif *netif)
|
||||
|
||||
/* Do whatever else is needed to initialize interface. */
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* low_level_output():
|
||||
*
|
||||
@@ -96,7 +96,7 @@ low_level_init(struct netif *netif)
|
||||
* might be chained.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
static err_t
|
||||
low_level_output(struct ethernetif *ethernetif, struct pbuf *p)
|
||||
@@ -120,7 +120,7 @@ low_level_output(struct ethernetif *ethernetif, struct pbuf *p)
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* low_level_input():
|
||||
*
|
||||
@@ -128,7 +128,7 @@ low_level_output(struct ethernetif *ethernetif, struct pbuf *p)
|
||||
* packet from the interface into the pbuf.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static struct pbuf *
|
||||
low_level_input(struct ethernetif *ethernetif)
|
||||
{
|
||||
@@ -165,7 +165,7 @@ low_level_input(struct ethernetif *ethernetif)
|
||||
|
||||
return p;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* ethernetif_output():
|
||||
*
|
||||
@@ -174,7 +174,7 @@ low_level_input(struct ethernetif *ethernetif)
|
||||
* do the actuall transmission of the packet.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static err_t
|
||||
ethernetif_output(struct netif *netif, struct pbuf *p,
|
||||
struct ip_addr *ipaddr)
|
||||
@@ -264,7 +264,7 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
|
||||
return low_level_output(ethernetif, p);
|
||||
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* ethernetif_input():
|
||||
*
|
||||
@@ -274,7 +274,7 @@ ethernetif_output(struct netif *netif, struct pbuf *p,
|
||||
* interface.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
ethernetif_input(struct netif *netif)
|
||||
{
|
||||
@@ -314,14 +314,14 @@ ethernetif_input(struct netif *netif)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
arp_timer(void *arg)
|
||||
{
|
||||
arp_tmr();
|
||||
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* ethernetif_init():
|
||||
*
|
||||
@@ -330,7 +330,7 @@ arp_timer(void *arg)
|
||||
* actual setup of the hardware.
|
||||
*
|
||||
*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
ethernetif_init(struct netif *netif)
|
||||
{
|
||||
@@ -350,4 +350,4 @@ ethernetif_init(struct netif *netif)
|
||||
|
||||
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
@@ -40,13 +40,23 @@
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/ip.h"
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static void
|
||||
loopif_input( void * arg )
|
||||
{
|
||||
struct netif *netif = (struct netif *)( ((void **)arg)[ 0 ] );
|
||||
struct pbuf *r = (struct pbuf *)( ((void **)arg)[ 1 ] );
|
||||
|
||||
mem_free( arg );
|
||||
netif -> input( r, netif );
|
||||
}
|
||||
|
||||
static err_t
|
||||
loopif_output(struct netif *netif, struct pbuf *p,
|
||||
struct ip_addr *ipaddr)
|
||||
{
|
||||
struct pbuf *q, *r;
|
||||
char *ptr;
|
||||
void **arg;
|
||||
|
||||
#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP)
|
||||
tcpdump(p);
|
||||
@@ -60,21 +70,42 @@ loopif_output(struct netif *netif, struct pbuf *p,
|
||||
memcpy(ptr, q->payload, q->len);
|
||||
ptr += q->len;
|
||||
}
|
||||
netif->input(r, netif);
|
||||
|
||||
arg = mem_malloc( sizeof( void *[2]));
|
||||
if( NULL == arg ) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
arg[0] = netif;
|
||||
arg[1] = r;
|
||||
/**
|
||||
* workaround (patch #1779) to try to prevent bug #2595:
|
||||
* When connecting to "localhost" with the loopif interface,
|
||||
* tcp_output doesn't get the opportunity to finnish sending the
|
||||
* segment before tcp_process gets it, resulting in tcp_process
|
||||
* referencing pcb->unacked-> which still is NULL.
|
||||
*
|
||||
* TODO: Is there still a race condition here? Leon
|
||||
*/
|
||||
sys_timeout( 1, loopif_input, arg );
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_MEM;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
err_t
|
||||
loopif_init(struct netif *netif)
|
||||
{
|
||||
netif->name[0] = 'l';
|
||||
netif->name[1] = 'o';
|
||||
#if 0 /** TODO: I think this should be enabled, or not? Leon */
|
||||
netif->input = loopif_input;
|
||||
#endif
|
||||
netif->output = loopif_output;
|
||||
return ERR_OK;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ void link_terminated(int unit)
|
||||
if (logged_in)
|
||||
logout();
|
||||
lcp_phase[unit] = PHASE_DEAD;
|
||||
ppp_trace(LOG_NOTICE, "Connection terminated.\n");
|
||||
AUTHDEBUG((LOG_NOTICE, "Connection terminated.\n"));
|
||||
pppMainWakeup(unit);
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ void link_established(int unit)
|
||||
* of "" and a password of "". If that's not OK, boot it out.
|
||||
*/
|
||||
if (!wo->neg_upap || !null_login(unit)) {
|
||||
ppp_trace(LOG_WARNING, "peer refused to authenticate\n");
|
||||
AUTHDEBUG((LOG_WARNING, "peer refused to authenticate\n"));
|
||||
lcp_close(unit, "peer refused to authenticate");
|
||||
return;
|
||||
}
|
||||
@@ -294,7 +294,7 @@ void link_established(int unit)
|
||||
if (ppp_settings.passwd[0] == 0) {
|
||||
passwd_from_file = 1;
|
||||
if (!get_pap_passwd(unit, ppp_settings.user, ppp_settings.passwd))
|
||||
ppp_trace(LOG_ERR, "No secret found for PAP login\n");
|
||||
AUTHDEBUG((LOG_ERR, "No secret found for PAP login\n"));
|
||||
}
|
||||
upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd);
|
||||
auth |= PAP_WITHPEER;
|
||||
@@ -337,8 +337,8 @@ void auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
|
||||
pbit = PAP_PEER;
|
||||
break;
|
||||
default:
|
||||
ppp_trace(LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
||||
protocol);
|
||||
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
||||
protocol));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -400,8 +400,8 @@ void auth_withpeer_success(int unit, u16_t protocol)
|
||||
pbit = PAP_WITHPEER;
|
||||
break;
|
||||
default:
|
||||
ppp_trace(LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
||||
protocol);
|
||||
AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n",
|
||||
protocol));
|
||||
pbit = 0;
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ int check_passwd(
|
||||
* On 10'th, drop the connection.
|
||||
*/
|
||||
if (attempts++ >= 10) {
|
||||
ppp_trace(LOG_WARNING, "%d LOGIN FAILURES BY %s\n", attempts, user);
|
||||
AUTHDEBUG((LOG_WARNING, "%d LOGIN FAILURES BY %s\n", attempts, user));
|
||||
/*ppp_panic("Excess Bad Logins");*/
|
||||
}
|
||||
if (attempts > 3) {
|
||||
@@ -616,7 +616,7 @@ int get_secret(
|
||||
|
||||
len = strlen(ppp_settings.passwd);
|
||||
if (len > MAXSECRETLEN) {
|
||||
ppp_trace(LOG_ERR, "Secret for %s on %s is too long\n", client, server);
|
||||
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
||||
len = MAXSECRETLEN;
|
||||
}
|
||||
BCOPY(ppp_settings.passwd, secret, len);
|
||||
@@ -640,7 +640,7 @@ int get_secret(
|
||||
|
||||
len = strlen(secbuf);
|
||||
if (len > MAXSECRETLEN) {
|
||||
ppp_trace(LOG_ERR, "Secret for %s on %s is too long\n", client, server);
|
||||
AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
|
||||
len = MAXSECRETLEN;
|
||||
}
|
||||
BCOPY(secbuf, secret, len);
|
||||
@@ -753,7 +753,7 @@ static void check_idle(void *arg)
|
||||
itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle);
|
||||
if (itime >= ppp_settings.idle_time_limit) {
|
||||
/* link is idle: shut it down. */
|
||||
ppp_trace(LOG_INFO, "Terminating connection due to lack of activity.\n");
|
||||
AUTHDEBUG((LOG_INFO, "Terminating connection due to lack of activity.\n"));
|
||||
lcp_close(0, "Link inactive");
|
||||
} else {
|
||||
TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit - itime);
|
||||
@@ -767,7 +767,7 @@ static void connect_time_expired(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
ppp_trace(LOG_INFO, "Connect time expired\n");
|
||||
AUTHDEBUG((LOG_INFO, "Connect time expired\n"));
|
||||
lcp_close(0, "Connect time expired"); /* Close connection */
|
||||
}
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ void pppInit(void)
|
||||
(*protp->init)(i);
|
||||
}
|
||||
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
/* Clear the statistics. */
|
||||
memset(&lwip_stats.link, 0, sizeof(lwip_stats.link));
|
||||
#endif
|
||||
@@ -326,6 +326,29 @@ void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd)
|
||||
#endif
|
||||
ppp_settings.refuse_chap = 1;
|
||||
break;
|
||||
case PPPAUTHTYPE_ANY:
|
||||
/* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
|
||||
* RFC 1994 says:
|
||||
*
|
||||
* In practice, within or associated with each PPP server, there is a
|
||||
* database which associates "user" names with authentication
|
||||
* information ("secrets"). It is not anticipated that a particular
|
||||
* named user would be authenticated by multiple methods. This would
|
||||
* make the user vulnerable to attacks which negotiate the least secure
|
||||
* method from among a set (such as PAP rather than CHAP). If the same
|
||||
* secret was used, PAP would reveal the secret to be used later with
|
||||
* CHAP.
|
||||
*
|
||||
* Instead, for each user name there should be an indication of exactly
|
||||
* one method used to authenticate that user name. If a user needs to
|
||||
* make use of different authentication methods under different
|
||||
* circumstances, then distinct user names SHOULD be employed, each of
|
||||
* which identifies exactly one authentication method.
|
||||
*
|
||||
*/
|
||||
ppp_settings.refuse_pap = 0;
|
||||
ppp_settings.refuse_chap = 0;
|
||||
break;
|
||||
case PPPAUTHTYPE_PAP:
|
||||
ppp_settings.refuse_pap = 0;
|
||||
ppp_settings.refuse_chap = 1;
|
||||
@@ -459,7 +482,7 @@ static void nPut(PPPControl *pc, struct pbuf *nb)
|
||||
if((c = sio_write(pc->fd, b->payload, b->len)) != b->len) {
|
||||
PPPDEBUG((LOG_WARNING,
|
||||
"PPP nPut: incomplete sio_write(%d,, %u) = %d\n", pc->fd, b->len, c));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.err++;
|
||||
#endif /* LINK_STATS */
|
||||
pc->lastXMit = 0; /* prepend PPP_FLAG to next packet */
|
||||
@@ -468,7 +491,7 @@ static void nPut(PPPControl *pc, struct pbuf *nb)
|
||||
}
|
||||
pbuf_free(nb);
|
||||
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.xmit++;
|
||||
#endif /* LINK_STATS */
|
||||
}
|
||||
@@ -492,7 +515,7 @@ static struct pbuf *pppAppend(u_char c, struct pbuf *nb, ext_accm *outACCM)
|
||||
if (tb) {
|
||||
nb->next = tb;
|
||||
}
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
else {
|
||||
lwip_stats.link.memerr++;
|
||||
}
|
||||
@@ -529,7 +552,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
|
||||
if (pd < 0 || pd >= NUM_PPP || !pc->openFlag || !pb) {
|
||||
PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: bad parms prot=%d pb=%p\n",
|
||||
pd, protocol, pb));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.opterr++;
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
@@ -539,7 +562,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
|
||||
/* Check that the link is up. */
|
||||
if (lcp_phase[pd] == PHASE_DEAD) {
|
||||
PPPDEBUG((LOG_ERR, "pppifOutput[%d]: link not up\n", pd));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.rterr++;
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
@@ -550,7 +573,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
|
||||
headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
|
||||
if (headMB == NULL) {
|
||||
PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: first alloc fail\n", pd));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.memerr++;
|
||||
lwip_stats.link.drop++;
|
||||
#endif /* LINK_STATS */
|
||||
@@ -577,7 +600,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
|
||||
break;
|
||||
default:
|
||||
PPPDEBUG((LOG_WARNING, "pppifOutput[%d]: bad IP packet\n", pd));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.proterr++;
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
@@ -639,7 +662,7 @@ static err_t pppifOutput(struct netif *netif, struct pbuf *pb, struct ip_addr *i
|
||||
"pppifOutput[%d]: Alloc err - dropping proto=%d\n",
|
||||
pd, protocol));
|
||||
pbuf_free(headMB);
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.memerr++;
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
@@ -728,7 +751,7 @@ int pppWrite(int pd, const u_char *s, int n)
|
||||
struct pbuf *headMB = NULL, *tailMB;
|
||||
headMB = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
|
||||
if (headMB == NULL) {
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.memerr++;
|
||||
lwip_stats.link.proterr++;
|
||||
#endif /* LINK_STATS */
|
||||
@@ -768,7 +791,7 @@ int pppWrite(int pd, const u_char *s, int n)
|
||||
"pppWrite[%d]: Alloc err - dropping pbuf len=%d\n", pd, headMB->len));
|
||||
/* "pppWrite[%d]: Alloc err - dropping %d:%.*H", pd, headMB->len, LWIP_MIN(headMB->len * 2, 40), headMB->payload)); */
|
||||
pbuf_free(headMB);
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.memerr++;
|
||||
lwip_stats.link.proterr++;
|
||||
#endif /* LINK_STATS */
|
||||
@@ -1275,7 +1298,7 @@ static void pppInput(void *arg)
|
||||
|
||||
pbuf_header(nb, -(int)sizeof(struct pppInputHeader));
|
||||
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.recv++;
|
||||
#endif /* LINK_STATS */
|
||||
|
||||
@@ -1365,7 +1388,7 @@ static void pppInput(void *arg)
|
||||
}
|
||||
|
||||
drop:
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
|
||||
@@ -1395,7 +1418,7 @@ static void pppDrop(PPPControl *pc)
|
||||
vj_uncompress_err(&pc->vjComp);
|
||||
#endif
|
||||
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.drop++;
|
||||
#endif /* LINK_STATS */
|
||||
}
|
||||
@@ -1433,7 +1456,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
PPPDEBUG((LOG_WARNING,
|
||||
"pppInProc[%d]: Dropping incomplete packet %d\n",
|
||||
pd, pc->inState));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.lenerr++;
|
||||
#endif
|
||||
pppDrop(pc);
|
||||
@@ -1443,7 +1466,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
PPPDEBUG((LOG_INFO,
|
||||
"pppInProc[%d]: Dropping bad fcs 0x%04X proto=0x%04X\n",
|
||||
pd, pc->inFCS, pc->inProtocol));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.chkerr++;
|
||||
#endif
|
||||
pppDrop(pc);
|
||||
@@ -1457,14 +1480,12 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
|
||||
pc->inTail->tot_len = pc->inTail->len;
|
||||
if (pc->inTail != pc->inHead) {
|
||||
pbuf_chain(pc->inHead, pc->inTail);
|
||||
pbuf_free(pc->inTail);
|
||||
pbuf_cat(pc->inHead, pc->inTail);
|
||||
}
|
||||
} else {
|
||||
pc->inTail->tot_len = pc->inTail->len;
|
||||
if (pc->inTail != pc->inHead) {
|
||||
pbuf_chain(pc->inHead, pc->inTail);
|
||||
pbuf_free(pc->inTail);
|
||||
pbuf_cat(pc->inHead, pc->inTail);
|
||||
}
|
||||
|
||||
pbuf_realloc(pc->inHead, pc->inHead->tot_len - 2);
|
||||
@@ -1475,7 +1496,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
PPPDEBUG((LOG_ERR,
|
||||
"pppInProc[%d]: tcpip_callback() failed, dropping packet\n", pd));
|
||||
pbuf_free(pc->inHead);
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
}
|
||||
@@ -1560,8 +1581,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
if(pc->inTail) {
|
||||
pc->inTail->tot_len = pc->inTail->len;
|
||||
if (pc->inTail != pc->inHead) {
|
||||
pbuf_chain(pc->inHead, pc->inTail);
|
||||
pbuf_free(pc->inTail);
|
||||
pbuf_cat(pc->inHead, pc->inTail);
|
||||
}
|
||||
}
|
||||
/* If we haven't started a packet, we need a packet header. */
|
||||
@@ -1571,7 +1591,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
||||
* higher layers deal with it. Continue processing
|
||||
* the received pbuf chain in case a new packet starts. */
|
||||
PPPDEBUG((LOG_ERR, "pppInProc[%d]: NO FREE MBUFS!\n", pd));
|
||||
#ifdef LINK_STATS
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.memerr++;
|
||||
#endif /* LINK_STATS */
|
||||
pppDrop(pc);
|
||||
|
||||
@@ -208,8 +208,11 @@ enum NPmode {
|
||||
#define BCMP(s0, s1, l) memcmp((u_char *)(s0), (u_char *)(s1), (l))
|
||||
#define BCOPY(s, d, l) memcpy((d), (s), (l))
|
||||
#define BZERO(s, n) memset(s, 0, n)
|
||||
|
||||
#if PPP_DEBUG
|
||||
#define PRINTMSG(m, l) { m[l] = '\0'; ppp_trace(LOG_INFO, "Remote message: %s\n", m); }
|
||||
#else
|
||||
#define PRINTMSG(m, l)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MAKEHEADER - Add PPP Header fields to a packet.
|
||||
@@ -340,8 +343,28 @@ extern struct protent *ppp_protocols[];/* Table of pointers to supported protoco
|
||||
/* Initialize the PPP subsystem. */
|
||||
void pppInit(void);
|
||||
|
||||
/* Warning: Using PPPAUTHTYPE_ANY might have security consequences.
|
||||
* RFC 1994 says:
|
||||
*
|
||||
* In practice, within or associated with each PPP server, there is a
|
||||
* database which associates "user" names with authentication
|
||||
* information ("secrets"). It is not anticipated that a particular
|
||||
* named user would be authenticated by multiple methods. This would
|
||||
* make the user vulnerable to attacks which negotiate the least secure
|
||||
* method from among a set (such as PAP rather than CHAP). If the same
|
||||
* secret was used, PAP would reveal the secret to be used later with
|
||||
* CHAP.
|
||||
*
|
||||
* Instead, for each user name there should be an indication of exactly
|
||||
* one method used to authenticate that user name. If a user needs to
|
||||
* make use of different authentication methods under different
|
||||
* circumstances, then distinct user names SHOULD be employed, each of
|
||||
* which identifies exactly one authentication method.
|
||||
*
|
||||
*/
|
||||
enum pppAuthType {
|
||||
PPPAUTHTYPE_NONE,
|
||||
PPPAUTHTYPE_ANY,
|
||||
PPPAUTHTYPE_PAP,
|
||||
PPPAUTHTYPE_CHAP
|
||||
};
|
||||
|
||||
@@ -115,9 +115,7 @@ slipif_input( struct netif * netif )
|
||||
/* Received whole packet. */
|
||||
pbuf_realloc(q, recved);
|
||||
|
||||
#ifdef LINK_STATS
|
||||
++lwip_stats.link.recv;
|
||||
#endif /* LINK_STATS */
|
||||
LINK_STATS_INC(link.recv);
|
||||
|
||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
|
||||
return q;
|
||||
@@ -141,16 +139,13 @@ slipif_input( struct netif * netif )
|
||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: alloc\n"));
|
||||
p = pbuf_alloc(PBUF_LINK, PBUF_POOL_BUFSIZE, PBUF_POOL);
|
||||
|
||||
#ifdef LINK_STATS
|
||||
if (p == NULL) {
|
||||
++lwip_stats.link.drop;
|
||||
LINK_STATS_INC(link.drop);
|
||||
LWIP_DEBUGF(SLIP_DEBUG, ("slipif_input: no new pbuf! (DROP)\n"));
|
||||
}
|
||||
#endif /* LINK_STATS */
|
||||
|
||||
if (q != NULL) {
|
||||
pbuf_chain(q, p);
|
||||
pbuf_free(p);
|
||||
pbuf_cat(q, p);
|
||||
} else {
|
||||
q = p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user