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

@ -6,6 +6,12 @@ HISTORY
++ New features:
* nearly all files: 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
* opt.h, ip4_addr.h, ip4.c, ip6.c: loopif is not required for loopback traffic
any more but passed through any netif (ENABLE_LOOPBACK has to be enabled)

View File

@ -172,10 +172,10 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
API_MSG_VAR_REF(msg).msg.msg.ad.local = local;
#if LWIP_MPU_COMPATIBLE
TCPIP_APIMSG(msg, lwip_netconn_do_getaddr, err);
*addr = *ipX_2_ip(&(msg->msg.msg.ad.ipaddr));
*addr = msg->msg.msg.ad.ipaddr;
*port = msg->msg.msg.ad.port;
#else /* LWIP_MPU_COMPATIBLE */
msg.msg.msg.ad.ipaddr = ip_2_ipX(addr);
msg.msg.msg.ad.ipaddr = addr;
msg.msg.msg.ad.port = port;
TCPIP_APIMSG(&msg, lwip_netconn_do_getaddr, err);
#endif /* LWIP_MPU_COMPATIBLE */
@ -542,7 +542,7 @@ netconn_recv(struct netconn *conn, struct netbuf **new_buf)
buf->p = p;
buf->ptr = p;
buf->port = 0;
ipX_addr_set_any(LWIP_IPV6, &buf->addr);
ip_addr_set_zero(&buf->addr);
*new_buf = buf;
/* don't set conn->last_err: it's only ERR_OK, anyway */
return ERR_OK;
@ -605,7 +605,7 @@ err_t
netconn_sendto(struct netconn *conn, struct netbuf *buf, const ip_addr_t *addr, u16_t port)
{
if (buf != NULL) {
ipX_addr_set_ipaddr(PCB_ISIPV6(conn->pcb.ip), &buf->addr, addr);
ip_addr_set(&buf->addr, addr);
buf->port = port;
return netconn_send(conn, buf);
}
@ -798,8 +798,8 @@ netconn_join_leave_group(struct netconn *conn,
}
#endif /* LWIP_MPU_COMPATIBLE */
API_MSG_VAR_REF(msg).msg.conn = conn;
API_MSG_VAR_REF(msg).msg.msg.jl.multiaddr = API_MSG_VAR_REF(ip_2_ipX(multiaddr));
API_MSG_VAR_REF(msg).msg.msg.jl.netif_addr = API_MSG_VAR_REF(ip_2_ipX(netif_addr));
API_MSG_VAR_REF(msg).msg.msg.jl.multiaddr = API_MSG_VAR_REF(multiaddr);
API_MSG_VAR_REF(msg).msg.msg.jl.netif_addr = API_MSG_VAR_REF(netif_addr);
API_MSG_VAR_REF(msg).msg.msg.jl.join_or_leave = join_or_leave;
TCPIP_APIMSG(&API_MSG_VAR_REF(msg), lwip_netconn_do_join_leave_group, err);
API_MSG_VAR_FREE(msg);

View File

@ -123,7 +123,7 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
buf->p = q;
buf->ptr = q;
ipX_addr_copy(PCB_ISIPV6(pcb), buf->addr, *ipX_current_src_addr());
ip_addr_copy(buf->addr, *ip_current_src_addr());
buf->port = pcb->protocol;
len = q->tot_len;
@ -186,16 +186,16 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
} else {
buf->p = p;
buf->ptr = p;
ipX_addr_set_ipaddr(ip_current_is_v6(), &buf->addr, addr);
ip_addr_set(&buf->addr, addr);
buf->port = port;
#if LWIP_NETBUF_RECVINFO
{
/* get the UDP header - always in the first pbuf, ensured by udp_input */
const struct udp_hdr* udphdr = ipX_next_header_ptr();
const struct udp_hdr* udphdr = (const struct udp_hdr*)ip_next_header_ptr();
#if LWIP_CHECKSUM_ON_COPY
buf->flags = NETBUF_FLAG_DESTADDR;
#endif /* LWIP_CHECKSUM_ON_COPY */
ipX_addr_set(ip_current_is_v6(), &buf->toaddr, ipX_current_dest_addr());
ip_addr_set(&buf->toaddr, ip_current_dest_addr());
buf->toport_chksum = udphdr->dest;
}
#endif /* LWIP_NETBUF_RECVINFO */
@ -1337,29 +1337,29 @@ lwip_netconn_do_send(struct api_msg_msg *msg)
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
if (ipX_addr_isany(PCB_ISIPV6(msg->conn->pcb.ip), &msg->msg.b->addr)) {
if (ip_addr_isany(&msg->msg.b->addr)) {
msg->err = raw_send(msg->conn->pcb.raw, msg->msg.b->p);
} else {
msg->err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, ipX_2_ip(&msg->msg.b->addr));
msg->err = raw_sendto(msg->conn->pcb.raw, msg->msg.b->p, &msg->msg.b->addr);
}
break;
#endif
#if LWIP_UDP
case NETCONN_UDP:
#if LWIP_CHECKSUM_ON_COPY
if (ipX_addr_isany(PCB_ISIPV6(msg->conn->pcb.ip), &msg->msg.b->addr)) {
if (ip_addr_isany(&msg->msg.b->addr)) {
msg->err = udp_send_chksum(msg->conn->pcb.udp, msg->msg.b->p,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
} else {
msg->err = udp_sendto_chksum(msg->conn->pcb.udp, msg->msg.b->p,
ipX_2_ip(&msg->msg.b->addr), msg->msg.b->port,
&msg->msg.b->addr, msg->msg.b->port,
msg->msg.b->flags & NETBUF_FLAG_CHKSUM, msg->msg.b->toport_chksum);
}
#else /* LWIP_CHECKSUM_ON_COPY */
if (ipX_addr_isany(PCB_ISIPV6(msg->conn->pcb.ip), &msg->msg.b->addr)) {
if (ip_addr_isany(&msg->msg.b->addr)) {
msg->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
} else {
msg->err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, ipX_2_ip(&msg->msg.b->addr), msg->msg.b->port);
msg->err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, &msg->msg.b->addr, msg->msg.b->port);
}
#endif /* LWIP_CHECKSUM_ON_COPY */
break;
@ -1624,10 +1624,10 @@ lwip_netconn_do_getaddr(struct api_msg_msg *msg)
{
if (msg->conn->pcb.ip != NULL) {
if (msg->msg.ad.local) {
ipX_addr_copy(PCB_ISIPV6(msg->conn->pcb.ip), API_EXPR_DEREF(msg->msg.ad.ipaddr),
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
msg->conn->pcb.ip->local_ip);
} else {
ipX_addr_copy(PCB_ISIPV6(msg->conn->pcb.ip), API_EXPR_DEREF(msg->msg.ad.ipaddr),
ip_addr_copy(API_EXPR_DEREF(msg->msg.ad.ipaddr),
msg->conn->pcb.ip->remote_ip);
}
msg->err = ERR_OK;
@ -1770,11 +1770,11 @@ lwip_netconn_do_join_leave_group(struct api_msg_msg *msg)
#if LWIP_IPV6 && LWIP_IPV6_MLD
if (PCB_ISIPV6(msg->conn->pcb.udp)) {
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = mld6_joingroup(ipX_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ipX_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
msg->err = mld6_joingroup(ip_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = mld6_leavegroup(ipX_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ipX_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
msg->err = mld6_leavegroup(ip_2_ip6(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip6(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
}
else
@ -1782,11 +1782,11 @@ lwip_netconn_do_join_leave_group(struct api_msg_msg *msg)
{
#if LWIP_IGMP
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->err = igmp_joingroup(ipX_2_ip(API_EXPR_REF(msg->msg.jl.netif_addr)),
ipX_2_ip(API_EXPR_REF(msg->msg.jl.multiaddr)));
msg->err = igmp_joingroup(ip_2_ip4(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
} else {
msg->err = igmp_leavegroup(ipX_2_ip(API_EXPR_REF(msg->msg.jl.netif_addr)),
ipX_2_ip(API_EXPR_REF(msg->msg.jl.multiaddr)));
msg->err = igmp_leavegroup(ip_2_ip4(API_EXPR_REF(msg->msg.jl.netif_addr)),
ip_2_ip4(API_EXPR_REF(msg->msg.jl.multiaddr)));
}
#endif /* LWIP_IGMP */
}

View File

@ -61,7 +61,7 @@ netbuf *netbuf_new(void)
if (buf != NULL) {
buf->p = NULL;
buf->ptr = NULL;
ipX_addr_set_any(LWIP_IPV6, &buf->addr);
ip_addr_set_zero(&buf->addr);
buf->port = 0;
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY
@ -69,7 +69,7 @@ netbuf *netbuf_new(void)
#endif /* LWIP_CHECKSUM_ON_COPY */
buf->toport_chksum = 0;
#if LWIP_NETBUF_RECVINFO
ipX_addr_set_any(LWIP_IPV6, &buf->toaddr);
ip_addr_set_zero(&buf->toaddr);
#endif /* LWIP_NETBUF_RECVINFO */
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
return buf;

View File

@ -122,9 +122,9 @@ lwip_gethostbyname(const char *name)
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list == %p\n", s_hostent.h_addr_list));
if (s_hostent.h_addr_list != NULL) {
u8_t idx;
for ( idx=0; s_hostent.h_addr_list[idx]; idx++) {
for (idx=0; s_hostent.h_addr_list[idx]; idx++) {
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t*)s_hostent.h_addr_list[idx])));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip4_addr_t*)s_hostent.h_addr_list[idx])));
}
}
#endif /* DNS_DEBUG */
@ -301,7 +301,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
}
} else {
/* service location specified, use loopback address */
ip_addr_set_loopback(&addr);
ip_addr_set_loopback(0, &addr);
}
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_in);
@ -320,7 +320,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
memset(ai, 0, total_size);
sa = (struct sockaddr_in*)((u8_t*)ai + sizeof(struct addrinfo));
/* set up sockaddr */
inet_addr_from_ipaddr(&sa->sin_addr, &addr);
inet_addr_from_ipaddr(&sa->sin_addr, ip_2_ip4(&addr));
sa->sin_family = AF_INET;
sa->sin_len = sizeof(struct sockaddr_in);
sa->sin_port = htons((u16_t)port_nr);

View File

@ -102,9 +102,9 @@ netifapi_do_netif_common(struct netifapi_msg_msg *msg)
*/
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)
@ -114,13 +114,13 @@ netifapi_netif_add(struct netif *netif,
NETIFAPI_VAR_ALLOC(msg);
#if LWIP_MPU_COMPATIBLE
if (ipaddr == NULL) {
ipaddr = IP_ADDR_ANY;
ipaddr = IP4_ADDR_ANY;
}
if (netmask == NULL) {
netmask = IP_ADDR_ANY;
netmask = IP4_ADDR_ANY;
}
if (gw == NULL) {
gw = IP_ADDR_ANY;
gw = IP4_ADDR_ANY;
}
#endif /* LWIP_MPU_COMPATIBLE */
NETIFAPI_VAR_REF(msg).function = netifapi_do_netif_add;
@ -146,22 +146,22 @@ netifapi_netif_add(struct netif *netif,
*/
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 err;
NETIFAPI_VAR_DECLARE(msg);
NETIFAPI_VAR_ALLOC(msg);
#if LWIP_MPU_COMPATIBLE
if (ipaddr == NULL) {
ipaddr = IP_ADDR_ANY;
ipaddr = IP4_ADDR_ANY;
}
if (netmask == NULL) {
netmask = IP_ADDR_ANY;
netmask = IP4_ADDR_ANY;
}
if (gw == NULL) {
gw = IP_ADDR_ANY;
gw = IP4_ADDR_ANY;
}
#endif /* LWIP_MPU_COMPATIBLE */
NETIFAPI_VAR_REF(msg).function = netifapi_do_netif_set_addr;

View File

@ -213,7 +213,7 @@ pppapi_do_pppol2tp_create(struct pppapi_msg_msg *msg)
* tcpip_thread context.
*/
ppp_pcb*
pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
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)
{

View File

@ -71,14 +71,14 @@
#define LWIP_NETCONN 0
#endif
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipXaddr, port) do { \
#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \
(sin)->sin_len = sizeof(struct sockaddr_in); \
(sin)->sin_family = AF_INET; \
(sin)->sin_port = htons((port)); \
inet_addr_from_ipaddr(&(sin)->sin_addr, ipX_2_ip(ipXaddr)); \
inet_addr_from_ipaddr(&(sin)->sin_addr, ipaddr); \
memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0)
#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipXaddr, port) do { \
inet_addr_to_ipaddr(ipX_2_ip(ipXaddr), &((sin)->sin_addr)); \
#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \
inet_addr_to_ipaddr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \
(port) = ntohs((sin)->sin_port); }while(0)
#if LWIP_IPV6
@ -89,26 +89,26 @@
#define SOCK_ADDR_TYPE_MATCH(name, sock) \
((((name)->sa_family == AF_INET) && !(NETCONNTYPE_ISIPV6((sock)->conn->type))) || \
(((name)->sa_family == AF_INET6) && (NETCONNTYPE_ISIPV6((sock)->conn->type))))
#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipXaddr, port) do { \
#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \
(sin6)->sin6_len = sizeof(struct sockaddr_in6); \
(sin6)->sin6_family = AF_INET6; \
(sin6)->sin6_port = htons((port)); \
(sin6)->sin6_flowinfo = 0; \
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipX_2_ip6(ipXaddr)); }while(0)
#define IPXADDR_PORT_TO_SOCKADDR(isipv6, sockaddr, ipXaddr, port) do { \
if (isipv6) { \
IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ipXaddr, port); \
inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); }while(0)
#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) do { \
if (IP_IS_V6(ipaddr)) { \
IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ip_2_ip6(ipaddr), port); \
} else { \
IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port); \
IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port); \
} } while(0)
#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipXaddr, port) do { \
inet6_addr_to_ip6addr(ipX_2_ip6(ipXaddr), &((sin6)->sin6_addr)); \
#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \
inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \
(port) = ntohs((sin6)->sin6_port); }while(0)
#define SOCKADDR_TO_IPXADDR_PORT(isipv6, sockaddr, ipXaddr, port) do { \
if (isipv6) { \
SOCKADDR6_TO_IP6ADDR_PORT((struct sockaddr_in6*)(void*)(sockaddr), ipXaddr, port); \
#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) do { \
if (((sockaddr)->sa_family) == AF_INET6) { \
SOCKADDR6_TO_IP6ADDR_PORT((struct sockaddr_in6*)(void*)(sockaddr), ipaddr, port); \
} else { \
SOCKADDR4_TO_IP4ADDR_PORT((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port); \
SOCKADDR4_TO_IP4ADDR_PORT((struct sockaddr_in*)(void*)(sockaddr), ipaddr, port); \
} } while(0)
#define DOMAIN_TO_NETCONN_TYPE(domain, type) (((domain) == AF_INET) ? \
(type) : (enum netconn_type)((type) | NETCONN_TYPE_IPV6))
@ -116,10 +116,10 @@
#define IS_SOCK_ADDR_LEN_VALID(namelen) ((namelen) == sizeof(struct sockaddr_in))
#define IS_SOCK_ADDR_TYPE_VALID(name) ((name)->sa_family == AF_INET)
#define SOCK_ADDR_TYPE_MATCH(name, sock) 1
#define IPXADDR_PORT_TO_SOCKADDR(isipv6, sockaddr, ipXaddr, port) \
IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port)
#define SOCKADDR_TO_IPXADDR_PORT(isipv6, sockaddr, ipXaddr, port) \
SOCKADDR4_TO_IP4ADDR_PORT((struct sockaddr_in*)(void*)(sockaddr), ipXaddr, port)
#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \
IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port)
#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \
SOCKADDR4_TO_IP4ADDR_PORT((struct sockaddr_in*)(void*)(sockaddr), ipaddr, port)
#define DOMAIN_TO_NETCONN_TYPE(domain, netconn_type) (netconn_type)
#endif /* LWIP_IPV6 */
@ -249,15 +249,15 @@ struct lwip_socket_multicast_pair {
/** the socket (+1 to not require initialization) */
int sa;
/** the interface address */
ip_addr_t if_addr;
ip4_addr_t if_addr;
/** the group address */
ip_addr_t multi_addr;
ip4_addr_t multi_addr;
};
struct lwip_socket_multicast_pair socket_ipv4_multicast_memberships[LWIP_SOCKET_MAX_MEMBERSHIPS];
static int lwip_socket_register_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr);
static void lwip_socket_unregister_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr);
static int lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr);
static void lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr);
static void lwip_socket_drop_registered_memberships(int s);
#endif /* LWIP_IGMP */
@ -451,7 +451,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
struct lwip_sock *sock, *nsock;
struct netconn *newconn;
ipX_addr_t naddr;
ip_addr_t naddr;
u16_t port = 0;
int newsock;
err_t err;
@ -490,7 +490,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
if (addr != NULL) {
union sockaddr_aligned tempaddr;
/* get the IP address and port of the remote host */
err = netconn_peer(newconn, ipX_2_ip(&naddr), &port);
err = netconn_peer(newconn, &naddr, &port);
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
netconn_delete(newconn);
@ -499,7 +499,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
}
LWIP_ASSERT("addr valid but addrlen NULL", addrlen != NULL);
IPXADDR_PORT_TO_SOCKADDR(NETCONNTYPE_ISIPV6(newconn->type), &tempaddr, &naddr, port);
IPADDR_PORT_TO_SOCKADDR(&tempaddr, &naddr, port);
if (*addrlen > tempaddr.sa.sa_len) {
*addrlen = tempaddr.sa.sa_len;
}
@ -529,7 +529,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d", s, newsock));
if (addr != NULL) {
LWIP_DEBUGF(SOCKETS_DEBUG, (" addr="));
ipX_addr_debug_print(NETCONNTYPE_ISIPV6(newconn->type), SOCKETS_DEBUG, &naddr);
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", port));
}
@ -541,7 +541,7 @@ int
lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
{
struct lwip_sock *sock;
ipX_addr_t local_addr;
ip_addr_t local_addr;
u16_t local_port;
err_t err;
@ -562,12 +562,12 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
LWIP_UNUSED_ARG(namelen);
SOCKADDR_TO_IPXADDR_PORT((name->sa_family == AF_INET6), name, &local_addr, local_port);
SOCKADDR_TO_IPADDR_PORT(name, &local_addr, local_port);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
ipX_addr_debug_print(name->sa_family == AF_INET6, SOCKETS_DEBUG, &local_addr);
ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", local_port));
err = netconn_bind(sock->conn, ipX_2_ip(&local_addr), local_port);
err = netconn_bind(sock->conn, &local_addr, local_port);
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err));
@ -638,7 +638,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
err = netconn_disconnect(sock->conn);
} else {
ipX_addr_t remote_addr;
ip_addr_t remote_addr;
u16_t remote_port;
/* check size, family and alignment of 'name' */
@ -646,12 +646,12 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC(name) && IS_SOCK_ADDR_ALIGNED(name),
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
SOCKADDR_TO_IPXADDR_PORT((name->sa_family == AF_INET6), name, &remote_addr, remote_port);
SOCKADDR_TO_IPADDR_PORT(name, &remote_addr, remote_port);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
ipX_addr_debug_print(name->sa_family == AF_INET6, SOCKETS_DEBUG, &remote_addr);
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", remote_port));
err = netconn_connect(sock->conn, ipX_2_ip(&remote_addr), remote_port);
err = netconn_connect(sock->conn, &remote_addr, remote_port);
}
if (err != ERR_OK) {
@ -823,22 +823,19 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
#endif /* !SOCKETS_DEBUG */
{
u16_t port;
ipX_addr_t tmpaddr;
ipX_addr_t *fromaddr;
ip_addr_t tmpaddr;
ip_addr_t *fromaddr;
union sockaddr_aligned saddr;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) {
fromaddr = &tmpaddr;
/* @todo: this does not work for IPv6, yet */
netconn_getaddr(sock->conn, ipX_2_ip(fromaddr), &port, 0);
netconn_getaddr(sock->conn, fromaddr, &port, 0);
} else {
port = netbuf_fromport((struct netbuf *)buf);
fromaddr = netbuf_fromaddr_ipX((struct netbuf *)buf);
fromaddr = netbuf_fromaddr((struct netbuf *)buf);
}
IPXADDR_PORT_TO_SOCKADDR(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
&saddr, fromaddr, port);
ipX_addr_debug_print(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
SOCKETS_DEBUG, fromaddr);
IPADDR_PORT_TO_SOCKADDR(&saddr, fromaddr, port);
ip_addr_debug_print(SOCKETS_DEBUG, fromaddr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%d\n", port, off));
#if SOCKETS_DEBUG
if (from && fromlen)
@ -976,18 +973,17 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
buf.flags = 0;
#endif /* LWIP_CHECKSUM_ON_COPY */
if (to) {
SOCKADDR_TO_IPXADDR_PORT((to->sa_family) == AF_INET6, to, &buf.addr, remote_port);
SOCKADDR_TO_IPADDR_PORT(to, &buf.addr, remote_port);
} else {
remote_port = 0;
ipX_addr_set_any(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)), &buf.addr);
ip_addr_set_any(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)), &buf.addr);
}
netbuf_fromport(&buf) = remote_port;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%"U16_F", flags=0x%x to=",
s, data, short_size, flags));
ipX_addr_debug_print(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
SOCKETS_DEBUG, &buf.addr);
ip_addr_debug_print(SOCKETS_DEBUG, &buf.addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", remote_port));
/* make the buffer point to the data that should be sent */
@ -1521,7 +1517,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
{
struct lwip_sock *sock;
union sockaddr_aligned saddr;
ipX_addr_t naddr;
ip_addr_t naddr;
u16_t port;
err_t err;
@ -1532,17 +1528,15 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
/* get the IP address and port */
/* @todo: this does not work for IPv6, yet */
err = netconn_getaddr(sock->conn, ipX_2_ip(&naddr), &port, local);
err = netconn_getaddr(sock->conn, &naddr, &port, local);
if (err != ERR_OK) {
sock_set_errno(sock, err_to_errno(err));
return -1;
}
IPXADDR_PORT_TO_SOCKADDR(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
&saddr, &naddr, port);
IPADDR_PORT_TO_SOCKADDR(&saddr, &naddr, port);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getaddrname(%d, addr=", s));
ipX_addr_debug_print(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
SOCKETS_DEBUG, &naddr);
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", port));
if (*namelen > saddr.sa.sa_len) {
@ -2164,7 +2158,7 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
break;
case IP_MULTICAST_IF:
{
ip_addr_t if_addr;
ip4_addr_t if_addr;
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct in_addr, NETCONN_UDP);
inet_addr_to_ipaddr(&if_addr, (struct in_addr*)optval);
udp_set_multicast_netif_addr(sock->conn->pcb.udp, &if_addr);
@ -2185,8 +2179,8 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
/* @todo: assign membership to this socket so that it is dropped when closing the socket */
err_t igmp_err;
struct ip_mreq *imr = (struct ip_mreq *)optval;
ip_addr_t if_addr;
ip_addr_t multi_addr;
ip4_addr_t if_addr;
ip4_addr_t multi_addr;
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ip_mreq, NETCONN_UDP);
inet_addr_to_ipaddr(&if_addr, &imr->imr_interface);
inet_addr_to_ipaddr(&multi_addr, &imr->imr_multiaddr);
@ -2497,7 +2491,7 @@ lwip_fcntl(int s, int cmd, int val)
* @return 1 on success, 0 on failure
*/
static int
lwip_socket_register_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr)
lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr)
{
/* s+1 is stored in the array to prevent having to initialize the array
(default initialization is to 0) */
@ -2507,8 +2501,8 @@ lwip_socket_register_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
if (socket_ipv4_multicast_memberships[i].sa == 0) {
socket_ipv4_multicast_memberships[i].sa = sa;
ip_addr_copy(socket_ipv4_multicast_memberships[i].if_addr, *if_addr);
ip_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr);
ip4_addr_copy(socket_ipv4_multicast_memberships[i].if_addr, *if_addr);
ip4_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr);
return 1;
}
}
@ -2521,7 +2515,7 @@ lwip_socket_register_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr
* ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK).
*/
static void
lwip_socket_unregister_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_addr)
lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr)
{
/* s+1 is stored in the array to prevent having to initialize the array
(default initialization is to 0) */
@ -2530,11 +2524,11 @@ lwip_socket_unregister_membership(int s, ip_addr_t *if_addr, ip_addr_t *multi_ad
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
if ((socket_ipv4_multicast_memberships[i].sa == sa) &&
ip_addr_cmp(&socket_ipv4_multicast_memberships[i].if_addr, if_addr) &&
ip_addr_cmp(&socket_ipv4_multicast_memberships[i].multi_addr, multi_addr)) {
ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].if_addr, if_addr) &&
ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].multi_addr, multi_addr)) {
socket_ipv4_multicast_memberships[i].sa = 0;
ip_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
return;
}
}
@ -2555,11 +2549,14 @@ static void lwip_socket_drop_registered_memberships(int s)
for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
if (socket_ipv4_multicast_memberships[i].sa == sa) {
netconn_join_leave_group(sockets[s].conn, &socket_ipv4_multicast_memberships[i].multi_addr,
&socket_ipv4_multicast_memberships[i].if_addr, NETCONN_LEAVE);
ip_addr_t multi_addr, if_addr;
ip_addr_copy_from_ip4(multi_addr, socket_ipv4_multicast_memberships[i].multi_addr);
ip_addr_copy_from_ip4(if_addr, socket_ipv4_multicast_memberships[i].if_addr);
socket_ipv4_multicast_memberships[i].sa = 0;
ip_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr);
ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr);
netconn_join_leave_group(sockets[s].conn, &multi_addr, &if_addr, NETCONN_LEAVE);
}
}
}

View File

@ -115,17 +115,9 @@ tcpip_thread(void *arg)
ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);
} else
#endif /* LWIP_ETHERNET */
#if LWIP_IPV6
if (((*(u8_t*)(msg->msg.inp.p->payload)) & 0xf0) == 0x60) {
ip6_input(msg->msg.inp.p, msg->msg.inp.netif);
} else
#endif /* LWIP_IPV6 */
{
ip_input(msg->msg.inp.p, msg->msg.inp.netif);
}
ip_input(msg->msg.inp.p, msg->msg.inp.netif);
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
break;
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
#if PPPOS_SUPPORT && !PPP_INPROC_IRQ_SAFE
case TCPIP_MSG_INPKT_PPPOS:
@ -133,6 +125,7 @@ tcpip_thread(void *arg)
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
break;
#endif /* PPPOS_SUPPORT && !PPP_INPROC_IRQ_SAFE */
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
#if LWIP_NETIF_API
case TCPIP_MSG_NETIFAPI:
@ -200,14 +193,7 @@ tcpip_input(struct pbuf *p, struct netif *inp)
ret = ethernet_input(p, inp);
} else
#endif /* LWIP_ETHERNET */
#if LWIP_IPV6
if (((*(u8_t*)(p->payload)) & 0xf0) == 0x60) {
ret = ip6_input(p, inp);
} else
#endif /* LWIP_IPV6 */
{
ret = ip_input(p, inp);
}
ret = ip_input(p, inp);
UNLOCK_TCPIP_CORE();
return ret;
#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */

View File

@ -68,7 +68,7 @@
#include "lwip/opt.h"
#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV4 && LWIP_DHCP /* don't build if not configured for use in lwipopts.h */
#include "lwip/stats.h"
#include "lwip/mem.h"
@ -112,7 +112,7 @@
/** This function must exist, in other to add offered NTP servers to
* the NTP (or SNTP) engine.
* See LWIP_DHCP_MAX_NTP_SERVERS */
extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_server_addrs);
#endif /* LWIP_DHCP_GET_NTP_SRV */
/** Option handling: options are parsed in dhcp_parse_reply
@ -222,7 +222,7 @@ dhcp_handle_nak(struct netif *netif)
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n",
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
/* remove IP address from interface (must no longer be used, as per RFC2131) */
netif_set_addr(netif, IP_ADDR_ANY, IP_ADDR_ANY, IP_ADDR_ANY);
netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);
/* Change to a defined state */
dhcp_set_state(dhcp, DHCP_BACKING_OFF);
/* We can immediately restart discovery */
@ -276,11 +276,11 @@ dhcp_handle_offer(struct netif *netif)
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
/* obtain the server address */
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) {
ip4_addr_set_u32(&dhcp->server_ip_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID)));
ip_addr_set_ip4_u32(&dhcp->server_ip_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID)));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->server_ip_addr)));
ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
/* remember offered address */
ip_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
ip4_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->offered_ip_addr)));
@ -321,7 +321,7 @@ dhcp_select(struct netif *netif)
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr)));
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, sizeof(dhcp_discover_select_options));
for (i = 0; i < sizeof(dhcp_discover_select_options); i++) {
@ -533,14 +533,14 @@ dhcp_handle_ack(struct netif *netif)
u8_t n;
#endif /* LWIP_DNS || LWIP_DHCP_GET_NTP_SRV */
#if LWIP_DHCP_GET_NTP_SRV
ip_addr_t ntp_server_addrs[LWIP_DHCP_MAX_NTP_SERVERS];
ip4_addr_t ntp_server_addrs[LWIP_DHCP_MAX_NTP_SERVERS];
#endif
/* clear options we might not get from the ACK */
ip_addr_set_zero(&dhcp->offered_sn_mask);
ip_addr_set_zero(&dhcp->offered_gw_addr);
ip4_addr_set_zero(&dhcp->offered_sn_mask);
ip4_addr_set_zero(&dhcp->offered_gw_addr);
#if LWIP_DHCP_BOOTP_FILE
ip_addr_set_zero(&dhcp->offered_si_addr);
ip4_addr_set_zero(&dhcp->offered_si_addr);
#endif /* LWIP_DHCP_BOOTP_FILE */
/* lease time given? */
@ -567,7 +567,7 @@ dhcp_handle_ack(struct netif *netif)
}
/* (y)our internet address */
ip_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
ip4_addr_copy(dhcp->offered_ip_addr, dhcp->msg_in->yiaddr);
#if LWIP_DHCP_BOOTP_FILE
/* copy boot server address,
@ -601,7 +601,7 @@ dhcp_handle_ack(struct netif *netif)
/* DNS servers */
for(n = 0; (n < DNS_MAX_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
ip_addr_t dns_addr;
ip4_addr_set_u32(&dns_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
ip_addr_set_ip4_u32(&dns_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
dns_setserver(n, &dns_addr);
}
#endif /* LWIP_DNS */
@ -838,7 +838,7 @@ dhcp_network_changed(struct netif *netif)
* @param netif the network interface on which the reply was received
* @param addr The IP address we received a reply from
*/
void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr)
void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr)
{
LWIP_ERROR("netif != NULL", (netif != NULL), return;);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n"));
@ -848,7 +848,7 @@ void dhcp_arp_reply(struct netif *netif, ip_addr_t *addr)
ip4_addr_get_u32(addr)));
/* did a host respond with the address we
were offered by the DHCP server? */
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
if (ip4_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
/* we will not accept the offered address */
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
("dhcp_arp_reply(): arp reply matched with offered address, declining\n"));
@ -916,7 +916,7 @@ dhcp_discover(struct netif *netif)
u16_t msecs;
u8_t i;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover()\n"));
ip_addr_set_any(&dhcp->offered_ip_addr);
ip4_addr_set_any(&dhcp->offered_ip_addr);
dhcp_set_state(dhcp, DHCP_SELECTING);
/* create and initialize the DHCP message header */
result = dhcp_create_msg(netif, dhcp, DHCP_DISCOVER);
@ -969,7 +969,7 @@ dhcp_bind(struct netif *netif)
{
u32_t timeout;
struct dhcp *dhcp;
ip_addr_t sn_mask, gw_addr;
ip4_addr_t sn_mask, gw_addr;
LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;);
dhcp = netif->dhcp;
LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;);
@ -1029,7 +1029,7 @@ dhcp_bind(struct netif *netif)
if (dhcp->subnet_mask_given) {
/* copy offered network mask */
ip_addr_copy(sn_mask, dhcp->offered_sn_mask);
ip4_addr_copy(sn_mask, dhcp->offered_sn_mask);
} else {
/* subnet mask not given, choose a safe subnet mask given the network class */
u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
@ -1042,11 +1042,11 @@ dhcp_bind(struct netif *netif)
}
}
ip_addr_copy(gw_addr, dhcp->offered_gw_addr);
ip4_addr_copy(gw_addr, dhcp->offered_gw_addr);
/* gateway address not given? */
if (ip_addr_isany(&gw_addr)) {
if (ip4_addr_isany(&gw_addr)) {
/* copy network address */
ip_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
ip4_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
/* use first host address on network as gateway */
ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | PP_HTONL(0x00000001UL));
}
@ -1223,11 +1223,11 @@ dhcp_release(struct netif *netif)
dhcp_set_state(dhcp, DHCP_OFF);
/* clean old DHCP offer */
ip_addr_set_zero(&dhcp->server_ip_addr);
ip_addr_set_zero(&dhcp->offered_ip_addr);
ip_addr_set_zero(&dhcp->offered_sn_mask);
ip_addr_set_zero(&dhcp->offered_gw_addr);
ip4_addr_set_zero(&dhcp->offered_ip_addr);
ip4_addr_set_zero(&dhcp->offered_sn_mask);
ip4_addr_set_zero(&dhcp->offered_gw_addr);
#if LWIP_DHCP_BOOTP_FILE
ip_addr_set_zero(&dhcp->offered_si_addr);
ip4_addr_set_zero(&dhcp->offered_si_addr);
#endif /* LWIP_DHCP_BOOTP_FILE */
dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0;
@ -1235,7 +1235,7 @@ dhcp_release(struct netif *netif)
result = dhcp_create_msg(netif, dhcp, DHCP_RELEASE);
if (result == ERR_OK) {
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&server_ip_addr)));
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr))));
dhcp_option_trailer(dhcp);
@ -1254,7 +1254,7 @@ dhcp_release(struct netif *netif)
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_release(): set request timeout %"U16_F" msecs\n", msecs));
/* remove IP address from interface (prevents routing from selecting this interface) */
netif_set_addr(netif, IP_ADDR_ANY, IP_ADDR_ANY, IP_ADDR_ANY);
netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);
return result;
}
@ -1754,16 +1754,16 @@ dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type)
/* we don't need the broadcast flag since we can receive unicast traffic
before being fully configured! */
dhcp->msg_out->flags = 0;
ip_addr_set_zero(&dhcp->msg_out->ciaddr);
ip4_addr_set_zero(&dhcp->msg_out->ciaddr);
/* set ciaddr to netif->ip_addr based on message_type and state */
if ((message_type == DHCP_INFORM) || (message_type == DHCP_DECLINE) || (message_type == DHCP_RELEASE) ||
((message_type == DHCP_REQUEST) && /* DHCP_BOUND not used for sending! */
((dhcp->state==DHCP_RENEWING) || dhcp->state==DHCP_REBINDING))) {
ip_addr_copy(dhcp->msg_out->ciaddr, netif->ip_addr);
ip4_addr_copy(dhcp->msg_out->ciaddr, netif->ip_addr);
}
ip_addr_set_zero(&dhcp->msg_out->yiaddr);
ip_addr_set_zero(&dhcp->msg_out->siaddr);
ip_addr_set_zero(&dhcp->msg_out->giaddr);
ip4_addr_set_zero(&dhcp->msg_out->yiaddr);
ip4_addr_set_zero(&dhcp->msg_out->siaddr);
ip4_addr_set_zero(&dhcp->msg_out->giaddr);
for (i = 0; i < DHCP_CHADDR_LEN; i++) {
/* copy netif hardware address, pad with zeroes */
dhcp->msg_out->chaddr[i] = (i < netif->hwaddr_len && i < NETIF_MAX_HWADDR_LEN) ? netif->hwaddr[i] : 0/* pad byte*/;
@ -1827,4 +1827,4 @@ dhcp_option_trailer(struct dhcp *dhcp)
}
}
#endif /* LWIP_DHCP */
#endif /* LWIP_IPV4 && LWIP_DHCP */

View File

@ -113,7 +113,7 @@ static u16_t dns_txid;
/** DNS server IP address */
#ifndef DNS_SERVER_ADDRESS
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
#define DNS_SERVER_ADDRESS(ipaddr) ip_addr_set_ip4_u32(ipaddr, ipaddr_addr("208.67.222.222")) /* resolver1.opendns.com */
#endif
/** DNS server port address */
@ -459,7 +459,7 @@ dns_lookup_local(const char *hostname)
struct local_hostlist_entry *entry = local_hostlist_dynamic;
while(entry != NULL) {
if (LWIP_DNS_STRICMP(entry->name, hostname) == 0) {
return ip4_addr_get_u32(&entry->addr);
return ip_addr_get_ip4_u32(&entry->addr);
}
entry = entry->next;
}
@ -467,7 +467,7 @@ dns_lookup_local(const char *hostname)
int i;
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
if (LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) {
return ip4_addr_get_u32(&local_hostlist_static[i].addr);
return ip_addr_get_ip4_u32(&local_hostlist_static[i].addr);
}
}
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
@ -577,9 +577,9 @@ dns_lookup(const char *name)
if ((dns_table[i].state == DNS_STATE_DONE) &&
(LWIP_DNS_STRICMP(name, dns_table[i].name) == 0)) {
LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
ip4_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
return ip4_addr_get_u32(&dns_table[i].ipaddr);
return ip_addr_get_ip4_u32(&dns_table[i].ipaddr);
}
}
@ -1059,7 +1059,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
/* Check for IP address type and Internet class. Others are discarded. */
pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx);
if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
(ans.len == PP_HTONS(sizeof(ip_addr_t))) ) {
(ans.len == PP_HTONS(sizeof(ip4_addr_t))) ) {
res_idx += SIZEOF_DNS_ANSWER;
/* read the answer resource record's TTL, and maximize it if needed */
entry->ttl = ntohl(ans.ttl);
@ -1069,7 +1069,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
/* read the IP address after answer resource record's header */
pbuf_copy_partial(p, &(entry->ipaddr), sizeof(entry->ipaddr), res_idx);
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", entry->name));
ip_addr_debug_print(DNS_DEBUG, (&(entry->ipaddr)));
ip4_addr_debug_print(DNS_DEBUG, (&(entry->ipaddr)));
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
/* call specified callback function if provided */
dns_call_found(entry_idx, &entry->ipaddr);
@ -1279,7 +1279,8 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
#if LWIP_HAVE_LOOPIF
if (strcmp(hostname, "localhost") == 0) {
ip_addr_set_loopback(addr);
/* @todo: IPv6 support... */
ip_addr_set_loopback(0, addr);
return ERR_OK;
}
#endif /* LWIP_HAVE_LOOPIF */
@ -1291,7 +1292,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
ipaddr = dns_lookup(hostname);
}
if (ipaddr != IPADDR_NONE) {
ip4_addr_set_u32(addr, ipaddr);
ip_addr_set_ip4_u32(addr, ipaddr);
return ERR_OK;
}

View File

@ -295,9 +295,10 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
return (u16_t)~(acc & 0xffffUL);
}
#if LWIP_IPV4
/* inet_chksum_pseudo:
*
* Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain.
* Calculates the IPv4 pseudo Internet checksum used by TCP and UDP for a pbuf chain.
* IP addresses are expected to be in network byte order.
*
* @param p chain of pbufs over that a checksum should be calculated (ip data part)
@ -309,7 +310,7 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
*/
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)
const ip4_addr_t *src, const ip4_addr_t *dest)
{
u32_t acc;
u32_t addr;
@ -326,6 +327,8 @@ inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
return inet_cksum_pseudo_base(p, proto, proto_len, acc);
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
/**
* Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain.
@ -362,6 +365,37 @@ ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
}
#endif /* LWIP_IPV6 */
/* ip_chksum_pseudo:
*
* Calculates the IPv4 or IPv6 pseudo Internet checksum used by TCP and UDP for a pbuf chain.
* IP addresses are expected to be in network byte order.
*
* @param p chain of pbufs over that a checksum should be calculated (ip data part)
* @param src source ip address (used for checksum of pseudo header)
* @param dst destination ip address (used for checksum of pseudo header)
* @param proto ip protocol (used for checksum of pseudo header)
* @param proto_len length of the ip data part (used for checksum of pseudo header)
* @return checksum (as u16_t) to be saved directly in the protocol header
*/
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)
{
#if LWIP_IPV6
if (IP_IS_V6(dest)) {
return ip6_chksum_pseudo(p, proto, proto_len, ip_2_ip6(src), ip_2_ip6(dest));
}
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
else
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_IPV4
{
return inet_chksum_pseudo(p, proto, proto_len, ip_2_ip4(src), ip_2_ip4(dest));
}
#endif /* LWIP_IPV4 */
}
/** Parts of the pseudo checksum which are common to IPv4 and IPv6 */
static u16_t
inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len,
@ -407,9 +441,10 @@ inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len,
return (u16_t)~(acc & 0xffffUL);
}
#if LWIP_IPV4
/* inet_chksum_pseudo_partial:
*
* Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain.
* Calculates the IPv4 pseudo Internet checksum used by TCP and UDP for a pbuf chain.
* IP addresses are expected to be in network byte order.
*
* @param p chain of pbufs over that a checksum should be calculated (ip data part)
@ -421,7 +456,7 @@ inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len,
*/
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)
u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest)
{
u32_t acc;
u32_t addr;
@ -438,6 +473,7 @@ inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
return inet_cksum_pseudo_partial_base(p, proto, proto_len, chksum_len, acc);
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
/**
@ -477,6 +513,36 @@ ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len,
}
#endif /* LWIP_IPV6 */
/* ip_chksum_pseudo_partial:
*
* Calculates the IPv4 or IPv6 pseudo Internet checksum used by TCP and UDP for a pbuf chain.
*
* @param p chain of pbufs over that a checksum should be calculated (ip data part)
* @param src source ip address (used for checksum of pseudo header)
* @param dst destination ip address (used for checksum of pseudo header)
* @param proto ip protocol (used for checksum of pseudo header)
* @param proto_len length of the ip data part (used for checksum of pseudo header)
* @return checksum (as u16_t) to be saved directly in the protocol header
*/
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)
{
#if LWIP_IPV6
if (IP_IS_V6(dest)) {
return ip6_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip6(src), ip_2_ip6(dest));
}
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
else
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_IPV4
{
return inet_chksum_pseudo_partial(p, proto, proto_len, chksum_len, ip_2_ip4(src), ip_2_ip4(dest));
}
#endif /* LWIP_IPV4 */
}
/* inet_chksum:
*
* Calculates the Internet checksum over a portion of memory. Used primarily for IP

View File

@ -313,10 +313,12 @@ lwip_init(void)
memp_init();
pbuf_init();
netif_init();
#if LWIP_IPV4
ip_init();
#if LWIP_ARP
etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
raw_init();
#endif /* LWIP_RAW */

View File

@ -64,10 +64,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/mem.h"
#include "lwip/udp.h"
//#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/autoip.h"
@ -108,7 +108,7 @@
static void autoip_handle_arp_conflict(struct netif *netif);
/* creates a pseudo random LL IP-Address for a network interface */
static void autoip_create_addr(struct netif *netif, ip_addr_t *ipaddr);
static void autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr);
/* sends an ARP probe */
static err_t autoip_arp_probe(struct netif *netif);
@ -193,7 +193,7 @@ autoip_handle_arp_conflict(struct netif *netif)
* @param ipaddr ip address to initialize
*/
static void
autoip_create_addr(struct netif *netif, ip_addr_t *ipaddr)
autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr)
{
/* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255
* compliant to RFC 3927 Section 2.1
@ -229,7 +229,7 @@ static err_t
autoip_arp_probe(struct netif *netif)
{
return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, &ethbroadcast,
(struct eth_addr *)netif->hwaddr, IP_ADDR_ANY, &ethzero,
(struct eth_addr *)netif->hwaddr, IP4_ADDR_ANY, &ethzero,
&netif->autoip->llipaddr, ARP_REQUEST);
}
@ -255,7 +255,7 @@ static err_t
autoip_bind(struct netif *netif)
{
struct autoip *autoip = netif->autoip;
ip_addr_t sn_mask, gw_addr;
ip4_addr_t sn_mask, gw_addr;
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
("autoip_bind(netif=%p) %c%c%"U16_F" %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
@ -288,7 +288,7 @@ autoip_start(struct netif *netif)
/* Set IP-Address, Netmask and Gateway to 0 to make sure that
* ARP Packets are formed correctly
*/
netif_set_addr(netif, IP_ADDR_ANY, IP_ADDR_ANY, IP_ADDR_ANY);
netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0],
@ -311,7 +311,7 @@ autoip_start(struct netif *netif)
autoip->state = AUTOIP_STATE_OFF;
autoip->ttw = 0;
autoip->sent_num = 0;
ip_addr_set_zero(&autoip->llipaddr);
ip4_addr_set_zero(&autoip->llipaddr);
autoip->lastconflict = 0;
}
@ -373,8 +373,8 @@ autoip_stop(struct netif *netif)
{
if (netif->autoip) {
netif->autoip->state = AUTOIP_STATE_OFF;
if (ip_addr_islinklocal(&netif->ip_addr)) {
netif_set_addr(netif, IP_ADDR_ANY, IP_ADDR_ANY, IP_ADDR_ANY);
if (ip4_addr_islinklocal(&netif->ip_addr)) {
netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);
}
}
return ERR_OK;
@ -479,11 +479,11 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
* when probing ip.dst == llipaddr && hw.src != netif->hwaddr
* we have a conflict and must solve it
*/
ip_addr_t sipaddr, dipaddr;
ip4_addr_t sipaddr, dipaddr;
struct eth_addr netifaddr;
ETHADDR16_COPY(netifaddr.addr, netif->hwaddr);
/* 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);
@ -498,8 +498,8 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
* ip.src == llipaddr OR
* ip.dst == llipaddr && hw.src != own hwaddr
*/
if ((ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) ||
(ip_addr_cmp(&dipaddr, &netif->autoip->llipaddr) &&
if ((ip4_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) ||
(ip4_addr_cmp(&dipaddr, &netif->autoip->llipaddr) &&
!eth_addr_cmp(&netifaddr, &hdr->shwaddr))) {
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
("autoip_arp_reply(): Probe Conflict detected\n"));
@ -510,7 +510,7 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
* in any state we have a conflict if
* ip.src == llipaddr && hw.src != own hwaddr
*/
if (ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr) &&
if (ip4_addr_cmp(&sipaddr, &netif->autoip->llipaddr) &&
!eth_addr_cmp(&netifaddr, &hdr->shwaddr)) {
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
("autoip_arp_reply(): Conflicting ARP-Packet detected\n"));
@ -520,4 +520,4 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
}
}
#endif /* LWIP_AUTOIP */
#endif /* LWIP_IPV4 && LWIP_AUTOIP */

View File

@ -41,7 +41,7 @@
#include "lwip/opt.h"
#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 */
#include "lwip/icmp.h"
#include "lwip/inet_chksum.h"
@ -87,7 +87,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
ICMP_STATS_INC(icmp.recv);
snmp_inc_icmpinmsgs();
iphdr = (struct ip_hdr *)ip_current_header();
iphdr = (struct ip_hdr *)ip4_current_header();
hlen = IPH_HL(iphdr) * 4;
if (p->len < sizeof(u16_t)*2) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len));
@ -185,8 +185,8 @@ icmp_input(struct pbuf *p, struct netif *inp)
/* We generate an answer by switching the dest and src ip addresses,
* setting the icmp type to ECHO_RESPONSE and updating the checksum. */
iecho = (struct icmp_echo_hdr *)p->payload;
ip_addr_copy(iphdr->src, inp->ip_addr);
ip_addr_copy(iphdr->dest, *ip_current_src_addr());
ip4_addr_copy(iphdr->src, inp->ip_addr);
ip4_addr_copy(iphdr->dest, *ip4_current_src_addr());
ICMPH_TYPE_SET(iecho, ICMP_ER);
#if CHECKSUM_GEN_ICMP
/* adjust the checksum */
@ -217,7 +217,7 @@ icmp_input(struct pbuf *p, struct netif *inp)
} else {
err_t ret;
/* send an ICMP packet, src addr is the dest addr of the current packet */
ret = ip_output_if(p, ip_current_dest_addr(), IP_HDRINCL,
ret = ip4_output_if(p, ip4_current_dest_addr(), IP_HDRINCL,
ICMP_TTL, 0, IP_PROTO_ICMP, inp);
if (ret != ERR_OK) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ip_output_if returned an error: %c.\n", ret));
@ -292,7 +292,7 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
struct ip_hdr *iphdr;
/* we can use the echo header here */
struct icmp_echo_hdr *icmphdr;
ip_addr_t iphdr_src;
ip4_addr_t iphdr_src;
/* ICMP header + IP header + 8 bytes of data */
q = pbuf_alloc(PBUF_IP, sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE,
@ -306,9 +306,9 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
iphdr = (struct ip_hdr *)p->payload;
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));
ip_addr_debug_print(ICMP_DEBUG, &(iphdr->src));
ip4_addr_debug_print(ICMP_DEBUG, &(iphdr->src));
LWIP_DEBUGF(ICMP_DEBUG, (" to "));
ip_addr_debug_print(ICMP_DEBUG, &(iphdr->dest));
ip4_addr_debug_print(ICMP_DEBUG, &(iphdr->dest));
LWIP_DEBUGF(ICMP_DEBUG, ("\n"));
icmphdr = (struct icmp_echo_hdr *)q->payload;
@ -331,9 +331,9 @@ icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
snmp_inc_icmpoutmsgs();
/* increase number of destination unreachable messages attempted to send */
snmp_inc_icmpouttimeexcds();
ip_addr_copy(iphdr_src, iphdr->src);
ip_output(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP);
ip4_addr_copy(iphdr_src, iphdr->src);
ip4_output(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP);
pbuf_free(q);
}
#endif /* LWIP_ICMP */
#endif /* LWIP_IPV4 && LWIP_ICMP */

View File

@ -79,7 +79,7 @@ Steve Reynolds
#include "lwip/opt.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 */
#include "lwip/igmp.h"
#include "lwip/debug.h"
@ -124,10 +124,10 @@ Steve Reynolds
#endif
PACK_STRUCT_BEGIN
struct igmp_msg {
PACK_STRUCT_FLD_8(u8_t igmp_msgtype);
PACK_STRUCT_FLD_8(u8_t igmp_maxresp);
PACK_STRUCT_FIELD(u16_t igmp_checksum);
PACK_STRUCT_FLD_S(ip_addr_p_t igmp_group_address);
PACK_STRUCT_FLD_8(u8_t igmp_msgtype);
PACK_STRUCT_FLD_8(u8_t igmp_maxresp);
PACK_STRUCT_FIELD(u16_t igmp_checksum);
PACK_STRUCT_FLD_S(ip4_addr_p_t igmp_group_address);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
@ -135,18 +135,18 @@ PACK_STRUCT_END
#endif
static struct igmp_group *igmp_lookup_group(struct netif *ifp, const ip_addr_t *addr);
static struct igmp_group *igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr);
static err_t igmp_remove_group(struct igmp_group *group);
static void igmp_timeout( struct igmp_group *group);
static void igmp_start_timer(struct igmp_group *group, u8_t max_time);
static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp);
static err_t igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif);
static err_t igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, struct netif *netif);
static void igmp_send(struct igmp_group *group, u8_t type);
static struct igmp_group* igmp_group_list;
static ip_addr_t allsystems;
static ip_addr_t allrouters;
static ip4_addr_t allsystems;
static ip4_addr_t allrouters;
/**
@ -172,7 +172,7 @@ igmp_dump_group_list()
while (group != NULL) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_dump_group_list: [%"U32_F"] ", (u32_t)(group->group_state)));
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
ip4_addr_debug_print(IGMP_DEBUG, &group->group_address);
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif));
group = group->next;
}
@ -203,7 +203,7 @@ igmp_start(struct netif *netif)
/* Allow the igmp messages at the MAC level */
if (netif->igmp_mac_filter != NULL) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: igmp_mac_filter(ADD "));
ip_addr_debug_print(IGMP_DEBUG, &allsystems);
ip4_addr_debug_print(IGMP_DEBUG, &allsystems);
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER);
}
@ -242,7 +242,7 @@ igmp_stop(struct netif *netif)
/* disable the group at the MAC level */
if (netif->igmp_mac_filter != NULL) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL "));
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
ip4_addr_debug_print(IGMP_DEBUG, &group->group_address);
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
netif->igmp_mac_filter(netif, &(group->group_address), IGMP_DEL_MAC_FILTER);
}
@ -271,7 +271,7 @@ igmp_report_groups(struct netif *netif)
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_report_groups: sending IGMP reports on if %p\n", netif));
while (group != NULL) {
if ((group->netif == netif) && (!(ip_addr_cmp(&(group->group_address), &allsystems)))) {
if ((group->netif == netif) && (!(ip4_addr_cmp(&(group->group_address), &allsystems)))) {
igmp_delaying_member(group, IGMP_JOIN_DELAYING_MEMBER_TMR);
}
group = group->next;
@ -287,12 +287,12 @@ igmp_report_groups(struct netif *netif)
* NULL if the group wasn't found.
*/
struct igmp_group *
igmp_lookfor_group(struct netif *ifp, const ip_addr_t *addr)
igmp_lookfor_group(struct netif *ifp, const ip4_addr_t *addr)
{
struct igmp_group *group = igmp_group_list;
while (group != NULL) {
if ((group->netif == ifp) && (ip_addr_cmp(&(group->group_address), addr))) {
if ((group->netif == ifp) && (ip4_addr_cmp(&(group->group_address), addr))) {
return group;
}
group = group->next;
@ -313,7 +313,7 @@ igmp_lookfor_group(struct netif *ifp, const ip_addr_t *addr)
* NULL on memory error.
*/
struct igmp_group *
igmp_lookup_group(struct netif *ifp, const ip_addr_t *addr)
igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr)
{
struct igmp_group *group = igmp_group_list;
@ -328,7 +328,7 @@ igmp_lookup_group(struct netif *ifp, const ip_addr_t *addr)
group = (struct igmp_group *)memp_malloc(MEMP_IGMP_GROUP);
if (group != NULL) {
group->netif = ifp;
ip_addr_set(&(group->group_address), addr);
ip4_addr_set(&(group->group_address), addr);
group->timer = 0; /* Not running */
group->group_state = IGMP_GROUP_NON_MEMBER;
group->last_reporter_flag = 0;
@ -339,7 +339,7 @@ igmp_lookup_group(struct netif *ifp, const ip_addr_t *addr)
}
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: %sallocated a new group with address ", (group?"":"impossible to ")));
ip_addr_debug_print(IGMP_DEBUG, addr);
ip4_addr_debug_print(IGMP_DEBUG, addr);
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", ifp));
return group;
@ -386,7 +386,7 @@ igmp_remove_group(struct igmp_group *group)
* @param dest destination ip address of the igmp packet
*/
void
igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest)
igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest)
{
struct igmp_msg* igmp;
struct igmp_group* group;
@ -403,9 +403,9 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest)
}
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: message from "));
ip_addr_debug_print(IGMP_DEBUG, &(ip_current_header()->src));
ip4_addr_debug_print(IGMP_DEBUG, &(ip4_current_header()->src));
LWIP_DEBUGF(IGMP_DEBUG, (" to address "));
ip_addr_debug_print(IGMP_DEBUG, &(ip_current_header()->dest));
ip4_addr_debug_print(IGMP_DEBUG, &(ip4_current_header()->dest));
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", inp));
/* Now calculate and check the checksum */
@ -432,7 +432,7 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest)
switch (igmp->igmp_msgtype) {
case IGMP_MEMB_QUERY: {
/* IGMP_MEMB_QUERY to the "all systems" address ? */
if ((ip_addr_cmp(dest, &allsystems)) && ip_addr_isany(&igmp->igmp_group_address)) {
if ((ip4_addr_cmp(dest, &allsystems)) && ip4_addr_isany(&igmp->igmp_group_address)) {
/* THIS IS THE GENERAL QUERY */
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: General IGMP_MEMB_QUERY on \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
@ -447,21 +447,21 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest)
groupref = igmp_group_list;
while (groupref) {
/* Do not send messages on the all systems group address! */
if ((groupref->netif == inp) && (!(ip_addr_cmp(&(groupref->group_address), &allsystems)))) {
if ((groupref->netif == inp) && (!(ip4_addr_cmp(&(groupref->group_address), &allsystems)))) {
igmp_delaying_member(groupref, igmp->igmp_maxresp);
}
groupref = groupref->next;
}
} else {
/* IGMP_MEMB_QUERY to a specific group ? */
if (!ip_addr_isany(&igmp->igmp_group_address)) {
if (!ip4_addr_isany(&igmp->igmp_group_address)) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_MEMB_QUERY to a specific group "));
ip_addr_debug_print(IGMP_DEBUG, &igmp->igmp_group_address);
if (ip_addr_cmp(dest, &allsystems)) {
ip_addr_t groupaddr;
ip4_addr_debug_print(IGMP_DEBUG, &igmp->igmp_group_address);
if (ip4_addr_cmp(dest, &allsystems)) {
ip4_addr_t groupaddr;
LWIP_DEBUGF(IGMP_DEBUG, (" using \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
/* we first need to re-look for the group since we used dest last time */
ip_addr_copy(groupaddr, igmp->igmp_group_address);
ip4_addr_copy(groupaddr, igmp->igmp_group_address);
group = igmp_lookfor_group(inp, &groupaddr);
} else {
LWIP_DEBUGF(IGMP_DEBUG, (" with the group address as destination [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
@ -510,21 +510,21 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip_addr_t *dest)
* @return ERR_OK if group was joined on the netif(s), an err_t otherwise
*/
err_t
igmp_joingroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr)
igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
{
err_t err = ERR_VAL; /* no matching interface */
struct igmp_group *group;
struct netif *netif;
/* make sure it is multicast address */
LWIP_ERROR("igmp_joingroup: attempt to join non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;);
LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
LWIP_ERROR("igmp_joingroup: attempt to join non-multicast address", ip4_addr_ismulticast(groupaddr), return ERR_VAL;);
LWIP_ERROR("igmp_joingroup: attempt to join allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
/* loop through netif's */
netif = netif_list;
while (netif != NULL) {
/* Should we join this interface ? */
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) {
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(&(netif->ip_addr), ifaddr)))) {
/* find group or create a new one if not found */
group = igmp_lookup_group(netif, groupaddr);
@ -535,13 +535,13 @@ igmp_joingroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr)
} else {
/* OK - it was new group */
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: join to new group: "));
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
ip4_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
/* If first use of the group, allow the group at the MAC level */
if ((group->use==0) && (netif->igmp_mac_filter != NULL)) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup: igmp_mac_filter(ADD "));
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
ip4_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
netif->igmp_mac_filter(netif, groupaddr, IGMP_ADD_MAC_FILTER);
}
@ -580,28 +580,28 @@ igmp_joingroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr)
* @return ERR_OK if group was left on the netif(s), an err_t otherwise
*/
err_t
igmp_leavegroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr)
igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr)
{
err_t err = ERR_VAL; /* no matching interface */
struct igmp_group *group;
struct netif *netif;
/* make sure it is multicast address */
LWIP_ERROR("igmp_leavegroup: attempt to leave non-multicast address", ip_addr_ismulticast(groupaddr), return ERR_VAL;);
LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
LWIP_ERROR("igmp_leavegroup: attempt to leave non-multicast address", ip4_addr_ismulticast(groupaddr), return ERR_VAL;);
LWIP_ERROR("igmp_leavegroup: attempt to leave allsystems address", (!ip4_addr_cmp(groupaddr, &allsystems)), return ERR_VAL;);
/* loop through netif's */
netif = netif_list;
while (netif != NULL) {
/* Should we leave this interface ? */
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip_addr_isany(ifaddr) || ip_addr_cmp(&(netif->ip_addr), ifaddr)))) {
if ((netif->flags & NETIF_FLAG_IGMP) && ((ip4_addr_isany(ifaddr) || ip4_addr_cmp(&(netif->ip_addr), ifaddr)))) {
/* find group */
group = igmp_lookfor_group(netif, groupaddr);
if (group != NULL) {
/* Only send a leave if the flag is set according to the state diagram */
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: Leaving group: "));
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
ip4_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
/* If there is no other use of the group */
@ -612,19 +612,19 @@ igmp_leavegroup(const ip_addr_t *ifaddr, const ip_addr_t *groupaddr)
IGMP_STATS_INC(igmp.tx_leave);
igmp_send(group, IGMP_LEAVE_GROUP);
}
/* Disable the group at the MAC level */
if (netif->igmp_mac_filter != NULL) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: igmp_mac_filter(DEL "));
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
ip4_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", netif));
netif->igmp_mac_filter(netif, groupaddr, IGMP_DEL_MAC_FILTER);
}
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup: remove group: "));
ip_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
ip4_addr_debug_print(IGMP_DEBUG, groupaddr);
LWIP_DEBUGF(IGMP_DEBUG, ("\n"));
/* Free the group */
igmp_remove_group(group);
} else {
@ -677,9 +677,9 @@ igmp_timeout(struct igmp_group *group)
/* If the state is IGMP_GROUP_DELAYING_MEMBER then we send a report for this group
(unless it is the allsystems group) */
if ((group->group_state == IGMP_GROUP_DELAYING_MEMBER) &&
(!(ip_addr_cmp(&(group->group_address), &allsystems)))) {
(!(ip4_addr_cmp(&(group->group_address), &allsystems)))) {
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_timeout: report membership for group with address "));
ip_addr_debug_print(IGMP_DEBUG, &(group->group_address));
ip4_addr_debug_print(IGMP_DEBUG, &(group->group_address));
LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", group->netif));
IGMP_STATS_INC(igmp.tx_report);
@ -753,14 +753,14 @@ igmp_delaying_member(struct igmp_group *group, u8_t maxresp)
* returns errors returned by netif->output
*/
static err_t
igmp_ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, struct netif *netif)
igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, struct netif *netif)
{
/* This is the "router alert" option */
u16_t ra[2];
ra[0] = PP_HTONS(ROUTER_ALERT);
ra[1] = 0x0000; /* Router shall examine packet */
IGMP_STATS_INC(igmp.xmit);
return ip_output_if_opt(p, src, dest, IGMP_TTL, 0, IP_PROTO_IGMP, netif, ra, ROUTER_ALERTLEN);
return ip4_output_if_opt(p, src, dest, IGMP_TTL, 0, IP_PROTO_IGMP, netif, ra, ROUTER_ALERTLEN);
}
/**
@ -774,8 +774,8 @@ igmp_send(struct igmp_group *group, u8_t type)
{
struct pbuf* p = NULL;
struct igmp_msg* igmp = NULL;
ip_addr_t src = *IP_ADDR_ANY;
ip_addr_t* dest = NULL;
ip4_addr_t src = *IP4_ADDR_ANY;
ip4_addr_t* dest = NULL;
/* IP header + "router alert" option + IGMP header */
p = pbuf_alloc(PBUF_TRANSPORT, IGMP_MINLEN, PBUF_RAM);
@ -784,16 +784,16 @@ igmp_send(struct igmp_group *group, u8_t type)
igmp = (struct igmp_msg *)p->payload;
LWIP_ASSERT("igmp_send: check that first pbuf can hold struct igmp_msg",
(p->len >= sizeof(struct igmp_msg)));
ip_addr_copy(src, group->netif->ip_addr);
ip4_addr_copy(src, group->netif->ip_addr);
if (type == IGMP_V2_MEMB_REPORT) {
dest = &(group->group_address);
ip_addr_copy(igmp->igmp_group_address, group->group_address);
ip4_addr_copy(igmp->igmp_group_address, group->group_address);
group->last_reporter_flag = 1; /* Remember we were the last to report */
} else {
if (type == IGMP_LEAVE_GROUP) {
dest = &allrouters;
ip_addr_copy(igmp->igmp_group_address, group->group_address);
ip4_addr_copy(igmp->igmp_group_address, group->group_address);
}
}
@ -813,4 +813,4 @@ igmp_send(struct igmp_group *group, u8_t type)
}
}
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 && LWIP_IGMP */

View File

@ -39,6 +39,9 @@
*/
#include "lwip/opt.h"
#if LWIP_IPV4
#include "lwip/ip.h"
#include "lwip/def.h"
#include "lwip/mem.h"
@ -73,7 +76,7 @@
/** Some defines for DHCP to let link-layer-addressed packets through while the
* netif is down.
* To use this in your own application/protocol, define LWIP_IP_ACCEPT_UDP_PORT
* To use this in your own application/protocol, define LWIP_IP_ACCEPT_UDP_PORT(port)
* to return 1 if the port is accepted and 0 if the port is not accepted.
*/
#if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
@ -100,13 +103,13 @@ static u16_t ip_id;
#if LWIP_IGMP
/** The default netif used for multicast */
static struct netif* ip_default_multicast_netif;
static struct netif* ip4_default_multicast_netif;
/** Set a default netif for IPv4 multicast. */
void
ip_set_default_multicast_netif(struct netif* default_multicast_netif)
ip4_set_default_multicast_netif(struct netif* default_multicast_netif)
{
ip_default_multicast_netif = default_multicast_netif;
ip4_default_multicast_netif = default_multicast_netif;
}
#endif /* LWIP_IGMP */
@ -120,7 +123,7 @@ ip_set_default_multicast_netif(struct netif* default_multicast_netif)
* @return the netif on which to send to reach dest
*/
struct netif *
ip_route(const ip_addr_t *dest)
ip4_route(const ip4_addr_t *dest)
{
struct netif *netif;
@ -133,17 +136,17 @@ ip_route(const ip_addr_t *dest)
#if LWIP_IGMP
/* Use administratively selected interface for multicast by default */
if (ip_addr_ismulticast(dest) && ip_default_multicast_netif) {
return ip_default_multicast_netif;
if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
return ip4_default_multicast_netif;
}
#endif /* LWIP_IGMP */
/* iterate through netifs */
for (netif = netif_list; netif != NULL; netif = netif->next) {
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip_addr_isany(&(netif->ip_addr))) {
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany(&(netif->ip_addr))) {
/* network mask matches? */
if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
if (ip4_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
/* return netif on which to forward IP packet */
return netif;
}
@ -151,7 +154,7 @@ ip_route(const ip_addr_t *dest)
}
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) ||
ip_addr_isany(&netif_default->ip_addr)) {
ip4_addr_isany(&netif_default->ip_addr)) {
/* No matching netif found an default netif is not usable.
If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
@ -163,7 +166,7 @@ ip_route(const ip_addr_t *dest)
#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
/* loopif is disabled, looopback traffic is passed through any netif */
if (ip_addr_isloopback(dest)) {
if (ip4_addr_isloopback(dest)) {
/* don't check for link on loopback traffic */
if (netif_is_up(netif_default)) {
return netif_default;
@ -195,9 +198,9 @@ ip_route(const ip_addr_t *dest)
* @return 1: can forward 0: discard
*/
static int
ip_canforward(struct pbuf *p)
ip4_canforward(struct pbuf *p)
{
u32_t addr = htonl(ip4_addr_get_u32(ip_current_dest_addr()));
u32_t addr = htonl(ip4_addr_get_u32(ip4_current_dest_addr()));
if (p->flags & PBUF_FLAG_LLBCAST) {
/* don't route link-layer broadcasts */
@ -231,18 +234,18 @@ ip_canforward(struct pbuf *p)
* @param inp the netif on which this packet was received
*/
static void
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
{
struct netif *netif;
PERF_START;
if (!ip_canforward(p)) {
if (!ip4_canforward(p)) {
goto return_noroute;
}
/* RFC3927 2.7: do not forward link-local addresses */
if (ip_addr_islinklocal(ip_current_dest_addr())) {
if (ip4_addr_islinklocal(ip4_current_dest_addr())) {
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: not forwarding LLA %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
ip4_addr1_16(ip_current_dest_addr()), ip4_addr2_16(ip_current_dest_addr()),
ip4_addr3_16(ip_current_dest_addr()), ip4_addr4_16(ip_current_dest_addr())));
@ -250,7 +253,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
}
/* Find network interface where to forward this IP packet to. */
netif = ip_route(ip_current_dest_addr());
netif = ip4_route(ip4_current_dest_addr());
if (netif == NULL) {
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
ip4_addr1_16(ip_current_dest_addr()), ip4_addr2_16(ip_current_dest_addr()),
@ -301,7 +304,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
if (netif->mtu && (p->tot_len > netif->mtu)) {
if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) {
#if IP_FRAG
ip_frag(p, netif, ip_current_dest_addr());
ip4_frag(p, netif, ip4_current_dest_addr());
#else /* IP_FRAG */
/* @todo: send ICMP Destination Unreachable code 13 "Communication administratively prohibited"? */
#endif /* IP_FRAG */
@ -312,13 +315,30 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
return;
}
/* transmit pbuf on chosen interface */
netif->output(netif, p, ip_current_dest_addr());
netif->output(netif, p, ip4_current_dest_addr());
return;
return_noroute:
snmp_inc_ipoutnoroutes();
}
#endif /* IP_FORWARD */
#if LWIP_IPV6
/* If both IP versions are enabled, this function can dispatch packets to the correct one.
* May be used as netif input function.
*/
err_t
ip_input(struct pbuf *p, struct netif *inp)
{
if (p != NULL) {
if (IP_HDR_GET_VERSION(p->payload) == 6) {
return ip6_input(p, inp);
}
return ip4_input(p, inp);
}
return ERR_VAL;
}
#endif
/**
* This function is called by the network interface device driver when
* an IP packet is received. The function does the basic checks of the
@ -334,7 +354,7 @@ return_noroute:
* processed, but currently always returns ERR_OK)
*/
err_t
ip_input(struct pbuf *p, struct netif *inp)
ip4_input(struct pbuf *p, struct netif *inp)
{
struct ip_hdr *iphdr;
struct netif *netif;
@ -351,7 +371,7 @@ ip_input(struct pbuf *p, struct netif *inp)
iphdr = (struct ip_hdr *)p->payload;
if (IPH_V(iphdr) != 4) {
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr)));
ip_debug_print(p);
ip4_debug_print(p);
pbuf_free(p);
IP_STATS_INC(ip.err);
IP_STATS_INC(ip.drop);
@ -404,7 +424,7 @@ ip_input(struct pbuf *p, struct netif *inp)
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS,
("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdr_hlen)));
ip_debug_print(p);
ip4_debug_print(p);
pbuf_free(p);
IP_STATS_INC(ip.chkerr);
IP_STATS_INC(ip.drop);
@ -414,17 +434,17 @@ ip_input(struct pbuf *p, struct netif *inp)
#endif
/* copy IP addresses to aligned ip_addr_t */
ip_addr_copy(*ipX_2_ip(&ip_data.current_iphdr_dest), iphdr->dest);
ip_addr_copy(*ipX_2_ip(&ip_data.current_iphdr_src), iphdr->src);
ip_addr_copy_from_ip4(ip_data.current_iphdr_dest, iphdr->dest);
ip_addr_copy_from_ip4(ip_data.current_iphdr_src, iphdr->src);
/* match packet against an interface, i.e. is this packet for us? */
#if LWIP_IGMP
if (ip_addr_ismulticast(ip_current_dest_addr())) {
if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, ip_current_dest_addr()))) {
if (ip4_addr_ismulticast(ip4_current_dest_addr())) {
if ((inp->flags & NETIF_FLAG_IGMP) && (igmp_lookfor_group(inp, ip4_current_dest_addr()))) {
/* IGMP snooping switches need 0.0.0.0 to be allowed as source address (RFC 4541) */
ip_addr_t allsystems;
ip4_addr_t allsystems;
IP4_ADDR(&allsystems, 224, 0, 0, 1);
if (ip_addr_cmp(ip_current_dest_addr(), &allsystems) &&
if (ip4_addr_cmp(ip4_current_dest_addr(), &allsystems) &&
ip_addr_isany(ip_current_src_addr())) {
check_ip_src = 0;
}
@ -448,13 +468,13 @@ ip_input(struct pbuf *p, struct netif *inp)
ip4_addr_get_u32(&iphdr->dest) & ~ip4_addr_get_u32(&netif->netmask)));
/* interface is up and configured? */
if ((netif_is_up(netif)) && (!ip_addr_isany(&(netif->ip_addr)))) {
if ((netif_is_up(netif)) && (!ip4_addr_isany(&(netif->ip_addr)))) {
/* unicast to this interface address? */
if (ip_addr_cmp(ip_current_dest_addr(), &(netif->ip_addr)) ||
if (ip4_addr_cmp(ip4_current_dest_addr(), &(netif->ip_addr)) ||
/* or broadcast on this interface network address? */
ip_addr_isbroadcast(ip_current_dest_addr(), netif)
#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
|| (ip4_addr_get_u32(ip_current_dest_addr()) == PP_HTONL(IPADDR_LOOPBACK))
|| (ip4_addr_get_u32(ip4_current_dest_addr()) == PP_HTONL(IPADDR_LOOPBACK))
#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
) {
LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
@ -466,7 +486,7 @@ ip_input(struct pbuf *p, struct netif *inp)
/* connections to link-local addresses must persist after changing
the netif's address (RFC3927 ch. 1.9) */
if ((netif->autoip != NULL) &&
ip_addr_cmp(ip_current_dest_addr(), &(netif->autoip->llipaddr))) {
ip4_addr_cmp(ip4_current_dest_addr(), &(netif->autoip->llipaddr))) {
LWIP_DEBUGF(IP_DEBUG, ("ip_input: LLA packet accepted on interface %c%c\n",
netif->name[0], netif->name[1]));
/* break out of for loop */
@ -541,7 +561,7 @@ ip_input(struct pbuf *p, struct netif *inp)
/* non-broadcast packet? */
if (!ip_addr_isbroadcast(ip_current_dest_addr(), inp)) {
/* try to forward IP packet on (other) interfaces */
ip_forward(p, iphdr, inp);
ip4_forward(p, iphdr, inp);
} else
#endif /* IP_FORWARD */
{
@ -557,7 +577,7 @@ ip_input(struct pbuf *p, struct netif *inp)
LWIP_DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04"X16_F" tot_len=%"U16_F" len=%"U16_F" MF=%"U16_F" offset=%"U16_F"), calling ip_reass()\n",
ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
/* reassemble the packet*/
p = ip_reass(p);
p = ip4_reass(p);
/* packet not fully reassembled yet? */
if (p == NULL) {
return ERR_OK;
@ -595,7 +615,7 @@ ip_input(struct pbuf *p, struct netif *inp)
/* send to upper layers */
LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n"));
ip_debug_print(p);
ip4_debug_print(p);
LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len));
ip_data.current_netif = netif;
@ -634,7 +654,7 @@ ip_input(struct pbuf *p, struct netif *inp)
#endif /* LWIP_ICMP */
#if LWIP_IGMP
case IP_PROTO_IGMP:
igmp_input(p, inp, ip_current_dest_addr());
igmp_input(p, inp, ip4_current_dest_addr());
break;
#endif /* LWIP_IGMP */
default:
@ -662,8 +682,8 @@ ip_input(struct pbuf *p, struct netif *inp)
ip_data.current_input_netif = NULL;
ip_data.current_ip4_header = NULL;
ip_data.current_ip_header_tot_len = 0;
ip_addr_set_any(ip_current_src_addr());
ip_addr_set_any(ip_current_dest_addr());
ip4_addr_set_any(ip4_current_src_addr());
ip4_addr_set_any(ip4_current_dest_addr());
return ERR_OK;
}
@ -694,12 +714,12 @@ ip_input(struct pbuf *p, struct netif *inp)
* unique identifiers independent of destination"
*/
err_t
ip_output_if(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
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)
{
#if IP_OPTIONS_SEND
return ip_output_if_opt(p, src, dest, ttl, tos, proto, netif, NULL, 0);
return ip4_output_if_opt(p, src, dest, ttl, tos, proto, netif, NULL, 0);
}
/**
@ -708,23 +728,23 @@ ip_output_if(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
* @ param ip_options pointer to the IP options, copied into the IP header
* @ param optlen length of ip_options
*/
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)
{
#endif /* IP_OPTIONS_SEND */
const ip_addr_t *src_used = src;
const ip4_addr_t *src_used = src;
if (dest != IP_HDRINCL) {
if (ip_addr_isany(src)) {
if (ip4_addr_isany(src)) {
src_used = &netif->ip_addr;
}
}
#if IP_OPTIONS_SEND
return ip_output_if_opt_src(p, src_used, dest, ttl, tos, proto, netif,
return ip4_output_if_opt_src(p, src_used, dest, ttl, tos, proto, netif,
ip_options, optlen);
#else /* IP_OPTIONS_SEND */
return ip_output_if_src(p, src_used, dest, ttl, tos, proto, netif);
return ip4_output_if_src(p, src_used, dest, ttl, tos, proto, netif);
#endif /* IP_OPTIONS_SEND */
}
@ -733,25 +753,25 @@ err_t ip_output_if_opt(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *de
* when it is 'any'.
*/
err_t
ip_output_if_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
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 IP_OPTIONS_SEND
return ip_output_if_opt_src(p, src, dest, ttl, tos, proto, netif, NULL, 0);
return ip4_output_if_opt_src(p, src, dest, ttl, tos, proto, netif, NULL, 0);
}
/**
* Same as ip_output_if_opt() but 'src' address is not replaced by netif address
* when it is 'any'.
*/
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 */
struct ip_hdr *iphdr;
ip_addr_t dest_addr;
ip4_addr_t dest_addr;
#if CHECKSUM_GEN_IP_INLINE
u32_t chk_sum = 0;
#endif /* CHECKSUM_GEN_IP_INLINE */
@ -811,7 +831,7 @@ err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t
#endif /* CHECKSUM_GEN_IP_INLINE */
/* dest cannot be NULL here */
ip_addr_copy(iphdr->dest, *dest);
ip4_addr_copy(iphdr->dest, *dest);
#if CHECKSUM_GEN_IP_INLINE
chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
@ -834,10 +854,10 @@ err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t
++ip_id;
if (src == NULL) {
ip_addr_copy(iphdr->src, ip_addr_any);
ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY);
} else {
/* src cannot be NULL here */
ip_addr_copy(iphdr->src, *src);
ip4_addr_copy(iphdr->src, *src);
}
#if CHECKSUM_GEN_IP_INLINE
@ -856,19 +876,19 @@ err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t
} else {
/* IP header already included in p */
iphdr = (struct ip_hdr *)p->payload;
ip_addr_copy(dest_addr, iphdr->dest);
ip4_addr_copy(dest_addr, iphdr->dest);
dest = &dest_addr;
}
IP_STATS_INC(ip.xmit);
LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
ip_debug_print(p);
ip4_debug_print(p);
#if ENABLE_LOOPBACK
if (ip_addr_cmp(dest, &netif->ip_addr)
if (ip4_addr_cmp(dest, &netif->ip_addr)
#if !LWIP_HAVE_LOOPIF
|| ip_addr_isloopback(dest)
|| ip4_addr_isloopback(dest)
#endif /* !LWIP_HAVE_LOOPIF */
) {
/* Packet to self, enqueue it for loopback */
@ -884,7 +904,7 @@ err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t
#if IP_FRAG
/* don't fragment if interface has mtu set to 0 [loopif] */
if (netif->mtu && (p->tot_len > netif->mtu)) {
return ip_frag(p, netif, dest);
return ip4_frag(p, netif, dest);
}
#endif /* IP_FRAG */
@ -910,21 +930,21 @@ err_t ip_output_if_opt_src(struct pbuf *p, const ip_addr_t *src, const ip_addr_t
* see ip_output_if() for more return values
*/
err_t
ip_output(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
ip4_output(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;
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
if ((netif = ip_route(dest)) == NULL) {
if ((netif = ip4_route(dest)) == NULL) {
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
return ERR_RTE;
}
return ip_output_if(p, src, dest, ttl, tos, proto, netif);
return ip4_output_if(p, src, dest, ttl, tos, proto, netif);
}
#if LWIP_NETIF_HWADDRHINT
@ -947,7 +967,7 @@ ip_output(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
* see ip_output_if() for more return values
*/
err_t
ip_output_hinted(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
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)
{
struct netif *netif;
@ -955,7 +975,7 @@ ip_output_hinted(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p);
if ((netif = ip_route(dest)) == NULL) {
if ((netif = ip4_route(dest)) == NULL) {
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
@ -963,7 +983,7 @@ ip_output_hinted(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
}
NETIF_SET_HWADDRHINT(netif, addr_hint);
err = ip_output_if(p, src, dest, ttl, tos, proto, netif);
err = ip4_output_if(p, src, dest, ttl, tos, proto, netif);
NETIF_SET_HWADDRHINT(netif, NULL);
return err;
@ -975,7 +995,7 @@ ip_output_hinted(struct pbuf *p, const ip_addr_t *src, const ip_addr_t *dest,
* @param p an IP packet, p->payload pointing to the IP header
*/
void
ip_debug_print(struct pbuf *p)
ip4_debug_print(struct pbuf *p)
{
struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
@ -1013,3 +1033,5 @@ ip_debug_print(struct pbuf *p)
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
}
#endif /* IP_DEBUG */
#endif /* LWIP_IPV4 */

View File

@ -37,12 +37,31 @@
*/
#include "lwip/opt.h"
#if LWIP_IPV4
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
const ip_addr_t ip_addr_any = { IPADDR_ANY };
const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST };
const ip_addr_t ip_addr_any = {
#if LWIP_IPV6
{
#endif
IPADDR_ANY
#if LWIP_IPV6
}, IPADDR_TYPE_V4
#endif
};
const ip_addr_t ip_addr_broadcast = {
#if LWIP_IPV6
{
#endif
IPADDR_BROADCAST
#if LWIP_IPV6
}, IPADDR_TYPE_V4
#endif
};
/**
* Determine if an address is a broadcast address on a network interface
@ -52,9 +71,9 @@ const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST };
* @return returns non-zero if the address is a broadcast address
*/
u8_t
ip4_addr_isbroadcast(u32_t addr, const struct netif *netif)
ip4_addr_isbroadcast_u32(u32_t addr, const struct netif *netif)
{
ip_addr_t ipaddr;
ip4_addr_t ipaddr;
ip4_addr_set_u32(&ipaddr, addr);
/* all ones (broadcast) or all zeroes (old skool broadcast) */
@ -70,7 +89,7 @@ ip4_addr_isbroadcast(u32_t addr, const struct netif *netif)
} else if (addr == ip4_addr_get_u32(&netif->ip_addr)) {
return 0;
/* on the same (sub) network... */
} else if (ip_addr_netcmp(&ipaddr, &(netif->ip_addr), &(netif->netmask))
} else if (ip4_addr_netcmp(&ipaddr, &(netif->ip_addr), &(netif->netmask))
/* ...and host identifier bits are all ones? =>... */
&& ((addr & ~ip4_addr_get_u32(&netif->netmask)) ==
(IPADDR_BROADCAST & ~ip4_addr_get_u32(&netif->netmask)))) {
@ -129,9 +148,9 @@ ip4_addr_netmask_valid(u32_t netmask)
u32_t
ipaddr_addr(const char *cp)
{
ip_addr_t val;
ip4_addr_t val;
if (ipaddr_aton(cp, &val)) {
if (ip4addr_aton(cp, &val)) {
return ip4_addr_get_u32(&val);
}
return (IPADDR_NONE);
@ -149,7 +168,7 @@ ipaddr_addr(const char *cp)
* @return 1 if cp could be converted to addr, 0 on failure
*/
int
ipaddr_aton(const char *cp, ip_addr_t *addr)
ip4addr_aton(const char *cp, ip4_addr_t *addr)
{
u32_t val;
u8_t base;
@ -257,11 +276,11 @@ ipaddr_aton(const char *cp, ip_addr_t *addr)
* @return pointer to a global static (!) buffer that holds the ASCII
* representation of addr
*/
char *
ipaddr_ntoa(const ip_addr_t *addr)
char*
ip4addr_ntoa(const ip4_addr_t *addr)
{
static char str[16];
return ipaddr_ntoa_r(addr, str, 16);
static char str[IP4ADDR_STRLEN_MAX];
return ip4addr_ntoa_r(addr, str, IP4ADDR_STRLEN_MAX);
}
/**
@ -273,7 +292,8 @@ ipaddr_ntoa(const ip_addr_t *addr)
* @return either pointer to buf which now holds the ASCII
* representation of addr or NULL if buf was too small
*/
char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen)
char*
ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen)
{
u32_t s_addr;
char inv[3];
@ -310,3 +330,21 @@ char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen)
*--rp = 0;
return buf;
}
#if LWIP_IPV6
/** Convert IPv4 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)
{
if ((ip4addr == NULL) || (storage == NULL)) {
return NULL;
}
ip4_addr_copy(storage->addr.ip4, *ip4addr);
IP_SET_TYPE_L(storage, IPADDR_TYPE_V4);
return storage;
}
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 */

View File

@ -39,6 +39,9 @@
*/
#include "lwip/opt.h"
#if LWIP_IPV4
#include "lwip/ip_frag.h"
#include "lwip/def.h"
#include "lwip/inet_chksum.h"
@ -100,8 +103,8 @@ PACK_STRUCT_END
#endif
#define IP_ADDRESSES_AND_ID_MATCH(iphdrA, iphdrB) \
(ip_addr_cmp(&(iphdrA)->src, &(iphdrB)->src) && \
ip_addr_cmp(&(iphdrA)->dest, &(iphdrB)->dest) && \
(ip4_addr_cmp(&(iphdrA)->src, &(iphdrB)->src) && \
ip4_addr_cmp(&(iphdrA)->dest, &(iphdrB)->dest) && \
IPH_ID(iphdrA) == IPH_ID(iphdrB)) ? 1 : 0
/* global variables */
@ -476,7 +479,7 @@ freepbuf:
* @return NULL if reassembly is incomplete, ? otherwise
*/
struct pbuf *
ip_reass(struct pbuf *p)
ip4_reass(struct pbuf *p)
{
struct pbuf *r;
struct ip_hdr *fraghdr;
@ -679,8 +682,8 @@ ipfrag_free_pbuf_custom(struct pbuf *p)
*
* @return ERR_OK if sent successfully, err_t otherwise
*/
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)
{
struct pbuf *rambuf;
#if IP_FRAG_USES_STATIC_BUF
@ -879,3 +882,5 @@ ip_frag(struct pbuf *p, struct netif *netif, const ip_addr_t *dest)
return ERR_OK;
}
#endif /* IP_FRAG */
#endif /* LWIP_IPV4 */

View File

@ -41,10 +41,10 @@
#include "lwip/opt.h"
#if LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */
#if LWIP_IPV6 && LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */
#include "lwip/ip6_addr.h"
#include "lwip/def.h"
#endif /* LWIP_IPV6_DHCP6 */
#endif /* LWIP_IPV6 && LWIP_IPV6_DHCP6 */

View File

@ -44,8 +44,10 @@
#if LWIP_IPV6 && LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#include "lwip/def.h"
#include "lwip/inet6.h"
#include "lwip/inet.h"
/** @see ip6_addr.c for implementation of functions. */
/** This variable is initialized by the system to contain the wildcard IPv6 address.
*/
const struct ip6_addr in6addr_any = IN6ADDR_ANY_INIT;
#endif /* LWIP_IPV6 */

View File

@ -60,6 +60,10 @@
#include "lwip/debug.h"
#include "lwip/stats.h"
#if !LWIP_IPV4
/** Global data for IPv6 only */
struct ip_globals ip_data;
#endif /* !LWIP_IPV4 */
/**
* Finds the appropriate network interface for a given IPv6 address. It tries to select
@ -298,7 +302,7 @@ ip6_forward(struct pbuf *p, struct ip6_hdr *iphdr, struct netif *inp)
}
/* Find network interface where to forward this IP packet to. */
netif = ip6_route(IP6_ADDR_ANY, ip6_current_dest_addr());
netif = ip6_route(IP6_ADDR_ANY6, ip6_current_dest_addr());
if (netif == NULL) {
LWIP_DEBUGF(IP6_DEBUG, ("ip6_forward: no route for %"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F"\n",
IP6_ADDR_BLOCK1(ip6_current_dest_addr()),
@ -443,8 +447,8 @@ ip6_input(struct pbuf *p, struct netif *inp)
pbuf_realloc(p, IP6_HLEN + IP6H_PLEN(ip6hdr));
/* copy IP addresses to aligned ip6_addr_t */
ip6_addr_copy(ip_data.current_iphdr_dest.ip6, ip6hdr->dest);
ip6_addr_copy(ip_data.current_iphdr_src.ip6, ip6hdr->src);
ip_addr_copy_from_ip6(ip_data.current_iphdr_dest, ip6hdr->dest);
ip_addr_copy_from_ip6(ip_data.current_iphdr_src, ip6hdr->src);
/* current header pointer. */
ip_data.current_ip6_header = ip6hdr;
@ -764,8 +768,8 @@ ip6_input_cleanup:
ip_data.current_input_netif = NULL;
ip_data.current_ip6_header = NULL;
ip_data.current_ip_header_tot_len = 0;
ip6_addr_set_any(&ip_data.current_iphdr_src.ip6);
ip6_addr_set_any(&ip_data.current_iphdr_dest.ip6);
ip6_addr_set_zero(ip6_current_src_addr());
ip6_addr_set_zero(ip6_current_dest_addr());
return ERR_OK;
}
@ -852,7 +856,7 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
IP6H_PLEN_SET(ip6hdr, p->tot_len - IP6_HLEN);
if (src == NULL) {
src = IP6_ADDR_ANY;
src = IP6_ADDR_ANY6;
}
/* src cannot be NULL here */
ip6_addr_copy(ip6hdr->src, *src);
@ -975,7 +979,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
* see ip_output_if() for more return values
*/
err_t
ip6_output_hinted(struct pbuf *p, ip6_addr_t *src, ip6_addr_t *dest,
ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint)
{
struct netif *netif;

View File

@ -44,11 +44,17 @@
#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
#include "lwip/ip6_addr.h"
#include "lwip/ip_addr.h"
#include "lwip/def.h"
/* used by IP6_ADDR_ANY in ip6_addr.h */
const ip6_addr_t ip6_addr_any = { { 0ul, 0ul, 0ul, 0ul } };
/* used by IP6_ADDR_ANY(6) in ip6_addr.h */
const ip_addr_t ip6_addr_any = {
#if LWIP_IPV4
{ 0ul }, IPADDR_TYPE_V6
#else
0ul, 0ul, 0ul, 0ul
#endif
};
#ifndef isprint
#define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up)
@ -248,4 +254,53 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
return buf;
}
#if LWIP_IPV4
/** Convert 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*
ip6_2_ip(const ip6_addr_t *ip6addr, ip_addr_t* storage)
{
if ((ip6addr == NULL) || (storage == NULL)) {
return NULL;
}
ip6_addr_copy(storage->addr.ip6, *ip6addr);
IP_SET_TYPE_L(storage, IPADDR_TYPE_V6);
return storage;
}
/** Convert IP address string (both versions) to numeric.
* The version is auto-detected from the string.
*/
int
ipaddr_aton(const char *cp, ip_addr_t *addr)
{
if (cp != NULL) {
const char* c;
for (c = cp; *c != 0; c++) {
if (*c == '.') {
/* contains a dot: IPv4 address */
if (addr) {
IP_SET_TYPE_L(addr, IPADDR_TYPE_V4);
}
return ip4addr_aton(cp, ip_2_ip4(addr));
} else if (*c == ':') {
/* contains a colon: IPv6 address */
if (addr) {
IP_SET_TYPE_L(addr, IPADDR_TYPE_V6);
}
return ip6addr_aton(cp, ip_2_ip6(addr));
}
}
/* nothing found, call ip4addr_aton as fallback */
if (addr) {
IP_SET_TYPE_L(addr, IPADDR_TYPE_V4);
}
return ip4addr_aton(cp, ip_2_ip4(addr));
}
return 0;
}
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */

View File

@ -551,7 +551,7 @@ mld6_send(struct mld_group *group, u8_t type)
if (!ip6_addr_isvalid(netif_ip6_addr_state(group->netif, 0))) {
/* This is a special case, when we are performing duplicate address detection.
* We must join the multicast group, but we don't have a valid address yet. */
src_addr = IP6_ADDR_ANY;
src_addr = IP6_ADDR_ANY6;
} else {
/* Use link-local address as source address. */
src_addr = netif_ip6_addr(group->netif, 0);

View File

@ -840,7 +840,7 @@ nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags)
/* Use link-local address as source address. */
src_addr = netif_ip6_addr(netif, 0);
} else {
src_addr = IP6_ADDR_ANY;
src_addr = IP6_ADDR_ANY6;
}
/* Allocate a packet. */
@ -882,7 +882,7 @@ nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags)
/* Send the packet out. */
ND6_STATS_INC(nd6.xmit);
ip6_output_if(p, (src_addr == IP6_ADDR_ANY) ? NULL : src_addr, target_addr,
ip6_output_if(p, (src_addr == IP6_ADDR_ANY6) ? NULL : src_addr, target_addr,
LWIP_ICMP6_HL, 0, IP6_NEXTH_ICMP6, netif);
pbuf_free(p);
}
@ -984,14 +984,14 @@ nd6_send_rs(struct netif * netif)
src_addr = netif_ip6_addr(netif, 0);
}
else {
src_addr = IP6_ADDR_ANY;
src_addr = IP6_ADDR_ANY6;
}
/* Generate the all routers target address. */
ip6_addr_set_allrouters_linklocal(&multicast_address);
/* Allocate a packet. */
if (src_addr != IP6_ADDR_ANY) {
if (src_addr != IP6_ADDR_ANY6) {
lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0);
}
p = pbuf_alloc(PBUF_IP, sizeof(struct rs_header) + (lladdr_opt_len << 3), PBUF_RAM);
@ -1012,7 +1012,7 @@ nd6_send_rs(struct netif * netif)
rs_hdr->chksum = 0;
rs_hdr->reserved = 0;
if (src_addr != IP6_ADDR_ANY) {
if (src_addr != IP6_ADDR_ANY6) {
/* Include our hw address. */
lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct rs_header));
lladdr_opt->type = ND6_OPTION_TYPE_SOURCE_LLADDR;

View File

@ -93,14 +93,8 @@ static void netif_issue_reports(struct netif* netif, u8_t report_type);
static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
#endif /* LWIP_IPV6 */
#if LWIP_IPV6
#define ipX_input(in, netif) (IP6H_V((const struct ip6_hdr *)in->payload) == 6) ? ip6_input(in, netif) : ip_input(in, netif)
#else
#define ipX_input(in, netif) ip_input(in, netif)
#endif
#if LWIP_HAVE_LOOPIF
static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip_addr_t* addr);
static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr);
#if LWIP_IPV6
static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* addr);
#endif
@ -137,7 +131,7 @@ void
netif_init(void)
{
#if LWIP_HAVE_LOOPIF
ip_addr_t loop_ipaddr, loop_netmask, loop_gw;
ip4_addr_t loop_ipaddr, loop_netmask, loop_gw;
IP4_ADDR(&loop_gw, 127,0,0,1);
IP4_ADDR(&loop_ipaddr, 127,0,0,1);
IP4_ADDR(&loop_netmask, 255,0,0,0);
@ -176,8 +170,13 @@ netif_init(void)
* @return netif, or NULL if failed.
*/
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)
netif_add(struct netif *netif,
#if LWIP_IPV4
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
#else /* LWIP_IPV4 */
const void *ipaddr, const void *netmask, const void *gw,
#endif /* LWIP_IPV4 */
void *state, netif_init_fn init, netif_input_fn input)
{
#if LWIP_IPV6
u32_t i;
@ -186,9 +185,11 @@ netif_add(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask
LWIP_ASSERT("No init function given", init != NULL);
/* reset new interface configuration state */
ip_addr_set_zero(&netif->ip_addr);
ip_addr_set_zero(&netif->netmask);
ip_addr_set_zero(&netif->gw);
#if LWIP_IPV4
ip4_addr_set_zero(&netif->ip_addr);
ip4_addr_set_zero(&netif->netmask);
ip4_addr_set_zero(&netif->gw);
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
ip6_addr_set_zero(&netif->ip6_addr[i]);
@ -242,7 +243,9 @@ netif_add(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask
netif->loop_cnt_current = 0;
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
#if LWIP_IPV4
netif_set_addr(netif, ipaddr, netmask, gw);
#endif /* LWIP_IPV4 */
/* call user specified initialization function for netif */
if (init(netif) != ERR_OK) {
@ -261,17 +264,21 @@ netif_add(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask
}
#endif /* LWIP_IGMP */
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP",
netif->name[0], netif->name[1]));
ip_addr_debug_print(NETIF_DEBUG, ipaddr);
#if LWIP_IPV4
LWIP_DEBUGF(NETIF_DEBUG, (" addr "));
ip4_addr_debug_print(NETIF_DEBUG, ipaddr);
LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
ip_addr_debug_print(NETIF_DEBUG, netmask);
ip4_addr_debug_print(NETIF_DEBUG, netmask);
LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
ip_addr_debug_print(NETIF_DEBUG, gw);
ip4_addr_debug_print(NETIF_DEBUG, gw);
#endif /* LWIP_IPV4 */
LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
return netif;
}
#if LWIP_IPV4
/**
* Change IP address configuration for a network interface (including netmask
* and default gateway).
@ -282,14 +289,15 @@ netif_add(struct netif *netif, const ip_addr_t *ipaddr, const ip_addr_t *netmask
* @param gw the new default gateway
*/
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)
{
netif_set_netmask(netif, netmask);
netif_set_gw(netif, gw);
/* set ipaddr last to ensure netmask/gw have been set when status callback is called */
netif_set_ipaddr(netif, ipaddr);
}
#endif /* LWIP_IPV4*/
/**
* Remove a network interface from the list of lwIP netifs.
@ -303,7 +311,8 @@ netif_remove(struct netif *netif)
return;
}
if (!ip_addr_isany(&netif->ip_addr)) {
#if LWIP_IPV4
if (!ip4_addr_isany(&netif->ip_addr)) {
#if LWIP_TCP
tcp_netif_ipv4_addr_changed(&netif->ip_addr, NULL);
#endif /* LWIP_TCP */
@ -316,6 +325,8 @@ netif_remove(struct netif *netif)
igmp_stop(netif);
}
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4*/
#if LWIP_IPV6 && LWIP_IPV6_MLD
/* stop MLD processing */
mld6_stop(netif);
@ -387,6 +398,7 @@ netif_find(char *name)
return NULL;
}
#if LWIP_IPV4
/**
* Change the IP address of a network interface
*
@ -397,11 +409,11 @@ netif_find(char *name)
* default gateway
*/
void
netif_set_ipaddr(struct netif *netif, const ip_addr_t *ipaddr)
netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
{
ip_addr_t new_addr = (ipaddr ? *ipaddr : *IP_ADDR_ANY);
ip4_addr_t new_addr = (ipaddr ? *ipaddr : *IP4_ADDR_ANY);
/* address is actually being changed? */
if (ip_addr_cmp(&new_addr, &(netif->ip_addr)) == 0) {
if (ip4_addr_cmp(&new_addr, &(netif->ip_addr)) == 0) {
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
#if LWIP_TCP
tcp_netif_ipv4_addr_changed(&netif->ip_addr, ipaddr);
@ -413,7 +425,7 @@ netif_set_ipaddr(struct netif *netif, const ip_addr_t *ipaddr)
snmp_delete_ipaddridx_tree(netif);
snmp_delete_iprteidx_tree(0, netif);
/* set new IP address to netif */
ip_addr_set(&(netif->ip_addr), ipaddr);
ip4_addr_set(&(netif->ip_addr), ipaddr);
snmp_insert_ipaddridx_tree(netif);
snmp_insert_iprteidx_tree(0, netif);
@ -439,9 +451,9 @@ netif_set_ipaddr(struct netif *netif, const ip_addr_t *ipaddr)
* @note call netif_set_addr() if you also want to change ip address and netmask
*/
void
netif_set_gw(struct netif *netif, const ip_addr_t *gw)
netif_set_gw(struct netif *netif, const ip4_addr_t *gw)
{
ip_addr_set(&(netif->gw), gw);
ip4_addr_set(&(netif->gw), gw);
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1],
ip4_addr1_16(&netif->gw),
@ -460,11 +472,11 @@ netif_set_gw(struct netif *netif, const ip_addr_t *gw)
* default gateway
*/
void
netif_set_netmask(struct netif *netif, const ip_addr_t *netmask)
netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask)
{
snmp_delete_iprteidx_tree(0, netif);
/* set new netmask to netif */
ip_addr_set(&(netif->netmask), netmask);
ip4_addr_set(&(netif->netmask), netmask);
snmp_insert_iprteidx_tree(0, netif);
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1],
@ -473,6 +485,7 @@ netif_set_netmask(struct netif *netif, const ip_addr_t *netmask)
ip4_addr3_16(&netif->netmask),
ip4_addr4_16(&netif->netmask)));
}
#endif /* LWIP_IPV4 */
/**
* Set a network interface as the default network interface
@ -526,8 +539,9 @@ void netif_set_up(struct netif *netif)
static void
netif_issue_reports(struct netif* netif, u8_t report_type)
{
#if LWIP_IPV4
if ((report_type & NETIF_REPORT_TYPE_IPV4) &&
!ip_addr_isany(&netif->ip_addr)) {
!ip4_addr_isany(&netif->ip_addr)) {
#if LWIP_ARP
/* For Ethernet network interfaces, we would like to send a "gratuitous ARP" */
if (netif->flags & (NETIF_FLAG_ETHARP)) {
@ -542,6 +556,7 @@ netif_issue_reports(struct netif* netif, u8_t report_type)
}
#endif /* LWIP_IGMP */
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
if (report_type & NETIF_REPORT_TYPE_IPV6) {
@ -573,11 +588,11 @@ void netif_set_down(struct netif *netif)
snmp_get_sysuptime(&netif->ts);
#endif
#if LWIP_ARP
#if LWIP_IPV4 && LWIP_ARP
if (netif->flags & NETIF_FLAG_ETHARP) {
etharp_cleanup_netif(netif);
}
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 && LWIP_ARP */
NETIF_STATUS_CALLBACK(netif);
}
}
@ -751,12 +766,14 @@ netif_loop_output(struct netif *netif, struct pbuf *p)
return ERR_OK;
}
#if LWIP_IPV4
static err_t
netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip_addr_t* addr)
netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t* addr)
{
LWIP_UNUSED_ARG(addr);
return netif_loop_output(netif, p);
}
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
static err_t
@ -831,7 +848,7 @@ netif_poll(struct netif *netif)
snmp_add_ifinoctets(stats_if, in->tot_len);
snmp_inc_ifinucastpkts(stats_if);
/* loopback packets are always IP packets! */
if (ipX_input(in, netif) != ERR_OK) {
if (ip_input(in, netif) != ERR_OK) {
pbuf_free(in);
}
/* Don't reference the packet any more! */

View File

@ -136,7 +136,7 @@ pbuf_free_ooseq(void)
#if !NO_SYS
/**
* Just a callback function for tcpip_timeout() that calls pbuf_free_ooseq().
* Just a callback function for tcpip_callback() that calls pbuf_free_ooseq().
*/
static void
pbuf_free_ooseq_callback(void *arg)

View File

@ -78,24 +78,28 @@ u8_t
raw_input(struct pbuf *p, struct netif *inp)
{
struct raw_pcb *pcb, *prev;
struct ip_hdr *iphdr;
s16_t proto;
u8_t eaten = 0;
LWIP_UNUSED_ARG(inp);
iphdr = (struct ip_hdr *)p->payload;
#if LWIP_IPV6
if (IPH_V(iphdr) == 6) {
#if LWIP_IPV4
if (IP_HDR_GET_VERSION(p->payload) == 6)
#endif /* LWIP_IPV4 */
{
struct ip6_hdr *ip6hdr = (struct ip6_hdr *)p->payload;
proto = IP6H_NEXTH(ip6hdr);
iphdr = NULL;
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
proto = IPH_PROTO(iphdr);
proto = IPH_PROTO((struct ip_hdr *)p->payload);
}
#endif /* LWIP_IPV4 */
prev = NULL;
pcb = raw_pcbs;
@ -103,8 +107,8 @@ raw_input(struct pbuf *p, struct netif *inp)
/* this allows multiple pcbs to match against the packet by design */
while ((eaten == 0) && (pcb != NULL)) {
if ((pcb->protocol == proto) && IP_PCB_IPVER_INPUT_MATCH(pcb) &&
(ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->local_ip) ||
ipX_addr_cmp(PCB_ISIPV6(pcb), &(pcb->local_ip), ipX_current_dest_addr()))) {
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr()))) {
#if IP_SOF_BROADCAST_RECV
/* broadcast filter? */
if ((ip_get_option(pcb, SOF_BROADCAST) || !ip_addr_isbroadcast(ip_current_dest_addr(), inp))
@ -115,19 +119,12 @@ raw_input(struct pbuf *p, struct netif *inp)
#endif /* IP_SOF_BROADCAST_RECV */
{
/* receive callback function available? */
if (pcb->recv.ip4 != NULL) {
if (pcb->recv != NULL) {
#ifndef LWIP_NOASSERT
void* old_payload = p->payload;
#endif
/* the receive callback function did not eat the packet? */
#if LWIP_IPV6
if (PCB_ISIPV6(pcb)) {
eaten = pcb->recv.ip6(pcb->recv_arg, pcb, p, ip6_current_src_addr());
} else
#endif /* LWIP_IPV6 */
{
eaten = pcb->recv.ip4(pcb->recv_arg, pcb, p, ip_current_src_addr());
}
eaten = pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr());
if (eaten != 0) {
/* receive function ate the packet */
p = NULL;
@ -172,7 +169,10 @@ raw_input(struct pbuf *p, struct netif *inp)
err_t
raw_bind(struct raw_pcb *pcb, const ip_addr_t *ipaddr)
{
ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->local_ip, ipaddr);
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
return ERR_OK;
}
@ -192,11 +192,13 @@ raw_bind(struct raw_pcb *pcb, const ip_addr_t *ipaddr)
err_t
raw_connect(struct raw_pcb *pcb, const ip_addr_t *ipaddr)
{
ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->remote_ip, ipaddr);
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
return ERR_OK;
}
/**
* Set the callback function for received packets that match the
* raw PCB's protocol and binding.
@ -214,7 +216,7 @@ void
raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
{
/* remember recv() callback and user data */
pcb->recv.ip4 = recv;
pcb->recv = recv;
pcb->recv_arg = recv_arg;
}
@ -235,18 +237,28 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
{
err_t err;
struct netif *netif;
ipX_addr_t *src_ip;
ip_addr_t *src_ip;
struct pbuf *q; /* q will be sent down the stack */
s16_t header_size;
const ipX_addr_t *dst_ip = ip_2_ipX(ipaddr);
const ip_addr_t *dst_ip = ipaddr;
#if LWIP_IPV4 && LWIP_IPV6
ip_addr_t src_ip_tmp;
#endif /* LWIP_IPV4 && LWIP_IPV6 */
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
header_size = (
#if LWIP_IPV6
PCB_ISIPV6(pcb) ? IP6_HLEN :
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
PCB_ISIPV6(pcb) ? IP6_HLEN : IP_HLEN);
#elif LWIP_IPV4
IP_HLEN);
#else
IP6_HLEN);
#endif
/* not enough space to add an IP header to first pbuf in given p chain? */
if (pbuf_header(p, header_size)) {
@ -272,10 +284,10 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
}
}
netif = ipX_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip);
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip);
if (netif == NULL) {
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, dst_ip);
ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, dst_ip);
/* free any temporary header pbuf allocated by pbuf_header() */
if (q != p) {
pbuf_free(q);
@ -300,9 +312,9 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
}
#endif /* IP_SOF_BROADCAST */
if (ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->local_ip)) {
if (ip_addr_isany(&pcb->local_ip)) {
/* use outgoing network interface IP address as source address */
src_ip = ipX_netif_get_local_ipX(PCB_ISIPV6(pcb), netif, dst_ip);
src_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, dst_ip, &src_ip_tmp);
#if LWIP_IPV6
if (src_ip == NULL) {
if (q != p) {
@ -320,14 +332,14 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
/* If requested, based on the IPV6_CHECKSUM socket option per RFC3542,
compute the checksum and update the checksum in the payload. */
if (PCB_ISIPV6(pcb) && pcb->chksum_reqd) {
u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ipX_2_ip6(src_ip), ipX_2_ip6(dst_ip));
u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip));
LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2));
SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t));
}
#endif
NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
err = ipX_output_if(PCB_ISIPV6(pcb), q, ipX_2_ip(src_ip), ipX_2_ip(dst_ip), pcb->ttl, pcb->tos, pcb->protocol, netif);
err = ip_output_if(PCB_ISIPV6(pcb), q, src_ip, dst_ip, pcb->ttl, pcb->tos, pcb->protocol, netif);
NETIF_SET_HWADDRHINT(netif, NULL);
/* did we chain a header earlier? */
@ -348,7 +360,7 @@ 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)
{
return raw_sendto(pcb, p, ipX_2_ip(&pcb->remote_ip));
return raw_sendto(pcb, p, &pcb->remote_ip);
}
/**
@ -427,7 +439,9 @@ raw_new_ip6(u8_t proto)
{
struct raw_pcb *pcb;
pcb = raw_new(proto);
#if LWIP_IPV4
ip_set_v6(pcb, 1);
#endif /* LWIP_IPV4 */
return pcb;
}
#endif /* LWIP_IPV6 */

View File

@ -1055,7 +1055,7 @@ void snmp_dec_iflist(void)
* Inserts ARP table indexes (.xIfIndex.xNetAddress)
* into arp table index trees (both atTable and ipNetToMediaTable).
*/
void snmp_insert_arpidx_tree(struct netif *ni, ip_addr_t *ip)
void snmp_insert_arpidx_tree(struct netif *ni, ip4_addr_t *ip)
{
struct mib_list_rootnode *at_rn;
struct mib_list_node *at_node;
@ -1127,7 +1127,7 @@ void snmp_insert_arpidx_tree(struct netif *ni, ip_addr_t *ip)
* Removes ARP table indexes (.xIfIndex.xNetAddress)
* from arp table index trees.
*/
void snmp_delete_arpidx_tree(struct netif *ni, ip_addr_t *ip)
void snmp_delete_arpidx_tree(struct netif *ni, ip4_addr_t *ip)
{
struct mib_list_rootnode *at_rn, *next, *del_rn[5];
struct mib_list_node *at_n, *del_n[5];
@ -1408,20 +1408,20 @@ void snmp_delete_ipaddridx_tree(struct netif *ni)
void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
{
u8_t insert = 0;
ip_addr_t dst;
ip4_addr_t dst;
if (dflt != 0)
{
/* the default route 0.0.0.0 */
ip_addr_set_any(&dst);
ip4_addr_set_any(&dst);
insert = 1;
}
else
{
/* route to the network address */
ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
ip4_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
/* exclude 0.0.0.0 network (reserved for default rte) */
if (!ip_addr_isany(&dst)) {
if (!ip4_addr_isany(&dst)) {
insert = 1;
}
}
@ -1485,20 +1485,20 @@ void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
{
u8_t del = 0;
ip_addr_t dst;
ip4_addr_t dst;
if (dflt != 0)
{
/* the default route 0.0.0.0 */
ip_addr_set_any(&dst);
ip4_addr_set_any(&dst);
del = 1;
}
else
{
/* route to the network address */
ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
ip4_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
/* exclude 0.0.0.0 network (reserved for default rte) */
if (!ip_addr_isany(&dst)) {
if (!ip4_addr_isany(&dst)) {
del = 1;
}
}
@ -1766,7 +1766,11 @@ void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
u8_t level;
LWIP_ASSERT("pcb != NULL", pcb != NULL);
snmp_iptooid(ipX_2_ip(&pcb->local_ip), &udpidx[0]);
if (IP_IS_V6(&pcb->local_ip)) {
/* @todo: support IPv6: .udpLocalAddress.udpLocalPort is DEPRECATED */
return;
}
snmp_iptooid(ip_2_ip4(&pcb->local_ip), &udpidx[0]);
udpidx[4] = pcb->local_port;
udp_rn = &udp_root;
@ -1819,7 +1823,11 @@ void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
u8_t bindings, fc, level, del_cnt;
LWIP_ASSERT("pcb != NULL", pcb != NULL);
snmp_iptooid(ipX_2_ip(&pcb->local_ip), &udpidx[0]);
if (IP_IS_V6(&pcb->local_ip)) {
/* @todo: support IPv6: .udpLocalAddress.udpLocalPort is DEPRECATED */
return;
}
snmp_iptooid(ip_2_ip4(&pcb->local_ip), &udpidx[0]);
udpidx[4] = pcb->local_port;
/* count PCBs for a given binding
@ -1828,7 +1836,7 @@ void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
npcb = udp_pcbs;
while ((npcb != NULL))
{
if (ipX_addr_cmp(0, &npcb->local_ip, &pcb->local_ip) &&
if (ip_addr_cmp(&npcb->local_ip, &pcb->local_ip) &&
(npcb->local_port == udpidx[4]))
{
bindings++;
@ -2704,18 +2712,18 @@ atentry_get_value(struct obj_def *od, u16_t len, void *value)
#if LWIP_ARP
u8_t id;
struct eth_addr* ethaddr_ret;
const ip_addr_t* ipaddr_ret;
#endif /* LWIP_ARP */
ip_addr_t ip;
const ip4_addr_t* ipaddr_ret;
ip4_addr_t ip;
struct netif *netif;
#endif /* LWIP_ARP */
LWIP_UNUSED_ARG(len);
LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
#if LWIP_ARP /** @todo implement a netif_find_addr */
snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
snmp_oidtoip(&od->id_inst_ptr[2], &ip);
#if LWIP_ARP /** @todo implement a netif_find_addr */
if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
{
LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
@ -2737,7 +2745,7 @@ atentry_get_value(struct obj_def *od, u16_t len, void *value)
break;
case 3: /* atNetAddress */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
*dst = *ipaddr_ret;
}
@ -3061,13 +3069,13 @@ ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
u16_t ifidx;
ip_addr_t ip;
ip4_addr_t ip;
struct netif *netif = netif_list;
LWIP_UNUSED_ARG(len);
snmp_oidtoip(&od->id_inst_ptr[1], &ip);
ifidx = 0;
while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
while ((netif != NULL) && !ip4_addr_cmp(&ip, &netif->ip_addr))
{
netif = netif->next;
ifidx++;
@ -3081,7 +3089,7 @@ ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
{
case 1: /* ipAdEntAddr */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
*dst = netif->ip_addr;
}
break;
@ -3093,7 +3101,7 @@ ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
break;
case 3: /* ipAdEntNetMask */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
*dst = netif->netmask;
}
break;
@ -3204,14 +3212,14 @@ static void
ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
{
struct netif *netif;
ip_addr_t dest;
ip4_addr_t dest;
s32_t *ident;
u8_t id;
ident = od->id_inst_ptr;
snmp_oidtoip(&ident[1], &dest);
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* ip_route() uses default netif for default route */
netif = netif_default;
@ -3221,7 +3229,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
/* not using ip_route(), need exact match! */
netif = netif_list;
while ((netif != NULL) &&
!ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
!ip4_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
{
netif = netif->next;
}
@ -3234,17 +3242,17 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
{
case 1: /* ipRouteDest */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* default rte has 0.0.0.0 dest */
ip_addr_set_zero(dst);
ip4_addr_set_zero(dst);
}
else
{
/* netifs have netaddress dest */
ip_addr_get_network(dst, &netif->ip_addr, &netif->netmask);
ip4_addr_get_network(dst, &netif->ip_addr, &netif->netmask);
}
}
break;
@ -3259,7 +3267,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
{
s32_t *sint_ptr = (s32_t*)value;
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* default rte has metric 1 */
*sint_ptr = 1;
@ -3283,9 +3291,9 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
break;
case 7: /* ipRouteNextHop */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* default rte: gateway */
*dst = netif->gw;
@ -3301,7 +3309,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
{
s32_t *sint_ptr = (s32_t*)value;
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* default rte is indirect */
*sint_ptr = 4;
@ -3330,12 +3338,12 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
break;
case 11: /* ipRouteMask */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
if (ip_addr_isany(&dest))
if (ip4_addr_isany(&dest))
{
/* default rte use 0.0.0.0 mask */
ip_addr_set_zero(dst);
ip4_addr_set_zero(dst);
}
else
{
@ -3410,9 +3418,9 @@ ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
#if LWIP_ARP
u8_t id;
struct eth_addr* ethaddr_ret;
const ip_addr_t* ipaddr_ret;
const ip4_addr_t* ipaddr_ret;
#endif /* LWIP_ARP */
ip_addr_t ip;
ip4_addr_t ip;
struct netif *netif;
LWIP_UNUSED_ARG(len);
@ -3443,7 +3451,7 @@ ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
break;
case 3: /* ipNetToMediaNetAddress */
{
ip_addr_t *dst = (ip_addr_t*)value;
ip4_addr_t *dst = (ip4_addr_t*)value;
*dst = *ipaddr_ret;
}
@ -3889,17 +3897,18 @@ udpentry_get_value(struct obj_def *od, u16_t len, void *value)
{
u8_t id;
struct udp_pcb *pcb;
ipX_addr_t ip;
ip_addr_t ip;
u16_t port;
LWIP_UNUSED_ARG(len);
snmp_oidtoip(&od->id_inst_ptr[1], (ip_addr_t*)&ip);
snmp_oidtoip(&od->id_inst_ptr[1], ip_2_ip4(&ip));
IP_SET_TYPE(&ip, IPADDR_TYPE_V4);
LWIP_ASSERT("invalid port", (od->id_inst_ptr[5] >= 0) && (od->id_inst_ptr[5] <= 0xffff));
port = (u16_t)od->id_inst_ptr[5];
pcb = udp_pcbs;
while ((pcb != NULL) &&
!(ipX_addr_cmp(0, &pcb->local_ip, &ip) &&
!(ip_addr_cmp(&pcb->local_ip, &ip) &&
(pcb->local_port == port)))
{
pcb = pcb->next;
@ -3913,8 +3922,8 @@ udpentry_get_value(struct obj_def *od, u16_t len, void *value)
{
case 1: /* udpLocalAddress */
{
ipX_addr_t *dst = (ipX_addr_t*)value;
ipX_addr_copy(0, *dst, pcb->local_ip);
ip4_addr_t *dst = (ip4_addr_t*)value;
ip4_addr_copy(*dst, *(ip_2_ip4(&pcb->local_ip)));
}
break;
case 2: /* udpLocalPort */

View File

@ -134,7 +134,7 @@ snmp_netiftoifindex(struct netif *netif, s32_t *ifidx)
* @param ip points to output struct
*/
void
snmp_oidtoip(s32_t *ident, ip_addr_t *ip)
snmp_oidtoip(s32_t *ident, ip4_addr_t *ip)
{
IP4_ADDR(ip, ident[0], ident[1], ident[2], ident[3]);
}
@ -145,7 +145,7 @@ snmp_oidtoip(s32_t *ident, ip_addr_t *ip)
* @param ident points to s32_t ident[4] output
*/
void
snmp_iptooid(ip_addr_t *ip, s32_t *ident)
snmp_iptooid(ip4_addr_t *ip, s32_t *ident)
{
ident[0] = ip4_addr1(ip);
ident[1] = ip4_addr2(ip);

View File

@ -226,7 +226,10 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
{
struct snmp_trap_dst *td;
struct netif *dst_if;
ip_addr_t dst_ip;
#if LWIP_IPV4 && LWIP_IPV6
ip_addr_t dst_ip_storage;
#endif /* LWIP_IPV4 && LWIP_IPV6 */
ip_addr_t* dst_ip;
struct pbuf *p;
u16_t i,tot_len;
err_t err = ERR_OK;
@ -238,14 +241,11 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
/* network order trap destination */
ip_addr_copy(trap_msg.dip, td->dip);
/* lookup current source address for this dst */
dst_if = ip_route(&td->dip);
if (dst_if != NULL) {
ip_addr_copy(dst_ip, dst_if->ip_addr);
/* @todo: what about IPv6? */
trap_msg.sip_raw[0] = ip4_addr1(&dst_ip);
trap_msg.sip_raw[1] = ip4_addr2(&dst_ip);
trap_msg.sip_raw[2] = ip4_addr3(&dst_ip);
trap_msg.sip_raw[3] = ip4_addr4(&dst_ip);
ip_route_get_local_ip(PCB_ISIPV6(trap_msg.pcb), &trap_msg.pcb->local_ip,
&td->dip, dst_if, dst_ip, &dst_ip_storage);
if ((dst_if != NULL) && (dst_ip != NULL)) {
trap_msg.sip_raw_len = (IP_IS_V6_L(dst_ip) ? 16 : 4);
memcpy(trap_msg.sip_raw, dst_ip, trap_msg.sip_raw_len);
trap_msg.gen_trap = generic_trap;
trap_msg.spc_trap = specific_trap;
if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC)
@ -392,7 +392,7 @@ snmp_trap_header_sum(struct snmp_msg_trap *m_trap, u16_t vb_len)
snmp_asn1_enc_length_cnt(thl->gtrplen, &thl->gtrplenlen);
tot_len += 1 + thl->gtrplen + thl->gtrplenlen;
thl->aaddrlen = 4;
thl->aaddrlen = m_trap->sip_raw_len;
snmp_asn1_enc_length_cnt(thl->aaddrlen, &thl->aaddrlenlen);
tot_len += 1 + thl->aaddrlen + thl->aaddrlenlen;

View File

@ -183,7 +183,7 @@ tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
/* don't call tcp_abort here: we must not deallocate the pcb since
that might not be expected when calling tcp_close */
tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
pcb->local_port, pcb->remote_port, PCB_ISIPV6(pcb));
pcb->local_port, pcb->remote_port);
tcp_pcb_purge(pcb);
TCP_RMV_ACTIVE(pcb);
@ -403,7 +403,7 @@ tcp_abandon(struct tcp_pcb *pcb, int reset)
#endif /* TCP_QUEUE_OOSEQ */
if (send_rst) {
LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n"));
tcp_rst(seqno, ackno, &pcb->local_ip, &pcb->remote_ip, pcb->local_port, pcb->remote_port, PCB_ISIPV6(pcb));
tcp_rst(seqno, ackno, &pcb->local_ip, &pcb->remote_ip, pcb->local_port, pcb->remote_port);
}
memp_free(MEMP_TCP_PCB, pcb);
TCP_EVENT_ERR(errf, errf_arg, ERR_ABRT);
@ -481,9 +481,9 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
{
/* @todo: check accept_any_ip_version */
if (IP_PCB_IPVER_EQ(pcb, cpcb) &&
(ipX_addr_isany(PCB_ISIPV6(pcb), &cpcb->local_ip) ||
ipX_addr_isany(PCB_ISIPV6(pcb), ip_2_ipX(ipaddr)) ||
ipX_addr_cmp(PCB_ISIPV6(pcb), &cpcb->local_ip, ip_2_ipX(ipaddr)))) {
(ip_addr_isany(&cpcb->local_ip) ||
ip_addr_isany(ipaddr) ||
ip_addr_cmp(&cpcb->local_ip, ipaddr))) {
return ERR_USE;
}
}
@ -491,8 +491,8 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
}
}
if (!ipX_addr_isany(PCB_ISIPV6(pcb), ip_2_ipX(ipaddr))) {
ipX_addr_set(PCB_ISIPV6(pcb), &pcb->local_ip, ip_2_ipX(ipaddr));
if (!ip_addr_isany(ipaddr)) {
ip_addr_set(&pcb->local_ip, ipaddr);
}
pcb->local_port = port;
TCP_REG(&tcp_bound_pcbs, pcb);
@ -548,7 +548,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if ((lpcb->local_port == pcb->local_port) &&
IP_PCB_IPVER_EQ(pcb, lpcb)) {
if (ipX_addr_cmp(PCB_ISIPV6(pcb), &lpcb->local_ip, &pcb->local_ip)) {
if (ip_addr_cmp(&lpcb->local_ip, &pcb->local_ip)) {
/* this address/port is already used */
return NULL;
}
@ -567,11 +567,11 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
lpcb->so_options = pcb->so_options;
lpcb->ttl = pcb->ttl;
lpcb->tos = pcb->tos;
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
PCB_ISIPV6(lpcb) = PCB_ISIPV6(pcb);
lpcb->accept_any_ip_version = 0;
#endif /* LWIP_IPV6 */
ipX_addr_copy(PCB_ISIPV6(pcb), lpcb->local_ip, pcb->local_ip);
#endif /* LWIP_IPV4 && LWIP_IPV6 */
ip_addr_copy(lpcb->local_ip, pcb->local_ip);
if (pcb->local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb);
}
@ -587,7 +587,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
return (struct tcp_pcb *)lpcb;
}
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
/**
* Same as tcp_listen_with_backlog, but allows to accept IPv4 and IPv6
* connections, if the pcb's local address is set to ANY.
@ -611,7 +611,7 @@ tcp_listen_dual_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
lpcb = tcp_listen_with_backlog(pcb, backlog);
if ((lpcb != NULL) &&
ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->local_ip)) {
ip_addr_isany(&pcb->local_ip)) {
/* The default behavior is to accept connections on either
* IPv4 or IPv6, if not bound. */
/* @see NETCONN_FLAG_IPV6_V6ONLY for changing this behavior */
@ -619,7 +619,7 @@ tcp_listen_dual_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
}
return lpcb;
}
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
/**
* Update the state that tracks the available window space to advertise.
@ -749,30 +749,33 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
err_t ret;
u32_t iss;
u16_t old_local_port;
#if LWIP_IPV4 && LWIP_IPV6
ip_addr_t local_ip_tmp;
#endif /* LWIP_IPV4 && LWIP_IPV6 */
LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
if (ipaddr != NULL) {
ipX_addr_set(PCB_ISIPV6(pcb), &pcb->remote_ip, ip_2_ipX(ipaddr));
ip_addr_set(&pcb->remote_ip, ipaddr);
} else {
return ERR_VAL;
}
pcb->remote_port = port;
/* check if we have a route to the remote host */
if (ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->local_ip)) {
if (ip_addr_isany(&pcb->local_ip)) {
/* no local IP address set, yet. */
struct netif *netif;
ipX_addr_t *local_ip;
ipX_route_get_local_ipX(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip);
ip_addr_t *local_ip;
ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip, &local_ip_tmp);
if ((netif == NULL) || (local_ip == NULL)) {
/* Don't even try to send a SYN packet if we have no route
since that will fail. */
return ERR_RTE;
}
/* Use the address as local address of the pcb. */
ipX_addr_copy(PCB_ISIPV6(pcb), pcb->local_ip, *local_ip);
ip_addr_copy(pcb->local_ip, *local_ip);
}
old_local_port = pcb->local_port;
@ -794,8 +797,8 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
if ((cpcb->local_port == pcb->local_port) &&
(cpcb->remote_port == port) &&
IP_PCB_IPVER_EQ(cpcb, pcb) &&
ipX_addr_cmp(PCB_ISIPV6(pcb), &cpcb->local_ip, &pcb->local_ip) &&
ipX_addr_cmp(PCB_ISIPV6(pcb), &cpcb->remote_ip, ip_2_ipX(ipaddr))) {
ip_addr_cmp(&cpcb->local_ip, &pcb->local_ip) &&
ip_addr_cmp(&cpcb->remote_ip, ipaddr)) {
/* linux returns EISCONN here, but ERR_USE should be OK for us */
return ERR_USE;
}
@ -968,7 +971,7 @@ tcp_slowtmr_start:
(pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL)
{
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
ip_addr_debug_print(TCP_DEBUG, &pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
++pcb_remove;
@ -1032,7 +1035,7 @@ tcp_slowtmr_start:
if (pcb_reset) {
tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
pcb->local_port, pcb->remote_port, PCB_ISIPV6(pcb));
pcb->local_port, pcb->remote_port);
}
err_fn = pcb->errf;
@ -1543,7 +1546,9 @@ tcp_new_ip6(void)
{
struct tcp_pcb * pcb;
pcb = tcp_alloc(TCP_PRIO_NORMAL);
#if LWIP_IPV4
ip_set_v6(pcb, 1);
#endif /* LWIP_IPV4 */
return pcb;
}
#endif /* LWIP_IPV6 */
@ -1667,8 +1672,8 @@ tcp_pcb_purge(struct tcp_pcb *pcb)
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if ((lpcb->local_port == pcb->local_port) &&
IP_PCB_IPVER_EQ(pcb, lpcb) &&
(ipX_addr_isany(PCB_ISIPV6(lpcb), &lpcb->local_ip) ||
ipX_addr_cmp(PCB_ISIPV6(lpcb), &pcb->local_ip, &lpcb->local_ip))) {
(ip_addr_isany(&lpcb->local_ip) ||
ip_addr_cmp(&pcb->local_ip, &lpcb->local_ip))) {
/* port and address of the listen pcb match the timed-out pcb */
LWIP_ASSERT("tcp_pcb_purge: listen pcb does not have accepts pending",
lpcb->accepts_pending > 0);
@ -1769,9 +1774,12 @@ tcp_next_iss(void)
* calculating the minimum of TCP_MSS and that netif's mtu (if set).
*/
u16_t
tcp_eff_send_mss_impl(u16_t sendmss, ipX_addr_t *dest
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 */
)
{
@ -1779,28 +1787,45 @@ tcp_eff_send_mss_impl(u16_t sendmss, ipX_addr_t *dest
struct netif *outif;
s16_t mtu;
outif = ipX_route(isipv6, src, dest);
outif = ip_route(isipv6, src, dest);
#if LWIP_IPV6
if (isipv6) {
#if LWIP_IPV4
if (isipv6)
#endif /* LWIP_IPV4 */
{
/* First look in destination cache, to see if there is a Path MTU. */
mtu = nd6_get_destination_mtu(ipX_2_ip6(dest), outif);
} else
mtu = nd6_get_destination_mtu(ip_2_ip6(dest), outif);
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
if (outif == NULL) {
return sendmss;
}
mtu = outif->mtu;
}
#endif /* LWIP_IPV4 */
if (mtu != 0) {
mss_s = mtu - IP_HLEN - TCP_HLEN;
#if LWIP_IPV6
if (isipv6) {
/* for IPv6, subtract the difference in header size */
mss_s -= (IP6_HLEN - IP_HLEN);
#if LWIP_IPV4
if (isipv6)
#endif /* LWIP_IPV4 */
{
mss_s = mtu - IP6_HLEN - TCP_HLEN;
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
mss_s = mtu - IP_HLEN - TCP_HLEN;
}
#endif /* LWIP_IPV4 */
/* RFC 1122, chap 4.2.2.6:
* Eff.snd.MSS = min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize
* We correct for TCP options in tcp_write(), and don't support IP options.
@ -1811,18 +1836,19 @@ tcp_eff_send_mss_impl(u16_t sendmss, ipX_addr_t *dest
}
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
#if LWIP_IPV4
/** Helper function for tcp_netif_ipv4_addr_changed() that iterates a pcb list */
static void
tcp_netif_ipv4_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb_list)
tcp_netif_ipv4_addr_changed_pcblist(const ip4_addr_t* old_addr, struct tcp_pcb* pcb_list)
{
struct tcp_pcb *pcb;
pcb = pcb_list;
while (pcb != NULL) {
/* PCB bound to current local interface address? */
if (ip_addr_cmp(ipX_2_ip(&pcb->local_ip), old_addr)
if (!IP_IS_V6_L(&pcb->local_ip) && ip4_addr_cmp(ip_2_ip4(&pcb->local_ip), old_addr)
#if LWIP_AUTOIP
/* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
&& !ip_addr_islinklocal(ipX_2_ip(&pcb->local_ip))
&& !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip))
#endif /* LWIP_AUTOIP */
) {
/* this connection must be aborted */
@ -1841,27 +1867,31 @@ tcp_netif_ipv4_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* p
* @param old_addr IPv4 address of the netif before change
* @param new_addr IPv4 address of the netif after change or NULL if netif has been removed
*/
void tcp_netif_ipv4_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr)
void tcp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr)
{
struct tcp_pcb_listen *lpcb, *next;
tcp_netif_ipv4_addr_changed_pcblist(old_addr, tcp_active_pcbs);
tcp_netif_ipv4_addr_changed_pcblist(old_addr, tcp_bound_pcbs);
if (!ip_addr_isany(new_addr)) {
if (!ip4_addr_isany(new_addr)) {
/* PCB bound to current local interface address? */
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = next) {
next = lpcb->next;
/* PCB bound to current local interface address? */
if ((!(ip_addr_isany(ipX_2_ip(&lpcb->local_ip)))) &&
(ip_addr_cmp(ipX_2_ip(&lpcb->local_ip), old_addr))) {
/* The PCB is listening to the old ipaddr and
* is set to listen to the new one instead */
ip_addr_set(ipX_2_ip(&lpcb->local_ip), new_addr);
}
/* Is this an IPv4 pcb? */
if (!IP_IS_V6_L(&lpcb->local_ip)) {
/* PCB bound to current local interface address? */
if ((!(ip4_addr_isany(ip_2_ip4(&lpcb->local_ip)))) &&
(ip4_addr_cmp(ip_2_ip4(&lpcb->local_ip), old_addr))) {
/* The PCB is listening to the old ipaddr and
* is set to listen to the new one instead */
ip_addr_copy_from_ip4(lpcb->local_ip, *new_addr);
}
}
}
}
}
#endif /* LWIP_IPV4 */
const char*
tcp_debug_state_str(enum tcp_state s)

View File

@ -112,6 +112,8 @@ tcp_input(struct pbuf *p, struct netif *inp)
u16_t chksum;
#endif /* CHECKSUM_CHECK_TCP */
LWIP_UNUSED_ARG(inp);
PERF_START;
TCP_STATS_INC(tcp.recv);
@ -132,16 +134,19 @@ tcp_input(struct pbuf *p, struct netif *inp)
}
/* Don't even process incoming broadcasts/multicasts. */
if ((!ip_current_is_v6() && ip_addr_isbroadcast(ip_current_dest_addr(), inp)) ||
ipX_addr_ismulticast(ip_current_is_v6(), ipX_current_dest_addr())) {
if (
#if LWIP_IPV4
(!ip_current_is_v6() && ip_addr_isbroadcast(ip_current_dest_addr(), inp)) ||
#endif /* LWIP_IPV4 */
ip_addr_ismulticast(ip_current_dest_addr())) {
TCP_STATS_INC(tcp.proterr);
goto dropped;
}
#if CHECKSUM_CHECK_TCP
/* Verify TCP checksum. */
chksum = ipX_chksum_pseudo(ip_current_is_v6(), p, IP_PROTO_TCP, p->tot_len,
ipX_current_src_addr(), ipX_current_dest_addr());
chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
ip_current_src_addr(), ip_current_dest_addr());
if (chksum != 0) {
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to failing checksum 0x%04"X16_F"\n",
chksum));
@ -210,9 +215,8 @@ tcp_input(struct pbuf *p, struct netif *inp)
LWIP_ASSERT("tcp_input: active pcb->state != LISTEN", pcb->state != LISTEN);
if (pcb->remote_port == tcphdr->src &&
pcb->local_port == tcphdr->dest &&
IP_PCB_IPVER_INPUT_MATCH(pcb) &&
ipX_addr_cmp(ip_current_is_v6(), &pcb->remote_ip, ipX_current_src_addr()) &&
ipX_addr_cmp(ip_current_is_v6(),&pcb->local_ip, ipX_current_dest_addr())) {
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()) &&
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
/* Move this PCB to the front of the list so that subsequent
lookups will be faster (we exploit locality in TCP segment
arrivals). */
@ -235,9 +239,8 @@ tcp_input(struct pbuf *p, struct netif *inp)
LWIP_ASSERT("tcp_input: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
if (pcb->remote_port == tcphdr->src &&
pcb->local_port == tcphdr->dest &&
IP_PCB_IPVER_INPUT_MATCH(pcb) &&
ipX_addr_cmp(ip_current_is_v6(), &pcb->remote_ip, ipX_current_src_addr()) &&
ipX_addr_cmp(ip_current_is_v6(),&pcb->local_ip, ipX_current_dest_addr())) {
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()) &&
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
/* We don't really care enough to move this PCB to the front
of the list since we are not very likely to receive that
many segments for connections in TIME-WAIT. */
@ -253,7 +256,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
prev = NULL;
for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if (lpcb->local_port == tcphdr->dest) {
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
if (lpcb->accept_any_ip_version) {
/* found an ANY-match */
#if SO_REUSE
@ -263,12 +266,12 @@ tcp_input(struct pbuf *p, struct netif *inp)
break;
#endif /* SO_REUSE */
} else
#endif /* LWIP_IPV6 */
#endif /* LWIP_IPV4 && LWIP_IPV6 */
if (IP_PCB_IPVER_INPUT_MATCH(lpcb)) {
if (ipX_addr_cmp(ip_current_is_v6(), &lpcb->local_ip, ipX_current_dest_addr())) {
if (ip_addr_cmp(&lpcb->local_ip, ip_current_dest_addr())) {
/* found an exact match */
break;
} else if (ipX_addr_isany(ip_current_is_v6(), &lpcb->local_ip)) {
} else if (ip_addr_isany(&lpcb->local_ip)) {
/* found an ANY-match */
#if SO_REUSE
lpcb_any = lpcb;
@ -497,8 +500,8 @@ aborted:
if (!(TCPH_FLAGS(tcphdr) & TCP_RST)) {
TCP_STATS_INC(tcp.proterr);
TCP_STATS_INC(tcp.drop);
tcp_rst(ackno, seqno + tcplen, ipX_current_dest_addr(),
ipX_current_src_addr(), tcphdr->dest, tcphdr->src, ip_current_is_v6());
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(),
ip_current_src_addr(), tcphdr->dest, tcphdr->src);
}
pbuf_free(p);
}
@ -541,8 +544,8 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
/* For incoming segments with the ACK flag set, respond with a
RST. */
LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_listen_input: ACK in LISTEN, sending reset\n"));
tcp_rst(ackno, seqno + tcplen, ipX_current_dest_addr(),
ipX_current_src_addr(), tcphdr->dest, tcphdr->src, ip_current_is_v6());
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(),
ip_current_src_addr(), tcphdr->dest, tcphdr->src);
} else if (flags & TCP_SYN) {
LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest));
#if TCP_LISTEN_BACKLOG
@ -564,11 +567,11 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
pcb->accepts_pending++;
#endif /* TCP_LISTEN_BACKLOG */
/* Set up the new PCB. */
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
PCB_ISIPV6(npcb) = ip_current_is_v6();
#endif /* LWIP_IPV6 */
ipX_addr_copy(ip_current_is_v6(), npcb->local_ip, *ipX_current_dest_addr());
ipX_addr_copy(ip_current_is_v6(), npcb->remote_ip, *ipX_current_src_addr());
#endif /* LWIP_IPV4 && LWIP_IPV6 */
ip_addr_copy(npcb->local_ip, *ip_current_dest_addr());
ip_addr_copy(npcb->remote_ip, *ip_current_src_addr());
npcb->local_port = pcb->local_port;
npcb->remote_port = tcphdr->src;
npcb->state = SYN_RCVD;
@ -635,8 +638,8 @@ tcp_timewait_input(struct tcp_pcb *pcb)
should be sent in reply */
if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt, pcb->rcv_nxt+pcb->rcv_wnd)) {
/* If the SYN is in the window it is an error, send a reset */
tcp_rst(ackno, seqno + tcplen, ipX_current_dest_addr(),
ipX_current_src_addr(), tcphdr->dest, tcphdr->src, ip_current_is_v6());
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(),
ip_current_src_addr(), tcphdr->dest, tcphdr->src);
return ERR_OK;
}
} else if (flags & TCP_FIN) {
@ -773,8 +776,8 @@ tcp_process(struct tcp_pcb *pcb)
/* received ACK? possibly a half-open connection */
else if (flags & TCP_ACK) {
/* send a RST to bring the other side in a non-synchronized state. */
tcp_rst(ackno, seqno + tcplen, ipX_current_dest_addr(),
ipX_current_src_addr(), tcphdr->dest, tcphdr->src, ip_current_is_v6());
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(),
ip_current_src_addr(), tcphdr->dest, tcphdr->src);
}
break;
case SYN_RCVD:
@ -817,8 +820,8 @@ tcp_process(struct tcp_pcb *pcb)
}
} else {
/* incorrect ACK number, send RST */
tcp_rst(ackno, seqno + tcplen, ipX_current_dest_addr(),
ipX_current_src_addr(), tcphdr->dest, tcphdr->src, ip_current_is_v6());
tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(),
ip_current_src_addr(), tcphdr->dest, tcphdr->src);
}
} else if ((flags & TCP_SYN) && (seqno == pcb->rcv_nxt - 1)) {
/* Looks like another copy of the SYN - retransmit our SYN-ACK */

View File

@ -931,14 +931,14 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
#endif
#if CHECKSUM_GEN_TCP
tcphdr->chksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), p, IP_PROTO_TCP, p->tot_len,
tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
&pcb->local_ip, &pcb->remote_ip);
#endif
#if LWIP_NETIF_HWADDRHINT
err = ipX_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos,
err = ip_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos,
IP_PROTO_TCP, &pcb->addr_hint);
#else /* LWIP_NETIF_HWADDRHINT*/
err = ipX_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos,
err = ip_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos,
IP_PROTO_TCP);
#endif /* LWIP_NETIF_HWADDRHINT*/
pbuf_free(p);
@ -1186,14 +1186,16 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
/* If we don't have a local IP address, we get one by
calling ip_route(). */
if (ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->local_ip)) {
if (ip_addr_isany(&pcb->local_ip)) {
struct netif *netif;
ipX_addr_t *local_ip;
ipX_route_get_local_ipX(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip);
ip_addr_t *local_ip;
ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip, &pcb->local_ip);
if ((netif == NULL) || (local_ip == NULL)) {
return ERR_RTE;
}
ipX_addr_copy(PCB_ISIPV6(pcb), pcb->local_ip, *local_ip);
#if !LWIP_IPV4 || !LWIP_IPV6
ip_addr_copy(pcb->local_ip, *local_ip);
#endif /* !LWIP_IPV4 || !LWIP_IPV6 */
}
if (pcb->rttest == 0) {
@ -1218,7 +1220,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
{
u32_t acc;
#if TCP_CHECKSUM_ON_COPY_SANITY_CHECK
u16_t chksum_slow = ipX_chksum_pseudo(PCB_ISIPV6(pcb), seg->p, IP_PROTO_TCP,
u16_t chksum_slow = ip_chksum_pseudo(seg->p, IP_PROTO_TCP,
seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip);
#endif /* TCP_CHECKSUM_ON_COPY_SANITY_CHECK */
if ((seg->flags & TF_SEG_DATA_CHECKSUMMED) == 0) {
@ -1227,7 +1229,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
}
/* rebuild TCP header checksum (TCP header changes for retransmissions!) */
acc = ipX_chksum_pseudo_partial(PCB_ISIPV6(pcb), seg->p, IP_PROTO_TCP,
acc = ip_chksum_pseudo_partial(seg->p, IP_PROTO_TCP,
seg->p->tot_len, TCPH_HDRLEN(seg->tcphdr) * 4, &pcb->local_ip, &pcb->remote_ip);
/* add payload checksum */
if (seg->chksum_swapped) {
@ -1247,17 +1249,17 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
}
#else /* TCP_CHECKSUM_ON_COPY */
#if CHECKSUM_GEN_TCP
seg->tcphdr->chksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), seg->p, IP_PROTO_TCP,
seg->tcphdr->chksum = ip_chksum_pseudo(seg->p, IP_PROTO_TCP,
seg->p->tot_len, &pcb->local_ip, &pcb->remote_ip);
#endif /* CHECKSUM_GEN_TCP */
#endif /* TCP_CHECKSUM_ON_COPY */
TCP_STATS_INC(tcp.xmit);
#if LWIP_NETIF_HWADDRHINT
err = ipX_output_hinted(PCB_ISIPV6(pcb), seg->p, &pcb->local_ip, &pcb->remote_ip,
err = ip_output_hinted(PCB_ISIPV6(pcb), seg->p, &pcb->local_ip, &pcb->remote_ip,
pcb->ttl, pcb->tos, IP_PROTO_TCP, &pcb->addr_hint);
#else /* LWIP_NETIF_HWADDRHINT*/
err = ipX_output(PCB_ISIPV6(pcb), seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
err = ip_output(PCB_ISIPV6(pcb), seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
pcb->tos, IP_PROTO_TCP);
#endif /* LWIP_NETIF_HWADDRHINT*/
return err;
@ -1284,13 +1286,9 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
* @param remote_port the remote TCP port to send the segment to
*/
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 */
)
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)
{
struct pbuf *p;
struct tcp_hdr *tcphdr;
@ -1320,11 +1318,11 @@ tcp_rst_impl(u32_t seqno, u32_t ackno,
snmp_inc_tcpoutrsts();
#if CHECKSUM_GEN_TCP
tcphdr->chksum = ipX_chksum_pseudo(isipv6, p, IP_PROTO_TCP, p->tot_len,
tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
local_ip, remote_ip);
#endif
/* Send output with hardcoded TTL/HL since we have no access to the pcb */
ipX_output(isipv6, p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP);
ip_output(IP_IS_V6(remote_ip), p, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP);
pbuf_free(p);
LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno));
}
@ -1476,7 +1474,7 @@ tcp_keepalive(struct tcp_pcb *pcb)
#endif /* CHECKSUM_GEN_TCP */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
ip_addr_debug_print(TCP_DEBUG, &pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n",
@ -1491,17 +1489,17 @@ tcp_keepalive(struct tcp_pcb *pcb)
#if CHECKSUM_GEN_TCP
tcphdr = (struct tcp_hdr *)p->payload;
tcphdr->chksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), p, IP_PROTO_TCP, p->tot_len,
tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
&pcb->local_ip, &pcb->remote_ip);
#endif /* CHECKSUM_GEN_TCP */
TCP_STATS_INC(tcp.xmit);
/* Send output to IP */
#if LWIP_NETIF_HWADDRHINT
err = ipX_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip,
err = ip_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip,
pcb->ttl, 0, IP_PROTO_TCP, &pcb->addr_hint);
#else /* LWIP_NETIF_HWADDRHINT*/
err = ipX_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
err = ip_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
0, IP_PROTO_TCP);
#endif /* LWIP_NETIF_HWADDRHINT*/
@ -1532,7 +1530,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
u8_t is_fin;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: sending ZERO WINDOW probe to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
ip_addr_debug_print(TCP_DEBUG, &pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
LWIP_DEBUGF(TCP_DEBUG,
@ -1574,17 +1572,17 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
}
#if CHECKSUM_GEN_TCP
tcphdr->chksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), p, IP_PROTO_TCP, p->tot_len,
tcphdr->chksum = ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len,
&pcb->local_ip, &pcb->remote_ip);
#endif
TCP_STATS_INC(tcp.xmit);
/* Send output to IP */
#if LWIP_NETIF_HWADDRHINT
err = ipX_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
err = ip_output_hinted(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl,
0, IP_PROTO_TCP, &pcb->addr_hint);
#else /* LWIP_NETIF_HWADDRHINT*/
err = ipX_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
err = ip_output(PCB_ISIPV6(pcb), p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP);
#endif /* LWIP_NETIF_HWADDRHINT*/
pbuf_free(p);

View File

@ -111,6 +111,7 @@ tcp_timer_needed(void)
}
#endif /* LWIP_TCP */
#if LWIP_IPV4
#if IP_REASSEMBLY
/**
* Timer callback function that calls ip_reass_tmr() and reschedules itself.
@ -204,6 +205,7 @@ igmp_timer(void *arg)
sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
}
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 */
#if LWIP_DNS
/**
@ -272,6 +274,7 @@ mld6_timer(void *arg)
/** Initialize this module */
void sys_timeouts_init(void)
{
#if LWIP_IPV4
#if IP_REASSEMBLY
sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
#endif /* IP_REASSEMBLY */
@ -288,6 +291,7 @@ void sys_timeouts_init(void)
#if LWIP_IGMP
sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 */
#if LWIP_DNS
sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
#endif /* LWIP_DNS */

View File

@ -180,11 +180,7 @@ udp_input(struct pbuf *p, struct netif *inp)
udphdr = (struct udp_hdr *)p->payload;
/* is broadcast packet ? */
#if LWIP_IPV6
broadcast = !ip_current_is_v6() && ip_addr_isbroadcast(ip_current_dest_addr(), inp);
#else /* LWIP_IPV6 */
broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), inp);
#endif /* LWIP_IPV6 */
LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len));
@ -196,9 +192,9 @@ udp_input(struct pbuf *p, struct netif *inp)
/* print the UDP source and destination */
LWIP_DEBUGF(UDP_DEBUG, ("udp ("));
ipX_addr_debug_print(ip_current_is_v6(), UDP_DEBUG, ipX_current_dest_addr());
ip_addr_debug_print(UDP_DEBUG, ip_current_dest_addr());
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", ntohs(udphdr->dest)));
ipX_addr_debug_print(ip_current_is_v6(), UDP_DEBUG, ipX_current_src_addr());
ip_addr_debug_print(UDP_DEBUG, ip_current_src_addr());
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", ntohs(udphdr->src)));
#if LWIP_DHCP
@ -213,8 +209,8 @@ udp_input(struct pbuf *p, struct netif *inp)
(- broadcast or directed to us) -> DHCP is link-layer-addressed, local ip is always ANY!
- inp->dhcp->pcb->remote == ANY or iphdr->src
(no need to check for IPv6 since the dhcp struct always uses IPv4) */
if (ipX_addr_isany(0, &inp->dhcp->pcb->remote_ip) ||
ip_addr_cmp(ipX_2_ip(&(inp->dhcp->pcb->remote_ip)), ip_current_src_addr())) {
if (ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
ip_addr_cmp(&inp->dhcp->pcb->remote_ip, ip_current_src_addr())) {
pcb = inp->dhcp->pcb;
}
}
@ -233,9 +229,9 @@ udp_input(struct pbuf *p, struct netif *inp)
local_match = 0;
/* print the PCB local and remote address */
LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG, &pcb->local_ip);
ip_addr_debug_print(UDP_DEBUG, &pcb->local_ip);
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG, &pcb->remote_ip);
ip_addr_debug_print(UDP_DEBUG, &pcb->remote_ip);
LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
/* compare PCB local addr+port to UDP destination addr+port */
@ -243,29 +239,29 @@ udp_input(struct pbuf *p, struct netif *inp)
if (
#if LWIP_IPV6
((PCB_ISIPV6(pcb) && (ip_current_is_v6()) &&
(ip6_addr_isany(ipX_2_ip6(&pcb->local_ip)) ||
(ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
#if LWIP_IPV6_MLD
ip6_addr_ismulticast(ip6_current_dest_addr()) ||
#endif /* LWIP_IPV6_MLD */
ip6_addr_cmp(ipX_2_ip6(&pcb->local_ip), ip6_current_dest_addr()))) ||
ip6_addr_cmp(ip_2_ip6(&pcb->local_ip), ip6_current_dest_addr()))) ||
(!PCB_ISIPV6(pcb) &&
(ip_current_header() != NULL) &&
(ip4_current_header() != NULL) &&
#else /* LWIP_IPV6 */
((
#endif /* LWIP_IPV6 */
((!broadcast && ipX_addr_isany(0, &pcb->local_ip)) ||
ip_addr_cmp(ipX_2_ip(&pcb->local_ip), ip_current_dest_addr()) ||
((!broadcast && ip_addr_isany(&pcb->local_ip)) ||
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr()) ||
#if LWIP_IGMP
ip_addr_ismulticast(ip_current_dest_addr()) ||
#endif /* LWIP_IGMP */
#if IP_SOF_BROADCAST_RECV
(broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
(ipX_addr_isany(0, &pcb->local_ip) ||
ip_addr_netcmp(ipX_2_ip(&pcb->local_ip), ip_current_dest_addr(), &inp->netmask))))))) {
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask))))))) {
#else /* IP_SOF_BROADCAST_RECV */
(broadcast &&
(ipX_addr_isany(0, &pcb->local_ip) ||
ip_addr_netcmp(ipX_2_ip(&pcb->local_ip), ip_current_dest_addr(), &inp->netmask))))))) {
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask))))))) {
#endif /* IP_SOF_BROADCAST_RECV */
local_match = 1;
if ((uncon_pcb == NULL) &&
@ -278,8 +274,8 @@ udp_input(struct pbuf *p, struct netif *inp)
/* compare PCB remote addr+port to UDP source addr+port */
if ((local_match != 0) &&
(pcb->remote_port == src) && IP_PCB_IPVER_INPUT_MATCH(pcb) &&
(ipX_addr_isany(PCB_ISIPV6(pcb), &pcb->remote_ip) ||
ipX_addr_cmp(PCB_ISIPV6(pcb), &pcb->remote_ip, ipX_current_src_addr()))) {
(ip_addr_isany(&pcb->remote_ip) ||
ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
/* the first fully matching PCB */
if (prev != NULL) {
/* move the pcb to the front of udp_pcbs so that is
@ -307,11 +303,16 @@ udp_input(struct pbuf *p, struct netif *inp)
#if LWIP_IPV6
if (ip_current_is_v6()) {
for_us = netif_get_ip6_addr_match(inp, ip6_current_dest_addr()) >= 0;
} else
#endif /* LWIP_IPV6 */
{
for_us = ip_addr_cmp(&inp->ip_addr, ip_current_dest_addr());
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
for_us = ip4_addr_cmp(&inp->ip_addr, ip4_current_dest_addr());
}
#endif /* LWIP_IPV4 */
}
if (for_us) {
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_input: calculating checksum\n"));
@ -331,18 +332,18 @@ udp_input(struct pbuf *p, struct netif *inp)
goto chkerr;
}
}
if (ipX_chksum_pseudo_partial(ip_current_is_v6(), p, IP_PROTO_UDPLITE,
if (ip_chksum_pseudo_partial(p, IP_PROTO_UDPLITE,
p->tot_len, chklen,
ipX_current_src_addr(), ipX_current_dest_addr()) != 0) {
ip_current_src_addr(), ip_current_dest_addr()) != 0) {
goto chkerr;
}
} else
#endif /* LWIP_UDPLITE */
{
if (udphdr->chksum != 0) {
if (ipX_chksum_pseudo(ip_current_is_v6(), p, IP_PROTO_UDP, p->tot_len,
ipX_current_src_addr(),
ipX_current_dest_addr()) != 0) {
if (ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len,
ip_current_src_addr(),
ip_current_dest_addr()) != 0) {
goto chkerr;
}
}
@ -377,13 +378,13 @@ udp_input(struct pbuf *p, struct netif *inp)
#if LWIP_IPV6
((PCB_ISIPV6(mpcb) &&
(ip6_addr_ismulticast(ip6_current_dest_addr()) ||
ip6_addr_cmp(ipX_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
ip6_addr_cmp(ip_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
(!PCB_ISIPV6(mpcb) &&
#else /* LWIP_IPV6 */
((
#endif /* LWIP_IPV6 */
((!broadcast && ipX_addr_isany(0, &mpcb->local_ip)) ||
ip_addr_cmp(ipX_2_ip(&mpcb->local_ip), ip_current_dest_addr()) ||
((!broadcast && ip_addr_isany(&mpcb->local_ip)) ||
ip_addr_cmp(&mpcb->local_ip, ip_current_dest_addr()) ||
#if LWIP_IGMP
ip_addr_ismulticast(ip_current_dest_addr()) ||
#endif /* LWIP_IGMP */
@ -393,7 +394,7 @@ udp_input(struct pbuf *p, struct netif *inp)
(broadcast))))) {
#endif /* IP_SOF_BROADCAST_RECV */
/* pass a copy of the packet to all local matches */
if (mpcb->recv.ip4 != NULL) {
if (mpcb->recv != NULL) {
struct pbuf *q;
/* for that, move payload to IP header again */
if (p_header_changed == 0) {
@ -406,15 +407,7 @@ udp_input(struct pbuf *p, struct netif *inp)
if (err == ERR_OK) {
/* move payload to UDP data */
pbuf_header(q, -hdrs_len);
#if LWIP_IPV6
if (PCB_ISIPV6(mpcb)) {
mpcb->recv.ip6(mpcb->recv_arg, mpcb, q, ip6_current_src_addr(), src);
}
else
#endif /* LWIP_IPV6 */
{
mpcb->recv.ip4(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
}
mpcb->recv(mpcb->recv_arg, mpcb, q, ip_current_src_addr(), src);
}
}
}
@ -428,17 +421,9 @@ udp_input(struct pbuf *p, struct netif *inp)
}
#endif /* SO_REUSE && SO_REUSE_RXTOALL */
/* callback */
if (pcb->recv.ip4 != NULL) {
if (pcb->recv != NULL) {
/* now the recv function is responsible for freeing p */
#if LWIP_IPV6
if (PCB_ISIPV6(pcb)) {
pcb->recv.ip6(pcb->recv_arg, pcb, p, ip6_current_src_addr(), src);
}
else
#endif /* LWIP_IPV6 */
{
pcb->recv.ip4(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
}
pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
} else {
/* no recv function registered? then we have to free the pbuf! */
pbuf_free(p);
@ -450,11 +435,17 @@ udp_input(struct pbuf *p, struct netif *inp)
#if LWIP_ICMP || LWIP_ICMP6
/* No match was found, send ICMP destination port unreachable unless
destination address was broadcast/multicast. */
if (!broadcast &&
if (
#if LWIP_IPV4
!broadcast && !ip_addr_ismulticast(ip_current_dest_addr())
#if LWIP_IPV6
!ip6_addr_ismulticast(ip6_current_dest_addr()) &&
&&
#endif /* LWIP_IPV6 */
!ip_addr_ismulticast(ip_current_dest_addr())) {
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
!ip6_addr_ismulticast(ip6_current_dest_addr())
#endif /* LWIP_IPV6 */
) {
/* move payload pointer back to ip header */
pbuf_header_force(p, ip_current_header_tot_len() + UDP_HLEN);
icmp_port_unreach(ip_current_is_v6(), p);
@ -505,7 +496,7 @@ err_t
udp_send(struct udp_pcb *pcb, struct pbuf *p)
{
/* send to the packet using remote ip and port stored in the pcb */
return udp_sendto(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port);
return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
}
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
@ -516,7 +507,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
u8_t have_chksum, u16_t chksum)
{
/* send to the packet using remote ip and port stored in the pcb */
return udp_sendto_chksum(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port,
return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
have_chksum, chksum);
}
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
@ -553,12 +544,15 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
{
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
struct netif *netif;
const ipX_addr_t *dst_ip_route = ip_2_ipX(dst_ip);
const ip_addr_t *dst_ip_route = dst_ip;
#if LWIP_IPV6 && LWIP_IPV4 && LWIP_IGMP
ip_addr_t dst_ip_tmp;
#endif /* LWIP_IPV6 && LWIP_IPV4 && LWIP_IGMP */
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send\n"));
#if LWIP_IPV6 || LWIP_IGMP
if (ipX_addr_ismulticast(PCB_ISIPV6(pcb), dst_ip_route)) {
#if LWIP_IPV6 || (LWIP_IPV4 && LWIP_IGMP)
if (ip_addr_ismulticast(dst_ip_route)) {
#if LWIP_IPV6
if (PCB_ISIPV6(pcb)) {
/* For multicast, find a netif based on source address. */
@ -566,27 +560,27 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
} else
#endif /* LWIP_IPV6 */
{
#if LWIP_IGMP
#if LWIP_IPV4 && LWIP_IGMP
/* IPv4 does not use source-based routing by default, so we use an
administratively selected interface for multicast by default.
However, this can be overridden by setting an interface address
in pcb->multicast_ip that is used for routing. */
if (!ip_addr_isany(&pcb->multicast_ip) &&
!ip_addr_cmp(&pcb->multicast_ip, IP_ADDR_BROADCAST)) {
dst_ip_route = ip_2_ipX(&pcb->multicast_ip);
if (!ip4_addr_isany(&pcb->multicast_ip) &&
!ip4_addr_cmp(&pcb->multicast_ip, IP4_ADDR_BROADCAST)) {
dst_ip_route = ip4_2_ip(&pcb->multicast_ip, &dst_ip_tmp);
}
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 && LWIP_IGMP */
}
}
#endif /* LWIP_IPV6 || LWIP_IGMP */
/* find the outgoing network interface for this packet */
netif = ipX_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip_route);
netif = ip_route(PCB_ISIPV6(pcb), &pcb->local_ip, dst_ip_route);
/* no outgoing network interface could be found? */
if (netif == NULL) {
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ip_2_ipX(dst_ip));
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, dst_ip);
LWIP_DEBUGF(UDP_DEBUG, ("\n"));
UDP_STATS_INC(udp.rterr);
return ERR_RTE;
@ -633,40 +627,47 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_i
{
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
const ip_addr_t *src_ip;
#if LWIP_IPV6 && LWIP_IPV4
ip_addr_t src_ip_tmp;
#endif /* LWIP_IPV6 && LWIP_IPV4 */
/* PCB local address is IP_ANY_ADDR? */
#if LWIP_IPV6
if (PCB_ISIPV6(pcb)) {
if (ip6_addr_isany(ipX_2_ip6(&pcb->local_ip))) {
src_ip = ip6_2_ip(ip6_select_source_address(netif, ip_2_ip6(dst_ip)));
if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip))) {
src_ip = ip6_2_ip(ip6_select_source_address(netif, ip_2_ip6(dst_ip)), &src_ip_tmp);
if (src_ip == NULL) {
/* No suitable source address was found. */
return ERR_RTE;
}
} else {
/* use UDP PCB local IPv6 address as source address, if still valid. */
if (netif_get_ip6_addr_match(netif, ipX_2_ip6(&pcb->local_ip)) < 0) {
if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
/* Address isn't valid anymore. */
return ERR_RTE;
}
src_ip = ipX_2_ip(&pcb->local_ip);
src_ip = &pcb->local_ip;
}
}
else
#endif /* LWIP_IPV6 */
if (ip_addr_isany(ipX_2_ip(&pcb->local_ip))) {
#if LWIP_IPV4 && LWIP_IPV6
else
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_IPV4
if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip))) {
/* use outgoing network interface IP address as source address */
src_ip = &(netif->ip_addr);
src_ip = ip4_2_ip(&netif->ip_addr, &src_ip_tmp);
} else {
/* check if UDP PCB local IP address is correct
* this could be an old address if netif->ip_addr has changed */
if (!ip_addr_cmp(ipX_2_ip(&(pcb->local_ip)), &(netif->ip_addr))) {
if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), &(netif->ip_addr))) {
/* local_ip doesn't match, drop the packet */
return ERR_VAL;
}
/* use UDP PCB local IP address as source address */
src_ip = ipX_2_ip(&(pcb->local_ip));
src_ip = &pcb->local_ip;
}
#endif /* LWIP_IPV4 */
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
@ -696,7 +697,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
u8_t ip_proto;
u8_t ttl;
#if IP_SOF_BROADCAST
#if LWIP_IPV4 && IP_SOF_BROADCAST
/* broadcast filter? */
if (!ip_get_option(pcb, SOF_BROADCAST) &&
#if LWIP_IPV6
@ -707,12 +708,12 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
return ERR_VAL;
}
#endif /* IP_SOF_BROADCAST */
#endif /* LWIP_IPV4 && IP_SOF_BROADCAST */
/* if the PCB is not yet bound to a port, bind it here */
if (pcb->local_port == 0) {
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_send: not yet bound to a port, binding now\n"));
err = udp_bind(pcb, ipX_2_ip(&pcb->local_ip), pcb->local_port);
err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
if (err != ERR_OK) {
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: forced port bind failed\n"));
return err;
@ -748,25 +749,14 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
udphdr->src = htons(pcb->local_port);
udphdr->dest = htons(dst_port);
/* in UDP, 0 checksum means 'no checksum' */
udphdr->chksum = 0x0000;
udphdr->chksum = 0x0000;
/* Multicast Loop? */
#if LWIP_IGMP
if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) &&
#if LWIP_IPV6
(
#if LWIP_IPV6_MLD
(PCB_ISIPV6(pcb) &&
ip6_addr_ismulticast(ip_2_ip6(dst_ip))) ||
#endif /* LWIP_IPV6_MLD */
(!PCB_ISIPV6(pcb) &&
#else /* LWIP_IPV6 */
((
#endif /* LWIP_IPV6 */
ip_addr_ismulticast(dst_ip)))) {
#if (LWIP_IPV4 && LWIP_IGMP) || (LWIP_IPV6 && LWIP_IPV6_MLD)
if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
q->flags |= PBUF_FLAG_MCASTLOOP;
}
#endif /* LWIP_IGMP */
#endif /* (LWIP_IPV4 && LWIP_IGMP) || (LWIP_IPV6 && LWIP_IPV6_MLD) */
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: sending datagram of length %"U16_F"\n", q->tot_len));
@ -798,8 +788,8 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
chklen = UDP_HLEN;
}
#endif /* LWIP_CHECKSUM_ON_COPY */
udphdr->chksum = ipX_chksum_pseudo_partial(PCB_ISIPV6(pcb), q, IP_PROTO_UDPLITE,
q->tot_len, chklen, ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
udphdr->chksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDPLITE,
q->tot_len, chklen, src_ip, dst_ip);
#if LWIP_CHECKSUM_ON_COPY
if (have_chksum) {
u32_t acc;
@ -828,15 +818,15 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
#if LWIP_CHECKSUM_ON_COPY
if (have_chksum) {
u32_t acc;
udpchksum = ipX_chksum_pseudo_partial(PCB_ISIPV6(pcb), q, IP_PROTO_UDP,
q->tot_len, UDP_HLEN, ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
udpchksum = ip_chksum_pseudo_partial(q, IP_PROTO_UDP,
q->tot_len, UDP_HLEN, src_ip, dst_ip);
acc = udpchksum + (u16_t)~(chksum);
udpchksum = FOLD_U32T(acc);
} else
#endif /* LWIP_CHECKSUM_ON_COPY */
{
udpchksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), q, IP_PROTO_UDP, q->tot_len,
ip_2_ipX(src_ip), ip_2_ipX(dst_ip));
udpchksum = ip_chksum_pseudo(q, IP_PROTO_UDP, q->tot_len,
src_ip, dst_ip);
}
/* chksum zero must become 0xffff, as zero means 'no checksum' */
@ -860,7 +850,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d
LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto));
/* output to IP */
NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint));
err = ipX_output_if_src(PCB_ISIPV6(pcb), q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
err = ip_output_if_src(PCB_ISIPV6(pcb), q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
NETIF_SET_HWADDRHINT(netif, NULL);
/* TODO: must this be increased even if error occurred? */
@ -904,7 +894,7 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
u8_t rebind;
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, ("udp_bind(ipaddr = "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE, ip_2_ipX(ipaddr));
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE, ipaddr);
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE, (", port = %"U16_F")\n", port));
rebind = 0;
@ -930,9 +920,9 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
#endif /* SO_REUSE */
if ((ipcb->local_port == port) && IP_PCB_IPVER_EQ(pcb, ipcb) &&
/* IP address matches, or one is IP_ADDR_ANY? */
(ipX_addr_isany(PCB_ISIPV6(ipcb), &(ipcb->local_ip)) ||
ipX_addr_isany(PCB_ISIPV6(ipcb), ip_2_ipX(ipaddr)) ||
ipX_addr_cmp(PCB_ISIPV6(ipcb), &(ipcb->local_ip), ip_2_ipX(ipaddr)))) {
(ip_addr_isany(&ipcb->local_ip) ||
ip_addr_isany(ipaddr) ||
ip_addr_cmp(&ipcb->local_ip, ipaddr))) {
/* other PCB already binds to this local IP and port */
LWIP_DEBUGF(UDP_DEBUG,
("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
@ -941,7 +931,7 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
}
}
ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->local_ip, ipaddr);
ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
/* no port specified? */
if (port == 0) {
@ -961,7 +951,7 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
udp_pcbs = pcb;
}
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_bind: bound to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, &pcb->local_ip);
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, &pcb->local_ip);
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
return ERR_OK;
}
@ -989,13 +979,13 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
struct udp_pcb *ipcb;
if (pcb->local_port == 0) {
err_t err = udp_bind(pcb, ipX_2_ip(&pcb->local_ip), pcb->local_port);
err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
if (err != ERR_OK) {
return err;
}
}
ipX_addr_set_ipaddr(PCB_ISIPV6(pcb), &pcb->remote_ip, ipaddr);
ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
pcb->remote_port = port;
pcb->flags |= UDP_FLAGS_CONNECTED;
/** TODO: this functionality belongs in upper layers */
@ -1005,27 +995,26 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
#endif /* LWIP_IPV6 */
{
/* Nail down local IP for netconn_addr()/getsockname() */
if (ip_addr_isany(ipX_2_ip(&pcb->local_ip)) && !ip_addr_isany(ipX_2_ip(&pcb->remote_ip))) {
if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
struct netif *netif;
if ((netif = ip_route(ipX_2_ip(&pcb->remote_ip))) == NULL) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n",
ip4_addr_get_u32(ipX_2_ip(&pcb->remote_ip))));
if ((netif = ip_route(PCB_ISIPV6(pcb), (const ip_addr_t*)NULL, &pcb->remote_ip)) == NULL) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to %s\n", ipaddr_ntoa(&pcb->remote_ip)));
UDP_STATS_INC(udp.rterr);
return ERR_RTE;
}
/** TODO: this will bind the udp pcb locally, to the interface which
is used to route output packets to the remote address. However, we
might want to accept incoming packets on any interface! */
ipX_addr_copy(0, pcb->local_ip, netif->ip_addr);
} else if (ip_addr_isany(ipX_2_ip(&pcb->remote_ip))) {
ipX_addr_set_any(0, &pcb->local_ip);
ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip, &pcb->local_ip);
} else if (ip_addr_isany(&pcb->remote_ip)) {
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->local_ip);
}
}
#endif
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("udp_connect: connected to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
&pcb->remote_ip);
ip_addr_debug_print(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
&pcb->remote_ip);
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
/* Insert UDP PCB into the list of active UDP PCBs. */
@ -1050,7 +1039,7 @@ void
udp_disconnect(struct udp_pcb *pcb)
{
/* reset remote address association */
ipX_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
pcb->remote_port = 0;
/* mark PCB as unconnected */
pcb->flags &= ~UDP_FLAGS_CONNECTED;
@ -1069,7 +1058,7 @@ void
udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
{
/* remember recv() callback and user data */
pcb->recv.ip4 = recv;
pcb->recv = recv;
pcb->recv_arg = recv_arg;
}
@ -1146,32 +1135,39 @@ udp_new_ip6(void)
{
struct udp_pcb *pcb;
pcb = udp_new();
#if LWIP_IPV4
ip_set_v6(pcb, 1);
#endif /* LWIP_IPV4 */
return pcb;
}
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
/** This function is called from netif.c when address is changed
*
* @param old_addr IPv4 address of the netif before change
* @param new_addr IPv4 address of the netif after change
*/
void udp_netif_ipv4_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr)
void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr)
{
struct udp_pcb* upcb;
if (!ip_addr_isany(new_addr)) {
if (!ip4_addr_isany(new_addr)) {
for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) {
/* PCB bound to current local interface address? */
if ((!(ip_addr_isany(ipX_2_ip(&upcb->local_ip)))) &&
(ip_addr_cmp(ipX_2_ip(&upcb->local_ip), old_addr))) {
/* The PCB is bound to the old ipaddr and
* is set to bound to the new one instead */
ip_addr_set(ipX_2_ip(&upcb->local_ip), new_addr);
/* Is this an IPv4 pcb? */
if (!IP_IS_V6_L(&upcb->local_ip)) {
/* PCB bound to current local interface address? */
if (!ip4_addr_isany(ip_2_ip4(&upcb->local_ip)) &&
ip4_addr_cmp(ip_2_ip4(&upcb->local_ip), old_addr)) {
/* The PCB is bound to the old ipaddr and
* is set to bound to the new one instead */
ip_addr_copy_from_ip4(upcb->local_ip, *new_addr);
}
}
}
}
}
#endif /* LWIP_IPV4 */
#if UDP_DEBUG
/**

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);

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;
}