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

Upstream vale port type extraction #569

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions apps/vale-ctl/vale-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@
#include <libgen.h> /* basename */
#include <stdlib.h> /* atoi, free */

/* Text/UI versions of VALE port types to display. Type NaN is if
* we get a response type from the kernel outside the range we know
* how to interpret.
*/

static const char TXT_VALE_PORT_T_ERROR[] = "ERR";
static const char TXT_VALE_PORT_T_PHYS[] = "PHYS";
static const char TXT_VALE_PORT_T_STACK[] = "STACK";
static const char TXT_VALE_PORT_T_VIRT[] = "VIRT";
static const char TXT_VALE_PORT_T_NAN[] = "NaN";

static const char* vale_port_type_to_text(uint port_type) {
switch (port_type) {
case VALE_PORT_T_ERROR:
return TXT_VALE_PORT_T_ERROR;
case VALE_PORT_T_PHYS:
return TXT_VALE_PORT_T_PHYS;
case VALE_PORT_T_STACK:
return TXT_VALE_PORT_T_STACK;
case VALE_PORT_T_VIRT:
return TXT_VALE_PORT_T_VIRT;
default:
return TXT_VALE_PORT_T_NAN;
}
}

/* XXX cut and paste from pkt-gen.c because I'm not sure whether this
* program may include nm_util.h
*/
Expand Down Expand Up @@ -137,16 +163,16 @@ bdg_ctl(const char *name, int nr_cmd, int nr_arg, char *nmr_config, int nr_arg2)
ND("Unable to obtain info for %s", name);
perror(name);
} else
D("%s at bridge:%d port:%d", name, nmr.nr_arg1,
nmr.nr_arg2);
D("%s at bridge:%d port:%d type:%s", name, nmr.nr_arg1,
nmr.nr_arg2, vale_port_type_to_text(nmr.nr_arg3));
break;
}

/* scan all the bridges and ports */
nmr.nr_arg1 = nmr.nr_arg2 = 0;
for (; !ioctl(fd, NIOCGINFO, &nmr); nmr.nr_arg2++) {
D("bridge:%d port:%d %s", nmr.nr_arg1, nmr.nr_arg2,
nmr.nr_name);
D("bridge:%d port:%d type:%s %s", nmr.nr_arg1, nmr.nr_arg2,
vale_port_type_to_text(nmr.nr_arg3), nmr.nr_name);
nmr.nr_name[0] = '\0';
}

Expand Down
1 change: 1 addition & 0 deletions sys/dev/netmap/netmap_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ nmreq_to_legacy(struct nmreq_header *hdr, struct nmreq *nmr)
strlcpy(nmr->nr_name, hdr->nr_name, sizeof(nmr->nr_name));
nmr->nr_arg1 = req->nr_bridge_idx;
nmr->nr_arg2 = req->nr_port_idx;
nmr->nr_arg3 = req->nr_port_type;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is legacy API, and therefore can't be changed.

break;
}
case NETMAP_REQ_PORT_HDR_SET:
Expand Down
44 changes: 44 additions & 0 deletions sys/dev/netmap/netmap_vale.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,28 @@ netmap_vale_list(struct nmreq_header *hdr)
*/
if (!strcmp(vpna->up.name, hdr->nr_name)) {
req->nr_port_idx = i; /* port index */
/* VALE port type logic */
if (vpna->up.pdev &&
vpna->up.na_hostvp &&
vpna->up.na_vp) {
req->nr_port_type = VALE_PORT_T_PHYS;
} else if (!vpna->up.pdev &&
vpna->up.na_hostvp &&
vpna->up.na_vp) {
if (vpna->up.na_flags & NAF_HOST_RINGS)
req->nr_port_type = VALE_PORT_T_PHYS;
else
req->nr_port_type = VALE_PORT_T_STACK;
} else if (!vpna->up.pdev &&
!vpna->up.na_hostvp &&
vpna->up.na_vp) {
req->nr_port_type = VALE_PORT_T_VIRT;
} else {
D("Unknown VALE port %s with pdev: %p, hvp: %p, na_vp: %p",
vpna->up.name, vpna->up.pdev, vpna->up.na_hostvp,
vpna->up.na_vp);
req->nr_port_type = VALE_PORT_T_ERROR;
}
break;
}
}
Expand All @@ -373,6 +395,28 @@ netmap_vale_list(struct nmreq_header *hdr)
/* write back the VALE switch name */
strlcpy(hdr->nr_name, vpna->up.name,
sizeof(hdr->nr_name));
/* VALE port type logic */
if (vpna->up.pdev &&
vpna->up.na_hostvp &&
vpna->up.na_vp) {
req->nr_port_type = VALE_PORT_T_PHYS;
} else if (!vpna->up.pdev &&
vpna->up.na_hostvp &&
vpna->up.na_vp) {
if (vpna->up.na_flags & NAF_HOST_RINGS)
req->nr_port_type = VALE_PORT_T_PHYS;
else
req->nr_port_type = VALE_PORT_T_STACK;
} else if (!vpna->up.pdev &&
!vpna->up.na_hostvp &&
vpna->up.na_vp) {
req->nr_port_type = VALE_PORT_T_VIRT;
} else {
D("Unknown VALE port %s with pdev: %p, hvp: %p, na_vp: %p",
vpna->up.name, vpna->up.pdev, vpna->up.na_hostvp,
vpna->up.na_vp);
req->nr_port_type = VALE_PORT_T_ERROR;
}
error = 0;
goto out;
}
Expand Down
13 changes: 13 additions & 0 deletions sys/net/netmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,24 @@ struct nmreq_vale_detach {
* nr_reqtype: NETMAP_REQ_VALE_LIST
* List the ports of a VALE switch.
*/

/* Use the following port type values to indicate the type of port attached to
* the vale bridge
*/
enum {
VALE_PORT_T_ERROR = 0,
VALE_PORT_T_PHYS = 1,
VALE_PORT_T_STACK = 2,
VALE_PORT_T_VIRT = 3,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we distinguish between ephemeral vale ports and persistent vale ports (e.g. created with vale-ctl -n?)

};

struct nmreq_vale_list {
/* Name of the VALE port (valeXXX:YYY) or empty. */
uint16_t nr_bridge_idx;
uint16_t pad1;
uint32_t nr_port_idx;
/* Type of the VALE port */
uint8_t nr_port_type;
};

/*
Expand Down