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

@@ -95,7 +95,7 @@ struct api_msg_msg {
} bc;
/** used for lwip_netconn_do_getaddr */
struct {
ipX_addr_t API_MSG_M_DEF(ipaddr);
ip_addr_t API_MSG_M_DEF(ipaddr);
u16_t API_MSG_M_DEF(port);
u8_t local;
} ad;
@@ -124,8 +124,8 @@ struct api_msg_msg {
#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
/** used for lwip_netconn_do_join_leave_group */
struct {
API_MSG_M_DEF_C(ipX_addr_t, multiaddr);
API_MSG_M_DEF_C(ipX_addr_t, netif_addr);
API_MSG_M_DEF_C(ip_addr_t, multiaddr);
API_MSG_M_DEF_C(ip_addr_t, netif_addr);
enum netconn_igmp join_or_leave;
} jl;
#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */

View File

@@ -46,10 +46,10 @@
#include "lwip/opt.h"
#if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
#include "lwip/netif.h"
#include "lwip/udp.h"
//#include "lwip/udp.h"
#include "netif/etharp.h"
#ifdef __cplusplus
@@ -80,7 +80,7 @@ extern "C" {
struct autoip
{
ip_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */
ip4_addr_t llipaddr; /* the currently selected, probed, announced or used LL IP-Address */
u8_t state; /* current AutoIP state machine state */
u8_t sent_num; /* sent number of probes or announces, dependent on state */
u16_t ttw; /* ticks to wait, tick is AUTOIP_TMR_INTERVAL long */
@@ -116,6 +116,6 @@ void autoip_network_changed(struct netif *netif);
}
#endif
#endif /* LWIP_AUTOIP */
#endif /* LWIP_IPV4 && LWIP_AUTOIP */
#endif /* LWIP_HDR_AUTOIP_H */

View File

@@ -53,10 +53,10 @@ struct dhcp
u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */
u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */
u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */
ip_addr_t server_ip_addr; /* dhcp server address that offered this lease */
ip_addr_t offered_ip_addr;
ip_addr_t offered_sn_mask;
ip_addr_t offered_gw_addr;
ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */
ip4_addr_t offered_ip_addr;
ip4_addr_t offered_sn_mask;
ip4_addr_t offered_gw_addr;
u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
@@ -82,10 +82,10 @@ struct dhcp_msg
PACK_STRUCT_FIELD(u32_t xid);
PACK_STRUCT_FIELD(u16_t secs);
PACK_STRUCT_FIELD(u16_t flags);
PACK_STRUCT_FLD_S(ip_addr_p_t ciaddr);
PACK_STRUCT_FLD_S(ip_addr_p_t yiaddr);
PACK_STRUCT_FLD_S(ip_addr_p_t siaddr);
PACK_STRUCT_FLD_S(ip_addr_p_t giaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr);
PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr);
PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]);
PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]);
PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]);
@@ -126,7 +126,7 @@ void dhcp_network_changed(struct netif *netif);
/** if enabled, check whether the offered IP address is not in use, using ARP */
#if DHCP_DOES_ARP_CHECK
void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr);
void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr);
#endif
/** to be called every minute */

View File

@@ -36,7 +36,13 @@
#include "lwip/opt.h"
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
/* @todo/@fixme: implement IPV6 support for DNS (see task #12243) */
#if !LWIP_IPV4 && LWIP_DNS
/* init.c/timers.c compatibility until task #12243 is done: */
#define dns_init()
#define dns_tmr()
#define DNS_TMR_INTERVAL 1000
#elif LWIP_DNS /* don't build if not configured for use in lwipopts.h */
#ifdef __cplusplus
extern "C" {

View File

@@ -100,23 +100,25 @@ PACK_STRUCT_END
#define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c))
#if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV4 && LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
void icmp_input(struct pbuf *p, struct netif *inp);
void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
#endif /* LWIP_ICMP */
#endif /* LWIP_IPV4 && LWIP_ICMP */
#if (LWIP_IPV6 && LWIP_ICMP6)
#if LWIP_IPV4 && LWIP_IPV6 && LWIP_ICMP6
#define icmp_port_unreach(isipv6, pbuf) ((isipv6) ? \
icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT) : \
icmp_dest_unreach(pbuf, ICMP_DUR_PORT))
#elif LWIP_ICMP
#elif LWIP_IPV6 && LWIP_ICMP6
#define icmp_port_unreach(isipv6, pbuf) icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT)
#elif LWIP_IPV4 && LWIP_ICMP
#define icmp_port_unreach(isipv6, pbuf) icmp_dest_unreach(pbuf, ICMP_DUR_PORT)
#else /* (LWIP_IPV6 && LWIP_ICMP6) || LWIP_ICMP*/
#else /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) */
#define icmp_port_unreach(isipv6, pbuf)
#endif /* (LWIP_IPV6 && LWIP_ICMP6) || LWIP_ICMP*/
#endif /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) LWIP_IPV4*/
#ifdef __cplusplus
}

View File

@@ -40,7 +40,7 @@
#include "lwip/netif.h"
#include "lwip/pbuf.h"
#if LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV4 && LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
#ifdef __cplusplus
extern "C" {
@@ -75,7 +75,7 @@ struct igmp_group {
/** interface on which the group is active */
struct netif *netif;
/** multicast address */
ip_addr_t group_address;
ip4_addr_t group_address;
/** signifies we were the last person to report */
u8_t last_reporter_flag;
/** current state of the group */
@@ -91,16 +91,16 @@ void igmp_init(void);
err_t igmp_start(struct netif *netif);
err_t igmp_stop(struct netif *netif);
void igmp_report_groups(struct netif *netif);
struct igmp_group *igmp_lookfor_group(struct netif *ifp, const ip_addr_t *addr);
void igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest);
err_t igmp_joingroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr);
err_t igmp_leavegroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr);
struct igmp_group *igmp_lookfor_group(struct netif *ifp, const ip4_addr_t *addr);
void igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest);
err_t igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr);
err_t igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr);
void igmp_tmr(void);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 && LWIP_IGMP */
#endif /* LWIP_HDR_IGMP_H */

View File

@@ -1,3 +1,11 @@
/**
* @file
* This file (together with sockets.h) aims to provide structs and functions from
* - arpa/inet.h
* - netinet/in.h
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
@@ -35,6 +43,7 @@
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h"
#ifdef __cplusplus
extern "C" {
@@ -45,11 +54,19 @@ extern "C" {
#if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
typedef u32_t in_addr_t;
#endif
/** For compatibility with BSD code */
struct in_addr {
in_addr_t s_addr;
};
struct in6_addr {
union {
u8_t u8_addr[16];
u32_t u32_addr[4];
} un;
#define s6_addr un.u8_addr
};
/** 255.255.255.255 */
#define INADDR_NONE IPADDR_NONE
/** 127.0.0.1 */
@@ -59,7 +76,16 @@ struct in_addr {
/** 255.255.255.255 */
#define INADDR_BROADCAST IPADDR_BROADCAST
/* Definitions of the bits in an Internet address integer.
/** This macro can be used to initialize a variable of type struct in6_addr
to the IPv6 wildcard address. */
#define IN6ADDR_ANY_INIT {0,0,0,0}
/** This macro can be used to initialize a variable of type struct in6_addr
to the IPv6 loopback address. */
#define IN6ADDR_LOOPBACK_INIT {0,0,0,PP_HTONL(1)}
/** This variable is initialized by the system to contain the wildcard IPv6 address. */
extern const struct ip6_addr in6addr_any;
/* Definitions of the bits in an (IPv4) Internet address integer.
On subnets, host and network parts are found according to
the subnet mask, not these masks. */
@@ -94,6 +120,7 @@ struct in_addr {
#define IN_LOOPBACKNET IP_LOOPBACKNET
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX
#endif
@@ -103,17 +130,40 @@ struct in_addr {
#endif
#endif
#if LWIP_IPV4
#define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
#define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
/* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */
#define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr))
/* directly map this to the lwip internal functions */
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr)
/* if those casts were originally introduced solely to strip off any const qualifier, they could be removed. */
#define inet_ntoa(addr) ipaddr_ntoa((const ip_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((const ip_addr_t*)&(addr), buf, buflen)
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ipaddr_aton(cp, (ip4_addr_t*)addr)
#define inet_ntoa(addr) ipaddr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \
(target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \
(target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \
(target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];}
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \
(target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \
(target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \
(target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3];}
/* ATTENTION: the next define only works because both in6_addr and ip6_addr_t are an u32_t[4] effectively! */
#define inet6_addr_to_ip6addr_p(target_ip6addr_p, source_in6addr) ((target_ip6addr_p) = (ip6_addr_t*)(source_in6addr))
/* directly map this to the lwip internal functions */
#define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr)
#define inet6_ntoa(addr) ip6addr_ntoa((const ip6_addr_t*)&(addr))
#define inet6_ntoa_r(addr, buf, buflen) ip6addr_ntoa_r((const ip6_addr_t*)&(addr), buf, buflen)
#endif /* LWIP_IPV6 */
#ifdef __cplusplus
}

View File

@@ -1,92 +0,0 @@
/**
* @file
*
* INET v6 addresses.
*/
/*
* Copyright (c) 2010 Inico Technologies Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Ivan Delamer <delamer@inicotech.com>
*
*
* Please coordinate changes and requests with Ivan Delamer
* <delamer@inicotech.com>
*/
#ifndef LWIP_HDR_INET6_H
#define LWIP_HDR_INET6_H
#include "lwip/opt.h"
#if LWIP_IPV6 && LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#include "lwip/ip6_addr.h"
#include "lwip/def.h"
#ifdef __cplusplus
extern "C" {
#endif
/** For compatibility with BSD code */
struct in6_addr {
union {
u8_t u8_addr[16];
u32_t u32_addr[4];
} un;
#define s6_addr un.u8_addr
};
#define IN6ADDR_ANY_INIT {0,0,0,0}
#define IN6ADDR_LOOPBACK_INIT {0,0,0,PP_HTONL(1)}
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \
(target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \
(target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \
(target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];}
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \
(target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \
(target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \
(target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3];}
/* ATTENTION: the next define only works because both in6_addr and ip6_addr_t are an u32_t[4] effectively! */
#define inet6_addr_to_ip6addr_p(target_ip6addr_p, source_in6addr) ((target_ip6addr_p) = (ip6_addr_t*)(source_in6addr))
/* directly map this to the lwip internal functions */
#define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr)
#define inet6_ntoa(addr) ip6addr_ntoa((ip6_addr_t*)&(addr))
#define inet6_ntoa_r(addr, buf, buflen) ip6addr_ntoa_r((ip6_addr_t*)&(addr), buf, buflen)
#ifdef __cplusplus
}
#endif
#endif /* LWIP_IPV6 */
#endif /* LWIP_HDR_INET6_H */

View File

@@ -72,38 +72,30 @@ extern "C" {
u16_t inet_chksum(void *dataptr, u16_t len);
u16_t inet_chksum_pbuf(struct pbuf *p);
u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
const ip_addr_t *src, const ip_addr_t *dest);
u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto,
u16_t proto_len, u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest);
#if LWIP_CHKSUM_COPY_ALGORITHM
u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len);
#endif /* LWIP_CHKSUM_COPY_ALGORITHM */
#if LWIP_IPV4
u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
const ip4_addr_t *src, const ip4_addr_t *dest);
u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto,
u16_t proto_len, u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
const ip6_addr_t *src, const ip6_addr_t *dest);
u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest);
#define ipX_chksum_pseudo(isipv6, p, proto, proto_len, src, dest) \
((isipv6) ? \
ip6_chksum_pseudo(p, proto, proto_len, ipX_2_ip6(src), ipX_2_ip6(dest)) :\
inet_chksum_pseudo(p, proto, proto_len, ipX_2_ip(src), ipX_2_ip(dest)))
#define ipX_chksum_pseudo_partial(isipv6, p, proto, proto_len, chksum_len, src, dest) \
((isipv6) ? \
ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ipX_2_ip6(src), ipX_2_ip6(dest)) :\
inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ipX_2_ip(src), ipX_2_ip(dest)))
#else /* LWIP_IPV6 */
#define ipX_chksum_pseudo(isipv6, p, proto, proto_len, src, dest) \
inet_chksum_pseudo(p, proto, proto_len, src, dest)
#define ipX_chksum_pseudo_partial(isipv6, p, proto, proto_len, chksum_len, src, dest) \
inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, src, dest)
#endif /* LWIP_IPV6 */
u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
const ip_addr_t *src, const ip_addr_t *dest);
u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest);
#ifdef __cplusplus
}
#endif

View File

@@ -46,6 +46,15 @@
extern "C" {
#endif
#define IP_PROTO_ICMP 1
#define IP_PROTO_IGMP 2
#define IP_PROTO_UDP 17
#define IP_PROTO_UDPLITE 136
#define IP_PROTO_TCP 6
/** This operates on a void* by loading the first byte */
#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4)
/* This is passed as the destination address to ip_output_if (not
to ip_output), meaning that an IP header already is constructed
in the pbuf. This is used when TCP retransmits. */
@@ -66,8 +75,8 @@ extern "C" {
#define IP_PCB_ADDRHINT
#endif /* LWIP_NETIF_HWADDRHINT */
#if LWIP_IPV6
#define IP_PCB_ISIPV6_MEMBER u8_t isipv6;
#if LWIP_IPV6 && LWIP_IPV4
#define IP_PCB_ISIPV6_MEMBER u8_t isipv6;
#define IP_PCB_IPVER_EQ(pcb1, pcb2) ((pcb1)->isipv6 == (pcb2)->isipv6)
#define IP_PCB_IPVER_INPUT_MATCH(pcb) (ip_current_is_v6() ? \
((pcb)->isipv6 != 0) : \
@@ -77,7 +86,7 @@ extern "C" {
#define IP_PCB_ISIPV6_MEMBER
#define IP_PCB_IPVER_EQ(pcb1, pcb2) 1
#define IP_PCB_IPVER_INPUT_MATCH(pcb) 1
#define PCB_ISIPV6(pcb) 0
#define PCB_ISIPV6(pcb) LWIP_IPV6
#endif /* LWIP_IPV6 */
/* This is the common part of all PCB types. It needs to be at the
@@ -87,8 +96,8 @@ extern "C" {
#define IP_PCB \
IP_PCB_ISIPV6_MEMBER \
/* ip addresses in network byte order */ \
ipX_addr_t local_ip; \
ipX_addr_t remote_ip; \
ip_addr_t local_ip; \
ip_addr_t remote_ip; \
/* Socket options */ \
u8_t so_options; \
/* Type Of Service */ \
@@ -120,8 +129,10 @@ struct ip_globals
struct netif *current_netif;
/** The interface that received the packet for the current callback invocation. */
struct netif *current_input_netif;
#if LWIP_IPV4
/** Header of the input packet currently being processed. */
const struct ip_hdr *current_ip4_header;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
/** Header of the input IPv6 packet currently being processed. */
const struct ip6_hdr *current_ip6_header;
@@ -129,9 +140,9 @@ struct ip_globals
/** Total header length of current_ip4/6_header (i.e. after this, the UDP/TCP header starts) */
u16_t current_ip_header_tot_len;
/** Source IP address of current_header */
ipX_addr_t current_iphdr_src;
ip_addr_t current_iphdr_src;
/** Destination IP address of current_header */
ipX_addr_t current_iphdr_dest;
ip_addr_t current_iphdr_dest;
};
extern struct ip_globals ip_data;
@@ -145,18 +156,18 @@ extern struct ip_globals ip_data;
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
#define ip_current_input_netif() (ip_data.current_input_netif)
/** Get the IP header of the current packet.
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
#define ip_current_header() (ip_data.current_ip4_header)
/** Total header length of ip(6)_current_header() (i.e. after this, the UDP/TCP header starts) */
#define ip_current_header_tot_len() (ip_data.current_ip_header_tot_len)
/** Source IP address of current_header */
#define ipX_current_src_addr() (&ip_data.current_iphdr_src)
#define ip_current_src_addr() (&ip_data.current_iphdr_src)
/** Destination IP address of current_header */
#define ipX_current_dest_addr() (&ip_data.current_iphdr_dest)
#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
/** Get the IPv4 header of the current packet.
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
#define ip4_current_header() (ip_data.current_ip4_header)
/** Get the IPv6 header of the current packet.
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
@@ -164,44 +175,65 @@ extern struct ip_globals ip_data;
/** Returns TRUE if the current IP input packet is IPv6, FALSE if it is IPv4 */
#define ip_current_is_v6() (ip6_current_header() != NULL)
/** Source IPv6 address of current_header */
#define ip6_current_src_addr() (ipX_2_ip6(&ip_data.current_iphdr_src))
#define ip6_current_src_addr() (ip_2_ip6(&ip_data.current_iphdr_src))
/** Destination IPv6 address of current_header */
#define ip6_current_dest_addr() (ipX_2_ip6(&ip_data.current_iphdr_dest))
#define ip6_current_dest_addr() (ip_2_ip6(&ip_data.current_iphdr_dest))
/** Get the transport layer protocol */
#define ip_current_header_proto() (ip_current_is_v6() ? \
IP6H_NEXTH(ip6_current_header()) :\
IPH_PROTO(ip_current_header()))
IPH_PROTO(ip4_current_header()))
/** Get the transport layer header */
#define ipX_next_header_ptr() ((void*)((ip_current_is_v6() ? \
(u8_t*)ip6_current_header() : (u8_t*)ip_current_header()) + ip_current_header_tot_len()))
#define ip_next_header_ptr() ((void*)((ip_current_is_v6() ? \
(u8_t*)ip6_current_header() : (u8_t*)ip4_current_header()) + ip_current_header_tot_len()))
/** Set an IP_PCB to IPv6 (IPv4 is the default) */
#define ip_set_v6(pcb, val) do{if(pcb != NULL) { pcb->isipv6 = val; }}while(0)
/** Source IP4 address of current_header */
#define ip_current_src_addr() (ipX_2_ip(&ip_data.current_iphdr_src))
#define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src))
/** Destination IP4 address of current_header */
#define ip_current_dest_addr() (ipX_2_ip(&ip_data.current_iphdr_dest))
#define ip4_current_dest_addr() (ip_2_ip4(&ip_data.current_iphdr_dest))
#else /* LWIP_IPV6 */
#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
/** Always returns FALSE when only supporting IPv4 */
/** Get the IPv4 header of the current packet.
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
#define ip4_current_header() (ip_data.current_ip4_header)
/** Always returns FALSE when only supporting IPv4 only */
#define ip_current_is_v6() 0
/** Get the transport layer protocol */
#define ip_current_header_proto() IPH_PROTO(ip_current_header())
#define ip_current_header_proto() IPH_PROTO(ip4_current_header())
/** Get the transport layer header */
#define ipX_next_header_ptr() ((void*)((u8_t*)ip_current_header() + ip_current_header_tot_len()))
#define ip_next_header_ptr() ((void*)((u8_t*)ip4_current_header() + ip_current_header_tot_len()))
/** Source IP4 address of current_header */
#define ip_current_src_addr() (&ip_data.current_iphdr_src)
#define ip4_current_src_addr() (&ip_data.current_iphdr_src)
/** Destination IP4 address of current_header */
#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
#define ip4_current_dest_addr() (&ip_data.current_iphdr_dest)
#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
/** Get the IPv6 header of the current packet.
* This function must only be called from a receive callback (udp_recv,
* raw_recv, tcp_accept). It will return NULL otherwise. */
#define ip6_current_header() (ip_data.current_ip6_header)
/** Always returns TRUE when only supporting IPv6 only */
#define ip_current_is_v6() 1
/** Get the transport layer protocol */
#define ip_current_header_proto() IP6H_NEXTH(ip6_current_header())
/** Get the transport layer header */
#define ip_next_header_ptr() ((void*)((u8_t*)ip6_current_header()))
/** Source IP6 address of current_header */
#define ip6_current_src_addr() (&ip_data.current_iphdr_src)
/** Destination IP6 address of current_header */
#define ip6_current_dest_addr() (&ip_data.current_iphdr_dest)
#endif /* LWIP_IPV6 */
/** Union source address of current_header */
#define ipX_current_src_addr() (&ip_data.current_iphdr_src)
#define ip_current_src_addr() (&ip_data.current_iphdr_src)
/** Union destination address of current_header */
#define ipX_current_dest_addr() (&ip_data.current_iphdr_dest)
#define ip_current_dest_addr() (&ip_data.current_iphdr_dest)
/** Gets an IP pcb option (SOF_* flags) */
#define ip_get_option(pcb, opt) ((pcb)->so_options & (opt))
@@ -210,51 +242,67 @@ extern struct ip_globals ip_data;
/** Resets an IP pcb option (SOF_* flags) */
#define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
#if LWIP_IPV6
#define ipX_output(isipv6, p, src, dest, ttl, tos, proto) \
#if LWIP_IPV4 && LWIP_IPV6
#define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
((isipv6) ? \
ip6_output(p, ipX_2_ip6(src), ipX_2_ip6(dest), ttl, tos, proto) : \
ip_output(p, ipX_2_ip(src), ipX_2_ip(dest), ttl, tos, proto))
#define ipX_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \
ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto))
#define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
((isipv6) ? \
ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
ip_output_if(p, (src), (dest), ttl, tos, proto, netif))
#define ipX_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
#define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
((isipv6) ? \
ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \
ip_output_if_src(p, (src), (dest), ttl, tos, proto, netif))
#define ipX_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
ip4_output_if_src(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif))
#define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
((isipv6) ? \
ip6_output_hinted(p, ipX_2_ip6(src), ipX_2_ip6(dest), ttl, tos, proto, addr_hint) : \
ip_output_hinted(p, ipX_2_ip(src), ipX_2_ip(dest), ttl, tos, proto, addr_hint))
#define ipX_route(isipv6, src, dest) \
ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \
ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint))
#define ip_route(isipv6, src, dest) \
((isipv6) ? \
ip6_route(ipX_2_ip6(src), ipX_2_ip6(dest)) : \
ip_route(ipX_2_ip(dest)))
#define ipX_netif_get_local_ipX(isipv6, netif, dest) \
((isipv6) ? \
ip6_netif_get_local_ipX(netif, ipX_2_ip6(dest)) : \
ip_netif_get_local_ipX(netif))
#define ipX_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip_debug_print(p))
#else /* LWIP_IPV6 */
#define ipX_output(isipv6, p, src, dest, ttl, tos, proto) \
ip_output(p, src, dest, ttl, tos, proto)
#define ipX_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip_output_if(p, src, dest, ttl, tos, proto, netif)
#define ipX_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip_output_if_src(p, src, dest, ttl, tos, proto, netif)
#define ipX_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
#define ipX_route(isipv6, src, dest) \
ip_route(ipX_2_ip(dest))
#define ipX_netif_get_local_ipX(isipv6, netif, dest) \
ip_netif_get_local_ipX(netif)
#define ipX_debug_print(is_ipv6, p) ip_debug_print(p)
ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \
ip4_route(ip_2_ip4(dest)))
#define ip_netif_get_local_ip(isipv6, netif, dest, storage) ((isipv6) ? \
ip6_2_ip(ip6_netif_get_local_ip(netif, ip_2_ip6(dest)), storage) : \
ip4_2_ip(ip4_netif_get_local_ip(netif), storage))
#define ip_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip4_debug_print(p))
err_t ip_input(struct pbuf *p, struct netif *inp);
#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
#define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
ip4_output(p, src, dest, ttl, tos, proto)
#define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip4_output_if(p, src, dest, ttl, tos, proto, netif)
#define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip4_output_if_src(p, src, dest, ttl, tos, proto, netif)
#define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
ip4_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
#define ip_route(isipv6, src, dest) \
ip4_route(dest)
#define ip_netif_get_local_ip(isipv6, netif, dest, storage) \
ip4_netif_get_local_ip(netif)
#define ip_debug_print(is_ipv6, p) ip4_debug_print(p)
#define ip_input(p, inp) ip4_input(p, inp)
#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */
#define ip_output(isipv6, p, src, dest, ttl, tos, proto) \
ip6_output(p, src, dest, ttl, tos, proto)
#define ip_output_if(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip6_output_if(p, src, dest, ttl, tos, proto, netif)
#define ip_output_if_src(isipv6, p, src, dest, ttl, tos, proto, netif) \
ip6_output_if_src(p, src, dest, ttl, tos, proto, netif)
#define ip_output_hinted(isipv6, p, src, dest, ttl, tos, proto, addr_hint) \
ip6_output_hinted(p, src, dest, ttl, tos, proto, addr_hint)
#define ip_route(isipv6, src, dest) \
ip6_route(src, dest)
#define ip_netif_get_local_ip(isipv6, netif, dest, storage) \
ip6_netif_get_local_ip(netif, dest)
#define ip_debug_print(is_ipv6, p) ip6_debug_print(p)
#define ip_input(p, inp) ip6_input(p, inp)
#endif /* LWIP_IPV6 */
#define ipX_route_get_local_ipX(isipv6, src, dest, netif, ipXaddr) do { \
(netif) = ipX_route(isipv6, src, dest); \
(ipXaddr) = ipX_netif_get_local_ipX(isipv6, netif, dest); \
#define ip_route_get_local_ip(isipv6, src, dest, netif, ipaddr, storage) do { \
(netif) = ip_route(isipv6, src, dest); \
(ipaddr) = ip_netif_get_local_ip(isipv6, netif, dest, storage); \
}while(0)
#ifdef __cplusplus

View File

@@ -34,6 +34,8 @@
#include "lwip/opt.h"
#if LWIP_IPV4
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
@@ -46,16 +48,10 @@ extern "C" {
#endif
/** Currently, the function ip_output_if_opt() is only used with IGMP */
#define IP_OPTIONS_SEND LWIP_IGMP
#define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP)
#define IP_HLEN 20
#define IP_PROTO_ICMP 1
#define IP_PROTO_IGMP 2
#define IP_PROTO_UDP 17
#define IP_PROTO_UDPLITE 136
#define IP_PROTO_TCP 6
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
@@ -83,8 +79,8 @@ struct ip_hdr {
/* checksum */
PACK_STRUCT_FIELD(u16_t _chksum);
/* source and destination IP addresses */
PACK_STRUCT_FLD_S(ip_addr_p_t src);
PACK_STRUCT_FLD_S(ip_addr_p_t dest);
PACK_STRUCT_FLD_S(ip4_addr_p_t src);
PACK_STRUCT_FLD_S(ip4_addr_p_t dest);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
@@ -110,45 +106,46 @@ PACK_STRUCT_END
#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
#define ip_init() /* Compatibility define, no init needed. */
struct netif *ip_route(const ip_addr_t *dest);
err_t ip_input(struct pbuf *p, struct netif *inp);
err_t ip_output(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
struct netif *ip4_route(const ip4_addr_t *dest);
err_t ip4_input(struct pbuf *p, struct netif *inp);
err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto);
err_t ip_output_if(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
err_t ip_output_if_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
#if LWIP_NETIF_HWADDRHINT
err_t ip_output_hinted(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint);
#endif /* LWIP_NETIF_HWADDRHINT */
#if IP_OPTIONS_SEND
err_t ip_output_if_opt(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
u16_t optlen);
err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
u16_t optlen);
#endif /* IP_OPTIONS_SEND */
#if LWIP_IGMP
void ip_set_default_multicast_netif(struct netif* default_multicast_netif);
void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
#endif /* LWIP_IGMP */
#define ip_netif_get_local_ipX(netif) (((netif) != NULL) ? ip_2_ipX(&((netif)->ip_addr)) : NULL)
#define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? &((netif)->ip_addr) : NULL)
#if IP_DEBUG
void ip_debug_print(struct pbuf *p);
void ip4_debug_print(struct pbuf *p);
#else
#define ip_debug_print(p)
#define ip4_debug_print(p)
#endif /* IP_DEBUG */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_IPV4 */
#endif /* LWIP_HDR_IP_H */

View File

@@ -35,23 +35,25 @@
#include "lwip/opt.h"
#include "lwip/def.h"
#if LWIP_IPV4
#ifdef __cplusplus
extern "C" {
#endif
/* This is the aligned version of ip_addr_t,
/* This is the aligned version of ip4_addr_t,
used as local variable, on the stack, etc. */
struct ip_addr {
struct ip4_addr {
u32_t addr;
};
/* This is the packed version of ip_addr_t,
/* This is the packed version of ip4_addr_t,
used in network headers that are itself packed */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct ip_addr_packed {
struct ip4_addr_packed {
PACK_STRUCT_FIELD(u32_t addr);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
@@ -59,10 +61,10 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
/** ip_addr_t uses a struct for convenience only, so that the same defines can
* operate both on ip_addr_t as well as on ip_addr_p_t. */
typedef struct ip_addr ip_addr_t;
typedef struct ip_addr_packed ip_addr_p_t;
/** ip4_addr_t uses a struct for convenience only, so that the same defines can
* operate both on ip4_addr_t as well as on ip4_addr_p_t. */
typedef struct ip4_addr ip4_addr_t;
typedef struct ip4_addr_packed ip4_addr_p_t;
/*
* struct ipaddr2 is used in the definition of the ARP packet format in
@@ -72,7 +74,7 @@ typedef struct ip_addr_packed ip_addr_p_t;
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct ip_addr2 {
struct ip4_addr2 {
PACK_STRUCT_FIELD(u16_t addrw[2]);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
@@ -83,15 +85,6 @@ PACK_STRUCT_END
/* Forward declaration to not include netif.h */
struct netif;
extern const ip_addr_t ip_addr_any;
extern const ip_addr_t ip_addr_broadcast;
/** IP_ADDR_ can be used as a fixed IP address
* for the wildcard and the broadcast address
*/
#define IP_ADDR_ANY (&ip_addr_any)
#define IP_ADDR_BROADCAST (&ip_addr_broadcast)
/** 255.255.255.255 */
#define IPADDR_NONE ((u32_t)0xffffffffUL)
/** 127.0.0.1 */
@@ -155,26 +148,26 @@ extern const ip_addr_t ip_addr_broadcast;
* 16-bit-aligned if the port is correctly configured (so a port could define
* this to copying 2 u16_t's) - no NULL-pointer-checking needed. */
#ifndef IPADDR2_COPY
#define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip_addr_t))
#define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t))
#endif
/** Copy IP address - faster than ip_addr_set: no NULL check */
#define ip_addr_copy(dest, src) ((dest).addr = (src).addr)
/** Copy IP address - faster than ip4_addr_set: no NULL check */
#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
/** Safely copy one IP address to another (src may be NULL) */
#define ip_addr_set(dest, src) ((dest)->addr = \
#define ip4_addr_set(dest, src) ((dest)->addr = \
((src) == NULL ? 0 : \
(src)->addr))
/** Set complete address to zero */
#define ip_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
/** Set address to IPADDR_ANY (no need for htonl()) */
#define ip_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
#define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
/** Set address to loopback address */
#define ip_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
#define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
/** Check if an address is in the loopback region */
#define ip_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
#define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
/** Safely copy one IP address to another and change byte order
* from host- to network-order. */
#define ip_addr_set_hton(dest, src) ((dest)->addr = \
#define ip4_addr_set_hton(dest, src) ((dest)->addr = \
((src) == NULL ? 0:\
htonl((src)->addr)))
/** IPv4 only: set the IP address given as an u32_t */
@@ -183,7 +176,7 @@ extern const ip_addr_t ip_addr_broadcast;
#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
/** Get the network address by combining host address with netmask */
#define ip_addr_get_network(target, host, netmask) ((target)->addr = ((host)->addr) & ((netmask)->addr))
#define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
/**
* Determine if two address are on the same network.
@@ -193,25 +186,25 @@ extern const ip_addr_t ip_addr_broadcast;
* @arg mask network identifier mask
* @return !0 if the network identifiers of both address match
*/
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
#define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
(mask)->addr) == \
((addr2)->addr & \
(mask)->addr))
#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
#define ip4_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
#define ip_addr_isbroadcast(ipaddr, netif) ip4_addr_isbroadcast((ipaddr)->addr, (netif))
u8_t ip4_addr_isbroadcast(u32_t addr, const struct netif *netif);
#define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
u8_t ip4_addr_isbroadcast_u32(u32_t addr, const struct netif *netif);
#define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
u8_t ip4_addr_netmask_valid(u32_t netmask);
#define ip_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
#define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
#define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
#define ip_addr_debug_print(debug, ipaddr) \
#define ip4_addr_debug_print(debug, ipaddr) \
LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, \
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
@@ -237,13 +230,15 @@ u8_t ip4_addr_netmask_valid(u32_t netmask);
#define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
u32_t ipaddr_addr(const char *cp);
int ipaddr_aton(const char *cp, ip_addr_t *addr);
int ip4addr_aton(const char *cp, ip4_addr_t *addr);
/** returns ptr to static buffer; not reentrant! */
char *ipaddr_ntoa(const ip_addr_t *addr);
char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen);
char *ip4addr_ntoa(const ip4_addr_t *addr);
char *ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_IPV4 */
#endif /* LWIP_HDR_IP_ADDR_H */

View File

@@ -179,8 +179,8 @@ err_t ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6
err_t ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value);
#endif /* LWIP_IPV6_MLD */
#define ip6_netif_get_local_ipX(netif, dest) (((netif) != NULL) ? \
ip6_2_ipX(ip6_select_source_address(netif, dest)) : NULL)
#define ip6_netif_get_local_ip(netif, dest) (((netif) != NULL) ? \
ip6_select_source_address(netif, dest) : NULL)
#if IP6_DEBUG
void ip6_debug_print(struct pbuf *p);

View File

@@ -72,19 +72,10 @@ PACK_STRUCT_END
# include "arch/epstruct.h"
#endif
/** ip6_addr_t uses a struct for convenience only, so that the same defines can
* operate both on ip6_addr_t as well as on ip6_addr_p_t. */
typedef struct ip6_addr ip6_addr_t;
typedef struct ip6_addr_packed ip6_addr_p_t;
/** IP6_ADDR_ANY can be used as a fixed IPv6 address
* for the wildcard
*/
extern const ip6_addr_t ip6_addr_any;
#define IP6_ADDR_ANY ((ip6_addr_t *)&ip6_addr_any)
#if BYTE_ORDER == BIG_ENDIAN
/** Set an IPv6 partial address given by byte-parts. */
#define IP6_ADDR(ip6addr, index, a,b,c,d) \

View File

@@ -42,86 +42,203 @@
extern "C" {
#endif
#if LWIP_IPV6
/* A union struct for both IP version's addresses. */
typedef union {
ip_addr_t ip4;
ip6_addr_t ip6;
} ipX_addr_t;
#if LWIP_IPV4 && LWIP_IPV6
/** A union struct for both IP version's addresses.
* ATTENTION: watch out for its size when adding IPv6 address scope!
*/
typedef struct _ip_addr {
union {
ip4_addr_t ip4;
ip6_addr_t ip6;
} addr;
u8_t type;
} ip_addr_t;
/** These functions only exist for type-safe conversion from ip_addr_t to
ip6_addr_t and back */
/** These are the values for ip_addr_t.type */
#define IPADDR_TYPE_V4 0U
#define IPADDR_TYPE_V6 6U
#define IP_IS_V6_L(ipaddr) ((ipaddr)->type == IPADDR_TYPE_V6)
#define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_L(ipaddr))
#define IP_SET_TYPE_L(ipaddr, iptype) do { (ipaddr)->type = (iptype); }while(0)
#define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_L(ipaddr, iptype); }}while(0)
#define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (PCB_ISIPV6(pcb) == IP_IS_V6_L(ipaddr))
/* Convert ipv4/ipv6 address to generic ip address.
Since source types do not contain the type field, a target storage need to be supplied. */
ip_addr_t* ip4_2_ip(const ip4_addr_t *ip4addr, ip_addr_t* storage);
ip_addr_t* ip6_2_ip(const ip6_addr_t *ip6addr, ip_addr_t* storage);
/* Convert generic ip address to specific protocol version (just a cast) */
#ifdef LWIP_ALLOW_STATIC_FN_IN_HEADER
static ip6_addr_t* ip_2_ip6(ip_addr_t *ipaddr)
{ return (ip6_addr_t*)ipaddr;}
static ip_addr_t* ip6_2_ip(ip6_addr_t *ip6addr)
{ return (ip_addr_t*)ip6addr; }
static ipX_addr_t* ip_2_ipX(ip_addr_t *ipaddr)
{ return (ipX_addr_t*)ipaddr; }
static ipX_addr_t* ip6_2_ipX(ip6_addr_t *ip6addr)
{ return (ipX_addr_t*)ip6addr; }
static ip6_addr_t* ip_2_ip6(const ip_addr_t *ipaddr)
{ if(ipaddr) { return (ip6_addr_t*)&((ipaddr)->addr.ip6); } return NULL; }
static ip4_addr_t* ip_2_ip4(const ip_addr_t *ipaddr)
{ if(ipaddr) { return (ip4_addr_t*)&((ipaddr)->addr.ip4); } return NULL; }
#else /* LWIP_ALLOW_STATIC_FN_IN_HEADER */
#define ip_2_ip6(ipaddr) ((ip6_addr_t*)(ipaddr))
#define ip6_2_ip(ip6addr) ((ip_addr_t*)(ip6addr))
#define ip_2_ipX(ipaddr) ((ipX_addr_t*)ipaddr)
#define ip6_2_ipX(ip6addr) ((ipX_addr_t*)ip6addr)
#endif /* LWIP_ALLOW_STATIC_FN_IN_HEADER*/
#define ipX_2_ip6(ip6addr) (&((ip6addr)->ip6))
#define ipX_2_ip(ipaddr) (&((ipaddr)->ip4))
#define ip_2_ip4(ipaddr) ((ip4_addr_t*)(ipaddr))
#endif /* LWIP_ALLOW_STATIC_FN_IN_HEADER */
#define ipX_addr_copy(is_ipv6, dest, src) do{if(is_ipv6){ \
ip6_addr_copy((dest).ip6, (src).ip6); }else{ \
ip_addr_copy((dest).ip4, (src).ip4); }}while(0)
#define ipX_addr_set(is_ipv6, dest, src) do{if(is_ipv6){ \
ip6_addr_set(ipX_2_ip6(dest), ipX_2_ip6(src)); }else{ \
ip_addr_set(ipX_2_ip(dest), ipX_2_ip(src)); }}while(0)
#define ipX_addr_set_ipaddr(is_ipv6, dest, src) do{if(is_ipv6){ \
ip6_addr_set(ipX_2_ip6(dest), ip_2_ip6(src)); }else{ \
ip_addr_set(ipX_2_ip(dest), src); }}while(0)
#define ipX_addr_set_zero(is_ipv6, ipaddr) do{if(is_ipv6){ \
ip6_addr_set_zero(ipX_2_ip6(ipaddr)); }else{ \
ip_addr_set_zero(ipX_2_ip(ipaddr)); }}while(0)
#define ipX_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
ip6_addr_set_any(ipX_2_ip6(ipaddr)); }else{ \
ip_addr_set_any(ipX_2_ip(ipaddr)); }}while(0)
#define ipX_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
ip6_addr_set_loopback(ipX_2_ip6(ipaddr)); }else{ \
ip_addr_set_loopback(ipX_2_ip(ipaddr)); }}while(0)
#define ipX_addr_set_hton(is_ipv6, dest, src) do{if(is_ipv6){ \
ip6_addr_set_hton(ipX_2_ip6(ipaddr), (src)) ;}else{ \
ip_addr_set_hton(ipX_2_ip(ipaddr), (src));}}while(0)
#define ipX_addr_cmp(is_ipv6, addr1, addr2) ((is_ipv6) ? \
ip6_addr_cmp(ipX_2_ip6(addr1), ipX_2_ip6(addr2)) : \
ip_addr_cmp(ipX_2_ip(addr1), ipX_2_ip(addr2)))
#define ipX_addr_isany(is_ipv6, ipaddr) ((is_ipv6) ? \
ip6_addr_isany(ipX_2_ip6(ipaddr)) : \
ip_addr_isany(ipX_2_ip(ipaddr)))
#define ipX_addr_ismulticast(is_ipv6, ipaddr) ((is_ipv6) ? \
ip6_addr_ismulticast(ipX_2_ip6(ipaddr)) : \
ip_addr_ismulticast(ipX_2_ip(ipaddr)))
#define ipX_addr_debug_print(is_ipv6, debug, ipaddr) do { if(is_ipv6) { \
ip6_addr_debug_print(debug, ipX_2_ip6(ipaddr)); } else { \
ip_addr_debug_print(debug, ipX_2_ip(ipaddr)); }}while(0)
#define ip_addr_copy(dest, src) do{if(IP_IS_V6_L(&(src))){ \
ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); IP_SET_TYPE_L(&(dest), IPADDR_TYPE_V6); }else{ \
ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); IP_SET_TYPE_L(&(dest), IPADDR_TYPE_V4); }}while(0)
#define ip_addr_copy_from_ip6(dest, src) do{ \
ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_L(&(dest), IPADDR_TYPE_V6); }while(0)
#define ip_addr_copy_from_ip4(dest, src) do{ \
ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_L(&(dest), IPADDR_TYPE_V4); }while(0)
#define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && !IP_IS_V6(ipaddr)) ? \
ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0)
#define ip_addr_set(dest, src) do{if(IP_IS_V6(src)){ \
ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_set_ipaddr(dest, src) do{if(IP_IS_V6(src)){ \
ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_set_zero(ipaddr) do{ \
ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
#define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \
ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \
ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \
ip4_addr_get_network(ip_2_ip4(target), ip_2_ip4(host), ip_2_ip4(netmask)); IP_SET_TYPE(target, IPADDR_TYPE_V4); }}while(0)
#define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
0 : \
ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
#define ip_addr_cmp(addr1, addr2) ((IP_IS_V6(addr1) != IP_IS_V6(addr2)) ? 0 : (IP_IS_V6(addr1) ? \
ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
#define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
ip6_addr_isany(ip_2_ip6(ipaddr)) : \
ip4_addr_isany(ip_2_ip4(ipaddr)))
#define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
0 : \
ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
#define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
#define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
ip4_addr_isloopback(ip_2_ip4(ipaddr)))
#define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \
ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \
ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0)
#define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
#define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr))), buf, buflen)
int ipaddr_aton(const char *cp, ip_addr_t *addr);
#else /* LWIP_IPV6 */
#else /* LWIP_IPV4 && LWIP_IPV6 */
typedef ip_addr_t ipX_addr_t;
#define ipX_2_ip(ipaddr) (ipaddr)
#define ip_2_ipX(ipaddr) (ipaddr)
#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
#define ipX_addr_copy(is_ipv6, dest, src) ip_addr_copy(dest, src)
#define ipX_addr_set(is_ipv6, dest, src) ip_addr_set(dest, src)
#define ipX_addr_set_ipaddr(is_ipv6, dest, src) ip_addr_set(dest, src)
#define ipX_addr_set_zero(is_ipv6, ipaddr) ip_addr_set_zero(ipaddr)
#define ipX_addr_set_any(is_ipv6, ipaddr) ip_addr_set_any(ipaddr)
#define ipX_addr_set_loopback(is_ipv6, ipaddr) ip_addr_set_loopback(ipaddr)
#define ipX_addr_set_hton(is_ipv6, dest, src) ip_addr_set_hton(dest, src)
#define ipX_addr_cmp(is_ipv6, addr1, addr2) ip_addr_cmp(addr1, addr2)
#define ipX_addr_isany(is_ipv6, ipaddr) ip_addr_isany(ipaddr)
#define ipX_addr_ismulticast(is_ipv6, ipaddr) ip_addr_ismulticast(ipaddr)
#define ipX_addr_debug_print(is_ipv6, debug, ipaddr) ip_addr_debug_print(debug, ipaddr)
#if LWIP_IPV4
#endif /* LWIP_IPV6 */
typedef ip4_addr_t ip_addr_t;
#define IP_IS_V6_L(ipaddr) 0
#define IP_IS_V6(ipaddr) 0
#define IP_SET_TYPE_L(ipaddr, iptype)
#define IP_SET_TYPE(ipaddr, iptype)
#define ip4_2_ip(ipaddr, unused) (ipaddr)
#define ip_2_ip4(ipaddr) (ipaddr)
#define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
#define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src)
#define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val)
#define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr))
#define ip_addr_set(dest, src) ip4_addr_set(dest, src)
#define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src)
#define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
#define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
#define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr)
#define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src)
#define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask)
#define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask)
#define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
#define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
#define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr)
#define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif)
#define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr)
#define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr)
#define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr)
#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen)
#define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
#else /* LWIP_IPV4 */
typedef ip6_addr_t ip_addr_t;
#define IP_IS_V6_L(ipaddr) 1
#define IP_IS_V6(ipaddr) 1
#define IP_SET_TYPE_L(ipaddr, iptype)
#define IP_SET_TYPE(ipaddr, iptype)
#define ip6_2_ip(ipaddr, unused) (ipaddr)
#define ip_2_ip6(ipaddr) (ipaddr)
#define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
#define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
#define ip_addr_set(dest, src) ip6_addr_set(dest, src)
#define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
#define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
#define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
#define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
#define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
#define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
#define ip_addr_netcmp(addr1, addr2, mask) 0
#define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
#define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
#define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
#define ip_addr_isbroadcast(addr, netif) 0
#define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
#define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
#define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
#define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_IPV4
extern const ip_addr_t ip_addr_any;
extern const ip_addr_t ip_addr_broadcast;
/** IP_ADDR_ can be used as a fixed/const ip_addr_t
* for the IPv4 wildcard and the broadcast address
*/
#define IP_ADDR_ANY (&ip_addr_any)
#define IP_ADDR_BROADCAST (&ip_addr_broadcast)
/** IP4_ADDR_ can be used as a fixed/const ip4_addr_t
* for the wildcard and the broadcast address
*/
#define IP4_ADDR_ANY (ip_2_ip4(&ip_addr_any))
#define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast))
#endif /* LWIP_IPV4*/
#if LWIP_IPV6
extern const ip_addr_t ip6_addr_any;
/** IP6_ADDR_ANY can be used as a fixed ip_addr_t
* for the IPv6 wildcard address
*/
#define IP6_ADDR_ANY ((ip_addr_t*)&ip6_addr_any)
/** IP6_ADDR_ANY6 can be used as a fixed ip6_addr_t
* for the IPv6 wildcard address
*/
#define IP6_ADDR_ANY6 ((ip6_addr_t*)ip_2_ip6(&ip6_addr_any))
#endif
#ifdef __cplusplus
}

View File

@@ -40,6 +40,8 @@
#include "lwip/ip_addr.h"
#include "lwip/ip.h"
#if LWIP_IPV4
#ifdef __cplusplus
extern "C" {
#endif
@@ -62,7 +64,7 @@ struct ip_reassdata {
void ip_reass_init(void);
void ip_reass_tmr(void);
struct pbuf * ip_reass(struct pbuf *p);
struct pbuf * ip4_reass(struct pbuf *p);
#endif /* IP_REASSEMBLY */
#if IP_FRAG
@@ -81,11 +83,13 @@ struct pbuf_custom_ref {
#endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */
#endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */
err_t ip_frag(struct pbuf *p, struct netif *netif, const ip_addr_t *dest);
err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest);
#endif /* IP_FRAG */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_IPV4 */
#endif /* LWIP_HDR_IP_FRAG_H */

View File

@@ -44,9 +44,9 @@ LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_lis
LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG")
#endif /* LWIP_TCP */
#if IP_REASSEMBLY
#if LWIP_IPV4 && IP_REASSEMBLY
LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA")
#endif /* IP_REASSEMBLY */
#endif /* LWIP_IPV4 && IP_REASSEMBLY */
#if (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)
LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF")
#endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */
@@ -75,9 +75,9 @@ LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg),
#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */
#endif /* NO_SYS==0 */
#if LWIP_ARP && ARP_QUEUEING
#if LWIP_IPV4 && LWIP_ARP && ARP_QUEUEING
LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_entry), "ARP_QUEUE")
#endif /* LWIP_ARP && ARP_QUEUEING */
#endif /* LWIP_IPV4 && LWIP_ARP && ARP_QUEUEING */
#if LWIP_IGMP
LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP")

View File

@@ -57,7 +57,7 @@ extern "C" {
struct netbuf {
struct pbuf *p, *ptr;
ipX_addr_t addr;
ip_addr_t addr;
u16_t port;
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY
@@ -65,7 +65,7 @@ struct netbuf {
#endif /* LWIP_CHECKSUM_ON_COPY */
u16_t toport_chksum;
#if LWIP_NETBUF_RECVINFO
ipX_addr_t toaddr;
ip_addr_t toaddr;
#endif /* LWIP_NETBUF_RECVINFO */
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
};
@@ -91,12 +91,12 @@ LWIP_NETCONN_SCOPE void netbuf_first (struct netbuf *buf);
#define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0)
#define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len)
#define netbuf_len(buf) ((buf)->p->tot_len)
#define netbuf_fromaddr(buf) (ipX_2_ip(&((buf)->addr)))
#define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(ipX_2_ip(&((buf)->addr)), fromaddr)
#define netbuf_fromaddr(buf) (&((buf)->addr))
#define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(&((buf)->addr), fromaddr)
#define netbuf_fromport(buf) ((buf)->port)
#if LWIP_NETBUF_RECVINFO
#define netbuf_destaddr(buf) (ipX_2_ip(&((buf)->toaddr)))
#define netbuf_set_destaddr(buf, destaddr) ip_addr_set(ipX_2_ip(&((buf)->toaddr)), destaddr)
#define netbuf_destaddr(buf) (&((buf)->toaddr))
#define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr)
#define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
#endif /* LWIP_NETBUF_RECVINFO */
#if LWIP_CHECKSUM_ON_COPY
@@ -104,16 +104,6 @@ LWIP_NETCONN_SCOPE void netbuf_first (struct netbuf *buf);
(buf)->toport_chksum = chksum; } while(0)
#endif /* LWIP_CHECKSUM_ON_COPY */
#if LWIP_IPV6
#define netbuf_fromaddr_ip6(buf) (ipX_2_ip6(&((buf)->addr)))
#define netbuf_set_fromaddr_ip6(buf, fromaddr) ip6_addr_set(ipX_2_ip6(&((buf)->addr)), fromaddr)
#define netbuf_destaddr_ip6(buf) (ipX_2_ip6(&((buf)->toaddr)))
#define netbuf_set_destaddr_ip6(buf, destaddr) ip6_addr_set(ipX_2_ip6(&((buf)->toaddr)), destaddr)
#endif /* LWIP_IPV6 */
#define netbuf_fromaddr_ipX(buf) (&((buf)->addr))
#define netbuf_destaddr_ipX(buf) (&((buf)->toaddr))
#ifdef __cplusplus
}
#endif

View File

@@ -101,6 +101,8 @@ extern "C" {
* IPv6 packets must be fragmented or reassembled. */
#define NETIF_FLAG_LOWPAN6 0x80U
struct netif;
/** Function prototype for netif init functions. Set up flags and output/linkoutput
* callback functions in this function.
*
@@ -114,6 +116,8 @@ typedef err_t (*netif_init_fn)(struct netif *netif);
* @param inp The netif which received the packet
*/
typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
#if LWIP_IPV4
/** Function prototype for netif->output functions. Called by lwIP when a packet
* shall be sent. For ethernet netif, set this to 'etharp_output' and set
* 'linkoutput'.
@@ -123,7 +127,9 @@ typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
* @param ipaddr The IP address to which the packet shall be sent
*/
typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
const ip_addr_t *ipaddr);
const ip4_addr_t *ipaddr);
#endif /* LWIP_IPV4*/
#if LWIP_IPV6
/** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet
* shall be sent. For ethernet netif, set this to 'ethip6_output' and set
@@ -136,6 +142,7 @@ typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
const ip6_addr_t *ipaddr);
#endif /* LWIP_IPV6 */
/** Function prototype for netif->linkoutput functions. Only used for ethernet
* netifs. This function is called by ARP when a packet shall be sent.
*
@@ -145,9 +152,11 @@ typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
/** Function prototype for netif status- or link-callback functions. */
typedef void (*netif_status_callback_fn)(struct netif *netif);
#if LWIP_IPV4 && LWIP_IGMP
/** Function prototype for netif igmp_mac_filter functions */
typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
const ip_addr_t *group, u8_t action);
const ip4_addr_t *group, u8_t action);
#endif /* LWIP_IPV4 && LWIP_IGMP */
#if LWIP_IPV6 && LWIP_IPV6_MLD
/** Function prototype for netif mld_mac_filter functions */
typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
@@ -161,11 +170,12 @@ struct netif {
/** pointer to next in linked list */
struct netif *next;
#if LWIP_IPV4
/** IP address configuration in network byte order */
ip_addr_t ip_addr;
ip_addr_t netmask;
ip_addr_t gw;
ip4_addr_t ip_addr;
ip4_addr_t netmask;
ip4_addr_t gw;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
/** Array of IPv6 addresses for this netif. */
ip6_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
@@ -176,10 +186,12 @@ struct netif {
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
netif_input_fn input;
#if LWIP_IPV4
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically
* first resolves the hardware address, then sends the packet. */
netif_output_fn output;
#endif /* LWIP_IPV4 */
/** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium. */
@@ -260,11 +272,11 @@ struct netif {
u32_t ifoutnucastpkts;
u32_t ifoutdiscards;
#endif /* LWIP_SNMP */
#if LWIP_IGMP
#if LWIP_IPV4 && LWIP_IGMP
/** This function could be called to add or delete an entry in the multicast
filter table of the ethernet MAC.*/
netif_igmp_mac_filter_fn igmp_mac_filter;
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 && LWIP_IGMP */
#if LWIP_IPV6 && LWIP_IPV6_MLD
/** This function could be called to add or delete an entry in the IPv6 multicast
filter table of the ethernet MAC. */
@@ -310,12 +322,18 @@ extern struct netif *netif_default;
void netif_init(void);
struct netif *netif_add(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask,
const ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input);
#if LWIP_IPV4
struct netif *
netif_add(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
const ip4_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input);
void
netif_set_addr(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask,
const ip_addr_t *gw);
netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
const ip4_addr_t *gw);
#else /* LWIP_IPV4 */
struct netif *
netif_add(struct netif *netif, const void *ipaddr, const void *netmask,
const void *gw, void *state, netif_init_fn init, netif_input_fn input);
#endif /* LWIP_IPV4 */
void netif_remove(struct netif * netif);
/* Returns a network interface given its name. The name is of the form
@@ -326,9 +344,11 @@ struct netif *netif_find(char *name);
void netif_set_default(struct netif *netif);
void netif_set_ipaddr(struct netif *netif, const ip_addr_t *ipaddr);
void netif_set_netmask(struct netif *netif, const ip_addr_t *netmask);
void netif_set_gw(struct netif *netif, const ip_addr_t *gw);
#if LWIP_IPV4
void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr);
void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask);
void netif_set_gw(struct netif *netif, const ip4_addr_t *gw);
#endif /* LWIP_IPV4 */
void netif_set_up(struct netif *netif);
void netif_set_down(struct netif *netif);

View File

@@ -42,9 +42,9 @@ extern "C" {
#endif
#if LWIP_MPU_COMPATIBLE
#define NETIFAPI_IPADDR_DEF(m) m
#define NETIFAPI_IPADDR_DEF(type, m) type m
#else /* LWIP_MPU_COMPATIBLE */
#define NETIFAPI_IPADDR_DEF(m) *m
#define NETIFAPI_IPADDR_DEF(type, m) const type * m
#endif /* LWIP_MPU_COMPATIBLE */
typedef void (*netifapi_void_fn)(struct netif *netif);
@@ -58,9 +58,9 @@ struct netifapi_msg_msg {
struct netif *netif;
union {
struct {
ip_addr_t NETIFAPI_IPADDR_DEF(ipaddr);
ip_addr_t NETIFAPI_IPADDR_DEF(netmask);
ip_addr_t NETIFAPI_IPADDR_DEF(gw);
NETIFAPI_IPADDR_DEF(ip4_addr_t, ipaddr);
NETIFAPI_IPADDR_DEF(ip4_addr_t, netmask);
NETIFAPI_IPADDR_DEF(ip4_addr_t, gw);
void *state;
netif_init_fn init;
netif_input_fn input;
@@ -80,17 +80,17 @@ struct netifapi_msg {
/* API for application */
err_t netifapi_netif_add ( struct netif *netif,
ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw,
const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
const ip4_addr_t *gw,
void *state,
netif_init_fn init,
netif_input_fn input);
err_t netifapi_netif_set_addr ( struct netif *netif,
ip_addr_t *ipaddr,
ip_addr_t *netmask,
ip_addr_t *gw );
const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
const ip4_addr_t *gw );
err_t netifapi_netif_common ( struct netif *netif,
netifapi_void_fn voidfunc,

View File

@@ -576,6 +576,13 @@
---------- IP options ----------
--------------------------------
*/
/**
* LWIP_IPV4==1: Enable IPv4
*/
#ifndef LWIP_IPV4
#define LWIP_IPV4 1
#endif
/**
* IP_FORWARD==1: Enables the ability to forward IP packets across network
* interfaces. If you are going to run lwIP on a device with only one network
@@ -585,15 +592,6 @@
#define IP_FORWARD 0
#endif
/**
* IP_OPTIONS_ALLOWED: Defines the behavior for IP options.
* IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped.
* IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed).
*/
#ifndef IP_OPTIONS_ALLOWED
#define IP_OPTIONS_ALLOWED 1
#endif
/**
* IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that
* this option does not affect outgoing packet sizes, which can be controlled
@@ -612,6 +610,25 @@
#define IP_FRAG 1
#endif
#if !LWIP_IPV4
/* disable IPv4 extensions when IPv4 is disabled */
#undef IP_FORWARD
#define IP_FORWARD 0
#undef IP_REASSEMBLY
#define IP_REASSEMBLY 0
#undef IP_FRAG
#define IP_FRAG 0
#endif /* !LWIP_IPV4 */
/**
* IP_OPTIONS_ALLOWED: Defines the behavior for IP options.
* IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped.
* IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed).
*/
#ifndef IP_OPTIONS_ALLOWED
#define IP_OPTIONS_ALLOWED 1
#endif
/**
* IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
* a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived
@@ -758,6 +775,11 @@
#ifndef LWIP_DHCP
#define LWIP_DHCP 0
#endif
#if !LWIP_IPV4
/* disable DHCP when IPv4 is disabled */
#undef LWIP_DHCP
#define LWIP_DHCP 0
#endif /* !LWIP_IPV4 */
/**
* DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address.
@@ -810,6 +832,11 @@
#ifndef LWIP_AUTOIP
#define LWIP_AUTOIP 0
#endif
#if !LWIP_IPV4
/* disable AUTOIP when IPv4 is disabled */
#undef LWIP_AUTOIP
#define LWIP_AUTOIP 0
#endif /* !LWIP_IPV4 */
/**
* LWIP_DHCP_AUTOIP_COOP==1: Allow DHCP and AUTOIP to be both enabled on
@@ -945,6 +972,10 @@
#ifndef LWIP_IGMP
#define LWIP_IGMP 0
#endif
#if !LWIP_IPV4
#undef LWIP_IGMP
#define LWIP_IGMP 0
#endif
/*
----------------------------------
@@ -1552,7 +1583,7 @@
* timers running in tcpip_thread from another thread.
*/
#ifndef LWIP_TCPIP_TIMEOUT
#define LWIP_TCPIP_TIMEOUT 1
#define LWIP_TCPIP_TIMEOUT 0
#endif
/** LWIP_NETCONN_SEM_PER_THREAD==1: Use one (thread-local) semaphore per
@@ -1946,7 +1977,7 @@
* PPP_IPV4_SUPPORT==1: Enable PPP IPv4 support
*/
#ifndef PPP_IPV4_SUPPORT
#define PPP_IPV4_SUPPORT 1
#define PPP_IPV4_SUPPORT (LWIP_IPV4)
#endif
/**

View File

@@ -79,7 +79,7 @@ struct pppapi_msg_msg {
struct {
struct netif *pppif;
struct netif *netif;
ip_addr_t *ipaddr;
ip4_addr_t *ipaddr;
u16_t port;
#if PPPOL2TP_AUTH_SUPPORT
u8_t *secret;
@@ -141,7 +141,7 @@ ppp_pcb *pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const cha
void *ctx_cb);
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, 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);
#if LWIP_IPV6

View File

@@ -61,27 +61,6 @@ struct raw_pcb;
typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr);
#if LWIP_IPV6
/** Function prototype for raw pcb IPv6 receive callback functions.
* @param arg user supplied argument (raw_pcb.recv_arg)
* @param pcb the raw_pcb which received data
* @param p the packet buffer that was received
* @param addr the remote IPv6 address from which the packet was received
* @return 1 if the packet was 'eaten' (aka. deleted),
* 0 if the packet lives on
* If returning 1, the callback is responsible for freeing the pbuf
* if it's not used any more.
*/
typedef u8_t (*raw_recv_ip6_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
ip6_addr_t *addr);
#endif /* LWIP_IPV6 */
#if LWIP_IPV6
#define RAW_PCB_RECV_IP6 raw_recv_ip6_fn ip6;
#else
#define RAW_PCB_RECV_IP6
#endif /* LWIP_IPV6 */
struct raw_pcb {
/* Common members of all PCB types */
IP_PCB;
@@ -91,10 +70,7 @@ struct raw_pcb {
u8_t protocol;
/** receive callback function */
union {
raw_recv_fn ip4;
RAW_PCB_RECV_IP6
} recv;
raw_recv_fn recv;
/* user-supplied argument for the recv callback */
void *recv_arg;
#if LWIP_IPV6
@@ -111,16 +87,13 @@ void raw_remove (struct raw_pcb *pcb);
err_t raw_bind (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
err_t raw_connect (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);
void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
#if LWIP_IPV6
struct raw_pcb * raw_new_ip6 (u8_t proto);
#define raw_bind_ip6(pcb, ip6addr) raw_bind(pcb, ip6_2_ip(ip6addr))
#define raw_connect_ip6(pcb, ip6addr) raw_connect(pcb, ip6_2_ip(ip6addr))
#define raw_recv_ip6(pcb, recv_ip6_fn, recv_arg) raw_recv(pcb, (raw_recv_fn)recv_ip6_fn, recv_arg)
#define raw_sendto_ip6(pcb, pbuf, ip6addr) raw_sendto(pcb, pbuf, ip6_2_ip(ip6addr))
struct raw_pcb * raw_new_ip6 (u8_t proto);
#endif /* LWIP_IPV6 */
/* The following functions are the lower layer interface to RAW. */

View File

@@ -129,9 +129,14 @@ void snmp_inc_ifoutdiscards(struct netif *ni);
void snmp_inc_iflist(void);
void snmp_dec_iflist(void);
#if LWIP_IPV4 && LWIP_ARP
/* ARP (for atTable and ipNetToMediaTable) */
void snmp_insert_arpidx_tree(struct netif *ni, ip_addr_t *ip);
void snmp_delete_arpidx_tree(struct netif *ni, ip_addr_t *ip);
void snmp_insert_arpidx_tree(struct netif *ni, ip4_addr_t *ip);
void snmp_delete_arpidx_tree(struct netif *ni, ip4_addr_t *ip);
#else /* LWIP_IPV4 && LWIP_ARP */
#define snmp_insert_arpidx_tree(ni,ip)
#define snmp_delete_arpidx_tree(ni,ip)
#endif /* LWIP_IPV4 && LWIP_ARP */
/* IP */
void snmp_inc_ipinreceives(void);

View File

@@ -268,6 +268,8 @@ struct snmp_msg_trap
const struct snmp_obj_id *enterprise;
/* source IP address, raw network order format */
u8_t sip_raw[4];
/* source IP address length */
u8_t sip_raw_len;
/* generic trap code */
u32_t gen_trap;
/* specific trap code */

View File

@@ -240,8 +240,8 @@ void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
void snmp_oidtoip(s32_t *ident, ip_addr_t *ip);
void snmp_iptooid(ip_addr_t *ip, s32_t *ident);
void snmp_oidtoip(s32_t *ident, ip4_addr_t *ip);
void snmp_iptooid(ip4_addr_t *ip, s32_t *ident);
void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);

View File

@@ -43,7 +43,6 @@
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/inet6.h"
#ifdef __cplusplus
extern "C" {

View File

@@ -313,9 +313,9 @@ struct tcp_pcb_listen {
u8_t backlog;
u8_t accepts_pending;
#endif /* TCP_LISTEN_BACKLOG */
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
u8_t accept_any_ip_version;
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
};
#if LWIP_EVENT_API
@@ -396,16 +396,14 @@ const char* tcp_debug_state_str(enum tcp_state s);
#if LWIP_IPV6
struct tcp_pcb * tcp_new_ip6 (void);
#define tcp_bind_ip6(pcb, ip6addr, port) \
tcp_bind(pcb, ip6_2_ip(ip6addr), port)
#define tcp_connect_ip6(pcb, ip6addr, port, connected) \
tcp_connect(pcb, ip6_2_ip(ip6addr), port, connected)
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
struct tcp_pcb * tcp_listen_dual_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
#define tcp_listen_dual(pcb) tcp_listen_dual_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
#else /* LWIP_IPV6 */
#else /* LWIP_IPV4 && LWIP_IPV6 */
#define tcp_listen_dual_with_backlog(pcb, backlog) tcp_listen_with_backlog(pcb, backlog)
#define tcp_listen_dual(pcb) tcp_listen(pcb)
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#ifdef __cplusplus

View File

@@ -478,20 +478,9 @@ err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags);
void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
void tcp_rst_impl(u32_t seqno, u32_t ackno,
ipX_addr_t *local_ip, ipX_addr_t *remote_ip,
u16_t local_port, u16_t remote_port
#if LWIP_IPV6
, u8_t isipv6
#endif /* LWIP_IPV6 */
);
#if LWIP_IPV6
#define tcp_rst(seqno, ackno, local_ip, remote_ip, local_port, remote_port, isipv6) \
tcp_rst_impl(seqno, ackno, local_ip, remote_ip, local_port, remote_port, isipv6)
#else /* LWIP_IPV6 */
#define tcp_rst(seqno, ackno, local_ip, remote_ip, local_port, remote_port, isipv6) \
tcp_rst_impl(seqno, ackno, local_ip, remote_ip, local_port, remote_port)
#endif /* LWIP_IPV6 */
void tcp_rst(u32_t seqno, u32_t ackno,
const ip_addr_t *local_ip, const ip_addr_t *remote_ip,
u16_t local_port, u16_t remote_port);
u32_t tcp_next_iss(void);
@@ -500,16 +489,21 @@ err_t tcp_zero_window_probe(struct tcp_pcb *pcb);
void tcp_trigger_input_pcb_close(void);
#if TCP_CALCULATE_EFF_SEND_MSS
u16_t tcp_eff_send_mss_impl(u16_t sendmss, ipX_addr_t *dest
u16_t tcp_eff_send_mss_impl(u16_t sendmss, const ip_addr_t *dest
#if LWIP_IPV6
, ipX_addr_t *src, u8_t isipv6
, const ip_addr_t *src
#if LWIP_IPV4
, u8_t isipv6
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
);
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
#define tcp_eff_send_mss(sendmss, src, dest, isipv6) tcp_eff_send_mss_impl(sendmss, dest, src, isipv6)
#else /* LWIP_IPV6 */
#elif LWIP_IPV6
#define tcp_eff_send_mss(sendmss, src, dest, isipv6) tcp_eff_send_mss_impl(sendmss, dest, src)
#else /* LWIP_IPV4 && LWIP_IPV6 */
#define tcp_eff_send_mss(sendmss, src, dest, isipv6) tcp_eff_send_mss_impl(sendmss, dest)
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
#if LWIP_CALLBACK_API
@@ -534,7 +528,9 @@ s16_t tcp_pcbs_sane(void);
* that a timer is needed (i.e. active- or time-wait-pcb found). */
void tcp_timer_needed(void);
void tcp_netif_ipv4_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr);
#if LWIP_IPV4
void tcp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr);
#endif /* LWIP_IPV4 */
#ifdef __cplusplus
}

View File

@@ -76,8 +76,8 @@ struct udp_pcb;
* The callback is responsible for freeing the pbuf
* if it's not used any more.
*
* ATTENTION: Be aware that 'addr' points into the pbuf 'p' so freeing this pbuf
* makes 'addr' invalid, too.
* ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf
* can make 'addr' invalid, too.
*
* @param arg user supplied argument (udp_pcb.recv_arg)
* @param pcb the udp_pcb which received data
@@ -88,27 +88,6 @@ struct udp_pcb;
typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);
#if LWIP_IPV6
/** Function prototype for udp pcb IPv6 receive callback functions
* The callback is responsible for freeing the pbuf
* if it's not used any more.
*
* @param arg user supplied argument (udp_pcb.recv_arg)
* @param pcb the udp_pcb which received data
* @param p the packet buffer that was received
* @param addr the remote IPv6 address from which the packet was received
* @param port the remote port from which the packet was received
*/
typedef void (*udp_recv_ip6_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
ip6_addr_t *addr, u16_t port);
#endif /* LWIP_IPV6 */
#if LWIP_IPV6
#define UDP_PCB_RECV_IP6 udp_recv_ip6_fn ip6;
#else
#define UDP_PCB_RECV_IP6
#endif /* LWIP_IPV6 */
struct udp_pcb {
/* Common members of all PCB types */
IP_PCB;
@@ -123,7 +102,7 @@ struct udp_pcb {
#if LWIP_IGMP
/** outgoing network interface for multicast packets */
ip_addr_t multicast_ip;
ip4_addr_t multicast_ip;
/** TTL for outgoing multicast packets */
u8_t mcast_ttl;
#endif /* LWIP_IGMP */
@@ -134,12 +113,9 @@ struct udp_pcb {
#endif /* LWIP_UDPLITE */
/** receive callback function */
union {
udp_recv_fn ip4;
UDP_PCB_RECV_IP6
}recv;
udp_recv_fn recv;
/** user-supplied argument for the recv callback */
void *recv_arg;
void *recv_arg;
};
/* udp_pcbs export for external reference (e.g. SNMP agent) */
extern struct udp_pcb *udp_pcbs;
@@ -190,22 +166,6 @@ void udp_init (void);
#if LWIP_IPV6
struct udp_pcb * udp_new_ip6(void);
#define udp_bind_ip6(pcb, ip6addr, port) \
udp_bind(pcb, ip6_2_ip(ip6addr), port)
#define udp_connect_ip6(pcb, ip6addr, port) \
udp_connect(pcb, ip6_2_ip(ip6addr), port)
#define udp_recv_ip6(pcb, recv_ip6_fn, recv_arg) \
udp_recv(pcb, (udp_recv_fn)recv_ip6_fn, recv_arg)
#define udp_sendto_ip6(pcb, pbuf, ip6addr, port) \
udp_sendto(pcb, pbuf, ip6_2_ip(ip6addr), port)
#define udp_sendto_if_ip6(pcb, pbuf, ip6addr, port, netif) \
udp_sendto_if(pcb, pbuf, ip6_2_ip(ip6addr), port, netif)
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
#define udp_sendto_chksum_ip6(pcb, pbuf, ip6addr, port, have_chk, chksum) \
udp_sendto_chksum(pcb, pbuf, ip6_2_ip(ip6addr), port, have_chk, chksum)
#define udp_sendto_if_chksum_ip6(pcb, pbuf, ip6addr, port, netif, have_chk, chksum) \
udp_sendto_if_chksum(pcb, pbuf, ip6_2_ip(ip6addr), port, netif, have_chk, chksum)
#endif /*LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
#endif /* LWIP_IPV6 */
#if LWIP_IGMP
@@ -221,7 +181,9 @@ void udp_debug_print(struct udp_hdr *udphdr);
#define udp_debug_print(udphdr)
#endif
void udp_netif_ipv4_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr);
#if LWIP_IPV4
void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr);
#endif /* LWIP_IPV4 */
#ifdef __cplusplus
}

View File

@@ -107,6 +107,24 @@ PACK_STRUCT_END
#endif /* ETHARP_SUPPORT_VLAN */
/* A list of often ethtypes (although lwIP does not use all of them): */
#define ETHTYPE_IP 0x0800U /* Internet protocol v4 */
#define ETHTYPE_ARP 0x0806U /* Address resolution protocol */
#define ETHTYPE_WOL 0x0842U /* Wake on lan */
#define ETHTYPE_VLAN 0x8100U /* Virtual local area network */
#define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */
#define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */
#define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */
#define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */
#define ETHTYPE_PROFINET 0x8892U /* Process field network */
#define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */
#define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */
#define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */
#define ETHTYPE_PTP 0x88F7U /* Precision time protocol */
#define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */
#if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
@@ -119,9 +137,9 @@ struct etharp_hdr {
PACK_STRUCT_FLD_8(u8_t protolen);
PACK_STRUCT_FIELD(u16_t opcode);
PACK_STRUCT_FLD_S(struct eth_addr shwaddr);
PACK_STRUCT_FLD_S(struct ip_addr2 sipaddr);
PACK_STRUCT_FLD_S(struct ip4_addr2 sipaddr);
PACK_STRUCT_FLD_S(struct eth_addr dhwaddr);
PACK_STRUCT_FLD_S(struct ip_addr2 dipaddr);
PACK_STRUCT_FLD_S(struct ip4_addr2 dipaddr);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
@@ -140,22 +158,6 @@ PACK_STRUCT_END
/** 1 seconds period */
#define ARP_TMR_INTERVAL 1000
/* A list of often ethtypes (although lwIP does not use all of them): */
#define ETHTYPE_IP 0x0800U /* Internet protocol v4 */
#define ETHTYPE_ARP 0x0806U /* Address resolution protocol */
#define ETHTYPE_WOL 0x0842U /* Wake on lan */
#define ETHTYPE_VLAN 0x8100U /* Virtual local area network */
#define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */
#define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */
#define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */
#define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */
#define ETHTYPE_PROFINET 0x8892U /* Process field network */
#define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */
#define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */
#define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */
#define ETHTYPE_PTP 0x88F7U /* Precision time protocol */
#define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */
/** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
* or known to be 32-bit aligned within the protocol header. */
#ifndef ETHADDR32_COPY
@@ -168,8 +170,6 @@ PACK_STRUCT_END
#define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETHARP_HWADDR_LEN)
#endif
#if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
/** ARP message types (opcodes) */
#define ARP_REQUEST 1
#define ARP_REPLY 2
@@ -196,11 +196,11 @@ struct etharp_q_entry {
#define etharp_init() /* Compatibility define, no init needed. */
void etharp_tmr(void);
s8_t etharp_find_addr(struct netif *netif, const ip_addr_t *ipaddr,
struct eth_addr **eth_ret, const ip_addr_t **ip_ret);
err_t 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);
err_t etharp_request(struct netif *netif, const ip_addr_t *ipaddr);
s8_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr,
struct eth_addr **eth_ret, const ip4_addr_t **ip_ret);
err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr);
err_t etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q);
err_t etharp_request(struct netif *netif, const ip4_addr_t *ipaddr);
/** For Ethernet network interfaces, we might want to send "gratuitous ARP";
* this is an ARP packet sent by a node in order to spontaneously cause other
* nodes to update an entry in their ARP cache.
@@ -209,19 +209,19 @@ err_t etharp_request(struct netif *netif, const ip_addr_t *ipaddr);
void etharp_cleanup_netif(struct netif *netif);
#if ETHARP_SUPPORT_STATIC_ENTRIES
err_t etharp_add_static_entry(const ip_addr_t *ipaddr, struct eth_addr *ethaddr);
err_t etharp_remove_static_entry(const ip_addr_t *ipaddr);
err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr);
err_t etharp_remove_static_entry(const ip4_addr_t *ipaddr);
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
#if LWIP_AUTOIP
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);
#endif /* LWIP_AUTOIP */
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 && LWIP_ARP */
err_t ethernet_input(struct pbuf *p, struct netif *netif);

View File

@@ -299,9 +299,9 @@ typedef struct ppp_settings_s {
#if PPP_SERVER
struct ppp_addrs {
#if PPP_IPV4_SUPPORT
ip_addr_t our_ipaddr, his_ipaddr, netmask;
ip4_addr_t our_ipaddr, his_ipaddr, netmask;
#if LWIP_DNS
ip_addr_t dns1, dns2;
ip4_addr_t dns1, dns2;
#endif /* LWIP_DNS */
#endif /* PPP_IPV4_SUPPORT */
#if PPP_IPV6_SUPPORT

View File

@@ -166,7 +166,7 @@ struct pppol2tp_pcb_s {
u8_t phase; /* L2TP phase */
struct udp_pcb *udp; /* UDP L2TP Socket */
struct netif *netif; /* Output interface, used as a default route */
ipX_addr_t remote_ip; /* LNS IP Address */
ip_addr_t remote_ip; /* LNS IP Address */
u16_t remote_port; /* LNS port */
#if PPPOL2TP_AUTH_SUPPORT
u8_t *secret; /* Secret string */
@@ -193,7 +193,7 @@ struct pppol2tp_pcb_s {
/* Create a new L2TP session over IPv4. */
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);