Commit 5015bfc7 authored by Alessandro Rubini's avatar Alessandro Rubini

userspace/tools/radiusvlan: various fixes

This commit fixes errors in pipe closing, and changes the parsing.

NOTE: it also changes the identification of "self" frames. ppsi
sends everything using the eth0 mac address, which is different
from the wriXX port.

This is hacked now by checking the first 5 bytes, but it must be
fixed for real.

Finally, I save both stdin and stdout that I exchange with radclient
into tmp, so we can check what happened during tests.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 447615c4
......@@ -166,7 +166,16 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
prgname, dev->name, ret);
return -1;
}
if (!memcmp(frame + ETH_ALEN, dev->mac, ETH_ALEN))
if (0 && verbose) {
printf("got %02x%02x%02x%02x%02x%02x ",
frame[6], frame[7], frame[8],
frame[9], frame[10], frame[11]);
printf("own %02x%02x%02x%02x%02x%02x ",
dev->mac[0], dev->mac[1], dev->mac[2],
dev->mac[3], dev->mac[4], dev->mac[5]);
}
/* FIXME: check with all local addresses or packet type */
if (!memcmp(frame + ETH_ALEN, dev->mac, 5))
break; /* own sending, ignore */
/* success, it seems */
......@@ -208,7 +217,7 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
exit(1);
default:
close(pipe0[1]); close(pipe1[0]);
close(pipe0[0]); close(pipe1[1]);
dev->pid = pid;
break;
}
......@@ -221,8 +230,20 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
write(pipe0[1], dev->radbuffer, i);
close(pipe0[1]);
/* save a copy of stdin for diagnostics */
if (1) {
FILE *f;
char fname[40];
sprintf(fname, "/tmp/radclient-%s-in", dev->name);
f = fopen(fname, "w");
if (f) {
fprintf(f, "%s", dev->radbuffer);
fclose(f);
}
}
/* and return when data is there to read */
dev->poll_fd = pipe1[1];
dev->poll_fd = pipe1[0];
dev->radbuffer_size = 0;
dev->fsm_state = RVLAN_AUTH;
break;
......@@ -232,7 +253,7 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
i = read(dev->poll_fd, dev->radbuffer + dev->radbuffer_size,
sizeof(dev->radbuffer) - 1 - dev->radbuffer_size);
if (i < 0) {
fprintf(stderr, "%s: read(raclient): %s\n",
fprintf(stderr, "%s: read(radclient): %s\n",
prgname, strerror(errno));
close(dev->poll_fd); dev->poll_fd = -1;
kill(dev->pid, SIGTERM);
......@@ -243,7 +264,7 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
dev->radbuffer_size += i;
dev->radbuffer[dev->radbuffer_size] = '\0';
if (verbose)
printf("dev %s, got %i bytes so far ",
printf("dev %s, got %i bytes so far ",
dev->name, dev->radbuffer_size);
break;
}
......@@ -254,9 +275,21 @@ int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
waitpid(dev->pid, &i, 0);
dev->pid = -1;
/* save a copy for diagnostics */
if (1) {
FILE *f;
char fname[40];
sprintf(fname, "/tmp/radclient-%s-out", dev->name);
f = fopen(fname, "w");
if (f) {
fprintf(f, "%s", dev->radbuffer);
fclose(f);
}
}
/* And parse the result */
dev->chosen_vlan = rvlan_noauth_vlan;
if (strstr(dev->radbuffer, "Access-Accept")) {
if (strstr(dev->radbuffer, "Framed-User")) {
char *s;
/* Tunnel-Private-Group-Id:0 = "2984" */
s = strstr(dev->radbuffer, "Tunnel-Private-Group-Id");
......@@ -567,7 +600,7 @@ void rvlan_reconfigure_vlans(void)
/* And a main to keep it all together */
int main(int argc, char **argv)
{
int ret, sock;
int sock;
char *rvlan_dev_prefix = "wri";
char *dotconfig = "/wr/etc/dot-config";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment