Together with Simon: Eliminate last instances of isipv6 member in pcbs;

Don't allow NULL pointers (IPv4 ANY) in connect() and sendto() functions as destinations since this does not make sense.
This commit is contained in:
Dirk Ziegelmeier 2016-02-22 13:03:51 +01:00
parent be9cd800b0
commit 880f1008d6
6 changed files with 35 additions and 37 deletions

View File

@ -556,7 +556,8 @@ pcb_new(struct api_msg_msg *msg)
#if LWIP_IPV4 && LWIP_IPV6
else {
if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
ip_set_v6(msg->conn->pcb.ip, 1);
IP_SET_TYPE_VAL(msg->conn->pcb.ip->local_ip, IPADDR_TYPE_V6);
IP_SET_TYPE_VAL(msg->conn->pcb.ip->remote_ip, IPADDR_TYPE_V6);
}
}
#endif /* LWIP_IPV4 && LWIP_IPV6 */
@ -1764,7 +1765,7 @@ lwip_netconn_do_join_leave_group(struct api_msg_msg *msg)
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
#if LWIP_UDP
#if LWIP_IPV6 && LWIP_IPV6_MLD
if (PCB_ISIPV6(msg->conn->pcb.udp)) {
if (NETCONNTYPE_ISIPV6(msg->conn->type)) {
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
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)));

View File

@ -442,7 +442,15 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
int max_pcb_list = NUM_TCP_PCB_LISTS;
struct tcp_pcb *cpcb;
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
#if LWIP_IPV4
/* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
if (ipaddr == NULL) {
ipaddr = IP_ADDR_ANY;
}
#endif /* LWIP_IPV4 */
/* still need to check for ipaddr == NULL in IPv6 only case */
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
@ -566,8 +574,8 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
lpcb->ttl = pcb->ttl;
lpcb->tos = pcb->tos;
#if LWIP_IPV4 && LWIP_IPV6
PCB_ISIPV6(lpcb) = PCB_ISIPV6(pcb);
lpcb->accept_any_ip_version = 0;
IP_SET_TYPE_VAL(lpcb->remote_ip, pcb->local_ip.type);
#endif /* LWIP_IPV4 && LWIP_IPV6 */
ip_addr_copy(lpcb->local_ip, pcb->local_ip);
if (pcb->local_port != 0) {
@ -748,7 +756,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
u32_t iss;
u16_t old_local_port;
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
@ -1545,7 +1553,6 @@ tcp_new_ip6(void)
struct tcp_pcb * pcb;
pcb = tcp_alloc(TCP_PRIO_NORMAL);
#if LWIP_IPV4
ip_set_v6(pcb, 1);
IP_SET_TYPE_VAL(pcb->local_ip, IPADDR_TYPE_V6);
IP_SET_TYPE_VAL(pcb->remote_ip, IPADDR_TYPE_V6);
#endif /* LWIP_IPV4 */

View File

@ -569,9 +569,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
pcb->accepts_pending++;
#endif /* TCP_LISTEN_BACKLOG */
/* Set up the new PCB. */
#if LWIP_IPV4 && LWIP_IPV6
PCB_ISIPV6(npcb) = ip_current_is_v6();
#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;
@ -1151,7 +1148,7 @@ tcp_receive(struct tcp_pcb *pcb)
pcb->polltmr = 0;
#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS
if (PCB_ISIPV6(pcb)) {
if (ip_current_is_v6()) {
/* Inform neighbor reachability of forward progress. */
nd6_reachability_hint(ip6_current_src_addr());
}
@ -1485,7 +1482,7 @@ tcp_receive(struct tcp_pcb *pcb)
tcp_ack(pcb);
#if LWIP_IPV6 && LWIP_ND6_TCP_REACHABILITY_HINTS
if (PCB_ISIPV6(pcb)) {
if (ip_current_is_v6()) {
/* Inform neighbor reachability of forward progress. */
nd6_reachability_hint(ip6_current_src_addr());
}

View File

@ -244,7 +244,7 @@ udp_input(struct pbuf *p, struct netif *inp)
if (pcb->local_port == dest) {
if (
#if LWIP_IPV6
(PCB_ISIPV6(pcb) && (ip_current_is_v6()) &&
(IP_IS_V6_VAL(pcb->local_ip) && ip_current_is_v6() &&
(ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
#if LWIP_IPV6_MLD
ip6_addr_ismulticast(ip6_current_dest_addr()) ||
@ -252,7 +252,7 @@ udp_input(struct pbuf *p, struct netif *inp)
ip6_addr_cmp(ip_2_ip6(&pcb->local_ip), ip6_current_dest_addr())))
#endif /* LWIP_IPV6 */
#if LWIP_IPV4 && LWIP_IPV6
|| (!PCB_ISIPV6(pcb) &&
|| (!IP_IS_V6_VAL(pcb->local_ip) &&
(ip4_current_header() != NULL) &&
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#if LWIP_IPV4
@ -393,10 +393,10 @@ udp_input(struct pbuf *p, struct netif *inp)
/* compare PCB local addr+port to UDP destination addr+port */
if ((mpcb->local_port == dest) &&
#if LWIP_IPV6
((PCB_ISIPV6(mpcb) &&
((IP_IS_V6_VAL(mpcb->local_ip) &&
(ip6_addr_ismulticast(ip6_current_dest_addr()) ||
ip6_addr_cmp(ip_2_ip6(&mpcb->local_ip), ip6_current_dest_addr()))) ||
(!PCB_ISIPV6(mpcb) &&
(!IP_IS_V6_VAL(mpcb->local_ip) &&
#else /* LWIP_IPV6 */
((
#endif /* LWIP_IPV6 */
@ -571,7 +571,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
struct netif *netif;
const ip_addr_t *dst_ip_route = dst_ip;
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -654,7 +654,7 @@ 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 ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -724,7 +724,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 ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
if ((pcb == NULL) || (dst_ip == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
return ERR_VAL;
}
@ -929,7 +929,15 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
struct udp_pcb *ipcb;
u8_t rebind;
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
#if LWIP_IPV4
/* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
if (ipaddr == NULL) {
ipaddr = IP_ADDR_ANY;
}
#endif /* LWIP_IPV4 */
/* still need to check for ipaddr == NULL in IPv6 only case */
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
@ -1020,7 +1028,7 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
{
struct udp_pcb *ipcb;
if ((pcb == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
return ERR_VAL;
}
@ -1062,7 +1070,7 @@ void
udp_disconnect(struct udp_pcb *pcb)
{
/* reset remote address association */
ip_addr_set_any(PCB_ISIPV6(pcb), &pcb->remote_ip);
ip_addr_set_any(IP_IS_V6_VAL(pcb->remote_ip), &pcb->remote_ip);
pcb->remote_port = 0;
/* mark PCB as unconnected */
pcb->flags &= ~UDP_FLAGS_CONNECTED;
@ -1160,7 +1168,6 @@ udp_new_ip6(void)
struct udp_pcb *pcb;
pcb = udp_new();
#if LWIP_IPV4
ip_set_v6(pcb, 1);
IP_SET_TYPE_VAL(pcb->local_ip, IPADDR_TYPE_V6);
IP_SET_TYPE_VAL(pcb->remote_ip, IPADDR_TYPE_V6);
#endif /* LWIP_IPV4 */

View File

@ -75,20 +75,11 @@ extern "C" {
#define IP_PCB_ADDRHINT
#endif /* LWIP_NETIF_HWADDRHINT */
#if LWIP_IPV6 && LWIP_IPV4
#define IP_PCB_ISIPV6_MEMBER u8_t isipv6;
#define PCB_ISIPV6(pcb) ((pcb)->isipv6)
#else
#define IP_PCB_ISIPV6_MEMBER
#define PCB_ISIPV6(pcb) LWIP_IPV6
#endif /* LWIP_IPV6 */
/* This is the common part of all PCB types. It needs to be at the
beginning of a PCB type definition. It is located here so that
changes to this common part are made in one location instead of
having to change all PCB structs. */
#define IP_PCB \
IP_PCB_ISIPV6_MEMBER \
/* ip addresses in network byte order */ \
ip_addr_t local_ip; \
ip_addr_t remote_ip; \
@ -180,11 +171,6 @@ extern struct ip_globals ip_data;
#define ip_next_header_ptr() ((const void*)((ip_current_is_v6() ? \
(const u8_t*)ip6_current_header() : (const 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; \
IP_SET_TYPE(&(pcb)->local_ip, (val)?IPADDR_TYPE_V6:IPADDR_TYPE_V4); \
IP_SET_TYPE(&(pcb)->remote_ip, (val)?IPADDR_TYPE_V6:IPADDR_TYPE_V4); }}while(0)
/** Source IP4 address of current_header */
#define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src))
/** Destination IP4 address of current_header */

View File

@ -66,7 +66,7 @@ typedef struct _ip_addr {
#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
#define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
#define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (PCB_ISIPV6(pcb) == IP_IS_V6(ipaddr))
#define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_V6_VAL(pcb->local_ip) == IP_IS_V6(ipaddr))
/* Convert generic ip address to specific protocol version */
#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6))