driver_bsd.c: Clean up EAPOL frame transmission code

The bsd_send_eapol() prepares 3000 bytes buffer for every EAPOL
frame transmission. I think malloc() is better way for efficient
memory use.
This commit is contained in:
Masashi Honma 2010-01-16 11:47:05 +02:00 committed by Jouni Malinen
parent 73b217570c
commit 11386396cc

View file

@ -696,39 +696,35 @@ bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
int encrypt, const u8 *own_addr) int encrypt, const u8 *own_addr)
{ {
struct bsd_driver_data *drv = priv; struct bsd_driver_data *drv = priv;
unsigned char buf[3000]; unsigned char *bp;
unsigned char *bp = buf;
struct l2_ethhdr *eth; struct l2_ethhdr *eth;
size_t len; size_t len;
int status; int status;
/* /*
* Prepend the Etherent header. If the caller left us * Prepend the Ethernet header. If the caller left us
* space at the front we could just insert it but since * space at the front we could just insert it but since
* we don't know we copy to a local buffer. Given the frequency * we don't know we copy to a local buffer. Given the frequency
* and size of frames this probably doesn't matter. * and size of frames this probably doesn't matter.
*/ */
len = data_len + sizeof(struct l2_ethhdr); len = data_len + sizeof(struct l2_ethhdr);
if (len > sizeof(buf)) { bp = os_zalloc(len);
bp = malloc(len); if (bp == NULL) {
if (bp == NULL) { wpa_printf(MSG_ERROR, "malloc() failed for bsd_send_eapol"
printf("EAPOL frame discarded, cannot malloc temp " "(len=%lu)", (unsigned long) len);
"buffer of size %u!\n", (unsigned int) len); return -1;
return -1;
}
} }
eth = (struct l2_ethhdr *) bp; eth = (struct l2_ethhdr *) bp;
memcpy(eth->h_dest, addr, ETH_ALEN); os_memcpy(eth->h_dest, addr, ETH_ALEN);
memcpy(eth->h_source, own_addr, ETH_ALEN); os_memcpy(eth->h_source, own_addr, ETH_ALEN);
eth->h_proto = htons(ETH_P_EAPOL); eth->h_proto = htons(ETH_P_EAPOL);
memcpy(eth+1, data, data_len); os_memcpy(eth + 1, data, data_len);
wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len); wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len); status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
if (bp != buf) os_free(bp);
free(bp);
return status; return status;
} }