Skip to content

Commit

Permalink
apps: fix multiple compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhk098 committed Oct 3, 2020
1 parent 924ed6a commit 985278a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 77 deletions.
4 changes: 2 additions & 2 deletions apps/bridge/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <unistd.h>
#include <libnetmap.h>

int verbose = 0;
static int verbose = 0;

static int do_abort = 0;
static int zerocopy = 1; /* enable zerocopy if possible */
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions apps/include/ctrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 20 additions & 19 deletions apps/lb/lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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];
Expand All @@ -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 {
Expand All @@ -192,7 +192,7 @@ struct group_des {
int custom_port;
};

struct group_des *groups;
static struct group_des *groups;

/* statistcs */
struct counters {
Expand All @@ -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)
Expand Down Expand Up @@ -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");
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down
52 changes: 26 additions & 26 deletions apps/lb/pkt_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -156,31 +156,31 @@ 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,
ntohs(udph->uh_dport) + 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:
Expand All @@ -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;
Expand All @@ -227,36 +227,36 @@ 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,
ntohs(udph->uh_dport) + 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:
Expand All @@ -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;

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit 985278a

Please sign in to comment.