Skip to content

Commit

Permalink
Merge pull request appneta#114 from appneta/Bug_#113_vale_handle_unco…
Browse files Browse the repository at this point in the history
…nfiged

Report failure if NIOCREGIF returns zero memory size - closes appneta#113
  • Loading branch information
fklassen committed Jul 30, 2014
2 parents 42463c8 + b678108 commit fa30c7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
06/28/2014 Version 4.0.5beta2
- Proper error message when vale is unconfigured (#113)
- Avoid a netmap module debug message (#110)
- Add missing header to distribution (#108)

Expand Down
40 changes: 22 additions & 18 deletions src/common/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
size_t namelen;
u_int32_t nr_ringid = 0;
u_int32_t nr_flags = NR_REG_DEFAULT;
int is_default = 0;

assert(device);
assert(errbuf);
Expand Down Expand Up @@ -307,7 +308,8 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
break;

default: /* '\0', no suffix */
nr_flags = NR_REG_DEFAULT;
nr_flags = NR_REG_ALL_NIC;
is_default = 1;
break;
}

Expand All @@ -320,10 +322,6 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
nmr.nr_flags = nr_flags;
}

/* prevent a useless warning from the kernel module */
if (nr_flags == NR_REG_DEFAULT && sp->netmap_version >= 10)
nmr.nr_flags = NR_REG_ALL_NIC;

nmr.nr_version = sp->netmap_version;
memcpy(nmr.nr_name, ifname, namelen);
nmr.nr_name[namelen] = '\0';
Expand All @@ -341,12 +339,17 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
fflush(NULL);
sleep(1); /* ensure message prints when user is connected via ssh */


if (ioctl (sp->handle.fd, NIOCREGIF, &nmr)) {
snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Failure accessing netmap.\n"
"\tRequest for netmap version %u failed.\n\tCompiled netmap driver is version %u.\n\tError=%s\n",
sp->netmap_version, NETMAP_API, strerror(errno));
goto NETMAP_UP_FAILED;
goto NETMAP_IF_FAILED;
}

if (!nmr.nr_memsize) {
snprintf(errbuf, SENDPACKET_ERRBUF_SIZE, "Netmap interface '%s' not configured.\n",
device, NETMAP_API, strerror(errno));
goto NETMAP_IF_FAILED;
}

sp->mmap_size = nmr.nr_memsize;
Expand All @@ -373,8 +376,12 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
break;

case NR_REG_ALL_NIC:
sp->first_tx_ring = sp->cur_tx_ring = 0;
sp->last_tx_ring = nmr.nr_tx_rings - 1;
if (is_default) {
sp->first_tx_ring = sp->last_tx_ring = sp->cur_tx_ring = 0;
} else {
sp->first_tx_ring = sp->cur_tx_ring = 0;
sp->last_tx_ring = nmr.nr_tx_rings - 1;
}
break;

case NR_REG_SW:
Expand Down Expand Up @@ -418,21 +425,18 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
if (!sp->is_vale) {
if (nm_do_ioctl(sp, SIOCGIFFLAGS, 0) < 0)
goto NM_DO_IOCTL_FAILED;
}

if ((sp->if_flags & IFF_UP) == 0) {
dbgx(1, "%s is down, bringing up...", sp->device);
sp->if_flags |= IFF_UP;
}


if (!sp->is_vale) {
if ((sp->if_flags & IFF_RUNNING) == 0) {
dbgx(1, "sendpacket_open_netmap: %s is not running", sp->device);
snprintf (errbuf, SENDPACKET_ERRBUF_SIZE, "interface %s is not running - check cables\n", sp->device);
goto NETMAP_IF_NOT_RUNNING;
}

if ((sp->if_flags & IFF_UP) == 0) {
dbgx(1, "%s is down, bringing up...", sp->device);
sp->if_flags |= IFF_UP;
}

/* set promiscuous mode */
sp->if_flags |= IFF_PROMISC;
if (nm_do_ioctl(sp, SIOCSIFFLAGS, 0) < 0)
Expand Down Expand Up @@ -480,7 +484,7 @@ sendpacket_open_netmap(const char *device, char *errbuf) {
#if NETMAP_API < 10
ioctl(sp->handle.fd, NIOCUNREGIF, NULL);
#endif
NETMAP_UP_FAILED:
NETMAP_IF_FAILED:
NETMAP_IF_PARSE_FAIL:
close (sp->handle.fd);
OPEN_FAILED:
Expand Down

0 comments on commit fa30c7c

Please sign in to comment.