Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes #4

Merged
merged 8 commits into from
Jul 1, 2021
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
*~
aclocal.m4
autom4te.cache/
aux/
config.h
config.h.in
config.log
config.status
configure
GPATH
GRTAGS
GTAGS
Makefile
Makefile.in
stamp-h1
37 changes: 37 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,40 @@ SUBDIRS = src
doc_DATA = README.md COPYING
DISTCLEANFILES = *~ *.d
ACLOCAL_AMFLAGS = -I m4


## Check if tagged in git
release-hook:
if [ ! `git tag $(PACKAGE_VERSION) | grep $(PACKAGE_VERSION)` ]; then \
echo; \
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
printf "OK, aborting release.\n"; \
exit 1; \
fi; \
echo; \
else \
echo; \
printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
echo; \
fi

## Target to run when building a release
release: release-hook distcheck
@for file in $(DIST_ARCHIVES); do \
md5sum $$file > ../$$file.md5; \
sha1sum $$file > ../$$file.sha1; \
sha256sum $$file > ../$$file.sha256; \
done
@mv $(DIST_ARCHIVES) ../
@echo
@echo "Resulting release files:"
@echo "================================================================="
@for file in $(DIST_ARCHIVES); do \
printf "$$file \tDistribution tarball\n"; \
printf "$$file.md5\t"; cat ../$$file.md5 | cut -f1 -d' '; \
printf "$$file.sha1\t"; cat ../$$file.sha1 | cut -f1 -d' '; \
printf "$$file.sha256\t"; cat ../$$file.sha256 | cut -f1 -d' '; \
done
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ Common options:
Build
-----

Standard autotools procedure.
Standard autotools procedure, requires `pkg-config` to locate the `libmnl`
development files.

./configure && make all && sudo make install

At the moment, the kernel module has to be built separately, set
`KDIR` if building against a kernel in a non-standard location.

When building from GIT, the `configure` script first needs to be generated, this
requires `autoconf` and `automake` to be installed. A helper script to generate
configure is available:

./autogen.sh
3 changes: 3 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

autoreconf -W portability -vifm
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AC_PREREQ(2.61)
AC_INIT(mdio-tools, m4_esyscmd_s(git describe --always --dirty),
https://github.com/wkz/mdio-tools/issues)

AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE(1.11 foreign subdir-objects)
AM_SILENT_RULES(yes)

Expand Down
3 changes: 3 additions & 0 deletions src/mdio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
.deps/
mdio
3 changes: 3 additions & 0 deletions src/mvls/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
.deps/
mvls
93 changes: 72 additions & 21 deletions src/mvls/mvls.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <err.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
Expand All @@ -17,8 +18,10 @@ static int __dev_vtu_parse(struct dev *dev,
{
int i;

if (!bit(kentry->vid, 12))
return ENODATA;
if (!bit(kentry->vid, 12)) {
errno = ENODATA;
return -1;
}

entry->vid = bits(kentry->vid, 0, 12);
entry->fid = bits(kentry->fid, 0, 12);
Expand Down Expand Up @@ -54,8 +57,10 @@ int opal_dev_atu_parse(struct dev *dev,
struct mv88e6xxx_devlink_atu_entry *kentry,
struct atu_entry *entry)
{
if (!bits(kentry->atu_data, 0, 4))
return ENODATA;
if (!bits(kentry->atu_data, 0, 4)) {
errno = ENODATA;
return -1;
}

entry->fid = kentry->fid;
entry->addr[0] = bits(kentry->atu_01, 8, 8);
Expand Down Expand Up @@ -231,16 +236,20 @@ static void dev_show_pvt(struct dev *dev)

TAILQ_FOREACH(port, &dev->ports, node) {
err = port_load_regs(port);
if (err)
if (err) {
warn("failed querying ports");
return;
}
printf("%2x %x", dev->index, port->index);
dev_print_portvec(dev, bits(reg16(port->regs, 6), 0, 11));
putchar('\n');
}

err = dev_load_pvt(dev);
if (err)
if (err) {
warn("failed querying pvt");
return;
}

for (di = 0; di < 32; di++) {
for (pi = 0; pi < 16; pi++) {
Expand Down Expand Up @@ -278,6 +287,7 @@ static struct dev *env_dev_get(struct env *env, int index)
return dev;
}

errno = EINVAL;
return NULL;
}

Expand All @@ -296,6 +306,7 @@ static struct dev *env_dev_find(struct env *env,
return dev;
}

errno = ENODEV;
return NULL;
}

Expand Down Expand Up @@ -481,8 +492,10 @@ int env_init(struct env *env)
if (err)
return err;

if (TAILQ_EMPTY(&env->devs))
return ENODEV;
if (TAILQ_EMPTY(&env->devs)) {
errno = ENODEV;
return -1;
}

TAILQ_FOREACH(dev, &env->devs, node) {
err = dev_init(dev);
Expand Down Expand Up @@ -544,8 +557,10 @@ void env_show_atu(struct env *env)

err = devlink_region_get(&env->dl, &dev->devlink, "atu",
devlink_region_dup_cb, &atu);
if (err)
if (err) {
warn("failed querying atu");
break;
}

kentry = (void *)atu.data.u8;
while (!dev_op(dev, atu_parse, kentry, &entry)) {
Expand Down Expand Up @@ -589,8 +604,10 @@ void env_show_vtu(struct env *env)

err = devlink_region_get(&env->dl, &dev->devlink, "vtu",
devlink_region_dup_cb, &vtu);
if (err)
if (err) {
warn("failed querying vtu");
break;
}

kentry = (void *)vtu.data.u8;
while (!dev_op(dev, vtu_parse, kentry, &entry)) {
Expand Down Expand Up @@ -675,7 +692,7 @@ void env_show_pvt_port(struct port *src, unsigned lags)
putchar('\n');
}

void env_show_pvt(struct env *env)
int env_show_pvt(struct env *env)
{
struct dev *dev;
struct port *port;
Expand All @@ -685,13 +702,17 @@ void env_show_pvt(struct env *env)
fputs("\e[7mD ", stdout);
TAILQ_FOREACH(dev, &env->devs, node) {
err = dev_load_pvt(dev);
if (err)
return;
if (err) {
warn("failed querying pvt");
return 1;
}

TAILQ_FOREACH(port, &dev->ports, node) {
err = port_load_regs(port);
if (err)
return;
if (err) {
warn("failed querying ports");
return 1;
}

lag = port_op(port, lag);
if (lag >= 0)
Expand Down Expand Up @@ -734,23 +755,53 @@ void env_show_pvt(struct env *env)
if (TAILQ_NEXT(dev, node))
puts("\e[7m \e[0m");
}

return 0;
}

int usage(int rc)
{
fputs("Usage: mvls [CMD]\n"
"\n"
"Commands:\n"
"\n"
" port\n"
" Displays and overview of switchcore ports and their properties.\n"
"\n"
" atu\n"
" Displays the contents of the ATU with VLAN and port vectors.\n"
"\n"
" vtu\n"
" Displays the contents of the VTU with FID and port mappings.\n"
" Port VLAN membership states: (u)ntagged, (t)agged, =CPU, (D)SA\n"
"\n"
" pvt [INDEX]\n"
" Displays the contents of the Port VLAN Table, optionally on the\n"
" given switchcore index, by default index 0 is shown."
"\n"
"By default, mvls displays an overview of the VTU, ATU and ports.\n"
, stdout);

return rc;
}

int main(int argc, char **argv)
{
struct env env;

if (env_init(&env)) {
fprintf(stderr, "ERROR: Failed to discover devices.\n");
return 1;
}
if (env_init(&env))
err(1, "failed discovering any devices");

if (argc == 1) {
env_show_vtu(&env); puts("");
env_show_atu(&env); puts("");
env_show_ports(&env);
return 0;
}

if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "help"))
return usage(0);

if (!strcmp(argv[1], "port"))
env_show_ports(&env);
if (!strcmp(argv[1], "atu"))
Expand All @@ -762,12 +813,12 @@ int main(int argc, char **argv)
int index;

if (argc == 2)
env_show_pvt(&env);
return env_show_pvt(&env);

index = strtol(argv[2], NULL, 0);
dev = env_dev_get(&env, index);
if (!dev)
fprintf(stderr, "ERROR: Unknown device index \"%s\".\n", argv[2]);
err(1, "unknown device index \"%s\"", argv[2]);

dev_show_pvt(dev);
}
Expand Down