Repository : ssh://git@diktynna/batctl On branches: main,main
commit 0c1d7753e35f8996c7c255689992db7f63f59f1e Author: Sven Eckelmann sven@narfation.org Date: Sun Oct 20 11:24:03 2024 +0200
batctl: Apply checkpatch suggestions
Signed-off-by: Sven Eckelmann sven@narfation.org
0c1d7753e35f8996c7c255689992db7f63f59f1e allocate.h | 1 - backbonetable.c | 2 +- bat-hosts.c | 11 ++--- bat-hosts.h | 4 +- bisect_iv.c | 144 +++++++++++++++++++++++++++----------------------------- claimtable.c | 4 +- dat_cache.c | 2 +- debug.c | 8 ++-- debug.h | 2 +- functions.c | 7 ++- gateways.c | 2 +- genl_json.c | 18 +++---- gw_mode.c | 7 +-- hash.c | 45 +++++++----------- hash.h | 3 +- icmp_helper.c | 1 - interface.c | 3 +- 17 files changed, 119 insertions(+), 145 deletions(-)
diff --git a/allocate.h b/allocate.h index 1792866..22f1445 100644 --- a/allocate.h +++ b/allocate.h @@ -6,7 +6,6 @@ * License-Filename: LICENSES/preferred/GPL-2.0 */
- #ifndef _BATCTL_ALLOCATE_H #define _BATCTL_ALLOCATE_H
diff --git a/backbonetable.c b/backbonetable.c index db4b4ba..0408b45 100644 --- a/backbonetable.c +++ b/backbonetable.c @@ -31,7 +31,7 @@ static const int bla_backbone_mandatory[] = {
static int bla_backbone_callback(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); int last_seen_msecs, last_seen_secs; struct print_opts *opts = arg; diff --git a/bat-hosts.c b/bat-hosts.c index 54fb56f..a422d85 100644 --- a/bat-hosts.c +++ b/bat-hosts.c @@ -7,7 +7,6 @@ */
- #include <stdint.h> #include <stdio.h> #include <limits.h> @@ -21,11 +20,9 @@ #include "hash.h" #include "functions.h"
- -static struct hashtable_t *host_hash = NULL; +static struct hashtable_t *host_hash; const char *bat_hosts_path[3] = {"/etc/bat-hosts", "~/bat-hosts", "bat-hosts"};
- static int compare_mac(void *data1, void *data2) { return (memcmp(data1, data2, sizeof(struct ether_addr)) == 0 ? 1 : 0); @@ -33,7 +30,7 @@ static int compare_mac(void *data1, void *data2)
static int choose_mac(void *data, int32_t size) { - unsigned char *key= data; + unsigned char *key = data; uint32_t hash = 0, m_size = sizeof(struct ether_addr); size_t i;
@@ -176,8 +173,8 @@ void bat_hosts_init(int read_opt) for (i = 0; i < locations; i++) { strcpy(confdir, "");
- if (strlen(bat_hosts_path[i]) >= 2 - && bat_hosts_path[i][0] == '~' && bat_hosts_path[i][1] == '/') { + if (strlen(bat_hosts_path[i]) >= 2 && + bat_hosts_path[i][0] == '~' && bat_hosts_path[i][1] == '/') { if (!homedir) continue;
diff --git a/bat-hosts.h b/bat-hosts.h index 7312ba8..a0432f1 100644 --- a/bat-hosts.h +++ b/bat-hosts.h @@ -7,7 +7,6 @@ */
- #ifndef _BATCTL_BAT_HOSTS_H #define _BATCTL_BAT_HOSTS_H
@@ -16,11 +15,10 @@ #define HOST_NAME_MAX_LEN 50 #define CONF_DIR_LEN 256
- struct bat_host { struct ether_addr mac_addr; char name[HOST_NAME_MAX_LEN]; -} __attribute__((packed)); +} __attribute__((__packed__));
void bat_hosts_init(int read_opt); struct bat_host *bat_hosts_find_by_name(char *name); diff --git a/bisect_iv.c b/bisect_iv.c index fc66367..3f9b24b 100644 --- a/bisect_iv.c +++ b/bisect_iv.c @@ -21,8 +21,8 @@ #include "main.h" #include "functions.h"
-static struct hashtable_t *node_hash = NULL; -static struct bat_node *curr_bat_node = NULL; +static struct hashtable_t *node_hash; +static struct bat_node *curr_bat_node;
static void bisect_iv_usage(void) { @@ -44,7 +44,7 @@ static int compare_name(void *data1, void *data2)
static int choose_name(void *data, int32_t size) { - unsigned char *key= data; + unsigned char *key = data; uint32_t hash = 0, m_size = NAME_LEN - 1; size_t i;
@@ -280,8 +280,8 @@ static int routing_table_new(char *orig, char *next_hop, char *old_next_hop, cha
if (rt_table->num_entries != prev_rt_table->num_entries) { fprintf(stderr, - "Found a delete entry of orig '%s' but no existing record - skipping", - orig); + "Found a delete entry of orig '%s' but no existing record - skipping", + orig); goto rt_hist_free; }
@@ -512,7 +512,7 @@ static int parse_log_file(char *file_path) continue; }
-// fprintf(stderr, "received packet (line %i): neigh: '%s', iface_addr: '%s', orig: '%s', prev_sender: '%s', seqno: %i, tq: %i, ttl: %i\n", line_count, neigh, iface_addr, orig, prev_sender, seqno, tq, ttl); +// fprintf(stderr, "received packet (line %i): neigh: '%s', iface_addr: '%s', orig: '%s', prev_sender: '%s', seqno: %i, tq: %i, ttl: %i\n", line_count, neigh, iface_addr, orig, prev_sender, seqno, tq, ttl);
res = seqno_event_new(iface_addr, orig, prev_sender, neigh, seqno, tq, ttl); if (res < 1) @@ -521,7 +521,6 @@ static int parse_log_file(char *file_path) } else if (strstr(start_ptr, "Adding route towards") || strstr(start_ptr, "Changing route towards") || strstr(start_ptr, "Deleting route towards")) { - rt_flag = RT_FLAG_UPDATE; max = 12;
@@ -563,16 +562,16 @@ static int parse_log_file(char *file_path) } }
-// printf("route (file: %s, line %i): orig: '%s', neigh: '%s', prev_sender: '%s'\n", -// file_path, line_count, orig, neigh, prev_sender); +// printf("route (file: %s, line %i): orig: '%s', neigh: '%s', prev_sender: '%s'\n", +// file_path, line_count, orig, neigh, prev_sender);
if (((rt_flag == RT_FLAG_ADD) && (!neigh)) || ((rt_flag == RT_FLAG_UPDATE) && (!prev_sender)) || ((rt_flag == RT_FLAG_DELETE) && (!orig))) { fprintf(stderr, "Broken '%s route' line found - skipping [file: %s, line: %i]\n", - (rt_flag == RT_FLAG_UPDATE ? "changing" : - (rt_flag == RT_FLAG_ADD ? "adding" : "deleting")), - file_path, line_count); + (rt_flag == RT_FLAG_UPDATE ? "changing" : + (rt_flag == RT_FLAG_ADD ? "adding" : "deleting")), + file_path, line_count); continue; }
@@ -582,7 +581,7 @@ static int parse_log_file(char *file_path) } }
-// printf("File '%s' parsed (lines: %i)\n", file_path, line_count); +// printf("File '%s' parsed (lines: %i)\n", file_path, line_count); fclose(fd); curr_bat_node = NULL; return 1; @@ -618,7 +617,7 @@ static struct rt_hist *get_rt_hist_by_node_seqno(struct bat_node *bat_node, stru }
static int print_rt_path_at_seqno(struct bat_node *src_node, struct bat_node *dst_node, - struct bat_node *next_hop, long long seqno, long long seqno_rand, int read_opt) + struct bat_node *next_hop, long long seqno, long long seqno_rand, int read_opt) { struct bat_node *next_hop_tmp; struct orig_event *orig_event; @@ -626,7 +625,7 @@ static int print_rt_path_at_seqno(struct bat_node *src_node, struct bat_node *ds char curr_loop_magic[LOOP_MAGIC_LEN];
snprintf(curr_loop_magic, sizeof(curr_loop_magic), "%s%s%lli%lli", src_node->name, - dst_node->name, seqno, seqno_rand); + dst_node->name, seqno, seqno_rand);
printf("Path towards %s (seqno %lli ", get_name_by_macstr(dst_node->name, read_opt), seqno); @@ -679,8 +678,8 @@ out: }
static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_node, - struct bat_node *curr_node, long long seqno_min, long long seqno_max, - long long seqno_rand, int read_opt) + struct bat_node *curr_node, long long seqno_min, long long seqno_max, + long long seqno_rand, int read_opt) { struct orig_event *orig_event; struct rt_hist *rt_hist, *rt_hist_tmp; @@ -700,13 +699,13 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_
if (rt_hist) print_rt_path_at_seqno(src_node, dst_node, rt_hist->next_hop, - seqno_max, seqno_rand, read_opt); + seqno_max, seqno_rand, read_opt); return 0; }
snprintf(curr_loop_magic, sizeof(curr_loop_magic), "%s%s%lli%lli", - src_node->name, dst_node->name, - seqno_min_tmp, seqno_rand); + src_node->name, dst_node->name, + seqno_min_tmp, seqno_rand);
orig_event = orig_event_get_by_ptr(curr_node, dst_node); if (!orig_event) @@ -728,11 +727,11 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_ /* we are running in a loop */ if (memcmp(curr_loop_magic, rt_hist->loop_magic, LOOP_MAGIC_LEN) == 0) { rt_hist_tmp = get_rt_hist_by_node_seqno(src_node, dst_node, - rt_hist->seqno_event->seqno); + rt_hist->seqno_event->seqno);
if (rt_hist_tmp) print_rt_path_at_seqno(src_node, dst_node, rt_hist_tmp->next_hop, - rt_hist->seqno_event->seqno, seqno_rand, read_opt); + rt_hist->seqno_event->seqno, seqno_rand, read_opt); goto loop; }
@@ -744,8 +743,8 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_ get_name_by_macstr(curr_node->name, read_opt)); */
res = find_rt_table_change(src_node, dst_node, rt_hist->next_hop, - seqno_min_tmp, rt_hist->seqno_event->seqno, - seqno_rand, read_opt); + seqno_min_tmp, rt_hist->seqno_event->seqno, + seqno_rand, read_opt);
seqno_min_tmp = rt_hist->seqno_event->seqno + 1;
@@ -763,7 +762,7 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_ continue;
print_rt_path_at_seqno(src_node, dst_node, rt_hist_tmp->next_hop, - rt_hist->seqno_event->seqno, seqno_rand, read_opt); + rt_hist->seqno_event->seqno, seqno_rand, read_opt); }
/** @@ -776,7 +775,7 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_
if (rt_hist_tmp) print_rt_path_at_seqno(src_node, dst_node, rt_hist_tmp->next_hop, - seqno_min, seqno_rand, read_opt); + seqno_min, seqno_rand, read_opt);
/* no need to print the path twice */ if (seqno_min == seqno_max) @@ -796,7 +795,7 @@ static int find_rt_table_change(struct bat_node *src_node, struct bat_node *dst_
if (rt_hist) return find_rt_table_change(src_node, dst_node, rt_hist->next_hop, - seqno_min_tmp, seqno_max, seqno_rand, read_opt); + seqno_min_tmp, seqno_max, seqno_rand, read_opt);
out: return -1; @@ -856,14 +855,14 @@ static void loop_detection(char *loop_orig, long long seqno_min, long long seqno /* we might have no log file from this node */ if (list_empty(&orig_event->event_list)) { fprintf(stderr, "No seqno data of originator '%s' - skipping\n", - get_name_by_macstr(orig_event->orig_node->name, read_opt)); + get_name_by_macstr(orig_event->orig_node->name, read_opt)); continue; }
/* or routing tables */ if (list_empty(&orig_event->rt_hist_list)) { fprintf(stderr, "No routing history of originator '%s' - skipping\n", - get_name_by_macstr(orig_event->orig_node->name, read_opt)); + get_name_by_macstr(orig_event->orig_node->name, read_opt)); continue; }
@@ -891,7 +890,7 @@ static void loop_detection(char *loop_orig, long long seqno_min, long long seqno
if (rt_hist->flags == RT_FLAG_DELETE) { printf("Path towards %s deleted (originator timeout)\n", - get_name_by_macstr(rt_hist->seqno_event->orig->name, read_opt)); + get_name_by_macstr(rt_hist->seqno_event->orig->name, read_opt)); continue; }
@@ -901,9 +900,9 @@ static void loop_detection(char *loop_orig, long long seqno_min, long long seqno (rt_hist->seqno_event->seqno != prev_rt_hist->seqno_event->seqno)) { if (rt_hist->seqno_event->seqno < prev_rt_hist->seqno_event->seqno) { fprintf(stderr, - "Smaller seqno (%lli) than previously received seqno (%lli) of orig %s triggered routing table change - skipping recursive check\n", - rt_hist->seqno_event->seqno, prev_rt_hist->seqno_event->seqno, - get_name_by_macstr(rt_hist->seqno_event->orig->name, read_opt)); + "Smaller seqno (%lli) than previously received seqno (%lli) of orig %s triggered routing table change - skipping recursive check\n", + rt_hist->seqno_event->seqno, prev_rt_hist->seqno_event->seqno, + get_name_by_macstr(rt_hist->seqno_event->orig->name, read_opt)); goto validate_path; }
@@ -919,10 +918,10 @@ static void loop_detection(char *loop_orig, long long seqno_min, long long seqno get_name_by_macstr(prev_rt_hist->next_hop->name, read_opt)); */
res = find_rt_table_change(bat_node, rt_hist->seqno_event->orig, - prev_rt_hist->next_hop, - prev_rt_hist->seqno_event->seqno + 1, - rt_hist->seqno_event->seqno, - seqno_count, read_opt); + prev_rt_hist->next_hop, + prev_rt_hist->seqno_event->seqno + 1, + rt_hist->seqno_event->seqno, + seqno_count, read_opt);
if (res != -2) continue; @@ -930,47 +929,47 @@ static void loop_detection(char *loop_orig, long long seqno_min, long long seqno
validate_path: print_rt_path_at_seqno(bat_node, rt_hist->seqno_event->orig, rt_hist->next_hop, - rt_hist->seqno_event->seqno, seqno_count, read_opt); + rt_hist->seqno_event->seqno, seqno_count, read_opt); } } } }
static void seqno_trace_print_neigh(struct seqno_trace_neigh *seqno_trace_neigh, - struct seqno_event *seqno_event_parent, - int num_sisters, char *head, int read_opt) + struct seqno_event *seqno_event_parent, + int num_sisters, char *head, int read_opt) { char new_head[MAX_LINE]; int i;
printf("%s%s- %s [tq: %i, ttl: %i", head, - (strlen(head) == 1 ? "" : num_sisters == 0 ? "\" : "|"), - get_name_by_macstr(seqno_trace_neigh->bat_node->name, read_opt), - seqno_trace_neigh->seqno_event->tq, - seqno_trace_neigh->seqno_event->ttl); + (strlen(head) == 1 ? "" : num_sisters == 0 ? "\" : "|"), + get_name_by_macstr(seqno_trace_neigh->bat_node->name, read_opt), + seqno_trace_neigh->seqno_event->tq, + seqno_trace_neigh->seqno_event->ttl);
printf(", neigh: %s", get_name_by_macstr(seqno_trace_neigh->seqno_event->neigh->name, read_opt)); printf(", prev_sender: %s]", get_name_by_macstr(seqno_trace_neigh->seqno_event->prev_sender->name, read_opt));
if ((seqno_event_parent) && - (seqno_trace_neigh->seqno_event->tq > seqno_event_parent->tq)) + (seqno_trace_neigh->seqno_event->tq > seqno_event_parent->tq)) printf(" TQ UP!\n"); else printf("\n");
for (i = 0; i < seqno_trace_neigh->num_neighbors; i++) { snprintf(new_head, sizeof(new_head), "%s%s", - (strlen(head) > 1 ? head : num_sisters == 0 ? " " : head), - (strlen(head) == 1 ? " " : - num_sisters == 0 ? " " : "| ")); + (strlen(head) > 1 ? head : num_sisters == 0 ? " " : head), + (strlen(head) == 1 ? " " : + num_sisters == 0 ? " " : "| "));
seqno_trace_print_neigh(seqno_trace_neigh->seqno_trace_neigh[i], seqno_trace_neigh->seqno_event, - seqno_trace_neigh->num_neighbors - i - 1, new_head, read_opt); + seqno_trace_neigh->num_neighbors - i - 1, new_head, read_opt); } }
static void seqno_trace_print(struct list_head *trace_list, char *trace_orig, - long long seqno_min, long long seqno_max, char *filter_orig, int read_opt) + long long seqno_min, long long seqno_max, char *filter_orig, int read_opt) { struct seqno_trace *seqno_trace; char head[MAX_LINE], check_orig[NAME_LEN]; @@ -1003,16 +1002,14 @@ static void seqno_trace_print(struct list_head *trace_list, char *trace_orig, get_name_by_macstr(trace_orig, read_opt), seqno_trace->seqno);
- for (i = 0; i < seqno_trace->seqno_trace_neigh.num_neighbors; i++) { - snprintf(head, sizeof(head), "%c", - (seqno_trace->seqno_trace_neigh.num_neighbors == i + 1 ? '\' : '|')); + (seqno_trace->seqno_trace_neigh.num_neighbors == i + 1 ? '\' : '|'));
seqno_trace_print_neigh(seqno_trace->seqno_trace_neigh.seqno_trace_neigh[i], - NULL, - seqno_trace->seqno_trace_neigh.num_neighbors - i - 1, - head, read_opt); + NULL, + seqno_trace->seqno_trace_neigh.num_neighbors - i - 1, + head, read_opt); }
printf("\n"); @@ -1020,7 +1017,7 @@ static void seqno_trace_print(struct list_head *trace_list, char *trace_orig, }
static int _seqno_trace_neigh_add(struct seqno_trace_neigh *seqno_trace_mom, - struct seqno_trace_neigh *seqno_trace_child) + struct seqno_trace_neigh *seqno_trace_child) { struct seqno_trace_neigh **data_ptr;
@@ -1041,7 +1038,7 @@ static int _seqno_trace_neigh_add(struct seqno_trace_neigh *seqno_trace_mom, }
static struct seqno_trace_neigh *seqno_trace_neigh_add(struct seqno_trace_neigh *seqno_trace_neigh, - struct bat_node *bat_node, struct seqno_event *seqno_event) + struct bat_node *bat_node, struct seqno_event *seqno_event) { struct seqno_trace_neigh *seqno_trace_neigh_new; int res; @@ -1068,7 +1065,7 @@ err: }
static struct seqno_trace_neigh *seqno_trace_find_neigh(struct bat_node *neigh, struct bat_node *prev_sender, - struct seqno_trace_neigh *seqno_trace_neigh) + struct seqno_trace_neigh *seqno_trace_neigh) { struct seqno_trace_neigh *seqno_trace_neigh_tmp, *seqno_trace_neigh_ret; int i; @@ -1103,7 +1100,7 @@ static void seqno_trace_neigh_free(struct seqno_trace_neigh *seqno_trace_neigh) }
static int seqno_trace_fix_leaf(struct seqno_trace_neigh *seqno_trace_mom, - struct seqno_trace_neigh *seqno_trace_old_mom, + struct seqno_trace_neigh *seqno_trace_old_mom, struct seqno_trace_neigh *seqno_trace_child) { struct seqno_trace_neigh **data_ptr, *seqno_trace_neigh; @@ -1182,7 +1179,7 @@ static void seqno_trace_free(struct seqno_trace *seqno_trace) }
static int seqno_trace_add(struct list_head *trace_list, struct bat_node *bat_node, - struct seqno_event *seqno_event, char print_trace) + struct seqno_event *seqno_event, char print_trace) { struct seqno_trace *seqno_trace = NULL, *seqno_trace_tmp = NULL, *seqno_trace_prev = NULL; struct seqno_trace_neigh *seqno_trace_neigh; @@ -1217,13 +1214,13 @@ static int seqno_trace_add(struct list_head *trace_list, struct bat_node *bat_no seqno_trace->print = print_trace;
seqno_trace_neigh = seqno_trace_find_neigh(seqno_event->neigh, - seqno_event->prev_sender, - &seqno_trace->seqno_trace_neigh); + seqno_event->prev_sender, + &seqno_trace->seqno_trace_neigh);
/* no neighbor found to hook up to - adding new root node */ if (!seqno_trace_neigh) seqno_trace_neigh = seqno_trace_neigh_add(&seqno_trace->seqno_trace_neigh, - bat_node, seqno_event); + bat_node, seqno_event); else seqno_trace_neigh = seqno_trace_neigh_add(seqno_trace_neigh, bat_node, seqno_event);
@@ -1255,7 +1252,6 @@ static void trace_seqnos(char *trace_orig, long long seqno_min, long long seqno_ bat_node = hashit->bucket->data;
list_for_each_entry(orig_event, &bat_node->orig_event_list, list) { - /* we might have no log file from this node */ if (list_empty(&orig_event->event_list)) continue; @@ -1359,7 +1355,7 @@ static void print_rt_tables(char *rt_orig, long long seqno_min, long long seqno_ printf(", prev_sender: %s)\n", get_name_by_macstr(seqno_event->prev_sender->name, read_opt)); } else { - printf("rt change triggered by originator timeout: \n"); + printf("rt change triggered by originator timeout:\n"); }
for (i = 0; i < rt_table->num_entries; i++) { @@ -1445,7 +1441,7 @@ static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv) return EXIT_SUCCESS; case 'l': loop_orig_ptr = optarg; - found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2); + found_args += ((*((char *)(optarg - 1)) == optchar) ? 1 : 2); break; case 'n': read_opt &= ~USE_BAT_HOSTS; @@ -1453,25 +1449,25 @@ static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv) break; case 'o': filter_orig_ptr = optarg; - found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2); + found_args += ((*((char *)(optarg - 1)) == optchar) ? 1 : 2); break; case 'r': rt_orig_ptr = optarg; - found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2); + found_args += ((*((char *)(optarg - 1)) == optchar) ? 1 : 2); break; case 's': dash_ptr = strchr(optarg, '-'); if (dash_ptr) *dash_ptr = 0;
- tmp_seqno = strtol(optarg, NULL , 10); + tmp_seqno = strtol(optarg, NULL, 10); if ((tmp_seqno >= 0) && (tmp_seqno <= UINT32_MAX)) seqno_min = tmp_seqno; else fprintf(stderr, "Warning - given sequence number is out of range: %lli\n", tmp_seqno);
if (dash_ptr) { - tmp_seqno = strtol(dash_ptr + 1, NULL , 10); + tmp_seqno = strtol(dash_ptr + 1, NULL, 10); if ((tmp_seqno >= 0) && (tmp_seqno <= UINT32_MAX)) seqno_max = tmp_seqno; else @@ -1480,11 +1476,11 @@ static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv) *dash_ptr = '-'; }
- found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2); + found_args += ((*((char *)(optarg - 1)) == optchar) ? 1 : 2); break; case 't': trace_orig_ptr = optarg; - found_args += ((*((char*)(optarg - 1)) == optchar ) ? 1 : 2); + found_args += ((*((char *)(optarg - 1)) == optchar) ? 1 : 2); break; default: bisect_iv_usage(); @@ -1540,7 +1536,7 @@ static int bisect_iv(struct state *state __maybe_unused, int argc, char **argv)
if (seqno_min > seqno_max) { fprintf(stderr, "Error - the sequence range minimum (%lli) should be smaller than the maximum (%lli)\n", - seqno_min, seqno_max); + seqno_min, seqno_max); goto err; }
diff --git a/claimtable.c b/claimtable.c index 10691b7..22f691b 100644 --- a/claimtable.c +++ b/claimtable.c @@ -31,7 +31,7 @@ static const int bla_claim_mandatory[] = {
static int bla_claim_callback(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); struct print_opts *opts = arg; struct bat_host *bat_host; @@ -59,7 +59,7 @@ static int bla_claim_callback(struct nl_msg *msg, void *arg) }
if (missing_mandatory_attrs(attrs, bla_claim_mandatory, - ARRAY_SIZE(bla_claim_mandatory))) { + ARRAY_SIZE(bla_claim_mandatory))) { fputs("Missing attributes from kernel\n", stderr); exit(1); } diff --git a/dat_cache.c b/dat_cache.c index b51ecc9..b666a43 100644 --- a/dat_cache.c +++ b/dat_cache.c @@ -34,7 +34,7 @@ static const int dat_cache_mandatory[] = { static int dat_cache_callback(struct nl_msg *msg, void *arg) { int last_seen_msecs, last_seen_secs, last_seen_mins; - struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); struct print_opts *opts = arg; struct bat_host *bat_host; diff --git a/debug.c b/debug.c index 458c137..127129d 100644 --- a/debug.c +++ b/debug.c @@ -6,7 +6,6 @@ * License-Filename: LICENSES/preferred/GPL-2.0 */
- #include <unistd.h> #include <stdio.h> #include <stdlib.h> @@ -30,7 +29,7 @@ static void debug_table_usage(struct state *state) fprintf(stderr, " \t -w [interval] watch mode - refresh the table continuously\n");
if (debug_table->option_timeout_interval) - fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds \n"); + fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds\n");
if (debug_table->option_orig_iface) fprintf(stderr, " \t -i [interface] - show multiif originator table for a specific interface\n"); @@ -125,8 +124,7 @@ int handle_debug_table(struct state *state, int argc, char **argv) } else if (optopt == 'w') { read_opt |= CLR_CONT_READ; break; - } - else + } else fprintf(stderr, "Error - unrecognised option: '-%c'\n", optopt);
return EXIT_FAILURE; @@ -144,7 +142,7 @@ int handle_debug_table(struct state *state, int argc, char **argv) return EXIT_FAILURE; }
- err = debug_table->netlink_fn(state , orig_iface, read_opt, + err = debug_table->netlink_fn(state, orig_iface, read_opt, orig_timeout, watch_interval); return err; } diff --git a/debug.h b/debug.h index bfc6224..ac208fe 100644 --- a/debug.h +++ b/debug.h @@ -14,7 +14,7 @@
struct debug_table_data { int (*netlink_fn)(struct state *state, char *hard_iface, int read_opt, - float orig_timeout, float watch_interval); + float orig_timeout, float watch_interval); unsigned int option_unicast_only:1; unsigned int option_multicast_only:1; unsigned int option_timeout_interval:1; diff --git a/functions.c b/functions.c index 617fc5b..1faba08 100644 --- a/functions.c +++ b/functions.c @@ -6,7 +6,6 @@ * License-Filename: LICENSES/preferred/GPL-2.0 */
- #include <netinet/ether.h> #include <sys/socket.h> #include <netdb.h> @@ -49,7 +48,7 @@
static struct timespec start_time; static char *host_name; -char *line_ptr = NULL; +char *line_ptr;
void start_timer(void) { @@ -283,7 +282,7 @@ struct resolve_mac_nl_arg { int found; };
-static struct nla_policy neigh_policy[NDA_MAX+1] = { +static struct nla_policy neigh_policy[NDA_MAX + 1] = { [NDA_CACHEINFO] = { .minlen = sizeof(struct nda_cacheinfo) }, [NDA_PROBES] = { .type = NLA_U32 }, }; @@ -909,7 +908,7 @@ static int get_random_bytes_urandom(void *buf, size_t buflen) static int get_random_bytes_fallback(void *buf, size_t buflen) { struct timespec now; - static int initialized = 0; + static int initialized; size_t i; uint8_t *bufc = buf;
diff --git a/gateways.c b/gateways.c index f5b8a44..b0cc938 100644 --- a/gateways.c +++ b/gateways.c @@ -34,7 +34,7 @@ static const int gateways_mandatory[] = {
static int gateways_callback(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); struct print_opts *opts = arg; struct bat_host *bat_host; diff --git a/genl_json.c b/genl_json.c index 2c2c5c3..939e730 100644 --- a/genl_json.c +++ b/genl_json.c @@ -70,22 +70,22 @@ static void nljson_print_bool(struct nlattr *attrs[], int idx)
static void nljson_print_uint8(struct nlattr *attrs[], int idx) { - printf("%"PRIu8, nla_get_u8(attrs[idx])); + printf("%" PRIu8, nla_get_u8(attrs[idx])); }
static void nljson_print_uint16(struct nlattr *attrs[], int idx) { - printf("%"PRIu16, nla_get_u16(attrs[idx])); + printf("%" PRIu16, nla_get_u16(attrs[idx])); }
static void nljson_print_uint32(struct nlattr *attrs[], int idx) { - printf("%"PRIu32, nla_get_u32(attrs[idx])); + printf("%" PRIu32, nla_get_u32(attrs[idx])); }
static void nljson_print_uint64(struct nlattr *attrs[], int idx) { - printf("%"PRIu64, nla_get_u64(attrs[idx])); + printf("%" PRIu64, nla_get_u64(attrs[idx])); }
static void nljson_print_vlanid(struct nlattr *attrs[], int idx) @@ -124,7 +124,7 @@ static void nljson_print_ttflags(struct nlattr *attrs[], int idx) val & BATADV_TT_CLIENT_PENDING ? "true" : "false"); printf(""temp": %s,", val & BATADV_TT_CLIENT_TEMP ? "true" : "false"); - printf(""raw": %"PRIu32, val); + printf(""raw": %" PRIu32, val); putchar('}'); }
@@ -159,7 +159,7 @@ static void nljson_print_mcastflags(struct nlattr *attrs[], int idx) val & BATADV_MCAST_WANT_NO_RTR6 ? "true" : "false"); printf(""have_mc_ptype_capa": %s,", val & BATADV_MCAST_HAVE_MC_PTYPE_CAPA ? "true" : "false"); - printf(""raw": %"PRIu32, val); + printf(""raw": %" PRIu32, val); putchar('}'); }
@@ -178,7 +178,7 @@ static void nljson_print_mcastflags_priv(struct nlattr *attrs[], int idx) val & BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING ? "true" : "false"); printf(""querier_ipv6_shadowing": %s,", val & BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING ? "true" : "false"); - printf(""raw": %"PRIu32, val); + printf(""raw": %" PRIu32, val); putchar('}'); }
@@ -223,7 +223,7 @@ static void nljson_print_loglevel(struct nlattr *attrs[], int idx) val & BIT(6) ? "true" : "false"); printf(""tp": %s,", val & BIT(7) ? "true" : "false"); - printf(""raw": %"PRIu32, val); + printf(""raw": %" PRIu32, val); putchar('}'); }
@@ -510,7 +510,7 @@ static void json_query_usage(struct state *state)
static int netlink_print_query_json_cb(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlattr *attrs[BATADV_ATTR_MAX + 1]; struct nlmsghdr *nlh = nlmsg_hdr(msg); struct nlquery_opts *query_opts = arg; struct json_opts *json_opts; diff --git a/gw_mode.c b/gw_mode.c index 93f255c..5cde2ce 100644 --- a/gw_mode.c +++ b/gw_mode.c @@ -58,6 +58,7 @@ static bool is_throughput_select_class(struct state *state)
return false; } + static int parse_gw_limit(char *buff) { char *slash_ptr; @@ -68,7 +69,7 @@ static int parse_gw_limit(char *buff) *slash_ptr = 0;
ret = parse_throughput(buff, "download gateway speed", - &gw_globals.bandwidth_down); + &gw_globals.bandwidth_down); if (!ret) return -EINVAL;
@@ -193,7 +194,7 @@ static int print_gw(struct nl_msg *msg, void *arg) break; case BATADV_GW_MODE_CLIENT: if (missing_mandatory_attrs(attrs, mandatory_client, - ARRAY_SIZE(mandatory_client))) + ARRAY_SIZE(mandatory_client))) return NL_OK;
algo = nla_data(attrs[BATADV_ATTR_ALGO_NAME]); @@ -207,7 +208,7 @@ static int print_gw(struct nl_msg *msg, void *arg) break; case BATADV_GW_MODE_SERVER: if (missing_mandatory_attrs(attrs, mandatory_server, - ARRAY_SIZE(mandatory_server))) + ARRAY_SIZE(mandatory_server))) return NL_OK;
down = nla_get_u32(attrs[BATADV_ATTR_GW_BANDWIDTH_DOWN]); diff --git a/hash.c b/hash.c index 5262800..ec54f4f 100644 --- a/hash.c +++ b/hash.c @@ -6,7 +6,6 @@ * License-Filename: LICENSES/preferred/GPL-2.0 */
- #include "hash.h" #include <stdlib.h> #include <stdio.h> @@ -32,19 +31,15 @@ void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb) int i;
for (i = 0; i < hash->size; i++) { - bucket = hash->table[i]; - while (bucket != NULL) { - - if (free_cb != NULL) + while (bucket) { + if (free_cb) free_cb(bucket->data);
last_bucket = bucket; bucket = bucket->next; debugFree(last_bucket, 1301); - } - }
hash_destroy(hash); @@ -61,7 +56,7 @@ static int hash_add_bucket(struct hashtable_t *hash, void *data, index = hash->choose(data, hash->size); bucket_it = hash->table[index];
- while (bucket_it != NULL) { + while (bucket_it) { if (check_duplicate && hash->compare(bucket_it->data, data)) return -1; @@ -75,7 +70,7 @@ static int hash_add_bucket(struct hashtable_t *hash, void *data, bucket->next = NULL;
/* and link it */ - if (prev_bucket == NULL) + if (!prev_bucket) hash->table[index] = bucket; else prev_bucket->next = bucket; @@ -105,7 +100,7 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash, { struct hash_it_t *iter;
- if (iter_in == NULL) { + if (!iter_in) { iter = debugMalloc(sizeof(struct hash_it_t), 301); if (!iter) return NULL; @@ -119,13 +114,11 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
/* sanity checks first (if our bucket got deleted in the last * iteration): */ - if (iter->bucket != NULL) { - if (iter->first_bucket != NULL) { - + if (iter->bucket) { + if (iter->first_bucket) { /* we're on the first element and it got removed after * the last iteration. */ if ((*iter->first_bucket) != iter->bucket) { - /* there are still other elements in the list */ if ((*iter->first_bucket) != NULL) { iter->prev_bucket = NULL; @@ -135,25 +128,21 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash, } else { iter->bucket = NULL; } - }
- } else if (iter->prev_bucket != NULL) { - + } else if (iter->prev_bucket) { /* we're not on the first element, and the bucket got * removed after the last iteration. The last bucket's * next pointer is not pointing to our actual bucket * anymore. Select the next. */ if (iter->prev_bucket->next != iter->bucket) iter->bucket = iter->prev_bucket; - } - }
/* now as we are sane, select the next one if there is some */ - if (iter->bucket != NULL) { - if (iter->bucket->next != NULL) { + if (iter->bucket) { + if (iter->bucket->next) { iter->prev_bucket = iter->bucket; iter->bucket = iter->bucket->next; iter->first_bucket = NULL; @@ -166,7 +155,6 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash, iter->index++; /* go through the entries of the hash table */ while (iter->index < hash->size) { - if ((hash->table[iter->index]) == NULL) { iter->index++; continue; @@ -194,7 +182,7 @@ struct hashtable_t *hash_new(int size, hashdata_compare_cb compare, return NULL;
hash->size = size; - hash->table = debugMalloc(sizeof(struct element_t *)*size, 303); + hash->table = debugMalloc(sizeof(struct element_t *) * size, 303);
if (!hash->table) { debugFree(hash, 1305); @@ -233,10 +221,10 @@ void *hash_find(struct hashtable_t *hash, void *keydata) int index; struct element_t *bucket;
- index = hash->choose(keydata , hash->size); + index = hash->choose(keydata, hash->size); bucket = hash->table[index];
- while (bucket != NULL) { + while (bucket) { if (hash->compare(bucket->data, keydata)) return bucket->data;
@@ -257,9 +245,9 @@ void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t) /* save the pointer to the data */ data_save = hash_it_t->bucket->data;
- if (hash_it_t->prev_bucket != NULL) + if (hash_it_t->prev_bucket) hash_it_t->prev_bucket->next = hash_it_t->bucket->next; - else if (hash_it_t->first_bucket != NULL) + else if (hash_it_t->first_bucket) (*hash_it_t->first_bucket) = hash_it_t->bucket->next;
debugFree(hash_it_t->bucket, 1306); @@ -280,9 +268,10 @@ void *hash_remove(struct hashtable_t *hash, void *data) hash_it_t.bucket = hash->table[hash_it_t.index]; hash_it_t.prev_bucket = NULL;
- while (hash_it_t.bucket != NULL) { + while (hash_it_t.bucket) { if (hash->compare(hash_it_t.bucket->data, data)) { int bucket_same; + bucket_same = (hash_it_t.bucket == hash->table[hash_it_t.index]); hash_it_t.first_bucket = (bucket_same ? diff --git a/hash.h b/hash.h index 08628fa..2a92c59 100644 --- a/hash.h +++ b/hash.h @@ -9,7 +9,6 @@ #define _BATMAN_HASH_H
- typedef int (*hashdata_compare_cb)(void *, void *); typedef int (*hashdata_choose_cb)(void *, int); typedef void (*hashdata_free_cb)(void *); @@ -46,7 +45,7 @@ void hash_init(struct hashtable_t *hash);
/* allocates and clears the hash */ struct hashtable_t *hash_new(int size, hashdata_compare_cb compare, - hashdata_choose_cb choose); + hashdata_choose_cb choose);
/* remove bucket (this might be used in hash_iterate() if you already found * the bucket you want to delete and don't need the overhead to find it again diff --git a/icmp_helper.c b/icmp_helper.c index f0b5082..9ee4fb1 100644 --- a/icmp_helper.c +++ b/icmp_helper.c @@ -301,7 +301,6 @@ static void icmp_interface_unmark(void) iface->mark = 0; }
- static void icmp_interface_sweep(void) { struct icmp_interface *iface, *safe; diff --git a/interface.c b/interface.c index a96a328..93a35da 100644 --- a/interface.c +++ b/interface.c @@ -38,7 +38,6 @@ static void interface_usage(void)
static int get_iface_status_netlink_parse(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[NUM_BATADV_ATTR]; struct nlmsghdr *nlh = nlmsg_hdr(msg); char *iface_status = arg; @@ -75,7 +74,7 @@ static char *get_iface_status_netlink(struct state *state, unsigned int hardif, iface_status[0] = '\0';
nl_cb_set(state->cb, NL_CB_VALID, NL_CB_CUSTOM, get_iface_status_netlink_parse, - iface_status); + iface_status);
msg = nlmsg_alloc(); if (!msg)