task #12722 (improve IPv4/v6 address handling): renamed ip_addr_t to ip4_addr_t, renamed ipX_addr_t to ip_addr_t and added IP version;

ip_addr_t is used for all generic IP addresses for the API, ip(4/6)_addr_t are only used internally or when initializing netifs or when calling version-related functions
This commit is contained in:
sg
2015-04-09 22:21:15 +02:00
parent 4ff1eb1890
commit ce7e31cd04
74 changed files with 1709 additions and 1395 deletions

View File

@@ -71,7 +71,7 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}};
#define LL_MULTICAST_ADDR_1 0x00
#define LL_MULTICAST_ADDR_2 0x5e
#if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */
/** the time an ARP entry stays valid after its last update,
* for ARP_TMR_INTERVAL = 1000, this is
@@ -114,7 +114,7 @@ struct etharp_entry {
/** Pointer to a single pending outgoing packet on this ARP entry. */
struct pbuf *q;
#endif /* ARP_QUEUEING */
ip_addr_t ipaddr;
ip4_addr_t ipaddr;
struct netif *netif;
struct eth_addr ethaddr;
u16_t ctime;
@@ -149,7 +149,7 @@ static u8_t etharp_cached_entry;
#endif
static err_t etharp_request_dst(struct netif *netif, const ip_addr_t *ipaddr, const struct eth_addr* hw_dst_addr);
static err_t etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr);
#if ARP_QUEUEING
@@ -198,7 +198,7 @@ etharp_free_entry(int i)
/* for debugging, clean out the complete entry */
arp_table[i].ctime = 0;
arp_table[i].netif = NULL;
ip_addr_set_zero(&arp_table[i].ipaddr);
ip4_addr_set_zero(&arp_table[i].ipaddr);
arp_table[i].ethaddr = ethzero;
#endif /* LWIP_DEBUG */
}
@@ -239,12 +239,9 @@ etharp_tmr(void)
/* Reset state to stable, so that the next transmitted packet will
re-send an ARP request. */
arp_table[i].state = ETHARP_STATE_STABLE;
}
/* still pending entry? (not expired) */
else if (arp_table[i].state == ETHARP_STATE_PENDING) {
/* resend an ARP query here? */
if (etharp_request(arp_table[i].netif, &arp_table[i].ipaddr) != ERR_OK) {
}
} else if (arp_table[i].state == ETHARP_STATE_PENDING) {
/* still pending, resend an ARP query */
etharp_request(arp_table[i].netif, &arp_table[i].ipaddr);
}
}
}
@@ -272,7 +269,7 @@ etharp_tmr(void)
* entry is found or could be recycled.
*/
static s8_t
etharp_find_entry(const ip_addr_t *ipaddr, u8_t flags, struct netif* netif)
etharp_find_entry(const ip4_addr_t *ipaddr, u8_t flags, struct netif* netif)
{
s8_t old_pending = ARP_TABLE_SIZE, old_stable = ARP_TABLE_SIZE;
s8_t empty = ARP_TABLE_SIZE;
@@ -310,7 +307,7 @@ etharp_find_entry(const ip_addr_t *ipaddr, u8_t flags, struct netif* netif)
LWIP_ASSERT("state == ETHARP_STATE_PENDING || state >= ETHARP_STATE_STABLE",
state == ETHARP_STATE_PENDING || state >= ETHARP_STATE_STABLE);
/* if given, does IP address match IP address in ARP entry? */
if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)
if (ipaddr && ip4_addr_cmp(ipaddr, &arp_table[i].ipaddr)
#if ETHARP_TABLE_MATCH_NETIF
&& ((netif == NULL) || (netif == arp_table[i].netif))
#endif /* ETHARP_TABLE_MATCH_NETIF */
@@ -410,7 +407,7 @@ etharp_find_entry(const ip_addr_t *ipaddr, u8_t flags, struct netif* netif)
/* IP address given? */
if (ipaddr != NULL) {
/* set IP address */
ip_addr_copy(arp_table[i].ipaddr, *ipaddr);
ip4_addr_copy(arp_table[i].ipaddr, *ipaddr);
}
arp_table[i].ctime = 0;
#if ETHARP_TABLE_MATCH_NETIF
@@ -479,7 +476,7 @@ etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr *src, struct
* @see pbuf_free()
*/
static err_t
etharp_update_arp_entry(struct netif *netif, const ip_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
{
s8_t i;
LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == ETHARP_HWADDR_LEN);
@@ -488,9 +485,9 @@ etharp_update_arp_entry(struct netif *netif, const ip_addr_t *ipaddr, struct eth
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
/* non-unicast address? */
if (ip_addr_isany(ipaddr) ||
ip_addr_isbroadcast(ipaddr, netif) ||
ip_addr_ismulticast(ipaddr)) {
if (ip4_addr_isany(ipaddr) ||
ip4_addr_isbroadcast(ipaddr, netif) ||
ip4_addr_ismulticast(ipaddr)) {
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_update_arp_entry: will not add non-unicast IP address to ARP cache\n"));
return ERR_ARG;
}
@@ -557,7 +554,7 @@ etharp_update_arp_entry(struct netif *netif, const ip_addr_t *ipaddr, struct eth
* @return @see return values of etharp_add_static_entry
*/
err_t
etharp_add_static_entry(const ip_addr_t *ipaddr, struct eth_addr *ethaddr)
etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr)
{
struct netif *netif;
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_add_static_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
@@ -565,7 +562,7 @@ etharp_add_static_entry(const ip_addr_t *ipaddr, struct eth_addr *ethaddr)
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
netif = ip_route(ipaddr);
netif = ip4_route(ipaddr);
if (netif == NULL) {
return ERR_RTE;
}
@@ -582,7 +579,7 @@ etharp_add_static_entry(const ip_addr_t *ipaddr, struct eth_addr *ethaddr)
* ERR_ARG: entry wasn't a static entry but a dynamic one
*/
err_t
etharp_remove_static_entry(const ip_addr_t *ipaddr)
etharp_remove_static_entry(const ip4_addr_t *ipaddr)
{
s8_t i;
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_remove_static_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
@@ -634,8 +631,8 @@ void etharp_cleanup_netif(struct netif *netif)
* @return table index if found, -1 otherwise
*/
s8_t
etharp_find_addr(struct netif *netif, const ip_addr_t *ipaddr,
struct eth_addr **eth_ret, const ip_addr_t **ip_ret)
etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr,
struct eth_addr **eth_ret, const ip4_addr_t **ip_ret)
{
s8_t i;
@@ -674,7 +671,7 @@ etharp_ip_input(struct netif *netif, struct pbuf *p)
{
struct eth_hdr *ethhdr;
struct ip_hdr *iphdr;
ip_addr_t iphdr_src;
ip4_addr_t iphdr_src;
LWIP_ERROR("netif != NULL", (netif != NULL), return;);
/* Only insert an entry if the source IP address of the
@@ -687,10 +684,10 @@ etharp_ip_input(struct netif *netif, struct pbuf *p)
}
#endif /* ETHARP_SUPPORT_VLAN */
ip_addr_copy(iphdr_src, iphdr->src);
ip4_addr_copy(iphdr_src, iphdr->src);
/* source is not on the local network? */
if (!ip_addr_netcmp(&iphdr_src, &(netif->ip_addr), &(netif->netmask))) {
if (!ip4_addr_netcmp(&iphdr_src, &(netif->ip_addr), &(netif->netmask))) {
/* do nothing */
return;
}
@@ -724,7 +721,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
struct etharp_hdr *hdr;
struct eth_hdr *ethhdr;
/* these are aligned properly, whereas the ARP header fields might not be */
ip_addr_t sipaddr, dipaddr;
ip4_addr_t sipaddr, dipaddr;
u8_t for_us;
#if LWIP_AUTOIP
const u8_t * ethdst_hwaddr;
@@ -755,7 +752,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
/* RFC 826 "Packet Reception": */
if ((hdr->hwtype != PP_HTONS(HWTYPE_ETHERNET)) ||
(hdr->hwlen != ETHARP_HWADDR_LEN) ||
(hdr->protolen != sizeof(ip_addr_t)) ||
(hdr->protolen != sizeof(ip4_addr_t)) ||
(hdr->proto != PP_HTONS(ETHTYPE_IP))) {
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
("etharp_arp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n",
@@ -774,17 +771,17 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
autoip_arp_reply(netif, hdr);
#endif /* LWIP_AUTOIP */
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
/* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without
* structure packing (not using structure copy which breaks strict-aliasing rules). */
IPADDR2_COPY(&sipaddr, &hdr->sipaddr);
IPADDR2_COPY(&dipaddr, &hdr->dipaddr);
/* this interface is not configured? */
if (ip_addr_isany(&netif->ip_addr)) {
if (ip4_addr_isany(&netif->ip_addr)) {
for_us = 0;
} else {
/* ARP packet directed to us? */
for_us = (u8_t)ip_addr_cmp(&dipaddr, &(netif->ip_addr));
for_us = (u8_t)ip4_addr_cmp(&dipaddr, &(netif->ip_addr));
}
/* ARP message directed to us?
@@ -822,7 +819,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
/* If we are using Link-Local, all ARP packets that contain a Link-Local
* 'sender IP address' MUST be sent using link-layer broadcast instead of
* link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */
ethdst_hwaddr = ip_addr_islinklocal(&netif->ip_addr) ? (u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr;
ethdst_hwaddr = ip4_addr_islinklocal(&netif->ip_addr) ? (u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr;
#endif /* LWIP_AUTOIP */
ETHADDR16_COPY(&hdr->dhwaddr, &hdr->shwaddr);
@@ -840,7 +837,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
/* return ARP reply */
netif->linkoutput(netif, p);
/* we are not configured? */
} else if (ip_addr_isany(&netif->ip_addr)) {
} else if (ip4_addr_isany(&netif->ip_addr)) {
/* { for_us == 0 and netif->ip_addr.addr == 0 } */
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n"));
/* request was not directed to us */
@@ -917,11 +914,11 @@ etharp_output_to_arp_index(struct netif *netif, struct pbuf *q, u8_t arp_idx)
* or the return type of either etharp_query() or etharp_send_ip().
*/
err_t
etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
{
struct eth_addr *dest;
struct eth_addr mcastaddr;
const ip_addr_t *dst_addr = ipaddr;
const ip4_addr_t *dst_addr = ipaddr;
LWIP_ASSERT("netif != NULL", netif != NULL);
LWIP_ASSERT("q != NULL", q != NULL);
@@ -944,11 +941,11 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
* are special, other IP addresses are looked up in the ARP table. */
/* broadcast destination IP address? */
if (ip_addr_isbroadcast(ipaddr, netif)) {
if (ip4_addr_isbroadcast(ipaddr, netif)) {
/* broadcast on Ethernet also */
dest = (struct eth_addr *)&ethbroadcast;
/* multicast destination IP address? */
} else if (ip_addr_ismulticast(ipaddr)) {
} else if (ip4_addr_ismulticast(ipaddr)) {
/* Hash IP multicast address to MAC address.*/
mcastaddr.addr[0] = LL_MULTICAST_ADDR_0;
mcastaddr.addr[1] = LL_MULTICAST_ADDR_1;
@@ -963,8 +960,8 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
s8_t i;
/* outside local network? if so, this can neither be a global broadcast nor
a subnet broadcast. */
if (!ip_addr_netcmp(ipaddr, &(netif->ip_addr), &(netif->netmask)) &&
!ip_addr_islinklocal(ipaddr)) {
if (!ip4_addr_netcmp(ipaddr, &(netif->ip_addr), &(netif->netmask)) &&
!ip4_addr_islinklocal(ipaddr)) {
#if LWIP_AUTOIP
struct ip_hdr *iphdr = (struct ip_hdr*)((u8_t*)q->payload +
#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
@@ -975,7 +972,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
a link-local source address must always be "directly to its destination
on the same physical link. The host MUST NOT send the packet to any
router for forwarding". */
if (!ip_addr_islinklocal(&iphdr->src))
if (!ip4_addr_islinklocal(&iphdr->src))
#endif /* LWIP_AUTOIP */
{
#ifdef LWIP_HOOK_ETHARP_GET_GW
@@ -986,7 +983,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
#endif /* LWIP_HOOK_ETHARP_GET_GW */
{
/* interface has default gateway? */
if (!ip_addr_isany(&netif->gw)) {
if (!ip4_addr_isany(&netif->gw)) {
/* send to hardware address of default gateway IP address */
dst_addr = &(netif->gw);
/* no default gateway available */
@@ -1004,7 +1001,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
if (etharp_cached_entry < ARP_TABLE_SIZE) {
#endif /* LWIP_NETIF_HWADDRHINT */
if ((arp_table[etharp_cached_entry].state >= ETHARP_STATE_STABLE) &&
(ip_addr_cmp(dst_addr, &arp_table[etharp_cached_entry].ipaddr))) {
(ip4_addr_cmp(dst_addr, &arp_table[etharp_cached_entry].ipaddr))) {
/* the per-pcb-cached entry is stable and the right one! */
ETHARP_STATS_INC(etharp.cachehit);
return etharp_output_to_arp_index(netif, q, etharp_cached_entry);
@@ -1018,7 +1015,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
throughput and etharp_find_entry() is kind of slow */
for (i = 0; i < ARP_TABLE_SIZE; i++) {
if ((arp_table[i].state >= ETHARP_STATE_STABLE) &&
(ip_addr_cmp(dst_addr, &arp_table[i].ipaddr))) {
(ip4_addr_cmp(dst_addr, &arp_table[i].ipaddr))) {
/* found an existing, stable entry */
ETHARP_SET_HINT(netif, i);
return etharp_output_to_arp_index(netif, q, i);
@@ -1069,7 +1066,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
*
*/
err_t
etharp_query(struct netif *netif, const ip_addr_t *ipaddr, struct pbuf *q)
etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
{
struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr;
err_t result = ERR_MEM;
@@ -1077,9 +1074,9 @@ etharp_query(struct netif *netif, const ip_addr_t *ipaddr, struct pbuf *q)
s8_t i; /* ARP entry index */
/* non-unicast address? */
if (ip_addr_isbroadcast(ipaddr, netif) ||
ip_addr_ismulticast(ipaddr) ||
ip_addr_isany(ipaddr)) {
if (ip4_addr_isbroadcast(ipaddr, netif) ||
ip4_addr_ismulticast(ipaddr) ||
ip4_addr_isany(ipaddr)) {
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: will not add non-unicast IP address to ARP cache\n"));
return ERR_ARG;
}
@@ -1246,8 +1243,8 @@ static
err_t
etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
const struct eth_addr *ethdst_addr,
const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr,
const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr,
const u16_t opcode)
{
struct pbuf *p;
@@ -1291,12 +1288,12 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
/* If we are using Link-Local, all ARP packets that contain a Link-Local
* 'sender IP address' MUST be sent using link-layer broadcast instead of
* link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */
ethdst_hwaddr = ip_addr_islinklocal(ipsrc_addr) ? (u8_t*)(ethbroadcast.addr) : ethdst_addr->addr;
ethdst_hwaddr = ip4_addr_islinklocal(ipsrc_addr) ? (u8_t*)(ethbroadcast.addr) : ethdst_addr->addr;
#endif /* LWIP_AUTOIP */
/* Write the ARP MAC-Addresses */
ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr);
ETHADDR16_COPY(&hdr->dhwaddr, hwdst_addr);
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
/* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without
* structure packing. */
IPADDR2_COPY(&hdr->sipaddr, ipsrc_addr);
IPADDR2_COPY(&hdr->dipaddr, ipdst_addr);
@@ -1305,7 +1302,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
hdr->proto = PP_HTONS(ETHTYPE_IP);
/* set hwlen and protolen */
hdr->hwlen = ETHARP_HWADDR_LEN;
hdr->protolen = sizeof(ip_addr_t);
hdr->protolen = sizeof(ip4_addr_t);
#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
ethhdr->type = PP_HTONS(ETHTYPE_VLAN);
@@ -1353,7 +1350,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
* any other err_t on failure
*/
static err_t
etharp_request_dst(struct netif *netif, const ip_addr_t *ipaddr, const struct eth_addr* hw_dst_addr)
etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr)
{
return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, hw_dst_addr,
(struct eth_addr *)netif->hwaddr, &netif->ip_addr, &ethzero,
@@ -1370,12 +1367,12 @@ etharp_request_dst(struct netif *netif, const ip_addr_t *ipaddr, const struct et
* any other err_t on failure
*/
err_t
etharp_request(struct netif *netif, const ip_addr_t *ipaddr)
etharp_request(struct netif *netif, const ip4_addr_t *ipaddr)
{
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n"));
return etharp_request_dst(netif, ipaddr, &ethbroadcast);
}
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 && LWIP_ARP */
/**
* Process received ethernet frames. Using this function instead of directly
@@ -1458,7 +1455,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
}
switch (type) {
#if LWIP_ARP
#if LWIP_IPV4 && LWIP_ARP
/* IP packet? */
case PP_HTONS(ETHTYPE_IP):
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
@@ -1488,7 +1485,7 @@ ethernet_input(struct pbuf *p, struct netif *netif)
/* pass p to ARP module */
etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p);
break;
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 && LWIP_ARP */
#if PPPOE_SUPPORT
case PP_HTONS(ETHTYPE_PPPOEDISC): /* PPP Over Ethernet Discovery Stage */
pppoe_disc_input(netif, p);

View File

@@ -181,7 +181,7 @@ const struct protent* const protocols[] = {
/* Prototypes for procedures local to this file. */
static void ppp_do_connect(void *arg);
static err_t ppp_netif_init_cb(struct netif *netif);
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip_addr_t *ipaddr);
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr);
#if PPP_IPV6_SUPPORT
static err_t ppp_netif_output_ip6(struct netif *netif, struct pbuf *pb, const ip6_addr_t *ipaddr);
#endif /* PPP_IPV6_SUPPORT */
@@ -426,7 +426,7 @@ static err_t ppp_netif_init_cb(struct netif *netif) {
/*
* Send an IPv4 packet on the given connection.
*/
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip_addr_t *ipaddr) {
static err_t ppp_netif_output_ip4(struct netif *netif, struct pbuf *pb, const ip4_addr_t *ipaddr) {
#if PPP_IPV4_SUPPORT
ppp_pcb *pcb = (ppp_pcb*)netif->state;
LWIP_UNUSED_ARG(ipaddr);
@@ -556,7 +556,7 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
pcb->settings.fsm_max_nak_loops = FSM_DEFMAXNAKLOOPS;
pcb->netif = pppif;
if (!netif_add(pcb->netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY,
if (!netif_add(pcb->netif, IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY,
(void *)pcb, ppp_netif_init_cb, NULL)) {
memp_free(MEMP_PPP_PCB, pcb);
PPPDEBUG(LOG_ERR, ("ppp_new: netif_add failed\n"));
@@ -861,7 +861,7 @@ int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp) {
* sifaddr - Config the interface IP addresses and netmask.
*/
int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask) {
ip_addr_t ip, nm, gw;
ip4_addr_t ip, nm, gw;
ip4_addr_set_u32(&ip, our_adr);
ip4_addr_set_u32(&nm, netmask);
@@ -879,7 +879,7 @@ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) {
LWIP_UNUSED_ARG(our_adr);
LWIP_UNUSED_ARG(his_adr);
netif_set_addr(pcb->netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY);
netif_set_addr(pcb->netif, IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY);
return 1;
}
@@ -915,9 +915,9 @@ int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
ip_addr_t ns;
LWIP_UNUSED_ARG(pcb);
ip4_addr_set_u32(&ns, ns1);
ip_addr_set_ip4_u32(&ns, ns1);
dns_setserver(0, &ns);
ip4_addr_set_u32(&ns, ns2);
ip_addr_set_ip4_u32(&ns, ns2);
dns_setserver(1, &ns);
return 1;
}
@@ -931,12 +931,12 @@ int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) {
LWIP_UNUSED_ARG(pcb);
nsa = dns_getserver(0);
ip4_addr_set_u32(&nsb, ns1);
ip_addr_set_ip4_u32(&nsb, ns1);
if (ip_addr_cmp(&nsa, &nsb)) {
dns_setserver(0, (ip_addr_t*)IP_ADDR_ANY);
}
nsa = dns_getserver(1);
ip4_addr_set_u32(&nsb, ns2);
ip_addr_set_ip4_u32(&nsb, ns2);
if (ip_addr_cmp(&nsa, &nsb)) {
dns_setserver(1, (ip_addr_t*)IP_ADDR_ANY);
}

View File

@@ -82,10 +82,7 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx); /* Be a LAC, connect
static void pppol2tp_disconnect(ppp_pcb *ppp, void *ctx); /* Disconnect */
/* Prototypes for procedures local to this file. */
static void pppol2tp_input_ip4(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
#if LWIP_IPV6
static void pppol2tp_input_ip6(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip6_addr_t *addr, u16_t port);
#endif /* LWIP_IPV6 */
static void pppol2tp_input_ip(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
static void pppol2tp_input(pppol2tp_pcb *l2tp, struct pbuf *p, u16_t port);
static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, struct pbuf *p, u16_t ns, u16_t nr);
static void pppol2tp_timeout(void *arg);
@@ -122,7 +119,7 @@ static const struct link_callbacks pppol2tp_callbacks = {
/* Create a new L2TP session. */
ppp_pcb *pppol2tp_create(struct netif *pppif,
struct netif *netif, ip_addr_t *ipaddr, u16_t port,
struct netif *netif, ip4_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
ppp_pcb *ppp;
@@ -146,14 +143,18 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
ppp_free(ppp);
return NULL;
}
udp_recv(udp, pppol2tp_input_ip4, l2tp);
udp_recv(udp, pppol2tp_input_ip, l2tp);
memset(l2tp, 0, sizeof(pppol2tp_pcb));
l2tp->phase = PPPOL2TP_STATE_INITIAL;
l2tp->ppp = ppp;
l2tp->udp = udp;
l2tp->netif = netif;
ip_addr_set(ipX_2_ip(&l2tp->remote_ip), ipaddr);
if (ipaddr) {
ip_addr_copy_from_ip4(l2tp->remote_ip, *ipaddr);
} else {
ip_addr_set_any(0, &l2tp->remote_ip);
}
l2tp->remote_port = port;
#if PPPOL2TP_AUTH_SUPPORT
l2tp->secret = secret;
@@ -191,14 +192,18 @@ ppp_pcb *pppol2tp_create_ip6(struct netif *pppif,
ppp_free(ppp);
return NULL;
}
udp_recv_ip6(udp, pppol2tp_input_ip6, l2tp);
udp_recv(udp, pppol2tp_input_ip, l2tp);
memset(l2tp, 0, sizeof(pppol2tp_pcb));
l2tp->phase = PPPOL2TP_STATE_INITIAL;
l2tp->ppp = ppp;
l2tp->udp = udp;
l2tp->netif = netif;
ip6_addr_set(&l2tp->remote_ip.ip6, ip6addr);
if (ip6addr) {
ip_addr_copy_from_ip6(l2tp->remote_ip, *ip6addr);
} else {
ip_addr_set_any(1, &l2tp->remote_ip);
}
l2tp->remote_port = port;
#if PPPOL2TP_AUTH_SUPPORT
l2tp->secret = secret;
@@ -351,7 +356,7 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) {
*/
#if LWIP_IPV6
if (PCB_ISIPV6(l2tp->udp)) {
udp_bind_ip6(l2tp->udp, IP6_ADDR_ANY, 0);
udp_bind(l2tp->udp, IP6_ADDR_ANY, 0);
} else
#endif /* LWIP_IPV6 */
udp_bind(l2tp->udp, IP_ADDR_ANY, 0);
@@ -392,7 +397,7 @@ static void pppol2tp_disconnect(ppp_pcb *ppp, void *ctx) {
}
/* UDP Callback for incoming IPv4 L2TP frames */
static void pppol2tp_input_ip4(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) {
static void pppol2tp_input_ip(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) {
pppol2tp_pcb *l2tp = (pppol2tp_pcb*)arg;
LWIP_UNUSED_ARG(pcb);
@@ -400,7 +405,7 @@ static void pppol2tp_input_ip4(void *arg, struct udp_pcb *pcb, struct pbuf *p, c
goto free_and_return;
}
if (!ip_addr_cmp(ipX_2_ip(&l2tp->remote_ip), addr)) {
if (!ip_addr_cmp(&l2tp->remote_ip, addr)) {
goto free_and_return;
}
@@ -411,28 +416,6 @@ free_and_return:
pbuf_free(p);
}
#if LWIP_IPV6
/* UDP Callback for incoming IPv6 L2TP frames */
static void pppol2tp_input_ip6(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip6_addr_t *addr, u16_t port) {
pppol2tp_pcb *l2tp = (pppol2tp_pcb*)arg;
LWIP_UNUSED_ARG(pcb);
if (l2tp->phase < PPPOL2TP_STATE_SCCRQ_SENT) {
goto free_and_return;
}
if (!ip6_addr_cmp(&l2tp->remote_ip.ip6, addr)) {
goto free_and_return;
}
pppol2tp_input(l2tp, p, port);
return;
free_and_return:
pbuf_free(p);
}
#endif /* LWIP_IPV6 */
static void pppol2tp_input(pppol2tp_pcb *l2tp, struct pbuf *p, u16_t port) {
u16_t hflags, hlen, len=0, tunnel_id=0, session_id=0, ns=0, nr=0, offset=0;
u8_t *inp;
@@ -1215,19 +1198,10 @@ static err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb) {
static err_t pppol2tp_udp_send(pppol2tp_pcb *l2tp, struct pbuf *pb) {
err_t err;
#if LWIP_IPV6
if (PCB_ISIPV6(l2tp->udp)) {
if (l2tp->netif) {
err = udp_sendto_if_ip6(l2tp->udp, pb, &l2tp->remote_ip.ip6, l2tp->tunnel_port, l2tp->netif);
} else {
err = udp_sendto_ip6(l2tp->udp, pb, &l2tp->remote_ip.ip6, l2tp->tunnel_port);
}
} else
#endif /* LWIP_IPV6 */
if (l2tp->netif) {
err = udp_sendto_if(l2tp->udp, pb, ipX_2_ip(&l2tp->remote_ip), l2tp->tunnel_port, l2tp->netif);
err = udp_sendto_if(l2tp->udp, pb, &l2tp->remote_ip, l2tp->tunnel_port, l2tp->netif);
} else {
err = udp_sendto(l2tp->udp, pb, ipX_2_ip(&l2tp->remote_ip), l2tp->tunnel_port);
err = udp_sendto(l2tp->udp, pb, &l2tp->remote_ip, l2tp->tunnel_port);
}
pbuf_free(pb);
return err;

View File

@@ -216,6 +216,7 @@ pppos_write(ppp_pcb *ppp, void *ctx, struct pbuf *p)
u16_t n;
u16_t fcs_out;
err_t err;
LWIP_UNUSED_ARG(ppp);
/* Grab an output buffer. */
nb = pbuf_alloc(PBUF_RAW, 0, PBUF_POOL);
@@ -261,6 +262,7 @@ pppos_netif_output(ppp_pcb *ppp, void *ctx, struct pbuf *pb, u16_t protocol)
struct pbuf *nb, *p;
u16_t fcs_out;
err_t err;
LWIP_UNUSED_ARG(ppp);
#if VJ_SUPPORT
/*

View File

@@ -172,8 +172,8 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf *pb)
* again & we don't have to do any reordering if it's used.
*/
INCR(vjs_packets);
if (!ip_addr_cmp(&ip->src, &cs->cs_ip.src)
|| !ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
if (!ip4_addr_cmp(&ip->src, &cs->cs_ip.src)
|| !ip4_addr_cmp(&ip->dest, &cs->cs_ip.dest)
|| *(long *)th != ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
/*
* Wasn't the first -- search for it.
@@ -193,8 +193,8 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf *pb)
do {
lcs = cs; cs = cs->cs_next;
INCR(vjs_searches);
if (ip_addr_cmp(&ip->src, &cs->cs_ip.src)
&& ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
if (ip4_addr_cmp(&ip->src, &cs->cs_ip.src)
&& ip4_addr_cmp(&ip->dest, &cs->cs_ip.dest)
&& *(long *)th == ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
goto found;
}