|
|
|
@ -1437,6 +1437,11 @@ static int cmp_int(const void *a, const void *b)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int tag_is_valid(u8 tag) {
|
|
|
|
|
return 0x1 <= tag && tag <= 0x1F;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* radius_msg_get_vlanid - Parse RADIUS attributes for VLAN tunnel information
|
|
|
|
|
* The k tagged vlans found are sorted by vlan_id and stored in the first k
|
|
|
|
@ -1450,7 +1455,7 @@ static int cmp_int(const void *a, const void *b)
|
|
|
|
|
* Returns: 0 if neither tagged nor untagged configuration is found, 1 otherwise
|
|
|
|
|
*/
|
|
|
|
|
int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
|
|
|
|
|
int *tagged)
|
|
|
|
|
int *tagged, u8 tag)
|
|
|
|
|
{
|
|
|
|
|
struct radius_tunnel_attrs tunnel[RADIUS_TUNNEL_TAGS], *tun;
|
|
|
|
|
size_t i;
|
|
|
|
@ -1465,6 +1470,11 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
|
|
|
|
|
tagged[j] = 0;
|
|
|
|
|
*untagged = 0;
|
|
|
|
|
|
|
|
|
|
if (tag_is_valid(tag))
|
|
|
|
|
tun = &tunnel[tag];
|
|
|
|
|
else
|
|
|
|
|
tun = &tunnel[0];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < msg->attr_used; i++) {
|
|
|
|
|
attr = radius_get_attr_hdr(msg, i);
|
|
|
|
|
if (attr->length < sizeof(*attr))
|
|
|
|
@ -1473,10 +1483,8 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
|
|
|
|
|
dlen = attr->length - sizeof(*attr);
|
|
|
|
|
if (attr->length < 3)
|
|
|
|
|
continue;
|
|
|
|
|
if (data[0] >= RADIUS_TUNNEL_TAGS)
|
|
|
|
|
tun = &tunnel[0];
|
|
|
|
|
else
|
|
|
|
|
tun = &tunnel[data[0]];
|
|
|
|
|
if (data[0] != tag)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
switch (attr->type) {
|
|
|
|
|
case RADIUS_ATTR_TUNNEL_TYPE:
|
|
|
|
@ -1521,17 +1529,11 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Use tunnel with the lowest tag for untagged VLAN id */
|
|
|
|
|
for (i = 0; i < RADIUS_TUNNEL_TAGS; i++) {
|
|
|
|
|
tun = &tunnel[i];
|
|
|
|
|
if (tun->tag_used &&
|
|
|
|
|
tun->type == RADIUS_TUNNEL_TYPE_VLAN &&
|
|
|
|
|
tun->medium_type == RADIUS_TUNNEL_MEDIUM_TYPE_802 &&
|
|
|
|
|
tun->vlanid > 0) {
|
|
|
|
|
*untagged = tun->vlanid;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tun->tag_used &&
|
|
|
|
|
tun->type == RADIUS_TUNNEL_TYPE_VLAN &&
|
|
|
|
|
tun->medium_type == RADIUS_TUNNEL_MEDIUM_TYPE_802 &&
|
|
|
|
|
tun->vlanid > 0)
|
|
|
|
|
*untagged = tun->vlanid;
|
|
|
|
|
|
|
|
|
|
if (taggedidx)
|
|
|
|
|
qsort(tagged, taggedidx, sizeof(int), cmp_int);
|
|
|
|
@ -1554,7 +1556,8 @@ int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
|
|
|
|
|
*/
|
|
|
|
|
char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
|
|
|
|
|
const u8 *secret, size_t secret_len,
|
|
|
|
|
struct radius_msg *sent_msg, size_t n)
|
|
|
|
|
struct radius_msg *sent_msg, size_t n,
|
|
|
|
|
u8 *tag)
|
|
|
|
|
{
|
|
|
|
|
u8 *buf = NULL;
|
|
|
|
|
size_t buflen;
|
|
|
|
@ -1572,6 +1575,9 @@ char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
|
|
|
|
|
size_t fdlen = -1;
|
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
|
|
if (tag)
|
|
|
|
|
*tag = 0;
|
|
|
|
|
|
|
|
|
|
/* find n-th valid Tunnel-Password attribute */
|
|
|
|
|
for (i = 0; i < msg->attr_used; i++) {
|
|
|
|
|
attr = radius_get_attr_hdr(msg, i);
|
|
|
|
@ -1589,6 +1595,9 @@ char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
|
|
|
|
|
if (j <= n)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (tag && tag_is_valid(data[0]))
|
|
|
|
|
*tag = data[0];
|
|
|
|
|
|
|
|
|
|
fdata = data;
|
|
|
|
|
fdlen = dlen;
|
|
|
|
|
break;
|
|
|
|
|