aboutsummaryrefslogtreecommitdiff
path: root/tools/tools
diff options
context:
space:
mode:
authorVincenzo Maffione <vmaffione@FreeBSD.org>2020-10-03 13:19:48 +0000
committerVincenzo Maffione <vmaffione@FreeBSD.org>2020-10-03 13:19:48 +0000
commit7eb32dc8f003402de96c63dfe6609c57df74342f (patch)
treeca4edccc1f5585c9a1192ae845d31b98e9dad8bd /tools/tools
parentf7265157586a1fa983fb959824d5e701dcf4e4b5 (diff)
downloadsrc-7eb32dc8f003402de96c63dfe6609c57df74342f.tar.gz
src-7eb32dc8f003402de96c63dfe6609c57df74342f.zip
netmap: tools: fix several compiler warnings
MFC after: 1 week
Notes
Notes: svn path=/head/; revision=366393
Diffstat (limited to 'tools/tools')
-rw-r--r--tools/tools/netmap/Makefile2
-rw-r--r--tools/tools/netmap/bridge.c4
-rw-r--r--tools/tools/netmap/ctrs.h6
-rw-r--r--tools/tools/netmap/lb.c39
-rw-r--r--tools/tools/netmap/nmreplay.c33
-rw-r--r--tools/tools/netmap/pkt-gen.c25
-rw-r--r--tools/tools/netmap/pkt_hash.c52
7 files changed, 82 insertions, 79 deletions
diff --git a/tools/tools/netmap/Makefile b/tools/tools/netmap/Makefile
index 2c0e6f4a28b8..bc8ef6e8552b 100644
--- a/tools/tools/netmap/Makefile
+++ b/tools/tools/netmap/Makefile
@@ -21,6 +21,8 @@ LDFLAGS += -lm # used by nmreplay
.include <bsd.prog.mk>
.include <bsd.lib.mk>
+CFLAGS += -Wno-cast-align
+
all: $(PROGS)
pkt-gen: pkt-gen.o
diff --git a/tools/tools/netmap/bridge.c b/tools/tools/netmap/bridge.c
index 8c9bd574d84e..6f1a6dc598c8 100644
--- a/tools/tools/netmap/bridge.c
+++ b/tools/tools/netmap/bridge.c
@@ -14,7 +14,7 @@
#include <net/netmap_user.h>
#include <sys/poll.h>
-int verbose = 0;
+static int verbose = 0;
static int do_abort = 0;
static int zerocopy = 1; /* enable zerocopy if possible */
@@ -31,7 +31,7 @@ sigint_h(int sig)
/*
* how many packets on this set of queues ?
*/
-int
+static int
pkt_queued(struct nm_desc *d, int tx)
{
u_int i, tot = 0;
diff --git a/tools/tools/netmap/ctrs.h b/tools/tools/netmap/ctrs.h
index a41ae6853fbf..eb4c4c9d4bfd 100644
--- a/tools/tools/netmap/ctrs.h
+++ b/tools/tools/netmap/ctrs.h
@@ -18,12 +18,12 @@ struct my_ctrs {
* Caller has to make sure that the buffer is large enough.
*/
static const char *
-norm2(char *buf, double val, char *fmt, int normalize)
+norm2(char *buf, double val, const char *fmt, int normalize)
{
- char *units[] = { "", "K", "M", "G", "T" };
+ const char *units[] = { "", "K", "M", "G", "T" };
u_int i;
if (normalize)
- for (i = 0; val >=1000 && i < sizeof(units)/sizeof(char *) - 1; i++)
+ for (i = 0; val >=1000 && i < sizeof(units)/sizeof(const char *) - 1; i++)
val /= 1000;
else
i=0;
diff --git a/tools/tools/netmap/lb.c b/tools/tools/netmap/lb.c
index 771cf6f18082..b868835c6dc1 100644
--- a/tools/tools/netmap/lb.c
+++ b/tools/tools/netmap/lb.c
@@ -89,7 +89,7 @@ struct compact_ipv6_hdr {
#define BUF_REVOKE 100
#define STAT_MSG_MAXSIZE 1024
-struct {
+static struct {
char ifname[MAX_IFNAMELEN];
char base_name[MAX_IFNAMELEN];
int netmap_fd;
@@ -115,7 +115,7 @@ struct overflow_queue {
uint32_t size;
};
-struct overflow_queue *freeq;
+static struct overflow_queue *freeq;
static inline int
oq_full(struct overflow_queue *q)
@@ -160,12 +160,12 @@ oq_deq(struct overflow_queue *q)
static volatile int do_abort = 0;
-uint64_t dropped = 0;
-uint64_t forwarded = 0;
-uint64_t received_bytes = 0;
-uint64_t received_pkts = 0;
-uint64_t non_ip = 0;
-uint32_t freeq_n = 0;
+static uint64_t dropped = 0;
+static uint64_t forwarded = 0;
+static uint64_t received_bytes = 0;
+static uint64_t received_pkts = 0;
+static uint64_t non_ip = 0;
+static uint32_t freeq_n = 0;
struct port_des {
char interface[MAX_PORTNAMELEN];
@@ -178,7 +178,7 @@ struct port_des {
struct group_des *group;
};
-struct port_des *ports;
+static struct port_des *ports;
/* each group of pipes receives all the packets */
struct group_des {
@@ -190,7 +190,7 @@ struct group_des {
int custom_port;
};
-struct group_des *groups;
+static struct group_des *groups;
/* statistcs */
struct counters {
@@ -205,7 +205,7 @@ struct counters {
#define COUNTERS_FULL 1
};
-struct counters counters_buf;
+static struct counters counters_buf;
static void *
print_stats(void *arg)
@@ -387,7 +387,7 @@ static void sigint_h(int sig)
signal(SIGINT, SIG_DFL);
}
-void usage()
+static void usage()
{
printf("usage: lb [options]\n");
printf("where options are:\n");
@@ -404,9 +404,9 @@ void usage()
}
static int
-parse_pipes(char *spec)
+parse_pipes(const char *spec)
{
- char *end = index(spec, ':');
+ const char *end = index(spec, ':');
static int max_groups = 0;
struct group_des *g;
@@ -458,7 +458,8 @@ parse_pipes(char *spec)
}
/* complete the initialization of the groups data structure */
-void init_groups(void)
+static void
+init_groups(void)
{
int i, j, t = 0;
struct group_des *g = NULL;
@@ -484,7 +485,8 @@ void init_groups(void)
* chain headed by g.
* Return a free buffer.
*/
-uint32_t forward_packet(struct group_des *g, struct netmap_slot *rs)
+static uint32_t
+forward_packet(struct group_des *g, struct netmap_slot *rs)
{
uint32_t hash = rs->ptr;
uint32_t output_port = hash % g->nports;
@@ -886,7 +888,6 @@ run:
*/
for (i = glob_arg.num_groups - 1U; i > 0; i--) {
struct group_des *g = &groups[i - 1];
- int j;
for (j = 0; j < g->nports; j++) {
struct port_des *p = &g->ports[j];
@@ -917,7 +918,7 @@ run:
for (i = 0; i < npipes; i++) {
struct port_des *p = &ports[i];
struct overflow_queue *q = p->oq;
- uint32_t j, lim;
+ uint32_t k, lim;
struct netmap_ring *ring;
struct netmap_slot *slot;
@@ -929,7 +930,7 @@ run:
continue;
if (q->n < lim)
lim = q->n;
- for (j = 0; j < lim; j++) {
+ for (k = 0; k < lim; k++) {
struct netmap_slot s = oq_deq(q), tmp;
tmp.ptr = 0;
slot = &ring->slot[ring->head];
diff --git a/tools/tools/netmap/nmreplay.c b/tools/tools/netmap/nmreplay.c
index d4857a3f7273..9736f8910612 100644
--- a/tools/tools/netmap/nmreplay.c
+++ b/tools/tools/netmap/nmreplay.c
@@ -431,7 +431,7 @@ readpcap(const char *fn)
enum my_pcap_mode { PM_NONE, PM_FAST, PM_FIXED, PM_REAL };
-int verbose = 0;
+static int verbose = 0;
static int do_abort = 0;
@@ -988,7 +988,8 @@ usage(void)
static char **
split_arg(const char *src, int *_ac)
{
- char *my = NULL, **av = NULL, *seps = " \t\r\n,";
+ char *my = NULL, **av = NULL;
+ const char *seps = " \t\r\n,";
int l, i, ac; /* number of entries */
if (!src)
@@ -1127,15 +1128,15 @@ main(int argc, char **argv)
/* set default values */
for (i = 0; i < N_OPTS; i++) {
- struct _qs *q = &bp[i].q;
-
- q->burst = 128;
- q->c_delay.optarg = "0";
- q->c_delay.run = null_run_fn;
- q->c_loss.optarg = "0";
- q->c_loss.run = null_run_fn;
- q->c_bw.optarg = "0";
- q->c_bw.run = null_run_fn;
+ struct _qs *qs = &bp[i].q;
+
+ qs->burst = 128;
+ qs->c_delay.optarg = "0";
+ qs->c_delay.run = null_run_fn;
+ qs->c_loss.optarg = "0";
+ qs->c_loss.run = null_run_fn;
+ qs->c_bw.optarg = "0";
+ qs->c_bw.run = null_run_fn;
}
// Options:
@@ -1250,10 +1251,10 @@ main(int argc, char **argv)
/* apply commands */
for (i = 0; i < N_OPTS; i++) { /* once per queue */
- struct _qs *q = &bp[i].q;
- err += cmd_apply(delay_cfg, d[i], q, &q->c_delay);
- err += cmd_apply(bw_cfg, b[i], q, &q->c_bw);
- err += cmd_apply(loss_cfg, l[i], q, &q->c_loss);
+ struct _qs *qs = &bp[i].q;
+ err += cmd_apply(delay_cfg, d[i], qs, &qs->c_delay);
+ err += cmd_apply(bw_cfg, b[i], qs, &qs->c_bw);
+ err += cmd_apply(loss_cfg, l[i], qs, &qs->c_loss);
}
pthread_create(&bp[0].cons_tid, NULL, nmreplay_main, (void*)&bp[0]);
@@ -1287,7 +1288,7 @@ main(int argc, char **argv)
* the final entry has s = NULL.
*/
struct _sm { /* string and multiplier */
- char *s;
+ const char *s;
double m;
};
diff --git a/tools/tools/netmap/pkt-gen.c b/tools/tools/netmap/pkt-gen.c
index 6b66d28a52e5..56fbb57cdd9a 100644
--- a/tools/tools/netmap/pkt-gen.c
+++ b/tools/tools/netmap/pkt-gen.c
@@ -42,7 +42,6 @@
#define NETMAP_WITH_LIBS
#include <net/netmap_user.h>
-
#include <ctype.h> // isprint()
#include <unistd.h> // sysconf()
#include <sys/poll.h>
@@ -179,14 +178,14 @@ static inline void CPU_SET(uint32_t i, cpuset_t *p)
do {struct timespec t0 = {0,0}; *(b) = t0; } while (0)
#endif /* __APPLE__ */
-const char *default_payload="netmap pkt-gen DIRECT payload\n"
+static const char *default_payload = "netmap pkt-gen DIRECT payload\n"
"http://info.iet.unipi.it/~luigi/netmap/ ";
-const char *indirect_payload="netmap pkt-gen indirect payload\n"
+static const char *indirect_payload = "netmap pkt-gen indirect payload\n"
"http://info.iet.unipi.it/~luigi/netmap/ ";
-int verbose = 0;
-int normalize = 1;
+static int verbose = 0;
+static int normalize = 1;
#define VIRT_HDR_1 10 /* length of a base vnet-hdr */
#define VIRT_HDR_2 12 /* length of the extenede vnet-hdr */
@@ -218,7 +217,7 @@ struct pkt {
((af) == AF_INET ? (p)->ipv4.f: (p)->ipv6.f)
struct ip_range {
- char *name;
+ const char *name;
union {
struct {
uint32_t start, end; /* same as struct in_addr */
@@ -232,7 +231,7 @@ struct ip_range {
};
struct mac_range {
- char *name;
+ const char *name;
struct ether_addr start, end;
};
@@ -295,7 +294,7 @@ struct glob_arg {
int td_type;
void *mmap_addr;
char ifname[MAX_IFNAMELEN];
- char *nmr_config;
+ const char *nmr_config;
int dummy_send;
int virt_header; /* send also the virt_header */
char *packet_file; /* -P option */
@@ -620,7 +619,7 @@ system_ncpus(void)
* If there is no 4th number, then the 3rd is assigned to both #tx-rings
* and #rx-rings.
*/
-int
+static int
parse_nmr_config(const char* conf, struct nmreq *nmr)
{
char *w, *tok;
@@ -727,7 +726,7 @@ checksum(const void *data, uint16_t len, uint32_t sum)
/* Checksum all the pairs of bytes first... */
for (i = 0; i < (len & ~1U); i += 2) {
- sum += (u_int16_t)ntohs(*((u_int16_t *)(addr + i)));
+ sum += (uint16_t)ntohs(*((const uint16_t *)(addr + i)));
if (sum > 0xFFFF)
sum -= 0xFFFF;
}
@@ -1241,7 +1240,7 @@ send_packets(struct netmap_ring *ring, struct pkt *pkt, void *frame,
/*
* Index of the highest bit set
*/
-uint32_t
+static uint32_t
msb64(uint64_t x)
{
uint64_t m = 1ULL << 63;
@@ -2695,7 +2694,7 @@ main_thread(struct glob_arg *g)
struct td_desc {
int ty;
- char *key;
+ const char *key;
void *f;
int default_burst;
};
@@ -2715,7 +2714,7 @@ tap_alloc(char *dev)
{
struct ifreq ifr;
int fd, err;
- char *clonedev = TAP_CLONEDEV;
+ const char *clonedev = TAP_CLONEDEV;
(void)err;
(void)dev;
diff --git a/tools/tools/netmap/pkt_hash.c b/tools/tools/netmap/pkt_hash.c
index 73bd023d81ac..949a7e9a5370 100644
--- a/tools/tools/netmap/pkt_hash.c
+++ b/tools/tools/netmap/pkt_hash.c
@@ -145,7 +145,7 @@ static uint32_t decode_gre_hash(const uint8_t *, uint8_t, uint8_t);
** Parser + hash function for the IPv4 packet
**/
static uint32_t
-decode_ip_n_hash(struct ip *iph, uint8_t hash_split, uint8_t seed)
+decode_ip_n_hash(const struct ip *iph, uint8_t hash_split, uint8_t seed)
{
uint32_t rc = 0;
@@ -155,19 +155,19 @@ decode_ip_n_hash(struct ip *iph, uint8_t hash_split, uint8_t seed)
ntohs(0xFFFD) + seed,
ntohs(0xFFFE) + seed);
} else {
- struct tcphdr *tcph = NULL;
- struct udphdr *udph = NULL;
+ const struct tcphdr *tcph = NULL;
+ const struct udphdr *udph = NULL;
switch (iph->ip_p) {
case IPPROTO_TCP:
- tcph = (struct tcphdr *)((uint8_t *)iph + (iph->ip_hl<<2));
+ tcph = (const struct tcphdr *)((const uint8_t *)iph + (iph->ip_hl<<2));
rc = sym_hash_fn(ntohl(iph->ip_src.s_addr),
ntohl(iph->ip_dst.s_addr),
ntohs(tcph->th_sport) + seed,
ntohs(tcph->th_dport) + seed);
break;
case IPPROTO_UDP:
- udph = (struct udphdr *)((uint8_t *)iph + (iph->ip_hl<<2));
+ udph = (const struct udphdr *)((const uint8_t *)iph + (iph->ip_hl<<2));
rc = sym_hash_fn(ntohl(iph->ip_src.s_addr),
ntohl(iph->ip_dst.s_addr),
ntohs(udph->uh_sport) + seed,
@@ -175,11 +175,11 @@ decode_ip_n_hash(struct ip *iph, uint8_t hash_split, uint8_t seed)
break;
case IPPROTO_IPIP:
/* tunneling */
- rc = decode_ip_n_hash((struct ip *)((uint8_t *)iph + (iph->ip_hl<<2)),
+ rc = decode_ip_n_hash((const struct ip *)((const uint8_t *)iph + (iph->ip_hl<<2)),
hash_split, seed);
break;
case IPPROTO_GRE:
- rc = decode_gre_hash((uint8_t *)iph + (iph->ip_hl<<2),
+ rc = decode_gre_hash((const uint8_t *)iph + (iph->ip_hl<<2),
hash_split, seed);
break;
case IPPROTO_ICMP:
@@ -205,7 +205,7 @@ decode_ip_n_hash(struct ip *iph, uint8_t hash_split, uint8_t seed)
** Parser + hash function for the IPv6 packet
**/
static uint32_t
-decode_ipv6_n_hash(struct ip6_hdr *ipv6h, uint8_t hash_split, uint8_t seed)
+decode_ipv6_n_hash(const struct ip6_hdr *ipv6h, uint8_t hash_split, uint8_t seed)
{
uint32_t saddr, daddr;
uint32_t rc = 0;
@@ -226,19 +226,19 @@ decode_ipv6_n_hash(struct ip6_hdr *ipv6h, uint8_t hash_split, uint8_t seed)
ntohs(0xFFFD) + seed,
ntohs(0xFFFE) + seed);
} else {
- struct tcphdr *tcph = NULL;
- struct udphdr *udph = NULL;
+ const struct tcphdr *tcph = NULL;
+ const struct udphdr *udph = NULL;
switch(ntohs(ipv6h->ip6_ctlun.ip6_un1.ip6_un1_nxt)) {
case IPPROTO_TCP:
- tcph = (struct tcphdr *)(ipv6h + 1);
+ tcph = (const struct tcphdr *)(ipv6h + 1);
rc = sym_hash_fn(ntohl(saddr),
ntohl(daddr),
ntohs(tcph->th_sport) + seed,
ntohs(tcph->th_dport) + seed);
break;
case IPPROTO_UDP:
- udph = (struct udphdr *)(ipv6h + 1);
+ udph = (const struct udphdr *)(ipv6h + 1);
rc = sym_hash_fn(ntohl(saddr),
ntohl(daddr),
ntohs(udph->uh_sport) + seed,
@@ -246,16 +246,16 @@ decode_ipv6_n_hash(struct ip6_hdr *ipv6h, uint8_t hash_split, uint8_t seed)
break;
case IPPROTO_IPIP:
/* tunneling */
- rc = decode_ip_n_hash((struct ip *)(ipv6h + 1),
+ rc = decode_ip_n_hash((const struct ip *)(ipv6h + 1),
hash_split, seed);
break;
case IPPROTO_IPV6:
/* tunneling */
- rc = decode_ipv6_n_hash((struct ip6_hdr *)(ipv6h + 1),
+ rc = decode_ipv6_n_hash((const struct ip6_hdr *)(ipv6h + 1),
hash_split, seed);
break;
case IPPROTO_GRE:
- rc = decode_gre_hash((uint8_t *)(ipv6h + 1), hash_split, seed);
+ rc = decode_gre_hash((const uint8_t *)(ipv6h + 1), hash_split, seed);
break;
case IPPROTO_ICMP:
case IPPROTO_ESP:
@@ -280,7 +280,7 @@ decode_ipv6_n_hash(struct ip6_hdr *ipv6h, uint8_t hash_split, uint8_t seed)
* * (See decode_vlan_n_hash & pkt_hdr_hash functions).
* */
static uint32_t
-decode_others_n_hash(struct ether_header *ethh, uint8_t seed)
+decode_others_n_hash(const struct ether_header *ethh, uint8_t seed)
{
uint32_t saddr, daddr, rc;
@@ -305,18 +305,18 @@ decode_others_n_hash(struct ether_header *ethh, uint8_t seed)
** Parser + hash function for VLAN packet
**/
static inline uint32_t
-decode_vlan_n_hash(struct ether_header *ethh, uint8_t hash_split, uint8_t seed)
+decode_vlan_n_hash(const struct ether_header *ethh, uint8_t hash_split, uint8_t seed)
{
uint32_t rc = 0;
- struct vlanhdr *vhdr = (struct vlanhdr *)(ethh + 1);
+ const struct vlanhdr *vhdr = (const struct vlanhdr *)(ethh + 1);
switch (ntohs(vhdr->proto)) {
case ETHERTYPE_IP:
- rc = decode_ip_n_hash((struct ip *)(vhdr + 1),
+ rc = decode_ip_n_hash((const struct ip *)(vhdr + 1),
hash_split, seed);
break;
case ETHERTYPE_IPV6:
- rc = decode_ipv6_n_hash((struct ip6_hdr *)(vhdr + 1),
+ rc = decode_ipv6_n_hash((const struct ip6_hdr *)(vhdr + 1),
hash_split, seed);
break;
case ETHERTYPE_ARP:
@@ -336,15 +336,15 @@ uint32_t
pkt_hdr_hash(const unsigned char *buffer, uint8_t hash_split, uint8_t seed)
{
uint32_t rc = 0;
- struct ether_header *ethh = (struct ether_header *)buffer;
+ const struct ether_header *ethh = (const struct ether_header *)buffer;
switch (ntohs(ethh->ether_type)) {
case ETHERTYPE_IP:
- rc = decode_ip_n_hash((struct ip *)(ethh + 1),
+ rc = decode_ip_n_hash((const struct ip *)(ethh + 1),
hash_split, seed);
break;
case ETHERTYPE_IPV6:
- rc = decode_ipv6_n_hash((struct ip6_hdr *)(ethh + 1),
+ rc = decode_ipv6_n_hash((const struct ip6_hdr *)(ethh + 1),
hash_split, seed);
break;
case ETHERTYPE_VLAN:
@@ -372,15 +372,15 @@ decode_gre_hash(const uint8_t *grehdr, uint8_t hash_split, uint8_t seed)
!!(*grehdr & 2) + /* Routing */
!!(*grehdr & 4) + /* Key */
!!(*grehdr & 8)); /* Sequence Number */
- uint16_t proto = ntohs(*(uint16_t *)(void *)(grehdr + 2));
+ uint16_t proto = ntohs(*(const uint16_t *)(const void *)(grehdr + 2));
switch (proto) {
case ETHERTYPE_IP:
- rc = decode_ip_n_hash((struct ip *)(grehdr + len),
+ rc = decode_ip_n_hash((const struct ip *)(grehdr + len),
hash_split, seed);
break;
case ETHERTYPE_IPV6:
- rc = decode_ipv6_n_hash((struct ip6_hdr *)(grehdr + len),
+ rc = decode_ipv6_n_hash((const struct ip6_hdr *)(grehdr + len),
hash_split, seed);
break;
case 0x6558: /* Transparent Ethernet Bridging */