Commit 955cf469 authored by Alessandro Rubini's avatar Alessandro Rubini

rvlan: collect all mac addresses

also, the mac address is always saved in dev->mac, so we get it
in rvlan-status also for "down" interfaces.

Example:

   wri12 (001bc509084f <-> ): state down, vlan 0, pid 0, fd -1
   wri13 (001bc5090850 <-> ): state down, vlan 0, pid 0, fd -1
   wri14 (001bc5090851 <-> ): state down, vlan 0, pid 0, fd -1
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b8965b45
......@@ -80,6 +80,13 @@ char *fsm_names[] = {
struct rvlan_dev *devs;
/* And this otherlist is for mac addresses (binary) */
struct rvlan_binmac {
unsigned char mac[ETH_ALEN];
struct rvlan_binmac *next;
};
struct rvlan_binmac *macs;
/* Authentication of a port is a state machine */
int rvlan_fsm(struct rvlan_dev *dev, fd_set *rdset)
{
......@@ -369,6 +376,7 @@ static int rvlan_enumerate_devices(char *prefix)
FILE *f;
struct dirent *ent;
struct rvlan_dev *dev;
struct rvlan_binmac *binmac;
char *s, cfgname[40];
int portnr, mode_access;
......@@ -381,6 +389,32 @@ static int rvlan_enumerate_devices(char *prefix)
while ( (ent = readdir(d)) ) {
if (ent->d_type != DT_LNK)
continue; /* not a symlink --> not an interface */
/* collect the mac address for all interfaces */
binmac = calloc(1, sizeof(*binmac));
if (binmac) {
sprintf(path, "%s/%s/address", dirname, ent->d_name);
f = fopen(path, "r");
if (f) {
ret = fscanf(f, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
binmac->mac+0, binmac->mac+1,
binmac->mac+2, binmac->mac+3,
binmac->mac+4, binmac->mac+5);
/* discard all-0 -- e.g. lo interface */
if (!binmac->mac[0] && !binmac->mac[1] &&
!binmac->mac[2] && !binmac->mac[3] &&
!binmac->mac[4] && !binmac->mac[5])
ret = 0;
if (ret == 6) {
binmac->next = macs;
macs = binmac;
}
fclose(f);
}
if (macs != binmac) /* not enqueued */
free(binmac);
}
if (strncmp(ent->d_name, prefix, strlen(prefix)))
continue; /* no match -> we do not care */
......@@ -413,6 +447,8 @@ static int rvlan_enumerate_devices(char *prefix)
dev = calloc(1, sizeof(*dev));
dev->name = strdup(ent->d_name);
if (macs) /* last allocated is ours */
memcpy(dev->mac, macs->mac, ETH_ALEN);
dev->portnr = portnr;
dev->poll_fd = -1;
if (IS_WRS) {
......
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