diff --git a/code/bngblaster/src/bbl.c b/code/bngblaster/src/bbl.c index 3fd270cf..00c1b480 100644 --- a/code/bngblaster/src/bbl.c +++ b/code/bngblaster/src/bbl.c @@ -128,11 +128,11 @@ struct keyval_ log_names[] = { static char * bbl_print_usage_arg (struct option *option) { - if (option->has_arg == 1) { - if (strcmp(option->name, "logging") == 0) { + if(option->has_arg == 1) { + if(strcmp(option->name, "logging") == 0) { return log_usage(); } - if (strcmp(option->name, "json-report-content") == 0) { + if(strcmp(option->name, "json-report-content") == 0) { return " sessions|streams"; } return " "; @@ -169,8 +169,8 @@ bbl_print_usage (void) int idx; printf("%s", banner); printf("Usage: bngblaster [OPTIONS]\n\n"); - for (idx = 0; ; idx++) { - if (long_options[idx].name == NULL) { + for(idx = 0; ; idx++) { + if(long_options[idx].name == NULL) { break; } printf(" -%c --%s%s\n", long_options[idx].val, long_options[idx].name, @@ -312,7 +312,7 @@ bbl_ctrl_job(timer_s *timer) if(session->access_config->dhcp_enable) { /* Start IPoE session by sending DHCP discovery if enabled. */ bbl_dhcp_start(session); - } else if (session->ip_address && session->peer_ip_address) { + } else if(session->ip_address && session->peer_ip_address) { /* Start IPoE session by sending ARP request if local and * remote IP addresses are already provided. */ session->send_requests |= BBL_SEND_ARP_REQUEST; @@ -386,7 +386,7 @@ main(int argc, char *argv[]) /* Process config options. */ while (true) { ch = getopt_long(argc, argv, optstring, long_options, &long_index); - if (ch == -1) { + if(ch == -1) { break; } switch (ch) { @@ -400,9 +400,9 @@ main(int argc, char *argv[]) g_ctx->pcap.filename = optarg; break; case 'j': - if (strcmp("sessions", optarg) == 0) { + if(strcmp("sessions", optarg) == 0) { g_ctx->config.json_report_sessions = true; - } else if (strcmp("streams", optarg) == 0) { + } else if(strcmp("streams", optarg) == 0) { g_ctx->config.json_report_streams = true; } break; diff --git a/code/bngblaster/src/bbl_access.c b/code/bngblaster/src/bbl_access.c index a3b0fbfb..7b63d3f7 100644 --- a/code/bngblaster/src/bbl_access.c +++ b/code/bngblaster/src/bbl_access.c @@ -1611,7 +1611,7 @@ bbl_access_session_id_from_broadcast(bbl_access_interface_s *interface, ipv4 = (bbl_ipv4_s*)eth->next; if(ipv4->protocol == PROTOCOL_IPV4_UDP) { udp = (bbl_udp_s*)ipv4->next; - if (udp->protocol == UDP_PROTOCOL_DHCP) { + if(udp->protocol == UDP_PROTOCOL_DHCP) { dhcp = (bbl_dhcp_s*)udp->next; session_id |= ((uint8_t*)(dhcp->header->chaddr))[5]; session_id |= ((uint8_t*)(dhcp->header->chaddr))[4] << 8; diff --git a/code/bngblaster/src/bbl_config.c b/code/bngblaster/src/bbl_config.c index 9deac580..c033652a 100644 --- a/code/bngblaster/src/bbl_config.c +++ b/code/bngblaster/src/bbl_config.c @@ -1961,7 +1961,7 @@ json_parse_config(json_t *root) g_ctx->config.send_multicast_traffic = json_boolean_value(value); } value = json_object_get(section, "multicast-traffic-autostart"); - if (json_is_boolean(value)) { + if(json_is_boolean(value)) { g_ctx->config.multicast_traffic_autostart = json_boolean_value(value); } value = json_object_get(section, "multicast-traffic-length"); diff --git a/code/bngblaster/src/bbl_ctrl.c b/code/bngblaster/src/bbl_ctrl.c index 428649a3..016ad8db 100644 --- a/code/bngblaster/src/bbl_ctrl.c +++ b/code/bngblaster/src/bbl_ctrl.c @@ -197,7 +197,7 @@ bbl_ctrl_socket_thread(void *thread_data) if(fd > 0) { /* New connection */ root = json_loadfd(fd, flags, &error); - if (!root) { + if(!root) { LOG(DEBUG, "Invalid json via ctrl socket: line %d: %s\n", error.line, error.text); bbl_ctrl_status(fd, "error", 400, "invalid json"); } else { @@ -223,7 +223,7 @@ bbl_ctrl_socket_thread(void *thread_data) } else { if(arguments) { value = json_object_get(arguments, "session-id"); - if (value) { + if(value) { if(json_is_number(value)) { session_id = json_number_value(value); } else { @@ -236,7 +236,7 @@ bbl_ctrl_socket_thread(void *thread_data) * support per session commands using VLAN index instead of * new session-id. */ value = json_object_get(arguments, "ifindex"); - if (value) { + if(value) { if(json_is_number(value)) { key.ifindex = json_number_value(value); } else { @@ -251,7 +251,7 @@ bbl_ctrl_socket_thread(void *thread_data) } } value = json_object_get(arguments, "outer-vlan"); - if (value) { + if(value) { if(json_is_number(value)) { key.outer_vlan_id = json_number_value(value); } else { @@ -260,7 +260,7 @@ bbl_ctrl_socket_thread(void *thread_data) } } value = json_object_get(arguments, "inner-vlan"); - if (value) { + if(value) { if(json_is_number(value)) { key.inner_vlan_id = json_number_value(value); } else { diff --git a/code/bngblaster/src/bbl_ctx.c b/code/bngblaster/src/bbl_ctx.c index 5d9258c4..65b08709 100644 --- a/code/bngblaster/src/bbl_ctx.c +++ b/code/bngblaster/src/bbl_ctx.c @@ -54,7 +54,7 @@ bool bbl_ctx_add() { g_ctx = calloc(1, sizeof(bbl_ctx_s)); - if (!g_ctx) { + if(!g_ctx) { return false; } diff --git a/code/bngblaster/src/bbl_dhcp.c b/code/bngblaster/src/bbl_dhcp.c index 47eebc2b..4f38e280 100644 --- a/code/bngblaster/src/bbl_dhcp.c +++ b/code/bngblaster/src/bbl_dhcp.c @@ -263,7 +263,7 @@ bbl_dhcp_rx(bbl_session_s *session, bbl_ethernet_header_s *eth, bbl_dhcp_s *dhcp timer_add(&g_ctx->timer_root, &session->timer_dhcp_t2, "DHCP T2", session->dhcp_t2, 0, session, &bbl_dhcp_s2); session->send_requests |= BBL_SEND_ARP_REQUEST; bbl_session_tx_qnode_insert(session); - } else if (dhcp->type == DHCP_MESSAGE_NAK) { + } else if(dhcp->type == DHCP_MESSAGE_NAK) { bbl_dhcp_restart(session); } break; @@ -287,7 +287,7 @@ bbl_dhcp_rx(bbl_session_s *session, bbl_ethernet_header_s *eth, bbl_dhcp_s *dhcp timer_add(&g_ctx->timer_root, &session->timer_dhcp_t2, "DHCP T2", session->dhcp_t2, 0, session, &bbl_dhcp_s2); session->send_requests |= BBL_SEND_ARP_REQUEST; bbl_session_tx_qnode_insert(session); - } else if (dhcp->type == DHCP_MESSAGE_NAK) { + } else if(dhcp->type == DHCP_MESSAGE_NAK) { bbl_dhcp_restart(session); } break; diff --git a/code/bngblaster/src/bbl_igmp.c b/code/bngblaster/src/bbl_igmp.c index edfc050a..4943a6ac 100644 --- a/code/bngblaster/src/bbl_igmp.c +++ b/code/bngblaster/src/bbl_igmp.c @@ -85,24 +85,24 @@ bbl_igmp_ctrl_join(int fd, uint32_t session_id, json_t *arguments) return bbl_ctrl_status(fd, "error", 400, "missing session-id"); } /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "group", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "group", &s) == 0) { if(!inet_pton(AF_INET, s, &group_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid group address"); } } else { return bbl_ctrl_status(fd, "error", 400, "missing group address"); } - if (json_unpack(arguments, "{s:s}", "source1", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source1", &s) == 0) { if(!inet_pton(AF_INET, s, &source1)) { return bbl_ctrl_status(fd, "error", 400, "invalid source1 address"); } } - if (json_unpack(arguments, "{s:s}", "source2", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source2", &s) == 0) { if(!inet_pton(AF_INET, s, &source2)) { return bbl_ctrl_status(fd, "error", 400, "invalid source2 address"); } } - if (json_unpack(arguments, "{s:s}", "source3", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source3", &s) == 0) { if(!inet_pton(AF_INET, s, &source3)) { return bbl_ctrl_status(fd, "error", 400, "invalid source3 address"); } @@ -114,7 +114,7 @@ bbl_igmp_ctrl_join(int fd, uint32_t session_id, json_t *arguments) /* Search for free slot ... */ for(i=0; i < IGMP_MAX_GROUPS; i++) { if(!session->igmp_groups[i].zapping) { - if (session->igmp_groups[i].group == group_address) { + if(session->igmp_groups[i].group == group_address) { group = &session->igmp_groups[i]; if(group->state == IGMP_GROUP_IDLE) { break; @@ -164,14 +164,14 @@ bbl_igmp_ctrl_join_iter(int fd, uint32_t session_id __attribute__((unused)), jso uint32_t join_count; /* Unpack group arguments */ - if (json_unpack(arguments, "{s:s}", "group", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "group", &s) == 0) { if(!inet_pton(AF_INET, s, &group_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid group address"); } } else { return bbl_ctrl_status(fd, "error", 400, "missing group address"); } - if (json_unpack(arguments, "{s:d}", "group-iter", &s) == 0) { + if(json_unpack(arguments, "{s:d}", "group-iter", &s) == 0) { if(!inet_pton(AF_INET, s, &group_iter)) { return bbl_ctrl_status(fd, "error", 400, "invalid group-iter"); } @@ -181,17 +181,17 @@ bbl_igmp_ctrl_join_iter(int fd, uint32_t session_id __attribute__((unused)), jso if(group_count < 1) group_count = 1; /* Unpack source address arguments */ - if (json_unpack(arguments, "{s:s}", "source1", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source1", &s) == 0) { if(!inet_pton(AF_INET, s, &source1)) { return bbl_ctrl_status(fd, "error", 400, "invalid source1 address"); } } - if (json_unpack(arguments, "{s:s}", "source2", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source2", &s) == 0) { if(!inet_pton(AF_INET, s, &source2)) { return bbl_ctrl_status(fd, "error", 400, "invalid source2 address"); } } - if (json_unpack(arguments, "{s:s}", "source3", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "source3", &s) == 0) { if(!inet_pton(AF_INET, s, &source3)) { return bbl_ctrl_status(fd, "error", 400, "invalid source3 address"); } @@ -261,7 +261,7 @@ bbl_igmp_ctrl_leave(int fd, uint32_t session_id, json_t *arguments) return bbl_ctrl_status(fd, "error", 400, "missing session-id"); } /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "group", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "group", &s) == 0) { if(!inet_pton(AF_INET, s, &group_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid group address"); } @@ -273,7 +273,7 @@ bbl_igmp_ctrl_leave(int fd, uint32_t session_id, json_t *arguments) if(session) { /* Search for group ... */ for(i=0; i < IGMP_MAX_GROUPS; i++) { - if (session->igmp_groups[i].group == group_address) { + if(session->igmp_groups[i].group == group_address) { group = &session->igmp_groups[i]; break; } diff --git a/code/bngblaster/src/bbl_interactive.c b/code/bngblaster/src/bbl_interactive.c index b63af876..b7827d59 100644 --- a/code/bngblaster/src/bbl_interactive.c +++ b/code/bngblaster/src/bbl_interactive.c @@ -67,14 +67,14 @@ bbl_interactive_format_progress(uint32_t complete, uint32_t current) float percentage; uint16_t idx; - if (!complete || !current) { + if(!complete || !current) { memset(buf, ' ', sizeof(buf)); goto EXIT; } percentage = (float)current / (float)complete; for(idx = 0; idx < sizeof(buf); idx++) { - if (idx <= (percentage * PROGRESS_BAR_SIZE)) { + if(idx <= (percentage * PROGRESS_BAR_SIZE)) { buf[idx] = '#'; continue; } @@ -617,7 +617,7 @@ bbl_interactive_window_job(timer_s *timer) wprintw(stats_win, " %-16.16s | %-9.9s | %7lu | %10lu | %7lu | %10lu | %8lu\n", stream->config->name, stream->direction == BBL_DIRECTION_UP ? "up" : "down", stream->rate_packets_tx.avg, tx_kbps, stream->rate_packets_rx.avg, rx_kbps, stream->rx_loss); - } else if (i == 16+stats_win_postion) { + } else if(i == 16+stats_win_postion) { wprintw(stats_win, " ...\n"); } i++; diff --git a/code/bngblaster/src/bbl_interface.c b/code/bngblaster/src/bbl_interface.c index 3432d644..c6e5ddd8 100644 --- a/code/bngblaster/src/bbl_interface.c +++ b/code/bngblaster/src/bbl_interface.c @@ -58,7 +58,7 @@ bbl_interface_lock(char *interface_name) /* lock file exists */ if(fscanf(lock_file,"%d", &lock_pid) == 1 && lock_pid > 1) { snprintf(proc_pid_path, sizeof(proc_pid_path), "/proc/%d", lock_pid); - if (!(stat(proc_pid_path, &sts) == -1 && errno == ENOENT)) { + if(!(stat(proc_pid_path, &sts) == -1 && errno == ENOENT)) { LOG(ERROR, "Interface %s in use by process %d (%s)\n", interface_name, lock_pid, lock_path); if(!g_ctx->config.interface_lock_force) return false; } @@ -110,7 +110,7 @@ bbl_interface_link_add(char *interface_name, bbl_link_config_s *link_config) bbl_interface_s *interface; interface = calloc(1, sizeof(bbl_interface_s)); - if (!interface) { + if(!interface) { LOG(ERROR, "No memory for interface %s\n", interface_name); return NULL; } @@ -149,7 +149,7 @@ bbl_interface_links_add() return false; } interface = bbl_interface_link_add(link_config->interface, link_config); - if (!interface) { + if(!interface) { LOG(ERROR, "Failed to add link %s\n", link_config->interface); return false; } @@ -208,7 +208,7 @@ bbl_interface_get(char *interface_name) } CIRCLEQ_FOREACH(interface, &g_ctx->interface_qhead, interface_qnode) { - if (strcmp(interface->name, interface_name) == 0) { + if(strcmp(interface->name, interface_name) == 0) { return interface; } } diff --git a/code/bngblaster/src/bbl_l2tp.c b/code/bngblaster/src/bbl_l2tp.c index 28483b1a..9307d745 100644 --- a/code/bngblaster/src/bbl_l2tp.c +++ b/code/bngblaster/src/bbl_l2tp.c @@ -229,7 +229,7 @@ bbl_l2tp_tunnel_update_state(bbl_l2tp_tunnel_s *l2tp_tunnel, l2tp_tunnel_state_t l2tp_tunnel->server->host_name, l2tp_tunnel->tunnel_id, l2tp_tunnel->peer_name, format_ipv4_address(&l2tp_tunnel->peer_ip)); - } else if (l2tp_tunnel->state == BBL_L2TP_TUNNEL_ESTABLISHED) { + } else if(l2tp_tunnel->state == BBL_L2TP_TUNNEL_ESTABLISHED) { if(g_ctx->l2tp_tunnels_established) { g_ctx->l2tp_tunnels_established--; } @@ -268,7 +268,7 @@ bbl_l2tp_tunnel_tx_job(timer_s *timer) q = CIRCLEQ_FIRST(&l2tp_tunnel->txq_qhead); while (q != (const void *)(&l2tp_tunnel->txq_qhead)) { - if (L2TP_SEQ_LT(q->ns, l2tp_tunnel->peer_nr)) { + if(L2TP_SEQ_LT(q->ns, l2tp_tunnel->peer_nr)) { /* Delete acknowledged messages from queue. */ q_del = q; q = CIRCLEQ_NEXT(q, txq_qnode); @@ -279,7 +279,7 @@ bbl_l2tp_tunnel_tx_job(timer_s *timer) free(q_del); continue; } - if (L2TP_SEQ_LT(q->ns, max_ns)) { + if(L2TP_SEQ_LT(q->ns, max_ns)) { if(q->last_tx_time.tv_sec) { timespec_sub(&time_diff, ×tamp, &q->last_tx_time); time_diff_ms = round(time_diff.tv_nsec / 1.0e6) * (time_diff.tv_sec * 1000); @@ -616,7 +616,7 @@ bbl_l2tp_sccrq_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s *eth } l2tp_tunnel->tunnel_id = l2tp_session->key.tunnel_id; result = dict_insert(g_ctx->l2tp_session_dict, &l2tp_session->key); - if (!result.inserted) { + if(!result.inserted) { LOG(ERROR, "L2TP Error (%s) Failed to add tunnel session\n", l2tp_tunnel->server->host_name); free(l2tp_session); @@ -715,7 +715,7 @@ bbl_l2tp_scccn_rx(bbl_network_interface_s *interface, MD5_Update(&md5_ctx, (unsigned char *) l2tp_tunnel->server->secret, strlen(l2tp_tunnel->server->secret)); MD5_Update(&md5_ctx, l2tp_tunnel->challenge, l2tp_tunnel->challenge_len); MD5_Final(digest, &md5_ctx); - if (memcmp(digest, l2tp_tunnel->peer_challenge_response, L2TP_MD5_DIGEST_LEN) != 0) { + if(memcmp(digest, l2tp_tunnel->peer_challenge_response, L2TP_MD5_DIGEST_LEN) != 0) { LOG(ERROR, "L2TP Error (%s) Wrong challenge response in SCCCN from %s\n", l2tp_tunnel->server->host_name, format_ipv4_address(&l2tp_tunnel->peer_ip)); @@ -805,7 +805,7 @@ bbl_l2tp_icrq_rx(bbl_network_interface_s *interface, } } result = dict_insert(g_ctx->l2tp_session_dict, &l2tp_session->key); - if (!result.inserted) { + if(!result.inserted) { LOG(ERROR, "L2TP Error (%s) Failed to add session\n", l2tp_tunnel->server->host_name); free(l2tp_session); @@ -970,7 +970,7 @@ bbl_l2tp_data_rx(bbl_network_interface_s *interface, } } bbl_l2tp_send_data(l2tp_session, PROTOCOL_IPCP, ipcp_rx); - } else if (ipcp_rx->code == PPP_CODE_CONF_ACK) { + } else if(ipcp_rx->code == PPP_CODE_CONF_ACK) { if(l2tp_session->ipcp_state == BBL_PPP_PEER_ACK) { l2tp_session->ipcp_state = BBL_PPP_OPENED; } else { @@ -998,7 +998,7 @@ bbl_l2tp_data_rx(bbl_network_interface_s *interface, bbl_l2tp_send_data(l2tp_session, PROTOCOL_IP6CP, &ip6cp_tx); } bbl_l2tp_send_data(l2tp_session, PROTOCOL_IP6CP, ip6cp_rx); - } else if (ip6cp_rx->code == PPP_CODE_CONF_ACK) { + } else if(ip6cp_rx->code == PPP_CODE_CONF_ACK) { if(l2tp_session->ip6cp_state == BBL_PPP_PEER_ACK) { l2tp_session->ip6cp_state = BBL_PPP_OPENED; } else { @@ -1068,10 +1068,10 @@ bbl_l2tp_handler_rx(bbl_network_interface_s *interface, /* L2TP Control Packet */ l2tp_tunnel->stats.control_rx++; interface->stats.l2tp_control_rx++; - if (L2TP_SEQ_GT(l2tp->nr, l2tp_tunnel->peer_nr)) { + if(L2TP_SEQ_GT(l2tp->nr, l2tp_tunnel->peer_nr)) { l2tp_tunnel->peer_nr = l2tp->nr; } - if (l2tp_tunnel->nr == l2tp->ns) { + if(l2tp_tunnel->nr == l2tp->ns) { /* In-Order packet received */ LOG(DEBUG, "L2TP Debug (%s) %s received from %s\n", l2tp_tunnel->server->host_name, @@ -1161,7 +1161,7 @@ bbl_l2tp_handler_rx(bbl_network_interface_s *interface, } } } else { - if (L2TP_SEQ_LT(l2tp->ns, l2tp_tunnel->nr)) { + if(L2TP_SEQ_LT(l2tp->ns, l2tp_tunnel->nr)) { /* Duplicate packet received */ LOG(DEBUG, "L2TP Debug (%s) Duplicate %s received with Ns. %u (expected %u) from %s\n", l2tp_tunnel->server->host_name, @@ -1286,7 +1286,7 @@ bbl_l2tp_ctrl_sessions(int fd, uint32_t session_id __attribute__((unused)), json json_decref(sessions); return result; } - } else if (l2tp_tunnel_id) { + } else if(l2tp_tunnel_id) { l2tp_key.tunnel_id = l2tp_tunnel_id; search = dict_search(g_ctx->l2tp_session_dict, &l2tp_key); if(search) { @@ -1341,7 +1341,7 @@ bbl_l2tp_ctrl_csurq(int fd, uint32_t session_id __attribute__((unused)), json_t int size, i; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:i}", "tunnel-id", &l2tp_tunnel_id) != 0) { + if(json_unpack(arguments, "{s:i}", "tunnel-id", &l2tp_tunnel_id) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing tunnel-id"); } l2tp_key.tunnel_id = l2tp_tunnel_id; @@ -1353,7 +1353,7 @@ bbl_l2tp_ctrl_csurq(int fd, uint32_t session_id __attribute__((unused)), json_t return bbl_ctrl_status(fd, "warning", 400, "tunnel not established"); } sessions = json_object_get(arguments, "sessions"); - if (json_is_array(sessions)) { + if(json_is_array(sessions)) { size = json_array_size(sessions); l2tp_tunnel->csurq_requests_len = size; l2tp_tunnel->csurq_requests = malloc(size * sizeof(uint16_t)); @@ -1388,7 +1388,7 @@ bbl_l2tp_ctrl_tunnel_terminate(int fd, uint32_t session_id __attribute__((unused char *error_message; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:i}", "tunnel-id", &l2tp_tunnel_id) != 0) { + if(json_unpack(arguments, "{s:i}", "tunnel-id", &l2tp_tunnel_id) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing tunnel-id"); } l2tp_key.tunnel_id = l2tp_tunnel_id; @@ -1400,15 +1400,15 @@ bbl_l2tp_ctrl_tunnel_terminate(int fd, uint32_t session_id __attribute__((unused return bbl_ctrl_status(fd, "warning", 400, "tunnel not established"); } bbl_l2tp_tunnel_update_state(l2tp_tunnel, BBL_L2TP_TUNNEL_SEND_STOPCCN); - if (json_unpack(arguments, "{s:i}", "result-code", &result_code) != 0) { + if(json_unpack(arguments, "{s:i}", "result-code", &result_code) != 0) { result_code = 1; } l2tp_tunnel->result_code = result_code; - if (json_unpack(arguments, "{s:i}", "error-code", &error_code) != 0) { + if(json_unpack(arguments, "{s:i}", "error-code", &error_code) != 0) { error_code = 0; } l2tp_tunnel->error_code = error_code; - if (json_unpack(arguments, "{s:s}", "error-message", &error_message) != 0) { + if(json_unpack(arguments, "{s:s}", "error-message", &error_message) != 0) { error_message = NULL; } l2tp_tunnel->error_message = error_message; @@ -1452,31 +1452,31 @@ bbl_l2tp_ctrl_session_terminate(int fd, uint32_t session_id, json_t *arguments) if(l2tp_session->state != BBL_L2TP_SESSION_ESTABLISHED) { return bbl_ctrl_status(fd, "warning", 400, "session not established"); } - if (json_unpack(arguments, "{s:i}", "result-code", &result_code) != 0) { + if(json_unpack(arguments, "{s:i}", "result-code", &result_code) != 0) { result_code = 2; } l2tp_session->result_code = result_code; - if (json_unpack(arguments, "{s:i}", "error-code", &error_code) != 0) { + if(json_unpack(arguments, "{s:i}", "error-code", &error_code) != 0) { error_code = 0; } l2tp_session->error_code = error_code; - if (json_unpack(arguments, "{s:s}", "error-message", &error_message) != 0) { + if(json_unpack(arguments, "{s:s}", "error-message", &error_message) != 0) { error_message = NULL; } l2tp_session->error_message = error_message; - if (json_unpack(arguments, "{s:i}", "disconnect-code", &disconnect_code) != 0) { + if(json_unpack(arguments, "{s:i}", "disconnect-code", &disconnect_code) != 0) { disconnect_code = 0; } l2tp_session->disconnect_code = disconnect_code; - if (json_unpack(arguments, "{s:i}", "disconnect-protocol", &disconnect_protocol) != 0) { + if(json_unpack(arguments, "{s:i}", "disconnect-protocol", &disconnect_protocol) != 0) { disconnect_protocol = 0; } l2tp_session->disconnect_protocol = disconnect_protocol; - if (json_unpack(arguments, "{s:i}", "disconnect-direction", &disconnect_direction) != 0) { + if(json_unpack(arguments, "{s:i}", "disconnect-direction", &disconnect_direction) != 0) { disconnect_direction = 0; } l2tp_session->disconnect_direction = disconnect_direction; - if (json_unpack(arguments, "{s:s}", "disconnect-message", &disconnect_message) != 0) { + if(json_unpack(arguments, "{s:s}", "disconnect-message", &disconnect_message) != 0) { disconnect_message = NULL; } l2tp_session->disconnect_message = disconnect_message; diff --git a/code/bngblaster/src/bbl_l2tp_avp.c b/code/bngblaster/src/bbl_l2tp_avp.c index 6ee5914f..50de8510 100644 --- a/code/bngblaster/src/bbl_l2tp_avp.c +++ b/code/bngblaster/src/bbl_l2tp_avp.c @@ -209,7 +209,7 @@ bbl_l2tp_avp_unhide(bbl_l2tp_tunnel_s *l2tp_tunnel, bbl_l2tp_avp_t *avp, uint8_t len |= digest[idx++] ^ *value; value++; - if (len + 2 > avp->len) { + if(len + 2 > avp->len) { LOG(DEBUG, "L2TP Error (%s) Decrypted length %u > AVP length %u\n", l2tp_tunnel->server->host_name, len, avp->len); return false; diff --git a/code/bngblaster/src/bbl_li.c b/code/bngblaster/src/bbl_li.c index 80c22ccd..9fcc65f5 100644 --- a/code/bngblaster/src/bbl_li.c +++ b/code/bngblaster/src/bbl_li.c @@ -77,7 +77,7 @@ bbl_qmx_li_handler_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s li_flow->sub_packet_type = qmx_li->sub_packet_type; li_flow->liid = qmx_li->liid; result = dict_insert(g_ctx->li_flow_dict, &qmx_li->header); - if (!result.inserted) { + if(!result.inserted) { free(li_flow); return; } @@ -117,7 +117,7 @@ bbl_qmx_li_handler_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s default: break; } - } else if (inner_ipv6) { + } else if(inner_ipv6) { li_flow->packets_rx_ipv6++; switch(inner_ipv6->protocol) { case IPV6_NEXT_HEADER_TCP: diff --git a/code/bngblaster/src/bbl_network.c b/code/bngblaster/src/bbl_network.c index f98b96b6..369d392b 100644 --- a/code/bngblaster/src/bbl_network.c +++ b/code/bngblaster/src/bbl_network.c @@ -56,7 +56,7 @@ bbl_network_interfaces_add() } interface = bbl_interface_get(network_config->interface); - if (!interface) { + if(!interface) { LOG(ERROR, "Failed to add network interface %s (interface not found)\n", ifname); return false; } diff --git a/code/bngblaster/src/bbl_pcap.c b/code/bngblaster/src/bbl_pcap.c index 944e459d..692474ed 100644 --- a/code/bngblaster/src/bbl_pcap.c +++ b/code/bngblaster/src/bbl_pcap.c @@ -31,7 +31,7 @@ pcapng_open() * Open the file. */ g_ctx->pcap.fd = open(g_ctx->pcap.filename, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, PCAPNG_PERMS); - if (g_ctx->pcap.fd == -1) { + if(g_ctx->pcap.fd == -1) { switch (errno) { default: LOG(ERROR, "failed to open pcap file %s with error %s (%d)\n", @@ -56,7 +56,7 @@ pcapng_init() /* * Write buffer for I/O. */ - if (!g_ctx->pcap.write_buf) { + if(!g_ctx->pcap.write_buf) { g_ctx->pcap.write_buf = calloc(1, PCAPNG_WRITEBUFSIZE); } else { g_ctx->pcap.write_idx = 0; @@ -85,7 +85,7 @@ pcapng_fflush() * File is not yet opened, try to open it. */ pcapng_open(); - if (g_ctx->pcap.fd == -1) { + if(g_ctx->pcap.fd == -1) { /* * Darn, still closed. */ @@ -94,7 +94,7 @@ pcapng_fflush() * We may have buffered for too long. * Reset the buffer before it is running full. */ - if (g_ctx->pcap.write_idx >= (PCAPNG_WRITEBUFSIZE/16)*15) { + if(g_ctx->pcap.write_idx >= (PCAPNG_WRITEBUFSIZE/16)*15) { g_ctx->pcap.write_idx = 0; g_ctx->pcap.wrote_header = false; } @@ -122,7 +122,7 @@ pcapng_fflush() } /* Full write? */ - if (res == (int)g_ctx->pcap.write_idx) { + if(res == (int)g_ctx->pcap.write_idx) { LOG(PCAP, "drained %u bytes buffer to pcap file %s\n", g_ctx->pcap.write_idx, g_ctx->pcap.filename); g_ctx->pcap.write_idx = 0; @@ -130,7 +130,7 @@ pcapng_fflush() } /* Partial write? */ - if (res && res < (int)g_ctx->pcap.write_idx) { + if(res && res < (int)g_ctx->pcap.write_idx) { /* Rebase the buffer.*/ memmove(g_ctx->pcap.write_buf, g_ctx->pcap.write_buf+res, g_ctx->pcap.write_idx - res); g_ctx->pcap.write_idx -= res; @@ -144,19 +144,19 @@ pcapng_fflush() void pcapng_free() { - if (!g_ctx) { + if(!g_ctx) { return; } pcapng_fflush(); - if (g_ctx->pcap.fd != -1) { + if(g_ctx->pcap.fd != -1) { close(g_ctx->pcap.fd); g_ctx->pcap.fd = -1; return; } - if (g_ctx->pcap.write_buf) { + if(g_ctx->pcap.write_buf) { free(g_ctx->pcap.write_buf); g_ctx->pcap.write_buf = NULL; } @@ -169,7 +169,7 @@ static void bbl_pcap_push_le_uint(uint32_t length, uint64_t value) { /* Buffer overrun protection. */ - if ((g_ctx->pcap.write_idx + length) >= PCAPNG_WRITEBUFSIZE) { + if((g_ctx->pcap.write_idx + length) >= PCAPNG_WRITEBUFSIZE) { return; } @@ -277,7 +277,7 @@ pcapng_push_packet_header(struct timespec *ts, uint8_t *data, uint32_t packet_le uint32_t start_idx, total_length; uint64_t ts_usec; - if (!g_ctx->pcap.wrote_header) { + if(!g_ctx->pcap.wrote_header) { pcapng_push_section_header(); /* Push a list of interfaces. */ @@ -319,7 +319,7 @@ pcapng_push_packet_header(struct timespec *ts, uint8_t *data, uint32_t packet_le packet_length, g_ctx->pcap.write_idx, PCAPNG_WRITEBUFSIZE); /* Buffer about to be overrun? */ - if (g_ctx->pcap.write_idx >= (PCAPNG_WRITEBUFSIZE/16)*15) { + if(g_ctx->pcap.write_idx >= (PCAPNG_WRITEBUFSIZE/16)*15) { pcapng_fflush(); } } \ No newline at end of file diff --git a/code/bngblaster/src/bbl_protocols.c b/code/bngblaster/src/bbl_protocols.c index c25685a1..5906a9ab 100644 --- a/code/bngblaster/src/bbl_protocols.c +++ b/code/bngblaster/src/bbl_protocols.c @@ -49,7 +49,7 @@ _checksum(void *buf, ssize_t len) len -= 2; } /* Add left-over byte, if any */ - if (len) { + if(len) { result += *(uint8_t*)cur; } return result; @@ -1971,7 +1971,7 @@ encode_ethernet(uint8_t *buf, uint16_t *len, } BUMP_WRITE_BUFFER(buf, len, sizeof(uint32_t)); } - } else if (eth->type == ISIS_PROTOCOL_IDENTIFIER) { + } else if(eth->type == ISIS_PROTOCOL_IDENTIFIER) { /* Remember ethernet length field position */ eth_len_ptr = (uint16_t*)buf; BUMP_WRITE_BUFFER(buf, len, sizeof(uint16_t)); diff --git a/code/bngblaster/src/bbl_session.c b/code/bngblaster/src/bbl_session.c index 3064a984..831c3052 100644 --- a/code/bngblaster/src/bbl_session.c +++ b/code/bngblaster/src/bbl_session.c @@ -829,7 +829,7 @@ bbl_sessions_init() if(access_config->vlan_mode == VLAN_MODE_11) { /* Add 1:1 sessions to VLAN/session dictionary */ result = dict_insert(g_ctx->vlan_session_dict, &session->vlan_key); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = session; } } @@ -860,7 +860,7 @@ NEXT: if(access_config->next) { access_config = access_config->next; } else { - if (t) { + if(t) { t = 0; access_config = g_ctx->config.access_config; } else { @@ -905,7 +905,7 @@ bbl_session_id_from_broadcast(bbl_interface_s *interface, bbl_ethernet_header_s ipv4 = (bbl_ipv4_s*)eth->next; if(ipv4->protocol == PROTOCOL_IPV4_UDP) { udp = (bbl_udp_s*)ipv4->next; - if (udp->protocol == UDP_PROTOCOL_DHCP) { + if(udp->protocol == UDP_PROTOCOL_DHCP) { dhcp = (bbl_dhcp_s*)udp->next; session_id |= ((uint8_t*)(dhcp->header->chaddr))[5]; session_id |= ((uint8_t*)(dhcp->header->chaddr))[4] << 8; diff --git a/code/bngblaster/src/bbl_stream.c b/code/bngblaster/src/bbl_stream.c index e3b41a21..6ad264e0 100644 --- a/code/bngblaster/src/bbl_stream.c +++ b/code/bngblaster/src/bbl_stream.c @@ -2173,7 +2173,7 @@ bbl_stream_ctrl_info(int fd, uint32_t session_id __attribute__((unused)), json_t uint64_t flow_id; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:i}", "flow-id", &number) != 0) { + if(json_unpack(arguments, "{s:i}", "flow-id", &number) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing flow-id"); } diff --git a/code/bngblaster/src/bbl_tcp.c b/code/bngblaster/src/bbl_tcp.c index 3d0f9052..a2e156c1 100644 --- a/code/bngblaster/src/bbl_tcp.c +++ b/code/bngblaster/src/bbl_tcp.c @@ -131,7 +131,7 @@ bbl_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb, u16_t len) { } } - if (result == ERR_MEM) { + if(result == ERR_MEM) { tcp_output(tpcb); } return result; diff --git a/code/bngblaster/src/bbl_tx.c b/code/bngblaster/src/bbl_tx.c index 3e0adfdc..98cf64d5 100644 --- a/code/bngblaster/src/bbl_tx.c +++ b/code/bngblaster/src/bbl_tx.c @@ -757,7 +757,7 @@ bbl_lcp_simeout(timer_s *timer) session->send_requests |= BBL_SEND_LCP_REQUEST; bbl_session_tx_qnode_insert(session); } - } else if (session->session_state == BBL_PPP_TERMINATING) { + } else if(session->session_state == BBL_PPP_TERMINATING) { if(session->lcp_retries > 3) { /* Send max 3 terminate requests. */ bbl_session_update_state(session, BBL_TERMINATING); @@ -1287,53 +1287,53 @@ bbl_tx_encode_packet(bbl_session_s *session, uint8_t *buf, uint16_t *len) if(session->send_requests & BBL_SEND_DISCOVERY) { result = bbl_tx_encode_packet_discovery(session); session->send_requests &= ~BBL_SEND_DISCOVERY; - } else if (session->send_requests & BBL_SEND_LCP_REQUEST) { + } else if(session->send_requests & BBL_SEND_LCP_REQUEST) { result = bbl_tx_encode_packet_lcp_request(session); session->send_requests &= ~BBL_SEND_LCP_REQUEST; session->lcp_retries++; - } else if (session->send_requests & BBL_SEND_LCP_RESPONSE) { + } else if(session->send_requests & BBL_SEND_LCP_RESPONSE) { result = bbl_tx_encode_packet_lcp_response(session); session->send_requests &= ~BBL_SEND_LCP_RESPONSE; - } else if (session->send_requests & BBL_SEND_PAP_REQUEST) { + } else if(session->send_requests & BBL_SEND_PAP_REQUEST) { result = bbl_tx_encode_packet_pap_request(session); session->send_requests &= ~BBL_SEND_PAP_REQUEST; session->auth_retries++; - } else if (session->send_requests & BBL_SEND_CHAP_RESPONSE) { + } else if(session->send_requests & BBL_SEND_CHAP_RESPONSE) { result = bbl_tx_encode_packet_chap_response(session); session->send_requests &= ~BBL_SEND_CHAP_RESPONSE; session->auth_retries++; - } else if (session->send_requests & BBL_SEND_IPCP_REQUEST) { + } else if(session->send_requests & BBL_SEND_IPCP_REQUEST) { result = bbl_tx_encode_packet_ipcp_request(session); session->send_requests &= ~BBL_SEND_IPCP_REQUEST; session->ipcp_retries++; - } else if (session->send_requests & BBL_SEND_IPCP_RESPONSE) { + } else if(session->send_requests & BBL_SEND_IPCP_RESPONSE) { result = bbl_tx_encode_packet_ipcp_response(session); session->send_requests &= ~BBL_SEND_IPCP_RESPONSE; - } else if (session->send_requests & BBL_SEND_IP6CP_REQUEST) { + } else if(session->send_requests & BBL_SEND_IP6CP_REQUEST) { result = bbl_tx_encode_packet_ip6cp_request(session); session->send_requests &= ~BBL_SEND_IP6CP_REQUEST; session->ip6cp_retries++; - } else if (session->send_requests & BBL_SEND_IP6CP_RESPONSE) { + } else if(session->send_requests & BBL_SEND_IP6CP_RESPONSE) { result = bbl_tx_encode_packet_ip6cp_response(session); session->send_requests &= ~BBL_SEND_IP6CP_RESPONSE; - } else if (session->send_requests & BBL_SEND_ICMPV6_RS) { + } else if(session->send_requests & BBL_SEND_ICMPV6_RS) { result = bbl_tx_encode_packet_icmpv6_rs(session); session->send_requests &= ~BBL_SEND_ICMPV6_RS; - } else if (session->send_requests & BBL_SEND_DHCPV6_REQUEST) { + } else if(session->send_requests & BBL_SEND_DHCPV6_REQUEST) { result = bbl_tx_encode_packet_dhcpv6_request(session); session->send_requests &= ~BBL_SEND_DHCPV6_REQUEST; - } else if (session->send_requests & BBL_SEND_IGMP) { + } else if(session->send_requests & BBL_SEND_IGMP) { result = bbl_tx_encode_packet_igmp(session); - } else if (session->send_requests & BBL_SEND_ARP_REQUEST) { + } else if(session->send_requests & BBL_SEND_ARP_REQUEST) { result = bbl_tx_encode_packet_arp_request(session); session->send_requests &= ~BBL_SEND_ARP_REQUEST; - } else if (session->send_requests & BBL_SEND_ARP_REPLY) { + } else if(session->send_requests & BBL_SEND_ARP_REPLY) { result = bbl_tx_encode_packet_arp_reply(session); session->send_requests &= ~BBL_SEND_ARP_REPLY; - } else if (session->send_requests & BBL_SEND_DHCP_REQUEST) { + } else if(session->send_requests & BBL_SEND_DHCP_REQUEST) { result = bbl_tx_encode_packet_dhcp(session); session->send_requests &= ~BBL_SEND_DHCP_REQUEST; - } else if (session->send_requests & BBL_SEND_CFM_CC) { + } else if(session->send_requests & BBL_SEND_CFM_CC) { result = bbl_tx_encode_packet_cfm_cc(session); session->send_requests &= ~BBL_SEND_CFM_CC; } else { @@ -1532,7 +1532,7 @@ bbl_tx(bbl_interface_s *interface, uint8_t *buf, uint16_t *len) } return result; } - } else if (interface->a10nsp) { + } else if(interface->a10nsp) { a10nsp_interface = interface->a10nsp; if(!bbl_txq_is_empty(a10nsp_interface->txq)) { *len = bbl_txq_from_buffer(a10nsp_interface->txq, buf); @@ -1563,7 +1563,7 @@ bbl_tx(bbl_interface_s *interface, uint8_t *buf, uint16_t *len) } } /* L2TP packets. */ - if (!CIRCLEQ_EMPTY(&network_interface->l2tp_tx_qhead)) { + if(!CIRCLEQ_EMPTY(&network_interface->l2tp_tx_qhead)) { /* Pop element from queue. */ l2tpq = CIRCLEQ_FIRST(&network_interface->l2tp_tx_qhead); CIRCLEQ_REMOVE(&network_interface->l2tp_tx_qhead, l2tpq, tx_qnode); diff --git a/code/bngblaster/src/bgp/bgp_ctrl.c b/code/bngblaster/src/bgp/bgp_ctrl.c index 000563f3..98d304e1 100644 --- a/code/bngblaster/src/bgp/bgp_ctrl.c +++ b/code/bngblaster/src/bgp/bgp_ctrl.c @@ -89,12 +89,12 @@ bgp_ctrl_sessions(int fd, uint32_t session_id __attribute__((unused)), json_t *a uint32_t ipv4_peer_address = 0; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_local_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid local-ipv4-address"); } } - if (json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_peer_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid peer-ipv4-address"); } @@ -159,15 +159,15 @@ bgp_ctrl_raw_update(int fd, uint32_t session_id __attribute__((unused)), json_t uint32_t ipv4_peer_address = 0; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "file", &file_path) != 0) { + if(json_unpack(arguments, "{s:s}", "file", &file_path) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing argument file"); } - if (json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_local_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid local-ipv4-address"); } } - if (json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_peer_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid peer-ipv4-address"); } @@ -273,12 +273,12 @@ bgp_ctrl_disconnect(int fd, uint32_t session_id __attribute__((unused)), json_t uint32_t ipv4_peer_address = 0; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "local-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_local_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid local-ipv4-address"); } } - if (json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { + if(json_unpack(arguments, "{s:s}", "peer-ipv4-address", &s) == 0) { if(!inet_pton(AF_INET, s, &ipv4_peer_address)) { return bbl_ctrl_status(fd, "error", 400, "invalid peer-ipv4-address"); } diff --git a/code/bngblaster/src/bgp/bgp_message.c b/code/bngblaster/src/bgp/bgp_message.c index 7189ac15..f9e7e620 100644 --- a/code/bngblaster/src/bgp/bgp_message.c +++ b/code/bngblaster/src/bgp/bgp_message.c @@ -54,7 +54,7 @@ bgp_push_open_message(bgp_session_s *session) uint32_t open_start_idx, length, opt_parms_idx, opt_parms_length; io_buffer_t *buffer = &session->write_buf; - if (buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { + if(buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { return; } @@ -97,7 +97,7 @@ bgp_push_keepalive_message(bgp_session_s *session) uint32_t keepalive_start_idx, length; io_buffer_t *buffer = &session->write_buf; - if (buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { + if(buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { return; } @@ -118,7 +118,7 @@ bgp_push_notification_message(bgp_session_s *session) uint32_t notification_start_idx, length; io_buffer_t *buffer = &session->write_buf; - if (buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { + if(buffer->idx > (buffer->size - BGP_MIN_MESSAGE_SIZE)) { return; } diff --git a/code/bngblaster/src/bgp/bgp_raw_update.c b/code/bngblaster/src/bgp/bgp_raw_update.c index 5018069c..f7d113f3 100644 --- a/code/bngblaster/src/bgp/bgp_raw_update.c +++ b/code/bngblaster/src/bgp/bgp_raw_update.c @@ -22,7 +22,7 @@ bgp_raw_update_load_file(const char *file, bool decode_file) /* Open file */ FILE *f = fopen(file, "rb"); - if (f == NULL) { + if(f == NULL) { LOG(ERROR, "Failed to open BGP RAW update file %s\n", file); return NULL; } @@ -101,7 +101,7 @@ bgp_raw_update_load(const char *file, bool decode_file) /* Check if file is already loaded */ while(raw_update){ - if (strcmp(file, raw_update->file) == 0) { + if(strcmp(file, raw_update->file) == 0) { return raw_update; } raw_update = raw_update->next; diff --git a/code/bngblaster/src/bgp/bgp_receive.c b/code/bngblaster/src/bgp/bgp_receive.c index 45a888fd..dd1d9187 100644 --- a/code/bngblaster/src/bgp/bgp_receive.c +++ b/code/bngblaster/src/bgp/bgp_receive.c @@ -176,7 +176,7 @@ bgp_rebase_read_buffer(bgp_session_s *session) io_buffer_t *buffer = &session->read_buf; size = buffer->idx - buffer->start_idx; - if (size) { + if(size) { /* Copy what is left to the buffer start. */ memcpy(buffer->data, buffer->data+buffer->start_idx, size); } @@ -198,19 +198,19 @@ bpg_read(bgp_session_s *session) size = buffer->idx - buffer->start_idx; /* Minimum message size */ - if (size < BGP_MIN_MESSAGE_SIZE) { + if(size < BGP_MIN_MESSAGE_SIZE) { break; } length = read_be_uint(start+16, 2); - if (length < BGP_MIN_MESSAGE_SIZE || + if(length < BGP_MIN_MESSAGE_SIZE || length > BGP_MAX_MESSAGE_SIZE) { bgp_decode_error(session); break; } /* Full message on the wire to consume? */ - if (length > size) { + if(length > size) { break; } diff --git a/code/bngblaster/src/bgp/bgp_session.c b/code/bngblaster/src/bgp/bgp_session.c index b9e0bd17..a203357f 100644 --- a/code/bngblaster/src/bgp/bgp_session.c +++ b/code/bngblaster/src/bgp/bgp_session.c @@ -203,7 +203,7 @@ bgp_session_state_established(bgp_session_s *session) void bgp_session_state_change(bgp_session_s *session, bgp_state_t new_state) { - if (session->state == new_state) { + if(session->state == new_state) { return; } diff --git a/code/bngblaster/src/io/io_interface.c b/code/bngblaster/src/io/io_interface.c index a4e22bf9..22dc0509 100644 --- a/code/bngblaster/src/io/io_interface.c +++ b/code/bngblaster/src/io/io_interface.c @@ -51,7 +51,7 @@ set_promisc(bbl_interface_s *interface) { /* This socket is only opened, but not closed. Closing the socket would reset * its flags - effectively removing the just added promisc mode. * We want to keep the interface in promisc mode until the end of the program. */ - if ((sfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1) { + if((sfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) == -1) { LOG_NOARG(ERROR, "Unable to open control socket for promiscuous mode activation\n"); return false; } diff --git a/code/bngblaster/src/io/io_raw.c b/code/bngblaster/src/io/io_raw.c index a932f982..db114894 100644 --- a/code/bngblaster/src/io/io_raw.c +++ b/code/bngblaster/src/io/io_raw.c @@ -44,7 +44,7 @@ io_raw_rx_job(timer_s *timer) eth->timestamp.tv_sec = io->timestamp.tv_sec; eth->timestamp.tv_nsec = io->timestamp.tv_nsec; bbl_rx_handler(interface, eth); - } else if (decode_result == UNKNOWN_PROTOCOL) { + } else if(decode_result == UNKNOWN_PROTOCOL) { io->stats.unknown++; } else { io->stats.protocol_errors++; diff --git a/code/bngblaster/src/io/io_socket.c b/code/bngblaster/src/io/io_socket.c index 8b96d51c..0bc74555 100644 --- a/code/bngblaster/src/io/io_socket.c +++ b/code/bngblaster/src/io/io_socket.c @@ -24,7 +24,7 @@ set_qdisc_bypass(io_handle_s *io) { * increased drops when network device transmit queues are busy; * therefore, use at your own risk. */ int qdisc_bypass = 1; - if (setsockopt(io->fd, SOL_PACKET, PACKET_QDISC_BYPASS, &qdisc_bypass, sizeof(qdisc_bypass)) == -1) { + if(setsockopt(io->fd, SOL_PACKET, PACKET_QDISC_BYPASS, &qdisc_bypass, sizeof(qdisc_bypass)) == -1) { LOG(ERROR, "Failed to set qdisc bypass for interface %s - %s (%d)\n", io->interface->name, strerror(errno), errno); return false; @@ -37,7 +37,7 @@ static bool set_fanout(io_handle_s *io) { if(io->fanout_id && io->direction == IO_INGRESS) { int fanout_arg = (io->fanout_id | (io->fanout_type << 16)); - if (setsockopt(io->fd, SOL_PACKET, PACKET_FANOUT, &fanout_arg, sizeof(fanout_arg)) == -1) { + if(setsockopt(io->fd, SOL_PACKET, PACKET_FANOUT, &fanout_arg, sizeof(fanout_arg)) == -1) { LOG(ERROR, "Failed to set fanout group for interface %s - %s (%d)\n", io->interface->name, strerror(errno), errno); return false; @@ -49,7 +49,7 @@ set_fanout(io_handle_s *io) { /* Set packet version (TPACKET_V1, TPACKET_V2 or TPACKET_V3). */ static bool set_packet_version(io_handle_s *io, int version) { - if ((setsockopt(io->fd, SOL_PACKET, PACKET_VERSION, &version, sizeof(version))) == -1) { + if((setsockopt(io->fd, SOL_PACKET, PACKET_VERSION, &version, sizeof(version))) == -1) { LOG(ERROR, "Failed to set packet version error for interface %s - %s (%d)\n", io->interface->name, strerror(errno), errno); return false; @@ -83,7 +83,7 @@ set_ring(io_handle_s *io, int slots) { LOG(DEBUG, "Setup %u byte packet_mmap ringbuffer (%d slots) for interface %s\n", ring_size, slots, io->interface->name); - if (setsockopt(io->fd, SOL_PACKET, flag, &io->req, sizeof(struct tpacket_req)) == -1) { + if(setsockopt(io->fd, SOL_PACKET, flag, &io->req, sizeof(struct tpacket_req)) == -1) { LOG(ERROR, "Allocating ringbuffer error for interface %s - %s (%d)\n", io->interface->name, strerror(errno), errno); return false; @@ -123,7 +123,7 @@ io_socket_open(io_handle_s *io) { io->addr.sll_family = AF_PACKET; io->addr.sll_ifindex = io->interface->ifindex; io->addr.sll_protocol = protocol; - if (bind(io->fd, (struct sockaddr*)&io->addr, sizeof(io->addr)) == -1) { + if(bind(io->fd, (struct sockaddr*)&io->addr, sizeof(io->addr)) == -1) { LOG(ERROR, "Failed to bind socket for interface %s - %s (%d)\n", io->interface->name, strerror(errno), errno); return false; diff --git a/code/bngblaster/src/io/io_thread.c b/code/bngblaster/src/io/io_thread.c index 597f7dff..ffc1519f 100644 --- a/code/bngblaster/src/io/io_thread.c +++ b/code/bngblaster/src/io/io_thread.c @@ -129,13 +129,13 @@ io_thread_main_rx_job(timer_s *timer) eth->timestamp.tv_sec = slot->timestamp.tv_sec; eth->timestamp.tv_nsec = slot->timestamp.tv_nsec; bbl_rx_handler(interface, eth); - } else if (decode_result == UNKNOWN_PROTOCOL) { + } else if(decode_result == UNKNOWN_PROTOCOL) { io->stats.unknown++; } else { io->stats.protocol_errors++; } /* Dump the packet into pcap file. */ - if (g_ctx->pcap.write_buf && (!eth->bbl || g_ctx->pcap.include_streams)) { + if(g_ctx->pcap.write_buf && (!eth->bbl || g_ctx->pcap.include_streams)) { pcap = true; pcapng_push_packet_header(&io->timestamp, io->buf, io->buf_len, interface->pcap_index, PCAPNG_EPB_FLAGS_INBOUND); diff --git a/code/bngblaster/src/isis/isis_checksum.c b/code/bngblaster/src/isis/isis_checksum.c index 7a816004..bd35ecb8 100644 --- a/code/bngblaster/src/isis/isis_checksum.c +++ b/code/bngblaster/src/isis/isis_checksum.c @@ -55,11 +55,11 @@ isis_checksum_fletcher16(uint8_t *buf, uint16_t len, uint16_t offset) * is taken as a signed value. */ x = (int)((len - offset - 1) * c0 - c1) % 255; - if (x <= 0) { + if(x <= 0) { x += 255; } y = 510 - c0 - x; - if (y > 255) { + if(y > 255) { y -= 255; } diff --git a/code/bngblaster/src/isis/isis_ctrl.c b/code/bngblaster/src/isis/isis_ctrl.c index ea4acb60..3305850e 100644 --- a/code/bngblaster/src/isis/isis_ctrl.c +++ b/code/bngblaster/src/isis/isis_ctrl.c @@ -178,13 +178,13 @@ isis_ctrl_database(int fd, uint32_t session_id __attribute__((unused)), json_t * int level = 0; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { + if(json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing ISIS instance"); } - if (json_unpack(arguments, "{s:i}", "level", &level) != 0) { + if(json_unpack(arguments, "{s:i}", "level", &level) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing ISIS level"); } - if (!(level == ISIS_LEVEL_1 || level == ISIS_LEVEL_2)) { + if(!(level == ISIS_LEVEL_1 || level == ISIS_LEVEL_2)) { return bbl_ctrl_status(fd, "error", 400, "invalid ISIS level"); } @@ -197,7 +197,7 @@ isis_ctrl_database(int fd, uint32_t session_id __attribute__((unused)), json_t * instance = instance->next; } - if (!instance) { + if(!instance) { return bbl_ctrl_status(fd, "error", 400, "ISIS instance not found"); } @@ -233,10 +233,10 @@ isis_ctrl_load_mrt(int fd, uint32_t session_id __attribute__((unused)), json_t * isis_instance_s *instance = NULL; /* Unpack further arguments */ - if (json_unpack(arguments, "{s:s}", "file", &file_path) != 0) { + if(json_unpack(arguments, "{s:s}", "file", &file_path) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing MRT file"); } - if (json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { + if(json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing ISIS instance"); } @@ -249,7 +249,7 @@ isis_ctrl_load_mrt(int fd, uint32_t session_id __attribute__((unused)), json_t * instance = instance->next; } - if (!instance) { + if(!instance) { return bbl_ctrl_status(fd, "error", 404, "ISIS instance not found"); } @@ -280,7 +280,7 @@ isis_ctrl_lsp_update(int fd, uint32_t session_id __attribute__((unused)), json_t /* Unpack further arguments */ - if (json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { + if(json_unpack(arguments, "{s:i}", "instance", &instance_id) != 0) { return bbl_ctrl_status(fd, "error", 400, "missing ISIS instance"); } @@ -293,13 +293,13 @@ isis_ctrl_lsp_update(int fd, uint32_t session_id __attribute__((unused)), json_t instance = instance->next; } - if (!instance) { + if(!instance) { return bbl_ctrl_status(fd, "error", 404, "ISIS instance not found"); } /* Process PDU array */ value = json_object_get(arguments, "pdu"); - if (json_is_array(value)) { + if(json_is_array(value)) { pdu_count = json_array_size(value); for (size_t i = 0; i < pdu_count; i++) { pdu_string = json_string_value(json_array_get(value, i)); diff --git a/code/bngblaster/src/isis/isis_lsp.c b/code/bngblaster/src/isis/isis_lsp.c index eab1beed..c4b918bf 100644 --- a/code/bngblaster/src/isis/isis_lsp.c +++ b/code/bngblaster/src/isis/isis_lsp.c @@ -32,7 +32,7 @@ isis_lsp_flood_adjacency(isis_lsp_s *lsp, isis_adjacency_s *adjacency) flood->tx_count = 0; } else { result = hb_tree_insert(adjacency->flood_tree, &lsp->id); - if (result.inserted) { + if(result.inserted) { flood = calloc(1, sizeof(isis_flood_entry_s)); flood->lsp = lsp; *result.datum_ptr = flood; @@ -350,7 +350,7 @@ isis_lsp_self_update(isis_instance_s *instance, uint8_t level) /* Create new LSP. */ lsp = isis_lsp_new(lsp_id, level, instance); result = hb_tree_insert(lsdb, &lsp->id); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = lsp; } else { LOG_NOARG(ISIS, "Failed to add LSP to LSDB\n"); @@ -549,7 +549,7 @@ isis_lsp_handler_rx(bbl_network_interface_s *interface, isis_pdu_s *pdu, uint8_t /* Create new LSP. */ lsp = isis_lsp_new(lsp_id, level, adjacency->instance); result = hb_tree_insert(lsdb, &lsp->id); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = lsp; } else { LOG_NOARG(ISIS, "Failed to add LSP to LSDB\n"); @@ -579,7 +579,7 @@ isis_lsp_handler_rx(bbl_network_interface_s *interface, isis_pdu_s *pdu, uint8_t ACK: /* Add LSP to adjacency PSNP tree for acknowledgement. */ result = hb_tree_insert(adjacency->psnp_tree, &lsp->id); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = lsp; lsp->refcount++; if(!adjacency->timer_psnp_started) { @@ -708,7 +708,7 @@ isis_lsp_update_external(isis_instance_s *instance, isis_pdu_s *pdu) /* Create new LSP. */ lsp = isis_lsp_new(lsp_id, level, instance); result = hb_tree_insert(lsdb, &lsp->id); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = lsp; } else { LOG_NOARG(ISIS, "Failed to add LSP to LSDB\n"); diff --git a/code/bngblaster/src/isis/isis_mrt.c b/code/bngblaster/src/isis/isis_mrt.c index 034691ba..8d825e9a 100644 --- a/code/bngblaster/src/isis/isis_mrt.c +++ b/code/bngblaster/src/isis/isis_mrt.c @@ -95,7 +95,7 @@ isis_mrt_load(isis_instance_s *instance, char *file_path) /* Create new LSP. */ lsp = isis_lsp_new(lsp_id, level, instance); result = hb_tree_insert(lsdb, &lsp->id); - if (result.inserted) { + if(result.inserted) { *result.datum_ptr = lsp; } else { LOG_NOARG(ISIS, "Failed to add LSP to LSDB\n"); diff --git a/code/bngblaster/test/protocols_decode_pcap.c b/code/bngblaster/test/protocols_decode_pcap.c index fee02754..e456f993 100644 --- a/code/bngblaster/test/protocols_decode_pcap.c +++ b/code/bngblaster/test/protocols_decode_pcap.c @@ -84,13 +84,13 @@ main(int argc, char **argv) { } fp = pcap_open_offline(argv[1], errbuf); - if (fp == NULL) { + if(fp == NULL) { fprintf(stderr, "\nFailed to open PCAP: %s\n", errbuf); exit(1); } /* Load PCAP to memory... */ - if (pcap_loop(fp, 0, packet_handler, NULL) < 0) { + if(pcap_loop(fp, 0, packet_handler, NULL) < 0) { fprintf(stderr, "\nReading PCAP failed: %s\n", pcap_geterr(fp)); exit(1); }