Return wpabuf from radius_msg_get_eap()

This simplifies the implementation by using the buffer type to which the
returned data will be converted anyway. This avoids one memory
allocation for each processed RADIUS message.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-08-07 18:14:42 +03:00
parent 95ac3bf49f
commit e100828b76
5 changed files with 38 additions and 50 deletions

View file

@ -707,9 +707,9 @@ int radius_msg_add_eap(struct radius_msg *msg, const u8 *data, size_t data_len)
}
u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *eap_len)
struct wpabuf * radius_msg_get_eap(struct radius_msg *msg)
{
u8 *eap, *pos;
struct wpabuf *eap;
size_t len, i;
struct radius_attr_hdr *attr;
@ -726,23 +726,18 @@ u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *eap_len)
if (len == 0)
return NULL;
eap = os_malloc(len);
eap = wpabuf_alloc(len);
if (eap == NULL)
return NULL;
pos = eap;
for (i = 0; i < msg->attr_used; i++) {
attr = radius_get_attr_hdr(msg, i);
if (attr->type == RADIUS_ATTR_EAP_MESSAGE) {
int flen = attr->length - sizeof(*attr);
os_memcpy(pos, attr + 1, flen);
pos += flen;
wpabuf_put_data(eap, attr + 1, flen);
}
}
if (eap_len)
*eap_len = len;
return eap;
}

View file

@ -213,7 +213,7 @@ struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
size_t data_len);
u8 *radius_msg_get_eap(struct radius_msg *msg, size_t *len);
struct wpabuf * radius_msg_get_eap(struct radius_msg *msg);
int radius_msg_verify(struct radius_msg *msg, const u8 *secret,
size_t secret_len, struct radius_msg *sent_msg,
int auth);

View file

@ -689,8 +689,7 @@ static int radius_server_request(struct radius_server_data *data,
const char *from_addr, int from_port,
struct radius_session *force_sess)
{
u8 *eap = NULL;
size_t eap_len;
struct wpabuf *eap = NULL;
int res, state_included = 0;
u8 statebuf[4];
unsigned int state;
@ -754,7 +753,7 @@ static int radius_server_request(struct radius_server_data *data,
return -1;
}
eap = radius_msg_get_eap(msg, &eap_len);
eap = radius_msg_get_eap(msg);
if (eap == NULL) {
RADIUS_DEBUG("No EAP-Message in RADIUS packet from %s",
from_addr);
@ -763,7 +762,7 @@ static int radius_server_request(struct radius_server_data *data,
return -1;
}
RADIUS_DUMP("Received EAP data", eap, eap_len);
RADIUS_DUMP("Received EAP data", wpabuf_head(eap), wpabuf_len(eap));
/* FIX: if Code is Request, Success, or Failure, send Access-Reject;
* RFC3579 Sect. 2.6.2.
@ -773,10 +772,7 @@ static int radius_server_request(struct radius_server_data *data,
* Or is this already done by the EAP state machine? */
wpabuf_free(sess->eap_if->eapRespData);
sess->eap_if->eapRespData = wpabuf_alloc_ext_data(eap, eap_len);
if (sess->eap_if->eapRespData == NULL)
os_free(eap);
eap = NULL;
sess->eap_if->eapRespData = eap;
sess->eap_if->eapResp = TRUE;
eap_server_sm_step(sess->eap);