misc bugfixes:
- stdio.h is needed for fprint() - make memsize uint32_t to avoid errors due to overflow - honor the *XPOLL flagg in NIOCREGIF requests - mmap fails wit MAP_FAILED, not NULL. MFC after: 3 days
This commit is contained in:
parent
5c8c100428
commit
9225c8085b
@ -133,6 +133,7 @@ nm_ring_space(struct netmap_ring *ring)
|
||||
#ifndef HAVE_NETMAP_WITH_LIBS
|
||||
#define HAVE_NETMAP_WITH_LIBS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h> /* memset */
|
||||
@ -192,7 +193,7 @@ struct nm_desc {
|
||||
struct nm_desc *self; /* point to self if netmap. */
|
||||
int fd;
|
||||
void *mem;
|
||||
int memsize;
|
||||
uint32_t memsize;
|
||||
int done_mmap; /* set if mem is the result of mmap */
|
||||
struct netmap_if * const nifp;
|
||||
uint16_t first_tx_ring, last_tx_ring, cur_tx_ring;
|
||||
@ -404,8 +405,6 @@ nm_open(const char *ifname, const struct nmreq *req,
|
||||
errmsg = "invalid ringid";
|
||||
goto fail;
|
||||
}
|
||||
/* add the *XPOLL flags */
|
||||
nr_ringid |= new_flags & (NETMAP_NO_TX_POLL | NETMAP_DO_RX_POLL);
|
||||
|
||||
d = (struct nm_desc *)calloc(1, sizeof(*d));
|
||||
if (d == NULL) {
|
||||
@ -461,6 +460,9 @@ nm_open(const char *ifname, const struct nmreq *req,
|
||||
d->req.nr_flags = parent->req.nr_flags;
|
||||
}
|
||||
}
|
||||
/* add the *XPOLL flags */
|
||||
d->req.nr_ringid |= new_flags & (NETMAP_NO_TX_POLL | NETMAP_DO_RX_POLL);
|
||||
|
||||
if (ioctl(d->fd, NIOCREGIF, &d->req)) {
|
||||
errmsg = "NIOCREGIF failed";
|
||||
goto fail;
|
||||
@ -472,10 +474,11 @@ nm_open(const char *ifname, const struct nmreq *req,
|
||||
d->memsize = parent->memsize;
|
||||
d->mem = parent->mem;
|
||||
} else {
|
||||
/* XXX TODO: check if memsize is too large (or there is overflow) */
|
||||
d->memsize = d->req.nr_memsize;
|
||||
d->mem = mmap(0, d->memsize, PROT_WRITE | PROT_READ, MAP_SHARED,
|
||||
d->fd, 0);
|
||||
if (d->mem == NULL) {
|
||||
if (d->mem == MAP_FAILED) {
|
||||
errmsg = "mmap failed";
|
||||
goto fail;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user