mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-29 00:32:51 +00:00
use checksum-on-copy for sending UDP data for LWIP_NETIF_TX_SINGLE_PBUF==1
This commit is contained in:
parent
108ed3c81a
commit
4b7288e8f4
@ -13,6 +13,10 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ New features:
|
||||||
|
|
||||||
|
2010-05-02: Simon Goldschmidt
|
||||||
|
* netbuf.h/.c, sockets.c, api_msg.c: use checksum-on-copy for sending
|
||||||
|
UDP data for LWIP_NETIF_TX_SINGLE_PBUF==1
|
||||||
|
|
||||||
2010-04-30: Simon Goldschmidt
|
2010-04-30: Simon Goldschmidt
|
||||||
* udp.h/.c, pbuf.h/.c: task #6849: added udp_send(_to/_if) functions that
|
* udp.h/.c, pbuf.h/.c: task #6849: added udp_send(_to/_if) functions that
|
||||||
take a precalculated checksum, added pbuf_fill_chksum() to copy data
|
take a precalculated checksum, added pbuf_fill_chksum() to copy data
|
||||||
|
@ -180,8 +180,11 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
|||||||
const struct ip_hdr* iphdr = ip_current_header();
|
const struct ip_hdr* iphdr = ip_current_header();
|
||||||
/* get the UDP header - always in the first pbuf, ensured by udp_input */
|
/* get the UDP header - always in the first pbuf, ensured by udp_input */
|
||||||
const struct udp_hdr* udphdr = (void*)(((char*)iphdr) + IPH_LEN(iphdr));
|
const struct udp_hdr* udphdr = (void*)(((char*)iphdr) + IPH_LEN(iphdr));
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
buf->flags = NETBUF_FLAG_DESTADDR;
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
buf->toaddr = (ip_addr_t*)&iphdr->dest;
|
buf->toaddr = (ip_addr_t*)&iphdr->dest;
|
||||||
buf->toport = udphdr->dest;
|
buf->toport_chksum = udphdr->dest;
|
||||||
}
|
}
|
||||||
#endif /* LWIP_NETBUF_RECVINFO */
|
#endif /* LWIP_NETBUF_RECVINFO */
|
||||||
}
|
}
|
||||||
@ -1091,11 +1094,22 @@ do_send(struct api_msg_msg *msg)
|
|||||||
#endif
|
#endif
|
||||||
#if LWIP_UDP
|
#if LWIP_UDP
|
||||||
case NETCONN_UDP:
|
case NETCONN_UDP:
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
if (msg->msg.b->addr == NULL) {
|
||||||
|
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,
|
||||||
|
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 (msg->msg.b->addr == NULL) {
|
if (msg->msg.b->addr == NULL) {
|
||||||
msg->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
|
msg->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
|
||||||
} else {
|
} else {
|
||||||
msg->err = udp_sendto(msg->conn->pcb.udp, msg->msg.b->p, 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;
|
break;
|
||||||
#endif /* LWIP_UDP */
|
#endif /* LWIP_UDP */
|
||||||
default:
|
default:
|
||||||
|
@ -63,10 +63,15 @@ netbuf *netbuf_new(void)
|
|||||||
buf->ptr = NULL;
|
buf->ptr = NULL;
|
||||||
buf->addr = NULL;
|
buf->addr = NULL;
|
||||||
buf->port = 0;
|
buf->port = 0;
|
||||||
|
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
buf->flags = 0;
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
|
buf->toport_chksum = 0;
|
||||||
#if LWIP_NETBUF_RECVINFO
|
#if LWIP_NETBUF_RECVINFO
|
||||||
buf->toaddr = NULL;
|
buf->toaddr = NULL;
|
||||||
buf->toport = 0;
|
|
||||||
#endif /* LWIP_NETBUF_RECVINFO */
|
#endif /* LWIP_NETBUF_RECVINFO */
|
||||||
|
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
|
||||||
return buf;
|
return buf;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
#include "lwip/tcpip.h"
|
#include "lwip/tcpip.h"
|
||||||
#include "lwip/pbuf.h"
|
#include "lwip/pbuf.h"
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
#include "lwip/inet_chksum.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -823,6 +826,12 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|||||||
#if LWIP_NETIF_TX_SINGLE_PBUF
|
#if LWIP_NETIF_TX_SINGLE_PBUF
|
||||||
p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_RAM);
|
p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_RAM);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
u16_t chksum = 0;
|
||||||
|
if (sock->conn->type != NETCONN_RAW) {
|
||||||
|
chksum = LWIP_CHKSUM_COPY(p->payload, data, short_size);
|
||||||
|
} else
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
MEMCPY(p->payload, data, size);
|
MEMCPY(p->payload, data, size);
|
||||||
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
|
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
|
||||||
p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_REF);
|
p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_REF);
|
||||||
@ -836,7 +845,13 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|||||||
if (sock->conn->type == NETCONN_RAW) {
|
if (sock->conn->type == NETCONN_RAW) {
|
||||||
err = sock->conn->last_err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr);
|
err = sock->conn->last_err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr);
|
||||||
} else {
|
} else {
|
||||||
err = sock->conn->last_err = udp_sendto(sock->conn->pcb.udp, p, &remote_addr, ntohs(to_in->sin_port));
|
#if LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF
|
||||||
|
err = sock->conn->last_err = udp_sendto_chksum(sock->conn->pcb.udp, p,
|
||||||
|
&remote_addr, ntohs(to_in->sin_port), 1, chksum);
|
||||||
|
#else /* LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF */
|
||||||
|
err = sock->conn->last_err = udp_sendto(sock->conn->pcb.udp, p,
|
||||||
|
&remote_addr, ntohs(to_in->sin_port));
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF */
|
||||||
}
|
}
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
|
|
||||||
@ -848,16 +863,19 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|||||||
#else
|
#else
|
||||||
/* initialize a buffer */
|
/* initialize a buffer */
|
||||||
buf.p = buf.ptr = NULL;
|
buf.p = buf.ptr = NULL;
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
buf.flags = 0;
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
if (to) {
|
if (to) {
|
||||||
inet_addr_to_ipaddr(&remote_addr, &to_in->sin_addr);
|
inet_addr_to_ipaddr(&remote_addr, &to_in->sin_addr);
|
||||||
remote_port = ntohs(to_in->sin_port);
|
remote_port = ntohs(to_in->sin_port);
|
||||||
buf.addr = &remote_addr;
|
netbuf_fromaddr(&buf) = &remote_addr;
|
||||||
buf.port = remote_port;
|
netbuf_fromport(&buf) = remote_port;
|
||||||
} else {
|
} else {
|
||||||
ip_addr_set_zero(&remote_addr);
|
ip_addr_set_zero(&remote_addr);
|
||||||
remote_port = 0;
|
remote_port = 0;
|
||||||
buf.addr = NULL;
|
netbuf_fromaddr(&buf) = NULL;
|
||||||
buf.port = 0;
|
netbuf_fromport(&buf) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%d"U16_F", flags=0x%x to=",
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%d"U16_F", flags=0x%x to=",
|
||||||
@ -871,7 +889,16 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|||||||
if (netbuf_alloc(&buf, short_size) == NULL) {
|
if (netbuf_alloc(&buf, short_size) == NULL) {
|
||||||
err = ERR_MEM;
|
err = ERR_MEM;
|
||||||
} else {
|
} else {
|
||||||
err = netbuf_take(&buf, data, short_size);
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
if (sock->conn->type != NETCONN_RAW) {
|
||||||
|
u16_t chksum = LWIP_CHKSUM_COPY(buf.p->payload, data, short_size);
|
||||||
|
netbuf_set_chksum(&buf, chksum);
|
||||||
|
err = ERR_OK;
|
||||||
|
} else
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
|
{
|
||||||
|
err = netbuf_take(&buf, data, short_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
|
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
|
||||||
err = netbuf_ref(&buf, data, short_size);
|
err = netbuf_ref(&buf, data, short_size);
|
||||||
|
@ -40,14 +40,24 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** This netbuf has dest-addr/port set */
|
||||||
|
#define NETBUF_FLAG_DESTADDR 0x01
|
||||||
|
/** This netbuf includes a checksum */
|
||||||
|
#define NETBUF_FLAG_CHKSUM 0x02
|
||||||
|
|
||||||
struct netbuf {
|
struct netbuf {
|
||||||
struct pbuf *p, *ptr;
|
struct pbuf *p, *ptr;
|
||||||
ip_addr_t *addr;
|
ip_addr_t *addr;
|
||||||
u16_t port;
|
u16_t port;
|
||||||
|
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
u8_t flags;
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
|
u16_t toport_chksum;
|
||||||
#if LWIP_NETBUF_RECVINFO
|
#if LWIP_NETBUF_RECVINFO
|
||||||
u16_t toport;
|
|
||||||
ip_addr_t *toaddr;
|
ip_addr_t *toaddr;
|
||||||
#endif /* LWIP_NETBUF_RECVINFO */
|
#endif /* LWIP_NETBUF_RECVINFO */
|
||||||
|
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Network buffer functions: */
|
/* Network buffer functions: */
|
||||||
@ -56,12 +66,12 @@ void netbuf_delete (struct netbuf *buf);
|
|||||||
void * netbuf_alloc (struct netbuf *buf, u16_t size);
|
void * netbuf_alloc (struct netbuf *buf, u16_t size);
|
||||||
void netbuf_free (struct netbuf *buf);
|
void netbuf_free (struct netbuf *buf);
|
||||||
err_t netbuf_ref (struct netbuf *buf,
|
err_t netbuf_ref (struct netbuf *buf,
|
||||||
const void *dataptr, u16_t size);
|
const void *dataptr, u16_t size);
|
||||||
void netbuf_chain (struct netbuf *head,
|
void netbuf_chain (struct netbuf *head,
|
||||||
struct netbuf *tail);
|
struct netbuf *tail);
|
||||||
|
|
||||||
err_t netbuf_data (struct netbuf *buf,
|
err_t netbuf_data (struct netbuf *buf,
|
||||||
void **dataptr, u16_t *len);
|
void **dataptr, u16_t *len);
|
||||||
s8_t netbuf_next (struct netbuf *buf);
|
s8_t netbuf_next (struct netbuf *buf);
|
||||||
void netbuf_first (struct netbuf *buf);
|
void netbuf_first (struct netbuf *buf);
|
||||||
|
|
||||||
@ -75,8 +85,12 @@ void netbuf_first (struct netbuf *buf);
|
|||||||
#define netbuf_fromport(buf) ((buf)->port)
|
#define netbuf_fromport(buf) ((buf)->port)
|
||||||
#if LWIP_NETBUF_RECVINFO
|
#if LWIP_NETBUF_RECVINFO
|
||||||
#define netbuf_destaddr(buf) ((buf)->toaddr)
|
#define netbuf_destaddr(buf) ((buf)->toaddr)
|
||||||
#define netbuf_destport(buf) ((buf)->toport)
|
#define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0)
|
||||||
#endif /* LWIP_NETBUF_RECVINFO */
|
#endif /* LWIP_NETBUF_RECVINFO */
|
||||||
|
#if LWIP_CHECKSUM_ON_COPY
|
||||||
|
#define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \
|
||||||
|
(buf)->toport_chksum = chksum; } while(0)
|
||||||
|
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user