From 985278a328a7519bd3801be320346f4b40da02dc Mon Sep 17 00:00:00 2001 From: jhk Date: Sat, 3 Oct 2020 15:12:30 +0200 Subject: [PATCH] apps: fix multiple compilation warnings --- apps/bridge/bridge.c | 4 ++-- apps/include/ctrs.h | 6 ++--- apps/lb/lb.c | 39 +++++++++++++++--------------- apps/lb/pkt_hash.c | 52 ++++++++++++++++++++-------------------- apps/nmreplay/nmreplay.c | 33 ++++++++++++------------- apps/pkt-gen/pkt-gen.c | 22 ++++++++--------- 6 files changed, 79 insertions(+), 77 deletions(-) diff --git a/apps/bridge/bridge.c b/apps/bridge/bridge.c index e826f2498..4c7290866 100644 --- a/apps/bridge/bridge.c +++ b/apps/bridge/bridge.c @@ -17,7 +17,7 @@ #include #include -int verbose = 0; +static int verbose = 0; static int do_abort = 0; static int zerocopy = 1; /* enable zerocopy if possible */ @@ -34,7 +34,7 @@ sigint_h(int sig) /* * how many packets on this set of queues ? */ -int +static int pkt_queued(struct nmport_d *d, int tx) { u_int i, tot = 0; diff --git a/apps/include/ctrs.h b/apps/include/ctrs.h index b8bb8c986..7e0265b48 100644 --- a/apps/include/ctrs.h +++ b/apps/include/ctrs.h @@ -20,12 +20,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/apps/lb/lb.c b/apps/lb/lb.c index eeffdbcdd..251d53fb0 100644 --- a/apps/lb/lb.c +++ b/apps/lb/lb.c @@ -91,7 +91,7 @@ struct compact_ipv6_hdr { #define BUF_REVOKE 150 #define STAT_MSG_MAXSIZE 1024 -struct { +static struct { char ifname[MAX_IFNAMELEN + 1]; char base_name[MAX_IFNAMELEN + 1]; int netmap_fd; @@ -117,7 +117,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) @@ -162,12 +162,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]; @@ -180,7 +180,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 { @@ -192,7 +192,7 @@ struct group_des { int custom_port; }; -struct group_des *groups; +static struct group_des *groups; /* statistcs */ struct counters { @@ -207,7 +207,7 @@ struct counters { #define COUNTERS_FULL 1 }; -struct counters counters_buf; +static struct counters counters_buf; static void * print_stats(void *arg) @@ -389,7 +389,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"); @@ -406,9 +406,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; @@ -460,7 +460,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; @@ -508,7 +509,8 @@ struct morefrag { * 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; @@ -939,7 +941,6 @@ int main(int argc, char **argv) */ 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]; @@ -970,7 +971,7 @@ int main(int argc, char **argv) for (i = 0; i < npipes; i++) { struct port_des *p = &ports[i]; struct overflow_queue *q = p->oq; - uint32_t j; + uint32_t k; int64_t lim; struct netmap_ring *ring; struct netmap_slot *slot; @@ -987,7 +988,7 @@ int main(int argc, char **argv) lim += ring->num_slots; 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[mf->shadow_head]; diff --git a/apps/lb/pkt_hash.c b/apps/lb/pkt_hash.c index ba7be296c..3071935e1 100644 --- a/apps/lb/pkt_hash.c +++ b/apps/lb/pkt_hash.c @@ -146,7 +146,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; @@ -156,19 +156,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, @@ -176,11 +176,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: @@ -206,7 +206,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; @@ -227,19 +227,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, @@ -247,16 +247,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: @@ -281,7 +281,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; @@ -306,18 +306,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: @@ -337,15 +337,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: @@ -373,15 +373,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 */ diff --git a/apps/nmreplay/nmreplay.c b/apps/nmreplay/nmreplay.c index c72a659d6..0fe0a1a76 100644 --- a/apps/nmreplay/nmreplay.c +++ b/apps/nmreplay/nmreplay.c @@ -433,7 +433,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; @@ -990,7 +990,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) @@ -1129,15 +1130,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: @@ -1252,10 +1253,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]); @@ -1289,7 +1290,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/apps/pkt-gen/pkt-gen.c b/apps/pkt-gen/pkt-gen.c index d78ebb3a2..897b558a4 100644 --- a/apps/pkt-gen/pkt-gen.c +++ b/apps/pkt-gen/pkt-gen.c @@ -184,14 +184,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 */ @@ -223,7 +223,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 */ @@ -237,7 +237,7 @@ struct ip_range { }; struct mac_range { - char *name; + const char *name; struct ether_addr start, end; }; @@ -302,7 +302,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 */ @@ -633,7 +633,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_register *nmr) { char *w, *tok; @@ -1255,7 +1255,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; @@ -2722,7 +2722,7 @@ main_thread(struct glob_arg *g) struct td_desc { int ty; - char *key; + const char *key; void *f; int default_burst; }; @@ -2742,7 +2742,7 @@ tap_alloc(char *dev) { struct ifreq ifr; int fd, err; - char *clonedev = TAP_CLONEDEV; + const char *clonedev = TAP_CLONEDEV; (void)err; (void)dev;