From a5e7ffff166bdb69f993a04743b3a09e13237f5f Mon Sep 17 00:00:00 2001 From: scribam Date: Thu, 28 May 2026 20:18:34 +0200 Subject: [PATCH 1/2] Update uncrustify.cfg, format and use ci to check --- .github/workflows/uncrustify.yml | 18 + include/arch/pico_arm9.h | 2 +- include/arch/pico_atsamd21j18.h | 4 +- include/arch/pico_avr.h | 2 +- include/arch/pico_esp8266.h | 6 +- include/arch/pico_generic_gcc.h | 20 +- include/arch/pico_mbed.h | 8 +- include/arch/pico_msp430.h | 2 +- include/arch/pico_pic24.h | 10 +- include/arch/pico_pic32.h | 4 +- include/arch/pico_posix.h | 14 +- include/heap.h | 4 +- include/pico_addressing.h | 4 +- include/pico_config.h | 4 +- include/pico_constants.h | 6 +- include/pico_device.h | 4 +- include/pico_eth.h | 4 +- include/pico_frame.h | 4 +- include/pico_jobs.h | 2 +- include/pico_md5.h | 4 +- include/pico_protocol.h | 4 +- include/pico_queue.h | 8 +- include/pico_socket_multicast.h | 4 +- include/pico_stack.h | 16 +- include/pico_tree.h | 4 +- modules/pico_6lowpan.c | 493 ++- modules/pico_6lowpan.h | 6 +- modules/pico_6lowpan_ll.c | 36 +- modules/pico_6lowpan_ll.h | 4 +- modules/pico_802154.c | 22 +- modules/pico_802154.h | 6 +- modules/pico_aodv.c | 8 +- modules/pico_aodv.h | 4 +- modules/pico_arp.c | 41 +- modules/pico_arp.h | 4 +- modules/pico_dev_ipc.c | 20 +- modules/pico_dev_ipc.h | 4 +- modules/pico_dev_loop.c | 8 +- modules/pico_dev_loop.h | 4 +- modules/pico_dev_mock.c | 59 +- modules/pico_dev_mock.h | 4 +- modules/pico_dev_null.c | 6 +- modules/pico_dev_null.h | 4 +- modules/pico_dev_pcap.c | 8 +- modules/pico_dev_ppp.c | 56 +- modules/pico_dev_ppp.h | 4 +- modules/pico_dev_radio_mgr.c | 15 +- modules/pico_dev_radio_mgr.h | 4 +- modules/pico_dev_radiotest.c | 21 +- modules/pico_dev_radiotest.h | 4 +- modules/pico_dev_tap.c | 54 +- modules/pico_dev_tap.h | 4 +- modules/pico_dev_tap_windows.c | 399 +- modules/pico_dev_tap_windows.h | 4 +- modules/pico_dev_tap_windows_private.h | 4 +- modules/pico_dev_tun.c | 22 +- modules/pico_dev_tun.h | 4 +- modules/pico_dev_vde.c | 36 +- modules/pico_dev_vde.h | 4 +- modules/pico_dhcp_client.c | 38 +- modules/pico_dhcp_client.h | 4 +- modules/pico_dhcp_common.c | 7 +- modules/pico_dhcp_common.h | 4 +- modules/pico_dhcp_server.c | 18 +- modules/pico_dhcp_server.h | 4 +- modules/pico_dns_client.c | 55 +- modules/pico_dns_client.h | 4 +- modules/pico_dns_common.c | 265 +- modules/pico_dns_common.h | 128 +- modules/pico_dns_sd.c | 96 +- modules/pico_dns_sd.h | 44 +- modules/pico_ethernet.c | 32 +- modules/pico_ethernet.h | 4 +- modules/pico_fragments.c | 113 +- modules/pico_fragments.h | 4 +- modules/pico_hotplug_detection.c | 32 +- modules/pico_hotplug_detection.h | 4 +- modules/pico_icmp4.c | 32 +- modules/pico_icmp4.h | 4 +- modules/pico_icmp6.c | 75 +- modules/pico_icmp6.h | 10 +- modules/pico_igmp.c | 37 +- modules/pico_igmp.h | 4 +- modules/pico_ipfilter.c | 32 +- modules/pico_ipfilter.h | 4 +- modules/pico_ipv4.c | 129 +- modules/pico_ipv4.h | 5 +- modules/pico_ipv6.c | 106 +- modules/pico_ipv6.h | 4 +- modules/pico_ipv6_nd.c | 273 +- modules/pico_ipv6_nd.h | 4 +- modules/pico_ipv6_pmtu.c | 11 +- modules/pico_ipv6_pmtu.h | 4 +- modules/pico_mcast.c | 32 +- modules/pico_mcast.h | 4 +- modules/pico_mdns.c | 565 ++- modules/pico_mdns.h | 55 +- modules/pico_mld.c | 74 +- modules/pico_mld.h | 4 +- modules/pico_mm.c | 424 +- modules/pico_mm.h | 4 +- modules/pico_nat.c | 12 +- modules/pico_nat.h | 4 +- modules/pico_olsr.c | 145 +- modules/pico_olsr.h | 6 +- modules/pico_slaacv4.c | 66 +- modules/pico_slaacv4.h | 4 +- modules/pico_sntp_client.c | 46 +- modules/pico_sntp_client.h | 4 +- modules/pico_socket_ll.c | 12 +- modules/pico_socket_ll.h | 2 +- modules/pico_socket_tcp.c | 40 +- modules/pico_socket_tcp.h | 4 +- modules/pico_socket_udp.c | 35 +- modules/pico_socket_udp.h | 4 +- modules/pico_strings.c | 2 +- modules/pico_strings.h | 4 +- modules/pico_tcp.c | 175 +- modules/pico_tcp.h | 4 +- modules/pico_tftp.c | 6 +- modules/pico_tftp.h | 4 +- modules/pico_udp.c | 4 +- modules/pico_udp.h | 4 +- stack/pico_device.c | 45 +- stack/pico_frame.c | 4 +- stack/pico_jobs.c | 16 +- stack/pico_md5.c | 4 +- stack/pico_protocol.c | 53 +- stack/pico_socket.c | 163 +- stack/pico_socket_multicast.c | 202 +- stack/pico_stack.c | 92 +- stack/pico_tree.c | 152 +- test/examples/dhcp_client.c | 4 +- test/examples/dns_sd.c | 20 +- test/examples/iperfc.c | 2 +- test/examples/mdns.c | 14 +- test/examples/multicast_ip6_recv.c | 28 +- test/examples/multicast_ip6_send.c | 4 +- test/examples/multicast_recv.c | 26 +- test/examples/multicast_send.c | 2 +- test/examples/noop.c | 2 +- test/examples/slaacv4.c | 11 +- test/examples/sntp.c | 6 +- test/examples/tcpbench.c | 13 +- test/examples/tcpclient.c | 4 +- test/examples/tcpecho.c | 2 +- test/examples/tftp.c | 10 +- test/examples/udp_client.c | 14 +- test/examples/udp_echo.c | 8 +- test/examples/udpnat.c | 8 +- test/pico_faulty.h | 2 +- test/picoapp.c | 92 +- test/ppp.c | 6 +- test/test_tftp_app_client.c | 6 +- test/tickless.c | 23 +- test/unit/modunit_pico_6lowpan.c | 204 +- test/unit/modunit_pico_802154.c | 96 +- test/unit/modunit_pico_aodv.c | 5 +- test/unit/modunit_pico_dev_ppp.c | 19 +- test/unit/modunit_pico_dns_client.c | 2 +- test/unit/modunit_pico_dns_common.c | 2 +- test/unit/modunit_pico_dns_sd.c | 10 +- test/unit/modunit_pico_ethernet.c | 4 +- test/unit/modunit_pico_fragments.c | 4 +- test/unit/modunit_pico_frame.c | 6 +- test/unit/modunit_pico_hotplug_detection.c | 12 +- test/unit/modunit_pico_igmp.c | 20 +- test/unit/modunit_pico_ipv6_nd.c | 3306 ++++++++------- test/unit/modunit_pico_ipv6_pmtu.c | 692 ++-- test/unit/modunit_pico_mdns.c | 32 +- test/unit/modunit_pico_mld.c | 22 +- test/unit/modunit_pico_sntp_client.c | 30 +- test/unit/modunit_pico_strings.c | 28 +- test/unit/modunit_pico_tftp.c | 2 +- test/unit/modunit_queue.c | 22 +- test/unit/unit_arp.c | 2 +- test/unit/unit_dhcp.c | 16 +- test/unit/unit_dns.c | 2 +- test/unit/unit_icmp4.c | 12 +- test/unit/unit_ipv4.c | 23 +- test/unit/unit_ipv6.c | 31 +- test/unit/unit_mem_manager.c | 44 +- test/unit/unit_mocks.c | 18 +- test/unit/unit_pico_device.c | 30 +- test/unit/unit_rbtree.c | 9 +- test/unit/unit_socket.c | 6 +- test/unit/unit_timer.c | 10 +- test/units.c | 2 +- uncrustify.cfg | 4302 +++++++++++++++----- 189 files changed, 8231 insertions(+), 6709 deletions(-) create mode 100644 .github/workflows/uncrustify.yml diff --git a/.github/workflows/uncrustify.yml b/.github/workflows/uncrustify.yml new file mode 100644 index 00000000..b68e4a54 --- /dev/null +++ b/.github/workflows/uncrustify.yml @@ -0,0 +1,18 @@ +name: Uncrustify + +on: [ push, pull_request ] + +jobs: + uncrustify: + runs-on: ubuntu-slim + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Install uncrustify + run: | + sudo apt-get update + sudo apt-get install -y uncrustify + + - name: Check formatting + run: find . -iname "*.[hc]" -type f -exec uncrustify --check -c uncrustify.cfg -l C {} + diff --git a/include/arch/pico_arm9.h b/include/arch/pico_arm9.h index ac9c269b..ca4265c9 100644 --- a/include/arch/pico_arm9.h +++ b/include/arch/pico_arm9.h @@ -30,6 +30,6 @@ static inline unsigned long PICO_TIME_MS(void) static inline void PICO_IDLE(void) { unsigned long tick_now = __str9_tick; - while(tick_now == __str9_tick) ; + while (tick_now == __str9_tick); } diff --git a/include/arch/pico_atsamd21j18.h b/include/arch/pico_atsamd21j18.h index 27d272a0..c54dcca0 100644 --- a/include/arch/pico_atsamd21j18.h +++ b/include/arch/pico_atsamd21j18.h @@ -34,7 +34,7 @@ static inline void sam_dbg(const char *format, ...) print_uart(msg); } -//#define dbg sam_dbg +/*#define dbg sam_dbg */ #define dbg(...) do { } while(0) extern volatile uint32_t sam_tick; @@ -56,6 +56,6 @@ static inline unsigned long PICO_TIME_MS(void) static inline void PICO_IDLE(void) { unsigned long tick_now = sam_tick; - while(tick_now == sam_tick) ; + while (tick_now == sam_tick); } diff --git a/include/arch/pico_avr.h b/include/arch/pico_avr.h index bd5f7207..c8ef862d 100644 --- a/include/arch/pico_avr.h +++ b/include/arch/pico_avr.h @@ -34,6 +34,6 @@ static inline unsigned long PICO_TIME_MS(void) static inline void PICO_IDLE(void) { unsigned long tick_now = __avr_tick; - while(tick_now == __avr_tick) ; + while (tick_now == __avr_tick); } diff --git a/include/arch/pico_esp8266.h b/include/arch/pico_esp8266.h index fecac73e..e07478e5 100644 --- a/include/arch/pico_esp8266.h +++ b/include/arch/pico_esp8266.h @@ -19,8 +19,8 @@ #define dbg printf /* -------------- MEMORY ------------- */ -extern void *pvPortMalloc( size_t xWantedSize ); -extern void vPortFree( void *pv ); +extern void *pvPortMalloc(size_t xWantedSize); +extern void vPortFree(void *pv); #define pico_free vPortFree @@ -28,7 +28,7 @@ static inline void *pico_zalloc(size_t size) { void *ptr = (void *)pvPortMalloc(size); - if(ptr) + if (ptr) memset(ptr, 0u, size); return ptr; diff --git a/include/arch/pico_generic_gcc.h b/include/arch/pico_generic_gcc.h index 79ef41d7..6a295011 100644 --- a/include/arch/pico_generic_gcc.h +++ b/include/arch/pico_generic_gcc.h @@ -29,8 +29,8 @@ extern volatile unsigned int pico_ms_tick; extern void *pico_mutex_init(void); extern void pico_mutex_lock(void*); extern void pico_mutex_unlock(void*); -extern void *pvPortMalloc( size_t xSize ); -extern void vPortFree( void *pv ); +extern void *pvPortMalloc(size_t xSize); +extern void vPortFree(void *pv); #define pico_free(x) vPortFree(x) #define free(x) vPortFree(x) @@ -39,7 +39,7 @@ static inline void *pico_zalloc(size_t size) { void *ptr = pvPortMalloc(size); - if(ptr) + if (ptr) memset(ptr, 0u, size); return ptr; @@ -53,25 +53,25 @@ extern int32_t prescale_time; static inline pico_time PICO_TIME_MS() { #ifdef TIME_PRESCALE - return pico_ms_tick << prescale_time; + return pico_ms_tick << prescale_time; #else - return pico_ms_tick; + return pico_ms_tick; #endif } static inline pico_time PICO_TIME() { #ifdef TIME_PRESCALE - return (pico_ms_tick / 1000) << prescale_time; + return (pico_ms_tick / 1000) << prescale_time; #else - return (pico_ms_tick / 1000); + return (pico_ms_tick / 1000); #endif } static inline void PICO_IDLE(void) { pico_time now = PICO_TIME_MS(); - while(now == PICO_TIME_MS()) ; + while (now == PICO_TIME_MS()); } #else /* NO RTOS SUPPORT */ @@ -88,7 +88,7 @@ extern void memmeas_free(void *); static inline void *pico_zalloc(size_t size) { void *ptr = malloc(size); - if(ptr) + if (ptr) memset(ptr, 0u, size); return ptr; @@ -108,7 +108,7 @@ static inline pico_time PICO_TIME(void) static inline void PICO_IDLE(void) { unsigned int now = pico_ms_tick; - while(now == pico_ms_tick) ; + while (now == pico_ms_tick); } #endif /* IFNDEF RTOS */ diff --git a/include/arch/pico_mbed.h b/include/arch/pico_mbed.h index cb140c70..7490f936 100644 --- a/include/arch/pico_mbed.h +++ b/include/arch/pico_mbed.h @@ -26,8 +26,8 @@ #define dbg(...) /* - #define MEMORY_MEASURE - #define JENKINS_DEBUG + #define MEMORY_MEASURE + #define JENKINS_DEBUG */ /* Intended for Mr. Jenkins endurance test loggings */ @@ -80,7 +80,7 @@ static inline void *pico_zalloc(int x) #ifdef JENKINS_DEBUG if (!stats) { jenkins_dbg(">> OUT OF MEM\n"); - while(1) ; + while (1); ; } @@ -106,7 +106,7 @@ static inline void pico_free(void *x) #ifdef MEMORY_MEASURE_ADV if ((stats->signature != 0xdeadbeef) || (x != stats->mem)) { jenkins_dbg(">> FREE ERROR: caller is %p\n", __builtin_return_address(0)); - while(1) ; + while (1); ; } diff --git a/include/arch/pico_msp430.h b/include/arch/pico_msp430.h index c2fc7bda..b6cc7ab6 100644 --- a/include/arch/pico_msp430.h +++ b/include/arch/pico_msp430.h @@ -27,7 +27,7 @@ static inline void *pico_zalloc(size_t size) { void *ptr = malloc(size); - if(ptr) + if (ptr) memset(ptr, 0u, size); return ptr; diff --git a/include/arch/pico_pic24.h b/include/arch/pico_pic24.h index eb3f1175..8bfac847 100644 --- a/include/arch/pico_pic24.h +++ b/include/arch/pico_pic24.h @@ -20,9 +20,9 @@ #endif /* - #ifndef __PIC24FJ256GA106__ - #define __PIC24FJ256GA106__ - #endif + #ifndef __PIC24FJ256GA106__ + #define __PIC24FJ256GA106__ + #endif */ #ifndef PICO_MAX_SOCKET_FRAMES @@ -59,7 +59,7 @@ static inline void pico_free(void *tgt) # define pico_free(x) free(x) #endif -extern void *pvPortMalloc( size_t xWantedSize ); +extern void *pvPortMalloc(size_t xWantedSize); extern volatile pico_time __pic24_tick; static inline unsigned long PICO_TIME(void) @@ -94,7 +94,7 @@ static inline void PICO_IDLE(void) TIMBASE_INT_E = 1; /* Doesn't matter that this call isn't interrupt safe, */ /* we just check for the value to change */ - while(tick_now == __pic24_tick) ; + while (tick_now == __pic24_tick); } #endif diff --git a/include/arch/pico_pic32.h b/include/arch/pico_pic32.h index ff902e44..227c306f 100644 --- a/include/arch/pico_pic32.h +++ b/include/arch/pico_pic32.h @@ -28,7 +28,7 @@ extern volatile unsigned int pico_ms_tick; static inline void *pico_zalloc(size_t size) { void *ptr = malloc(size); - if(ptr) + if (ptr) memset(ptr, 0u, size); return ptr; @@ -47,7 +47,7 @@ static inline pico_time PICO_TIME(void) static inline void PICO_IDLE(void) { unsigned int now = pico_ms_tick; - while(now == pico_ms_tick) ; + while (now == pico_ms_tick); } #endif /* PICO_PIC32 */ diff --git a/include/arch/pico_posix.h b/include/arch/pico_posix.h index e864aedd..dfe561e0 100644 --- a/include/arch/pico_posix.h +++ b/include/arch/pico_posix.h @@ -12,9 +12,9 @@ #include /* - #define MEMORY_MEASURE - #define TIME_PRESCALE - #define PICO_SUPPORT_THREADING + #define MEMORY_MEASURE + #define TIME_PRESCALE + #define PICO_SUPPORT_THREADING */ /* uncomment for debugging */ @@ -71,18 +71,18 @@ extern volatile uint32_t pico_ms_tick; static inline uint32_t PICO_TIME(void) { #ifdef TIME_PRESCALE - return (pico_ms_tick / 1000) << prescale_time; + return (pico_ms_tick / 1000) << prescale_time; #else - return (pico_ms_tick / 1000); + return (pico_ms_tick / 1000); #endif } static inline uint32_t PICO_TIME_MS(void) { #ifdef TIME_PRESCALE - return pico_ms_tick << prescale_time; + return pico_ms_tick << prescale_time; #else - return pico_ms_tick; + return pico_ms_tick; #endif } diff --git a/include/heap.h b/include/heap.h index 988dae3f..0671dd6d 100644 --- a/include/heap.h +++ b/include/heap.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_addressing.h b/include/pico_addressing.h index e47f3e1c..48f8e9b0 100644 --- a/include/pico_addressing.h +++ b/include/pico_addressing.h @@ -71,8 +71,8 @@ PACKED_STRUCT_DEF pico_6lowpan_ext PACKED_STRUCT_DEF pico_ll { uint16_t proto; uint16_t hatype; - uint8_t pktype; - uint8_t halen; + uint8_t pktype; + uint8_t halen; struct pico_eth hwaddr; struct pico_device *dev; }; diff --git a/include/pico_config.h b/include/pico_config.h index 27ca2f10..ffc96ad9 100644 --- a/include/pico_config.h +++ b/include/pico_config.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_constants.h b/include/pico_constants.h index 66264469..1d0348f3 100644 --- a/include/pico_constants.h +++ b/include/pico_constants.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -68,7 +68,7 @@ static inline uint32_t pico_hash(const void *buf, uint32_t size) uint32_t hash = 5381; uint32_t i; const uint8_t *ptr = (const uint8_t *)buf; - for(i = 0; i < size; i++) + for (i = 0; i < size; i++) hash = ((hash << 5) + hash) + ptr[i]; /* hash * 33 + char */ return hash; } diff --git a/include/pico_device.h b/include/pico_device.h index edfd4cd2..df66f10a 100644 --- a/include/pico_device.h +++ b/include/pico_device.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_eth.h b/include/pico_eth.h index 5bbd4599..38a0d892 100644 --- a/include/pico_eth.h +++ b/include/pico_eth.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_frame.h b/include/pico_frame.h index e1ccf54b..ca503e4c 100644 --- a/include/pico_frame.h +++ b/include/pico_frame.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_jobs.h b/include/pico_jobs.h index 1d2c421b..fcf30981 100644 --- a/include/pico_jobs.h +++ b/include/pico_jobs.h @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only diff --git a/include/pico_md5.h b/include/pico_md5.h index bc8e841d..855b107e 100644 --- a/include/pico_md5.h +++ b/include/pico_md5.h @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_protocol.h b/include/pico_protocol.h index 07bb15a9..54015076 100644 --- a/include/pico_protocol.h +++ b/include/pico_protocol.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_queue.h b/include/pico_queue.h index 05b5cd74..71a5a32d 100644 --- a/include/pico_queue.h +++ b/include/pico_queue.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -104,7 +104,7 @@ static void debug_q(struct pico_queue *q) { struct pico_frame *p = q->head; dbg("%d: ", q->frames); - while(p) { + while (p) { dbg("(%p)-->", p); p = p->next; } @@ -204,7 +204,7 @@ static inline void pico_queue_deinit(struct pico_queue *q) static inline void pico_queue_empty(struct pico_queue *q) { struct pico_frame *p = pico_dequeue(q); - while(p) { + while (p) { pico_frame_discard(p); p = pico_dequeue(q); } diff --git a/include/pico_socket_multicast.h b/include/pico_socket_multicast.h index a2216f09..b383192c 100644 --- a/include/pico_socket_multicast.h +++ b/include/pico_socket_multicast.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/include/pico_stack.h b/include/pico_stack.h index aa7a2087..ab3171c4 100644 --- a/include/pico_stack.h +++ b/include/pico_stack.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -90,7 +90,7 @@ struct arp_service_ipconflict { ATTACH_QUEUES_LISTENERS(St, pname, P); \ } while(0) -#define EMPTY_TREE(name,comp) \ +#define EMPTY_TREE(name, comp) \ do { name.root = &LEAF; name.compare = comp;} while(0) struct pico_timer @@ -148,8 +148,8 @@ struct pico_stack { #ifdef PICO_SUPPORT_IPV4 DECLARE_QUEUES(ipv4); - struct pico_tree Tree_dev_link; - struct pico_tree Routes; + struct pico_tree Tree_dev_link; + struct pico_tree Routes; uint16_t ipv4_progressive_id; struct pico_ipv4_route *default_bcast_route; # ifdef PICO_SUPPORT_RAWSOCKETS @@ -217,7 +217,7 @@ struct pico_stack { #if defined(PICO_SUPPORT_IGMP) && defined(PICO_SUPPORT_MCAST) DECLARE_QUEUES(igmp); struct pico_tree IGMPParameters, IGMPTimers, IGMPAllow, IGMPBlock; - struct pico_tree MCASTSockets, MCASTFilter, MCASTFilter_ipv6; + struct pico_tree MCASTSockets, MCASTFilter, MCASTFilter_ipv6; #endif #ifdef PICO_SUPPORT_UDP @@ -271,10 +271,10 @@ struct pico_stack { struct pico_tree DNSTable; #endif #ifdef PICO_SUPPORT_MDNS -# if (PICO_MDNS_ALLOW_CACHING==1) +# if (PICO_MDNS_ALLOW_CACHING == 1) /* S->MDNSCache records from mDNS peers on the network */ struct pico_tree MDNSCache; -# endif +# endif /* My records for which I want to have the authority */ struct pico_tree MDNSOwnRecords; /* Cookie-tree */ diff --git a/include/pico_tree.h b/include/pico_tree.h index 1f75434f..b9dadb06 100644 --- a/include/pico_tree.h +++ b/include/pico_tree.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_6lowpan.c b/modules/pico_6lowpan.c index d35c1aee..d53234b6 100644 --- a/modules/pico_6lowpan.c +++ b/modules/pico_6lowpan.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -249,10 +249,10 @@ frag_store(struct pico_frame *f, uint16_t dgram_size, uint16_t tag, fr->timestamp = PICO_TIME_MS(); if (&f->dev->stack->LPFragTree == tree) { fr->hash = pico_hash((void *)fr, sizeof(struct frag_ctx)); - f->hash = fr->hash; // Also set hash in frame so we can identify it - lp_dbg("6LP: START: "ORG"fragmentation"RST" with hash '%X' of %u bytes.\n", fr->hash, f->len); + f->hash = fr->hash; /* Also set hash in frame so we can identify it */ + lp_dbg("6LP: START: " ORG "fragmentation" RST " with hash '%X' of %u bytes.\n", fr->hash, f->len); } else { - lp_dbg("6LP: START: "GRN"reassembly"RST" with tag '%d' of %u bytes.\n", tag, dgram_size); + lp_dbg("6LP: START: " GRN "reassembly" RST " with tag '%d' of %u bytes.\n", tag, dgram_size); } /* Insert the cookie in the appropriate tree (S->LPFragTree/S->LPReassemblyTree) */ if (pico_tree_insert(tree, fr)) { @@ -260,9 +260,9 @@ frag_store(struct pico_frame *f, uint16_t dgram_size, uint16_t tag, return -1; } } else { - return (-1); + return -1; } - return (1); // Success for 'proto_loop_out' + return 1; /* Success for 'proto_loop_out' */ } /******************************************************************************* @@ -278,8 +278,8 @@ compressor_vtf(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * { uint8_t ecn = 0, dscp = 0; uint32_t fl = 0; - *ori &= 0x0F; // Clear version field - *iphc &= (uint8_t)0x07; // Clear IPHC field + *ori &= 0x0F; /* Clear version field */ + *iphc &= (uint8_t)0x07; /* Clear IPHC field */ *iphc |= (uint8_t)IPHC_DISPATCH; IGNORE_PARAMETER(llsrc); IGNORE_PARAMETER(lldst); @@ -293,13 +293,13 @@ compressor_vtf(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * fl += long_be((uint32_t)(ori[3] & 0xFF)); if (fl) { - if (!dscp) { // Flow label carried in-line + if (!dscp) { /* Flow label carried in-line */ *iphc |= TF_ELIDED_DSCP; comp[0] = (uint8_t)(ecn | (ori[1] & 0x0F)); comp[1] = ori[2]; comp[2] = ori[3]; return 3; - } else { // Traffic class and flow label carried in-line + } else { /* Traffic class and flow label carried in-line */ *iphc |= TF_INLINE; *comp = ecn | dscp; comp[1] = ori[1] & 0x0F; @@ -307,11 +307,11 @@ compressor_vtf(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * comp[3] = ori[3]; return 4; } - } else if (ecn || dscp) { // Traffic class carried in-line + } else if (ecn || dscp) { /* Traffic class carried in-line */ *iphc |= TF_ELIDED_FL; *comp = ecn | dscp; return 1; - } else { // Traffic class and flow label elided + } else { /* Traffic class and flow label elided */ *iphc |= TF_ELIDED; return 0; } @@ -344,7 +344,7 @@ decompressor_vtf(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr *ori = (uint8_t)(*comp << 4) & 0xF0; return 1; } else { - *ori = 0x60; // Set version field to IPv6 + *ori = 0x60; /* Set version field to IPv6 */ return 0; } } @@ -354,12 +354,12 @@ static int32_t compressible_nh(uint8_t nh) { switch (nh) { - case PICO_IPV6_EXTHDR_HOPBYHOP: - case PICO_IPV6_EXTHDR_ROUTING: - case PICO_IPV6_EXTHDR_FRAG: - case PICO_IPV6_EXTHDR_DESTOPT: - case PICO_PROTO_UDP: return 1; - default: return 0; + case PICO_IPV6_EXTHDR_HOPBYHOP: + case PICO_IPV6_EXTHDR_ROUTING: + case PICO_IPV6_EXTHDR_FRAG: + case PICO_IPV6_EXTHDR_DESTOPT: + case PICO_PROTO_UDP: return 1; + default: return 0; } } @@ -368,9 +368,9 @@ compressible_nh(uint8_t nh) */ static int8_t compressor_nh(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * - llsrc, union pico_ll_addr *lldst, struct pico_device *dev) + llsrc, union pico_ll_addr *lldst, struct pico_device *dev) { - *iphc &= (uint8_t)~NH_COMPRESSED; + *iphc &= (uint8_t) ~NH_COMPRESSED; IGNORE_PARAMETER(comp); IGNORE_PARAMETER(llsrc); IGNORE_PARAMETER(lldst); @@ -389,14 +389,14 @@ compressor_nh(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * * and fill in the NH-header field in IPv6 header */ static int8_t decompressor_nh(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr - *llsrc, union pico_ll_addr *lldst, struct pico_device *dev) + *llsrc, union pico_ll_addr *lldst, struct pico_device *dev) { IGNORE_PARAMETER(llsrc); IGNORE_PARAMETER(lldst); IGNORE_PARAMETER(dev); IGNORE_PARAMETER(comp); if (*iphc & NH_COMPRESSED) { - *ori = 0; // Indicate that next header needs to be decompressed + *ori = 0; /* Indicate that next header needs to be decompressed */ return 0; } else { *ori = *comp; @@ -413,38 +413,38 @@ compressor_hl(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr * IGNORE_PARAMETER(llsrc); IGNORE_PARAMETER(lldst); IGNORE_PARAMETER(dev); - *iphc &= (uint8_t)~HL_COMPRESSED_255; + *iphc &= (uint8_t) ~HL_COMPRESSED_255; switch (*ori) { - case 1: *iphc |= (uint8_t)HL_COMPRESSED_1; - return 0; - case 64: *iphc |= (uint8_t)HL_COMPRESSED_64; - return 0; - case 255: *iphc |= (uint8_t)HL_COMPRESSED_255; - return 0; - default: *comp = *ori; - return 1; + case 1: *iphc |= (uint8_t)HL_COMPRESSED_1; + return 0; + case 64: *iphc |= (uint8_t)HL_COMPRESSED_64; + return 0; + case 255: *iphc |= (uint8_t)HL_COMPRESSED_255; + return 0; + default: *comp = *ori; + return 1; } } /* Decompresses the HL-field to common hop limit values like 1, 64 and 255 */ static int8_t decompressor_hl(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr - *llsrc, union pico_ll_addr *lldst, struct pico_device *dev) + *llsrc, union pico_ll_addr *lldst, struct pico_device *dev) { uint8_t hl = *iphc & HL_COMPRESSED_255; IGNORE_PARAMETER(llsrc); IGNORE_PARAMETER(lldst); IGNORE_PARAMETER(dev); - switch(hl) { - case HL_COMPRESSED_1: *ori = (uint8_t)1; - return 0; - case HL_COMPRESSED_64: *ori = (uint8_t)64; - return 0; - case HL_COMPRESSED_255: *ori = (uint8_t)255; - return 0; - default: *ori = *comp; - return 1; + switch (hl) { + case HL_COMPRESSED_1: *ori = (uint8_t)1; + return 0; + case HL_COMPRESSED_64: *ori = (uint8_t)64; + return 0; + case HL_COMPRESSED_255: *ori = (uint8_t)255; + return 0; + default: *ori = *comp; + return 1; } } @@ -454,22 +454,22 @@ addr_comp_prefix(struct pico_stack *S, uint8_t *iphc, struct pico_ip6 *addr, int { struct iphc_ctx *ctx = NULL; uint8_t state = src ? SRC_STATEFUL : DST_STATEFUL; - iphc[1] &= (uint8_t)~state; // Clear out compression state for src/dst + iphc[1] &= (uint8_t) ~state; /* Clear out compression state for src/dst */ if (pico_ipv6_is_multicast(addr->addr)) { /* TODO: Support stateful multicast compression with Unicast-Prefix-Based * IPv6 Multicast Addresses as defined in RFC3956 */ - return COMP_MULTICAST; // AC = 0 + return COMP_MULTICAST; /* AC = 0 */ } else if (pico_ipv6_is_linklocal(addr->addr)) { - return COMP_LINKLOCAL; // AC = 0 + return COMP_LINKLOCAL; /* AC = 0 */ } else if ((ctx = ctx_lookup(S, *addr))) { if (ctx->flags & PICO_IPHC_CTX_COMPRESS) { - iphc[1] |= state; // AC = 1 - iphc[1] |= CTX_EXTENSION; // SRC or DST is stateful, CID = 1 + iphc[1] |= state; /* AC = 1 */ + iphc[1] |= CTX_EXTENSION; /* SRC or DST is stateful, CID = 1 */ return (int8_t)ctx->id; } } - return COMP_STATELESS; // AC = 0 + return COMP_STATELESS; /* AC = 0 */ } /* Checks whether or not an IPv6 address is derived from a link layer address */ @@ -490,19 +490,19 @@ static int8_t addr_comp_mode(uint8_t *iphc, struct pico_ip6 *addr, union pico_ll_addr lladdr, struct pico_device *dev, int8_t shift) { int8_t mac = addr_ll_derived(addr, &lladdr, dev); - iphc[1] &= (uint8_t)((uint8_t)~DST_COMPRESSED << shift); // Clear src/dst mode + iphc[1] &= (uint8_t)((uint8_t) ~DST_COMPRESSED << shift); /* Clear src/dst mode */ - if (mac > 0) { // Address is mac derived + if (mac > 0) { /* Address is mac derived */ iphc[1] |= (uint8_t)(DST_COMPRESSED << shift); return 0; - } else if (!mac && IID_16(&addr->addr[8])) { // Address is 16-bit deriveable + } else if (!mac && IID_16(&addr->addr[8])) { /* Address is 16-bit deriveable */ iphc[1] |= (uint8_t)(DST_COMPRESSED_16 << shift); return 2; - } else if (!mac) { // Copy the entire IID + } else if (!mac) { /* Copy the entire IID */ iphc[1] |= (uint8_t)(DST_COMPRESSED_64 << shift); return 8; } else { - return -1; // Something went wrong, indicate failure + return -1; /* Something went wrong, indicate failure */ } } @@ -510,25 +510,25 @@ addr_comp_mode(uint8_t *iphc, struct pico_ip6 *addr, union pico_ll_addr lladdr, static int8_t addr_comp_mcast(uint8_t *iphc, uint8_t *comp, struct pico_ip6 *mcast) { - iphc[1] &= (uint8_t)~DST_MCAST_8; // Clear out addressing mode - iphc[1] |= (uint8_t)DST_MULTICAST; // Set multicast flag + iphc[1] &= (uint8_t) ~DST_MCAST_8; /* Clear out addressing mode */ + iphc[1] |= (uint8_t)DST_MULTICAST; /* Set multicast flag */ if (IPV6_MCAST_48(mcast->addr)) { - comp[0] = mcast->addr[1]; // Copy flags and scope - buf_move(&comp[1], &mcast->addr[11], 5); // Copy group identifier + comp[0] = mcast->addr[1]; /* Copy flags and scope */ + buf_move(&comp[1], &mcast->addr[11], 5); /* Copy group identifier */ iphc[1] |= DST_MCAST_48; return 6; } else if (IPV6_MCAST_32(mcast->addr)) { - comp[0] = mcast->addr[1]; // Copy flags and scope - buf_move(&comp[1], &mcast->addr[13], 3); // Copy group identifier + comp[0] = mcast->addr[1]; /* Copy flags and scope */ + buf_move(&comp[1], &mcast->addr[13], 3); /* Copy group identifier */ iphc[1] |= DST_MCAST_32; return 4; } else if (IPV6_MCAST_8(mcast->addr)) { - comp[0] = mcast->addr[15]; // Copy group identifier - iphc[1] |= DST_MCAST_8; // Flags and scope = 0x02 + comp[0] = mcast->addr[15]; /* Copy group identifier */ + iphc[1] |= DST_MCAST_8; /* Flags and scope = 0x02 */ return 1; } else { - buf_move(comp, mcast->addr, PICO_SIZE_IP6); // Copy entire address + buf_move(comp, mcast->addr, PICO_SIZE_IP6); /* Copy entire address */ return PICO_SIZE_IP6; } } @@ -540,20 +540,20 @@ addr_comp_iid(uint8_t *iphc, uint8_t *comp, int8_t state, struct pico_ip6 *addr, { int8_t len = PICO_SIZE_IP6; switch (state) { - case COMP_UNSPECIFIED: // Set stateful bit - iphc[1] |= SRC_STATEFUL; - break; - case COMP_STATELESS: // Clear compressed flags - iphc[1] &= (uint8_t)~SRC_COMPRESSED; - break; - case COMP_LINKLOCAL: - len = addr_comp_mode(iphc, addr, ll, dev, shift); - break; - case COMP_MULTICAST: // Multicast, compress statelessly - return addr_comp_mcast(iphc, comp, addr); - default: // Context available, extend header, and check for IID - iphc[2] = (uint8_t)((uint8_t)state << shift); - len = addr_comp_mode(iphc, addr, ll, dev, shift); + case COMP_UNSPECIFIED: /* Set stateful bit */ + iphc[1] |= SRC_STATEFUL; + break; + case COMP_STATELESS: /* Clear compressed flags */ + iphc[1] &= (uint8_t) ~SRC_COMPRESSED; + break; + case COMP_LINKLOCAL: + len = addr_comp_mode(iphc, addr, ll, dev, shift); + break; + case COMP_MULTICAST: /* Multicast, compress statelessly */ + return addr_comp_mcast(iphc, comp, addr); + default: /* Context available, extend header, and check for IID */ + iphc[2] = (uint8_t)((uint8_t)state << shift); + len = addr_comp_mode(iphc, addr, ll, dev, shift); } if (len >= 0) @@ -580,14 +580,14 @@ compressor_src(uint8_t *ori, uint8_t *comp, uint8_t *iphc, union pico_ll_addr *l static int8_t addr_decomp_prefix(struct pico_stack *S, uint8_t *prefix, uint8_t *iphc, int8_t shift) { - struct pico_ip6 ll = { .addr = {0xfe,0x80,0,0,0,0,0,0,0,0,0,0xff,0xfe,0,0,0}}; + struct pico_ip6 ll = { .addr = {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0, 0}}; uint8_t addr_state = (uint8_t)(DST_STATEFUL << shift); struct iphc_ctx *ctx = NULL; - if (iphc[1] & addr_state) { + if (iphc[1] & addr_state) { if ((ctx = ctx_lookup_id(S, (uint8_t)(iphc[2] >> shift)))) { buf_move(prefix, ctx->prefix.addr, PICO_SIZE_IP6); - buf_move(&prefix[8], &ll.addr[8], 8); // For 16-bit derived addresses + buf_move(&prefix[8], &ll.addr[8], 8); /* For 16-bit derived addresses */ } else { /* No context available while stateful compression is used... */ return -1; @@ -605,19 +605,19 @@ addr_decomp_iid(struct pico_ip6 *addr, uint8_t *comp, uint8_t am, union pico_ll_ { if (addr) { switch (am) { - case DST_COMPRESSED_64: buf_move(&addr->addr[8], comp, 8); - return 8; - case DST_COMPRESSED_16: buf_move(&addr->addr[14], comp, 2); - return 2; - case DST_COMPRESSED: - if (dev && pico_6lowpan_lls[dev->mode].addr_iid) { - pico_6lowpan_lls[dev->mode].addr_iid(&addr->addr[8], &lladdr); - return 0; - } else { - return -1; - } - default: buf_move(addr->addr, comp, PICO_SIZE_IP6); - return 16; + case DST_COMPRESSED_64: buf_move(&addr->addr[8], comp, 8); + return 8; + case DST_COMPRESSED_16: buf_move(&addr->addr[14], comp, 2); + return 2; + case DST_COMPRESSED: + if (dev && pico_6lowpan_lls[dev->mode].addr_iid) { + pico_6lowpan_lls[dev->mode].addr_iid(&addr->addr[8], &lladdr); + return 0; + } else { + return -1; + } + default: buf_move(addr->addr, comp, PICO_SIZE_IP6); + return 16; } } else { return -1; @@ -661,19 +661,19 @@ addr_decomp_mcast(uint8_t *comp, struct pico_ip6 *dst, uint8_t am) dst->addr[0] = 0xff; dst->addr[1] = *comp; switch (am) { - case DST_MCAST_48: - buf_move(dst->addr + 11, comp + 1, 5); - return 6; - case DST_MCAST_32: - buf_move(dst->addr + 13, comp + 1, 3); - return 4; - case DST_MCAST_8: - dst->addr[1] = 0x02; - dst->addr[15] = *comp; - return 1; - default: - buf_move(dst->addr, comp, PICO_SIZE_IP6); - return PICO_SIZE_IP6; + case DST_MCAST_48: + buf_move(dst->addr + 11, comp + 1, 5); + return 6; + case DST_MCAST_32: + buf_move(dst->addr + 13, comp + 1, 3); + return 4; + case DST_MCAST_8: + dst->addr[1] = 0x02; + dst->addr[15] = *comp; + return 1; + default: + buf_move(dst->addr, comp, PICO_SIZE_IP6); + return PICO_SIZE_IP6; } } else { return -1; @@ -726,16 +726,15 @@ compressor_iphc(struct pico_frame *f, int32_t *compressed_len, uint8_t *nh) for (i = 0; i < NUM_IPV6_FIELDS; i++) { if (ip6_fields[i].compress) { ret = ip6_fields[i].compress(ori, comp, iphc, &f->src, &f->dst, f->dev); - if (ret < 0) { // Something went wrong ... + if (ret < 0) { /* Something went wrong ... */ PICO_FREE(inline_buf); return NULL; } - *compressed_len += ret; // Increase compressed length - comp += ret; // Move forward compressed length + *compressed_len += ret; /* Increase compressed length */ + comp += ret; /* Move forward compressed length */ } - ori += ip6_fields[i].ori_size; // Move to next field + ori += ip6_fields[i].ori_size; /* Move to next field */ } - /* Rearrange IPHC-header if CTX-extension is included */ if (iphc[1] & CTX_EXTENSION) { *compressed_len += 3; @@ -763,14 +762,14 @@ decompressor_iphc(struct pico_frame *f, int32_t *compressed_len) for (i = 0; i < NUM_IPV6_FIELDS; i++) { if (ip6_fields[i].decompress) { ret = ip6_fields[i].decompress(ori, comp, iphc, &f->src, &f->dst, f->dev); - if (ret < 0) { // Something went wrong ... + if (ret < 0) { /* Something went wrong ... */ PICO_FREE(ipv6_hdr); return NULL; } - *compressed_len += ret; // Increase compressed size - comp += ret; // Move to next compressed chunk + *compressed_len += ret; /* Increase compressed size */ + comp += ret; /* Move to next compressed chunk */ } - ori += ip6_fields[i].ori_size; // Move to next IPv6 field + ori += ip6_fields[i].ori_size; /* Move to next IPv6 field */ } } return ipv6_hdr; @@ -810,7 +809,7 @@ compressor_nhc_udp(struct pico_frame *f, int32_t *compressed_len) buf_move(inline_buf + 1, (uint8_t *)hdr, 2); *compressed_len = 4; } else { - inline_buf[0] &= (uint8_t)~UDP_COMPRESSED_BOTH; + inline_buf[0] &= (uint8_t) ~UDP_COMPRESSED_BOTH; buf_move(inline_buf + 1, (uint8_t *)hdr, 4); *compressed_len = 5; } @@ -855,8 +854,8 @@ decompressor_nhc_udp(struct pico_frame *f, int32_t processed_len, int32_t *compr buf_move((uint8_t *)&hdr->trans, &buf[1], 4); *compressed_len = 5; } - if (!(buf[0] & UDP_COMPRESSED_CHCK)) { // Leave empty room for checksum - buf_move((uint8_t *)&hdr->crc, &buf[*compressed_len],2); + if (!(buf[0] & UDP_COMPRESSED_CHCK)) { /* Leave empty room for checksum */ + buf_move((uint8_t *)&hdr->crc, &buf[*compressed_len], 2); *compressed_len += 2; } /* Restore inherently compressed length */ @@ -874,26 +873,26 @@ ext_hdr_len(struct pico_ipv6_exthdr *ext, uint8_t hdr, uint8_t *dispatch) int32_t len = 0; /* Get length of extension header */ switch (hdr) { - case PICO_IPV6_EXTHDR_HOPBYHOP: - *dispatch |= (uint8_t)EXT_HOPBYHOP; - len = IPV6_OPTLEN(ext->ext.destopt.len); // Length in bytes - ext->ext.destopt.len = (uint8_t)(len - 2); // Octets after len-field - return (int32_t)len; - case PICO_IPV6_EXTHDR_ROUTING: - *dispatch |= (uint8_t)EXT_ROUTING; - len = IPV6_OPTLEN(ext->ext.destopt.len); // Length in bytes - ext->ext.destopt.len = (uint8_t)(len - 2); // Octets after len-field - return (int32_t)len; - case PICO_IPV6_EXTHDR_DESTOPT: - *dispatch |= (uint8_t)EXT_DSTOPT; - len = IPV6_OPTLEN(ext->ext.destopt.len); // Length in bytes - ext->ext.destopt.len = (uint8_t)(len - 2); // Octets after len-field - return (int32_t)len; - case PICO_IPV6_EXTHDR_FRAG: - *dispatch |= (uint8_t)EXT_FRAG; - return (int32_t)8; - default: // Somethin went wrong, bail out... - return -1; + case PICO_IPV6_EXTHDR_HOPBYHOP: + *dispatch |= (uint8_t)EXT_HOPBYHOP; + len = IPV6_OPTLEN(ext->ext.destopt.len); /* Length in bytes */ + ext->ext.destopt.len = (uint8_t)(len - 2); /* Octets after len-field */ + return (int32_t)len; + case PICO_IPV6_EXTHDR_ROUTING: + *dispatch |= (uint8_t)EXT_ROUTING; + len = IPV6_OPTLEN(ext->ext.destopt.len); /* Length in bytes */ + ext->ext.destopt.len = (uint8_t)(len - 2); /* Octets after len-field */ + return (int32_t)len; + case PICO_IPV6_EXTHDR_DESTOPT: + *dispatch |= (uint8_t)EXT_DSTOPT; + len = IPV6_OPTLEN(ext->ext.destopt.len); /* Length in bytes */ + ext->ext.destopt.len = (uint8_t)(len - 2); /* Octets after len-field */ + return (int32_t)len; + case PICO_IPV6_EXTHDR_FRAG: + *dispatch |= (uint8_t)EXT_FRAG; + return (int32_t)8; + default: /* Somethin went wrong, bail out... */ + return -1; } } @@ -911,10 +910,10 @@ compressor_nhc_ext(struct pico_frame *f, int32_t *compressed_len, uint8_t *nh) /* Determine next header */ *nh = ext->nxthdr; if (!compressible_nh(*nh)) { - len++; // Dispatch header has to be prepended - lead++; // Copy right after dispatch + len++; /* Dispatch header has to be prepended */ + lead++; /* Copy right after dispatch */ } else { - dispatch |= (uint8_t)0x01; // Set NH flag + dispatch |= (uint8_t)0x01; /* Set NH flag */ } /* Get length of extension header */ @@ -930,9 +929,9 @@ compressor_nhc_ext(struct pico_frame *f, int32_t *compressed_len, uint8_t *nh) } else { /* Copy extension header */ buf_move(buf + lead, (uint8_t *)ext, (size_t)(len - lead)); - buf[0] = dispatch; // Set the dispatch header + buf[0] = dispatch; /* Set the dispatch header */ *compressed_len = len; - f->net_hdr += *compressed_len; // Move to next header + f->net_hdr += *compressed_len; /* Move to next header */ return buf; } } @@ -947,16 +946,16 @@ ext_nh_retrieve(uint8_t *buf, int32_t len) if ((buf[0] & 0xF0) == EXT_DISPATCH) { eid = buf[0] & 0x0E; switch (eid) { - case EXT_HOPBYHOP: - return (uint8_t)PICO_IPV6_EXTHDR_HOPBYHOP; - case EXT_ROUTING: - return (uint8_t)PICO_IPV6_EXTHDR_ROUTING; - case EXT_FRAG: - return (uint8_t)PICO_IPV6_EXTHDR_FRAG; - case EXT_DSTOPT: - return (uint8_t)PICO_IPV6_EXTHDR_DESTOPT; - default: - return 0; + case EXT_HOPBYHOP: + return (uint8_t)PICO_IPV6_EXTHDR_HOPBYHOP; + case EXT_ROUTING: + return (uint8_t)PICO_IPV6_EXTHDR_ROUTING; + case EXT_FRAG: + return (uint8_t)PICO_IPV6_EXTHDR_FRAG; + case EXT_DSTOPT: + return (uint8_t)PICO_IPV6_EXTHDR_DESTOPT; + default: + return 0; } } else if ((buf[0] & 0xF8) == UDP_DISPATCH) { return PICO_PROTO_UDP; @@ -971,11 +970,11 @@ static int32_t ext_align(uint8_t *buf, int32_t alloc, int32_t len) { int32_t padlen = alloc - len; - buf += len; // Move to padding location + buf += len; /* Move to padding location */ if (padlen == 1) { - buf[0] = 0; // Pad1 + buf[0] = 0; /* Pad1 */ } else if (padlen > 1) { - buf[0] = 1; // PadN + buf[0] = 1; /* PadN */ buf[1] = (uint8_t)(padlen - 2); } else { return -1; @@ -990,24 +989,24 @@ ext_compressed_length(uint8_t *buf, uint8_t eid, int32_t *compressed_len, int32_ { int32_t len = 0; switch (eid) { - case EXT_HOPBYHOP: // Intentional fall-through - case EXT_ROUTING: // Intentional fall-through - case EXT_DSTOPT: // Intentional fall-through - if (!(buf[0] & NH_COMPRESSED)) { // [ DIS | NXT | LEN | ... (len) - len = 2 + buf[2]; - *compressed_len = len + 1; - } else { // [ DIS | LEN | ... (len) - len = 2 + buf[1]; - *compressed_len = len; - *head = 1; - } - return len; - case EXT_FRAG: // [ DIS | FRAG ... - len = 8; + case EXT_HOPBYHOP: /* Intentional fall-through */ + case EXT_ROUTING: /* Intentional fall-through */ + case EXT_DSTOPT: /* Intentional fall-through */ + if (!(buf[0] & NH_COMPRESSED)) { /* [ DIS | NXT | LEN | ... (len) */ + len = 2 + buf[2]; + *compressed_len = len + 1; + } else { /* [ DIS | LEN | ... (len) */ + len = 2 + buf[1]; *compressed_len = len; - return len; - default: // Something went wrong, bail out... - return -1; + *head = 1; + } + return len; + case EXT_FRAG: /* [ DIS | FRAG ... */ + len = 8; + *compressed_len = len; + return len; + default: /* Something went wrong, bail out... */ + return -1; } } @@ -1070,7 +1069,7 @@ pico_iphc_reassemble(struct pico_frame *f, uint8_t **chunks, int32_t *chunks_len /* Calculate buffer size including IPv6 payload */ payload_len = (int32_t)f->len - handled_len; - processed_len += payload_len; // Length of frame after processing + processed_len += payload_len; /* Length of frame after processing */ /* Reallocate frame size if there isn't enough room available */ if (f->len < (uint16_t)processed_len) { @@ -1080,9 +1079,9 @@ pico_iphc_reassemble(struct pico_frame *f, uint8_t **chunks, int32_t *chunks_len return pico_iphc_bail_out(chunks, n); } - chunks[n] = f->net_hdr + handled_len; // Start of payload_available - chunks_len[n] = payload_len; // Size of payload - n++; // Payload is another chunk to copy + chunks[n] = f->net_hdr + handled_len; /* Start of payload_available */ + chunks_len[n] = payload_len; /* Size of payload */ + n++; /* Payload is another chunk to copy */ /* Provide a new frame */ if (!(new = pico_frame_deepcopy(f))) @@ -1095,14 +1094,14 @@ pico_iphc_reassemble(struct pico_frame *f, uint8_t **chunks, int32_t *chunks_len dst -= chunks_len[i]; buf_move(dst, chunks[i], (size_t)chunks_len[i]); } - new->net_hdr = dst; // Last destination is net_hdr - new->start = new->net_hdr; // Start of useful data is at net_hdr + new->net_hdr = dst; /* Last destination is net_hdr */ + new->start = new->net_hdr; /* Start of useful data is at net_hdr */ new->len = (uint32_t)processed_len; new->transport_len = 0; new->payload_len = 0; new->app_len = 0; new->transport_hdr = new->net_hdr + new->net_len; - pico_iphc_bail_out(chunks, n - 1); // Success, discard compressed chunk + pico_iphc_bail_out(chunks, n - 1); /* Success, discard compressed chunk */ if (new->start < new->buffer) { pico_frame_discard(new); return NULL; @@ -1115,36 +1114,36 @@ static struct pico_frame * pico_iphc_compress(struct pico_frame *f) { int32_t i = 0, compressed_len = 0, loop = 1, uncompressed = f->net_len; - uint8_t *old_nethdr = f->net_hdr; // Save net_hdr temporary ... + uint8_t *old_nethdr = f->net_hdr; /* Save net_hdr temporary ... */ uint8_t nh = PICO_PROTO_IPV6; uint8_t *chunks[8] = { NULL }; int32_t chunks_len[8] = { 0 }; do { switch (nh) { - /* IPV6 HEADER */ - case PICO_PROTO_IPV6: - chunks[i] = compressor_iphc(f, &chunks_len[i], &nh); - f->net_hdr += 40; // Move after IPv6 header - f->net_len = (uint16_t)chunks_len[i]; - break; - /* IPV6 EXTENSION HEADERS */ - case PICO_IPV6_EXTHDR_HOPBYHOP: - case PICO_IPV6_EXTHDR_ROUTING: - case PICO_IPV6_EXTHDR_FRAG: - case PICO_IPV6_EXTHDR_DESTOPT: - chunks[i] = compressor_nhc_ext(f, &chunks_len[i], &nh); - f->net_len = (uint16_t)(f->net_len + chunks_len[i]); - /* f->net_hdr is updated in compresor_nhc_ext with original size */ - break; - /* UDP HEADER */ - case PICO_PROTO_UDP: - chunks[i] = compressor_nhc_udp(f, &chunks_len[i]); - uncompressed += PICO_UDPHDR_SIZE; - f->transport_len = (uint16_t)chunks_len[i]; - /* fall-through */ - default: /* Intentional fall-through */ - loop = 0; + /* IPV6 HEADER */ + case PICO_PROTO_IPV6: + chunks[i] = compressor_iphc(f, &chunks_len[i], &nh); + f->net_hdr += 40; /* Move after IPv6 header */ + f->net_len = (uint16_t)chunks_len[i]; + break; + /* IPV6 EXTENSION HEADERS */ + case PICO_IPV6_EXTHDR_HOPBYHOP: + case PICO_IPV6_EXTHDR_ROUTING: + case PICO_IPV6_EXTHDR_FRAG: + case PICO_IPV6_EXTHDR_DESTOPT: + chunks[i] = compressor_nhc_ext(f, &chunks_len[i], &nh); + f->net_len = (uint16_t)(f->net_len + chunks_len[i]); + /* f->net_hdr is updated in compresor_nhc_ext with original size */ + break; + /* UDP HEADER */ + case PICO_PROTO_UDP: + chunks[i] = compressor_nhc_udp(f, &chunks_len[i]); + uncompressed += PICO_UDPHDR_SIZE; + f->transport_len = (uint16_t)chunks_len[i]; + /* fall-through */ + default: /* Intentional fall-through */ + loop = 0; } /* Check if an error occurred */ if (!chunks[i]) @@ -1153,7 +1152,7 @@ pico_iphc_compress(struct pico_frame *f) compressed_len += chunks_len[i++]; } while (compressible_nh(nh) && loop && i < 8); - f->net_hdr = old_nethdr; // ... Restore old net_hdr + f->net_hdr = old_nethdr; /* ... Restore old net_hdr */ return pico_iphc_reassemble(f, chunks, chunks_len, i, compressed_len, uncompressed); } @@ -1178,7 +1177,7 @@ static struct pico_frame * pico_iphc_decompress(struct pico_frame *f) { int32_t i = 0, compressed = 0, loop = 1, uncompressed = 0, ret = 0; - uint8_t *old_nethdr = f->net_hdr; // Save net_hdr temporary ... + uint8_t *old_nethdr = f->net_hdr; /* Save net_hdr temporary ... */ uint8_t dispatch = PICO_PROTO_IPV6; uint8_t *chunks[8] = { NULL }; struct pico_frame *n = NULL; @@ -1187,29 +1186,29 @@ pico_iphc_decompress(struct pico_frame *f) do { switch (dispatch) { - /* IPV6 HEADER */ - case PICO_PROTO_IPV6: - chunks[i] = decompressor_iphc(f, &ret); - chunks_len[i] = PICO_SIZE_IP6HDR; - f->net_len = PICO_SIZE_IP6HDR; - nh = ext_nh_retrieve(f->net_hdr, ret); - break; - /* IPV6 EXTENSION HEADERS */ - case PICO_IPV6_EXTHDR_HOPBYHOP: - case PICO_IPV6_EXTHDR_ROUTING: - case PICO_IPV6_EXTHDR_FRAG: - case PICO_IPV6_EXTHDR_DESTOPT: - chunks[i] = decompressor_nhc_ext(f, &ret, &chunks_len[i]); - f->net_len = (uint16_t)(f->net_len + chunks_len[i]); - break; - /* UDP HEADER */ - case PICO_PROTO_UDP: - f->transport_hdr = f->net_hdr; // Switch to transport header - chunks[i] = decompressor_nhc_udp(f, compressed, &ret); - chunks_len[i] = PICO_UDPHDR_SIZE; - /* fall-through */ - default: /* Intentional fall-through */ - loop = 0; + /* IPV6 HEADER */ + case PICO_PROTO_IPV6: + chunks[i] = decompressor_iphc(f, &ret); + chunks_len[i] = PICO_SIZE_IP6HDR; + f->net_len = PICO_SIZE_IP6HDR; + nh = ext_nh_retrieve(f->net_hdr, ret); + break; + /* IPV6 EXTENSION HEADERS */ + case PICO_IPV6_EXTHDR_HOPBYHOP: + case PICO_IPV6_EXTHDR_ROUTING: + case PICO_IPV6_EXTHDR_FRAG: + case PICO_IPV6_EXTHDR_DESTOPT: + chunks[i] = decompressor_nhc_ext(f, &ret, &chunks_len[i]); + f->net_len = (uint16_t)(f->net_len + chunks_len[i]); + break; + /* UDP HEADER */ + case PICO_PROTO_UDP: + f->transport_hdr = f->net_hdr; /* Switch to transport header */ + chunks[i] = decompressor_nhc_udp(f, compressed, &ret); + chunks_len[i] = PICO_UDPHDR_SIZE; + /* fall-through */ + default: /* Intentional fall-through */ + loop = 0; } /* Check if an error occurred */ if (!chunks[i]) @@ -1223,7 +1222,7 @@ pico_iphc_decompress(struct pico_frame *f) f->net_hdr += ret; dispatch = ext_nh_retrieve(f->net_hdr, 0); } while (dispatch && loop && i < 8); - f->net_hdr = old_nethdr; // ... Restore old net_hdr + f->net_hdr = old_nethdr; /* ... Restore old net_hdr */ /* Reassemble gathererd decompressed buffers */ n = pico_iphc_reassemble(f, chunks, chunks_len, i, uncompressed, compressed); @@ -1236,7 +1235,7 @@ pico_iphc_decompress(struct pico_frame *f) static void pico_iphc_no_comp(struct pico_frame *f) { - f->net_hdr--; // Only need one byte + f->net_hdr--; /* Only need one byte */ f->start--; f->len++; f->net_len++; @@ -1263,15 +1262,15 @@ frag_update(struct pico_frame *f, struct frag_ctx *frag, uint8_t units, uint16_t frag->copied = (uint16_t)(frag->copied + copy); /* Datagram is completely transmitted */ if (frag->copied >= f->len) { - lp_dbg("6LP: FIN: "ORG"fragmentation"RST" with hash '%X', sent %u of %u bytes\n", frag->hash, frag->copied, f->len); + lp_dbg("6LP: FIN: " ORG "fragmentation" RST " with hash '%X', sent %u of %u bytes\n", frag->hash, frag->copied, f->len); pico_tree_delete(&f->dev->stack->LPFragTree, frag); PICO_FREE(frag); pico_frame_discard(f); } else { - lp_dbg("6LP: UPDATE: "ORG"fragmentation"RST" with hash '%X', sent %u of %u bytes\n", frag->hash, frag->copied, f->len); + lp_dbg("6LP: UPDATE: " ORG "fragmentation" RST " with hash '%X', sent %u of %u bytes\n", frag->hash, frag->copied, f->len); return pico_datalink_send(f); } - return (int32_t)1; // Success + return (int32_t)1; /* Success */ } static void @@ -1324,7 +1323,7 @@ frag_nth(struct pico_stack *S, struct pico_frame *f) /* Try to push fragment to link layer */ ret = pico_6lowpan_ll_push(n); - if (!ret) { // Update frag cookie + if (!ret) { /* Update frag cookie */ return frag_update(f, frag, units, copy); } } @@ -1347,7 +1346,7 @@ frag_1st(struct pico_frame *f, uint16_t dgram_size, uint8_t dgram_off, uint16_t n = pico_proto_6lowpan_ll.alloc(f->dev->stack, &pico_proto_6lowpan_ll, f->dev, alloc); if (n) { - frag_fill(n->net_hdr, FRAG1_DISPATCH, dgram_size, f->dev->stack->lowpan_dgram_tag, 0, 4, copy, 0,f->net_hdr); + frag_fill(n->net_hdr, FRAG1_DISPATCH, dgram_size, f->dev->stack->lowpan_dgram_tag, 0, 4, copy, 0, f->net_hdr); n->net_len = alloc; n->len = (uint32_t)n->net_len; n->src = f->src; @@ -1432,17 +1431,17 @@ pico_6lowpan_compress(struct pico_frame *f, int32_t avail) return frag_1st_comp(try, dgram_size, avail, udp); } else if (!avail) { pico_frame_discard(f); - return (int32_t)try->len; // Success, compression was enough + return (int32_t)try->len; /* Success, compression was enough */ } else if (0 > avail) { pico_frame_discard(try); pico_frame_discard(f); - return -1; // Error pushing compressed frame + return -1; /* Error pushing compressed frame */ } pico_frame_discard(try); } #endif - pico_iphc_no_comp(f); // Add uncompressed dispatch header again + pico_iphc_no_comp(f); /* Add uncompressed dispatch header again */ return frag_1st_no_comp(f, dgram_size, avail); } @@ -1452,14 +1451,14 @@ static int32_t pico_6lowpan_send(struct pico_frame *f) { int32_t avail = 0; - pico_iphc_no_comp(f); // Add uncompressed dispatch header ... + pico_iphc_no_comp(f); /* Add uncompressed dispatch header ... */ /* Try to push frame to link layer */ avail = pico_6lowpan_ll_push(f); if (avail > 0) { - pico_iphc_no_comp_dec(f); // ... remove IPv6 Dispatch Header + pico_iphc_no_comp_dec(f); /* ... remove IPv6 Dispatch Header */ return pico_6lowpan_compress(f, avail); - } else if (!avail) { // Success + } else if (!avail) { /* Success */ return (int32_t)f->len; } else { return -1; @@ -1550,11 +1549,11 @@ static int32_t defrag_update(struct frag_ctx *frag, uint16_t off, struct pico_frame *f) { struct pico_frame *r = frag->f; - buf_move(r->start + (int32_t)off, f->start, f->len); // Copy at start + buf_move(r->start + (int32_t)off, f->start, f->len); /* Copy at start */ frag->copied = (uint16_t)(frag->copied + (uint16_t)f->len); pico_frame_discard(f); - if (frag->copied >= frag->dgram_size) { // Datagram completely reassembled - lp_dbg("6LP: FIN: "GRN"reassembly"RST" with tag '%u', stats: len: %d net: %d trans: %d\n", frag->dgram_tag, r->len, r->net_len, r->transport_len); + if (frag->copied >= frag->dgram_size) { /* Datagram completely reassembled */ + lp_dbg("6LP: FIN: " GRN "reassembly" RST " with tag '%u', stats: len: %d net: %d trans: %d\n", frag->dgram_tag, r->len, r->net_len, r->transport_len); pico_tree_delete(&frag->f->dev->stack->LPReassemblyTree, frag); PICO_FREE(frag); #ifdef PICO_6LOWPAN_IPHC_ENABLED @@ -1562,7 +1561,7 @@ defrag_update(struct frag_ctx *frag, uint16_t off, struct pico_frame *f) #endif return pico_network_receive(r); } else { - lp_dbg("6LP: UPDATE: "GRN"reassembly"RST" with tag '%u', %u of %u bytes received\n", frag->dgram_tag, frag->copied, frag->dgram_size); + lp_dbg("6LP: UPDATE: " GRN "reassembly" RST " with tag '%u', %u of %u bytes received\n", frag->dgram_tag, frag->copied, frag->dgram_size); } return (int32_t)r->len; } @@ -1628,7 +1627,7 @@ int32_t pico_6lowpan_pull(struct pico_frame *f) { if (pico_enqueue(pico_proto_6lowpan.q_in, f) > 0) { - return (int32_t)f->len; // Success + return (int32_t)f->len; /* Success */ } pico_frame_discard(f); diff --git a/modules/pico_6lowpan.h b/modules/pico_6lowpan.h index c6310fad..cf3f3317 100644 --- a/modules/pico_6lowpan.h +++ b/modules/pico_6lowpan.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ extern struct pico_protocol pico_proto_6lowpan; ******************************************************************************/ /* Compares two fragmentation cookies according to RFC4944 5.3 */ -int32_t lp_frag_ctx_cmp(void *a, void *b); +int32_t lp_frag_ctx_cmp(void *a, void *b); int32_t lp_frag_cmp(void *a, void *b); int32_t pico_6lowpan_pull(struct pico_frame *f); diff --git a/modules/pico_6lowpan_ll.c b/modules/pico_6lowpan_ll.c index 4021cd30..2411b98b 100644 --- a/modules/pico_6lowpan_ll.c +++ b/modules/pico_6lowpan_ll.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -119,7 +119,7 @@ struct iphc_ctx * ctx_lookup_id(struct pico_stack *S, uint8_t id) pico_tree_foreach(i, &S->SixLowPanCTXTree) { key = i->keyValue; - if (key && id ==key->id) + if (key && id == key->id) return key; } return NULL; @@ -317,7 +317,6 @@ pico_6lowpan_ll_process_out(struct pico_stack *S, struct pico_protocol *self, st if ((f->net_hdr - datalink_len) < f->buffer) /* Before buffer bound check */ goto fin; } - /* Frame is ready for sending to the device driver */ f->start = f->datalink_hdr; f->len = (uint32_t)(f->len + datalink_len); @@ -344,19 +343,18 @@ pico_6lowpan_ll_process_in(struct pico_stack *S, struct pico_protocol *self, str for (i = NUM_LL_EXTENSIONS - 1; i >= 0; i--) { ret = exts[i].in(f); switch (ret) { - case FRAME_6LOWPAN_LL_RELEASE: - /* Success, frame is somewhere else now... */ - break; - case FRAME_6LOWPAN_LL_DISCARD: - /* Something went wrong, discard the frame */ - pico_frame_discard(f); - break; - default: - /* Success, update link layer header length */ - len = (uint32_t)(len + (uint32_t)ret); + case FRAME_6LOWPAN_LL_RELEASE: + /* Success, frame is somewhere else now... */ + break; + case FRAME_6LOWPAN_LL_DISCARD: + /* Something went wrong, discard the frame */ + pico_frame_discard(f); + break; + default: + /* Success, update link layer header length */ + len = (uint32_t)(len + (uint32_t)ret); } } - /* Determine size at network layer */ f->net_len = (uint16_t)(f->len - len); f->len = (uint32_t)(f->len - len); @@ -382,7 +380,7 @@ int32_t pico_6lowpan_stack_recv(struct pico_device *dev, uint8_t *buffer, uint32 } else { return pico_stack_recv(dev, buffer, len); } - return -1; // return ERROR + return -1; /* return ERROR */ } /* Proxy for pico_devloop_sendto_dev, 6LoWPAN-devices have a different interface with pico. This @@ -441,10 +439,10 @@ pico_6lowpan_ll_push(struct pico_frame *f) return pl_available; /* Make sure these addresses are retrievable from the frame on processing */ - if (pico_enqueue(pico_proto_6lowpan_ll.q_out,f) > 0) { - return 0; // Frame enqueued for later processing + if (pico_enqueue(pico_proto_6lowpan_ll.q_out, f) > 0) { + return 0; /* Frame enqueued for later processing */ } - return -1; // Return ERROR + return -1; /* Return ERROR */ } struct pico_protocol pico_proto_6lowpan_ll = { diff --git a/modules/pico_6lowpan_ll.h b/modules/pico_6lowpan_ll.h index 3a1d1114..0922e007 100644 --- a/modules/pico_6lowpan_ll.h +++ b/modules/pico_6lowpan_ll.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_802154.c b/modules/pico_802154.c index f7b46a3f..fd58110c 100644 --- a/modules/pico_802154.c +++ b/modules/pico_802154.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -175,13 +175,13 @@ frame_802154_format(uint8_t *buf, uint8_t seq, uint16_t intra_pan, uint16_t ack, sam = short_be((uint16_t)(src.mode << 14)); /* Fill in frame control field */ - hdr->fcf |= (uint16_t)(FCF_TYPE_DATA | sec ); + hdr->fcf |= (uint16_t)(FCF_TYPE_DATA | sec); hdr->fcf |= (uint16_t)(FCF_NO_PENDING | ack); hdr->fcf |= (uint16_t)(intra_pan | dam | FCF_VER_2003); hdr->fcf |= (uint16_t)(sam); - hdr->fcf = short_be(hdr->fcf); // Convert to IEEE endianness + hdr->fcf = short_be(hdr->fcf); /* Convert to IEEE endianness */ - hdr->seq = seq; // Sequence number + hdr->seq = seq; /* Sequence number */ /* Convert addresses to IEEE-endianness */ pan.addr = short_be(pan.addr); @@ -191,7 +191,7 @@ frame_802154_format(uint8_t *buf, uint8_t seq, uint16_t intra_pan, uint16_t ack, /* Fill in the addresses */ memcpy(&hdr->pan_id, &pan.addr, SIZE_6LOWPAN_SHORT); memcpy(addresses, dst.addr.data, SIZE_6LOWPAN(dst.mode)); - memcpy(addresses + SIZE_6LOWPAN(dst.mode), src.addr.data,SIZE_6LOWPAN(src.mode)); + memcpy(addresses + SIZE_6LOWPAN(dst.mode), src.addr.data, SIZE_6LOWPAN(src.mode)); } #endif /* PICO_6LOWPAN_NOMAC */ @@ -315,7 +315,7 @@ addr_802154_ll_dst(struct pico_frame *f) addr.mode = AM_6LOWPAN_SHORT; } /* If the address is link local derive the link layer address from the IID */ - else { // if (pico_ipv6_is_linklocal(dst.addr)) { + else { /* if (pico_ipv6_is_linklocal(dst.addr)) { */ if (IID_16(&dst.addr[8])) { addr.addr.data[0] = dst.addr[14]; addr.addr.data[1] = dst.addr[15]; @@ -336,7 +336,7 @@ addr_802154_ll_dst(struct pico_frame *f) pico_ipv6_nd_postpone(f); } } -*/ + */ return addr; } @@ -354,7 +354,7 @@ addr_802154_from_buf(union pico_ll_addr *addr, uint8_t *buf) { uint8_t len = (uint8_t)*buf++; - if (len > 8) // OOB check + if (len > 8) /* OOB check */ return -1; memcpy(addr->pan.addr.data, buf, len); @@ -404,7 +404,7 @@ addr_802154_cmp(union pico_ll_addr *a, union pico_ll_addr *b) static int32_t addr_802154_iid(uint8_t iid[8], union pico_ll_addr *addr) { - uint8_t buf[8] = {0,0,0,0xff,0xfe,0,0,0}; + uint8_t buf[8] = { 0, 0, 0, 0xff, 0xfe, 0, 0, 0 }; struct pico_802154 pan = addr->pan; if (AM_6LOWPAN_SHORT == pan.mode) { @@ -437,7 +437,7 @@ addr_802154_iid(uint8_t iid[8], union pico_ll_addr *addr) static struct pico_frame * pico_frame_alloc_with_headroom(uint16_t size, uint16_t headroom, uint16_t overhead) { - int network_offset = (((headroom + overhead) >> 2) + 1) << 2; // Sufficient headroom for alignment + int network_offset = (((headroom + overhead) >> 2) + 1) << 2; /* Sufficient headroom for alignment */ struct pico_frame *f = pico_frame_alloc((uint32_t)(size + network_offset)); if (!f) diff --git a/modules/pico_802154.h b/modules/pico_802154.h index a55891d2..507d1371 100644 --- a/modules/pico_802154.h +++ b/modules/pico_802154.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -36,7 +36,7 @@ ******************************************************************************/ #define MTU_802154_PHY (128u) -#define MTU_802154_MAC (125u) // 127 - Frame Check Sequence +#define MTU_802154_MAC (125u) /* 127 - Frame Check Sequence */ #define SIZE_802154_MHR_MIN (5u) #define SIZE_802154_MHR_MAX (23u) diff --git a/modules/pico_aodv.c b/modules/pico_aodv.c index 09a31585..69b93b87 100644 --- a/modules/pico_aodv.c +++ b/modules/pico_aodv.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -128,8 +128,8 @@ static struct pico_aodv_node *aodv_peer_new(struct pico_stack *S, const union pi memcpy(&node->dest, addr, sizeof(union pico_address)); node->stack = S; if (pico_tree_insert(&S->aodv_nodes, node)) { - PICO_FREE(node); - return NULL; + PICO_FREE(node); + return NULL; } return node; diff --git a/modules/pico_aodv.h b/modules/pico_aodv.h index f8f551e7..883e8ee8 100644 --- a/modules/pico_aodv.h +++ b/modules/pico_aodv.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_arp.c b/modules/pico_arp.c index 1eb41755..b0a9ff99 100644 --- a/modules/pico_arp.c +++ b/modules/pico_arp.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -53,8 +53,7 @@ static void pico_arp_queued_trigger(void) { int i; struct pico_frame *f; - for (i = 0; i < PICO_ARP_MAX_PENDING; i++) - { + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) { f = frames_queued[i]; if (f) { if (pico_datalink_send(f) <= 0) @@ -148,7 +147,7 @@ struct pico_ip4 *pico_arp_reverse_lookup(struct pico_stack *S, struct pico_eth * struct pico_tree_node *index; pico_tree_foreach(index, &S->arp_tree){ search = index->keyValue; - if(memcmp(&(search->eth.addr), &dst->addr, 6) == 0) + if (memcmp(&(search->eth.addr), &dst->addr, 6) == 0) return &search->ipv4; } return NULL; @@ -160,8 +159,7 @@ static void pico_arp_unreachable(struct pico_stack *S, struct pico_ip4 *a) struct pico_frame *f; struct pico_ipv4_hdr *hdr; struct pico_ip4 dst; - for (i = 0; i < PICO_ARP_MAX_PENDING; i++) - { + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) { f = frames_queued[i]; if (f) { hdr = (struct pico_ipv4_hdr *) f->net_hdr; @@ -182,7 +180,7 @@ static void pico_arp_unreachable(struct pico_stack *S, struct pico_ip4 *a) static void pico_arp_retry(struct pico_stack *S, struct pico_frame *f, struct pico_ip4 *where) { if (++f->failure_count < 4) { - arp_dbg ("================= ARP REQUIRED: %d =============\n\n", f->failure_count); + arp_dbg("================= ARP REQUIRED: %d =============\n\n", f->failure_count); /* check if dst is local (gateway = 0), or if to use gateway */ pico_arp_request(f->dev, where, PICO_ARP_QUERY); } else { @@ -201,7 +199,7 @@ struct pico_eth *pico_arp_get(struct pico_stack *S, struct pico_frame *f) return NULL; l = pico_ipv4_link_get(S, &hdr->dst); - if(l) { + if (l) { /* address belongs to ourself */ return &l->dev->eth->mac; } @@ -225,8 +223,7 @@ struct pico_eth *pico_arp_get(struct pico_stack *S, struct pico_frame *f) void pico_arp_postpone(struct pico_frame *f) { int i; - for (i = 0; i < PICO_ARP_MAX_PENDING; i++) - { + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) { if (!frames_queued[i]) { if (f->failure_count < 4) frames_queued[i] = f; @@ -246,7 +243,7 @@ static void dbg_arp(void) pico_tree_foreach(index, &S->arp_tree) { a = index->keyValue; - arp_dbg("ARP to %08x, mac: %02x:%02x:%02x:%02x:%02x:%02x\n", a->ipv4.addr, a->eth.addr[0], a->eth.addr[1], a->eth.addr[2], a->eth.addr[3], a->eth.addr[4], a->eth.addr[5] ); + arp_dbg("ARP to %08x, mac: %02x:%02x:%02x:%02x:%02x:%02x\n", a->ipv4.addr, a->eth.addr[0], a->eth.addr[1], a->eth.addr[2], a->eth.addr[3], a->eth.addr[4], a->eth.addr[5]); } } #endif @@ -293,7 +290,7 @@ static int pico_arp_add_entry(struct pico_arp *entry) int pico_arp_create_entry(uint8_t *hwaddr, struct pico_ip4 ipv4, struct pico_device *dev) { struct pico_arp*arp = PICO_ZALLOC(sizeof(struct pico_arp)); - if(!arp) { + if (!arp) { pico_err = PICO_ERR_ENOMEM; return -1; } @@ -312,14 +309,13 @@ int pico_arp_create_entry(uint8_t *hwaddr, struct pico_ip4 ipv4, struct pico_dev static void pico_arp_check_conflict(struct pico_stack *S, struct pico_arp_hdr *hdr) { - if (S->conflict_ipv4.conflict) - { - if((S->conflict_ipv4.ip.addr == hdr->src.addr) && - (memcmp(hdr->s_mac, S->conflict_ipv4.mac.addr, PICO_SIZE_ETH) != 0)) - S->conflict_ipv4.conflict(S, PICO_ARP_CONFLICT_REASON_CONFLICT ); - - if((hdr->src.addr == 0) && (hdr->dst.addr == S->conflict_ipv4.ip.addr)) - S->conflict_ipv4.conflict(S, PICO_ARP_CONFLICT_REASON_PROBE ); + if (S->conflict_ipv4.conflict) { + if ((S->conflict_ipv4.ip.addr == hdr->src.addr) && + (memcmp(hdr->s_mac, S->conflict_ipv4.mac.addr, PICO_SIZE_ETH) != 0)) + S->conflict_ipv4.conflict(S, PICO_ARP_CONFLICT_REASON_CONFLICT); + + if ((hdr->src.addr == 0) && (hdr->dst.addr == S->conflict_ipv4.ip.addr)) + S->conflict_ipv4.conflict(S, PICO_ARP_CONFLICT_REASON_PROBE); } } @@ -522,8 +518,7 @@ int32_t pico_arp_request(struct pico_device *dev, struct pico_ip4 *dst, uint8_t if (!q) return -1; - if (type == PICO_ARP_QUERY) - { + if (type == PICO_ARP_QUERY) { src = pico_ipv4_source_find(dev->stack, dst); if (!src) { pico_frame_discard(q); diff --git a/modules/pico_arp.h b/modules/pico_arp.h index 725edbe8..8bfb0564 100644 --- a/modules/pico_arp.h +++ b/modules/pico_arp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_ipc.c b/modules/pico_dev_ipc.c index 95901663..be74ba8e 100644 --- a/modules/pico_dev_ipc.c +++ b/modules/pico_dev_ipc.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Michiel Kustermans - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ static int pico_ipc_poll(struct pico_device *dev, int loop_score) int len; pfd.fd = ipc->fd; pfd.events = POLLIN; - do { + do { if (poll(&pfd, 1, 0) <= 0) return loop_score; @@ -63,7 +63,7 @@ static int pico_ipc_poll(struct pico_device *dev, int loop_score) loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } - } while(loop_score > 0); + } while (loop_score > 0); return 0; } @@ -72,7 +72,7 @@ static int pico_ipc_poll(struct pico_device *dev, int loop_score) void pico_ipc_destroy(struct pico_device *dev) { struct pico_device_ipc *ipc = (struct pico_device_ipc *) dev; - if(ipc->fd > 0) { + if (ipc->fd > 0) { close(ipc->fd); } } @@ -82,8 +82,8 @@ static int ipc_connect(const char *sock_path) struct sockaddr_un addr; int ipc_fd; - if((ipc_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) < 0) { - return(-1); + if ((ipc_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) < 0) { + return -1; } memset(&addr, 0, sizeof(addr)); @@ -91,8 +91,8 @@ static int ipc_connect(const char *sock_path) strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; - if(connect(ipc_fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) < 0) { - return(-1); + if (connect(ipc_fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) < 0) { + return -1; } return ipc_fd; @@ -107,7 +107,7 @@ struct pico_device *pico_ipc_create(struct pico_stack *S, const char *sock_path, ipc->dev.mtu = IPC_MTU; - if( 0 != pico_device_init(S, (struct pico_device *)ipc, name, mac)) { + if (0 != pico_device_init(S, (struct pico_device *)ipc, name, mac)) { dbg("Ipc init failed.\n"); pico_ipc_destroy((struct pico_device *)ipc); return NULL; diff --git a/modules/pico_dev_ipc.h b/modules/pico_dev_ipc.h index a6cb4b00..4dcb40fa 100644 --- a/modules/pico_dev_ipc.h +++ b/modules/pico_dev_ipc.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_loop.c b/modules/pico_dev_loop.c index e57536c0..54fcefae 100644 --- a/modules/pico_dev_loop.c +++ b/modules/pico_dev_loop.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -71,8 +71,8 @@ struct pico_device *pico_loop_create(struct pico_stack *S) if (!loop) return NULL; - if( 0 != pico_device_init(S, loop, "loop", NULL)) { - dbg ("Loop init failed.\n"); + if (0 != pico_device_init(S, loop, "loop", NULL)) { + dbg("Loop init failed.\n"); pico_device_destroy(loop); return NULL; } diff --git a/modules/pico_dev_loop.h b/modules/pico_dev_loop.h index 1ae8ee11..43611db9 100644 --- a/modules/pico_dev_loop.h +++ b/modules/pico_dev_loop.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_mock.c b/modules/pico_dev_mock.c index 6b83e63f..06f9dad2 100644 --- a/modules/pico_dev_mock.c +++ b/modules/pico_dev_mock.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Frederik Van Slycken - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -66,18 +66,18 @@ static int pico_mock_send(struct pico_device *dev, void *buf, int len) struct mock_device*mock = pico_tree_findKey(&mock_device_tree, &search); struct mock_frame*frame; - if(!mock) + if (!mock) return 0; if (len > MOCK_MTU) return 0; frame = PICO_ZALLOC(sizeof(struct mock_frame)); - if(!frame) { + if (!frame) { return 0; } - if(mock->out_head == NULL) + if (mock->out_head == NULL) mock->out_head = frame; else mock->out_tail->next = frame; @@ -85,7 +85,7 @@ static int pico_mock_send(struct pico_device *dev, void *buf, int len) mock->out_tail = frame; mock->out_tail->buffer = PICO_ZALLOC((uint32_t)len); - if(!mock->out_tail->buffer) + if (!mock->out_tail->buffer) return 0; memcpy(mock->out_tail->buffer, buf, (uint32_t)len); @@ -103,20 +103,19 @@ static int pico_mock_poll(struct pico_device *dev, int loop_score) struct mock_device*mock = pico_tree_findKey(&mock_device_tree, &search); struct mock_frame*nxt; - if(!mock) + if (!mock) return 0; if (loop_score <= 0) return 0; - while(mock->in_head != NULL && loop_score > 0) - { + while (mock->in_head != NULL && loop_score > 0) { pico_stack_recv(dev, mock->in_head->buffer, (uint32_t)mock->in_head->len); loop_score--; PICO_FREE(mock->in_head->buffer); - if(mock->in_tail == mock->in_head) { + if (mock->in_tail == mock->in_head) { PICO_FREE(mock->in_head); mock->in_tail = mock->in_head = NULL; return loop_score; @@ -132,22 +131,22 @@ static int pico_mock_poll(struct pico_device *dev, int loop_score) int pico_mock_network_read(struct mock_device*mock, void *buf, int len) { struct mock_frame*nxt; - if(mock->out_head == NULL) + if (mock->out_head == NULL) return 0; - if(len > mock->out_head->len - mock->out_head->read) + if (len > mock->out_head->len - mock->out_head->read) len = mock->out_head->len - mock->out_head->read; memcpy(buf, mock->out_head->buffer, (uint32_t)len); - if(len + mock->out_head->read != mock->out_head->len) { + if (len + mock->out_head->read != mock->out_head->len) { mock->out_head->read += len; return len; } PICO_FREE(mock->out_head->buffer); - if(mock->out_tail == mock->out_head) { + if (mock->out_tail == mock->out_head) { PICO_FREE(mock->out_head); mock->out_tail = mock->out_head = NULL; return len; @@ -167,11 +166,11 @@ int pico_mock_network_write(struct mock_device*mock, const void *buf, int len) return 0; frame = PICO_ZALLOC(sizeof(struct mock_frame)); - if(!frame) { + if (!frame) { return 0; } - if(mock->in_head == NULL) + if (mock->in_head == NULL) mock->in_head = frame; else mock->in_tail->next = frame; @@ -179,7 +178,7 @@ int pico_mock_network_write(struct mock_device*mock, const void *buf, int len) mock->in_tail = frame; mock->in_tail->buffer = PICO_ZALLOC((uint32_t)len); - if(!mock->in_tail->buffer) + if (!mock->in_tail->buffer) return 0; memcpy(mock->in_tail->buffer, buf, (uint32_t)len); @@ -199,17 +198,17 @@ void pico_mock_destroy(struct pico_device *dev) struct mock_device*mock = pico_tree_findKey(&mock_device_tree, &search); struct mock_frame*nxt; - if(!mock) + if (!mock) return; nxt = mock->in_head; - while(nxt != NULL) { + while (nxt != NULL) { mock->in_head = mock->in_head->next; PICO_FREE(nxt); nxt = mock->in_head; } nxt = mock->out_head; - while(nxt != NULL) { + while (nxt != NULL) { mock->out_head = mock->out_head->next; PICO_FREE(nxt); nxt = mock->out_head; @@ -221,7 +220,7 @@ struct mock_device *pico_mock_create(struct pico_stack *S, uint8_t*mac) { struct mock_device*mock = PICO_ZALLOC(sizeof(struct mock_device)); - if(!mock) + if (!mock) return NULL; mock->dev = PICO_ZALLOC(sizeof(struct pico_device)); @@ -230,9 +229,9 @@ struct mock_device *pico_mock_create(struct pico_stack *S, uint8_t*mac) return NULL; } - if(mac != NULL) { + if (mac != NULL) { mock->mac = PICO_ZALLOC(6 * sizeof(uint8_t)); - if(!mock->mac) { + if (!mock->mac) { PICO_FREE(mock->dev); PICO_FREE(mock); return NULL; @@ -241,10 +240,10 @@ struct mock_device *pico_mock_create(struct pico_stack *S, uint8_t*mac) memcpy(mock->mac, mac, 6); } - if( 0 != pico_device_init(S, (struct pico_device *)mock->dev, "mock", mac)) { - dbg ("Loop init failed.\n"); + if (0 != pico_device_init(S, (struct pico_device *)mock->dev, "mock", mac)) { + dbg("Loop init failed.\n"); pico_device_destroy(mock->dev); - if(mock->mac != NULL) + if (mock->mac != NULL) PICO_FREE(mock->mac); PICO_FREE(mock); @@ -277,7 +276,7 @@ uint32_t mock_get_sender_ip4(struct mock_device*mock, const char*buf, int len) { uint32_t ret; int start = mock->mac ? 14 : 0; - if(start + 16 > len) { + if (start + 16 > len) { dbg("out of range!\n"); return 0; } @@ -307,7 +306,7 @@ int mock_ip_protocol(struct mock_device*mock, const char*buf, int len) { uint8_t type; int start = mock->mac ? 14 : 0; - if(start + 10 > len) { + if (start + 10 > len) { return 0; } @@ -320,7 +319,7 @@ int mock_icmp_type(struct mock_device*mock, const char*buf, int len) { uint8_t type; int start = mock->mac ? 14 : 0; - if(start + 21 > len) { + if (start + 21 > len) { return 0; } @@ -333,7 +332,7 @@ int mock_icmp_code(struct mock_device*mock, const char*buf, int len) { uint8_t type; int start = mock->mac ? 14 : 0; - if(start + 22 > len) { + if (start + 22 > len) { return 0; } diff --git a/modules/pico_dev_mock.h b/modules/pico_dev_mock.h index 5c4d0026..9da70b1d 100644 --- a/modules/pico_dev_mock.h +++ b/modules/pico_dev_mock.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_null.c b/modules/pico_dev_null.c index 24504891..cc854854 100644 --- a/modules/pico_dev_null.c +++ b/modules/pico_dev_null.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -65,7 +65,7 @@ struct pico_device *pico_null_create(struct pico_stack *S, const char *name) if (!null) return NULL; - if( 0 != pico_device_init(S, (struct pico_device *)null, name, NULL)) { + if (0 != pico_device_init(S, (struct pico_device *)null, name, NULL)) { return NULL; } diff --git a/modules/pico_dev_null.h b/modules/pico_dev_null.h index 427a58d3..f8e8f561 100644 --- a/modules/pico_dev_null.h +++ b/modules/pico_dev_null.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_pcap.c b/modules/pico_dev_pcap.c index 13ab4fb5..2b1866be 100644 --- a/modules/pico_dev_pcap.c +++ b/modules/pico_dev_pcap.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -79,8 +79,8 @@ static struct pico_device *pico_pcap_create(struct pico_stack *S, char *if_file_ if (!pcap) return NULL; - if( 0 != pico_device_init(S, (struct pico_device *)pcap, name, mac)) { - dbg ("Pcap init failed.\n"); + if (0 != pico_device_init(S, (struct pico_device *)pcap, name, mac)) { + dbg("Pcap init failed.\n"); pico_pcap_destroy((struct pico_device *)pcap); return NULL; } diff --git a/modules/pico_dev_ppp.c b/modules/pico_dev_ppp.c index 290e9bcd..ccaa3f28 100644 --- a/modules/pico_dev_ppp.c +++ b/modules/pico_dev_ppp.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012 TASS Belgium NV. * Authors: Serge Gadeyne, Daniele Lacamera, Maxime Vincent - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -320,8 +320,9 @@ static void lcp_optflags_print(struct pico_device_ppp *ppp, uint8_t *opts, uint3 #define PPP_TIMER_ON_AUTH 0x10u #define PPP_TIMER_ON_IPCP 0x20u -static int should_escape(uint8_t byte) { - return (byte == PPPF_FLAG_SEQ || byte == PPPF_CTRL_ESC || byte == PPPF_CTRL || byte < 0x20); +static int should_escape(uint8_t byte) +{ + return (byte == PPPF_FLAG_SEQ || byte == PPPF_CTRL_ESC || byte == PPPF_CTRL || byte < 0x20); } /* Escape and send */ @@ -338,7 +339,7 @@ static int ppp_serial_send_escape(struct pico_device_ppp *ppp, void *buf, int le uint32_t idx; if (len > 0) { ppp_dbg("PPP >>>> "); - for(idx = 0; idx < (uint32_t)len; idx++) { + for (idx = 0; idx < (uint32_t)len; idx++) { ppp_dbg(" %02x", ((uint8_t *)buf)[idx]); } ppp_dbg("\n"); @@ -346,8 +347,7 @@ static int ppp_serial_send_escape(struct pico_device_ppp *ppp, void *buf, int le } #endif - for (i = 1; i < (len - 1); i++) /* from 1 to len -1, as start/stop are not escaped */ - { + for (i = 1; i < (len - 1); i++) { /* from 1 to len -1, as start/stop are not escaped */ if (should_escape(in_buf[i])) esc_char_count++; } @@ -357,12 +357,12 @@ static int ppp_serial_send_escape(struct pico_device_ppp *ppp, void *buf, int le newlen = len + esc_char_count; out_buf = PICO_ZALLOC((uint32_t)newlen); - if(!out_buf) + if (!out_buf) return -1; /* Start byte. */ out_buf[0] = in_buf[0]; - for(i = 1, j = 1; i < (len - 1); i++) { + for (i = 1, j = 1; i < (len - 1); i++) { if (should_escape(in_buf[i])) { out_buf[j++] = PPPF_CTRL_ESC; out_buf[j++] = in_buf[i] ^ 0x20; @@ -469,8 +469,7 @@ static uint16_t ppp_fcs_char(uint16_t old_crc, uint8_t data) static uint16_t ppp_fcs_continue(uint16_t fcs, uint8_t *buf, uint32_t len) { uint8_t *pos = buf; - for (pos = buf; pos < buf + len; pos++) - { + for (pos = buf; pos < buf + len; pos++) { fcs = ppp_fcs_char(fcs, *pos); } return fcs; @@ -544,16 +543,14 @@ static int pico_ppp_send(struct pico_device *dev, void *buf, int len) return len; pico_ppp_data_buffer[i++] = PPPF_FLAG_SEQ; - if (!LCPOPT_ISSET_PEER(ppp, LCPOPT_ADDRCTL_COMP)) - { + if (!LCPOPT_ISSET_PEER(ppp, LCPOPT_ADDRCTL_COMP)) { pico_ppp_data_buffer[i++] = PPPF_ADDR; pico_ppp_data_buffer[i++] = PPPF_CTRL; } fcs_start = i; - if (!LCPOPT_ISSET_PEER(ppp, LCPOPT_PROTO_COMP)) - { + if (!LCPOPT_ISSET_PEER(ppp, LCPOPT_PROTO_COMP)) { pico_ppp_data_buffer[i++] = 0x00; } @@ -873,12 +870,11 @@ static void lcp_optflags_print(struct pico_device_ppp *ppp, uint8_t *opts, uint3 int off; IGNORE_PARAMETER(ppp); ppp_dbg("Parsing options:\n"); - while(p < (opts + opts_len)) { + while (p < (opts + opts_len)) { int i; ppp_dbg("-- LCP opt: %d - len: %d - data:", p[0], p[1]); - for (i = 0; i < p[1] - 2; i++) - { + for (i = 0; i < p[1] - 2; i++) { ppp_dbg(" %02X", p[2 + i]); } ppp_dbg("\n"); @@ -898,13 +894,11 @@ static uint16_t lcp_optflags(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t uint16_t flags = 0; uint8_t *p = pkt + sizeof(struct pico_lcp_hdr); int off; - while(p < (pkt + len)) { + while (p < (pkt + len)) { flags = (uint16_t)((uint16_t)(1u << (uint16_t)p[0]) | flags); - if (adjust_opts && ppp) - { - switch (p[0]) - { + if (adjust_opts && ppp) { + switch (p[0]) { case LCPOPT_MRU: /* XXX: Can we accept any MRU ? */ ppp_dbg("Adjusting MRU to %02x%02x\n", p[2], p[3]); @@ -1004,7 +998,7 @@ static void lcp_send_configure_nack(struct pico_device_ppp *ppp) dst_opts[dstopts_len++] = p[1]; ppp_dbg("data: "); - for(i = 0; i < p[1] - 2u; i++) { /* length includes type, length and data fields */ + for (i = 0; i < p[1] - 2u; i++) { /* length includes type, length and data fields */ dst_opts[dstopts_len++] = p[2 + i]; ppp_dbg("%02X ", p[2 + i]); } @@ -1096,7 +1090,7 @@ static void pap_process_in(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t l if (ppp->auth != 0xc023) return; - switch(p->code) { + switch (p->code) { case PAP_AUTH_ACK: ppp_dbg("PAP: Received Authentication OK!\n"); evaluate_auth_state(ppp, PPP_AUTH_EVENT_RAA); @@ -1122,7 +1116,7 @@ static void chap_process_in(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t if (ppp->auth != 0xc223) return; - switch(ch->code) { + switch (ch->code) { case CHAP_CHALLENGE: ppp_dbg("Received CHAP CHALLENGE\n"); ppp->pkt = pkt; @@ -1242,7 +1236,7 @@ static void ipcp_reject_vj(struct pico_device_ppp *ppp, uint8_t *comp_req) ih->id = ppp->frame_id++; ih->code = PICO_CONF_REQ; ih->len = short_be(IPCP_VJ_LEN + sizeof(struct pico_ipcp_hdr)); - for(i = 0; i < IPCP_OPT_VJ; i++) + for (i = 0; i < IPCP_OPT_VJ; i++) p[i] = comp_req[i + sizeof(struct pico_ipcp_hdr)]; ppp_dbg("Sending IPCP CONF REJ VJ\n"); pico_ppp_ctl_send(&ppp->dev, PPP_PROTO_IPCP, @@ -1341,7 +1335,7 @@ static void ipcp_process_in(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t ppp->pkt = pkt; ppp->len = len; - switch(ih->code) { + switch (ih->code) { case PICO_CONF_ACK: ppp_dbg("Received IPCP CONF ACK\n"); evaluate_ipcp_state(ppp, PPP_IPCP_EVENT_RCA); @@ -1449,7 +1443,7 @@ static void ppp_recv_data(struct pico_device_ppp *ppp, void *data, uint32_t len) uint32_t idx; if (len > 0) { ppp_dbg("PPP <<<<< "); - for(idx = 0; idx < len; idx++) { + for (idx = 0; idx < len; idx++) { ppp_dbg(" %02x", ((uint8_t *)data)[idx]); } ppp_dbg("\n"); @@ -2145,7 +2139,7 @@ static void check_to_lcp(struct pico_device_ppp *ppp) if (ppp->timer_val == 0) { if (ppp->timer_count == 0) evaluate_lcp_state(ppp, PPP_LCP_EVENT_TO_NEG); - else{ + else { evaluate_lcp_state(ppp, PPP_LCP_EVENT_TO_POS); ppp->timer_count--; } @@ -2206,7 +2200,7 @@ struct pico_device *pico_ppp_create(struct pico_stack *S) snprintf(devname, MAX_DEVICE_NAME, "ppp%d", ppp_devnum++); - if( 0 != pico_device_init(S, (struct pico_device *)ppp, devname, NULL)) { + if (0 != pico_device_init(S, (struct pico_device *)ppp, devname, NULL)) { return NULL; } diff --git a/modules/pico_dev_ppp.h b/modules/pico_dev_ppp.h index f153b6c3..ebb82149 100644 --- a/modules/pico_dev_ppp.h +++ b/modules/pico_dev_ppp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_radio_mgr.c b/modules/pico_dev_radio_mgr.c index 99a874b3..adc82d80 100644 --- a/modules/pico_dev_radio_mgr.c +++ b/modules/pico_dev_radio_mgr.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -60,7 +60,6 @@ #define LISTENING_PORT 7777 #define MESSAGE_MTU 150 -#define EVER (;;) struct socket { int s; @@ -189,8 +188,7 @@ pico_radio_mgr_welcome(int socket) if (errno && EINTR != errno) goto hup; } - - if (id <= 0) { // Node's can't have ID '0'. + if (id <= 0) { /* Node's can't have ID '0'. */ RADIO_DBG("Invalid socket\n"); close(socket); return -1; @@ -283,7 +281,7 @@ pico_radio_mgr_distribute(uint8_t *buf, int len, uint8_t id) pico_tree_foreach(i, &Sockets) { key = i->keyValue; - if (key && key->id != id && key->id) { // Do not sent to ourselves or manager + if (key && key->id != id && key->id) { /* Do not sent to ourselves or manager */ ar0 = key->area0; ar1 = key->area1; if (area0 == ar0 || area0 == ar1 || (area1 && (area1 == ar0 || area1 == ar1))) { @@ -307,7 +305,7 @@ pico_radio_mgr_process(struct pollfd *fds, int n) for (i = 0; i < n; i++) { event = fds[i].revents; - if (event && (event & POLLIN)) { // POLLIN + if (event && (event & POLLIN)) { /* POLLIN */ if (!i) { /* Accept a new connection */ pico_radio_mgr_accept(fds[i].fd); @@ -327,7 +325,6 @@ pico_radio_mgr_process(struct pollfd *fds, int n) goto hup; } } - return; hup: pico_radio_mgr_socket_hup(fds[i].fd); @@ -366,7 +363,7 @@ pico_radio_mgr_start(void) signal(SIGQUIT, pico_radio_mgr_quit); - for EVER { + for (;;) { if (fds) PICO_FREE(fds); fds = pico_radio_mgr_socket_all((int *)&n); diff --git a/modules/pico_dev_radio_mgr.h b/modules/pico_dev_radio_mgr.h index 2ea60b67..f542a004 100644 --- a/modules/pico_dev_radio_mgr.h +++ b/modules/pico_dev_radio_mgr.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_radiotest.c b/modules/pico_dev_radiotest.c index c866848e..bf399413 100644 --- a/modules/pico_dev_radiotest.c +++ b/modules/pico_dev_radiotest.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera, Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -68,7 +68,7 @@ ******************************************************************************/ /* Uncomment next line to enable Random packet loss (specify percentage) */ -//#define PACKET_LOSS 3 +/*#define PACKET_LOSS 3 */ #define RFDEV_PANID 0xABCD #define MC_ADDR_BE 0x010101EBU @@ -127,7 +127,7 @@ static void radiotest_pcap_open(struct radiotest_radio *dev, char *dump) #endif if (!dev->pcap) { perror("LibPCAP"); - exit (1); + exit(1); } /* Construct file path */ @@ -293,7 +293,6 @@ static uint16_t calculate_crc16(uint8_t *buf, uint8_t len) q = (crc ^ (c >> 4)) & 0xF; crc = (uint16_t)((uint16_t)(crc >> 4) ^ (q * 0x1081)); } - return crc; } @@ -302,7 +301,7 @@ static int radiotest_poll(struct pico_device *dev, int loop_score) { struct radiotest_radio *radio = (struct radiotest_radio *)dev; union pico_ll_addr src = {0}, dst = {0}; - int pollret, ret_len=0; + int pollret, ret_len = 0; struct pollfd p; uint8_t buf[128]; uint8_t phy = 0; @@ -401,7 +400,7 @@ static int radiotest_send(struct pico_device *dev, void *_buf, int len, union pi /* Store the addresses in buffer for management */ memcpy(buf, _buf, (size_t)len); - len = (uint16_t)(len + (uint16_t)RADIO_OVERHEAD); // CRC + ID + len = (uint16_t)(len + (uint16_t)RADIO_OVERHEAD); /* CRC + ID */ buf[len - 2] = (uint8_t)short_be(radio->addr.addr_short.addr); buf[len - 1] = did; @@ -482,10 +481,10 @@ struct pico_device *pico_radiotest_create(struct pico_stack *S, uint8_t addr, ui radiotest_gen_ex(radio->addr.addr_short, radio->addr.addr_ext.addr); RADIO_DBG("Radiotest short address: 0x%04X\n", short_be(radio->addr.addr_short.addr)); RADIO_DBG("Radiotest ext address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", - radio->addr.addr_ext.addr[0],radio->addr.addr_ext.addr[1], - radio->addr.addr_ext.addr[2],radio->addr.addr_ext.addr[3], - radio->addr.addr_ext.addr[4],radio->addr.addr_ext.addr[5], - radio->addr.addr_ext.addr[6],radio->addr.addr_ext.addr[7]); + radio->addr.addr_ext.addr[0], radio->addr.addr_ext.addr[1], + radio->addr.addr_ext.addr[2], radio->addr.addr_ext.addr[3], + radio->addr.addr_ext.addr[4], radio->addr.addr_ext.addr[5], + radio->addr.addr_ext.addr[6], radio->addr.addr_ext.addr[7]); if (!loop) { if ((connection = radiotest_connect(addr, area0, area1)) <= 0) { diff --git a/modules/pico_dev_radiotest.h b/modules/pico_dev_radiotest.h index ecb747e6..f63087e1 100644 --- a/modules/pico_dev_radiotest.h +++ b/modules/pico_dev_radiotest.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_tap.c b/modules/pico_dev_tap.c index 80575b17..2335d513 100644 --- a/modules/pico_dev_tap.c +++ b/modules/pico_dev_tap.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -84,7 +84,7 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score) int len; pfd.fd = tap->fd; pfd.events = POLLIN; - do { + do { if (poll(&pfd, 1, 0) <= 0) { return loop_score; } @@ -94,7 +94,7 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score) loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } - } while(loop_score > 0); + } while (loop_score > 0); return 0; } @@ -104,25 +104,25 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score) void pico_tap_dsr(void *arg) { - int len; - struct pico_device_tap *tap = (struct pico_device_tap *)arg; - unsigned char buf[TUN_MTU]; - len = read(tap->fd, buf, TUN_MTU); - if (len > 0) { - pico_stack_recv(&tap->dev, buf, (uint32_t)len); - } + int len; + struct pico_device_tap *tap = (struct pico_device_tap *)arg; + unsigned char buf[TUN_MTU]; + len = read(tap->fd, buf, TUN_MTU); + if (len > 0) { + pico_stack_recv(&tap->dev, buf, (uint32_t)len); + } } int pico_tap_WFI(struct pico_device *dev, int timeout_ms) { - struct pollfd pfd; - struct pico_device_tap *tap = (struct pico_device_tap *) dev; - pfd.fd = tap->fd; - pfd.events = POLLIN; - if (poll(&pfd, 1, timeout_ms) <= 0) - return 0; - pico_schedule_job(dev->stack, pico_tap_dsr, tap); - return 1; + struct pollfd pfd; + struct pico_device_tap *tap = (struct pico_device_tap *) dev; + pfd.fd = tap->fd; + pfd.events = POLLIN; + if (poll(&pfd, 1, timeout_ms) <= 0) + return 0; + pico_schedule_job(dev->stack, pico_tap_dsr, tap); + return 1; } #endif @@ -131,7 +131,7 @@ int pico_tap_WFI(struct pico_device *dev, int timeout_ms) void pico_tap_destroy(struct pico_device *dev) { struct pico_device_tap *tap = (struct pico_device_tap *) dev; - if(tap->fd > 0) { + if (tap->fd > 0) { close(tap->fd); } } @@ -141,14 +141,14 @@ static int tap_open(char *name) { struct ifreq ifr; int tap_fd; - if((tap_fd = open("/dev/net/tun", O_RDWR)) < 0) { + if ((tap_fd = open("/dev/net/tun", O_RDWR)) < 0) { return -1; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - strncpy(ifr.ifr_name, name, IFNAMSIZ-1); - if(ioctl(tap_fd, TUNSETIFF, &ifr) < 0) { + strncpy(ifr.ifr_name, name, IFNAMSIZ - 1); + if (ioctl(tap_fd, TUNSETIFF, &ifr) < 0) { return -1; } @@ -173,7 +173,7 @@ static int tap_get_mac(char *name, uint8_t *mac) int retval = -1; sck = socket(AF_INET, SOCK_DGRAM, 0); - if(sck < 0) { + if (sck < 0) { return retval; } @@ -185,7 +185,7 @@ static int tap_get_mac(char *name, uint8_t *mac) return -1; } - memcpy (mac, ð.ifr_hwaddr.sa_data, 6); + memcpy(mac, ð.ifr_hwaddr.sa_data, 6); close(sck); return 0; @@ -202,7 +202,7 @@ static int tap_get_mac(char *name, uint8_t *mac) return -1; root = ifap; - while(ifap) { + while (ifap) { if (strcmp(name, ifap->ifa_name) == 0) { sdl = (struct sockaddr_dl *) ifap->ifa_addr; } @@ -263,7 +263,7 @@ struct pico_device *pico_tap_create(struct pico_stack *S, char *name) */ mac[5]++; - if( 0 != pico_device_init(S, (struct pico_device *)tap, name, mac)) { + if (0 != pico_device_init(S, (struct pico_device *)tap, name, mac)) { dbg("Tap init failed.\n"); pico_tap_destroy((struct pico_device *)tap); return NULL; diff --git a/modules/pico_dev_tap.h b/modules/pico_dev_tap.h index 5af185e8..65af9eab 100644 --- a/modules/pico_dev_tap.h +++ b/modules/pico_dev_tap.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_tap_windows.c b/modules/pico_dev_tap_windows.c index 8a4c17b8..97b274b4 100644 --- a/modules/pico_dev_tap_windows.c +++ b/modules/pico_dev_tap_windows.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -7,7 +7,7 @@ * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Maxime Vincent * Based on the OpenVPN tun.c driver, under GPL - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -27,7 +27,7 @@ * *********************************************************************/ -/* +/* * NOTES: This is the Windows-only driver, a Linux-equivalent is available, too You need to have an OpenVPN TUN/TAP network adapter installed, first This driver is barely working: @@ -163,14 +163,12 @@ const struct tap_reg *get_tap_reg (void) KEY_READ, &adapter_key); - if (status != ERROR_SUCCESS) - { + if (status != ERROR_SUCCESS) { dbg_tap_reg("Error opening registry key: %s\n", ADAPTER_KEY); return NULL; } - while (1) - { + while (1) { char enum_name[256]; char unit_string[256]; HKEY unit_key; @@ -195,8 +193,8 @@ const struct tap_reg *get_tap_reg (void) else if (status != ERROR_SUCCESS) dbg_tap_reg("Error enumerating registry subkeys of key: %s.\n", ADAPTER_KEY); - snprintf (unit_string, sizeof(unit_string), "%s\\%s", - ADAPTER_KEY, enum_name); + snprintf(unit_string, sizeof(unit_string), "%s\\%s", + ADAPTER_KEY, enum_name); status = RegOpenKeyEx( HKEY_LOCAL_MACHINE, @@ -205,12 +203,9 @@ const struct tap_reg *get_tap_reg (void) KEY_READ, &unit_key); - if (status != ERROR_SUCCESS) - { + if (status != ERROR_SUCCESS) { dbg_tap_reg("Error opening registry key: %s\n", unit_string); - } - else - { + } else { len = sizeof (component_id); status = RegQueryValueEx( unit_key, @@ -220,12 +215,9 @@ const struct tap_reg *get_tap_reg (void) (LPBYTE)component_id, &len); - if (status != ERROR_SUCCESS || data_type != REG_SZ) - { + if (status != ERROR_SUCCESS || data_type != REG_SZ) { dbg_tap_reg("Error opening registry key: %s\\%s\n", unit_string, component_id_string); - } - else - { + } else { len = sizeof (net_cfg_instance_id); status = RegQueryValueEx( unit_key, @@ -235,10 +227,8 @@ const struct tap_reg *get_tap_reg (void) (LPBYTE)net_cfg_instance_id, &len); - if (status == ERROR_SUCCESS && data_type == REG_SZ) - { - if (!strcmp (component_id, TAP_WIN_COMPONENT_ID)) - { + if (status == ERROR_SUCCESS && data_type == REG_SZ) { + if (!strcmp(component_id, TAP_WIN_COMPONENT_ID)) { struct tap_reg *reg; reg = PICO_ZALLOC(sizeof(struct tap_reg), 1); /* ALLOC_OBJ_CLEAR_GC (reg, struct tap_reg, gc); */ @@ -246,9 +236,8 @@ const struct tap_reg *get_tap_reg (void) return NULL; /* reg->guid = string_alloc (net_cfg_instance_id, gc); */ - reg->guid = PICO_ZALLOC (strlen(net_cfg_instance_id) + 1, 1); - if (!(reg->guid)) - { + reg->guid = PICO_ZALLOC(strlen(net_cfg_instance_id) + 1, 1); + if (!(reg->guid)) { PICO_FREE(reg); return NULL; } @@ -266,12 +255,12 @@ const struct tap_reg *get_tap_reg (void) } } - RegCloseKey (unit_key); + RegCloseKey(unit_key); } ++i; } - RegCloseKey (adapter_key); + RegCloseKey(adapter_key); return first; } @@ -292,14 +281,12 @@ const struct panel_reg *get_panel_reg (void) KEY_READ, &network_connections_key); - if (status != ERROR_SUCCESS) - { + if (status != ERROR_SUCCESS) { dbg_tap_reg("Error opening registry key: %s\n", NETWORK_CONNECTIONS_KEY); return NULL; } - while (1) - { + while (1) { char enum_name[256]; char connection_string[256]; HKEY connection_key; @@ -322,7 +309,7 @@ const struct panel_reg *get_panel_reg (void) else if (status != ERROR_SUCCESS) dbg_tap_reg("Error enumerating registry subkeys of key: %s.\n", NETWORK_CONNECTIONS_KEY); - snprintf (connection_string, sizeof(connection_string), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, enum_name); + snprintf(connection_string, sizeof(connection_string), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, enum_name); status = RegOpenKeyEx( HKEY_LOCAL_MACHINE, @@ -332,8 +319,7 @@ const struct panel_reg *get_panel_reg (void) &connection_key); if (status != ERROR_SUCCESS) dbg_tap_reg("Error opening registry key: %s\n", connection_string); - else - { + else { len = sizeof (name_data); status = RegQueryValueExW( connection_key, @@ -345,8 +331,7 @@ const struct panel_reg *get_panel_reg (void) if (status != ERROR_SUCCESS || name_type != REG_SZ) dbg_tap_reg("Error opening registry key: %s\\%s\\%S\n", NETWORK_CONNECTIONS_KEY, connection_string, name_string); - else - { + else { int n; LPSTR name; struct panel_reg *reg; @@ -356,21 +341,19 @@ const struct panel_reg *get_panel_reg (void) if (!reg) return NULL; - n = WideCharToMultiByte (CP_UTF8, 0, name_data, -1, NULL, 0, NULL, NULL); + n = WideCharToMultiByte(CP_UTF8, 0, name_data, -1, NULL, 0, NULL, NULL); /* name = gc_malloc (n, false, gc); */ name = PICO_ZALLOC(n, 1); - if (!name) - { + if (!name) { PICO_FREE(reg); return NULL; } - WideCharToMultiByte (CP_UTF8, 0, name_data, -1, name, n, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, name_data, -1, name, n, NULL, NULL); reg->name = name; /* reg->guid = string_alloc (enum_name, gc); */ reg->guid = PICO_ZALLOC(strlen(enum_name) + 1, 1); - if (!reg->guid) - { + if (!reg->guid) { PICO_FREE((void *)reg->name); PICO_FREE((void *)reg); return NULL; @@ -388,12 +371,12 @@ const struct panel_reg *get_panel_reg (void) last = reg; } - RegCloseKey (connection_key); + RegCloseKey(connection_key); } ++i; } - RegCloseKey (network_connections_key); + RegCloseKey(network_connections_key); return first; } @@ -411,8 +394,8 @@ void show_tap_win_adapters (void) const struct tap_reg *tr1; const struct panel_reg *pr; - const struct tap_reg *tap_reg = get_tap_reg (); - const struct panel_reg *panel_reg = get_panel_reg (); + const struct tap_reg *tap_reg = get_tap_reg(); + const struct panel_reg *panel_reg = get_panel_reg(); if (!(tap_reg && panel_reg)) return; @@ -420,25 +403,19 @@ void show_tap_win_adapters (void) dbg_tap_info("Available TAP-WIN32 adapters [name, GUID]:\n"); /* loop through each TAP-Windows adapter registry entry */ - for (tr = tap_reg; tr != NULL; tr = tr->next) - { + for (tr = tap_reg; tr != NULL; tr = tr->next) { links = 0; /* loop through each network connections entry in the control panel */ - for (pr = panel_reg; pr != NULL; pr = pr->next) - { - if (!strcmp (tr->guid, pr->guid)) - { + for (pr = panel_reg; pr != NULL; pr = pr->next) { + if (!strcmp(tr->guid, pr->guid)) { dbg_tap_info("\t>> '%s' %s\n", pr->name, tr->guid); ++links; } } - if (links > 1) - { + if (links > 1) { warn_panel_dup = 1; - } - else if (links == 0) - { + } else if (links == 0) { /* a TAP adapter exists without a link from the network connections control panel */ warn_panel_null = 1; @@ -446,11 +423,9 @@ void show_tap_win_adapters (void) } } /* check for TAP-Windows adapter duplicated GUIDs */ - for (tr = tap_reg; tr != NULL; tr = tr->next) - { - for (tr1 = tap_reg; tr1 != NULL; tr1 = tr1->next) - { - if (tr != tr1 && !strcmp (tr->guid, tr1->guid)) + for (tr = tap_reg; tr != NULL; tr = tr->next) { + for (tr1 = tap_reg; tr1 != NULL; tr1 = tr1->next) { + if (tr != tr1 && !strcmp(tr->guid, tr1->guid)) warn_tap_dup = 1; } } @@ -472,13 +447,10 @@ const char *get_first_device_guid(const struct tap_reg *tap_reg, const struct pa const struct tap_reg *tr; const struct panel_reg *pr; /* loop through each TAP-Windows adapter registry entry */ - for (tr = tap_reg; tr != NULL; tr = tr->next) - { + for (tr = tap_reg; tr != NULL; tr = tr->next) { /* loop through each network connections entry in the control panel */ - for (pr = panel_reg; pr != NULL; pr = pr->next) - { - if (!strcmp (tr->guid, pr->guid)) - { + for (pr = panel_reg; pr != NULL; pr = pr->next) { + if (!strcmp(tr->guid, pr->guid)) { dbg_tap_info("Using first TAP device: '%s' %s\n", pr->name, tr->guid); if (name) strcpy(name, pr->name); @@ -498,10 +470,9 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc const char *device_guid = NULL; DWORD len; - dbg_tap_info("open_tun, tt->ipv6=%d\n", tt->ipv6 ); + dbg_tap_info("open_tun, tt->ipv6=%d\n", tt->ipv6); - if (!(tt->type == DEV_TYPE_TAP || tt->type == DEV_TYPE_TUN)) - { + if (!(tt->type == DEV_TYPE_TAP || tt->type == DEV_TYPE_TUN)) { dbg_tap_info("Unknown virtual device type: '%s'\n", dev); return -1; } @@ -514,25 +485,24 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc const struct panel_reg *panel_reg = get_panel_reg(); char name[256]; - if (!(tap_reg && panel_reg)) - { + if (!(tap_reg && panel_reg)) { dbg_tap_info("No TUN/TAP devices found\n"); return -1; } /* Get the device GUID for the device specified with --dev-node. */ - device_guid = get_first_device_guid (tap_reg, panel_reg, name); + device_guid = get_first_device_guid(tap_reg, panel_reg, name); if (!device_guid) dbg_tap_info("TAP-Windows adapter '%s' not found\n", dev_node); /* Open Windows TAP-Windows adapter */ - snprintf (device_path, sizeof(device_path), "%s%s%s", - USERMODEDEVICEDIR, - device_guid, - TAP_WIN_SUFFIX); + snprintf(device_path, sizeof(device_path), "%s%s%s", + USERMODEDEVICEDIR, + device_guid, + TAP_WIN_SUFFIX); - tt->hand = CreateFile ( + tt->hand = CreateFile( device_path, GENERIC_READ | GENERIC_WRITE, 0, /* was: FILE_SHARE_READ */ @@ -561,47 +531,43 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc ULONG info[3]; /* TODO TODO TODO */ /* CLEAR (info); */ - if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_VERSION, &info, sizeof (info), &info, sizeof (info), &len, NULL)) - { - dbg_tap_info ("TAP-Windows Driver Version %d.%d %s\n", - (int) info[0], - (int) info[1], - (info[2] ? "(DEBUG)" : "")); + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_VERSION, &info, sizeof (info), &info, sizeof (info), &len, NULL)) { + dbg_tap_info("TAP-Windows Driver Version %d.%d %s\n", + (int) info[0], + (int) info[1], + (info[2] ? "(DEBUG)" : "")); } if (!(info[0] == TAP_WIN_MIN_MAJOR && info[1] >= TAP_WIN_MIN_MINOR)) - dbg_tap_info ("ERROR: This version of " PACKAGE_NAME " requires a TAP-Windows driver that is at least version %d.%d \ + dbg_tap_info("ERROR: This version of " PACKAGE_NAME " requires a TAP-Windows driver that is at least version %d.%d \ -- If you recently upgraded your " PACKAGE_NAME " distribution, \ a reboot is probably required at this point to get Windows to see the new driver.\n", - TAP_WIN_MIN_MAJOR, - TAP_WIN_MIN_MINOR); + TAP_WIN_MIN_MAJOR, + TAP_WIN_MIN_MINOR); /* usage of numeric constants is ugly, but this is really tied to * *this* version of the driver */ - if ( tt->ipv6 && tt->type == DEV_TYPE_TUN && info[0] == 9 && info[1] < 8) - { + if (tt->ipv6 && tt->type == DEV_TYPE_TUN && info[0] == 9 && info[1] < 8) { dbg_tap_info("WARNING: Tap-Win32 driver version %d.%d does not support IPv6 in TUN mode. IPv6 will be disabled. \ - Upgrade to Tap-Win32 9.8 (2.2-beta3 release or later) or use TAP mode to get IPv6\n", (int) info[0], (int) info[1] ); + Upgrade to Tap-Win32 9.8 (2.2-beta3 release or later) or use TAP mode to get IPv6\n", (int) info[0], (int) info[1]); tt->ipv6 = 0; } /* tap driver 9.8 (2.2.0 and 2.2.1 release) is buggy */ - if ( tt->type == DEV_TYPE_TUN && info[0] == 9 && info[1] == 8) - { - dbg_tap_info("ERROR: Tap-Win32 driver version %d.%d is buggy regarding small IPv4 packets in TUN mode. Upgrade to Tap-Win32 9.9 (2.2.2 release or later) or use TAP mode\n", (int) info[0], (int) info[1] ); + if (tt->type == DEV_TYPE_TUN && info[0] == 9 && info[1] == 8) { + dbg_tap_info("ERROR: Tap-Win32 driver version %d.%d is buggy regarding small IPv4 packets in TUN mode. Upgrade to Tap-Win32 9.9 (2.2.2 release or later) or use TAP mode\n", (int) info[0], (int) info[1]); } } /* get driver MTU */ { ULONG mtu; - if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_MTU, - &mtu, sizeof (mtu), - &mtu, sizeof (mtu), &len, NULL)) - { + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_MTU, + &mtu, sizeof (mtu), + &mtu, sizeof (mtu), &len, NULL)) { tt->post_open_mtu = (int) mtu; dbg_tap_info("TAP-Windows MTU=%d\n", (int) mtu); } @@ -613,10 +579,9 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc uint8_t mac[6] = { 0, 0, 0, 0, 0, 0 }; - if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_MAC, - mac, sizeof (mac), - mac, sizeof (mac), &len, NULL)) - { + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_MAC, + mac, sizeof (mac), + mac, sizeof (mac), &len, NULL)) { dbg_tap_info("TAP-Windows MAC=[%x,%x,%x,%x,%x,%x]\n", mac[0], mac[1], mac[2], mac[2], mac[4], mac[5]); memcpy(tt->mac, mac, sizeof(mac)); @@ -625,22 +590,19 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc /* set point-to-point mode if TUN device */ - if (tt->type == DEV_TYPE_TUN) - { + if (tt->type == DEV_TYPE_TUN) { dbg_tap_info("TUN type not supported for now...\n"); return -1; - } - else if (tt->type == DEV_TYPE_TAP) - { /* TAP DEVICE */ + } else if (tt->type == DEV_TYPE_TAP) { /* TAP DEVICE */ dbg_tap_info("TODO: Set Point-to-point through DeviceIoControl\n"); } /* set driver media status to 'connected' */ { ULONG status = TRUE; - if (!DeviceIoControl (tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS, - &status, sizeof (status), - &status, sizeof (status), &len, NULL)) + if (!DeviceIoControl(tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS, + &status, sizeof (status), + &status, sizeof (status), &len, NULL)) dbg_tap_info("WARNING: The TAP-Windows driver rejected a TAP_WIN_IOCTL_SET_MEDIA_STATUS DeviceIoControl call."); } @@ -661,14 +623,12 @@ int open_tun (const char *dev, const char *dev_type, const char *dev_node, struc int tap_win_getinfo (const struct tuntap *tt, char *buf, int bufsize) { - if (tt && tt->hand != NULL && buf != NULL) - { + if (tt && tt->hand != NULL && buf != NULL) { DWORD len; - if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_INFO, - buf, bufsize, - buf, bufsize, - &len, NULL)) - { + if (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_INFO, + buf, bufsize, + buf, bufsize, + &len, NULL)) { return 0; } } @@ -678,14 +638,12 @@ int tap_win_getinfo (const struct tuntap *tt, char *buf, int bufsize) void tun_show_debug (struct tuntap *tt, char *buf, int bufsize) { - if (tt && tt->hand != NULL && buf != NULL) - { + if (tt && tt->hand != NULL && buf != NULL) { DWORD len; - while (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, - buf, bufsize, - buf, bufsize, - &len, NULL)) - { + while (DeviceIoControl(tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE, + buf, bufsize, + buf, bufsize, + &len, NULL)) { dbg_tap_info("TAP-Windows: %s\n", buf); } } @@ -695,8 +653,7 @@ void tun_show_debug (struct tuntap *tt, char *buf, int bufsize) /* returns the state */ int tun_read_queue (struct tuntap *tt, uint8_t *buffer, int maxsize) { - if (tt->reads.iostate == IOSTATE_INITIAL) - { + if (tt->reads.iostate == IOSTATE_INITIAL) { DWORD len = 1500; BOOL status; int err; @@ -710,7 +667,7 @@ int tun_read_queue (struct tuntap *tt, uint8_t *buffer, int maxsize) len = tt->reads.buf_len; /* the overlapped read will signal this event on I/O completion */ - if (!ResetEvent (tt->reads.overlapped.hEvent)) + if (!ResetEvent(tt->reads.overlapped.hEvent)) dbg_tap("ResetEvent failed\n"); status = ReadFile( @@ -721,37 +678,31 @@ int tun_read_queue (struct tuntap *tt, uint8_t *buffer, int maxsize) &tt->reads.overlapped ); - if (status) /* operation completed immediately? */ - { + if (status) { /* operation completed immediately? */ /* since we got an immediate return, we must signal the event object ourselves */ /* ASSERT (SetEvent (tt->reads.overlapped.hEvent)); */ - if (!SetEvent (tt->reads.overlapped.hEvent)) + if (!SetEvent(tt->reads.overlapped.hEvent)) dbg_tap("SetEvent failed\n"); tt->reads.iostate = IOSTATE_IMMEDIATE_RETURN; tt->reads.status = 0; - dbg_tap_win32 ("WIN32 I/O: TAP Read immediate return [%d,%d]\n", - (int) len, - (int) tt->reads.size); - } - else - { - err = GetLastError (); - if (err == ERROR_IO_PENDING) /* operation queued? */ - { + dbg_tap_win32("WIN32 I/O: TAP Read immediate return [%d,%d]\n", + (int) len, + (int) tt->reads.size); + } else { + err = GetLastError(); + if (err == ERROR_IO_PENDING) { /* operation queued? */ tt->reads.iostate = IOSTATE_QUEUED; tt->reads.status = err; - dbg_tap_win32 ("WIN32 I/O: TAP Read queued [%d]\n", (int) len); - } - else /* error occurred */ - { - if (!SetEvent (tt->reads.overlapped.hEvent)) + dbg_tap_win32("WIN32 I/O: TAP Read queued [%d]\n", (int) len); + } else { /* error occurred */ + if (!SetEvent(tt->reads.overlapped.hEvent)) dbg_tap("SetEvent failed\n"); tt->reads.iostate = IOSTATE_IMMEDIATE_RETURN; tt->reads.status = err; - dbg_tap ("WIN32 I/O: TAP Read error [%d] : %d\n", (int) len, (int) err); + dbg_tap("WIN32 I/O: TAP Read error [%d] : %d\n", (int) len, (int) err); } } } @@ -765,8 +716,7 @@ int tun_finalize(HANDLE h, struct overlapped_io *io, uint8_t **buf, uint32_t *bu int ret = -1; BOOL status; - switch (io->iostate) - { + switch (io->iostate) { case IOSTATE_QUEUED: status = GetOverlappedResult( h, @@ -774,11 +724,9 @@ int tun_finalize(HANDLE h, struct overlapped_io *io, uint8_t **buf, uint32_t *bu &io->size, 0u ); - if (status) - { + if (status) { /* successful return for a queued operation */ - if (buf) - { + if (buf) { *buf = io->buf; *buf_len = io->buf_len; } @@ -786,22 +734,19 @@ int tun_finalize(HANDLE h, struct overlapped_io *io, uint8_t **buf, uint32_t *bu ret = io->size; io->iostate = IOSTATE_INITIAL; - if (!ResetEvent (io->overlapped.hEvent)) + if (!ResetEvent(io->overlapped.hEvent)) dbg_tap("ResetEvent in finalize failed!\n"); - dbg_tap_win32 ("WIN32 I/O: TAP Completion success: QUEUED! [%d]\n", ret); - } - else - { + dbg_tap_win32("WIN32 I/O: TAP Completion success: QUEUED! [%d]\n", ret); + } else { /* error during a queued operation */ /* error, or just not completed? */ ret = 0; - if (GetLastError() != ERROR_IO_INCOMPLETE) - { + if (GetLastError() != ERROR_IO_INCOMPLETE) { /* if no error (i.e. just not finished yet), then DON'T execute this code */ io->iostate = IOSTATE_INITIAL; - if (!ResetEvent (io->overlapped.hEvent)) + if (!ResetEvent(io->overlapped.hEvent)) dbg_tap("ResetEvent in finalize failed!\n"); dbg_tap("WIN32 I/O: TAP Completion error\n"); @@ -813,36 +758,33 @@ int tun_finalize(HANDLE h, struct overlapped_io *io, uint8_t **buf, uint32_t *bu case IOSTATE_IMMEDIATE_RETURN: io->iostate = IOSTATE_INITIAL; - if (!ResetEvent (io->overlapped.hEvent)) + if (!ResetEvent(io->overlapped.hEvent)) dbg_tap("ResetEvent in finalize failed!\n"); - if (io->status) - { + if (io->status) { /* error return for a non-queued operation */ - SetLastError (io->status); + SetLastError(io->status); ret = -1; dbg_tap("WIN32 I/O: TAP Completion non-queued error\n"); - } - else - { + } else { /* successful return for a non-queued operation */ if (buf) *buf = io->buf; ret = io->size; - dbg_tap_win32 ("WIN32 I/O: TAP Completion non-queued success [%d]\n", ret); + dbg_tap_win32("WIN32 I/O: TAP Completion non-queued success [%d]\n", ret); } break; case IOSTATE_INITIAL: /* were we called without proper queueing? */ - SetLastError (ERROR_INVALID_FUNCTION); + SetLastError(ERROR_INVALID_FUNCTION); ret = -1; - dbg_tap ("WIN32 I/O: TAP Completion BAD STATE\n"); + dbg_tap("WIN32 I/O: TAP Completion BAD STATE\n"); break; default: - dbg_tap ("Some weird case happened..\n"); + dbg_tap("Some weird case happened..\n"); } if (buf) @@ -856,8 +798,7 @@ int tun_finalize(HANDLE h, struct overlapped_io *io, uint8_t **buf, uint32_t *bu /* returns the amount of bytes written */ int tun_write_queue (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) { - if (tt->writes.iostate == IOSTATE_INITIAL) - { + if (tt->writes.iostate == IOSTATE_INITIAL) { BOOL status; int err; @@ -867,7 +808,7 @@ int tun_write_queue (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) memcpy(tt->writes.buf, buf, buf_len); /* the overlapped write will signal this event on I/O completion */ - if (!ResetEvent (tt->writes.overlapped.hEvent)) + if (!ResetEvent(tt->writes.overlapped.hEvent)) dbg_tap("ResetEvent in write_queue failed!\n"); status = WriteFile( @@ -878,38 +819,32 @@ int tun_write_queue (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) &tt->writes.overlapped ); - if (status) /* operation completed immediately? */ - { + if (status) { /* operation completed immediately? */ tt->writes.iostate = IOSTATE_IMMEDIATE_RETURN; /* since we got an immediate return, we must signal the event object ourselves */ - if (!SetEvent (tt->writes.overlapped.hEvent)) + if (!SetEvent(tt->writes.overlapped.hEvent)) dbg_tap("SetEvent in write_queue failed!\n"); tt->writes.status = 0; - dbg_tap_win32 ("WIN32 I/O: TAP Write immediate return [%d,%d]\n", - (int)(tt->writes.buf_len), - (int)tt->writes.size); - } - else - { - err = GetLastError (); - if (err == ERROR_IO_PENDING) /* operation queued? */ - { + dbg_tap_win32("WIN32 I/O: TAP Write immediate return [%d,%d]\n", + (int)(tt->writes.buf_len), + (int)tt->writes.size); + } else { + err = GetLastError(); + if (err == ERROR_IO_PENDING) { /* operation queued? */ tt->writes.iostate = IOSTATE_QUEUED; tt->writes.status = err; dbg_tap_win32("WIN32 I/O: TAP Write queued [%d]\n", - (tt->writes.buf_len)); - } - else /* error occurred */ - { - if (!SetEvent (tt->writes.overlapped.hEvent)) + (tt->writes.buf_len)); + } else { /* error occurred */ + if (!SetEvent(tt->writes.overlapped.hEvent)) dbg_tap("SetEvent in write_queue failed!\n"); tt->writes.iostate = IOSTATE_IMMEDIATE_RETURN; tt->writes.status = err; - dbg_tap ("WIN32 I/O: TAP Write error [%d] : %d\n", (int) &tt->writes.buf_len, (int) err); + dbg_tap("WIN32 I/O: TAP Write error [%d] : %d\n", (int) &tt->writes.buf_len, (int) err); } } } @@ -927,27 +862,23 @@ static int tun_write_win32 (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) { int err = 0; int status = 0; - if (overlapped_io_active (&tt->writes)) - { - status = tun_finalize (tt->hand, &tt->writes, NULL, 0); - if (status == 0) - { + if (overlapped_io_active(&tt->writes)) { + status = tun_finalize(tt->hand, &tt->writes, NULL, 0); + if (status == 0) { /* busy, just wait, do not schedule a new write */ return 0; } if (status < 0) - err = GetLastError (); + err = GetLastError(); } /* the overlapped IO is done, now we can schedule a new write */ - tun_write_queue (tt, buf, buf_len); - if (status < 0) - { - SetLastError (err); + tun_write_queue(tt, buf, buf_len); + if (status < 0) { + SetLastError(err); return status; - } - else + } else return buf_len; } @@ -960,42 +891,34 @@ static int tun_read_win32 (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) /* First, finish possible pending IOs */ - if (overlapped_io_active (&tt->reads)) - { - status = tun_finalize (tt->hand, &tt->reads, &buf, &buf_len); - if (status == 0) - { + if (overlapped_io_active(&tt->reads)) { + status = tun_finalize(tt->hand, &tt->reads, &buf, &buf_len); + if (status == 0) { /* busy, just wait, do not schedule a new read */ return 0; } - if (status < 0) - { - dbg_tap ("tun_finalize status < 0: %d\n", status); - err = GetLastError (); + if (status < 0) { + dbg_tap("tun_finalize status < 0: %d\n", status); + err = GetLastError(); } - if (status > 0) - { + if (status > 0) { return buf_len; } } /* If no pending IOs, schedule a new read */ /* queue, or immediate return */ - if (IOSTATE_IMMEDIATE_RETURN == tun_read_queue(tt, buf, buf_len)) - { + if (IOSTATE_IMMEDIATE_RETURN == tun_read_queue(tt, buf, buf_len)) { return tt->reads.size; } /* If the pending IOs gave an error, report it */ - if (status < 0) - { - SetLastError (err); + if (status < 0) { + SetLastError(err); return status; - } - else - { + } else { /* no errors, but the newly scheduled read is now pending */ return 0; } @@ -1004,12 +927,12 @@ static int tun_read_win32 (struct tuntap *tt, uint8_t *buf, uint32_t buf_len) static int read_tun_buffered(struct tuntap *tt, uint8_t *buf, uint32_t buf_len) { - return tun_read_win32 (tt, buf, buf_len); + return tun_read_win32(tt, buf, buf_len); } static int write_tun_buffered(struct tuntap *tt, uint8_t *buf, uint32_t buf_len) { - return tun_write_win32 (tt, buf, buf_len); + return tun_write_win32(tt, buf, buf_len); } @@ -1021,7 +944,7 @@ static int pico_tap_send(struct pico_device *dev, void *buf, int len) /* Increase the statistic count */ tap->statistics_frames_out++; - bytes_sent = write_tun_buffered (tap->tt, buf, len); + bytes_sent = write_tun_buffered(tap->tt, buf, len); dbg_tap("TX> sent %d bytes\n", bytes_sent); /* Discard the frame content silently. */ @@ -1033,17 +956,14 @@ uint8_t recv_buffer[1500]; static int pico_tap_poll(struct pico_device *dev, int loop_score) { struct pico_device_tap *tap = (struct pico_device_tap *) dev; - while (loop_score) - { + while (loop_score) { int bytes_read = read_tun_buffered(tap->tt, recv_buffer, 1500); loop_score--; - if (bytes_read > 0) - { + if (bytes_read > 0) { dbg_tap("RX< recvd: %d bytes\n", bytes_read); pico_stack_recv(dev, recv_buffer, bytes_read); /* break; */ - } - else + } else break; } return loop_score; @@ -1055,12 +975,12 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score) void overlapped_io_init (struct overlapped_io *o, int event_state) { - CLEAR (*o); + CLEAR(*o); /* manual reset event, initially set according to event_state */ - o->overlapped.hEvent = CreateEvent (NULL, TRUE, event_state, NULL); + o->overlapped.hEvent = CreateEvent(NULL, TRUE, event_state, NULL); if (o->overlapped.hEvent == NULL) - dbg_tap ("Error: overlapped_io_init: CreateEvent failed\n"); + dbg_tap("Error: overlapped_io_init: CreateEvent failed\n"); /* allocate buffer for overlapped I/O */ o->buf_init = PICO_ZALLOC(1500); /* XXX: MTU */ @@ -1074,8 +994,8 @@ void overlapped_io_init (struct overlapped_io *o, int event_state) void init_tun_post (struct tuntap *tt) { dbg_tap("TUN post init (for overlapped io)\n"); - overlapped_io_init (&tt->reads, FALSE); - overlapped_io_init (&tt->writes, TRUE); + overlapped_io_init(&tt->reads, FALSE); + overlapped_io_init(&tt->writes, TRUE); tt->rw_handle.read = tt->reads.overlapped.hEvent; tt->rw_handle.write = tt->writes.overlapped.hEvent; } @@ -1102,8 +1022,7 @@ struct pico_device *pico_tap_create(struct pico_stack *S, char *name, uint8_t *m show_tap_win_adapters(); tt->type = DEV_TYPE_TAP; - if (open_tun(NULL, NULL, "tap0", tt)) - { + if (open_tun(NULL, NULL, "tap0", tt)) { dbg_tap("Failed to create TAP device!\n"); PICO_FREE(tt); PICO_FREE(tap); @@ -1112,7 +1031,7 @@ struct pico_device *pico_tap_create(struct pico_stack *S, char *name, uint8_t *m tap->tt = tt; - if( 0 != pico_device_init(S, (struct pico_device *)tap, name, mac)) { + if (0 != pico_device_init(S, (struct pico_device *)tap, name, mac)) { return NULL; } diff --git a/modules/pico_dev_tap_windows.h b/modules/pico_dev_tap_windows.h index 23b9bd06..87e6e12b 100644 --- a/modules/pico_dev_tap_windows.h +++ b/modules/pico_dev_tap_windows.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_tap_windows_private.h b/modules/pico_dev_tap_windows_private.h index ee306cc0..b62cde32 100644 --- a/modules/pico_dev_tap_windows_private.h +++ b/modules/pico_dev_tap_windows_private.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_tun.c b/modules/pico_dev_tun.c index ed85d7db..ed0533ab 100644 --- a/modules/pico_dev_tun.c +++ b/modules/pico_dev_tun.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -56,7 +56,7 @@ static int pico_tun_poll(struct pico_device *dev, int loop_score) int len; pfd.fd = tun->fd; pfd.events = POLLIN; - do { + do { if (poll(&pfd, 1, 0) <= 0) return loop_score; @@ -65,7 +65,7 @@ static int pico_tun_poll(struct pico_device *dev, int loop_score) loop_score--; pico_stack_recv(dev, buf, (uint32_t)len); } - } while(loop_score > 0); + } while (loop_score > 0); return 0; } @@ -74,7 +74,7 @@ static int pico_tun_poll(struct pico_device *dev, int loop_score) void pico_tun_destroy(struct pico_device *dev) { struct pico_device_tun *tun = (struct pico_device_tun *) dev; - if(tun->fd > 0) + if (tun->fd > 0) close(tun->fd); } @@ -83,15 +83,15 @@ static int tun_open(char *name) { struct ifreq ifr; int tun_fd; - if((tun_fd = open("/dev/net/tun", O_RDWR)) < 0) { - return(-1); + if ((tun_fd = open("/dev/net/tun", O_RDWR)) < 0) { + return -1; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_name, name, IFNAMSIZ-1); - if(ioctl(tun_fd, TUNSETIFF, &ifr) < 0) { - return(-1); + strncpy(ifr.ifr_name, name, IFNAMSIZ - 1); + if (ioctl(tun_fd, TUNSETIFF, &ifr) < 0) { + return -1; } return tun_fd; @@ -106,7 +106,7 @@ struct pico_device *pico_tun_create(struct pico_stack *S, char *name) if (!tun) return NULL; - if( 0 != pico_device_init(S, (struct pico_device *)tun, name, NULL)) { + if (0 != pico_device_init(S, (struct pico_device *)tun, name, NULL)) { dbg("Tun init failed.\n"); pico_tun_destroy((struct pico_device *)tun); return NULL; diff --git a/modules/pico_dev_tun.h b/modules/pico_dev_tun.h index baad8495..7cb64196 100644 --- a/modules/pico_dev_tun.h +++ b/modules/pico_dev_tun.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dev_vde.c b/modules/pico_dev_vde.c index 810dbacf..df55a053 100644 --- a/modules/pico_dev_vde.c +++ b/modules/pico_dev_vde.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -70,22 +70,22 @@ static int pico_vde_send(struct pico_device *dev, void *buf, int len) void pico_vde_dsr(void *arg) { - int len; - struct pico_device_vde *vde = (struct pico_device_vde *)arg; - unsigned char buf[VDE_MTU]; - len = vde_recv(vde->conn, buf, VDE_MTU, 0); - if (len > 0) { - pico_stack_recv(&vde->dev, buf, (uint32_t)len); - } + int len; + struct pico_device_vde *vde = (struct pico_device_vde *)arg; + unsigned char buf[VDE_MTU]; + len = vde_recv(vde->conn, buf, VDE_MTU, 0); + if (len > 0) { + pico_stack_recv(&vde->dev, buf, (uint32_t)len); + } } int pico_vde_WFI(struct pico_device *dev, int timeout_ms) { - struct pollfd pfd; - struct pico_device_vde *vde = (struct pico_device_vde *) dev; - pfd.fd = vde_datafd(vde->conn); - pfd.events = POLLIN; - return poll(&pfd, 1, timeout_ms); + struct pollfd pfd; + struct pico_device_vde *vde = (struct pico_device_vde *) dev; + pfd.fd = vde_datafd(vde->conn); + pfd.events = POLLIN; + return poll(&pfd, 1, timeout_ms); } #endif @@ -98,7 +98,7 @@ static int pico_vde_poll(struct pico_device *dev, int loop_score) int len; pfd.fd = vde_datafd(vde->conn); pfd.events = POLLIN; - do { + do { if (poll(&pfd, 1, 0) <= 0) return loop_score; @@ -110,7 +110,7 @@ static int pico_vde_poll(struct pico_device *dev, int loop_score) pico_stack_recv(dev, buf, (uint32_t)len); } } - } while(loop_score > 0); + } while (loop_score > 0); return 0; } @@ -153,8 +153,8 @@ struct pico_device *MOCKABLE pico_vde_create(struct pico_stack *S, char *sock, c return NULL; } - if( 0 != pico_device_init(S, (struct pico_device *)vde, name, mac)) { - dbg ("Vde init failed.\n"); + if (0 != pico_device_init(S, (struct pico_device *)vde, name, mac)) { + dbg("Vde init failed.\n"); pico_vde_destroy((struct pico_device *)vde); return NULL; } diff --git a/modules/pico_dev_vde.h b/modules/pico_dev_vde.h index 9f9ced7d..95a64915 100644 --- a/modules/pico_dev_vde.h +++ b/modules/pico_dev_vde.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dhcp_client.c b/modules/pico_dhcp_client.c index ae584cf3..c4ff339b 100644 --- a/modules/pico_dhcp_client.c +++ b/modules/pico_dhcp_client.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Kristof Roelants, Frederik Van Slycken, Maxime Vincent - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -160,8 +160,8 @@ static struct pico_dhcp_client_cookie *pico_dhcp_client_add_cookie(uint32_t xid, if (pico_tree_insert(&dev->stack->DHCPCookies, dhcpc)) { - PICO_FREE(dhcpc); - return NULL; + PICO_FREE(dhcpc); + return NULL; } return dhcpc; @@ -237,8 +237,7 @@ static struct dhcp_client_timer *pico_dhcp_timer_add(struct pico_stack *S, uint8 static int dhcp_get_timer_event(struct pico_dhcp_client_cookie *dhcpc, unsigned int type) { - const int events[PICO_DHCPC_TIMER_ARRAY_SIZE] = - { + const int events[PICO_DHCPC_TIMER_ARRAY_SIZE] = { PICO_DHCP_EVENT_RETRANSMIT, PICO_DHCP_EVENT_RETRANSMIT, PICO_DHCP_EVENT_RETRANSMIT, @@ -318,8 +317,7 @@ static void pico_dhcp_client_stop_timers(struct pico_dhcp_client_cookie *dhcpc) { int i; dhcpc->retry = 0; - for (i = 0; i < PICO_DHCPC_TIMER_ARRAY_SIZE; i++) - { + for (i = 0; i < PICO_DHCPC_TIMER_ARRAY_SIZE; i++) { if (dhcpc->timer[i]) { /* Do not cancel timer, but rather set it's state to be freed when it expires */ dhcpc->timer[i]->state = DHCP_CLIENT_TIMER_STOPPED; @@ -490,8 +488,7 @@ int MOCKABLE pico_dhcp_initiate_negotiation(struct pico_device *dev, void (*cb)( static void pico_dhcp_client_recv_params(struct pico_dhcp_client_cookie *dhcpc, struct pico_dhcp_opt *opt) { do { - switch (opt->code) - { + switch (opt->code) { case PICO_DHCP_OPT_PAD: break; @@ -618,7 +615,7 @@ static void pico_dhcp_client_update_link(struct pico_dhcp_client_cookie *dhcpc) pico_ipv4_link_del(dhcpc->stack, dhcpc->dev, address); l = pico_ipv4_link_by_dev(dhcpc->stack, dhcpc->dev); - while(l) { + while (l) { pico_ipv4_link_del(dhcpc->stack, dhcpc->dev, l->address); l = pico_ipv4_link_by_dev_next(dhcpc->stack, dhcpc->dev, l); } @@ -751,8 +748,7 @@ static int reset(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) if (dhcpc->cb) dhcpc->cb(dhcpc, PICO_DHCP_RESET); - if (dhcpc->state < DHCP_CLIENT_STATE_BOUND) - { + if (dhcpc->state < DHCP_CLIENT_STATE_BOUND) { /* pico_dhcp_client_timer_stop(dhcpc, PICO_DHCPC_TIMER_INIT); */ } @@ -766,8 +762,7 @@ static int reset(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) static int retransmit(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) { (void) buf; - switch (dhcpc->state) - { + switch (dhcpc->state) { case DHCP_CLIENT_STATE_INIT: pico_dhcp_client_msg(dhcpc, PICO_DHCP_MSG_DISCOVER); if (pico_dhcp_client_start_init_timer(dhcpc) < 0) @@ -810,8 +805,8 @@ struct dhcp_action_entry { int (*timer_retransmit)(struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf); }; -static struct dhcp_action_entry dhcp_fsm[] = -{ /* event |offer |ack |nak |T1 |T2 |lease |retransmit */ +static struct dhcp_action_entry dhcp_fsm[] = { +/* event |offer |ack |nak |T1 |T2 |lease |retransmit */ /* state init-reboot */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, /* state rebooting */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, /* state init */ { recv_offer, NULL, NULL, NULL, NULL, NULL, retransmit }, @@ -831,8 +826,7 @@ static struct dhcp_action_entry dhcp_fsm[] = static void pico_dhcp_state_machine(uint8_t event, struct pico_dhcp_client_cookie *dhcpc, uint8_t *buf) { - switch (event) - { + switch (event) { case PICO_DHCP_MSG_OFFER: dhcpc_dbg("DHCP client: received OFFER\n"); if (dhcp_fsm[dhcpc->state].offer) @@ -924,8 +918,7 @@ static int8_t pico_dhcp_client_msg(struct pico_dhcp_client_cookie *dhcpc, uint8_ /* Set again default route for the bcast request */ pico_ipv4_route_set_bcast_link(dhcpc->stack, pico_ipv4_link_by_dev(dhcpc->stack, dhcpc->dev)); - switch (msg_type) - { + switch (msg_type) { case PICO_DHCP_MSG_DISCOVER: dhcpc_dbg("DHCP client: sent DHCPDISCOVER\n"); optlen = PICO_DHCP_OPTLEN_MSGTYPE + PICO_DHCP_OPTLEN_MAXMSGSIZE + PICO_DHCP_OPTLEN_PARAMLIST + PICO_DHCP_OPTLEN_END; @@ -966,8 +959,7 @@ static int8_t pico_dhcp_client_msg(struct pico_dhcp_client_cookie *dhcpc, uint8_ offset = (uint16_t)(offset + pico_dhcp_opt_paramlist(DHCP_OPT(hdr, offset))); offset = (uint16_t)(offset + pico_dhcp_opt_end(DHCP_OPT(hdr, offset))); - switch (dhcpc->state) - { + switch (dhcpc->state) { case DHCP_CLIENT_STATE_BOUND: destination.addr = dhcpc->server_id.addr; hdr->ciaddr = dhcpc->address.addr; diff --git a/modules/pico_dhcp_client.h b/modules/pico_dhcp_client.h index edee9d96..bd937a5e 100644 --- a/modules/pico_dhcp_client.h +++ b/modules/pico_dhcp_client.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dhcp_common.c b/modules/pico_dhcp_common.c index 9f92962c..65e3fc96 100644 --- a/modules/pico_dhcp_common.c +++ b/modules/pico_dhcp_common.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Frederik Van Slycken - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -54,8 +54,7 @@ uint8_t pico_dhcp_are_options_valid(void *ptr, int32_t len) uint8_t optlen = 0, *p = ptr; while (len > 0) { - switch (*p) - { + switch (*p) { case PICO_DHCP_OPT_END: return 1; diff --git a/modules/pico_dhcp_common.h b/modules/pico_dhcp_common.h index 8e52db44..d6edaa25 100644 --- a/modules/pico_dhcp_common.h +++ b/modules/pico_dhcp_common.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dhcp_server.c b/modules/pico_dhcp_server.c index da89f8e2..911e6378 100644 --- a/modules/pico_dhcp_server.c +++ b/modules/pico_dhcp_server.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Frederik Van Slycken, Kristof Roelants - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -138,9 +138,9 @@ static inline struct pico_dhcp_server_setting *dhcps_try_open_socket(struct pico } if (pico_tree_insert(&dhcps->dev->stack->DHCPSettings, dhcps)) { - dhcps_dbg("DHCP server ERROR: could not insert settings in tree\n"); - PICO_FREE(dhcps); - return NULL; + dhcps_dbg("DHCP server ERROR: could not insert settings in tree\n"); + PICO_FREE(dhcps); + return NULL; } return dhcps; @@ -249,10 +249,10 @@ static struct pico_dhcp_server_negotiation *pico_dhcp_server_add_negotiation(str dhcp_negotiation_set_ciaddr(dhcpn); if (pico_tree_insert(&dev->stack->DHCPNegotiations, dhcpn)) { - dhcps_dbg("DHCP server ERROR: could not insert negotiations in tree\n"); - PICO_FREE(dhcpn); - return NULL; - } + dhcps_dbg("DHCP server ERROR: could not insert negotiations in tree\n"); + PICO_FREE(dhcpn); + return NULL; + } return dhcpn; } diff --git a/modules/pico_dhcp_server.h b/modules/pico_dhcp_server.h index 78d558d6..1e7e6468 100644 --- a/modules/pico_dhcp_server.h +++ b/modules/pico_dhcp_server.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dns_client.c b/modules/pico_dns_client.c index ee258095..dcd7b02f 100644 --- a/modules/pico_dns_client.c +++ b/modules/pico_dns_client.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Kristof Roelants - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -119,8 +119,7 @@ static struct pico_dns_ns *pico_dns_client_add_ns(struct pico_stack *S, struct p }; /* 0.0.0.0 */ /* Do not add 0.0.0.0 addresses, which some DHCP servers might reply */ - if (!pico_ipv4_compare(ns_addr, &zero)) - { + if (!pico_ipv4_compare(ns_addr, &zero)) { pico_err = PICO_ERR_EINVAL; return NULL; } @@ -347,8 +346,7 @@ static char *pico_dns_client_seek_suffix(char *suf, struct pico_dns_header *pre, while (i++ < short_be(pre->ancount)) { comp = short_from(suf); compression = short_be(comp); - switch (compression >> 14) - { + switch (compression >> 14) { case PICO_DNS_POINTER: while (compression >> 14 == PICO_DNS_POINTER) { dns_dbg("DNS: pointer\n"); @@ -424,7 +422,7 @@ static void pico_dns_client_retransmission(pico_time now, void *arg) struct pico_dns_client_retransmission_bookmark *b; IGNORE_PARAMETER(now); - if(!arg) + if (!arg) return; /* search for the dns query and free used space */ @@ -451,20 +449,19 @@ static void pico_dns_client_retransmission(pico_time now, void *arg) static int pico_dns_client_check_rdlength(uint16_t qtype, uint16_t rdlength) { - switch (qtype) - { - case PICO_DNS_TYPE_A: - if (rdlength != PICO_DNS_RR_A_RDLENGTH) - return -1; - break; + switch (qtype) { + case PICO_DNS_TYPE_A: + if (rdlength != PICO_DNS_RR_A_RDLENGTH) + return -1; + break; #ifdef PICO_SUPPORT_IPV6 - case PICO_DNS_TYPE_AAAA: - if (rdlength != PICO_DNS_RR_AAAA_RDLENGTH) - return -1; - break; + case PICO_DNS_TYPE_AAAA: + if (rdlength != PICO_DNS_RR_AAAA_RDLENGTH) + return -1; + break; #endif - default: - break; + default: + break; } return 0; @@ -481,8 +478,7 @@ static int pico_dns_client_user_callback(struct pico_dns_record_suffix *asuffix, return -1; } - switch (q->qtype) - { + switch (q->qtype) { case PICO_DNS_TYPE_A: ip = long_from(rdata); str = PICO_ZALLOC(PICO_DNS_IPV4_ADDR_LEN); @@ -604,7 +600,7 @@ static void pico_dns_client_callback(uint16_t ev, struct pico_socket *s) if (!q) return; - // FIX: what if the query is not a PTR query? + /* FIX: what if the query is not a PTR query? */ domain = (char *)header + sizeof(struct pico_dns_header); qsuffix = (struct pico_dns_question_suffix *)pico_dns_client_seek(domain); /* valid asuffix is determined dynamically later on */ @@ -639,7 +635,7 @@ static int pico_dns_create_message(struct pico_stack *S, struct pico_dns_header return -1; } - if(arpa == PICO_DNS_ARPA4) { + if (arpa == PICO_DNS_ARPA4) { strcpy(inaddr_arpa, ".in-addr.arpa"); strlen = pico_dns_strlen(url); } @@ -668,7 +664,7 @@ static int pico_dns_create_message(struct pico_stack *S, struct pico_dns_header domain = (char *) *header + sizeof(struct pico_dns_header); *qsuffix = (struct pico_dns_question_suffix *)(domain + *urlen); - if(arpa == PICO_DNS_ARPA4) { + if (arpa == PICO_DNS_ARPA4) { memcpy(domain + PICO_DNS_LABEL_INITIAL, url, strlen); pico_dns_mirror_addr(domain + PICO_DNS_LABEL_INITIAL); memcpy(domain + PICO_DNS_LABEL_INITIAL + strlen, inaddr_arpa, arpalen); @@ -698,9 +694,9 @@ static int pico_dns_client_addr_label_check_len(const char *url) label = url; p = label; - while(*p != (char) 0) { + while (*p != (char) 0) { count = 0; - while((*p != (char)0)) { + while ((*p != (char)0)) { if (*p == '.') { label = ++p; break; @@ -746,7 +742,7 @@ static int pico_dns_client_getaddr_init(struct pico_stack *S, const char *url, u if (pico_dns_client_getaddr_check(url, callback) < 0) return -1; - if(pico_dns_create_message(S, &header, &qsuffix, PICO_DNS_NO_ARPA, url, &lblen, &len) != 0) + if (pico_dns_create_message(S, &header, &qsuffix, PICO_DNS_NO_ARPA, url, &lblen, &len) != 0) return -1; #ifdef PICO_SUPPORT_IPV6 @@ -791,7 +787,7 @@ static int pico_dns_getname_univ(struct pico_stack *S, const char *ip, void (*ca return -1; } - if(pico_dns_create_message(S, &header, &qsuffix, arpa, ip, &lblen, &len) != 0) + if (pico_dns_create_message(S, &header, &qsuffix, arpa, ip, &lblen, &len) != 0) return -1; pico_dns_question_fill_suffix(qsuffix, PICO_DNS_TYPE_PTR, PICO_DNS_CLASS_IN); @@ -827,8 +823,7 @@ int pico_dns_client_nameserver(struct pico_stack *S, struct pico_ip4 *ns, uint8_ return -1; } - switch (flag) - { + switch (flag) { case PICO_DNS_NS_ADD: if (!pico_dns_client_add_ns(S, ns)) return -1; diff --git a/modules/pico_dns_client.h b/modules/pico_dns_client.h index 4c1da222..5918bc60 100644 --- a/modules/pico_dns_client.h +++ b/modules/pico_dns_client.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_dns_common.c b/modules/pico_dns_common.c index ab577990..2bdd13f5 100644 --- a/modules/pico_dns_common.c +++ b/modules/pico_dns_common.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Toon Stegen, Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -60,7 +60,7 @@ * @return 0 when the length is correct * ****************************************************************************/ int -pico_dns_check_namelen( uint16_t namelen ) +pico_dns_check_namelen(uint16_t namelen) { return ((namelen > 2u) && (namelen < PICO_DNS_NAMEBUF_SIZE)) ? (0) : (-1); } @@ -75,7 +75,7 @@ pico_dns_check_namelen( uint16_t namelen ) * like a trailing zero-byte * ****************************************************************************/ uint16_t -pico_dns_namelen_comp( char *name ) +pico_dns_namelen_comp(char *name) { uint16_t len = 0; char *label = NULL, *next = NULL; @@ -94,7 +94,7 @@ pico_dns_namelen_comp( char *name ) /* Calculate the length */ len = (uint16_t)(label - name); - if(*label != '\0') + if (*label != '\0') len++; return len; @@ -110,7 +110,7 @@ pico_dns_namelen_comp( char *name ) * @return Returns the decompressed name, NULL on failure. * ****************************************************************************/ char * -pico_dns_decompress_name( char *name, pico_dns_packet *packet ) +pico_dns_decompress_name(char *name, pico_dns_packet *packet) { char decompressed_name[PICO_DNS_NAMEBUF_SIZE] = { 0 @@ -124,12 +124,12 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet ) * Only one pointer is allowed in DNS compression, the pointer is always the last according to the RFC */ dns_name_foreach_label_safe(label, name, next, PICO_DNS_NAMEBUF_SIZE) { - uint8_t label_size = (uint8_t)(*label+1); + uint8_t label_size = (uint8_t)(*label + 1); if (decompressed_index + label_size >= PICO_DNS_NAMEBUF_SIZE) { return NULL; } memcpy(&decompressed_name[decompressed_index], label, label_size); - decompressed_index = (uint16_t)(decompressed_index+label_size); + decompressed_index = (uint16_t)(decompressed_index + label_size); } if (decompressed_index >= PICO_DNS_NAMEBUF_SIZE) { @@ -142,7 +142,7 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet ) ptr = (uint16_t)(ptr | (uint16_t) *(label + 1)); label = (char *)((uint8_t *)packet + ptr); - dns_name_foreach_label_safe(label, label, next, PICO_DNS_NAMEBUF_SIZE-decompressed_index) { + dns_name_foreach_label_safe(label, label, next, PICO_DNS_NAMEBUF_SIZE - decompressed_index) { uint8_t label_size = (uint8_t)(*label + 1); if (decompressed_index + label_size >= PICO_DNS_NAMEBUF_SIZE) { return NULL; @@ -161,7 +161,7 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet ) /* Provide storage for the name to return */ nslen = (uint16_t)(pico_dns_strlen(decompressed_name) + 1); - if(!(return_name = PICO_ZALLOC((size_t)nslen))) { + if (!(return_name = PICO_ZALLOC((size_t)nslen))) { pico_err = PICO_ERR_ENOMEM; return NULL; } @@ -183,9 +183,9 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet ) * @return Returns the length of the reverse name * ****************************************************************************/ static uint16_t -pico_dns_url_get_reverse_len( const char *url, - uint16_t *arpalen, - uint16_t proto ) +pico_dns_url_get_reverse_len(const char *url, + uint16_t *arpalen, + uint16_t proto) { uint16_t slen = (uint16_t)(pico_dns_strlen(url) + 2u); @@ -200,8 +200,7 @@ pico_dns_url_get_reverse_len( const char *url, *arpalen = (uint16_t) pico_dns_strlen(PICO_ARPA_IPV4_SUFFIX); #ifdef PICO_SUPPORT_IPV6 - else if (proto == PICO_PROTO_IPV6) - { + else if (proto == PICO_PROTO_IPV6) { *arpalen = (uint16_t) pico_dns_strlen(PICO_ARPA_IPV6_SUFFIX); slen = STRLEN_PTR_IP6 + 2u; } @@ -219,7 +218,7 @@ pico_dns_url_get_reverse_len( const char *url, * @return Returns a pointer to a string-buffer with the reverse DNS name. * ****************************************************************************/ static char * -pico_dns_url_to_reverse_qname( const char *url, uint8_t proto ) +pico_dns_url_to_reverse_qname(const char *url, uint8_t proto) { char *reverse_qname = NULL; uint16_t arpalen = 0; @@ -270,7 +269,7 @@ pico_dns_url_to_reverse_qname( const char *url, uint8_t proto ) * @return Returns a pointer to a string-buffer with the URL name on success. * ****************************************************************************/ char * -pico_dns_qname_to_url( const char *qname ) +pico_dns_qname_to_url(const char *qname) { char *url = NULL; char temp[PICO_DNS_NAMEBUF_SIZE] = { @@ -307,7 +306,7 @@ pico_dns_qname_to_url( const char *qname ) * @return Returns a pointer to a string-buffer with the DNS name on success. * ****************************************************************************/ char * -pico_dns_url_to_qname( const char *url ) +pico_dns_url_to_qname(const char *url) { char *qname = NULL; uint16_t namelen = (uint16_t)(pico_dns_strlen(url) + 2u); @@ -335,7 +334,7 @@ pico_dns_url_to_qname( const char *url ) * @return Length of string-buffer in an uint16_t * ****************************************************************************/ uint16_t -pico_dns_strlen( const char *url ) +pico_dns_strlen(const char *url) { if (!url) return 0; @@ -354,7 +353,7 @@ pico_dns_strlen( const char *url ) * @param maxlen Maximum length of buffer so it doesn't cause a buffer overflow * @return 0 on success, something else on failure. * ****************************************************************************/ -int pico_dns_name_to_dns_notation( char *url, uint16_t maxlen ) +int pico_dns_name_to_dns_notation(char *url, uint16_t maxlen) { char c = '\0'; char *lbl = url, *i = url; @@ -388,7 +387,7 @@ int pico_dns_name_to_dns_notation( char *url, uint16_t maxlen ) * @param maxlen Maximum length of buffer so it doesn't cause a buffer overflow * @return 0 on success, something else on failure. * ****************************************************************************/ -int pico_dns_notation_to_name( char *ptr, uint16_t maxlen ) +int pico_dns_notation_to_name(char *ptr, uint16_t maxlen) { char *label = NULL, *next = NULL; @@ -407,7 +406,7 @@ int pico_dns_notation_to_name( char *ptr, uint16_t maxlen ) * @return Length of the first label of DNS name in URL-format * ****************************************************************************/ uint16_t -pico_dns_first_label_length( const char *url ) +pico_dns_first_label_length(const char *url) { const char *i = NULL; uint16_t len = 0; @@ -432,7 +431,7 @@ pico_dns_first_label_length( const char *url ) * @return 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_mirror_addr( char *ip ) +pico_dns_mirror_addr(char *ip) { uint32_t addr = 0; @@ -457,7 +456,7 @@ pico_dns_mirror_addr( char *ip ) * @return The ASCII value of the Most Significant Nibble of the byte * ****************************************************************************/ static inline char -dns_ptr_ip6_nibble_lo( uint8_t byte ) +dns_ptr_ip6_nibble_lo(uint8_t byte) { uint8_t nibble = byte & 0x0f; if (nibble < 10) @@ -473,7 +472,7 @@ dns_ptr_ip6_nibble_lo( uint8_t byte ) * @return The ASCII value of the Least Significant Nibble of the byte * ****************************************************************************/ static inline char -dns_ptr_ip6_nibble_hi( uint8_t byte ) +dns_ptr_ip6_nibble_hi(uint8_t byte) { uint8_t nibble = (byte & 0xf0u) >> 4u; if (nibble < 10u) @@ -490,7 +489,7 @@ dns_ptr_ip6_nibble_hi( uint8_t byte ) * @param dst Destination to store IPv6-address in nibble-format * ****************************************************************************/ void -pico_dns_ipv6_set_ptr( const char *ip, char *dst ) +pico_dns_ipv6_set_ptr(const char *ip, char *dst) { int i = 0, j = 0; struct pico_ip6 ip6; @@ -517,7 +516,7 @@ pico_dns_ipv6_set_ptr( const char *ip, char *dst ) * @param question Void-point to DNS Question * @return Size in bytes of single DNS Question if it was copied flat. * ****************************************************************************/ -static uint16_t pico_dns_question_size( void *question ) +static uint16_t pico_dns_question_size(void *question) { uint16_t size = 0; struct pico_dns_question *q = (struct pico_dns_question *)question; @@ -537,7 +536,7 @@ static uint16_t pico_dns_question_size( void *question ) * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_question_delete( void **question ) +pico_dns_question_delete(void **question) { struct pico_dns_question **q = (struct pico_dns_question **)question; @@ -571,9 +570,9 @@ pico_dns_question_delete( void **question ) * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_question_fill_suffix( struct pico_dns_question_suffix *suf, - uint16_t qtype, - uint16_t qclass ) +pico_dns_question_fill_suffix(struct pico_dns_question_suffix *suf, + uint16_t qtype, + uint16_t qclass) { if (!suf) return -1; @@ -601,11 +600,11 @@ pico_dns_question_fill_suffix( struct pico_dns_question_suffix *suf, * @return The eventual length of the generated name, 0 on failure. * ****************************************************************************/ static uint16_t -pico_dns_question_fill_name( char **qname, - const char *url, - uint16_t qtype, - uint8_t proto, - uint8_t reverse ) +pico_dns_question_fill_name(char **qname, + const char *url, + uint16_t qtype, + uint8_t proto, + uint8_t reverse) { uint16_t slen = 0; @@ -640,12 +639,12 @@ pico_dns_question_fill_name( char **qname, * failure. * ****************************************************************************/ struct pico_dns_question * -pico_dns_question_create( const char *url, - uint16_t *len, - uint8_t proto, - uint16_t qtype, - uint16_t qclass, - uint8_t reverse ) +pico_dns_question_create(const char *url, + uint16_t *len, + uint8_t proto, + uint16_t qtype, + uint16_t qclass, + uint8_t reverse) { struct pico_dns_question *question = NULL; uint16_t slen = 0; @@ -691,8 +690,8 @@ pico_dns_question_create( const char *url, * @return Pointer to original name of the DNS question before decompressing. * ****************************************************************************/ char * -pico_dns_question_decompress( struct pico_dns_question *question, - pico_dns_packet *packet ) +pico_dns_question_decompress(struct pico_dns_question *question, + pico_dns_packet *packet) { char *qname_original = question->qname; @@ -716,8 +715,8 @@ pico_dns_question_decompress( struct pico_dns_question *question, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_record_copy_flat( struct pico_dns_record *record, - uint8_t **destination ) +pico_dns_record_copy_flat(struct pico_dns_record *record, + uint8_t **destination) { char *dest_rname = NULL; /* rname destination location */ struct pico_dns_record_suffix *dest_rsuffix = NULL; /* rsuffix destin. */ @@ -762,7 +761,7 @@ pico_dns_record_copy_flat( struct pico_dns_record *record, * @return Size of single DNS record if it was copied flat. * ****************************************************************************/ static uint16_t -pico_dns_record_size( void *record ) +pico_dns_record_size(void *record) { uint16_t size = 0; struct pico_dns_record *rr = (struct pico_dns_record *)record; @@ -784,7 +783,7 @@ pico_dns_record_size( void *record ) * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_record_delete( void **record ) +pico_dns_record_delete(void **record) { struct pico_dns_record **rr = (struct pico_dns_record **)record; @@ -813,7 +812,7 @@ pico_dns_record_delete( void **record ) * @return Pointer to copy of DNS record. * ****************************************************************************/ struct pico_dns_record * -pico_dns_record_copy( struct pico_dns_record *record ) +pico_dns_record_copy(struct pico_dns_record *record) { struct pico_dns_record *copy = NULL; @@ -867,11 +866,11 @@ pico_dns_record_copy( struct pico_dns_record *record ) * @return Returns 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_record_fill_suffix( struct pico_dns_record_suffix **suf, - uint16_t rtype, - uint16_t rclass, - uint32_t rttl, - uint16_t rdlength ) +pico_dns_record_fill_suffix(struct pico_dns_record_suffix **suf, + uint16_t rtype, + uint16_t rclass, + uint32_t rttl, + uint16_t rdlength) { /* Try to provide space for the rsuffix */ if (!(*suf = PICO_ZALLOC(sizeof(struct pico_dns_record_suffix)))) { @@ -903,10 +902,10 @@ pico_dns_record_fill_suffix( struct pico_dns_record_suffix **suf, * Can differ from datalen-param because of URL to DNS Name conversion. * ****************************************************************************/ static uint16_t -pico_dns_record_fill_rdata( uint8_t **rdata, - void *_rdata, - uint16_t datalen, - uint16_t rtype ) +pico_dns_record_fill_rdata(uint8_t **rdata, + void *_rdata, + uint16_t datalen, + uint16_t rtype) { uint16_t _datalen = 0; @@ -953,14 +952,14 @@ pico_dns_record_fill_rdata( uint8_t **rdata, * @return Returns pointer to the created DNS Resource Record * ****************************************************************************/ struct pico_dns_record * -pico_dns_record_create( struct pico_stack *S, - const char *url, - void *_rdata, - uint16_t datalen, - uint16_t *len, - uint16_t rtype, - uint16_t rclass, - uint32_t rttl ) +pico_dns_record_create(struct pico_stack *S, + const char *url, + void *_rdata, + uint16_t datalen, + uint16_t *len, + uint16_t rtype, + uint16_t rclass, + uint32_t rttl) { struct pico_dns_record *record = NULL; uint16_t slen = (uint16_t)(pico_dns_strlen(url) + 2u); @@ -1010,8 +1009,8 @@ pico_dns_record_create( struct pico_stack *S, * @return Pointer to original name of the DNS record before decompressing. * ****************************************************************************/ char * -pico_dns_record_decompress( struct pico_dns_record *record, - pico_dns_packet *packet ) +pico_dns_record_decompress(struct pico_dns_record *record, + pico_dns_packet *packet) { char *rname_original = record->rname; @@ -1045,8 +1044,8 @@ static int pico_tolower(int c) * @return 0 when the buffers are equal, returns difference when they're not. * ****************************************************************************/ int -pico_dns_rdata_cmp( uint8_t *a, uint8_t *b, - uint16_t rdlength_a, uint16_t rdlength_b, uint8_t caseinsensitive ) +pico_dns_rdata_cmp(uint8_t *a, uint8_t *b, + uint16_t rdlength_a, uint16_t rdlength_b, uint8_t caseinsensitive) { uint16_t i = 0; uint16_t slen = 0; @@ -1067,13 +1066,13 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b, slen = rdlength_b; /* loop over slen */ - if(caseinsensitive) { + if (caseinsensitive) { for (i = 0; i < slen; i++) { if ((dif = pico_tolower((int)a[i]) - pico_tolower((int)b[i]))) { return dif; } } - }else{ + } else { for (i = 0; i < slen; i++) { if ((dif = (int)a[i] - (int)b[i])) { return dif; @@ -1093,8 +1092,8 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b, * @return 0 when questions are equal, returns difference when they're not. * ****************************************************************************/ int -pico_dns_question_cmp( void *qa, - void *qb ) +pico_dns_question_cmp(void *qa, + void *qb) { int dif = 0; uint16_t at = 0, bt = 0; @@ -1128,8 +1127,8 @@ pico_dns_question_cmp( void *qa, * they're not. * ****************************************************************************/ int -pico_dns_record_cmp_name_type( void *ra, - void *rb ) +pico_dns_record_cmp_name_type(void *ra, + void *rb) { int dif; uint16_t at = 0, bt = 0; @@ -1162,8 +1161,8 @@ pico_dns_record_cmp_name_type( void *ra, * @return 0 when records are equal, returns difference when they're not * ****************************************************************************/ int -pico_dns_record_cmp( void *ra, - void *rb ) +pico_dns_record_cmp(void *ra, + void *rb) { int dif = 0; struct pico_dns_record *a = (struct pico_dns_record *)ra; @@ -1196,7 +1195,7 @@ pico_dns_record_cmp( void *ra, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_tree_destroy( struct pico_tree *tree, int (*node_delete)(void **)) +pico_tree_destroy(struct pico_tree *tree, int (*node_delete)(void **)) { struct pico_tree_node *node = NULL, *next = NULL; void *item = NULL; @@ -1231,9 +1230,9 @@ pico_tree_destroy( struct pico_tree *tree, int (*node_delete)(void **)) * @return Amount of items in the tree. * ****************************************************************************/ static uint16_t -pico_tree_size( struct pico_tree *tree, - uint16_t *size, - uint16_t (*node_size)(void *)) +pico_tree_size(struct pico_tree *tree, + uint16_t *size, + uint16_t (*node_size)(void *)) { struct pico_tree_node *node = NULL; void *node_item = NULL; @@ -1263,7 +1262,7 @@ pico_tree_size( struct pico_tree *tree, * @return Amount of items in the tree. * ****************************************************************************/ uint16_t -pico_tree_count( struct pico_tree *tree ) +pico_tree_count(struct pico_tree *tree) { struct pico_tree_node *node = NULL; uint16_t count = 0; @@ -1284,8 +1283,8 @@ pico_tree_count( struct pico_tree *tree ) * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_qtree_del_name( struct pico_tree *qtree, - const char *name ) +pico_dns_qtree_del_name(struct pico_tree *qtree, + const char *name) { struct pico_tree_node *node = NULL, *next = NULL; struct pico_dns_question *question = NULL; @@ -1316,8 +1315,8 @@ pico_dns_qtree_del_name( struct pico_tree *qtree, * @return 1 when the name is present in the qtree, 0 when it's not. * ****************************************************************************/ int -pico_dns_qtree_find_name( struct pico_tree *qtree, - const char *name ) +pico_dns_qtree_find_name(struct pico_tree *qtree, + const char *name) { struct pico_tree_node *node = NULL; struct pico_dns_question *question = NULL; @@ -1352,15 +1351,15 @@ pico_dns_qtree_find_name( struct pico_tree *qtree, * @param arcount Amount of additional records added to the packet * ****************************************************************************/ void -pico_dns_fill_packet_header( struct pico_dns_header *hdr, - uint16_t qdcount, - uint16_t ancount, - uint16_t nscount, - uint16_t arcount ) +pico_dns_fill_packet_header(struct pico_dns_header *hdr, + uint16_t qdcount, + uint16_t ancount, + uint16_t nscount, + uint16_t arcount) { /* ID should be filled by caller */ - if(qdcount > 0) { /* Questions present? Make it a query */ + if (qdcount > 0) { /* Questions present? Make it a query */ hdr->qr = PICO_DNS_QR_QUERY; hdr->aa = PICO_DNS_AA_NO_AUTHORITY; } else { /* No questions present? Make it an answer*/ @@ -1390,8 +1389,8 @@ pico_dns_fill_packet_header( struct pico_dns_header *hdr, * @return 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_fill_packet_rr_section( struct pico_tree *rtree, - uint8_t **dest ) +pico_dns_fill_packet_rr_section(struct pico_tree *rtree, + uint8_t **dest) { struct pico_tree_node *node = NULL; struct pico_dns_record *record = NULL; @@ -1418,11 +1417,11 @@ pico_dns_fill_packet_rr_section( struct pico_tree *rtree, * @return 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_fill_packet_rr_sections( pico_dns_packet *packet, - struct pico_tree *qtree, - struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree ) +pico_dns_fill_packet_rr_sections(pico_dns_packet *packet, + struct pico_tree *qtree, + struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree) { int anret = 0, nsret = 0, arret = 0; uint16_t temp = 0; @@ -1463,8 +1462,8 @@ pico_dns_fill_packet_rr_sections( pico_dns_packet *packet, * @return 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_fill_packet_question_section( pico_dns_packet *packet, - struct pico_tree *qtree ) +pico_dns_fill_packet_question_section(pico_dns_packet *packet, + struct pico_tree *qtree) { struct pico_tree_node *node = NULL; struct pico_dns_question *question = NULL; @@ -1505,9 +1504,9 @@ pico_dns_fill_packet_question_section( pico_dns_packet *packet, * beginning of the data buffer and the name itself. * ****************************************************************************/ static uint8_t * -pico_dns_packet_compress_find_ptr( uint8_t *name, - uint8_t *data, - uint16_t len ) +pico_dns_packet_compress_find_ptr(uint8_t *name, + uint8_t *data, + uint16_t len) { uint8_t *iterator = NULL; @@ -1536,9 +1535,9 @@ pico_dns_packet_compress_find_ptr( uint8_t *name, * packet-buffer. * ****************************************************************************/ static int -pico_dns_packet_compress_name( uint8_t *name, - uint8_t *packet, - uint16_t *len) +pico_dns_packet_compress_name(uint8_t *name, + uint8_t *packet, + uint16_t *len) { uint8_t *lbl_iterator = NULL; /* To iterate over labels */ uint8_t *compression_ptr = NULL; /* PTR to somewhere else in the packet */ @@ -1603,9 +1602,9 @@ pico_dns_packet_compress_name( uint8_t *name, * Utility function compress a record section * ****************************************************************************/ static int -pico_dns_compress_record_sections( uint16_t qdcount, uint16_t count, - uint8_t *buf, uint8_t **iterator, - uint16_t *len ) +pico_dns_compress_record_sections(uint16_t qdcount, uint16_t count, + uint8_t *buf, uint8_t **iterator, + uint16_t *len) { struct pico_dns_record_suffix *rsuffix = NULL; uint8_t *_iterator = NULL; @@ -1640,7 +1639,7 @@ pico_dns_compress_record_sections( uint16_t qdcount, uint16_t count, * Applies DNS name compression to an entire DNS packet * ****************************************************************************/ static int -pico_dns_packet_compress( pico_dns_packet *packet, uint16_t *len ) +pico_dns_packet_compress(pico_dns_packet *packet, uint16_t *len) { uint8_t *packet_buf = NULL; uint8_t *iterator = NULL; @@ -1665,7 +1664,7 @@ pico_dns_packet_compress( pico_dns_packet *packet, uint16_t *len ) /* Start with the questions */ for (i = 0; i < qdcount; i++) { - if(i) { /* First question can't be compressed */ + if (i) { /* First question can't be compressed */ pico_dns_packet_compress_name(iterator, packet_buf, len); } @@ -1695,12 +1694,12 @@ pico_dns_packet_compress( pico_dns_packet *packet, uint16_t *len ) * @return Returns the total length that the DNS packet needs to be. * ****************************************************************************/ static uint16_t -pico_dns_packet_len( struct pico_tree *qtree, - struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint8_t *qdcount, uint8_t *ancount, - uint8_t *nscount, uint8_t *arcount ) +pico_dns_packet_len(struct pico_tree *qtree, + struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint8_t *qdcount, uint8_t *ancount, + uint8_t *nscount, uint8_t *arcount) { uint16_t len = (uint16_t) sizeof(pico_dns_packet); @@ -1731,11 +1730,11 @@ pico_dns_packet_len( struct pico_tree *qtree, * @return Pointer to created DNS packet * ****************************************************************************/ static pico_dns_packet * -pico_dns_packet_create( struct pico_tree *qtree, - struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint16_t *len ) +pico_dns_packet_create(struct pico_tree *qtree, + struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint16_t *len) { PICO_DNS_QTREE_DECLARE(_qtree); PICO_DNS_RTREE_DECLARE(_antree); @@ -1795,11 +1794,11 @@ pico_dns_packet_create( struct pico_tree *qtree, * @return Pointer to created DNS packet * ****************************************************************************/ pico_dns_packet * -pico_dns_query_create( struct pico_tree *qtree, - struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint16_t *len ) +pico_dns_query_create(struct pico_tree *qtree, + struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint16_t *len) { return pico_dns_packet_create(qtree, antree, nstree, artree, len); } @@ -1816,10 +1815,10 @@ pico_dns_query_create( struct pico_tree *qtree, * @return Pointer to created DNS packet. * ****************************************************************************/ pico_dns_packet * -pico_dns_answer_create( struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint16_t *len ) +pico_dns_answer_create(struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint16_t *len) { return pico_dns_packet_create(NULL, antree, nstree, artree, len); } diff --git a/modules/pico_dns_common.h b/modules/pico_dns_common.h index 6ef46ee5..62932761 100644 --- a/modules/pico_dns_common.h +++ b/modules/pico_dns_common.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -148,7 +148,7 @@ struct pico_dns_record * @return 0 when the length is correct * ****************************************************************************/ int -pico_dns_check_namelen( uint16_t namelen ); +pico_dns_check_namelen(uint16_t namelen); /* **************************************************************************** * Returns the length of a name in a DNS-packet as if DNS name compression @@ -162,7 +162,7 @@ pico_dns_check_namelen( uint16_t namelen ); * like a trailing zero-byte. * ****************************************************************************/ uint16_t -pico_dns_namelen_comp( char *name ); +pico_dns_namelen_comp(char *name); /* **************************************************************************** * Returns the uncompressed name in DNS name format when DNS name compression @@ -173,7 +173,7 @@ pico_dns_namelen_comp( char *name ); * @return Returns the decompressed name, NULL on failure. * ****************************************************************************/ char * -pico_dns_decompress_name( char *name, pico_dns_packet *packet ); +pico_dns_decompress_name(char *name, pico_dns_packet *packet); /* **************************************************************************** * Converts a DNS name in DNS name format to a name in URL format. Provides @@ -184,7 +184,7 @@ pico_dns_decompress_name( char *name, pico_dns_packet *packet ); * @return Returns a pointer to a string-buffer with the URL name on success. * ****************************************************************************/ char * -pico_dns_qname_to_url( const char *qname ); +pico_dns_qname_to_url(const char *qname); /* **************************************************************************** * Converts a DNS name in URL format to name in DNS name format. Provides @@ -195,14 +195,14 @@ pico_dns_qname_to_url( const char *qname ); * @return Returns a pointer to a string-buffer with the DNS name on success. * ****************************************************************************/ char * -pico_dns_url_to_qname( const char *url ); +pico_dns_url_to_qname(const char *url); /* **************************************************************************** * @param url String-buffer * @return Length of string-buffer in an uint16_t * ****************************************************************************/ uint16_t -pico_dns_strlen( const char *url ); +pico_dns_strlen(const char *url); /* **************************************************************************** * Replaces .'s in a DNS name in URL format by the label lengths. So it @@ -215,7 +215,7 @@ pico_dns_strlen( const char *url ); * @param maxlen Maximum length of buffer so it doesn't cause a buffer overflow * @return 0 on success, something else on failure. * ****************************************************************************/ -int pico_dns_name_to_dns_notation( char *url, uint16_t maxlen ); +int pico_dns_name_to_dns_notation(char *url, uint16_t maxlen); /* **************************************************************************** * Replaces the label lengths in a DNS-name by .'s. So it actually converts a @@ -226,7 +226,7 @@ int pico_dns_name_to_dns_notation( char *url, uint16_t maxlen ); * @param maxlen Maximum length of buffer so it doesn't cause a buffer overflow * @return 0 on success, something else on failure. * ****************************************************************************/ -int pico_dns_notation_to_name( char *ptr, uint16_t maxlen ); +int pico_dns_notation_to_name(char *ptr, uint16_t maxlen); /* **************************************************************************** * Determines the length of the first label of a DNS name in URL-format @@ -235,7 +235,7 @@ int pico_dns_notation_to_name( char *ptr, uint16_t maxlen ); * @return Length of the first label of DNS name in URL-format * ****************************************************************************/ uint16_t -pico_dns_first_label_length( const char *url ); +pico_dns_first_label_length(const char *url); /* **************************************************************************** * Mirrors a dotted IPv4-address string. @@ -245,7 +245,7 @@ pico_dns_first_label_length( const char *url ); * @return 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_mirror_addr( char *ip ); +pico_dns_mirror_addr(char *ip); /* **************************************************************************** * Convert an IPv6-address in string-format to a IPv6-address in nibble-format. @@ -255,7 +255,7 @@ pico_dns_mirror_addr( char *ip ); * @param dst Destination to store IPv6-address in nibble-format * ****************************************************************************/ void -pico_dns_ipv6_set_ptr( const char *ip, char *dst ); +pico_dns_ipv6_set_ptr(const char *ip, char *dst); /* MARK: QUESTION FUNCTIONS */ @@ -267,7 +267,7 @@ pico_dns_ipv6_set_ptr( const char *ip, char *dst ); * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_question_delete( void **question); +pico_dns_question_delete(void **question); /* **************************************************************************** * Fills in the DNS question suffix-fields with the correct values. @@ -282,9 +282,9 @@ pico_dns_question_delete( void **question); * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_question_fill_suffix( struct pico_dns_question_suffix *suf, - uint16_t qtype, - uint16_t qclass ); +pico_dns_question_fill_suffix(struct pico_dns_question_suffix *suf, + uint16_t qtype, + uint16_t qclass); /* **************************************************************************** * Creates a standalone DNS Question with a given name and type. @@ -302,12 +302,12 @@ pico_dns_question_fill_suffix( struct pico_dns_question_suffix *suf, * failure. * ****************************************************************************/ struct pico_dns_question * -pico_dns_question_create( const char *url, - uint16_t *len, - uint8_t proto, - uint16_t qtype, - uint16_t qclass, - uint8_t reverse ); +pico_dns_question_create(const char *url, + uint16_t *len, + uint8_t proto, + uint16_t qtype, + uint16_t qclass, + uint8_t reverse); /* **************************************************************************** * Decompresses the name of a single DNS question. @@ -317,8 +317,8 @@ pico_dns_question_create( const char *url, * @return Pointer to original name of the DNS question before decompressing. * ****************************************************************************/ char * -pico_dns_question_decompress( struct pico_dns_question *question, - pico_dns_packet *packet ); +pico_dns_question_decompress(struct pico_dns_question *question, + pico_dns_packet *packet); /* MARK: RESOURCE RECORD FUNCTIONS */ @@ -329,7 +329,7 @@ pico_dns_question_decompress( struct pico_dns_question *question, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_record_delete( void **record ); +pico_dns_record_delete(void **record); /* **************************************************************************** * Just makes a hardcopy from a single DNS Resource Record @@ -338,7 +338,7 @@ pico_dns_record_delete( void **record ); * @return Pointer to copy of DNS record. * ****************************************************************************/ struct pico_dns_record * -pico_dns_record_copy( struct pico_dns_record *record ); +pico_dns_record_copy(struct pico_dns_record *record); /* **************************************************************************** * Create a standalone DNS Resource Record with given name, type and data. @@ -360,13 +360,13 @@ pico_dns_record_copy( struct pico_dns_record *record ); * ****************************************************************************/ struct pico_dns_record * pico_dns_record_create(struct pico_stack *S, - const char *url, - void *_rdata, - uint16_t datalen, - uint16_t *len, - uint16_t rtype, - uint16_t rclass, - uint32_t rttl ); + const char *url, + void *_rdata, + uint16_t datalen, + uint16_t *len, + uint16_t rtype, + uint16_t rclass, + uint32_t rttl); /* **************************************************************************** * Decompresses the name of single DNS record. @@ -376,8 +376,8 @@ pico_dns_record_create(struct pico_stack *S, * @return Pointer to original name of the DNS record before decompressing. * ****************************************************************************/ char * -pico_dns_record_decompress( struct pico_dns_record *record, - pico_dns_packet *packet ); +pico_dns_record_decompress(struct pico_dns_record *record, + pico_dns_packet *packet); /* MARK: COMPARING */ @@ -394,8 +394,8 @@ pico_dns_record_decompress( struct pico_dns_record *record, * @return 0 when the buffers are equal, returns difference when they're not. * ****************************************************************************/ int -pico_dns_rdata_cmp( uint8_t *a, uint8_t *b, - uint16_t rdlength_a, uint16_t rdlength_b, uint8_t caseinsensitive ); +pico_dns_rdata_cmp(uint8_t *a, uint8_t *b, + uint16_t rdlength_a, uint16_t rdlength_b, uint8_t caseinsensitive); /* **************************************************************************** * Compares 2 DNS questions @@ -405,8 +405,8 @@ pico_dns_rdata_cmp( uint8_t *a, uint8_t *b, * @return 0 when questions are equal, returns difference when they're not. * ****************************************************************************/ int -pico_dns_question_cmp( void *qa, - void *qb ); +pico_dns_question_cmp(void *qa, + void *qb); /* **************************************************************************** * Compares 2 DNS records by type and name only @@ -417,8 +417,8 @@ pico_dns_question_cmp( void *qa, * they're not. * ****************************************************************************/ int -pico_dns_record_cmp_name_type( void *ra, - void *rb ); +pico_dns_record_cmp_name_type(void *ra, + void *rb); /* **************************************************************************** * Compares 2 DNS records by type, name AND rdata for a truly unique result @@ -428,8 +428,8 @@ pico_dns_record_cmp_name_type( void *ra, * @return 0 when records are equal, returns difference when they're not * ****************************************************************************/ int -pico_dns_record_cmp( void *ra, - void *rb ); +pico_dns_record_cmp(void *ra, + void *rb); /* MARK: PICO_TREE */ @@ -441,7 +441,7 @@ pico_dns_record_cmp( void *ra, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_tree_destroy( struct pico_tree *tree, int (*node_delete)(void **)); +pico_tree_destroy(struct pico_tree *tree, int (*node_delete)(void **)); /* **************************************************************************** * Determines the amount of nodes in a pico_tree @@ -450,7 +450,7 @@ pico_tree_destroy( struct pico_tree *tree, int (*node_delete)(void **)); * @return Amount of items in the tree. * ****************************************************************************/ uint16_t -pico_tree_count( struct pico_tree *tree ); +pico_tree_count(struct pico_tree *tree); /* **************************************************************************** * Definition of DNS question tree @@ -469,8 +469,8 @@ typedef struct pico_tree pico_dns_qtree; * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_qtree_del_name( struct pico_tree *qtree, - const char *name ); +pico_dns_qtree_del_name(struct pico_tree *qtree, + const char *name); /* **************************************************************************** * Checks whether a question with given name is in the tree or not. @@ -480,8 +480,8 @@ pico_dns_qtree_del_name( struct pico_tree *qtree, * @return 1 when the name is present in the qtree, 0 when it's not. * ****************************************************************************/ int -pico_dns_qtree_find_name( struct pico_tree *qtree, - const char *name ); +pico_dns_qtree_find_name(struct pico_tree *qtree, + const char *name); /* **************************************************************************** * Definition of DNS record tree @@ -505,11 +505,11 @@ typedef struct pico_tree pico_dns_rtree; * @param arcount Amount of additional records added to the packet * ****************************************************************************/ void -pico_dns_fill_packet_header( struct pico_dns_header *hdr, - uint16_t qdcount, - uint16_t ancount, - uint16_t nscount, - uint16_t arcount ); +pico_dns_fill_packet_header(struct pico_dns_header *hdr, + uint16_t qdcount, + uint16_t ancount, + uint16_t nscount, + uint16_t arcount); /* **************************************************************************** * Creates a DNS Query packet with given question and resource records to put @@ -524,11 +524,11 @@ pico_dns_fill_packet_header( struct pico_dns_header *hdr, * @return Pointer to created DNS packet * ****************************************************************************/ pico_dns_packet * -pico_dns_query_create( struct pico_tree *qtree, - struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint16_t *len ); +pico_dns_query_create(struct pico_tree *qtree, + struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint16_t *len); /* **************************************************************************** * Creates a DNS Answer packet with given resource records to put in the @@ -542,9 +542,9 @@ pico_dns_query_create( struct pico_tree *qtree, * @return Pointer to created DNS packet. * ****************************************************************************/ pico_dns_packet * -pico_dns_answer_create( struct pico_tree *antree, - struct pico_tree *nstree, - struct pico_tree *artree, - uint16_t *len ); +pico_dns_answer_create(struct pico_tree *antree, + struct pico_tree *nstree, + struct pico_tree *artree, + uint16_t *len); #endif /* _INCLUDE_PICO_DNS_COMMON */ diff --git a/modules/pico_dns_sd.c b/modules/pico_dns_sd.c index 2d149f49..d2222566 100644 --- a/modules/pico_dns_sd.c +++ b/modules/pico_dns_sd.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -38,9 +38,9 @@ /* --- PROTOTYPES --- */ key_value_pair_t * -pico_dns_sd_kv_vector_get( kv_vector *vector, uint16_t index ); +pico_dns_sd_kv_vector_get(kv_vector *vector, uint16_t index); int -pico_dns_sd_kv_vector_erase( kv_vector *vector ); +pico_dns_sd_kv_vector_erase(kv_vector *vector); /* ------------------- */ typedef PACKED_STRUCT_DEF pico_dns_srv_record_prefix @@ -59,7 +59,7 @@ typedef PACKED_STRUCT_DEF pico_dns_srv_record_prefix * converted to a string. * ****************************************************************************/ static uint16_t -pico_dns_sd_kv_vector_strlen( kv_vector *vector ) +pico_dns_sd_kv_vector_strlen(kv_vector *vector) { key_value_pair_t *iterator = NULL; uint16_t i = 0, len = 0; @@ -113,14 +113,14 @@ pico_dns_sd_kv_vector_strlen( kv_vector *vector ) * @return Pointer to newly created record on success, NULL on failure. * ****************************************************************************/ static struct pico_mdns_record * -pico_dns_sd_srv_record_create( struct pico_stack *S, - const char *url, - uint16_t priority, - uint16_t weight, - uint16_t port, - const char *target_url, - uint32_t ttl, - uint8_t flags ) +pico_dns_sd_srv_record_create(struct pico_stack *S, + const char *url, + uint16_t priority, + uint16_t weight, + uint16_t port, + const char *target_url, + uint32_t ttl, + uint8_t flags) { struct pico_mdns_record *record = NULL; pico_dns_srv_record *srv_data = NULL; @@ -175,11 +175,11 @@ pico_dns_sd_srv_record_create( struct pico_stack *S, * @return Pointer to newly created record on success, NULL on failure. * ****************************************************************************/ static struct pico_mdns_record * -pico_dns_sd_txt_record_create( struct pico_stack *S, - const char *url, - kv_vector key_value_pairs, - uint32_t ttl, - uint8_t flags ) +pico_dns_sd_txt_record_create(struct pico_stack *S, + const char *url, + kv_vector key_value_pairs, + uint32_t ttl, + uint8_t flags) { struct pico_mdns_record *record = NULL; key_value_pair_t *iterator = NULL; @@ -242,7 +242,7 @@ pico_dns_sd_txt_record_create( struct pico_stack *S, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ static int -pico_dns_sd_kv_delete( key_value_pair_t **kv_pair ) +pico_dns_sd_kv_delete(key_value_pair_t **kv_pair) { /* Check params */ if (!kv_pair || !(*kv_pair)) { @@ -272,7 +272,7 @@ pico_dns_sd_kv_delete( key_value_pair_t **kv_pair ) * @return Pointer to newly created KV-instance on success, NULL on failure. * ****************************************************************************/ static key_value_pair_t * -pico_dns_sd_kv_create( const char *key, const char *value ) +pico_dns_sd_kv_create(const char *key, const char *value) { key_value_pair_t *kv_pair = NULL; @@ -315,7 +315,7 @@ pico_dns_sd_kv_create( const char *key, const char *value ) * it's not. * ****************************************************************************/ static int -pico_dns_sd_check_type_format( const char *type ) +pico_dns_sd_check_type_format(const char *type) { uint16_t first_lbl = 0; int8_t subtype_present = 0; @@ -352,7 +352,7 @@ pico_dns_sd_check_type_format( const char *type ) * it's not. * ****************************************************************************/ static int -pico_dns_sd_check_instance_name_format( const char *name ) +pico_dns_sd_check_instance_name_format(const char *name) { /* First of all check if the total length is larger than 63 bytes */ if (pico_dns_strlen(name) > 63 || !pico_dns_strlen(name)) @@ -369,8 +369,8 @@ pico_dns_sd_check_instance_name_format( const char *name ) * @return Pointer to newly created SIN on success, NULL on failure. * ****************************************************************************/ static char * -pico_dns_sd_create_service_url( const char *name, - const char *type ) +pico_dns_sd_create_service_url(const char *name, + const char *type) { char *url = NULL; uint16_t len = 0, namelen = 0, typelen = 0; @@ -410,13 +410,11 @@ pico_dns_sd_create_service_url( const char *name, * This function actually does exactly the same as pico_mdns_init(); * ****************************************************************************/ int -pico_dns_sd_init( struct pico_stack *S, - const char *_hostname, - struct pico_ip4 address, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_dns_sd_init(struct pico_stack *S, + const char *_hostname, + struct pico_ip4 address, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { return pico_mdns_init(S, _hostname, address, callback, arg); } @@ -426,16 +424,14 @@ pico_dns_sd_init( struct pico_stack *S, * See pico_mdns.h for description. * ****************************************************************************/ int -pico_dns_sd_register_service( struct pico_stack *S, - const char *name, - const char *type, - uint16_t port, - kv_vector *txt_data, - uint16_t ttl, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg) +pico_dns_sd_register_service(struct pico_stack *S, + const char *name, + const char *type, + uint16_t port, + kv_vector *txt_data, + uint16_t ttl, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { PICO_MDNS_RTREE_DECLARE(rtree); struct pico_mdns_record *srv_record = NULL; @@ -481,8 +477,8 @@ pico_dns_sd_register_service( struct pico_stack *S, if (pico_tree_insert(&rtree, srv_record) == &LEAF) { PICO_MDNS_RTREE_DESTROY(&rtree); pico_mdns_record_delete((void **)&srv_record); - return -1; - } + return -1; + } if (pico_mdns_claim(S, rtree, callback, arg)) { PICO_MDNS_RTREE_DESTROY(&rtree); @@ -502,11 +498,9 @@ pico_dns_sd_register_service( struct pico_stack *S, * @return When the module successfully started browsing the servicetype. * ****************************************************************************/ int -pico_dns_sd_browse_service( const char *type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_dns_sd_browse_service(const char *type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { IGNORE_PARAMETER(type); IGNORE_PARAMETER(callback); @@ -524,7 +518,7 @@ pico_dns_sd_browse_service( const char *type, * failure. * ****************************************************************************/ int -pico_dns_sd_kv_vector_add( kv_vector *vector, char *key, char *value ) +pico_dns_sd_kv_vector_add(kv_vector *vector, char *key, char *value) { key_value_pair_t *kv_pair = NULL; key_value_pair_t **new_pairs = NULL; @@ -568,7 +562,7 @@ pico_dns_sd_kv_vector_add( kv_vector *vector, char *key, char *value ) * @return key_value_pair_t* on success, NULL on failure. * ****************************************************************************/ key_value_pair_t * -pico_dns_sd_kv_vector_get( kv_vector *vector, uint16_t index ) +pico_dns_sd_kv_vector_get(kv_vector *vector, uint16_t index) { /* Check params */ if (!vector) @@ -588,7 +582,7 @@ pico_dns_sd_kv_vector_get( kv_vector *vector, uint16_t index ) * @return 0 on success, something else on failure. * ****************************************************************************/ int -pico_dns_sd_kv_vector_erase( kv_vector *vector ) +pico_dns_sd_kv_vector_erase(kv_vector *vector) { uint16_t i = 0; diff --git a/modules/pico_dns_sd.h b/modules/pico_dns_sd.h index ecff8b3b..4355bcbd 100644 --- a/modules/pico_dns_sd.h +++ b/modules/pico_dns_sd.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -54,13 +54,11 @@ typedef struct * See pico_mdns.h for description. * ****************************************************************************/ int -pico_dns_sd_init( struct pico_stack *S, - const char *_hostname, - struct pico_ip4 address, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); +pico_dns_sd_init(struct pico_stack *S, + const char *_hostname, + struct pico_ip4 address, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* **************************************************************************** * Register a DNS-SD service via Multicast DNS on the local network. @@ -76,16 +74,14 @@ pico_dns_sd_init( struct pico_stack *S, * @return * ****************************************************************************/ int -pico_dns_sd_register_service( struct pico_stack *S, - const char *name, - const char *type, - uint16_t port, - kv_vector *txt_data, - uint16_t ttl, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg); +pico_dns_sd_register_service(struct pico_stack *S, + const char *name, + const char *type, + uint16_t port, + kv_vector *txt_data, + uint16_t ttl, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* **************************************************************************** * Does nothing for now. @@ -95,11 +91,9 @@ pico_dns_sd_register_service( struct pico_stack *S, * @return When the module successfully started browsing the servicetype. * ****************************************************************************/ int -pico_dns_sd_browse_service( const char *type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); +pico_dns_sd_browse_service(const char *type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* **************************************************************************** * Add a key-value pair the a key-value pair vector. @@ -111,7 +105,7 @@ pico_dns_sd_browse_service( const char *type, * failure. * ****************************************************************************/ int -pico_dns_sd_kv_vector_add( kv_vector *vector, char *key, char *value ); +pico_dns_sd_kv_vector_add(kv_vector *vector, char *key, char *value); #endif /* _INCLUDE_PICO_DNS_SD */ diff --git a/modules/pico_ethernet.c b/modules/pico_ethernet.c index 27aae8d4..d59ecb87 100644 --- a/modules/pico_ethernet.c +++ b/modules/pico_ethernet.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -223,8 +223,7 @@ static void pico_eth_check_bcast(struct pico_stack *S, struct pico_frame *f) int32_t pico_ethernet_receive(struct pico_stack *S, struct pico_frame *f) { struct pico_eth_hdr *hdr; - if (!f || !f->dev || !f->datalink_hdr) - { + if (!f || !f->dev || !f->datalink_hdr) { pico_frame_discard(f); return -1; } @@ -235,8 +234,7 @@ int32_t pico_ethernet_receive(struct pico_stack *S, struct pico_frame *f) #ifdef PICO_SUPPORT_IPV6 (memcmp(hdr->daddr, PICO_ETHADDR_MCAST6, PICO_SIZE_MCAST6) != 0) && #endif - (memcmp(hdr->daddr, PICO_ETHADDR_ALL, PICO_SIZE_ETH) != 0)) - { + (memcmp(hdr->daddr, PICO_ETHADDR_ALL, PICO_SIZE_ETH) != 0)) { pico_frame_discard(f); return -1; } @@ -289,8 +287,7 @@ static int pico_ethernet_ipv6_dst(struct pico_stack *S, struct pico_frame *f, st retval = 0; } else { struct pico_eth *neighbor = pico_ipv6_get_neighbor(S, f); - if (neighbor) - { + if (neighbor) { memcpy(dstmac, neighbor, PICO_SIZE_ETH); retval = 0; } @@ -314,7 +311,7 @@ static int32_t pico_ethsend_local(struct pico_stack *S, struct pico_frame *f, st return 0; /* Check own mac */ - if(!memcmp(hdr->daddr, hdr->saddr, PICO_SIZE_ETH)) { + if (!memcmp(hdr->daddr, hdr->saddr, PICO_SIZE_ETH)) { struct pico_frame *clone = pico_frame_copy(f); dbg("sending out packet destined for our own mac\n"); if (pico_ethernet_receive(S, clone) < 0) { @@ -348,7 +345,7 @@ static int32_t pico_ethsend_bcast(struct pico_stack *S, struct pico_frame *f) */ static int32_t pico_ethsend_dispatch(struct pico_frame *f) { - return (pico_sendto_dev(f) > 0); // Return 1 on success, ret > 0 + return (pico_sendto_dev(f) > 0); /* Return 1 on success, ret > 0 */ } /* Checks whether or not there's enough headroom allocated in the frame to @@ -378,28 +375,24 @@ int32_t MOCKABLE pico_ethernet_send(struct pico_stack *S, struct pico_frame *f) * destination address is taken from the ND tables */ if (IS_IPV6(f)) { - if (pico_ethernet_ipv6_dst(S, f, &dstmac) < 0) - { + if (pico_ethernet_ipv6_dst(S, f, &dstmac) < 0) { /* Enqueue copy of frame in IPv6 ND-module to retry later. Discard * frame, otherwise we have a duplicate in IPv6-ND */ - pico_ipv6_nd_postpone(S,f); + pico_ipv6_nd_postpone(S, f); pico_frame_discard(f); return (int32_t)len; } dstmac_valid = 1; proto = PICO_IDETH_IPV6; - } - else + } else #endif /* In case of broadcast (IPV4 only), dst mac is FF:FF:... */ - if (IS_BCAST(f) || destination_is_bcast(S, f)) - { + if (IS_BCAST(f) || destination_is_bcast(S, f)) { memcpy(&dstmac, PICO_ETHADDR_ALL, PICO_SIZE_ETH); dstmac_valid = 1; } - /* In case of multicast, dst mac is translated from the group address */ else if (destination_is_mcast(f)) { uint8_t pico_mcast_mac[6] = { @@ -431,8 +424,7 @@ int32_t MOCKABLE pico_ethernet_send(struct pico_stack *S, struct pico_frame *f) struct pico_eth_hdr *hdr; if (!eth_check_headroom(f)) { hdr = (struct pico_eth_hdr *) f->datalink_hdr; - if ((f->start > f->buffer) && ((f->start - f->buffer) >= PICO_SIZE_ETHHDR)) - { + if ((f->start > f->buffer) && ((f->start - f->buffer) >= PICO_SIZE_ETHHDR)) { f->start -= PICO_SIZE_ETHHDR; f->len += PICO_SIZE_ETHHDR; f->datalink_hdr = f->start; diff --git a/modules/pico_ethernet.h b/modules/pico_ethernet.h index 02e8eaac..f4334c72 100644 --- a/modules/pico_ethernet.h +++ b/modules/pico_ethernet.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_fragments.c b/modules/pico_fragments.c index 16049ff8..704ffa7e 100644 --- a/modules/pico_fragments.c +++ b/modules/pico_fragments.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Laurens Miers, Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -101,8 +101,7 @@ int pico_ipv6_frag_compare(void *ka, void *kb) static void pico_ipv6_fragments_complete(struct pico_stack *S, unsigned int len, uint8_t proto) { - if (pico_fragments_reassemble(&S->ipv6_fragments, len, proto, PICO_PROTO_IPV6) == 0) - { + if (pico_fragments_reassemble(&S->ipv6_fragments, len, proto, PICO_PROTO_IPV6) == 0) { pico_timer_cancel(S, S->ipv6_fragments_timer); S->ipv6_fragments_timer = 0; } @@ -154,8 +153,7 @@ int pico_ipv4_frag_compare(void *ka, void *kb) static void pico_ipv4_fragments_complete(struct pico_stack *S, unsigned int len, uint8_t proto) { - if (pico_fragments_reassemble(&S->ipv4_fragments, len, proto, PICO_PROTO_IPV4) == 0) - { + if (pico_fragments_reassemble(&S->ipv4_fragments, len, proto, PICO_PROTO_IPV4) == 0) { pico_timer_cancel(S, S->ipv4_fragments_timer); S->ipv4_fragments_timer = 0; } @@ -196,14 +194,12 @@ static void pico_fragments_complete(struct pico_stack *S, unsigned int bookmark, if (0) {} #if defined(PICO_SUPPORT_IPV4) && defined(PICO_SUPPORT_IPV4FRAG) - else if (net == PICO_PROTO_IPV4) - { + else if (net == PICO_PROTO_IPV4) { pico_ipv4_fragments_complete(S, bookmark, proto); } #endif #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG) - else if (net == PICO_PROTO_IPV6) - { + else if (net == PICO_PROTO_IPV6) { pico_ipv6_fragments_complete(S, bookmark, proto); } #endif @@ -213,13 +209,12 @@ static void pico_fragments_empty_tree(struct pico_tree *tree) { struct pico_tree_node *index, *tmp; - if (!tree) - { + if (!tree) { return; } pico_tree_foreach_safe(index, tree, tmp) { - struct pico_frame * old = index->keyValue; + struct pico_frame *old = index->keyValue; pico_tree_delete(tree, old); pico_frame_discard(old); } @@ -257,8 +252,7 @@ static void pico_frag_expire(pico_time now, void *arg) struct pico_frame *first = NULL; IGNORE_PARAMETER(now); - if (!tree) - { + if (!tree) { frag_dbg("Expired packet but no tree supplied!\n"); return; } @@ -279,37 +273,31 @@ static void pico_fragments_send_notify(struct pico_stack *S, struct pico_frame * { uint8_t net = 0; - if (!first) - { + if (!first) { return; } if (0) {} #if defined(PICO_SUPPORT_IPV4) && defined(PICO_SUPPORT_IPV4FRAG) - else if (IS_IPV4(first)) - { + else if (IS_IPV4(first)) { net = PICO_PROTO_IPV4; frag_dbg("Packet expired! ID:%hu\n", S->ipv4_cur_frag_id); } #endif #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG) - else if (IS_IPV6(first)) - { + else if (IS_IPV6(first)) { net = PICO_PROTO_IPV6; frag_dbg("Packet expired! ID:%hu\n", S->ipv6_cur_frag_id); } #endif - if (((pico_fragments_get_offset(first, net) == 0) && (pico_frame_dst_is_unicast(S, first)))) - { + if (((pico_fragments_get_offset(first, net) == 0) && (pico_frame_dst_is_unicast(S, first)))) { frag_dbg("sending notify\n"); pico_notify_frag_expired(first->dev->stack, first); - } - else - { + } else { frag_dbg("Not first packet or not unicast address, not sending notify"); } } @@ -323,24 +311,21 @@ static int pico_fragments_reassemble(struct pico_tree *tree, unsigned int len, u struct pico_frame *full = NULL; struct pico_frame *first = NULL; - if (!tree) - { + if (!tree) { frag_dbg("Cannot reassemble packet, no tree supplied!\n"); return -1; } first = pico_tree_first(tree); - if (!first) - { + if (!first) { frag_dbg("Cannot reassemble packet, empty tree supplied!\n"); return -2; } header_length = pico_fragments_get_header_length(net); - if (!header_length) - { + if (!header_length) { return -3; } @@ -370,14 +355,12 @@ static uint16_t pico_fragments_get_header_length(uint8_t net) if (0) {} #if defined(PICO_SUPPORT_IPV4) && defined(PICO_SUPPORT_IPV4FRAG) - else if (net == PICO_PROTO_IPV4) - { + else if (net == PICO_PROTO_IPV4) { return PICO_SIZE_IP4HDR; } #endif #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG) - else if (net == PICO_PROTO_IPV6) - { + else if (net == PICO_PROTO_IPV6) { return PICO_SIZE_IP6HDR; } #endif @@ -387,24 +370,21 @@ static uint16_t pico_fragments_get_header_length(uint8_t net) static int pico_fragments_get_more_flag(struct pico_frame *frame, uint8_t net) { - if (!frame) - { - frag_dbg("no frame given to determine more flag\n"); - return 0; + if (!frame) { + frag_dbg("no frame given to determine more flag\n"); + return 0; } if (0) {} #if defined(PICO_SUPPORT_IPV4) && defined(PICO_SUPPORT_IPV4FRAG) - else if (net == PICO_PROTO_IPV4) - { - return IP4_FRAG_MORE(frame->frag); + else if (net == PICO_PROTO_IPV4) { + return IP4_FRAG_MORE(frame->frag); } #endif #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG) - else if (net == PICO_PROTO_IPV6) - { - return IP6_FRAG_MORE(frame->frag); + else if (net == PICO_PROTO_IPV6) { + return IP6_FRAG_MORE(frame->frag); } #endif @@ -413,24 +393,21 @@ static int pico_fragments_get_more_flag(struct pico_frame *frame, uint8_t net) static uint32_t pico_fragments_get_offset(struct pico_frame *frame, uint8_t net) { - if (!frame) - { - frag_dbg("no frame given to determine offset\n"); - return 0; + if (!frame) { + frag_dbg("no frame given to determine offset\n"); + return 0; } if (0) {} #if defined(PICO_SUPPORT_IPV4) && defined(PICO_SUPPORT_IPV4FRAG) - else if (net == PICO_PROTO_IPV4) - { - return IP4_FRAG_OFF(frame->frag); + else if (net == PICO_PROTO_IPV4) { + return IP4_FRAG_OFF(frame->frag); } #endif #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6FRAG) - else if (net == PICO_PROTO_IPV6) - { - return IP6_FRAG_OFF(frame->frag); + else if (net == PICO_PROTO_IPV6) { + return IP6_FRAG_OFF(frame->frag); } #endif @@ -443,8 +420,7 @@ void pico_ipv6_process_frag(struct pico_ipv6_exthdr *frag, struct pico_frame *f, struct pico_frame *first = NULL; struct pico_stack *S; - if (!f || !frag) - { + if (!f || !frag) { frag_dbg("Bad arguments provided to pico_ipv6_process_frag\n"); return; } @@ -453,8 +429,7 @@ void pico_ipv6_process_frag(struct pico_ipv6_exthdr *frag, struct pico_frame *f, first = pico_tree_first(&S->ipv6_fragments); - if (first) - { + if (first) { if ((pico_ipv6_frag_match(f, first) == 0 && (IP6_FRAG_ID(frag) == S->ipv6_cur_frag_id))) { struct pico_frame *temp = NULL; @@ -471,9 +446,7 @@ void pico_ipv6_process_frag(struct pico_ipv6_exthdr *frag, struct pico_frame *f, return; } } - } - else - { + } else { struct pico_frame *temp = NULL; if (S->ipv6_cur_frag_id && (IP6_FRAG_ID(frag) == S->ipv6_cur_frag_id)) { @@ -514,8 +487,7 @@ void pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uin struct pico_frame *first = NULL; struct pico_stack *S; - if (!f || !hdr) - { + if (!f || !hdr) { frag_dbg("Bad arguments provided to pico_ipv4_process_frag\n"); return; } @@ -524,8 +496,7 @@ void pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uin first = pico_tree_first(&S->ipv4_fragments); - if (first) - { + if (first) { /* fragments from old packets still in tree, and new first fragment ? */ if ((IP4_FRAG_ID(hdr) != S->ipv4_cur_frag_id) && (IP4_FRAG_OFF(f->frag) == 0)) { pico_fragments_empty_tree(&S->ipv4_fragments); @@ -545,14 +516,12 @@ void pico_ipv4_process_frag(struct pico_ipv4_hdr *hdr, struct pico_frame *f, uin } if (pico_tree_insert(&S->ipv4_fragments, temp)) { - frag_dbg("FRAG: Could not insert picoframe in tree\n"); + frag_dbg("FRAG: Could not insert picoframe in tree\n"); pico_frame_discard(temp); return; - } + } } - } - else - { + } else { struct pico_frame *temp = NULL; if (S->ipv4_cur_frag_id && (IP4_FRAG_ID(hdr) == S->ipv4_cur_frag_id)) { diff --git a/modules/pico_fragments.h b/modules/pico_fragments.h index d4b967e6..0a5f9cb1 100644 --- a/modules/pico_fragments.h +++ b/modules/pico_fragments.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_hotplug_detection.c b/modules/pico_hotplug_detection.c index fe775f15..f98dd9c1 100644 --- a/modules/pico_hotplug_detection.c +++ b/modules/pico_hotplug_detection.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Frederik Van Slycken - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -87,8 +87,7 @@ static void hotplug_timer_cb(__attribute__((unused)) pico_time t, void *v) cb(hpdev->dev, event); pico_tree_delete(&hpdev->init_callbacks, cb); } - if (new_state != hpdev->prev_state) - { + if (new_state != hpdev->prev_state) { /* we don't know if one of the callbacks might deregister, so be safe */ pico_tree_foreach_safe(cb_node, &(hpdev->callbacks), cb_safe) { @@ -107,8 +106,7 @@ static void hotplug_timer_cb(__attribute__((unused)) pico_time t, void *v) static int ensure_hotplug_timer(struct pico_stack *S) { - if (S->hotplug_timer_id == 0) - { + if (S->hotplug_timer_id == 0) { S->hotplug_timer_id = pico_timer_add(S, PICO_HOTPLUG_INTERVAL, &hotplug_timer_cb, S); if (S->hotplug_timer_id == 0) { dbg("HOTPLUG: Failed to start timer\n"); @@ -134,11 +132,9 @@ int pico_hotplug_register(struct pico_device *dev, void (*cb)(struct pico_device } hotplug_dev = (struct pico_hotplug_device*)pico_tree_findKey(&dev->stack->Hotplug_device_tree, &search); - if (!hotplug_dev ) - { + if (!hotplug_dev) { hotplug_dev = PICO_ZALLOC(sizeof(struct pico_hotplug_device)); - if (!hotplug_dev) - { + if (!hotplug_dev) { pico_err = PICO_ERR_ENOMEM; return -1; } @@ -151,20 +147,20 @@ int pico_hotplug_register(struct pico_device *dev, void (*cb)(struct pico_device hotplug_dev->init_callbacks.compare = &callback_compare; if (pico_tree_insert(&dev->stack->Hotplug_device_tree, hotplug_dev)) { PICO_FREE(hotplug_dev); - return -1; - } + return -1; + } } if (pico_tree_insert(&(hotplug_dev->callbacks), cb) == &LEAF) { PICO_FREE(hotplug_dev); return -1; - } + } if (pico_tree_insert(&(hotplug_dev->init_callbacks), cb) == &LEAF) { pico_tree_delete(&(hotplug_dev->callbacks), cb); PICO_FREE(hotplug_dev); - return -1; - } + return -1; + } if (ensure_hotplug_timer(dev->stack) < 0) { pico_hotplug_deregister((struct pico_device *)hotplug_dev, cb); @@ -188,14 +184,12 @@ int pico_hotplug_deregister(struct pico_device *dev, void (*cb)(struct pico_devi pico_tree_delete(&hotplug_dev->callbacks, cb); pico_tree_delete(&hotplug_dev->init_callbacks, cb); - if (pico_tree_empty(&hotplug_dev->callbacks)) - { + if (pico_tree_empty(&hotplug_dev->callbacks)) { pico_tree_delete(&dev->stack->Hotplug_device_tree, hotplug_dev); PICO_FREE(hotplug_dev); } - if (pico_tree_empty(&dev->stack->Hotplug_device_tree) && dev->stack->hotplug_timer_id != 0) - { + if (pico_tree_empty(&dev->stack->Hotplug_device_tree) && dev->stack->hotplug_timer_id != 0) { pico_timer_cancel(dev->stack, dev->stack->hotplug_timer_id); dev->stack->hotplug_timer_id = 0; } diff --git a/modules/pico_hotplug_detection.h b/modules/pico_hotplug_detection.h index 2f2e3707..0e8ad1d2 100644 --- a/modules/pico_hotplug_detection.h +++ b/modules/pico_hotplug_detection.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_icmp4.c b/modules/pico_icmp4.c index bc58e26d..039f22ef 100644 --- a/modules/pico_icmp4.c +++ b/modules/pico_icmp4.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -60,7 +60,7 @@ static void ping_recv_reply(struct pico_stack *S, struct pico_frame *f); /* ICMP socket implementation */ /******************************/ static uint16_t I4Socket_id = 0; -struct pico_socket_icmp4 +struct pico_socket_icmp4 { struct pico_socket sock; uint16_t id; @@ -74,7 +74,7 @@ int icmp4_socket_cmp(void *ka, void *kb) return -1; if (a->id > b->id) return 1; - return (0); + return 0; } struct pico_socket *pico_socket_icmp4_open(struct pico_stack *S) @@ -108,7 +108,7 @@ int pico_socket_icmp4_bind(struct pico_socket *s, void *addr, uint16_t port) } int pico_socket_icmp4_recvfrom(struct pico_socket *s, void *buf, int len, void *orig, - uint16_t *remote_port) + uint16_t *remote_port) { struct pico_frame *f; f = pico_dequeue(&s->q_in); @@ -145,7 +145,7 @@ int pico_socket_icmp4_sendto_check(struct pico_socket *s, const void *buf, int l pico_err = PICO_ERR_EINVAL; return -1; } - if(hdr->code != 0) { + if (hdr->code != 0) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -380,7 +380,7 @@ static int8_t pico_icmp4_send_echo(struct pico_stack *S, struct pico_icmp4_ping_ if (!dev) return -1; - // prevent overflow + /* prevent overflow */ if (cookie->size > PICO_ICMP_MAXCOOKIE) return -1; @@ -409,7 +409,7 @@ static void ping_timeout(pico_time now, void *arg) struct pico_icmp4_ping_cookie *cookie = (struct pico_icmp4_ping_cookie *)arg; IGNORE_PARAMETER(now); - if(pico_tree_findKey(&cookie->stack->Pings, cookie)) { + if (pico_tree_findKey(&cookie->stack->Pings, cookie)) { if (cookie->err == PICO_PING_ERR_PENDING) { struct pico_icmp4_stats stats; stats.dst = cookie->dst; @@ -460,7 +460,7 @@ static void next_ping(pico_time now, void *arg) struct pico_icmp4_ping_cookie *newcookie, *cookie = (struct pico_icmp4_ping_cookie *)arg; IGNORE_PARAMETER(now); - if(pico_tree_findKey(&cookie->stack->Pings, cookie)) { + if (pico_tree_findKey(&cookie->stack->Pings, cookie)) { if (cookie->err == PICO_PING_ERR_ABORTED) return; @@ -475,8 +475,8 @@ static void next_ping(pico_time now, void *arg) if (pico_tree_insert(&cookie->stack->Pings, newcookie)) { dbg("ICMP4: Failed to insert new cookie in tree \n"); PICO_FREE(newcookie); - return; - } + return; + } if (send_ping(cookie->stack, newcookie)) { dbg("ICMP4: Failed to send ping\n"); @@ -491,7 +491,7 @@ static void ping_recv_reply(struct pico_stack *S, struct pico_frame *f) { struct pico_icmp4_ping_cookie test, *cookie; struct pico_icmp4_hdr *hdr = (struct pico_icmp4_hdr *) f->transport_hdr; - test.id = short_be(hdr->hun.ih_idseq.idseq_id ); + test.id = short_be(hdr->hun.ih_idseq.idseq_id); test.seq = short_be(hdr->hun.ih_idseq.idseq_seq); cookie = pico_tree_findKey(&S->Pings, &test); @@ -507,7 +507,7 @@ static void ping_recv_reply(struct pico_stack *S, struct pico_frame *f) stats.time = S->pico_tick - cookie->timestamp; stats.err = cookie->err; stats.ttl = ((struct pico_ipv4_hdr *)f->net_hdr)->ttl; - if(cookie->cb != NULL) + if (cookie->cb != NULL) cookie->cb(&stats); } else { dbg("Reply for seq=%d, not found.\n", test.seq); @@ -520,7 +520,7 @@ int pico_icmp4_ping(struct pico_stack *S, char *dst, int count, int interval, in struct pico_icmp4_ping_cookie *cookie; uint32_t dst_a; - if((dst == NULL) || (interval == 0) || (timeout == 0) || (count == 0)) { + if ((dst == NULL) || (interval == 0) || (timeout == 0) || (count == 0)) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -551,8 +551,8 @@ int pico_icmp4_ping(struct pico_stack *S, char *dst, int count, int interval, in if (pico_tree_insert(&S->Pings, cookie)) { dbg("ICMP4: Failed to insert cookie in tree \n"); PICO_FREE(cookie); - return -1; - } + return -1; + } if (send_ping(S, cookie)) { PICO_FREE(cookie); diff --git a/modules/pico_icmp4.h b/modules/pico_icmp4.h index 1c649a23..f01eb4b4 100644 --- a/modules/pico_icmp4.h +++ b/modules/pico_icmp4.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_icmp6.c b/modules/pico_icmp6.c index ad480ab5..40bbc727 100644 --- a/modules/pico_icmp6.c +++ b/modules/pico_icmp6.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Kristof Roelants, Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -155,18 +155,18 @@ static int pico_icmp6_send_echoreply_frag(struct pico_frame *echo) reply->transport_len = (uint16_t) (reply->transport_len - PICO_IPV6_EXTHDR_FRAG_SIZE); /* Populate fragmentation header */ { - struct pico_ipv6_exthdr * frag_header = (struct pico_ipv6_exthdr *) (reply->transport_hdr-PICO_IPV6_EXTHDR_FRAG_SIZE); - uint16_t octet_offset = short_be((uint16_t)(offset)); - if (offset + size < frag_payload) { - octet_offset = octet_offset | short_be(1); - } - frag_header->nxthdr = PICO_PROTO_ICMP6; - memcpy(frag_header->ext.frag.id, (uint8_t *)(&frag_id), 4); - memcpy(frag_header->ext.frag.om, (uint8_t *)(&octet_offset), 2); + struct pico_ipv6_exthdr *frag_header = (struct pico_ipv6_exthdr *) (reply->transport_hdr - PICO_IPV6_EXTHDR_FRAG_SIZE); + uint16_t octet_offset = short_be((uint16_t)(offset)); + if (offset + size < frag_payload) { + octet_offset = octet_offset | short_be(1); + } + frag_header->nxthdr = PICO_PROTO_ICMP6; + memcpy(frag_header->ext.frag.id, (uint8_t *)(&frag_id), 4); + memcpy(frag_header->ext.frag.om, (uint8_t *)(&octet_offset), 2); } /* Prepare for sending */ memcpy(reply->transport_hdr, echo->transport_hdr + offset, size); - if (offset == 0){ + if (offset == 0) { rhdr = (struct pico_icmp6_hdr *)reply->transport_hdr; rhdr->type = PICO_ICMP6_ECHO_REPLY; rhdr->code = 0; @@ -202,9 +202,9 @@ static int pico_icmp6_send_echoreply(struct pico_frame *echo) #endif if (echo->transport_len < mtu - header_overhead) { - return pico_icmp6_send_echoreply_not_frag(echo); + return pico_icmp6_send_echoreply_not_frag(echo); } else { - return pico_icmp6_send_echoreply_frag(echo); + return pico_icmp6_send_echoreply_frag(echo); } } @@ -224,8 +224,7 @@ static int pico_icmp6_process_in(struct pico_stack *S, struct pico_protocol *sel icmp6_dbg("Process IN, type = %d\n", hdr->type); - switch (hdr->type) - { + switch (hdr->type) { case PICO_ICMP6_DEST_UNREACH: pico_ipv6_unreachable(S, f, hdr->code); break; @@ -242,8 +241,8 @@ static int pico_icmp6_process_in(struct pico_stack *S, struct pico_protocol *sel break; #ifdef PICO_SUPPORT_IPV6PMTU case PICO_ICMP6_PKT_TOO_BIG: - pico_icmp6_update_pmtu(S, f); - break; + pico_icmp6_update_pmtu(S, f); + break; #endif #if defined(PICO_SUPPORT_MCAST) && defined(PICO_SUPPORT_MLD) case PICO_MLD_QUERY: @@ -261,7 +260,7 @@ static int pico_icmp6_process_in(struct pico_stack *S, struct pico_protocol *sel static int pico_icmp6_process_out(struct pico_stack *S, struct pico_protocol *self, struct pico_frame *f) { - IGNORE_PARAMETER(S); + IGNORE_PARAMETER(S); IGNORE_PARAMETER(self); IGNORE_PARAMETER(f); return 0; @@ -288,8 +287,7 @@ static int pico_icmp6_notify(struct pico_stack *S, struct pico_frame *f, uint8_t ipv6_hdr = (struct pico_ipv6_hdr *)(f->net_hdr); len = (uint16_t)(short_be(ipv6_hdr->len) + PICO_SIZE_IP6HDR); - switch (type) - { + switch (type) { case PICO_ICMP6_DEST_UNREACH: /* as much of invoking packet as possible without exceeding the minimum IPv6 MTU */ if (PICO_SIZE_IP6HDR + PICO_ICMP6HDR_DEST_UNREACH_SIZE + len > PICO_IPV6_MIN_MTU) @@ -422,7 +420,7 @@ MOCKABLE int pico_icmp6_frag_expired(struct pico_stack *S, struct pico_frame *f) static int pico_icmp6_provide_llao(struct pico_icmp6_opt_lladdr *llao, uint8_t type, struct pico_device *dev, struct pico_ip6 *src) { #ifdef PICO_SUPPORT_6LOWPAN - struct pico_6lowpan_info *info = (struct pico_6lowpan_info *)dev->eth; + struct pico_6lowpan_info *info = (struct pico_6lowpan_info *)dev->eth; #endif IGNORE_PARAMETER(src); llao->type = type; @@ -433,15 +431,15 @@ static int pico_icmp6_provide_llao(struct pico_icmp6_opt_lladdr *llao, uint8_t t } #ifdef PICO_SUPPORT_6LOWPAN else if (PICO_DEV_IS_6LOWPAN(dev) && dev->eth) { - if (src && IID_16(&src->addr[8])) { - memcpy(llao->addr.pan.data, (uint8_t *)&info->addr_short.addr, SIZE_6LOWPAN_SHORT); + if (src && IID_16(&src->addr[8])) { + memcpy(llao->addr.pan.data, (uint8_t *)&info->addr_short.addr, SIZE_6LOWPAN_SHORT); memset(llao->addr.pan.data + SIZE_6LOWPAN_SHORT, 0, 4); llao->len = 1; - } else { + } else { memcpy(llao->addr.pan.data, info->addr_ext.addr, SIZE_6LOWPAN_EXT); memset(llao->addr.pan.data + SIZE_6LOWPAN_EXT, 0, 6); llao->len = 2; - } + } } #endif else { @@ -478,7 +476,7 @@ static struct pico_frame *pico_icmp6_neigh_sol_prep(struct pico_device *dev, str MOCKABLE int pico_icmp6_neighbor_solicitation(struct pico_device *dev, struct pico_ip6 *tgt, uint8_t type, struct pico_ip6 *dst) { struct pico_ip6 daddr = {{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00 }}; + 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00 }}; struct pico_icmp6_opt_lladdr *llao = NULL; struct pico_icmp6_hdr *icmp = NULL; struct pico_frame *sol = NULL; @@ -543,7 +541,7 @@ static void pico_6lp_nd_provide_aro(struct pico_icmp6_opt_aro *aro, struct pico_ aro->lifetime = 0; else aro->lifetime = short_be(PICO_6LP_ND_DEFAULT_LIFETIME); - memcpy(aro->eui64.addr, info->addr_ext.addr, SIZE_6LOWPAN_EXT-1); + memcpy(aro->eui64.addr, info->addr_ext.addr, SIZE_6LOWPAN_EXT - 1); } /* Send an ICMP6 neighbor solicitation according to RFC6775 */ @@ -551,7 +549,7 @@ static int pico_6lp_nd_neighbor_solicitation(struct pico_device *dev, struct pic { uint32_t llao_len = IID_16(&tgt->addr[8]) ? 8 : 16; struct pico_icmp6_opt_lladdr *llao = NULL; - struct pico_icmp6_opt_aro *aro = NULL; + struct pico_icmp6_opt_aro *aro = NULL; struct pico_icmp6_hdr *icmp = NULL; struct pico_frame *sol = NULL; uint16_t len = 0; @@ -710,7 +708,6 @@ static struct pico_ip6 pico_icmp6_address_to_prefix(struct pico_ip6 addr, struct for (i = 0; i < PICO_SIZE_IP6; i++) { prefix.addr[i] = (uint8_t)(addr.addr[i] & nm.addr[i]); } - return prefix; } @@ -796,7 +793,7 @@ struct pico_icmp6_ping_cookie struct pico_ip6 dst; struct pico_device *dev; void (*cb)(struct pico_icmp6_stats*); - struct pico_stack *stack; + struct pico_stack *stack; }; int icmp6_cookie_compare(void *ka, void *kb) @@ -916,9 +913,9 @@ static void pico_icmp6_next_ping(pico_time now, void *arg) if (pico_tree_insert(&cookie->stack->IPV6Pings, new)) { dbg("ICMP6: Failed to insert new cookie in tree\n"); - PICO_FREE(new); - return; - } + PICO_FREE(new); + return; + } if (pico_icmp6_send_ping(new)) { dbg("ICMP6: Failed to send ping\n"); @@ -953,7 +950,7 @@ static void pico_icmp6_ping_recv_reply(struct pico_frame *f) stats.time = f->dev->stack->pico_tick - cookie->timestamp; stats.err = cookie->err; stats.ttl = ((struct pico_ipv6_hdr *)f->net_hdr)->hop; - if(cookie->cb) + if (cookie->cb) cookie->cb(&stats); } else { dbg("Reply for seq=%d, not found.\n", test.seq); @@ -965,7 +962,7 @@ int pico_icmp6_ping(struct pico_stack *S, char *dst, int count, int interval, in static uint16_t next_id = 0x91c0; struct pico_icmp6_ping_cookie *cookie = NULL; - if(!dst || !count || !interval || !timeout) { + if (!dst || !count || !interval || !timeout) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -991,13 +988,13 @@ int pico_icmp6_ping(struct pico_stack *S, char *dst, int count, int interval, in cookie->cb = cb; cookie->count = count; cookie->dev = dev; - cookie->stack = S; + cookie->stack = S; if (pico_tree_insert(&S->IPV6Pings, cookie)) { dbg("ICMP6: Failed to insert cookie in tree\n"); PICO_FREE(cookie); - return -1; - } + return -1; + } if (pico_icmp6_send_ping(cookie)) { PICO_FREE(cookie); @@ -1038,7 +1035,7 @@ static void pico_icmp6_update_pmtu(struct pico_stack *S, struct pico_frame *f) icmp_payload = (struct pico_ipv6_hdr *)f->net_hdr; path_id.dst = icmp_payload->dst; - if (pico_ipv6_path_update(S, &path_id, be_to_host_long(icmp_hdr->msg.err.pkt_too_big.mtu)) == PICO_PMTU_OK){ + if (pico_ipv6_path_update(S, &path_id, be_to_host_long(icmp_hdr->msg.err.pkt_too_big.mtu)) == PICO_PMTU_OK) { #if defined PICO_SUPPORT_TCP || defined PICO_SUPPORT_UDP f->transport_hdr = f->net_hdr + PICO_SIZE_IP6HDR; f->transport_len = (uint16_t) (f->transport_len - ((uint16_t)PICO_SIZE_IP6HDR + PICO_ICMP6HDR_PKT_TOO_BIG_SIZE)); diff --git a/modules/pico_icmp6.h b/modules/pico_icmp6.h index 0b4de7fb..2f569ad6 100644 --- a/modules/pico_icmp6.h +++ b/modules/pico_icmp6.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -301,9 +301,9 @@ PACKED_STRUCT_DEF pico_icmp6_opt_6co uint8_t type; uint8_t len; uint8_t clen; - uint8_t id: 4; - uint8_t res: 3; - uint8_t c: 1; + uint8_t id : 4; + uint8_t res : 3; + uint8_t c : 1; uint16_t lifetime; uint8_t prefix; }; diff --git a/modules/pico_igmp.c b/modules/pico_igmp.c index f709c658..ce3f101d 100644 --- a/modules/pico_igmp.c +++ b/modules/pico_igmp.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Kristof Roelants (IGMPv3), Simon Maes, Brecht Van Cauwenberghe - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -328,8 +328,8 @@ static int pico_igmp_timer_start(struct pico_stack *S, struct igmp_timer *t) if (pico_tree_insert(&S->IGMPTimers, timer)) { igmp_dbg("IGMP: Failed to insert timer in tree\n"); PICO_FREE(timer); - return -1; - } + return -1; + } if (!pico_timer_add(S, timer->delay, &pico_igmp_timer_expired, timer)) { igmp_dbg("IGMP: Failed to start expiration timer\n"); @@ -404,7 +404,7 @@ static void pico_igmp_v2querier_expired(struct igmp_timer *t) { struct pico_ipv4_link *link = NULL; struct pico_tree_node *index = NULL, *_tmp = NULL; - if(!t || !t->f || !t->f->dev || !t->stack) + if (!t || !t->f || !t->f->dev || !t->stack) return; @@ -501,7 +501,7 @@ static int pico_igmp_compatibility_mode(struct pico_frame *f) message = (struct igmp_message *)f->transport_hdr; mcast_group.addr = message->mcast_group; p = pico_igmp_find_parameter(S, &link->address, &mcast_group); - if(p) { + if (p) { p->state = IGMP_STATE_NON_MEMBER; p->event = IGMP_EVENT_CREATE_GROUP; } @@ -555,8 +555,8 @@ static struct mcast_parameters *pico_igmp_analyse_packet(struct pico_frame *f) if (pico_tree_insert(&f->dev->stack->IGMPParameters, p)) { igmp_dbg("IGMP: Failed to insert parameters in tree\n"); PICO_FREE(p); - return NULL; - } + return NULL; + } } else if (!p) { return NULL; } @@ -650,8 +650,8 @@ int pico_igmp_state_change(struct pico_stack *S, struct pico_ip4 *mcast_link, st if (pico_tree_insert(&S->IGMPParameters, p)) { igmp_dbg("IGMP: Failed to insert parameters in tree\n"); PICO_FREE(p); - return -1; - } + return -1; + } } else if (!p) { pico_err = PICO_ERR_EINVAL; @@ -778,7 +778,7 @@ static int8_t pico_igmpv3_generate_report(struct mcast_filter_parameters *filter } } - if(i != filter->sources) { + if (i != filter->sources) { return -1; } @@ -832,10 +832,10 @@ static int8_t pico_igmp_generate_report(struct mcast_parameters *p) case PICO_IGMPV3: { result = pico_igmpv3_generate_filter(&filter, p); - if(result < 0) + if (result < 0) return -1; - if(result != MCAST_NO_REPORT) + if (result != MCAST_NO_REPORT) return pico_igmpv3_generate_report(&filter, p); } break; @@ -863,7 +863,7 @@ static int stslifs(struct mcast_parameters *p) if (pico_igmp_timer_stop(&t) < 0) return -1; - if(pico_igmp_generate_report(p) < 0) + if (pico_igmp_generate_report(p) < 0) return -1; /* always send leave, even if not last host */ if (pico_igmp_send_report(p, p->f) < 0) @@ -1009,7 +1009,7 @@ static int slifs(struct mcast_parameters *p) igmp_dbg("IGMP: event = leave group | action = send leave if flag set\n"); /* always send leave, even if not last host */ - if(pico_igmp_generate_report(p) < 0) + if (pico_igmp_generate_report(p) < 0) return -1; if (pico_igmp_send_report(p, p->f) < 0) return -1; @@ -1119,10 +1119,9 @@ static int discard(struct mcast_parameters *p) } /* finite state machine table */ -static const callback host_membership_diagram_table[3][6] = -{ /* event |Delete Group |Create Group |Update Group |Query Received |Report Received |Timer Expired */ -/* state Non-Member */ - { discard, srsfst, srsfst, discard, discard, discard }, +static const callback host_membership_diagram_table[3][6] = { +/* event |Delete Group |Create Group |Update Group |Query Received |Report Received |Timer Expired */ +/* state Non-Member */ { discard, srsfst, srsfst, discard, discard, discard }, /* state Delaying Member */ { stslifs, mrsrrt, mrsrrt, rtimrtct, stcl, srsf }, /* state Idle Member */ { slifs, srst, srst, st, discard, discard } }; diff --git a/modules/pico_igmp.h b/modules/pico_igmp.h index 5c5f56cb..3da6c8f0 100644 --- a/modules/pico_igmp.h +++ b/modules/pico_igmp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_ipfilter.c b/modules/pico_ipfilter.c index a97114af..42b0d7a4 100644 --- a/modules/pico_ipfilter.c +++ b/modules/pico_ipfilter.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Andrei Carp, Simon Maes - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -300,7 +300,7 @@ int filter_compare(void *filterA, void *filterB) } /* improve the search */ - if(a->filter_id == b->filter_id) + if (a->filter_id == b->filter_id) return 0; /* 1. Compare devices */ @@ -310,7 +310,7 @@ int filter_compare(void *filterA, void *filterB) /* 2. Compare protocol */ cmp = filter_compare_proto(a, b); - if(cmp) + if (cmp) return cmp; /* 3. Compare addresses order: in, out */ @@ -353,8 +353,7 @@ struct fp_function { }; -static const struct fp_function fp_function[FILTER_COUNT] = -{ +static const struct fp_function fp_function[FILTER_COUNT] = { {&fp_priority}, {&fp_reject}, {&fp_drop} @@ -362,7 +361,7 @@ static const struct fp_function fp_function[FILTER_COUNT] = static int pico_ipv4_filter_add_validate(int8_t priority, enum filter_action action) { - if ( priority > MAX_PRIORITY || priority < MIN_PRIORITY) { + if (priority > MAX_PRIORITY || priority < MIN_PRIORITY) { return -1; } @@ -408,8 +407,7 @@ uint32_t pico_ipv4_filter_add(struct pico_device *dev, uint8_t proto, new_filter->filter_id = filter_id++; new_filter->function_ptr = fp_function[action].fn; - if(pico_tree_insert(&dev->stack->ipfilter_tree, new_filter)) - { + if (pico_tree_insert(&dev->stack->ipfilter_tree, new_filter)) { PICO_FREE(new_filter); filter_id--; return 0; @@ -426,8 +424,7 @@ int pico_ipv4_filter_del(struct pico_stack *S, uint32_t filter_id) }; dummy.filter_id = filter_id; - if((node = pico_tree_delete(&S->ipfilter_tree, &dummy)) == NULL) - { + if ((node = pico_tree_delete(&S->ipfilter_tree, &dummy)) == NULL) { ipf_dbg("ipfilter> failed to delete filter :%d\n", filter_id); return -1; } @@ -440,8 +437,7 @@ static int ipfilter_apply_filter(struct pico_frame *f, struct filter_node *pkt) { struct filter_node *filter_frame = NULL; filter_frame = pico_tree_findKey(&f->dev->stack->ipfilter_tree, pkt); - if(filter_frame) - { + if (filter_frame) { filter_frame->function_ptr(filter_frame, f); return 1; } @@ -463,12 +459,12 @@ int ipfilter(struct pico_frame *f) temp.in_addr = ipv4_hdr->src.addr; if ((f->transport_hdr + sizeof(struct pico_trans)) <= (f->buffer + f->buffer_len)) { if ((ipv4_hdr->proto == PICO_PROTO_TCP) || (ipv4_hdr->proto == PICO_PROTO_UDP)) { - trans = (struct pico_trans *) f->transport_hdr; - temp.out_port = short_be(trans->dport); - temp.in_port = short_be(trans->sport); - } else if(ipv4_hdr->proto == PICO_PROTO_ICMP4) { + trans = (struct pico_trans *) f->transport_hdr; + temp.out_port = short_be(trans->dport); + temp.in_port = short_be(trans->sport); + } else if (ipv4_hdr->proto == PICO_PROTO_ICMP4) { icmp_hdr = (struct pico_icmp4_hdr *) f->transport_hdr; - if(icmp_hdr->type == PICO_ICMP_UNREACH && icmp_hdr->code == PICO_ICMP_UNREACH_FILTER_PROHIB) + if (icmp_hdr->type == PICO_ICMP_UNREACH && icmp_hdr->code == PICO_ICMP_UNREACH_FILTER_PROHIB) return 0; } temp.proto = ipv4_hdr->proto; diff --git a/modules/pico_ipfilter.h b/modules/pico_ipfilter.h index 98ff291f..aba83467 100644 --- a/modules/pico_ipfilter.h +++ b/modules/pico_ipfilter.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_ipv4.c b/modules/pico_ipv4.c index 5ad14c89..aa46871b 100644 --- a/modules/pico_ipv4.c +++ b/modules/pico_ipv4.c @@ -65,7 +65,7 @@ int pico_ipv4_rawsocket_cmp(void *ka, void *kb) return -1; if (a->id > b->id) return 1; - return (0); + return 0; } #endif @@ -98,8 +98,7 @@ int MOCKABLE pico_ipv4_to_string(char *ipbuf, const uint32_t ip) return -1; } - for(i = 0; i < 4; i++) - { + for (i = 0; i < 4; i++) { if (addr[i] > 99) { *ipbuf++ = (char)('0' + (addr[i] / 100)); *ipbuf++ = (char)('0' + ((addr[i] % 100) / 10)); @@ -143,12 +142,11 @@ int MOCKABLE pico_string_to_ipv4(const char *ipstr, uint32_t *ip) if (pico_string_check_null_args(ipstr, ip) < 0) return -1; - while((p = *ipstr++) != 0 && cnt < PICO_SIZE_IP4) - { + while ((p = *ipstr++) != 0 && cnt < PICO_SIZE_IP4) { if (pico_is_digit(p)) { overflow = (uint16_t) ((10 * buf[cnt]) + (p - '0')); - if(overflow > UINT8_MAX) { - return -1; + if (overflow > UINT8_MAX) { + return -1; } buf[cnt] = (uint8_t) overflow; } else if (p == '.') { @@ -189,7 +187,7 @@ int pico_ipv4_valid_netmask(uint32_t mask) * * */ - for(i = 0; i < 32; i++) { + for (i = 0; i < 32; i++) { if ((mask_swap << i) & 0x80000000) { if (end) { pico_err = PICO_ERR_EINVAL; @@ -241,7 +239,7 @@ int pico_ipv4_is_valid_src(struct pico_stack *S, uint32_t address, struct pico_d if (pico_ipv4_is_broadcast(S, address)) { dbg("Source is a broadcast address, discard packet\n"); return 0; - } else if ( pico_ipv4_is_multicast(address)) { + } else if (pico_ipv4_is_multicast(address)) { dbg("Source is a multicast address, discard packet\n"); return 0; } else if (pico_ipv4_is_invalid_loopback(address, dev)) { @@ -419,7 +417,7 @@ struct pico_socket *pico_socket_ipv4_open(struct pico_stack *S, uint16_t proto) pico_err = PICO_ERR_ENOMEM; return NULL; } - if ((proto & 0x00FF)== PICO_RAWSOCKET_RAW) + if ((proto & 0x00FF) == PICO_RAWSOCKET_RAW) s->hdr_included = 1; s->id = S->IP4Socket_id++; s->proto = (uint8_t)(proto & 0x00FF); @@ -431,7 +429,7 @@ struct pico_socket *pico_socket_ipv4_open(struct pico_stack *S, uint16_t proto) } int pico_socket_ipv4_recvfrom(struct pico_socket *s, void *buf, uint32_t len, void *orig, - uint16_t *remote_port) + uint16_t *remote_port) { struct pico_frame *f; uint8_t *data; @@ -519,7 +517,7 @@ int pico_socket_ipv4_sendto(struct pico_socket *s, const void *buf, uint32_t len struct pico_socket_ipv4 *s4 = (struct pico_socket_ipv4 *)s; (void)dst; if (!s4->hdr_included && (s4->proto == PICO_PROTO_IPV4)) { - /* Raw socket: no send allowed withouth IP_HDRINCL, or if protocol is IPPROTO_IP */ + /* Raw socket: no send allowed withouth IP_HDRINCL, or if protocol is IPPROTO_IP */ pico_err = PICO_ERR_EINVAL; return -1; } @@ -579,21 +577,21 @@ int pico_socket_ipv4_close(struct pico_socket *arg) int pico_setsockopt_ipv4(struct pico_socket *s, int option, void *value) { struct pico_socket_ipv4 *s4 = (struct pico_socket_ipv4 *)s; - switch(option) { - case PICO_SOCKET_OPT_IP_HDRINCL: - if (s4->proto == PICO_RAWSOCKET_RAW) { - pico_err = PICO_ERR_EINVAL; - return -1; - } - s4->hdr_included = (*(int*)value)?1:0; - return 0; - case PICO_SOCKET_OPT_IP_DONTROUTE: - s4->dontroute = (*(int*)value)?1:0; - return 0; - case PICO_SOCKET_OPT_IP_BINDTODEVICE: - s->dev = (struct pico_device *)value; - s->local_addr.ip4.addr = 0; - return 0; + switch (option) { + case PICO_SOCKET_OPT_IP_HDRINCL: + if (s4->proto == PICO_RAWSOCKET_RAW) { + pico_err = PICO_ERR_EINVAL; + return -1; + } + s4->hdr_included = (*(int*)value)?1:0; + return 0; + case PICO_SOCKET_OPT_IP_DONTROUTE: + s4->dontroute = (*(int*)value)?1:0; + return 0; + case PICO_SOCKET_OPT_IP_BINDTODEVICE: + s->dev = (struct pico_device *)value; + s->local_addr.ip4.addr = 0; + return 0; } /* switch's default */ pico_err = PICO_ERR_EINVAL; @@ -603,18 +601,18 @@ int pico_setsockopt_ipv4(struct pico_socket *s, int option, void *value) int pico_getsockopt_ipv4(struct pico_socket *s, int option, void *value) { int *val = (int *)value; - void ** pval = (void *)value; + void **pval = (void *)value; struct pico_socket_ipv4 *s4 = (struct pico_socket_ipv4 *)s; - switch(option) { - case PICO_SOCKET_OPT_IP_HDRINCL: - *val = (int)s4->hdr_included; - return 0; - case PICO_SOCKET_OPT_IP_DONTROUTE: - *val = (int)s4->dontroute; - return 0; - case PICO_SOCKET_OPT_IP_BINDTODEVICE: - *pval = s->dev; - return 0; + switch (option) { + case PICO_SOCKET_OPT_IP_HDRINCL: + *val = (int)s4->hdr_included; + return 0; + case PICO_SOCKET_OPT_IP_DONTROUTE: + *val = (int)s4->dontroute; + return 0; + case PICO_SOCKET_OPT_IP_BINDTODEVICE: + *pval = s->dev; + return 0; } /* switch's default */ pico_err = PICO_ERR_EINVAL; @@ -716,8 +714,7 @@ static int pico_ipv4_process_in(struct pico_stack *S, struct pico_protocol *self } #if defined(PICO_SUPPORT_IPV4FRAG) || defined(PICO_SUPPORT_IPV6FRAG) - if (f->frag & (PICO_IPV4_MOREFRAG | PICO_IPV4_FRAG_MASK)) - { + if (f->frag & (PICO_IPV4_MOREFRAG | PICO_IPV4_FRAG_MASK)) { #ifdef PICO_SUPPORT_IPV4FRAG pico_ipv4_process_frag(hdr, f, hdr->proto); /* Frame can be discarded, frag will handle its own copy */ @@ -877,8 +874,8 @@ struct pico_ip4 pico_ipv4_route_get_gateway(struct pico_stack *S, struct pico_ip pico_err = PICO_ERR_EHOSTUNREACH; return nullip; } - else - return route->gateway; + + return route->gateway; } struct pico_ip4 *pico_ipv4_source_find(struct pico_stack *S, const struct pico_ip4 *dst) @@ -964,7 +961,7 @@ static void pico_ipv4_mcast_print_groups(struct pico_ipv4_link *mcast_link) (void) source; ip_mcast_dbg("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); - ip_mcast_dbg("+ MULTICAST list interface %-16s +\n", mcast_link->dev->name); + ip_mcast_dbg("+ MULTICAST list interface %-16s +\n", mcast_link->dev->name); ip_mcast_dbg("+---------------------------------------------------------------------------------+\n"); ip_mcast_dbg("+ nr | interface | host group | reference count | filter mode | source +\n"); ip_mcast_dbg("+---------------------------------------------------------------------------------+\n"); @@ -1003,9 +1000,9 @@ static int mcast_group_update(struct pico_mcast_group *g, struct pico_tree *MCAS source->addr = ((struct pico_ip4 *)index->keyValue)->addr; if (pico_tree_insert(&g->MCASTSources, source)) { dbg("IPv4: Failed to insert source in tree\n"); - PICO_FREE(source); - return -1; - } + PICO_FREE(source); + return -1; + } } } } @@ -1052,8 +1049,8 @@ int pico_ipv4_mcast_join(struct pico_stack *S, struct pico_ip4 *mcast_link, stru if (pico_tree_insert(link->MCASTGroups, g)) { dbg("IPv4: Failed to insert group in tree\n"); PICO_FREE(g); - return -1; - } + return -1; + } #ifdef PICO_SUPPORT_IGMP pico_igmp_state_change(S, mcast_link, mcast_group, filter_mode, MCASTFilter, PICO_IGMP_STATE_CREATE); @@ -1313,7 +1310,7 @@ int pico_ipv4_frame_push(struct pico_stack *S, struct pico_frame *f, struct pico #ifdef PICO_SUPPORT_IPV4FRAG (0 == (f->frag & PICO_IPV4_MOREFRAG)) && #endif - 1 ) + 1) S->ipv4_progressive_id++; if (f->send_ttl > 0) { @@ -1338,8 +1335,7 @@ int pico_ipv4_frame_push(struct pico_stack *S, struct pico_frame *f, struct pico hdr->frag = short_be(f->frag); } - if (proto == PICO_PROTO_ICMP4) - { + if (proto == PICO_PROTO_ICMP4) { hdr->frag = short_be(f->frag); } @@ -1361,7 +1357,7 @@ int pico_ipv4_frame_push(struct pico_stack *S, struct pico_frame *f, struct pico struct pico_frame *cpy; int retval; /* Sending UDP multicast datagram, am I member? If so, loopback copy */ - if ((proto != PICO_PROTO_IGMP) && (pico_ipv4_mcast_filter(S,f) == 0)) { + if ((proto != PICO_PROTO_IGMP) && (pico_ipv4_mcast_filter(S, f) == 0)) { ip_mcast_dbg("MCAST: sender is member of group, loopback copy\n"); cpy = pico_frame_copy(f); if (!cpy) { @@ -1383,7 +1379,7 @@ int pico_ipv4_frame_push(struct pico_stack *S, struct pico_frame *f, struct pico { union pico_address node_address; node_address.ip4.addr = hdr->dst.addr; - if(hdr->dst.addr && pico_ipv4_is_unicast(hdr->dst.addr)) + if (hdr->dst.addr && pico_ipv4_is_unicast(hdr->dst.addr)) pico_aodv_lookup(&node_address); } #endif @@ -1391,7 +1387,7 @@ int pico_ipv4_frame_push(struct pico_stack *S, struct pico_frame *f, struct pico if (pico_ipv4_link_get(S, &hdr->dst)) { /* it's our own IP */ return pico_enqueue(&S->q_ipv4.in, f); - } else{ + } else { /* TODO: Check if there are members subscribed here */ return pico_enqueue(&S->q_ipv4.out, f); } @@ -1454,7 +1450,7 @@ int MOCKABLE pico_ipv4_route_add(struct pico_stack *S, struct pico_ip4 address, new->link = link; } else { struct pico_ipv4_route *r = route_find(S, &gateway); - if (!r ) { /* Specified Gateway is unreachable */ + if (!r) { /* Specified Gateway is unreachable */ pico_err = PICO_ERR_EHOSTUNREACH; PICO_FREE(new); return -1; @@ -1478,8 +1474,8 @@ int MOCKABLE pico_ipv4_route_add(struct pico_stack *S, struct pico_ip4 address, if (pico_tree_insert(&S->Routes, new)) { dbg("IPv4: Failed to insert route in tree\n"); PICO_FREE(new); - return -1; - } + return -1; + } dbg_route(); return 0; @@ -1565,8 +1561,8 @@ int pico_ipv4_link_add(struct pico_stack *S, struct pico_device *dev, struct pic PICO_FREE(new->MCASTGroups); #endif PICO_FREE(new); - return -1; - } + return -1; + } #ifdef PICO_SUPPORT_MCAST do { @@ -1581,7 +1577,7 @@ int pico_ipv4_link_add(struct pico_stack *S, struct pico_device *dev, struct pic mcast_all_hosts.addr = PICO_MCAST_ALL_HOSTS; pico_ipv4_mcast_join(S, &address, &mcast_all_hosts, 1, PICO_IP_MULTICAST_EXCLUDE, NULL); - } while(0); + } while (0); #endif network.addr = address.addr & netmask.addr; @@ -1651,7 +1647,7 @@ int pico_ipv4_link_del(struct pico_stack *S, struct pico_device *dev, struct pic pico_tree_delete(found->MCASTGroups, g); PICO_FREE(g); } - } while(0); + } while (0); PICO_FREE(found->MCASTGroups); #endif @@ -1744,7 +1740,7 @@ static int pico_ipv4_rebound_large(struct pico_stack *S, struct pico_frame *f) hdr = (struct pico_ipv4_hdr *) f->net_hdr; dst.addr = hdr->src.addr; - while(total_payload_written < len) { + while (total_payload_written < len) { uint32_t space = (uint32_t)len - total_payload_written; if (space > PICO_IPV4_MAXPAYLOAD) space = PICO_IPV4_MAXPAYLOAD; @@ -1755,12 +1751,9 @@ static int pico_ipv4_rebound_large(struct pico_stack *S, struct pico_frame *f) return -1; } - if (space + total_payload_written < len) - { + if (space + total_payload_written < len) { fr->frag |= PICO_IPV4_MOREFRAG; - } - else - { + } else { fr->frag &= PICO_IPV4_FRAG_MASK; } @@ -1914,7 +1907,7 @@ int pico_ipv4_cleanup_links(struct pico_stack *S, struct pico_device *dev) struct pico_tree_node *index = NULL, *_tmp = NULL; struct pico_ipv4_link *link = NULL; - if(!dev || !dev->stack) + if (!dev || !dev->stack) return PICO_ERR_EINVAL; pico_tree_foreach_safe(index, &S->Tree_dev_link, _tmp) { diff --git a/modules/pico_ipv4.h b/modules/pico_ipv4.h index 8434c1d9..7933f16e 100644 --- a/modules/pico_ipv4.h +++ b/modules/pico_ipv4.h @@ -112,10 +112,9 @@ struct pico_socket_ipv4 struct pico_in_pktinfo { - unsigned int ipi_ifindex; /* Device hash */ + unsigned int ipi_ifindex; /* Device hash */ struct pico_ip4 ipi_spec_dst; /* Local address */ - struct pico_ip4 ipi_addr; /* Header Destination - address */ + struct pico_ip4 ipi_addr; /* Header Destination address */ }; #endif diff --git a/modules/pico_ipv6.c b/modules/pico_ipv6.c index 90163b21..992708e1 100644 --- a/modules/pico_ipv6.c +++ b/modules/pico_ipv6.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera, Kristof Roelants - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -216,8 +216,7 @@ int MOCKABLE pico_string_to_ipv6(const char *ipstr, uint8_t *ip) memset(ip, 0, PICO_SIZE_IP6); - while((p = *ipstr++) != 0) - { + while ((p = *ipstr++) != 0) { if (pico_is_hex(p) || (p == ':') || *ipstr == '\0') { /* valid signs */ if (pico_is_hex(p)) { buf[byte] = (uint8_t)((buf[byte] << 4) + pico_ipv6_hex_to_dec(p)); @@ -351,7 +350,7 @@ int pico_ipv6_is_unicast(struct pico_stack *S, struct pico_ip6 *a) return 1; else if (pico_ipv6_is_localhost(a->addr)) return 1; - else if(pico_ipv6_link_get(S, a)) + else if (pico_ipv6_link_get(S, a)) return 1; else return 0; @@ -386,10 +385,10 @@ int pico_ipv6_is_solnode_multicast(const uint8_t addr[PICO_SIZE_IP6], struct pic return 0; link = pico_ipv6_link_by_dev(dev); - while(link) { + while (link) { if (pico_ipv6_is_linklocal(link->address.addr)) { int i, match = 0; - for(i = 13; i < 16; i++) { + for (i = 13; i < 16; i++) { if (addr[i] == link->address.addr[i]) ++match; } @@ -413,7 +412,7 @@ static struct pico_ipv6_route *pico_ipv6_route_find(struct pico_stack *S, const struct pico_tree_node *index = NULL; struct pico_ipv6_route *r = NULL; int i = 0; - if (!pico_ipv6_is_localhost(addr->addr) && (pico_ipv6_is_linklocal(addr->addr) || pico_ipv6_is_sitelocal(addr->addr))) { + if (!pico_ipv6_is_localhost(addr->addr) && (pico_ipv6_is_linklocal(addr->addr) || pico_ipv6_is_sitelocal(addr->addr))) { return NULL; } @@ -437,7 +436,7 @@ struct pico_ip6 *pico_ipv6_source_find(struct pico_stack *S, const struct pico_i struct pico_ip6 *myself = NULL; struct pico_ipv6_route *rt; - if(!dst) { + if (!dst) { pico_err = PICO_ERR_EINVAL; return NULL; } @@ -456,7 +455,7 @@ struct pico_device *pico_ipv6_source_dev_find(struct pico_stack *S, const struct struct pico_device *dev = NULL; struct pico_ipv6_route *rt; - if(!dst) { + if (!dst) { pico_err = PICO_ERR_EINVAL; return NULL; } @@ -472,10 +471,10 @@ struct pico_device *pico_ipv6_source_dev_find(struct pico_stack *S, const struct static int pico_ipv6_forward_check_dev(struct pico_stack *S, struct pico_frame *f) { - if(f->dev->mode == LL_MODE_ETHERNET && f->dev->eth != NULL) + if (f->dev->mode == LL_MODE_ETHERNET && f->dev->eth != NULL) f->len -= PICO_SIZE_ETHHDR; - if(f->len > f->dev->mtu) { + if (f->len > f->dev->mtu) { pico_notify_pkt_too_big(S, f); return -1; } @@ -523,8 +522,7 @@ static int pico_ipv6_forward(struct pico_stack *S, struct pico_frame *f) f->dev = rt->link->dev; - if (pico_ipv6_pre_forward_checks(S, f) < 0) - { + if (pico_ipv6_pre_forward_checks(S, f) < 0) { pico_frame_discard(f); return -1; } @@ -548,8 +546,7 @@ static int pico_ipv6_process_hopbyhop(struct pico_ipv6_exthdr *hbh, struct pico_ len = (uint8_t)HBH_LEN(hbh); ipv6_dbg("IPv6: hop by hop extension header length %u\n", len + 2); while (len) { - switch (*option) - { + switch (*option) { case PICO_IPV6_EXTHDR_OPT_PAD1: ++option; --len; @@ -565,7 +562,7 @@ static int pico_ipv6_process_hopbyhop(struct pico_ipv6_exthdr *hbh, struct pico_ case PICO_IPV6_EXTHDR_OPT_ROUTER_ALERT: optlen = (uint8_t)((*(option + 1)) + 2); /* plus type and len byte */ /* MLD package */ - if(*(option + 1) == 2) + if (*(option + 1) == 2) must_align = 0; if (optlen == 0) return -1; @@ -638,8 +635,7 @@ static int pico_ipv6_process_destopt(struct pico_ipv6_exthdr *destopt, struct pi optlen = (uint8_t)(*(option + 1) + 2); if ((optlen > len) || (optlen == 0)) return -1; - switch (*option) - { + switch (*option) { case PICO_IPV6_EXTHDR_OPT_PAD1: break; @@ -682,7 +678,7 @@ static int pico_ipv6_check_headers_sequence(struct pico_frame *f) int ptr = sizeof(struct pico_ipv6_hdr); int cur_nexthdr = 6; /* Starts with nexthdr field in ipv6 pkt */ uint8_t nxthdr = hdr->nxthdr; - for (;; ) { + for (;;) { uint8_t optlen = *(f->net_hdr + ptr + 1); if (optlen == 0) return 0; @@ -745,7 +741,7 @@ static int pico_ipv6_extension_headers(struct pico_frame *f) if (pico_ipv6_check_headers_sequence(f) < 0) return -1; - for (;; ) { + for (;;) { exthdr = (struct pico_ipv6_exthdr *)(f->net_hdr + f->net_len); cur_optlen = 0; @@ -762,7 +758,7 @@ static int pico_ipv6_extension_headers(struct pico_frame *f) cur_optlen = IPV6_OPTLEN(exthdr->ext.hopbyhop.len); f->net_len = (uint16_t) (f->net_len + cur_optlen); must_align = pico_ipv6_process_hopbyhop(exthdr, f); - if(must_align < 0) + if (must_align < 0) return -1; break; @@ -842,7 +838,7 @@ static int pico_ipv6_process_mcast_in(struct pico_frame *f) if (pico_ipv6_is_multicast(hdr->dst.addr)) { #ifdef PICO_SUPPORT_MCAST /* Receiving UDP multicast datagram TODO set f->flags? */ - if(hdr->nxthdr == 0) { + if (hdr->nxthdr == 0) { hbh = (struct pico_ipv6_exthdr *) (f->transport_hdr); } @@ -871,14 +867,14 @@ static int pico_ipv6_process_in(struct pico_stack *S, struct pico_protocol *self IGNORE_PARAMETER(self); /* forward if not local, except if router alert is set */ if (pico_ipv6_is_unicast(S, &hdr->dst) && !pico_ipv6_link_get(S, &hdr->dst)) { - if(hdr->nxthdr == 0) { + if (hdr->nxthdr == 0) { hbh = (struct pico_ipv6_exthdr *) f->transport_hdr; - if(hbh->ext.routing.routtype == 0 && + if (hbh->ext.routing.routtype == 0 && hbh->ext.routing.segleft != 0) return pico_ipv6_forward(S, f); } else /* not local, try to forward. */ - return pico_ipv6_forward(S,f); + return pico_ipv6_forward(S, f); } proto = pico_ipv6_extension_headers(f); @@ -954,7 +950,7 @@ static struct pico_frame *pico_ipv6_alloc(struct pico_stack *S, struct pico_prot static inline int ipv6_pushed_frame_valid(struct pico_frame *f, struct pico_ip6 *dst) { struct pico_ipv6_hdr *hdr = NULL; - if(!f || !dst) + if (!f || !dst) return -1; hdr = (struct pico_ipv6_hdr *)f->net_hdr; @@ -1101,8 +1097,8 @@ int pico_ipv6_mcast_join(struct pico_stack *S, struct pico_ip6 *mcast_link, stru if (pico_tree_insert(link->MCASTGroups, g)) { ipv6_mcast_dbg("IPv6 MCAST: Failed to insert group in tree\n"); PICO_FREE(g); - return -1; - } + return -1; + } #ifdef PICO_SUPPORT_MLD res = pico_mld_state_change(S, mcast_link, mcast_group, filter_mode, _MCASTFilter, PICO_MLD_STATE_CREATE); @@ -1188,7 +1184,7 @@ static int pico_ipv6_mcast_filter(struct pico_stack *S, struct pico_frame *f) if (g) { if (f->dev == link->dev) { #ifdef PICO_DEBUG_MULTICAST - pico_ipv6_to_string( ipv6_addr, &hdr->dst.addr[0]); + pico_ipv6_to_string(ipv6_addr, &hdr->dst.addr[0]); ipv6_mcast_dbg("MCAST: IP %s is group member of current link %s\n", ipv6_addr, f->dev->name); #endif /* perform source filtering */ @@ -1329,17 +1325,16 @@ static inline void ipv6_push_hdr_adjust(struct pico_stack *S, struct pico_frame } /* make adjustments to defaults according to proto */ - switch (proto) - { + switch (proto) { #ifdef PICO_SUPPORT_MLD case 0: { hbh = (struct pico_ipv6_exthdr *) f->transport_hdr; - switch(hbh->nxthdr) { + switch (hbh->nxthdr) { case PICO_PROTO_ICMP6: { icmp6_hdr = (struct pico_icmp6_hdr *)(f->transport_hdr + sizeof(struct pico_ipv6_exthdr)); - if((icmp6_hdr->type >= PICO_MLD_QUERY && icmp6_hdr->type <= PICO_MLD_DONE) || icmp6_hdr->type == PICO_MLD_REPORTV2) { + if ((icmp6_hdr->type >= PICO_MLD_QUERY && icmp6_hdr->type <= PICO_MLD_DONE) || icmp6_hdr->type == PICO_MLD_REPORTV2) { hdr->hop = 1; } @@ -1351,7 +1346,7 @@ static inline void ipv6_push_hdr_adjust(struct pico_stack *S, struct pico_frame break; } #else - IGNORE_PARAMETER(hbh); + IGNORE_PARAMETER(hbh); #endif case PICO_IPV6_EXTHDR_FRAG: { @@ -1367,7 +1362,7 @@ static inline void ipv6_push_hdr_adjust(struct pico_stack *S, struct pico_frame * ... An unspecified source address MUST NOT be used in NS messages. */ if (f->dev->mode == LL_MODE_ETHERNET && (is_dad || link->istentative) && (icmp6_hdr->type == PICO_ICMP6_NEIGH_SOL || icmp6_hdr->type == PICO_ICMP6_ROUTER_SOL)) { - memcpy(hdr->src.addr, PICO_IP6_ANY, PICO_SIZE_IP6); + memcpy(hdr->src.addr, PICO_IP6_ANY, PICO_SIZE_IP6); } @@ -1394,10 +1389,9 @@ static int ipv6_frame_push_final(struct pico_stack *S, struct pico_frame *f) { struct pico_ipv6_hdr *hdr = NULL; hdr = (struct pico_ipv6_hdr *)f->net_hdr; - if(pico_ipv6_link_get(S, &hdr->dst)) { + if (pico_ipv6_link_get(S, &hdr->dst)) { return pico_enqueue(&S->q_ipv6.in, f); - } - else { + } else { return pico_enqueue(&S->q_ipv6.out, f); } } @@ -1639,8 +1633,8 @@ int pico_ipv6_route_add(struct pico_stack *S, struct pico_ip6 address, struct pi if (pico_tree_insert(&S->IPV6Routes, new)) { ipv6_dbg("IPv6: Failed to insert route in tree\n"); PICO_FREE(new); - return -1; - } + return -1; + } pico_ipv6_dbg_route(); return 0; @@ -1743,8 +1737,7 @@ static void pico_ipv6_nd_dad(pico_time now, void *arg) } pico_ipv6_link_del(info->dev->stack, l->dev, old_address); - } - else { + } else { if (l->dup_detect_retrans-- == 0) { dbg("IPv6: DAD verified valid address.\n"); @@ -1824,8 +1817,8 @@ static struct pico_ipv6_link *pico_ipv6_do_link_add(struct pico_device *dev, str PICO_FREE(new->MCASTGroups); #endif PICO_FREE(new); - return NULL; - } + return NULL; + } for (i = 0; i < PICO_SIZE_IP6; ++i) { network.addr[i] = address.addr[i] & netmask.addr[i]; } @@ -1837,7 +1830,7 @@ static struct pico_ipv6_link *pico_ipv6_do_link_add(struct pico_device *dev, str } pico_ipv6_mcast_join(dev->stack, &address, &all_hosts, 1, PICO_IP_MULTICAST_EXCLUDE, NULL); - } while(0); + } while (0); #else IGNORE_PARAMETER(all_hosts); #endif @@ -1845,7 +1838,7 @@ static struct pico_ipv6_link *pico_ipv6_do_link_add(struct pico_device *dev, str #ifdef PICO_SUPPORT_6LOWPAN if (!PICO_DEV_IS_6LOWPAN(dev)) #endif - pico_ipv6_route_add(dev->stack, mcast_addr, mcast_nm, mcast_gw, 1, new); + pico_ipv6_route_add(dev->stack, mcast_addr, mcast_nm, mcast_gw, 1, new); /* XXX MUST join the all-nodes multicast address on that interface, as well as * the solicited-node multicast address corresponding to each of the IP * addresses assigned to the interface. (RFC 4861 $7.2.1) @@ -1888,8 +1881,7 @@ struct pico_ipv6_link *pico_ipv6_link_add(struct pico_device *dev, struct pico_i new->dup_detect_retrans = PICO_IPV6_DEFAULT_DAD_RETRANS; #ifndef UNIT_TEST /* Duplicate Address Detection */ - if (pico_ipv6_link_schedule_dad(new, 100)) - { + if (pico_ipv6_link_schedule_dad(new, 100)) { pico_ipv6_link_del(dev->stack, dev, address); return NULL; } @@ -2026,7 +2018,7 @@ struct pico_device *pico_ipv6_link_find(struct pico_stack *S, struct pico_ip6 *a struct pico_ipv6_link test = { 0 }, *found = NULL; - if(!address) { + if (!address) { pico_err = PICO_ERR_EINVAL; return NULL; } @@ -2061,8 +2053,8 @@ struct pico_ip6 pico_ipv6_route_get_gateway(struct pico_stack *S, struct pico_ip pico_err = PICO_ERR_EHOSTUNREACH; return nullip; } - else - return route->gateway; + + return route->gateway; } @@ -2151,7 +2143,7 @@ struct pico_ipv6_link *pico_ipv6_global_get(struct pico_device *dev) static uint32_t ipv6_lifetimer_check = 0u; static void pico_ipv6_check_link_lifetime_expired(pico_time now, void *arg); -static void pico_ipv6_nd_enable_lifetime_check(struct pico_stack *S) +static void pico_ipv6_nd_enable_lifetime_check(struct pico_stack *S) { if (!ipv6_lifetimer_check) ipv6_lifetimer_check = pico_timer_add(S, 1000, pico_ipv6_check_link_lifetime_expired, S); @@ -2165,14 +2157,14 @@ static void pico_ipv6_check_link_lifetime_expired(pico_time now, void *arg) #ifdef PICO_SUPPORT_6LOWPAN struct pico_ipv6_route *gw = NULL; #endif - struct pico_stack *S = (struct pico_stack *)arg; + struct pico_stack *S = (struct pico_stack *)arg; (void)arg; pico_tree_foreach_safe(index, &S->IPV6Links, temp) { link = index->keyValue; if ((link->expire_time > 0) && (link->expire_time < now)) { dbg("Warning: IPv6 address has expired.\n"); - pico_ipv6_link_del(S,link->dev, link->address); + pico_ipv6_link_del(S, link->dev, link->address); } #ifdef PICO_SUPPORT_6LOWPAN else if (PICO_DEV_IS_6LOWPAN(link->dev) && !pico_ipv6_is_linklocal(link->address.addr) && @@ -2203,7 +2195,7 @@ int pico_ipv6_lifetime_set(struct pico_ipv6_link *l, pico_time expire) if (expire > 0xFFFFFFFE) { l->expire_time = 0u; - }else if ((expire > (now + TWO_HOURS)) || (expire > l->expire_time)) { + } else if ((expire > (now + TWO_HOURS)) || (expire > l->expire_time)) { l->expire_time = expire; } else { l->expire_time = now + TWO_HOURS; @@ -2215,7 +2207,7 @@ int pico_ipv6_lifetime_set(struct pico_ipv6_link *l, pico_time expire) int pico_ipv6_dev_routing_enable(struct pico_device *dev) { pico_time next_timer_expire; - if (!dev->hostvars.routing) { + if (!dev->hostvars.routing) { next_timer_expire = PICO_IPV6_ND_MIN_RADV_INTERVAL + (pico_rand() % (PICO_IPV6_ND_MAX_RADV_INTERVAL - PICO_IPV6_ND_MIN_RADV_INTERVAL)); pico_timer_add(dev->stack, next_timer_expire, pico_ipv6_nd_ra_timer_callback, dev); } diff --git a/modules/pico_ipv6.h b/modules/pico_ipv6.h index c4b3f13c..3967227a 100644 --- a/modules/pico_ipv6.h +++ b/modules/pico_ipv6.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_ipv6_nd.c b/modules/pico_ipv6_nd.c index 04adba29..8882556b 100644 --- a/modules/pico_ipv6_nd.c +++ b/modules/pico_ipv6_nd.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera, Laurens Miers, Roel Postelmans, Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -86,7 +86,7 @@ struct pico_ipv6_neighbor { uint8_t failure_uni_count; uint16_t frames_queued; pico_time expire; - struct pico_stack *stack; + struct pico_stack *stack; }; struct pico_ipv6_router { @@ -131,8 +131,7 @@ static void print_nce(struct pico_ipv6_neighbor *n) nd_dbg("NCE with ADDR: "); pico_nd_print_addr(&n->address); - switch (n->state) - { + switch (n->state) { case PICO_ND_STATE_INCOMPLETE: nd_dbg("NB STATE : INCOMPLETE\n"); break; @@ -154,7 +153,7 @@ static void print_nce(struct pico_ipv6_neighbor *n) default: nd_dbg("NB STATE : NOT DEFINED??\n"); break; - }; + } nd_dbg("FAILURE COUNTS: %d %d\n", n->failure_multi_count, n->failure_uni_count); nd_dbg("FRAMES QUEUED: %d\n", n->frames_queued); @@ -178,7 +177,8 @@ int pico_ipv6_router_compare(void *ka, void *kb) return pico_ipv6_neighbor_compare(a->router, b->router); } -int pico_ipv6_nd_qcompare(void *ka, void *kb){ +int pico_ipv6_nd_qcompare(void *ka, void *kb) +{ struct pico_frame *a = ka, *b = kb; struct pico_ipv6_hdr *a_hdr = NULL, *b_hdr = NULL; struct pico_ip6 *a_dest_addr, *b_dest_addr; @@ -192,14 +192,14 @@ int pico_ipv6_nd_qcompare(void *ka, void *kb){ ret = pico_ipv6_compare(a_dest_addr, b_dest_addr); - if(ret){ + if (ret) { return ret; } - if(a->timestamp < b->timestamp){ + if (a->timestamp < b->timestamp) { return -1; } - if(a->timestamp > b->timestamp){ + if (a->timestamp > b->timestamp) { return 1; } return 0; @@ -254,7 +254,7 @@ static struct pico_frame *pico_nd_get_oldest_queued_frame(struct pico_stack *S, struct pico_frame *frame = NULL; struct pico_ipv6_hdr *frame_hdr = NULL; - pico_tree_foreach(index,&S->IPV6NQueue) { + pico_tree_foreach(index, &S->IPV6NQueue) { frame = index->keyValue; frame_hdr = (struct pico_ipv6_hdr *)frame->net_hdr; /* Get frames with dest addr == dst */ @@ -311,8 +311,7 @@ static struct pico_ipv6_router *pico_get_router_from_rcache(struct pico_stack *S test.router = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - if (!test.router) - { + if (!test.router) { nd_dbg("Could not allocate neighbor to get router from rcache\n"); return NULL; } @@ -326,20 +325,19 @@ static struct pico_ipv6_router *pico_get_router_from_rcache(struct pico_stack *S static struct pico_ipv6_router *pico_nd_get_default_router(struct pico_stack *S) { - struct pico_tree_node *index = NULL; - struct pico_ipv6_router *tmp = NULL, *ret = NULL; + struct pico_tree_node *index = NULL; + struct pico_ipv6_router *tmp = NULL, *ret = NULL; - pico_tree_foreach(index, &S->IPV6RCache) - { - tmp = index->keyValue; - if(tmp->is_default) - { - ret = tmp; - break; - } - } + pico_tree_foreach(index, &S->IPV6RCache) + { + tmp = index->keyValue; + if (tmp->is_default) { + ret = tmp; + break; + } + } - return ret; + return ret; } static void pico_nd_set_new_expire_time(struct pico_ipv6_neighbor *n) @@ -387,8 +385,7 @@ static void pico_ipv6_assign_router_on_link(struct pico_stack *S, int assign_def { r = index->keyValue; - if (r->link != link || default_router == r) - { + if (r->link != link || default_router == r) { /* router on other link or previous default router*/ continue; } @@ -414,10 +411,9 @@ static void pico_ipv6_set_router_link(struct pico_ip6 *addr, struct pico_ipv6_li pico_tree_foreach(index, &link->dev->stack->IPV6RCache) { r = index->keyValue; - if( pico_ipv6_compare(&r->router->address, addr) == 0) - { - r->link = link; - break; + if (pico_ipv6_compare(&r->router->address, addr) == 0) { + r->link = link; + break; } } } @@ -429,8 +425,7 @@ static void pico_ipv6_set_router_mtu(struct pico_stack *S, struct pico_ip6 *addr pico_tree_foreach(index, &S->IPV6RCache) { r = index->keyValue; - if(pico_ipv6_compare(&r->router->address, addr) == 0) - { + if (pico_ipv6_compare(&r->router->address, addr) == 0) { if (r->link != NULL) { r->link->mtu = mtu; } @@ -448,7 +443,7 @@ static void pico_nd_clear_queued_packets(const struct pico_ipv6_neighbor *n) .addr = {0} }; - pico_tree_foreach_safe(index,&n->stack->IPV6NQueue, _tmp) { + pico_tree_foreach_safe(index, &n->stack->IPV6NQueue, _tmp) { frame = index->keyValue; frame_hdr = (struct pico_ipv6_hdr *) frame->net_hdr; frame_dst = pico_ipv6_route_get_gateway(n->stack, &frame_hdr->dst); @@ -457,10 +452,10 @@ static void pico_nd_clear_queued_packets(const struct pico_ipv6_neighbor *n) } if (pico_ipv6_compare(&frame_dst, &n->address) == 0) { - if(pico_source_is_local(n->stack, frame) == 0){ + if (pico_source_is_local(n->stack, frame) == 0) { pico_notify_dest_unreachable(n->stack, frame); } - pico_tree_delete(&n->stack->IPV6NQueue,frame); + pico_tree_delete(&n->stack->IPV6NQueue, frame); pico_frame_discard(frame); } } @@ -487,24 +482,24 @@ static void pico_nd_trigger_queued_packets(struct pico_stack *S, struct pico_ip6 frame_hdr = (struct pico_ipv6_hdr *)frame->net_hdr; frame_dst = frame_hdr->dst; - if(!pico_ipv6_is_linklocal(frame_dst.addr)) { - frame_dst = pico_ipv6_route_get_gateway(S, &frame_dst); + if (!pico_ipv6_is_linklocal(frame_dst.addr)) { + frame_dst = pico_ipv6_route_get_gateway(S, &frame_dst); } - if(pico_ipv6_is_unspecified(frame_dst.addr)){ - frame_dst = frame_hdr->dst; + if (pico_ipv6_is_unspecified(frame_dst.addr)) { + frame_dst = frame_hdr->dst; } - if(pico_ipv6_compare(dst, &frame_dst) == 0){ - if(n) { - n->frames_queued--; - } - - pico_tree_delete(&S->IPV6NQueue, frame); - if (pico_datalink_send(frame) > 0) { - nd_dbg("ND-TRIGGER: FRAME SENT\n"); - } else { - pico_frame_discard(frame); - } + if (pico_ipv6_compare(dst, &frame_dst) == 0) { + if (n) { + n->frames_queued--; + } + + pico_tree_delete(&S->IPV6NQueue, frame); + if (pico_datalink_send(frame) > 0) { + nd_dbg("ND-TRIGGER: FRAME SENT\n"); + } else { + pico_frame_discard(frame); + } } } @@ -580,7 +575,7 @@ static struct pico_ipv6_neighbor *pico_nd_create_entry(struct pico_stack *S, str n->frames_queued = 0; n->state = PICO_ND_STATE_INCOMPLETE; n->expire = PICO_TIME_MS() + ONE_MINUTE_MS; - n->stack = S; + n->stack = S; if (pico_tree_insert(&S->IPV6NCache, n)) { nd_dbg("IPv6 ND: Failed to insert neigbor in tree\n"); @@ -596,8 +591,8 @@ static void pico_nd_delete_entry(struct pico_ipv6_neighbor *n) struct pico_ipv6_router *r = NULL; /* If it is a router, it should be in the S->IPV6RCache */ - if(n && n->is_router) - r = pico_get_router_from_rcache(n->stack, &n->address); + if (n && n->is_router) + r = pico_get_router_from_rcache(n->stack, &n->address); #ifdef PICO_SUPPORT_6LOWPAN /* 6LP: Find any 6LoWPAN-hosts for which this address might have been a default gateway. @@ -637,20 +632,20 @@ static void pico_nd_discover(struct pico_ipv6_neighbor *n) } if ((n->state == PICO_ND_STATE_INCOMPLETE) || (n->state == PICO_ND_STATE_INCOMPLETE_SEARCHING)) { - if (++n->failure_multi_count > PICO_ND_MAX_MULTICAST_SOLICIT){ - nd_dbg("failure multi count threshold reached\n"); - return; - } + if (++n->failure_multi_count > PICO_ND_MAX_MULTICAST_SOLICIT) { + nd_dbg("failure multi count threshold reached\n"); + return; + } - pico_icmp6_neighbor_solicitation(n->dev, &n->address, PICO_ICMP6_ND_SOLICITED, &gw->gateway); - nd_dbg("NS solicited for "); + pico_icmp6_neighbor_solicitation(n->dev, &n->address, PICO_ICMP6_ND_SOLICITED, &gw->gateway); + nd_dbg("NS solicited for "); } else { - if (++n->failure_uni_count > PICO_ND_MAX_UNICAST_SOLICIT){ - nd_dbg("failure uni count threshold reached\n"); - return; - } - pico_icmp6_neighbor_solicitation(n->dev, &n->address, PICO_ICMP6_ND_UNICAST, &gw->gateway); - nd_dbg("NS unicast for "); + if (++n->failure_uni_count > PICO_ND_MAX_UNICAST_SOLICIT) { + nd_dbg("failure uni count threshold reached\n"); + return; + } + pico_icmp6_neighbor_solicitation(n->dev, &n->address, PICO_ICMP6_ND_UNICAST, &gw->gateway); + nd_dbg("NS unicast for "); } print_nce(n); @@ -668,8 +663,8 @@ static struct pico_eth *pico_nd_get_neighbor(struct pico_ip6 *addr, struct pico_ if (!n) { nd_dbg("no NCE yet, create one\n"); - if((n = pico_nd_create_entry(dev->stack, addr, dev)) == NULL) { - return NULL; + if ((n = pico_nd_create_entry(dev->stack, addr, dev)) == NULL) { + return NULL; } } @@ -790,7 +785,6 @@ static int get_neigh_option(struct pico_frame *f, void *opt, uint8_t expected_op break; } } - return found; } @@ -1023,8 +1017,8 @@ static void pico_ipv6_router_from_unsolicited(struct pico_frame *f) return; } } else { - pico_nd_print_addr(&ip->src); - nd_dbg("already in cache, updating timer\n"); + pico_nd_print_addr(&ip->src); + nd_dbg("already in cache, updating timer\n"); } r->invalidation = PICO_TIME_MS() + (pico_time)(short_be(r_adv_hdr->life_time) * 1000); @@ -1042,17 +1036,13 @@ static int neigh_sol_detect_dad(struct pico_frame *f) if (!f->dev->mode) { link = pico_ipv6_link_istentative(f->dev->stack, &icmp6_hdr->msg.info.neigh_adv.target); if (link) { - if (pico_ipv6_is_unicast(f->dev->stack, &ipv6_hdr->src)) - { + if (pico_ipv6_is_unicast(f->dev->stack, &ipv6_hdr->src)) { /* RFC4862 5.4.3 : sender is performing address resolution, * our address is not yet valid, discard silently. */ nd_dbg("DAD:Sender performing AR\n"); - } - - else if (pico_ipv6_is_unspecified(ipv6_hdr->src.addr) && - !pico_ipv6_is_allhosts_multicast(ipv6_hdr->dst.addr)) - { + } else if (pico_ipv6_is_unspecified(ipv6_hdr->src.addr) && + !pico_ipv6_is_allhosts_multicast(ipv6_hdr->dst.addr)) { /* RFC4862 5.4.3 : sender is performing DaD */ nd_dbg("DAD:Sender performing DaD\n"); ipv6_duplicate_detected(link); @@ -1090,7 +1080,7 @@ static int neigh_sol_unicast_validity_check(struct pico_frame *f) link = pico_ipv6_link_by_dev(f->dev); icmp6_hdr = (struct pico_icmp6_hdr *)f->transport_hdr; - while(link) { + while (link) { /* RFC4861, 7.2.3: * * - The Target Address is a "valid" unicast or anycast address @@ -1141,14 +1131,12 @@ static int neigh_sol_validity_checks(struct pico_frame *f) /* Step 2 validation */ struct pico_icmp6_hdr *icmp6_hdr = NULL; struct pico_ipv6_hdr *hdr = (struct pico_ipv6_hdr *)(f->net_hdr); - if (f->transport_len < PICO_ICMP6HDR_NEIGH_ADV_SIZE) - { + if (f->transport_len < PICO_ICMP6HDR_NEIGH_ADV_SIZE) { nd_dbg("Neigh sol validity fail: transport len fail. %d\n", f->transport_len); return -1; } - if ((pico_ipv6_is_unspecified(hdr->src.addr)) && (neigh_sol_validate_unspec(f) < 0)) - { + if ((pico_ipv6_is_unspecified(hdr->src.addr)) && (neigh_sol_validate_unspec(f) < 0)) { nd_dbg("Neigh sol validity fail: unspecified %d && validate unspec %d\n", pico_ipv6_is_unspecified(hdr->src.addr), neigh_sol_validate_unspec(f)); return -1; } @@ -1200,14 +1188,12 @@ static int neigh_sol_process(struct pico_frame *f) static int pico_nd_neigh_sol_recv(struct pico_frame *f) { - if (icmp6_initial_checks(f) < 0) - { + if (icmp6_initial_checks(f) < 0) { nd_dbg("ND: neigh sol initial check failed\n"); return -1; } - if (neigh_sol_validity_checks(f) < 0) - { + if (neigh_sol_validity_checks(f) < 0) { nd_dbg("ND: neigh sol validity check failed\n"); return -1; } @@ -1351,11 +1337,11 @@ int pico_6lp_nd_start_soliciting(struct pico_ipv6_link *l, struct pico_ipv6_rout struct pico_ip6 *dst = NULL; if (dummy) { - if (gw) { // If the router solicitation has to be sent unicast ... - dst = &gw->gateway; // ... the gateway is the destination - memcpy(dummy->gateway.addr, gw->gateway.addr, PICO_SIZE_IP6); // and should be retrievable in the timer event + if (gw) { /* If the router solicitation has to be sent unicast ... */ + dst = &gw->gateway; /* ... the gateway is the destination */ + memcpy(dummy->gateway.addr, gw->gateway.addr, PICO_SIZE_IP6); /* and should be retrievable in the timer event */ } - dummy->link = l; // the link that has to be reconfirmed as well. + dummy->link = l; /* the link that has to be reconfirmed as well. */ /* If router list is empty, send router solicitation */ pico_icmp6_router_solicitation(l->dev, &l->address, dst); @@ -1411,14 +1397,14 @@ static int pico_6lp_nd_neigh_adv_process(struct pico_frame *f) return -1; /* Globally routable address has been registered @ 6LoWPAN Border Router */ - if (1 == status) { // Duplicate address detected + if (1 == status) { /* Duplicate address detected */ nd_dbg("[6LP-ND]: Registering routable address failed, removing link...\n"); ipv6_duplicate_detected(l); return -1; - } else if (2 == status) { // Router's NCE is full, remove router from default router list + } else if (2 == status) { /* Router's NCE is full, remove router from default router list */ pico_ipv6_route_del(f->dev->stack, zero, zero, hdr->src, 10, l); pico_6lp_nd_start_soliciting(pico_ipv6_linklocal_get(l->dev), NULL); - } else { // Registration success + } else { /* Registration success */ nd_dbg("[6LP-ND]: Registering routable address succeeded!\n"); } } @@ -1446,7 +1432,7 @@ static int neigh_sol_dad_reply(struct pico_frame *sol, struct pico_icmp6_opt_lla uint8_t sllao_len = (uint8_t)(sllao->len * 8); struct pico_icmp6_hdr *icmp = NULL; struct pico_frame *adv = pico_frame_copy(sol); - struct pico_ip6 ll = {{0xfe,0x80,0,0,0,0,0,0, 0,0,0,0,0,0,0,0}}; + struct pico_ip6 ll = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; size_t len = pico_hw_addr_len(sol->dev, sllao); union pico_ll_addr lladdr; @@ -1797,7 +1783,7 @@ static int radv_process(struct pico_frame *f) struct pico_icmp6_opt_mtu mtu_option; int mtu_valid = get_neigh_option(f, &mtu_option, PICO_ND_OPT_MTU); if (mtu_valid > 0) { - pico_ipv6_set_router_mtu(f->dev->stack, &hdr->src,long_be(mtu_option.mtu)); + pico_ipv6_set_router_mtu(f->dev->stack, &hdr->src, long_be(mtu_option.mtu)); } } @@ -1829,17 +1815,16 @@ static int pico_nd_router_adv_recv(struct pico_frame *f) hdr = (struct pico_ipv6_hdr *)f->net_hdr; pico_tree_foreach(index, &f->dev->stack->IPV6Links){ - link = index->keyValue; - if(link->rs_retries >= 1 && pico_ipv6_is_linklocal(hdr->src.addr)){ - link->rs_retries = MAX_INITIAL_RTR_ADVERTISEMENTS; - link->rs_expire_time = 0; - } - else if(link->rs_retries == 0 && pico_ipv6_is_linklocal(hdr->src.addr)){ - route = pico_ipv6_gateway_by_dev(f->dev->stack, f->dev); - pico_icmp6_router_solicitation(link->dev, &link->address, &route->gateway); - link->rs_retries = MAX_INITIAL_RTR_ADVERTISEMENTS; - link->rs_expire_time = 0; - } + link = index->keyValue; + if (link->rs_retries >= 1 && pico_ipv6_is_linklocal(hdr->src.addr)) { + link->rs_retries = MAX_INITIAL_RTR_ADVERTISEMENTS; + link->rs_expire_time = 0; + } else if (link->rs_retries == 0 && pico_ipv6_is_linklocal(hdr->src.addr)) { + route = pico_ipv6_gateway_by_dev(f->dev->stack, f->dev); + pico_icmp6_router_solicitation(link->dev, &link->address, &route->gateway); + link->rs_retries = MAX_INITIAL_RTR_ADVERTISEMENTS; + link->rs_expire_time = 0; + } } pico_ipv6_neighbor_from_unsolicited(f); @@ -1984,23 +1969,19 @@ static int pico_nd_redirect_is_valid(struct pico_frame *f) icmp6_hdr = (struct pico_icmp6_hdr *)f->transport_hdr; gateway = pico_ipv6_route_get_gateway(f->dev->stack, &icmp6_hdr->msg.info.redirect.dest); - if (f->transport_len < PICO_ICMP6HDR_REDIRECT_SIZE) - { + if (f->transport_len < PICO_ICMP6HDR_REDIRECT_SIZE) { return -1; } - if (pico_ipv6_is_linklocal(hdr->src.addr) != 1) - { + if (pico_ipv6_is_linklocal(hdr->src.addr) != 1) { return -1; } - if (pico_ipv6_is_multicast(icmp6_hdr->msg.info.redirect.dest.addr)) - { + if (pico_ipv6_is_multicast(icmp6_hdr->msg.info.redirect.dest.addr)) { return -1; } - if (! (pico_ipv6_is_linklocal(icmp6_hdr->msg.info.redirect.target.addr) == 1 || pico_ipv6_compare(&icmp6_hdr->msg.info.redirect.target, &icmp6_hdr->msg.info.redirect.dest) == 0) ) - { + if (!(pico_ipv6_is_linklocal(icmp6_hdr->msg.info.redirect.target.addr) == 1 || pico_ipv6_compare(&icmp6_hdr->msg.info.redirect.target, &icmp6_hdr->msg.info.redirect.dest) == 0)) { return -1; } @@ -2035,7 +2016,7 @@ static int redirect_process(struct pico_frame *f) if (optres_lladdr < 0 || optres_redirect < 0) { /* Malformed packet */ - nd_dbg("Redirect: bad packet options: %d %d\n", optres_lladdr, optres_redirect);; + nd_dbg("Redirect: bad packet options: %d %d\n", optres_lladdr, optres_redirect); return -1; } @@ -2114,14 +2095,12 @@ static int redirect_process(struct pico_frame *f) static int pico_nd_redirect_recv(struct pico_frame *f) { - if (icmp6_initial_checks(f) < 0) - { + if (icmp6_initial_checks(f) < 0) { nd_dbg("Redirect: initial checks failed\n"); return -1; } - if (pico_nd_redirect_is_valid(f) < 0) - { + if (pico_nd_redirect_is_valid(f) < 0) { nd_dbg("Redirect: redirect check failed\n"); return -1; } @@ -2133,11 +2112,11 @@ static void pico_ipv6_nd_timer_elapsed(pico_time now, struct pico_ipv6_neighbor { IGNORE_PARAMETER(now); - switch(n->state) { + switch (n->state) { case PICO_ND_STATE_INCOMPLETE: - /* Fallthrough */ + /* Fallthrough */ case PICO_ND_STATE_INCOMPLETE_SEARCHING: - /* Fallthrough */ + /* Fallthrough */ case PICO_ND_STATE_PROBE: if (n->failure_multi_count >= PICO_ND_MAX_MULTICAST_SOLICIT || n->failure_uni_count >= PICO_ND_MAX_UNICAST_SOLICIT) { @@ -2175,7 +2154,7 @@ static void pico_ipv6_check_ce_callback(pico_time now, void *arg) struct pico_tree_node *index = NULL, *_tmp = NULL; struct pico_ipv6_neighbor *n = NULL; struct pico_ipv6_router *r = NULL; - struct pico_stack *S = (struct pico_stack *)arg; + struct pico_stack *S = (struct pico_stack *)arg; pico_tree_foreach_safe(index, &S->IPV6NCache, _tmp) @@ -2188,14 +2167,14 @@ static void pico_ipv6_check_ce_callback(pico_time now, void *arg) pico_ipv6_nd_timer_elapsed(now, n); } - if(n->is_router) { - r = pico_get_router_from_rcache(S, &n->address); + if (n->is_router) { + r = pico_get_router_from_rcache(S, &n->address); - if (r && now > r->invalidation) { - nd_dbg("ROUTER EXPIRED\n"); - print_nce(r->router); - pico_nd_delete_rce(r); - } + if (r && now > r->invalidation) { + nd_dbg("ROUTER EXPIRED\n"); + print_nce(r->router); + pico_nd_delete_rce(r); + } } } if (!pico_timer_add(S, PICO_NEIGH_CHECK_INTERVAL, pico_ipv6_check_ce_callback, arg)) { @@ -2212,7 +2191,7 @@ void pico_ipv6_nd_ra_timer_callback(pico_time now, void *arg) struct pico_tree_node *rindex = NULL, *devindex = NULL; struct pico_device *dev = (struct pico_device *)arg; struct pico_ipv6_route *rt; - struct pico_ip6 nm64 = { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 } }; + struct pico_ip6 nm64 = { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0 }}; struct pico_stack *stack; pico_time next_timer_expire = 0u; @@ -2254,20 +2233,20 @@ static void pico_ipv6_router_sol_timer(pico_time now, void *arg) struct pico_stack *S = (struct pico_stack *)arg; pico_tree_foreach(index, &S->IPV6Links) { - link = index->keyValue; - if(pico_ipv6_is_linklocal(link->address.addr) && link->rs_retries < MAX_INITIAL_RTR_ADVERTISEMENTS && (link->rs_expire_time < now)) { - route = pico_ipv6_gateway_by_dev(link->dev->stack, link->dev); - if (route != NULL) { - link->rs_retries++; - pico_icmp6_router_solicitation(link->dev,&link->address, &route->gateway); - } else if (link->dev->mode == LL_MODE_ETHERNET) { - /* TODO: is it okay to supply zero as dst addr for 6LOWPAN links? (-->remove above if?) */ - /* dst parameter is ignored for non-6LOWPAN links */ - link->rs_retries++; - pico_icmp6_router_solicitation(link->dev,&link->address, &zero); - } - link->rs_expire_time = PICO_TIME_MS() + 4000; - } + link = index->keyValue; + if (pico_ipv6_is_linklocal(link->address.addr) && link->rs_retries < MAX_INITIAL_RTR_ADVERTISEMENTS && (link->rs_expire_time < now)) { + route = pico_ipv6_gateway_by_dev(link->dev->stack, link->dev); + if (route != NULL) { + link->rs_retries++; + pico_icmp6_router_solicitation(link->dev, &link->address, &route->gateway); + } else if (link->dev->mode == LL_MODE_ETHERNET) { + /* TODO: is it okay to supply zero as dst addr for 6LOWPAN links? (-->remove above if?) */ + /* dst parameter is ignored for non-6LOWPAN links */ + link->rs_retries++; + pico_icmp6_router_solicitation(link->dev, &link->address, &zero); + } + link->rs_expire_time = PICO_TIME_MS() + 4000; + } } if (!pico_timer_add(link->dev->stack, 1000, pico_ipv6_router_sol_timer, S)) { @@ -2376,7 +2355,7 @@ int pico_ipv6_nd_recv(struct pico_frame *f) struct pico_icmp6_hdr *hdr = (struct pico_icmp6_hdr *)f->transport_hdr; int ret = -1; - switch(hdr->type) { + switch (hdr->type) { case PICO_ICMP6_ROUTER_SOL: nd_dbg("ICMP6: received ROUTER SOL\n"); ret = pico_nd_router_sol_recv(f); diff --git a/modules/pico_ipv6_nd.h b/modules/pico_ipv6_nd.h index 220bc9e2..215c95e2 100644 --- a/modules/pico_ipv6_nd.h +++ b/modules/pico_ipv6_nd.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_ipv6_pmtu.c b/modules/pico_ipv6_pmtu.c index 9f99b2af..74d0c538 100644 --- a/modules/pico_ipv6_pmtu.c +++ b/modules/pico_ipv6_pmtu.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Milan Platisa - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -78,8 +78,7 @@ int pico_ipv6_path_add(struct pico_stack *S, const struct pico_ipv6_path_id *pat pico_tree_insert(&S->IPV6PathCache, new); status = PICO_PMTU_OK; } - } - else { + } else { new->mtu = mtu; new->cache_status = PICO_PMTU_CACHE_NEW; status = PICO_PMTU_OK; @@ -135,10 +134,10 @@ static void pico_ipv6_path_gc(pico_time now, void *arg) struct pico_tree_node *index = NULL, *_tmp = NULL; struct pico_stack *S = (struct pico_stack *)arg; IGNORE_PARAMETER(now); - if(!pico_tree_empty(&S->IPV6PathCache)) { + if (!pico_tree_empty(&S->IPV6PathCache)) { pico_tree_foreach_safe(index, &S->IPV6PathCache, _tmp) { - if(((struct pico_ipv6_path_mtu *)index->keyValue)->cache_status == PICO_PMTU_CACHE_OLD) { + if (((struct pico_ipv6_path_mtu *)index->keyValue)->cache_status == PICO_PMTU_CACHE_OLD) { pico_tree_delete(&S->IPV6PathCache, index->keyValue); } else { ((struct pico_ipv6_path_mtu *)index->keyValue)->cache_status = PICO_PMTU_CACHE_OLD; diff --git a/modules/pico_ipv6_pmtu.h b/modules/pico_ipv6_pmtu.h index a9097d50..6a0f9798 100644 --- a/modules/pico_ipv6_pmtu.h +++ b/modules/pico_ipv6_pmtu.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_mcast.c b/modules/pico_mcast.c index 6f92bca8..1b3a1bdc 100644 --- a/modules/pico_mcast.c +++ b/modules/pico_mcast.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Roel Postelmans - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -70,7 +70,7 @@ #define MCAST_BLOCK_OLD_SOURCES (6) -static void pico_mcast_src_filtering_cleanup(struct mcast_filter_parameters *mcast ) +static void pico_mcast_src_filtering_cleanup(struct mcast_filter_parameters *mcast) { struct pico_tree_node *index = NULL, *_tmp = NULL; /* cleanup filters */ @@ -83,7 +83,7 @@ static void pico_mcast_src_filtering_cleanup(struct mcast_filter_parameters *mca pico_tree_delete(mcast->block, index->keyValue); } } -static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast ) +static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast) { struct pico_tree_node *index = NULL; union pico_address *source; @@ -96,7 +96,7 @@ static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast pico_tree_foreach(index, mcast->p->MCASTFilter) /* B */ { if (pico_tree_insert(mcast->allow, index->keyValue) == &LEAF) { - multicast_dbg("MCAST: Failed to insert entry in tree\n"); + multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; } mcast->sources++; @@ -119,7 +119,7 @@ static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast if (pico_tree_insert(mcast->allow, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } pico_tree_foreach(index, &mcast->g->MCASTSources) /* A */ @@ -141,7 +141,7 @@ static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast if (pico_tree_insert(mcast->block, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } pico_tree_foreach(index, mcast->p->MCASTFilter) /* B */ @@ -160,7 +160,7 @@ static int pico_mcast_src_filtering_inc_inc(struct mcast_filter_parameters*mcast return MCAST_NO_REPORT; } -static int pico_mcast_src_filtering_inc_excl(struct mcast_filter_parameters*mcast ) +static int pico_mcast_src_filtering_inc_excl(struct mcast_filter_parameters*mcast) { struct pico_tree_node *index = NULL; mcast->record_type = MCAST_CHANGE_TO_EXCLUDE_MODE; @@ -170,12 +170,12 @@ static int pico_mcast_src_filtering_inc_excl(struct mcast_filter_parameters*mcas if (pico_tree_insert(mcast->block, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } return 0; } -static int pico_mcast_src_filtering_excl_inc(struct mcast_filter_parameters*mcast ) +static int pico_mcast_src_filtering_excl_inc(struct mcast_filter_parameters*mcast) { struct pico_tree_node *index = NULL; mcast->record_type = MCAST_CHANGE_TO_INCLUDE_MODE; @@ -186,14 +186,14 @@ static int pico_mcast_src_filtering_excl_inc(struct mcast_filter_parameters*mcas if (pico_tree_insert(mcast->allow, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } } /* else { allow stays empty } */ return 0; } -static int pico_mcast_src_filtering_excl_excl(struct mcast_filter_parameters*mcast ) +static int pico_mcast_src_filtering_excl_excl(struct mcast_filter_parameters*mcast) { struct pico_tree_node *index = NULL; struct pico_ip6 *source = NULL; @@ -204,7 +204,7 @@ static int pico_mcast_src_filtering_excl_excl(struct mcast_filter_parameters*mca if (pico_tree_insert(mcast->block, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } @@ -227,7 +227,7 @@ static int pico_mcast_src_filtering_excl_excl(struct mcast_filter_parameters*mca if (pico_tree_insert(mcast->allow, index->keyValue) == &LEAF) { multicast_dbg("MCAST: Failed to insert entry in tree\n"); return -1; - } + } mcast->sources++; } pico_tree_foreach(index, mcast->p->MCASTFilter) /* B */ @@ -266,7 +266,7 @@ int8_t pico_mcast_generate_filter(struct pico_stack *S, struct mcast_filter_para case PICO_IP_MULTICAST_INCLUDE: switch (p->filter_mode) { case PICO_IP_MULTICAST_INCLUDE: - if(pico_mcast_src_filtering_inc_inc(filter) == MCAST_NO_REPORT) + if (pico_mcast_src_filtering_inc_inc(filter) == MCAST_NO_REPORT) return MCAST_NO_REPORT; break; @@ -287,7 +287,7 @@ int8_t pico_mcast_generate_filter(struct pico_stack *S, struct mcast_filter_para break; case PICO_IP_MULTICAST_EXCLUDE: /* BLOCK (B-A) */ - if(pico_mcast_src_filtering_excl_excl(filter) == MCAST_NO_REPORT) + if (pico_mcast_src_filtering_excl_excl(filter) == MCAST_NO_REPORT) return MCAST_NO_REPORT; break; diff --git a/modules/pico_mcast.h b/modules/pico_mcast.h index 4d834106..8d2d3f7c 100644 --- a/modules/pico_mcast.h +++ b/modules/pico_mcast.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_mdns.c b/modules/pico_mdns.c index 3e713e15..93081996 100644 --- a/modules/pico_mdns.c +++ b/modules/pico_mdns.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Toon Stegen, Jelle De Vleeschouwer - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -124,10 +124,8 @@ struct pico_mdns_cookie uint8_t type; /* QUERY/ANNOUNCE/PROBE/ANSWER */ uint8_t status; /* Active status */ uint8_t timeout; /* Timeout counter */ - uint32_t send_timer; /* For sending events */ - void (*callback)(pico_mdns_rtree *, - char *, - void *); /* Callback */ + uint32_t send_timer; /* For sending events */ + void (*callback)(pico_mdns_rtree *, char *, void *); /* Callback */ void *arg; /* Argument to pass to callback */ struct pico_stack *stack; /* Reference to picoTCP stack context */ }; @@ -145,7 +143,7 @@ static struct pico_ip4 inaddr_any = { * they're not. * ****************************************************************************/ int -pico_mdns_record_cmp_name_type( void *a, void *b ) +pico_mdns_record_cmp_name_type(void *a, void *b) { struct pico_mdns_record *_a = NULL, *_b = NULL; @@ -167,7 +165,7 @@ pico_mdns_record_cmp_name_type( void *a, void *b ) * @return 0 when records are equal, returns difference when they're not. * ****************************************************************************/ int -pico_mdns_record_cmp( void *a, void *b ) +pico_mdns_record_cmp(void *a, void *b) { /* Check params */ if (!a || !b) { @@ -192,7 +190,7 @@ pico_mdns_record_cmp( void *a, void *b ) * @return 0 when cookies are equal, returns difference when they're not. * ****************************************************************************/ int -pico_mdns_cookie_cmp( void *ka, void *kb ) +pico_mdns_cookie_cmp(void *ka, void *kb) { struct pico_mdns_cookie *a = (struct pico_mdns_cookie *)ka; struct pico_mdns_cookie *b = (struct pico_mdns_cookie *)kb; @@ -249,21 +247,20 @@ pico_mdns_timer_add(struct pico_stack *S, pico_time expire, /* **************************************************************************** * MARK: PROTOTYPES */ static int -pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg); +pico_mdns_getrecord_generic(struct pico_stack *S, + const char *url, + uint16_t type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); static void -pico_mdns_send_probe_packet(pico_time now, void *arg ); +pico_mdns_send_probe_packet(pico_time now, void *arg); static int -pico_mdns_reclaim(struct pico_stack *S, pico_mdns_rtree rtree, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); +pico_mdns_reclaim(struct pico_stack *S, + pico_mdns_rtree rtree, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* EOF PROTOTYPES * ****************************************************************************/ @@ -278,7 +275,7 @@ pico_mdns_reclaim(struct pico_stack *S, pico_mdns_rtree rtree, * @return Numeric value of suffix on success * ****************************************************************************/ static inline uint16_t -pico_mdns_suffix_to_uint16( char *opening, char *closing) +pico_mdns_suffix_to_uint16(char *opening, char *closing) { uint16_t n = 0; char *i = 0; @@ -315,9 +312,9 @@ pico_mdns_suffix_to_uint16( char *opening, char *closing) * suffix is present. * ****************************************************************************/ static uint16_t -pico_mdns_is_suffix_present( char name[], - char **o_i, - char **c_i ) +pico_mdns_is_suffix_present(char name[], + char **o_i, + char **c_i) { char *i = NULL; uint16_t n = 0; @@ -352,7 +349,7 @@ pico_mdns_is_suffix_present( char name[], * @param s String to convert to * @return void * ****************************************************************************/ -static void pico_itoa( uint16_t n, char s[] ) +static void pico_itoa(uint16_t n, char s[]) { int i = 0, j = 0; char c = 0; @@ -378,7 +375,7 @@ static void pico_itoa( uint16_t n, char s[] ) * @return Newly created FQDN with suffix appended to first label. * ****************************************************************************/ static char * -pico_mdns_resolve_name_conflict( char rname[] ) +pico_mdns_resolve_name_conflict(char rname[]) { char *new_rname = NULL; char suffix[5] = { @@ -446,12 +443,12 @@ pico_mdns_resolve_name_conflict( char rname[] ) * failure. * ****************************************************************************/ static struct pico_dns_question * -pico_mdns_question_create( const char *url, - uint16_t *len, - uint8_t proto, - uint16_t qtype, - uint8_t flags, - uint8_t reverse ) +pico_mdns_question_create(const char *url, + uint16_t *len, + uint8_t proto, + uint16_t qtype, + uint8_t flags, + uint8_t reverse) { uint16_t qclass = PICO_DNS_CLASS_IN; @@ -477,7 +474,7 @@ pico_mdns_question_create( const char *url, * @return Pointer to copied mDNS resource record * ****************************************************************************/ static struct pico_mdns_record * -pico_mdns_record_copy( struct pico_mdns_record *record ) +pico_mdns_record_copy(struct pico_mdns_record *record) { struct pico_mdns_record *copy = NULL; @@ -516,9 +513,9 @@ pico_mdns_record_copy( struct pico_mdns_record *record ) * @return Tree with found hits, can possibly be empty * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_rtree_find_name( pico_mdns_rtree *tree, - const char *name, - uint8_t copy ) +pico_mdns_rtree_find_name(pico_mdns_rtree *tree, + const char *name, + uint8_t copy) { PICO_MDNS_RTREE_DECLARE(hits); struct pico_tree_node *node = NULL; @@ -559,10 +556,10 @@ pico_mdns_rtree_find_name( pico_mdns_rtree *tree, * @return Tree with found hits, can possibly be empty. * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_rtree_find_name_type( pico_mdns_rtree *tree, - char *name, - uint16_t rtype, - uint8_t copy ) +pico_mdns_rtree_find_name_type(pico_mdns_rtree *tree, + char *name, + uint16_t rtype, + uint8_t copy) { PICO_MDNS_RTREE_DECLARE(hits); @@ -596,13 +593,13 @@ pico_mdns_rtree_find_name_type( pico_mdns_rtree *tree, if (copy) record = pico_mdns_record_copy(record); - if (record){ + if (record) { if (pico_tree_insert(&hits, record) != NULL) { /* either key was already in there, or couldn't be inserted. */ /* Only delete record if it was copied */ if (copy) pico_mdns_record_delete((void **)&record); - } + } } } } @@ -618,8 +615,8 @@ pico_mdns_rtree_find_name_type( pico_mdns_rtree *tree, * @return 0 on success, something else on failure. * ****************************************************************************/ static int -pico_mdns_rtree_del_name( pico_mdns_rtree *tree, - const char *name ) +pico_mdns_rtree_del_name(pico_mdns_rtree *tree, + const char *name) { struct pico_tree_node *node = NULL, *safe = NULL; struct pico_mdns_record *record = NULL; @@ -653,9 +650,9 @@ pico_mdns_rtree_del_name( pico_mdns_rtree *tree, * ****************************************************************************/ #if PICO_MDNS_ALLOW_CACHING == 1 static int -pico_mdns_rtree_del_name_type( pico_mdns_rtree *tree, - char *name, - uint16_t type ) +pico_mdns_rtree_del_name_type(pico_mdns_rtree *tree, + char *name, + uint16_t type) { struct pico_tree_node *node = NULL, *next = NULL; struct pico_mdns_record *record = NULL; @@ -703,8 +700,8 @@ pico_mdns_rtree_del_name_type( pico_mdns_rtree *tree, * @return Pointer to the copy on success, NULL-pointer on failure. * ****************************************************************************/ static struct pico_mdns_record * -pico_mdns_record_copy_with_new_name( struct pico_mdns_record *record, - const char *new_rname ) +pico_mdns_record_copy_with_new_name(struct pico_mdns_record *record, + const char *new_rname) { struct pico_mdns_record *copy = NULL; uint16_t slen = (uint16_t)(pico_dns_strlen(new_rname) + 1u); @@ -745,9 +742,9 @@ pico_mdns_record_copy_with_new_name( struct pico_mdns_record *record, * @return A mDNS record tree that contains all the newly generated records. * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_generate_new_records(struct pico_stack *S, pico_mdns_rtree *conflict_records, - char *conflict_name, - char *new_name ) +pico_mdns_generate_new_records(struct pico_stack *S, pico_mdns_rtree *conflict_records, + char *conflict_name, + char *new_name) { PICO_MDNS_RTREE_DECLARE(new_records); struct pico_tree_node *node = NULL, *next = NULL; @@ -773,10 +770,10 @@ pico_mdns_generate_new_records(struct pico_stack *S, pico_mdns_rtree *conflict_ /* Add the record to the new tree */ if (pico_tree_insert(&new_records, new_record)) { - mdns_dbg("Could not add new non-conflicting record to the tree!\n"); + mdns_dbg("Could not add new non-conflicting record to the tree!\n"); pico_mdns_record_delete((void **)&new_record); - return new_records; - } + return new_records; + } /* Delete the old conflicting record */ record = pico_tree_delete(conflict_records, record); @@ -801,8 +798,8 @@ pico_mdns_generate_new_records(struct pico_stack *S, pico_mdns_rtree *conflict_ * @return 0 when the resolving is applied successfully, 1 otherwise. * ****************************************************************************/ static int -pico_mdns_record_resolve_conflict( struct pico_mdns_record *record, - char *rname ) +pico_mdns_record_resolve_conflict(struct pico_mdns_record *record, + char *rname) { int retval; PICO_MDNS_RTREE_DECLARE(new_records); @@ -822,12 +819,12 @@ pico_mdns_record_resolve_conflict( struct pico_mdns_record *record, copy = pico_mdns_record_copy_with_new_name(record, new_name); PICO_FREE(new_name); - if (copy){ - if (pico_tree_insert(&new_records, copy)) { + if (copy) { + if (pico_tree_insert(&new_records, copy)) { mdns_dbg("MDNS: Failed to insert copy in tree\n"); pico_mdns_record_delete((void **)©); return -1; - } + } } /* Copy stack pointer for later use */ @@ -853,8 +850,8 @@ pico_mdns_record_resolve_conflict( struct pico_mdns_record *record, * @return positive value when my record is lexicographically later * ****************************************************************************/ static int -pico_mdns_record_am_i_lexi_later( struct pico_mdns_record *my_record, - struct pico_mdns_record *peer_record) +pico_mdns_record_am_i_lexi_later(struct pico_mdns_record *my_record, + struct pico_mdns_record *peer_record) { struct pico_dns_record *my = NULL, *peer = NULL; uint16_t mclass = 0, pclass = 0, mtype = 0, ptype = 0; @@ -913,7 +910,7 @@ pico_mdns_record_am_i_lexi_later( struct pico_mdns_record *my_record, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_mdns_record_delete( void **record ) +pico_mdns_record_delete(void **record) { struct pico_mdns_record **rr = (struct pico_mdns_record **)record; @@ -939,7 +936,7 @@ pico_mdns_record_delete( void **record ) * Creates a single standalone mDNS resource record with given name, type and * data. * - * @param S TCP/IP stack reference + * @param S TCP/IP stack reference * @param url DNS rrecord name in URL format. Will be converted to DNS * name notation format. * @param _rdata Memory buffer with data to insert in the resource record. If @@ -958,12 +955,12 @@ pico_mdns_record_delete( void **record ) * ****************************************************************************/ struct pico_mdns_record * pico_mdns_record_create(struct pico_stack *S, - const char *url, - void *_rdata, - uint16_t datalen, - uint16_t rtype, - uint32_t rttl, - uint8_t flags ) + const char *url, + void *_rdata, + uint16_t datalen, + uint16_t rtype, + uint32_t rttl, + uint8_t flags) { struct pico_mdns_record *record = NULL; uint16_t len = 0; @@ -983,14 +980,14 @@ pico_mdns_record_create(struct pico_stack *S, else { /* Try to create the actual DNS record */ if (!(record->record = pico_dns_record_create(S, url, _rdata, datalen, - &len, rtype, - PICO_DNS_CLASS_IN, rttl))) { + &len, rtype, + PICO_DNS_CLASS_IN, rttl))) { mdns_dbg("Could not create DNS record for mDNS!\n"); PICO_FREE(record); return NULL; } /* Block 3, 2 paths */ } /* Block 4, Block 3 = 2 paths */ - /* Block 5, (Block 4 + Block 2) * Block 1 = 6 paths */ + /* Block 5, (Block 4 + Block 2) * Block 1 = 6 paths */ /* Initialise fields */ record->current_ttl = rttl; @@ -1001,7 +998,7 @@ pico_mdns_record_create(struct pico_stack *S, cl = record->record->rsuffix->rclass; record->record->rsuffix->rclass = PICO_MDNS_SET_MSB_BE(cl); } /* Block 6, 2 paths */ - /* Block 7, Block 6 * Block 5 * Block 1 = 12 paths */ + /* Block 7, Block 6 * Block 5 * Block 1 = 12 paths */ record->flags = flags; record->claim_id = 0; @@ -1020,7 +1017,7 @@ pico_mdns_record_create(struct pico_stack *S, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ static int -pico_mdns_cookie_delete( void **ptr ) +pico_mdns_cookie_delete(void **ptr) { struct pico_mdns_cookie **c = (struct pico_mdns_cookie **)ptr; @@ -1045,7 +1042,7 @@ pico_mdns_cookie_delete( void **ptr ) /* **************************************************************************** * Creates a single standalone mDNS cookie * - * @param S TCP/IP stack reference + * @param S TCP/IP stack reference * @param qtree DNS questions you want to insert in the cookie. * @param antree mDNS answers/authority records you want to add to cookie. * @param artree mDNS additional records you want to add to cookie. @@ -1055,16 +1052,14 @@ pico_mdns_cookie_delete( void **ptr ) * @return Pointer to newly create cookie, NULL on failure. * ****************************************************************************/ static struct pico_mdns_cookie * -pico_mdns_cookie_create( struct pico_stack *S, - pico_dns_qtree qtree, - pico_mdns_rtree antree, - pico_mdns_rtree artree, - uint8_t count, - uint8_t type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_cookie_create(struct pico_stack *S, + pico_dns_qtree qtree, + pico_mdns_rtree antree, + pico_mdns_rtree artree, + uint8_t count, + uint8_t type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { struct pico_mdns_cookie *cookie = NULL; /* Packet cookie to send */ @@ -1098,8 +1093,8 @@ pico_mdns_cookie_create( struct pico_stack *S, * @return 0 when SPT is applied correctly, -1 otherwise. * ****************************************************************************/ static int -pico_mdns_cookie_apply_spt( struct pico_mdns_cookie *cookie, - struct pico_dns_record *answer) +pico_mdns_cookie_apply_spt(struct pico_mdns_cookie *cookie, + struct pico_dns_record *answer) { struct pico_mdns_record *my_record = NULL; struct pico_mdns_record peer_record; @@ -1128,7 +1123,7 @@ pico_mdns_cookie_apply_spt( struct pico_mdns_cookie *cookie, cookie->timeout = PICO_MDNS_COOKIE_TIMEOUT; cookie->count = PICO_MDNS_PROBE_COUNT; cookie->send_timer = pico_mdns_timer_add(cookie->stack, 1000, pico_mdns_send_probe_packet, - cookie); + cookie); if (!cookie->send_timer) { mdns_dbg("cookie_apply_spt: failed to start timer\n"); return -1; @@ -1140,8 +1135,8 @@ pico_mdns_cookie_apply_spt( struct pico_mdns_cookie *cookie, } static int -pico_mdns_cookie_del_questions( struct pico_mdns_cookie *cookie, - char *rname ) +pico_mdns_cookie_del_questions(struct pico_mdns_cookie *cookie, + char *rname) { uint16_t qc = 0; @@ -1170,8 +1165,8 @@ pico_mdns_cookie_del_questions( struct pico_mdns_cookie *cookie, * @return Returns 0 on success, something else on failure. * ****************************************************************************/ static int -pico_mdns_cookie_resolve_conflict( struct pico_mdns_cookie *cookie, - char *rname ) +pico_mdns_cookie_resolve_conflict(struct pico_mdns_cookie *cookie, + char *rname) { struct pico_tree_node *node = NULL; struct pico_dns_question *question = NULL; @@ -1240,7 +1235,7 @@ pico_mdns_cookie_resolve_conflict( struct pico_mdns_cookie *cookie, * @return Pointer to cookie in tree when one is found, NULL on failure. * ****************************************************************************/ static struct pico_mdns_cookie * -pico_mdns_ctree_find_cookie(struct pico_stack *S, const char *name, uint8_t type ) +pico_mdns_ctree_find_cookie(struct pico_stack *S, const char *name, uint8_t type) { struct pico_mdns_cookie *cookie = NULL; struct pico_tree_node *node = NULL; @@ -1277,7 +1272,7 @@ pico_mdns_ctree_find_cookie(struct pico_stack *S, const char *name, uint8_t type * @return 0 on success, something else on failure. * ****************************************************************************/ static int -pico_mdns_my_records_add( pico_mdns_rtree *records, uint8_t reclaim ) +pico_mdns_my_records_add(pico_mdns_rtree *records, uint8_t reclaim) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL; @@ -1304,7 +1299,7 @@ pico_mdns_my_records_add( pico_mdns_rtree *records, uint8_t reclaim ) if (pico_tree_insert(&record->stack->MDNSOwnRecords, record) == &LEAF) { mdns_dbg("MDNS: Failed to insert record in tree\n"); return -1; - } + } } } return 0; @@ -1378,8 +1373,8 @@ pico_mdns_my_records_find_to_probe(struct pico_stack *S) * @return 1 when all S->MDNSOwnRecords with claim ID are probed, 0 when they're not. * ****************************************************************************/ static uint8_t -pico_mdns_my_records_claimed_id(struct pico_stack *S, uint8_t claim_id, - pico_mdns_rtree *reg_records ) +pico_mdns_my_records_claimed_id(struct pico_stack *S, uint8_t claim_id, + pico_mdns_rtree *reg_records) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL; @@ -1392,7 +1387,7 @@ pico_mdns_my_records_claimed_id(struct pico_stack *S, uint8_t claim_id, if (pico_tree_insert(reg_records, record) == &LEAF) { mdns_dbg("MDNS: Failed to insert record in tree\n"); return 0; - } + } } else { return 0; } @@ -1414,11 +1409,10 @@ pico_mdns_my_records_claimed_id(struct pico_stack *S, uint8_t claim_id, * @return Returns 0 when everything went smooth, something else otherwise. * ****************************************************************************/ static int -pico_mdns_my_records_claimed(struct pico_stack *S, pico_mdns_rtree rtree, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_my_records_claimed(struct pico_stack *S, + pico_mdns_rtree rtree, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { PICO_MDNS_RTREE_DECLARE(claimed_records); struct pico_mdns_record *record = NULL, *myrecord = NULL; @@ -1458,7 +1452,7 @@ pico_mdns_my_records_claimed(struct pico_stack *S, pico_mdns_rtree rtree, * @param records mDNS records which are probed. * ****************************************************************************/ static void -pico_mdns_my_records_probed( pico_mdns_rtree *records ) +pico_mdns_my_records_probed(pico_mdns_rtree *records) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL, *found = NULL; @@ -1473,13 +1467,13 @@ pico_mdns_my_records_probed( pico_mdns_rtree *records ) PICO_FREE(record->stack->mdns_hostname); } /* Re-allocate hostname from given rname */ - record->stack->mdns_hostname = + record->stack->mdns_hostname = pico_dns_qname_to_url(found->record->rname); } PICO_MDNS_CLR_FLAG(found->flags, PICO_MDNS_RECORD_CURRENTLY_PROBING); PICO_MDNS_SET_FLAG(found->flags, PICO_MDNS_RECORD_PROBED); - } else{ + } else { mdns_dbg("Could not find my corresponding record...\n"); } } @@ -1497,10 +1491,10 @@ pico_mdns_my_records_probed( pico_mdns_rtree *records ) * @return void * ****************************************************************************/ static inline void -pico_mdns_cache_update_ttl( struct pico_mdns_record *record, - uint32_t ttl ) +pico_mdns_cache_update_ttl(struct pico_mdns_record *record, + uint32_t ttl) { - if(ttl > 0) { + if (ttl > 0) { /* Update the TTL's */ record->record->rsuffix->rttl = long_be(ttl); record->current_ttl = ttl; @@ -1512,7 +1506,7 @@ pico_mdns_cache_update_ttl( struct pico_mdns_record *record, } static int -pico_mdns_cache_flush_name(struct pico_stack *S, char *name, struct pico_dns_record_suffix *suffix ) +pico_mdns_cache_flush_name(struct pico_stack *S, char *name, struct pico_dns_record_suffix *suffix) { /* Check if cache flush bit is set */ if (PICO_MDNS_IS_MSB_SET(short_be(suffix->rclass))) { @@ -1534,7 +1528,7 @@ pico_mdns_cache_flush_name(struct pico_stack *S, char *name, struct pico_dns_re * rribly wrong... * ****************************************************************************/ static int -pico_mdns_cache_add( struct pico_mdns_record *record ) +pico_mdns_cache_add(struct pico_mdns_record *record) { struct pico_dns_record_suffix *suffix = NULL; char *name = NULL; @@ -1581,7 +1575,7 @@ pico_mdns_cache_add( struct pico_mdns_record *record ) * @return 0 on grrrreat success, something else on awkward failure. * ****************************************************************************/ static int -pico_mdns_cache_add_record(struct pico_stack *S, struct pico_mdns_record *record ) +pico_mdns_cache_add_record(struct pico_stack *S, struct pico_mdns_record *record) { struct pico_mdns_record *found = NULL, *copy = NULL; uint32_t rttl = 0; @@ -1616,8 +1610,8 @@ pico_mdns_cache_add_record(struct pico_stack *S, struct pico_mdns_record *recor * @return 1 when Current TTL is at refresh point. 0 when it's not. * ****************************************************************************/ static int -pico_mdns_ttl_at_refresh_time( uint32_t original, - uint32_t current ) +pico_mdns_ttl_at_refresh_time(uint32_t original, + uint32_t current) { uint32_t rnd = 0; rnd = pico_rand() % 3; @@ -1715,7 +1709,7 @@ pico_mdns_cookies_check_timeouts(struct pico_stack *S) * @param _arg Ignore * ****************************************************************************/ static void -pico_mdns_tick( pico_time now, void *arg ) +pico_mdns_tick(pico_time now, void *arg) { struct pico_stack *S = (struct pico_stack *)arg; IGNORE_PARAMETER(now); @@ -1747,7 +1741,7 @@ pico_mdns_tick( pico_time now, void *arg ) * picoTCP. Doesn't mean the packet is successfully sent on the wire. * ****************************************************************************/ static int -pico_mdns_send_packet(struct pico_stack *S, pico_dns_packet *packet, uint16_t len ) +pico_mdns_send_packet(struct pico_stack *S, pico_dns_packet *packet, uint16_t len) { struct pico_ip4 dst4; uint32_t ipaddr; @@ -1772,9 +1766,9 @@ pico_mdns_send_packet(struct pico_stack *S, pico_dns_packet *packet, uint16_t l * picoTCP. Doesn't mean the packet is successfully send on the wire. * ****************************************************************************/ static int -pico_mdns_send_packet_unicast(struct pico_stack *S, pico_dns_packet *packet, - uint16_t len, - struct pico_ip4 peer ) +pico_mdns_send_packet_unicast(struct pico_stack *S, pico_dns_packet *packet, + uint16_t len, + struct pico_ip4 peer) { /* Send packet to IPv4 socket */ return pico_socket_sendto(S->mdns_sock_ipv4, packet, (int)len, &peer, @@ -1790,9 +1784,9 @@ pico_mdns_send_packet_unicast(struct pico_stack *S, pico_dns_packet *packet, * @return 0 when the packet is properly send, something else otherwise. * ****************************************************************************/ static int -pico_mdns_unicast_reply(struct pico_stack *S, pico_dns_rtree *unicast_tree, - pico_dns_rtree *artree, - struct pico_ip4 peer ) +pico_mdns_unicast_reply(struct pico_stack *S, pico_dns_rtree *unicast_tree, + pico_dns_rtree *artree, + struct pico_ip4 peer) { union pico_address *local_addr = NULL; pico_dns_packet *packet = NULL; @@ -1848,8 +1842,8 @@ pico_mdns_unicast_reply(struct pico_stack *S, pico_dns_rtree *unicast_tree, * @return 0 when the packet is properly send, something else otherwise. * ****************************************************************************/ static int -pico_mdns_multicast_reply(struct pico_stack *S, pico_dns_rtree *multicast_tree, - pico_dns_rtree *artree ) +pico_mdns_multicast_reply(struct pico_stack *S, pico_dns_rtree *multicast_tree, + pico_dns_rtree *artree) { pico_dns_packet *packet = NULL; uint16_t len = 0; @@ -1896,7 +1890,7 @@ pico_mdns_multicast_reply(struct pico_stack *S, pico_dns_rtree *multicast_tree, * @return Returns 0 when properly merged, or not... * ****************************************************************************/ static int -pico_tree_merge( struct pico_tree *dest, struct pico_tree *src ) +pico_tree_merge(struct pico_tree *dest, struct pico_tree *src) { struct pico_tree_node *node = NULL; @@ -1912,7 +1906,7 @@ pico_tree_merge( struct pico_tree *dest, struct pico_tree *src ) if (pico_tree_insert(dest, node->keyValue) == &LEAF) { mdns_dbg("MDNS: Failed to insert record in tree\n"); return -1; - } + } } } @@ -1929,7 +1923,7 @@ pico_tree_merge( struct pico_tree *dest, struct pico_tree *src ) * @return mDNS record tree with possible answers from S->MDNSOwnRecords * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_populate_antree(struct pico_stack *S, char *name, uint16_t qtype, uint16_t qclass ) +pico_mdns_populate_antree(struct pico_stack *S, char *name, uint16_t qtype, uint16_t qclass) { PICO_MDNS_RTREE_DECLARE(antree); struct pico_tree_node *node = NULL, *next; @@ -1970,8 +1964,8 @@ pico_mdns_populate_antree(struct pico_stack *S, char *name, uint16_t qtype, uin * be empty. * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_handle_single_question( struct pico_dns_question *question, - pico_dns_packet *packet ) +pico_mdns_handle_single_question(struct pico_dns_question *question, + pico_dns_packet *packet) { struct pico_mdns_cookie *cookie = NULL; PICO_MDNS_RTREE_DECLARE(antree); @@ -1991,7 +1985,7 @@ pico_mdns_handle_single_question( struct pico_dns_question *question, /* Find currently active query cookie */ if ((cookie = pico_mdns_ctree_find_cookie(question->stack, question->qname, - PICO_MDNS_PACKET_TYPE_QUERY))) { + PICO_MDNS_PACKET_TYPE_QUERY))) { mdns_dbg("Query cookie found for question, suppress duplicate.\n"); cookie->status = PICO_MDNS_COOKIE_STATUS_CANCELLED; } else { @@ -2015,8 +2009,8 @@ pico_mdns_handle_single_question( struct pico_dns_question *question, * @return Returns 0 when handling went OK, something else when it didn't. * ****************************************************************************/ static int -pico_mdns_handle_cookie_with_answer( struct pico_mdns_cookie *cookie, - struct pico_mdns_record *answer ) +pico_mdns_handle_cookie_with_answer(struct pico_mdns_cookie *cookie, + struct pico_mdns_record *answer) { PICO_MDNS_RTREE_DECLARE(antree); uint8_t type = 0, status = 0; @@ -2040,7 +2034,7 @@ pico_mdns_handle_cookie_with_answer( struct pico_mdns_cookie *cookie, if (pico_tree_insert(&antree, answer) == &LEAF) { mdns_dbg("MDNS: Failed to insert answer in tree\n"); return -1; - } + } cookie->callback(&antree, NULL, cookie->arg); } } else { /* Don't handle answer cookies with answer */ @@ -2057,7 +2051,7 @@ pico_mdns_handle_cookie_with_answer( struct pico_mdns_cookie *cookie, * @return 0 when answer is properly handled, something else when it's not. * ****************************************************************************/ static int -pico_mdns_handle_single_answer(struct pico_stack *S, struct pico_mdns_record *answer ) +pico_mdns_handle_single_answer(struct pico_stack *S, struct pico_mdns_record *answer) { struct pico_mdns_cookie *found = NULL; struct pico_mdns_record *record = NULL; @@ -2089,7 +2083,7 @@ pico_mdns_handle_single_answer(struct pico_stack *S, struct pico_mdns_record *a * @return 0 when authority is properly handled. -1 when it's not. * ****************************************************************************/ static int -pico_mdns_handle_single_authority(struct pico_stack *S, struct pico_mdns_record *answer ) +pico_mdns_handle_single_authority(struct pico_stack *S, struct pico_mdns_record *answer) { struct pico_mdns_cookie *found = NULL; char *name = NULL; @@ -2117,7 +2111,7 @@ pico_mdns_handle_single_authority(struct pico_stack *S, struct pico_mdns_record * @return 0 * ****************************************************************************/ static int -pico_mdns_handle_single_additional(struct pico_stack *S, struct pico_mdns_record *answer ) +pico_mdns_handle_single_additional(struct pico_stack *S, struct pico_mdns_record *answer) { /* Don't need this for now ... */ IGNORE_PARAMETER(S); @@ -2137,10 +2131,10 @@ pico_mdns_handle_single_additional(struct pico_stack *S, struct pico_mdns_recor * @return Tree with possible responses on the questions. * ****************************************************************************/ static pico_mdns_rtree -pico_mdns_handle_data_as_questions ( struct pico_stack *S, - uint8_t **ptr, - uint16_t qdcount, - pico_dns_packet *packet ) +pico_mdns_handle_data_as_questions (struct pico_stack *S, + uint8_t **ptr, + uint16_t qdcount, + pico_dns_packet *packet) { PICO_MDNS_RTREE_DECLARE(antree); PICO_MDNS_RTREE_DECLARE(rtree); @@ -2181,10 +2175,10 @@ pico_mdns_handle_data_as_questions ( struct pico_stack *S, static int pico_mdns_handle_data_as_answers_generic(struct pico_stack *S, - uint8_t **ptr, - uint16_t count, - pico_dns_packet *packet, - uint8_t type ) + uint8_t **ptr, + uint16_t count, + pico_dns_packet *packet, + uint8_t type) { struct pico_mdns_record mdns_answer = { .record = NULL, .current_ttl = 0, @@ -2226,18 +2220,18 @@ pico_mdns_handle_data_as_answers_generic(struct pico_stack *S, /* Handle a single answer */ switch (type) { - case 1: - pico_mdns_handle_single_authority(S, &mdns_answer); - break; - case 2: - pico_mdns_handle_single_additional(S, &mdns_answer); - break; - default: - pico_mdns_handle_single_answer(S, &mdns_answer); + case 1: + pico_mdns_handle_single_authority(S, &mdns_answer); + break; + case 2: + pico_mdns_handle_single_additional(S, &mdns_answer); + break; + default: + pico_mdns_handle_single_answer(S, &mdns_answer); #if PICO_MDNS_ALLOW_CACHING == 1 - pico_mdns_cache_add_record(S, &mdns_answer); + pico_mdns_cache_add_record(S, &mdns_answer); #endif - break; + break; } /* Free decompressed name and mDNS record */ @@ -2261,9 +2255,9 @@ pico_mdns_handle_data_as_answers_generic(struct pico_stack *S, * @return 0 when the tree is properly split up. * ****************************************************************************/ static int -pico_mdns_sort_unicast_multicast( pico_mdns_rtree *answers, - pico_dns_rtree *unicast_tree, - pico_dns_rtree *multicast_tree ) +pico_mdns_sort_unicast_multicast(pico_mdns_rtree *answers, + pico_dns_rtree *unicast_tree, + pico_dns_rtree *multicast_tree) { struct pico_mdns_record *record = NULL; struct pico_tree_node *node = NULL; @@ -2278,18 +2272,18 @@ pico_mdns_sort_unicast_multicast( pico_mdns_rtree *answers, record = node->keyValue; if ((record = node->keyValue)) { if (IS_UNICAST_REQUESTED(record)) { - if (record->record){ - if (pico_tree_insert(unicast_tree, record->record) == &LEAF) { + if (record->record) { + if (pico_tree_insert(unicast_tree, record->record) == &LEAF) { mdns_dbg("MDNS: Failed to insert unicast record in tree\n"); return -1; - } + } } } else { - if (record->record){ - if (pico_tree_insert(multicast_tree, record->record) == &LEAF) { + if (record->record) { + if (pico_tree_insert(multicast_tree, record->record) == &LEAF) { mdns_dbg("MDNS: Failed to insert multicast record in tree\n"); return -1; - } + } } } } @@ -2299,7 +2293,7 @@ pico_mdns_sort_unicast_multicast( pico_mdns_rtree *answers, } static uint16_t -pico_mdns_nsec_highest_type( pico_mdns_rtree *rtree ) +pico_mdns_nsec_highest_type(pico_mdns_rtree *rtree) { struct pico_tree_node *node = NULL, *next = NULL; struct pico_mdns_record *record = NULL; @@ -2319,7 +2313,7 @@ pico_mdns_nsec_highest_type( pico_mdns_rtree *rtree ) } static void -pico_mdns_nsec_gen_bitmap( uint8_t *ptr, pico_mdns_rtree *rtree ) +pico_mdns_nsec_gen_bitmap(uint8_t *ptr, pico_mdns_rtree *rtree) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL; @@ -2341,7 +2335,7 @@ pico_mdns_nsec_gen_bitmap( uint8_t *ptr, pico_mdns_rtree *rtree ) * @return Pointer to newly created NSEC record on success, NULL on failure. * ****************************************************************************/ static struct pico_mdns_record * -pico_mdns_gen_nsec_record(struct pico_stack *S, char *name ) +pico_mdns_gen_nsec_record(struct pico_stack *S, char *name) { PICO_MDNS_RTREE_DECLARE(rtree); struct pico_mdns_record *record = NULL; @@ -2404,8 +2398,8 @@ pico_mdns_gen_nsec_record(struct pico_stack *S, char *name ) * or a new one is generated doesn't matter. * ****************************************************************************/ static int -pico_mdns_additionals_add_nsec(struct pico_stack *S, pico_mdns_rtree *artree, - char *name ) +pico_mdns_additionals_add_nsec(struct pico_stack *S, pico_mdns_rtree *artree, + char *name) { struct pico_mdns_record *record = NULL, *nsec = NULL; struct pico_tree_node *node = NULL; @@ -2446,7 +2440,7 @@ pico_mdns_additionals_add_nsec(struct pico_stack *S, pico_mdns_rtree *artree, * something else on failure. * ****************************************************************************/ static int -pico_mdns_additionals_add_host(struct pico_stack *S, pico_mdns_rtree *artree ) +pico_mdns_additionals_add_host(struct pico_stack *S, pico_mdns_rtree *artree) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL, *copy = NULL; @@ -2466,7 +2460,7 @@ pico_mdns_additionals_add_host(struct pico_stack *S, pico_mdns_rtree *artree ) } /* Static path count: 4 */ static void -pico_rtree_add_copy( pico_mdns_rtree *tree, struct pico_mdns_record *record ) +pico_rtree_add_copy(pico_mdns_rtree *tree, struct pico_mdns_record *record) { struct pico_mdns_record *copy = NULL; @@ -2492,16 +2486,16 @@ pico_rtree_add_copy( pico_mdns_rtree *tree, struct pico_mdns_record *record ) * @return 0 When additional records are properly generated * ****************************************************************************/ static int -pico_mdns_gather_service_meta(struct pico_stack *S, pico_mdns_rtree *antree, - pico_mdns_rtree *artree, - struct pico_mdns_record *srv_record ) +pico_mdns_gather_service_meta(struct pico_stack *S, pico_mdns_rtree *antree, + pico_mdns_rtree *artree, + struct pico_mdns_record *srv_record) { struct pico_mdns_record *ptr_record = NULL, *meta_record = NULL; char *sin = NULL, *service = NULL; uint32_t ttl = 0; /* Generate proper service instance name and service */ - sin = pico_dns_qname_to_url(srv_record->record->rname); // May be leaking + sin = pico_dns_qname_to_url(srv_record->record->rname); /* May be leaking */ if (!antree || !artree || !sin) { pico_err = PICO_ERR_EINVAL; @@ -2516,16 +2510,16 @@ pico_mdns_gather_service_meta(struct pico_stack *S, pico_mdns_rtree *antree, /* Generate PTR records */ ptr_record = pico_mdns_record_create(S, service, (void *)sin, - (uint16_t)strlen(sin), - PICO_DNS_TYPE_PTR, - ttl, PICO_MDNS_RECORD_SHARED); + (uint16_t)strlen(sin), + PICO_DNS_TYPE_PTR, + ttl, PICO_MDNS_RECORD_SHARED); /* Meta DNS-SD record */ meta_record = pico_mdns_record_create(S, "_services._dns-sd._udp.local", - (void *)service, - (uint16_t)strlen(service), - PICO_DNS_TYPE_PTR, - ttl, PICO_MDNS_RECORD_SHARED); - PICO_FREE(sin); // Free allocated memory + (void *)service, + (uint16_t)strlen(service), + PICO_DNS_TYPE_PTR, + ttl, PICO_MDNS_RECORD_SHARED); + PICO_FREE(sin); /* Free allocated memory */ if (!meta_record || !ptr_record) { mdns_dbg("Could not generate META or PTR records!\n"); pico_mdns_record_delete((void **)&ptr_record); @@ -2542,7 +2536,7 @@ pico_mdns_gather_service_meta(struct pico_stack *S, pico_mdns_rtree *antree, pico_rtree_add_copy(antree, meta_record); pico_rtree_add_copy(antree, ptr_record); - /* Insert the created service record in S->MDNSOwnRecords, alread in, destroy */ + /* Insert the created service record in S->MDNSOwnRecords, already in, destroy */ if (pico_tree_insert(&S->MDNSOwnRecords, meta_record)) { mdns_dbg("MDNS: Failed to insert meta record in tree\n"); pico_mdns_record_delete((void **)&meta_record); @@ -2569,8 +2563,8 @@ pico_mdns_gather_service_meta(struct pico_stack *S, pico_mdns_rtree *antree, * @return Returns 0 when additionals are properly generated and added * ****************************************************************************/ static int -pico_mdns_gather_additionals(struct pico_stack *S, pico_mdns_rtree *antree, - pico_mdns_rtree *artree ) +pico_mdns_gather_additionals(struct pico_stack *S, pico_mdns_rtree *antree, + pico_mdns_rtree *artree) { struct pico_tree_node *node = NULL; struct pico_mdns_record *record = NULL; @@ -2593,7 +2587,7 @@ pico_mdns_gather_additionals(struct pico_stack *S, pico_mdns_rtree *antree, pico_tree_foreach(node, antree) { if ((record = node->keyValue) && IS_UNIQUE_RECORD(record) && (ret = pico_mdns_additionals_add_nsec(S, artree, - record->record->rname))) + record->record->rname))) return ret; } @@ -2601,7 +2595,7 @@ pico_mdns_gather_additionals(struct pico_stack *S, pico_mdns_rtree *antree, pico_tree_foreach(node, artree) { if ((record = node->keyValue) && IS_UNIQUE_RECORD(record) && (ret = pico_mdns_additionals_add_nsec(S, artree, - record->record->rname))) + record->record->rname))) return ret; } } @@ -2617,7 +2611,7 @@ pico_mdns_gather_additionals(struct pico_stack *S, pico_mdns_rtree *antree, * @return 0 when answers are properly handled, something else otherwise. * ****************************************************************************/ static int -pico_mdns_reply(struct pico_stack *S, pico_mdns_rtree *antree, struct pico_ip4 peer ) +pico_mdns_reply(struct pico_stack *S, pico_mdns_rtree *antree, struct pico_ip4 peer) { PICO_DNS_RTREE_DECLARE(antree_m); PICO_DNS_RTREE_DECLARE(antree_u); @@ -2670,10 +2664,10 @@ pico_mdns_reply(struct pico_stack *S, pico_mdns_rtree *antree, struct pico_ip4 * @return 0 K.A.S. could be properly applied, something else when not. * ****************************************************************************/ static int -pico_mdns_apply_k_a_s( pico_mdns_rtree *rtree, - pico_dns_packet *packet, - uint16_t ancount, - uint8_t **data ) +pico_mdns_apply_k_a_s(pico_mdns_rtree *rtree, + pico_dns_packet *packet, + uint16_t ancount, + uint8_t **data) { struct pico_tree_node *node = NULL, *next = NULL; struct pico_mdns_record *record = NULL, ka = { @@ -2730,7 +2724,7 @@ pico_mdns_apply_k_a_s( pico_mdns_rtree *rtree, * @return Returns 0 when the query packet is properly handled. * ****************************************************************************/ static int -pico_mdns_handle_query_packet(struct pico_stack *S, pico_dns_packet *packet, struct pico_ip4 peer ) +pico_mdns_handle_query_packet(struct pico_stack *S, pico_dns_packet *packet, struct pico_ip4 peer) { PICO_MDNS_RTREE_DECLARE(antree); uint16_t qdcount = 0, ancount = 0; @@ -2770,7 +2764,7 @@ pico_mdns_handle_query_packet(struct pico_stack *S, pico_dns_packet *packet, str * @return Returns 0 when the probe packet is properly handled. * ****************************************************************************/ static int -pico_mdns_handle_probe_packet(struct pico_stack *S, pico_dns_packet *packet, struct pico_ip4 peer ) +pico_mdns_handle_probe_packet(struct pico_stack *S, pico_dns_packet *packet, struct pico_ip4 peer) { PICO_MDNS_RTREE_DECLARE(antree); uint16_t qdcount = 0, nscount = 0; @@ -2804,7 +2798,7 @@ pico_mdns_handle_probe_packet(struct pico_stack *S, pico_dns_packet *packet, st * @return Returns 0 when the response packet is properly handled. * ****************************************************************************/ static int -pico_mdns_handle_response_packet(struct pico_stack *S, pico_dns_packet *packet ) +pico_mdns_handle_response_packet(struct pico_stack *S, pico_dns_packet *packet) { uint8_t *data = NULL; uint16_t ancount = 0; @@ -2832,7 +2826,7 @@ pico_mdns_handle_response_packet(struct pico_stack *S, pico_dns_packet *packet * @return 0 when the packet is properly handled. Something else when it's not * ****************************************************************************/ static int -pico_mdns_recv(struct pico_stack *S, void *buf, int buflen, struct pico_ip4 peer ) +pico_mdns_recv(struct pico_stack *S, void *buf, int buflen, struct pico_ip4 peer) { pico_dns_packet *packet = (pico_dns_packet *) buf; uint16_t qdcount = short_be(packet->qdcount); @@ -2845,7 +2839,7 @@ pico_mdns_recv(struct pico_stack *S, void *buf, int buflen, struct pico_ip4 pee /* ignored. */ /* 18.11: messages received with non-zero Response Codes MUST be silently */ /* ignored */ - if(packet->opcode == 0 && packet->rcode == 0) { + if (packet->opcode == 0 && packet->rcode == 0) { mdns_dbg(">>>>>>> QDcount: %u, ANcount: %u, NScount: %u, ARcount: %u\n", qdcount, ancount, authcount, addcount); @@ -2895,7 +2889,7 @@ pico_mdns_recv(struct pico_stack *S, void *buf, int buflen, struct pico_ip4 pee * @param s Socket on which the event occurred * ****************************************************************************/ static void -pico_mdns_event4( uint16_t ev, struct pico_socket *s ) +pico_mdns_event4(uint16_t ev, struct pico_socket *s) { char *recvbuf = NULL; struct pico_ip4 peer = { @@ -2914,8 +2908,8 @@ pico_mdns_event4( uint16_t ev, struct pico_socket *s ) } /* Receive while data is available in socket buffer */ - while((pico_read = pico_socket_recvfrom(s, recvbuf, PICO_MDNS_MAXBUF, - &peer, &port)) > 0) { + while ((pico_read = pico_socket_recvfrom(s, recvbuf, PICO_MDNS_MAXBUF, + &peer, &port)) > 0) { /* Handle the MDNS data received */ pico_mdns_recv(s->stack, recvbuf, pico_read, peer); } @@ -2935,7 +2929,7 @@ pico_mdns_event4( uint16_t ev, struct pico_socket *s ) * @param arg Void-pointer to query-cookie * ****************************************************************************/ static void -pico_mdns_send_query_packet( pico_time now, void *arg ) +pico_mdns_send_query_packet(pico_time now, void *arg) { struct pico_mdns_cookie *cookie = (struct pico_mdns_cookie *)arg; pico_dns_qtree *questions = NULL; @@ -2964,7 +2958,7 @@ pico_mdns_send_query_packet( pico_time now, void *arg ) if (cookie->status != PICO_MDNS_COOKIE_STATUS_CANCELLED) { cookie->status = PICO_MDNS_COOKIE_STATUS_ACTIVE; - if(pico_mdns_send_packet(cookie->stack, packet, len) != (int)len) { + if (pico_mdns_send_packet(cookie->stack, packet, len) != (int)len) { mdns_dbg("Send error occurred!\n"); return; } @@ -2990,11 +2984,11 @@ pico_mdns_send_query_packet( pico_time now, void *arg ) * @return 0 When the query is successfully generated and scheduled for sending * ****************************************************************************/ static int -pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg) +pico_mdns_getrecord_generic(struct pico_stack *S, + const char *url, + uint16_t type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { struct pico_mdns_cookie *cookie = NULL; PICO_DNS_QTREE_DECLARE(qtree); @@ -3011,15 +3005,15 @@ pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t typ } /* Associate the current TCP/IP stack reference to access relevant - * fields/trees + * fields/trees */ q->stack = S; if (pico_tree_insert(&qtree, q)) { - mdns_dbg("inserting query into tree failed!\n"); + mdns_dbg("inserting query into tree failed!\n"); pico_dns_question_delete((void **)&q); - return -1; - } + return -1; + } /* Create a mDNS cookie to send */ if (!(cookie = pico_mdns_cookie_create(S, qtree, antree, artree, 1, PICO_MDNS_PACKET_TYPE_QUERY, @@ -3030,16 +3024,16 @@ pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t typ } /* Add cookie to S->MDNSCookies to be able to find it afterwards */ - if(pico_tree_insert(&S->MDNSCookies, cookie) ){ - mdns_dbg("inserting cookie into tree failed!\n"); + if (pico_tree_insert(&S->MDNSCookies, cookie)) { + mdns_dbg("inserting cookie into tree failed!\n"); PICO_DNS_QTREE_DESTROY(&qtree); pico_mdns_cookie_delete((void **)&cookie); return -1; - } + } /* Create new pico_timer-event to send packet */ if (!pico_mdns_timer_add(S, (pico_rand() % 120) + 20, pico_mdns_send_query_packet, - (void *)cookie)) { + (void *)cookie)) { mdns_dbg("MDNS: Failed to start send_query_packet timer\n"); pico_tree_delete(&S->MDNSCookies, cookie); pico_mdns_cookie_delete((void**)&cookie); @@ -3061,11 +3055,11 @@ pico_mdns_getrecord_generic(struct pico_stack *S, const char *url, uint16_t typ * @return 0 when query is correctly parsed, something else on failure. * ****************************************************************************/ int -pico_mdns_getrecord(struct pico_stack *S, const char *url, uint16_t type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_getrecord(struct pico_stack *S, + const char *url, + uint16_t type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { #if PICO_MDNS_ALLOW_CACHING == 1 PICO_MDNS_RTREE_DECLARE(cache_hits); @@ -3106,7 +3100,7 @@ return 0; * @param arg Void-pointer to mDNS announcement cookie * ***************************************************************************/ static void -pico_mdns_send_announcement_packet( pico_time now, void *arg ) +pico_mdns_send_announcement_packet(pico_time now, void *arg) { struct pico_mdns_cookie *cookie = (struct pico_mdns_cookie *)arg; @@ -3141,8 +3135,7 @@ pico_mdns_send_announcement_packet( pico_time now, void *arg ) /* Try to delete the cookie */ pico_tree_delete(&cookie->stack->MDNSCookies, cookie); pico_mdns_cookie_delete((void **)&cookie); - } - else{ + } else { /* A responder MAY send up to eight unsolicited responses, provided that the interval between unsolicited responses increases @@ -3152,7 +3145,7 @@ pico_mdns_send_announcement_packet( pico_time now, void *arg ) get our milliseconds. */ if (!pico_mdns_timer_add(cookie->stack, (pico_time)((1 << (PICO_MDNS_ANNOUNCEMENT_COUNT - cookie->count - 1)) - * 1000), pico_mdns_send_announcement_packet, cookie)) { + * 1000), pico_mdns_send_announcement_packet, cookie)) { mdns_dbg("MDNS: Failed to start send_announcement_packet timer\n"); /* TODO no idea what the consequences of this are */ @@ -3169,10 +3162,9 @@ pico_mdns_send_announcement_packet( pico_time now, void *arg ) * @return 0 When the host successfully started announcing. * ****************************************************************************/ static int -pico_mdns_announce(struct pico_stack *S, void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_announce(struct pico_stack *S, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { struct pico_mdns_cookie *announcement_cookie = NULL; PICO_DNS_QTREE_DECLARE(qtree); @@ -3220,7 +3212,7 @@ pico_mdns_announce(struct pico_stack *S, void (*callback)(pico_mdns_rtree *, * Section of probe packet. * ****************************************************************************/ static pico_dns_rtree -pico_mdns_gen_probe_auths( pico_mdns_rtree *records ) +pico_mdns_gen_probe_auths(pico_mdns_rtree *records) { PICO_DNS_RTREE_DECLARE(nstree); struct pico_tree_node *node = NULL; @@ -3234,7 +3226,7 @@ pico_mdns_gen_probe_auths( pico_mdns_rtree *records ) if (pico_tree_insert(&nstree, record->record) == &LEAF) { mdns_dbg("MDNS: Failed to insert record in tree\n"); break; - } + } } } @@ -3248,7 +3240,7 @@ pico_mdns_gen_probe_auths( pico_mdns_rtree *records ) * @param arg Void-pointer to mDNS probe cookie * ****************************************************************************/ static void -pico_mdns_send_probe_packet( pico_time now, void *arg ) +pico_mdns_send_probe_packet(pico_time now, void *arg) { struct pico_mdns_cookie *cookie = (struct pico_mdns_cookie *)arg; pico_dns_packet *packet = NULL; @@ -3272,7 +3264,7 @@ pico_mdns_send_probe_packet( pico_time now, void *arg ) /* Create an mDNS answer */ if (!(packet = pico_dns_query_create(&(cookie->qtree), NULL, - &nstree, NULL, &len))) { + &nstree, NULL, &len))) { PICO_DNS_RTREE_DESTROY(&nstree); mdns_dbg("Could not create probe packet!\n"); return; @@ -3284,13 +3276,13 @@ pico_mdns_send_probe_packet( pico_time now, void *arg ) packet->id = 0; /* RFC6762: 18.6: In both multicast query and response messages, - the RD bit SHOULD be zero on transmission. - In pico_dns_fill_packet_header, the RD bit is set to - PICO_DNS_RD_IS_DESIRED, which is defined to be 1 */ + the RD bit SHOULD be zero on transmission. + In pico_dns_fill_packet_header, the RD bit is set to + PICO_DNS_RD_IS_DESIRED, which is defined to be 1 */ packet->rd = PICO_DNS_RD_NO_DESIRE; /* Send the mDNS answer unsolicited via multicast */ - if(pico_mdns_send_packet(cookie->stack, packet, len) != (int)len) { + if (pico_mdns_send_packet(cookie->stack, packet, len) != (int)len) { mdns_dbg("Send error occurred!\n"); return; } @@ -3300,10 +3292,10 @@ pico_mdns_send_probe_packet( pico_time now, void *arg ) mdns_dbg("DONE - Sent probe!\n"); /* Probes should be sent with a delay in between of 250 ms */ - if (PICO_MDNS_COOKIE_STATUS_ACTIVE == cookie->status ) { + if (PICO_MDNS_COOKIE_STATUS_ACTIVE == cookie->status) { cookie->send_timer = pico_mdns_timer_add(cookie->stack, 250, - pico_mdns_send_probe_packet, - (void *)cookie); + pico_mdns_send_probe_packet, + (void *)cookie); if (!cookie->send_timer) { mdns_dbg("MDNS: Failed to start send_probe_packet timer\n"); /* TODO no idea what the consequences of this are */ @@ -3333,8 +3325,8 @@ pico_mdns_send_probe_packet( pico_time now, void *arg ) * @return 0 when the probe question is already present or added successfully. * ****************************************************************************/ static int -pico_mdns_add_probe_question(struct pico_stack *S, pico_dns_qtree *qtree, - char *name ) +pico_mdns_add_probe_question(struct pico_stack *S, pico_dns_qtree *qtree, + char *name) { struct pico_dns_question *new = NULL; char *url = NULL; @@ -3373,10 +3365,9 @@ pico_mdns_add_probe_question(struct pico_stack *S, pico_dns_qtree *qtree, * @param callback Callback to call when all records are properly registered * @return When host successfully started probing. * ****************************************************************************/ -static int pico_mdns_probe(struct pico_stack *S, void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +static int pico_mdns_probe(struct pico_stack *S, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { struct pico_mdns_cookie *cookie = NULL; struct pico_mdns_record *record = NULL; @@ -3391,9 +3382,9 @@ static int pico_mdns_probe(struct pico_stack *S, void (*callback)(pico_mdns_rtr return -1; } else { /* Find my records that need to pass the probing step first - * All records that don't have their PROBED flag set and - * are not being probed at hte moment are added to the tree - */ + * All records that don't have their PROBED flag set and + * are not being probed at hte moment are added to the tree + */ antree = pico_mdns_my_records_find_to_probe(S); /* Create probe questions for the records to be probed */ @@ -3405,9 +3396,9 @@ static int pico_mdns_probe(struct pico_stack *S, void (*callback)(pico_mdns_rtr /* Create a mDNS packet to send */ cookie = pico_mdns_cookie_create(S, qtree, antree, artree, - PICO_MDNS_PROBE_COUNT, - PICO_MDNS_PACKET_TYPE_PROBE, - callback, arg); + PICO_MDNS_PROBE_COUNT, + PICO_MDNS_PACKET_TYPE_PROBE, + callback, arg); if (!cookie) { mdns_dbg("Cookie_create returned NULL @ probe()!\n"); PICO_DNS_QTREE_DESTROY(&qtree); @@ -3426,8 +3417,8 @@ static int pico_mdns_probe(struct pico_stack *S, void (*callback)(pico_mdns_rtr /* first wait for a short random delay time, uniformly distributed in */ /* the range 0-250 ms. */ cookie->send_timer = pico_mdns_timer_add(cookie->stack, pico_rand() % 250, - pico_mdns_send_probe_packet, - (void *)cookie); + pico_mdns_send_probe_packet, + (void *)cookie); if (!cookie->send_timer) { mdns_dbg("MDNS: Failed to start send_probe_packet timer\n"); pico_tree_delete(&S->MDNSCookies, cookie); @@ -3453,12 +3444,10 @@ static int pico_mdns_probe(struct pico_stack *S, void (*callback)(pico_mdns_rtr * ****************************************************************************/ static int pico_mdns_claim_generic(struct pico_stack *S, - pico_mdns_rtree rtree, - uint8_t reclaim, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) + pico_mdns_rtree rtree, + uint8_t reclaim, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { /* Check if arguments are passed correctly */ if (!callback) { @@ -3496,11 +3485,10 @@ pico_mdns_claim_generic(struct pico_stack *S, * @return 0 When claiming didn't horribly fail. * ****************************************************************************/ int -pico_mdns_claim(struct pico_stack *S, pico_mdns_rtree rtree, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_claim(struct pico_stack *S, + pico_mdns_rtree rtree, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { return pico_mdns_claim_generic(S, rtree, PICO_MDNS_NO_RECLAIM, callback, arg); } @@ -3514,11 +3502,10 @@ pico_mdns_claim(struct pico_stack *S, pico_mdns_rtree rtree, * @return 0 When claiming didn't horribly fail. * ****************************************************************************/ static int -pico_mdns_reclaim(struct pico_stack *S, pico_mdns_rtree rtree, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) +pico_mdns_reclaim(struct pico_stack *S, + pico_mdns_rtree rtree, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { return pico_mdns_claim_generic(S, rtree, PICO_MDNS_RECLAIM, callback, arg); } @@ -3537,7 +3524,7 @@ pico_mdns_reclaim(struct pico_stack *S, pico_mdns_rtree rtree, * Returns something else when it didn't succeeded. * ****************************************************************************/ int -pico_mdns_tryclaim_hostname(struct pico_stack *S, const char *url, void *arg ) +pico_mdns_tryclaim_hostname(struct pico_stack *S, const char *url, void *arg) { PICO_MDNS_RTREE_DECLARE(rtree); struct pico_mdns_record *record = NULL; @@ -3550,14 +3537,14 @@ pico_mdns_tryclaim_hostname(struct pico_stack *S, const char *url, void *arg ) } else { /* Create an A record for hostname */ record = pico_mdns_record_create(S, url, - &(S->mdns_sock_ipv4->local_addr.ip4.addr), - PICO_SIZE_IP4, PICO_DNS_TYPE_A, - PICO_MDNS_DEFAULT_TTL, - (PICO_MDNS_RECORD_UNIQUE | - PICO_MDNS_RECORD_HOSTNAME)); + &(S->mdns_sock_ipv4->local_addr.ip4.addr), + PICO_SIZE_IP4, PICO_DNS_TYPE_A, + PICO_MDNS_DEFAULT_TTL, + (PICO_MDNS_RECORD_UNIQUE | + PICO_MDNS_RECORD_HOSTNAME)); if (!record) { mdns_dbg("Could not create A record for hostname %s!\n", - strerror(pico_err)); + strerror(pico_err)); return -1; } @@ -3602,7 +3589,7 @@ pico_mdns_get_hostname(struct pico_stack *S) } static void -pico_mdns_cleanup(struct pico_stack *S ) +pico_mdns_cleanup(struct pico_stack *S) { /* Delete socket if it was previously opened */ if (S->mdns_sock_ipv4) { @@ -3640,12 +3627,10 @@ pico_mdns_cleanup(struct pico_stack *S ) * ****************************************************************************/ int pico_mdns_init(struct pico_stack *S, - const char *hostname, - struct pico_ip4 address, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ) + const char *hostname, + struct pico_ip4 address, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg) { struct pico_ip_mreq mreq4; uint16_t proto4 = PICO_PROTO_IPV4, port = 0, loop = 0, ttl = 255; @@ -3654,7 +3639,7 @@ pico_mdns_init(struct pico_stack *S, port = short_be(S->mdns_port); /* Check callback parameter */ - if(!callback || !hostname) { + if (!callback || !hostname) { mdns_dbg("No callback function supplied!\n"); pico_err = PICO_ERR_EINVAL; return -1; @@ -3670,13 +3655,13 @@ pico_mdns_init(struct pico_stack *S, /* Open global IPv4 mDNS socket */ S->mdns_sock_ipv4 = pico_socket_open(S, proto4, PICO_PROTO_UDP, &pico_mdns_event4); - if(!S->mdns_sock_ipv4) { + if (!S->mdns_sock_ipv4) { mdns_dbg("pico_socket_open_ex returned NULL-ptr...\n"); return -1; } /* Convert the mDNS IPv4 destination address to struct */ - if(pico_string_to_ipv4(PICO_MDNS_DEST_ADDR4, &mreq4.mcast_group_addr.ip4.addr)) { + if (pico_string_to_ipv4(PICO_MDNS_DEST_ADDR4, &mreq4.mcast_group_addr.ip4.addr)) { mdns_dbg("String to IPv4 error\n"); return -1; } @@ -3685,13 +3670,13 @@ pico_mdns_init(struct pico_stack *S, mreq4.mcast_link_addr.ip4 = inaddr_any; /* Don't want the multicast data to be looped back to the host */ - if(pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_MULTICAST_LOOP, &loop)) { + if (pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_MULTICAST_LOOP, &loop)) { mdns_dbg("socket_setoption PICO_IP_MULTICAST_LOOP failed\n"); return -1; } /* Tell the stack we're interested in this particular multicast group */ - if(pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_ADD_MEMBERSHIP, &mreq4)) { + if (pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_ADD_MEMBERSHIP, &mreq4)) { mdns_dbg("socket_setoption PICO_IP_ADD_MEMBERSHIP failed\n"); return -1; } @@ -3701,7 +3686,7 @@ pico_mdns_init(struct pico_stack *S, * All Multicast DNS responses (including responses sent via unicast) * SHOULD be sent with IP TTL set to 255. */ - if(pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_MULTICAST_TTL, &ttl)) { + if (pico_socket_setoption(S->mdns_sock_ipv4, PICO_IP_MULTICAST_TTL, &ttl)) { mdns_dbg("socket_setoption PICO_IP_MULTICAST_TTL failed\n"); return -1; } diff --git a/modules/pico_mdns.h b/modules/pico_mdns.h index e8b19cc4..e161ce8a 100644 --- a/modules/pico_mdns.h +++ b/modules/pico_mdns.h @@ -1,11 +1,11 @@ /* **************************************************************************** - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -91,7 +91,7 @@ struct pico_mdns_record * @return 0 when records are equal, returns difference when they're not. * ****************************************************************************/ int -pico_mdns_record_cmp( void *a, void *b ); +pico_mdns_record_cmp(void *a, void *b); /* **************************************************************************** * Deletes a single mDNS resource record. @@ -101,7 +101,7 @@ pico_mdns_record_cmp( void *a, void *b ); * @return Returns 0 on success, something else on failure. * ****************************************************************************/ int -pico_mdns_record_delete( void **record ); +pico_mdns_record_delete(void **record); /* **************************************************************************** * Creates a single standalone mDNS resource record with given name, type and @@ -125,11 +125,11 @@ pico_mdns_record_delete( void **record ); struct pico_mdns_record * pico_mdns_record_create(struct pico_stack *S, const char *url, - void *_rdata, - uint16_t datalen, - uint16_t rtype, - uint32_t rttl, - uint8_t flags ); + void *_rdata, + uint16_t datalen, + uint16_t rtype, + uint32_t rttl, + uint8_t flags); @@ -155,11 +155,11 @@ typedef struct pico_tree pico_mdns_rtree; * @return 0 when query is correctly parsed, something else on failure. * ****************************************************************************/ int -pico_mdns_getrecord(struct pico_stack *S, const char *url, uint16_t type, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); +pico_mdns_getrecord(struct pico_stack *S, + const char *url, + uint16_t type, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* **************************************************************************** * Claim all different mDNS records in a tree in a single API-call. All records @@ -170,11 +170,10 @@ pico_mdns_getrecord(struct pico_stack *S, const char *url, uint16_t type, * @return 0 When claiming didn't horribly fail. * ****************************************************************************/ int -pico_mdns_claim(struct pico_stack *S, pico_mdns_rtree rtree, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); +pico_mdns_claim(struct pico_stack *S, + pico_mdns_rtree rtree, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* **************************************************************************** * Tries to claim a hostname for this machine. Claims automatically a @@ -190,7 +189,7 @@ pico_mdns_claim(struct pico_stack *S, pico_mdns_rtree rtree, * Returns something else when it didn't succeeded. * ****************************************************************************/ int -pico_mdns_tryclaim_hostname(struct pico_stack *S, const char *url, void *arg ); +pico_mdns_tryclaim_hostname(struct pico_stack *S, const char *url, void *arg); /* **************************************************************************** * Get the current hostname for this machine. @@ -221,18 +220,14 @@ pico_mdns_get_hostname(struct pico_stack *S); * ****************************************************************************/ int pico_mdns_init(struct pico_stack *S, - const char *hostname, - struct pico_ip4 address, - void (*callback)(pico_mdns_rtree *, - char *, - void *), - void *arg ); + const char *hostname, + struct pico_ip4 address, + void (*callback)(pico_mdns_rtree *, char *, void *), + void *arg); /* Tree sorting functions */ -int pico_mdns_cookie_cmp( void *ka, void *kb ); -int pico_mdns_record_cmp_name_type( void *a, void *b ); - - +int pico_mdns_cookie_cmp(void *ka, void *kb); +int pico_mdns_record_cmp_name_type(void *a, void *b); #endif /* _INCLUDE_PICO_MDNS */ diff --git a/modules/pico_mld.c b/modules/pico_mld.c index 51667420..2fdcec15 100644 --- a/modules/pico_mld.c +++ b/modules/pico_mld.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Roel Postelmans - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -100,7 +100,7 @@ static struct mcast_parameters *pico_mld_find_parameter(struct pico_stack *S, st static uint8_t *pico_mld_fill_hopbyhop(struct pico_ipv6_hbhoption *hbh) { uint8_t *p; - if(hbh == NULL) + if (hbh == NULL) return NULL; hbh->type = PICO_PROTO_ICMP6; @@ -124,15 +124,15 @@ static int pico_mld_check_hopbyhop(struct pico_ipv6_hbhoption *hbh) }; int i; uint8_t *p; - if(hbh == NULL) + if (hbh == NULL) return -1; - if(hbh->type != options[0] || hbh->len != options[1]) + if (hbh->type != options[0] || hbh->len != options[1]) return -1; p = (uint8_t *)hbh + sizeof(struct pico_ipv6_hbhoption); - for(i = 0; i < MLD_ROUTER_ALERT_LEN - 2; i++) { - if( *(p + i) != options[i + 2]) + for (i = 0; i < MLD_ROUTER_ALERT_LEN - 2; i++) { + if (*(p + i) != options[i + 2]) return -1; } return 0; @@ -344,7 +344,7 @@ static int pico_mld_timer_start(struct pico_stack *S, struct mld_timer *t) if (pico_tree_insert(&S->MLDTimers, timer)) { mld_dbg("MLD: Failed to insert timer into tree\n"); return -1; - } + } if (!pico_timer_add(S, timer->delay, &pico_mld_timer_expired, timer)) { mld_dbg("MLD: Failed to start expiration timer\n"); @@ -432,7 +432,7 @@ static struct mcast_parameters *pico_mld_find_parameter(struct pico_stack *S, st } static int pico_mld_is_checksum_valid(struct pico_frame *f) { - if( pico_icmp6_checksum(f) == 0) + if (pico_icmp6_checksum(f) == 0) return 1; mld_dbg("ICMP6 (MLD) : invalid checksum\n"); @@ -480,7 +480,7 @@ static int pico_mld_compatibility_mode(struct pico_stack *S, struct pico_frame * datalen = (uint16_t)(datalen - PICO_SIZE_ETHHDR); } - if( datalen >= 28) { + if (datalen >= 28) { /* MLDv2 */ t.type = MLD_TIMER_V2_QUERIER; t.stack = S; @@ -492,7 +492,7 @@ static int pico_mld_compatibility_mode(struct pico_stack *S, struct pico_frame * mld_dbg("MLD Compatibility: v2\n"); return 0; } - } else if( datalen == 24) { + } else if (datalen == 24) { pico_tree_foreach_safe(index, &S->MLDTimers, _tmp) { ((struct mld_timer *)index->keyValue)->stopped = MLD_TIMER_STOPPED; @@ -504,7 +504,7 @@ static int pico_mld_compatibility_mode(struct pico_stack *S, struct pico_frame * /* Reset states to prevent deadlock */ mcast_group = mld_report->mcast_group; p = pico_mld_find_parameter(S, &link->address, &mcast_group); - if(p) { + if (p) { p->state = MLD_STATE_NON_LISTENER; p->event = MLD_EVENT_START_LISTENING; } @@ -551,10 +551,10 @@ int pico_mld_state_change(struct pico_stack *S, struct pico_ip6 *mcast_link, str p->mcast_link.ip6 = *mcast_link; p->mcast_group.ip6 = *mcast_group; p->stack = S; - if(pico_tree_insert(&S->MLDParameters, p)){ - PICO_FREE(p); - return -1; - } + if (pico_tree_insert(&S->MLDParameters, p)) { + PICO_FREE(p); + return -1; + } } else if (!p) { pico_err = PICO_ERR_EINVAL; return -1; @@ -595,45 +595,45 @@ static struct mcast_parameters *pico_mld_analyse_packet(struct pico_frame *f) struct pico_ipv6_exthdr *hbh; link = pico_ipv6_link_by_dev(f->dev); - if(!link) + if (!link) return NULL; mcast_group = mld_report->mcast_group; /* Package check */ - if(ipv6_hdr->hop != MLD_HOP_LIMIT) { + if (ipv6_hdr->hop != MLD_HOP_LIMIT) { mld_dbg("MLD: Hop limit > 1, ignoring frame\n"); return NULL; } hbh = (struct pico_ipv6_exthdr *) (f->transport_hdr); - if(pico_mld_check_hopbyhop((struct pico_ipv6_hbhoption *)hbh) < 0) { + if (pico_mld_check_hopbyhop((struct pico_ipv6_hbhoption *)hbh) < 0) { mld_dbg("MLD: Router Alert option is not set\n"); return NULL; } - if(!pico_ipv6_is_linklocal(ipv6_hdr->src.addr) || pico_ipv6_is_unspecified(ipv6_hdr->src.addr)) { + if (!pico_ipv6_is_linklocal(ipv6_hdr->src.addr) || pico_ipv6_is_unspecified(ipv6_hdr->src.addr)) { mld_dbg("MLD Source is invalid link-local address\n"); return NULL; } /* end package check */ p = pico_mld_find_parameter(f->dev->stack, &link->address, &mcast_group); - if(!p) { + if (!p) { mld_dbg("Alloc-ing MLD parameters\n"); p = PICO_ZALLOC(sizeof(struct mcast_parameters)); - if(!p) + if (!p) return NULL; p->state = MLD_STATE_NON_LISTENER; p->mcast_link.ip6 = link->address; if (pico_tree_insert(&f->dev->stack->MLDParameters, p)) { - PICO_FREE(p); - return NULL; - } + PICO_FREE(p); + return NULL; + } } mld_dbg("Analyse package, type = %d\n", hdr->type); - switch(hdr->type) { + switch (hdr->type) { case PICO_MLD_QUERY: p->max_resp_time = mld_report->max_resp_delay; p->event = MLD_EVENT_QUERY_RECV; @@ -663,7 +663,7 @@ int pico_mld_process_in(struct pico_stack *S, struct pico_frame *f) if (pico_mld_compatibility_mode(S, f) < 0) goto out; - if((p = pico_mld_analyse_packet(f)) == NULL) + if ((p = pico_mld_analyse_packet(f)) == NULL) goto out; return pico_mld_process_event(p); @@ -696,7 +696,7 @@ static int8_t pico_mld_send_done(struct mcast_parameters *p, struct pico_frame * /* p->f->len is correctly set by alloc */ hbh = (struct pico_ipv6_exthdr *)(p->f->transport_hdr); report = (struct mld_message *)(pico_mld_fill_hopbyhop((struct pico_ipv6_hbhoption*)hbh)); - if(!report) { + if (!report) { pico_err = PICO_ERR_ENOMEM; return -1; } @@ -771,7 +771,7 @@ static int8_t pico_mldv2_generate_report(struct mcast_filter_parameters *filter, uint16_t len = 0; uint16_t i = 0; /* RFC3810 $5.1.10 */ - if(filter->sources > MLD_MAX_SOURCES) { + if (filter->sources > MLD_MAX_SOURCES) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -805,7 +805,7 @@ static int8_t pico_mldv2_generate_report(struct mcast_filter_parameters *filter, } } - if(i != filter->sources) { + if (i != filter->sources) { return -1; } @@ -843,7 +843,7 @@ static int8_t pico_mldv1_generate_report(struct mcast_parameters *p) uint8_t report_type = PICO_MLD_REPORT; struct pico_ipv6_exthdr *hbh; struct pico_device *dev = pico_ipv6_link_find(p->stack, &p->mcast_link.ip6); - p->f = pico_proto_ipv6.alloc(p->stack, &pico_proto_ipv6, dev, sizeof(struct mld_message) + MLD_ROUTER_ALERT_LEN ); + p->f = pico_proto_ipv6.alloc(p->stack, &pico_proto_ipv6, dev, sizeof(struct mld_message) + MLD_ROUTER_ALERT_LEN); /* p->f->len is correctly set by alloc */ hbh = (struct pico_ipv6_exthdr *)(p->f->transport_hdr); @@ -862,7 +862,7 @@ static int8_t pico_mld_generate_report(struct mcast_parameters *p) struct mcast_filter_parameters filter; int8_t result; filter.link = (union pico_link *)pico_ipv6_link_get(p->stack, &p->mcast_link.ip6); - if( !filter.link || !pico_ipv6_is_multicast(p->mcast_group.ip6.addr)) { + if (!filter.link || !pico_ipv6_is_multicast(p->mcast_group.ip6.addr)) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -874,10 +874,10 @@ static int8_t pico_mld_generate_report(struct mcast_parameters *p) } case PICO_MLDV2: { result = pico_mldv2_generate_filter(&filter, p); - if(result < 0) + if (result < 0) return -1; - if(result != MCAST_NO_REPORT) + if (result != MCAST_NO_REPORT) return pico_mldv2_generate_report(&filter, p); } break; @@ -909,7 +909,7 @@ static int mld_stsdifs(struct mcast_parameters *p) if (pico_mld_timer_stop(&t) < 0) return -1; - switch(link->mcast_compatibility) { + switch (link->mcast_compatibility) { case PICO_MLDV2: if (pico_mld_generate_report(p) < 0) { return -1; @@ -1133,8 +1133,8 @@ static int mld_discard(struct mcast_parameters *p) } /* finite state machine table */ -static const mld_callback mld_state_diagram[3][6] = -{ /* event | Stop Listening | Start Listening | Update Group |Query receive |Report receive |Timer expired */ +static const mld_callback mld_state_diagram[3][6] = { +/* event | Stop Listening | Start Listening | Update Group |Query receive |Report receive |Timer expired */ /* none listener*/ { mld_discard, mld_srsfst, mld_srsfst, mld_discard, mld_discard, mld_discard}, /* idle listener */ { mld_stsdifs, mld_mrsrrt, mld_mrsrrt, mld_rtimrtct, mld_stcl, mld_srsf }, diff --git a/modules/pico_mld.h b/modules/pico_mld.h index d604919b..b1541dac 100644 --- a/modules/pico_mld.h +++ b/modules/pico_mld.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_mm.c b/modules/pico_mm.c index ea794749..ce1e86c8 100644 --- a/modules/pico_mm.c +++ b/modules/pico_mm.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Gustav Janssens, Jonas Van Nieuwenberg, Sam Van Den Berge - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -235,16 +235,11 @@ static int compare_slab_keys(void*keyA, void*keyB) uint32_t sizeKeyA = ***(uint32_t***) keyA; uint32_t sizeKeyB = ***(uint32_t***) keyB; DBG_MM_BLUE("Compare called: sizeA = %i, sizeB = %i", sizeKeyA, sizeKeyB); - if(sizeKeyA == sizeKeyB) - { + if (sizeKeyA == sizeKeyB) { return 0; - } - else if(sizeKeyA < sizeKeyB) - { + } else if (sizeKeyA < sizeKeyB) { return 1; - } - else - { + } else { return -1; } } @@ -270,8 +265,7 @@ static void _pico_mem_init_page(struct pico_mem_page*page, size_t slabsize) page->slab_size = (uint32_t)slabsize; page->slabs_max = (uint16_t)((PICO_MEM_PAGE_SIZE - sizeof(struct pico_mem_page) - sizeof(struct pico_mem_block)) / (slabsize + sizeof(struct pico_mem_block))); page->heap_max_size = (uint32_t)(PICO_MEM_PAGE_SIZE - sizeof(struct pico_mem_page) - sizeof(struct pico_mem_block) - (page->slabs_max * (sizeof(struct pico_mem_block) + slabsize))); - if(page->heap_max_size < PICO_MIN_HEAP_SIZE) - { + if (page->heap_max_size < PICO_MIN_HEAP_SIZE) { DBG_MM_BLUE("Not enough heap size available with slabsize %u, allocating one slab to heap.", slabsize); page->slabs_max--; /* DBG_MM_BLUE("Heap size %u -> %lu",page->heap_max_size, page->heap_max_size + sizeof(pico_mem_slab_block) + slabsize); */ @@ -293,8 +287,7 @@ static void _pico_mem_init_page(struct pico_mem_page*page, size_t slabsize) heap_block->internals.heap_block.size = page->heap_max_free_space; byteptr += sizeof(struct pico_mem_block) + heap_block->internals.heap_block.size; - for(i = 0; i < page->slabs_max; i++) - { + for (i = 0; i < page->slabs_max; i++) { slab_block = (struct pico_mem_block*) byteptr; DBG_MM_BLUE("Slab object %i at %p. Start of object data at %p", i, slab_block, (uint8_t*) slab_block + sizeof(struct pico_mem_slab_block)); slab_block->type = SLAB_BLOCK_TYPE; @@ -305,8 +298,7 @@ static void _pico_mem_init_page(struct pico_mem_page*page, size_t slabsize) DBG_MM("Creating slab_node.."); slab_node = pico_mem_page0_zalloc(sizeof(struct pico_mem_slab_node)); - if(slab_node == NULL) - { + if (slab_node == NULL) { DBG_MM_RED("No more space in the manager heap for the housekeeping of slab %i, and no more space for extra manager pages!", i + 1); DBG_MM_RED("Debug info:\nUsed size: %u/%u\nmanager_extra = %p", manager->used_size, manager->size, manager->manager_extra); DBG_MM_RED("This page will be initialized with %u slabs instead of %u slabs", i, page->slabs_max); @@ -322,15 +314,12 @@ static void _pico_mem_init_page(struct pico_mem_page*page, size_t slabsize) slab_block->internals.slab_block.slab_node = slab_node; - if(tree_node != NULL) - { + if (tree_node != NULL) { struct pico_mem_slab_node*first_node = (struct pico_mem_slab_node*) tree_node->keyValue; tree_node->keyValue = slab_node; slab_node->next = first_node; first_node->prev = slab_node; - } - else - { + } else { /* Insert new slab_node */ DBG_MM_BLUE("Inserting new slab node in the tree of size %u", slabsize); /* pico_err_t pico_err_backup = pico_err; */ @@ -343,8 +332,7 @@ static void _pico_mem_init_page(struct pico_mem_page*page, size_t slabsize) /* IF SLAB_NODE COULDN'T BE INSERTED */ /* if(pico_err == PICO_ERR_ENOMEM) */ /* if(temp == &LEAF) */ - if(temp != NULL) - { + if (temp != NULL) { DBG_MM_RED("No more space in the manager heap for the housekeeping of slab %i, and no more space for extra manager pages!", i + 1); DBG_MM_RED("This page will be initialized without slabs."); pico_mem_page0_free(slab_node); @@ -374,8 +362,7 @@ void pico_mem_init(uint32_t memsize) uint8_t*startofmanagerheap; DBG_MM_YELLOW("Initializing memory with memsize %u", memsize); - if(memsize < PICO_MEM_PAGE_SIZE * 2) - { + if (memsize < PICO_MEM_PAGE_SIZE * 2) { /* Not enough memory was provided to initialize a manager page and a data page, return without initializing memory */ /* Set pico_err to an appropriate value */ pico_err = PICO_ERR_ENOMEM; @@ -387,8 +374,7 @@ void pico_mem_init(uint32_t memsize) /* First pico_mem_page is already included in pico_mem_manager. Others are added. */ /* manager = pico_azalloc(sizeof(pico_mem_manager) + sizeof(pico_mem_page*)*(pages - 1)); //Points to usermanager if one present */ manager = pico_zalloc(PICO_MEM_PAGE_SIZE); - if( NULL != manager ) - { + if (NULL != manager) { manager->size = memsize; manager->used_size = PICO_MEM_PAGE_SIZE; manager->first_page = NULL; @@ -411,14 +397,11 @@ void pico_mem_init(uint32_t memsize) /* Initialize the first page only! */ page = pico_zalloc(PICO_MEM_PAGE_SIZE); - if(page != NULL) - { + if (page != NULL) { manager->used_size += PICO_MEM_PAGE_SIZE; DBG_MM_BLUE("Page 1 at %p, manager used size = %u", page, manager->used_size); _pico_mem_init_page(page, PICO_MEM_DEFAULT_SLAB_SIZE); - } - else - { + } else { /* Not enough memory was provided to initialize a manager page and a data page, return without initializing memory */ /* Set pico_err to an appropriate value */ pico_err = PICO_ERR_ENOMEM; @@ -430,9 +413,7 @@ void pico_mem_init(uint32_t memsize) } DBG_MM_GREEN("Memory initialized. Returning from pico_mem_init."); - } - else - { + } else { /* Not enough memory was provided to initialize a manager page and a data page, return without initializing memory */ /* Set pico_err to an appropriate value */ pico_err = PICO_ERR_ENOMEM; @@ -450,20 +431,15 @@ void pico_mem_deinit() struct pico_mem_manager_extra*next_manager_page; DBG_MM_YELLOW("Pico_mem_deinit called"); - if(manager == NULL) - { + if (manager == NULL) { DBG_MM_GREEN("No memory instance initialized, returning"); - } - else - { - while(manager->first_page != NULL) - { + } else { + while (manager->first_page != NULL) { next_page = manager->first_page->next_page; pico_free(manager->first_page); manager->first_page = next_page; } - while(manager->manager_extra != NULL) - { + while (manager->manager_extra != NULL) { next_manager_page = manager->manager_extra->next; pico_free(manager->manager_extra); manager->manager_extra = next_manager_page; @@ -499,8 +475,7 @@ static void*_pico_mem_manager_extra_alloc(struct pico_mem_manager_extra*heap_pag sizeleft = PICO_MEM_PAGE_SIZE - sizeof(struct pico_mem_manager_extra); - while(heap_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || heap_block->internals.heap_block.size < len) - { + while (heap_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || heap_block->internals.heap_block.size < len) { sizeleft -= (uint32_t)sizeof(struct pico_mem_block); sizeleft -= heap_block->internals.heap_block.size; /* DBG_MM("Sizeleft=%i", sizeleft); */ @@ -508,23 +483,19 @@ static void*_pico_mem_manager_extra_alloc(struct pico_mem_manager_extra*heap_pag byteptr = (uint8_t*) heap_block + sizeof(struct pico_mem_block); byteptr += heap_block->internals.heap_block.size; heap_block = (struct pico_mem_block*) byteptr; - if(sizeleft <= sizeof(struct pico_mem_block)) - { + if (sizeleft <= sizeof(struct pico_mem_block)) { DBG_MM_RED("No more heap space left in the extra manager heap page!"); - if(heap_page->next == NULL) - { + if (heap_page->next == NULL) { /* TODO: Probably need another function for this */ DBG_MM_RED("Trying to allocate a new page for extra heap space: space usage %uB/%uB", manager->used_size, manager->size); - if(manager->used_size + PICO_MEM_PAGE_SIZE > manager->size) - { + if (manager->used_size + PICO_MEM_PAGE_SIZE > manager->size) { DBG_MM_RED("No more space left for this page!"); /* exit(1); */ return NULL; } extra_heap_page = pico_zalloc(PICO_MEM_PAGE_SIZE); - if(extra_heap_page != NULL) - { + if (extra_heap_page != NULL) { extra_heap_page->blocks = 0; extra_heap_page->next = NULL; extra_heap_page->timestamp = 0; @@ -538,17 +509,13 @@ static void*_pico_mem_manager_extra_alloc(struct pico_mem_manager_extra*heap_pag manager->used_size += PICO_MEM_PAGE_SIZE; DBG_MM_BLUE("Allocated an extra manager heap page at %p, manager space usage: %uB/%uB", extra_heap_page, manager->used_size, manager->size); return _pico_mem_manager_extra_alloc(extra_heap_page, len); - } - else - { + } else { /* This should be a dirty crash */ DBG_MM_RED("Page not allocated even though the max size for the memory manager hasn't been reached yet!"); /* exit(1); */ return NULL; } - } - else - { + } else { DBG_MM_RED("This should never happen: debug information:"); DBG_MM_RED("manager->manager_extra = %p", manager->manager_extra); DBG_MM_RED("heap_page = %p", heap_page); @@ -563,13 +530,11 @@ static void*_pico_mem_manager_extra_alloc(struct pico_mem_manager_extra*heap_pag DBG_MM_BLUE("Found free heap block in extra manager page %p at: %p (%u blocks in use)", heap_page, heap_block, heap_page->blocks); heap_block->internals.heap_block.free = HEAP_BLOCK_NOT_FREE; - if(heap_block->internals.heap_block.size == sizeleft - sizeof(struct pico_mem_block)) - { + if (heap_block->internals.heap_block.size == sizeleft - sizeof(struct pico_mem_block)) { DBG_MM_BLUE("End of heap, splitting up into a new block"); heap_block->internals.heap_block.size = (uint32_t)len; sizeleft = (uint32_t)(sizeleft - (uint32_t)sizeof(struct pico_mem_block) - len); - if(sizeleft > sizeof(struct pico_mem_block)) - { + if (sizeleft > sizeof(struct pico_mem_block)) { sizeleft -= (uint32_t)sizeof(struct pico_mem_block); byteptr = (uint8_t*) heap_block + sizeof(struct pico_mem_block); byteptr += len; @@ -578,9 +543,7 @@ static void*_pico_mem_manager_extra_alloc(struct pico_mem_manager_extra*heap_pag new_block->internals.heap_block.free = HEAP_BLOCK_FREE; new_block->internals.heap_block.size = sizeleft; DBG_MM_BLUE("New block: %p, size = %u", new_block, new_block->internals.heap_block.size); - } - else - { + } else { DBG_MM_RED("No more space in extra manager heap page left to initialize a new heap block!"); DBG_MM_RED("A new page will be allocated when even more space is needed"); } @@ -616,30 +579,25 @@ void*pico_mem_page0_zalloc(size_t len) sizeleft = PICO_MEM_PAGE_SIZE - sizeof(struct pico_mem_manager); /* this would mean that heap_block is never NULL */ /* while(heap_block != NULL && ( heap_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || heap_block->internals.heap_block.size < len)) */ - while(heap_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || heap_block->internals.heap_block.size < len) - { + while (heap_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || heap_block->internals.heap_block.size < len) { sizeleft -= (uint32_t)sizeof(struct pico_mem_block); sizeleft -= heap_block->internals.heap_block.size; /* DBG_MM("Sizeleft=%i", sizeleft); */ byteptr = (uint8_t*) heap_block + sizeof(struct pico_mem_block); /* byteptr points to start of heap block data */ byteptr += heap_block->internals.heap_block.size; /* jump over that data to start of next heap_block */ heap_block = (struct pico_mem_block*) byteptr; - if(sizeleft <= sizeof(struct pico_mem_block)) - { + if (sizeleft <= sizeof(struct pico_mem_block)) { DBG_MM_RED("No more heap space left in the manager page!"); - if(manager->manager_extra == NULL) - { + if (manager->manager_extra == NULL) { DBG_MM_RED("Trying to allocate a new page for extra heap space: space usage: %uB/%uB", manager->used_size, manager->size); - if(manager->used_size + PICO_MEM_PAGE_SIZE > manager->size) - { + if (manager->used_size + PICO_MEM_PAGE_SIZE > manager->size) { DBG_MM_RED("No more space left for this page!"); /* exit(1); */ return NULL; } heap_page = pico_zalloc(PICO_MEM_PAGE_SIZE); - if(heap_page != NULL) - { + if (heap_page != NULL) { /* Initialize the new heap page */ heap_page->blocks = 0; heap_page->next = NULL; @@ -653,17 +611,13 @@ void*pico_mem_page0_zalloc(size_t len) manager->used_size += PICO_MEM_PAGE_SIZE; DBG_MM_BLUE("Allocated an extra manager heap page at %p, manager space usage: %uB/%uB", heap_page, manager->used_size, manager->size); return _pico_mem_manager_extra_alloc(heap_page, len); - } - else - { + } else { /* This should be a dirty crash */ DBG_MM_RED("Page not allocated even though the max size for the memory manager hasn't been reached yet!"); /* exit(1); */ return NULL; } - } - else - { + } else { return _pico_mem_manager_extra_alloc(manager->manager_extra, len); } } @@ -671,11 +625,9 @@ void*pico_mem_page0_zalloc(size_t len) DBG_MM_BLUE("Found free heap block in manager page at : %p", heap_block); heap_block->internals.heap_block.free = HEAP_BLOCK_NOT_FREE; - if(heap_block->internals.heap_block.size == sizeleft - sizeof(struct pico_mem_block)) - { + if (heap_block->internals.heap_block.size == sizeleft - sizeof(struct pico_mem_block)) { sizeleft = (uint32_t)(sizeleft - (uint32_t)sizeof(struct pico_mem_block) - len); - if(sizeleft > sizeof(struct pico_mem_block)) - { + if (sizeleft > sizeof(struct pico_mem_block)) { DBG_MM_BLUE("End of heap, splitting up into a new block"); heap_block->internals.heap_block.size = (uint32_t)len; sizeleft -= (uint32_t)sizeof(struct pico_mem_block); @@ -685,9 +637,7 @@ void*pico_mem_page0_zalloc(size_t len) new_block->internals.heap_block.free = HEAP_BLOCK_FREE; new_block->internals.heap_block.size = sizeleft; DBG_MM_BLUE("New block: %p, size = %u", new_block, new_block->internals.heap_block.size); - } - else - { + } else { /* DBG_MM_RED("ERROR! No more space in manager heap left to initialise a new heap_block!"); */ /* exit(1); */ DBG_MM_RED("No more space in manager heap left to initialize a new heap block!"); @@ -724,11 +674,9 @@ static void _pico_mem_free_and_merge_heap_block(struct pico_mem_page*page, struc byteptr += curr->internals.heap_block.size; next = (struct pico_mem_block*) byteptr; - while(curr->type == HEAP_BLOCK_TYPE && next->type == HEAP_BLOCK_TYPE) - { + while (curr->type == HEAP_BLOCK_TYPE && next->type == HEAP_BLOCK_TYPE) { DBG_MM("Checking heap block (%s) with size %u at %p", (curr->internals.heap_block.free == HEAP_BLOCK_FREE) ? "free" : "not free", curr->internals.heap_block.size, curr); - if(curr->internals.heap_block.free == HEAP_BLOCK_FREE && next->internals.heap_block.free == HEAP_BLOCK_FREE) - { + if (curr->internals.heap_block.free == HEAP_BLOCK_FREE && next->internals.heap_block.free == HEAP_BLOCK_FREE) { DBG_MM_BLUE("Merging blocks with sizes %u and %u", curr->internals.heap_block.size, next->internals.heap_block.size); curr->internals.heap_block.size += (uint32_t)sizeof(struct pico_mem_block) + next->internals.heap_block.size; } @@ -742,8 +690,7 @@ static void _pico_mem_free_and_merge_heap_block(struct pico_mem_page*page, struc next = (struct pico_mem_block*) byteptr; } DBG_MM("Checking heap block (%s) with size %u at %p", (curr->internals.heap_block.free == HEAP_BLOCK_FREE) ? "free" : "not free", curr->internals.heap_block.size, curr); - if(curr->type == HEAP_BLOCK_TYPE && prev->internals.heap_block.free == HEAP_BLOCK_FREE && curr->internals.heap_block.free == HEAP_BLOCK_FREE) - { + if (curr->type == HEAP_BLOCK_TYPE && prev->internals.heap_block.free == HEAP_BLOCK_FREE && curr->internals.heap_block.free == HEAP_BLOCK_FREE) { DBG_MM_BLUE("Merging blocks with sizes %u and %u", prev->internals.heap_block.size, curr->internals.heap_block.size); prev->internals.heap_block.size += (uint32_t)sizeof(struct pico_mem_block) + curr->internals.heap_block.size; } @@ -769,12 +716,10 @@ static uint32_t _pico_mem_determine_max_free_space(struct pico_mem_page*page) /* Determine max free space by iterating through the list */ /* while(mem_block != NULL && mem_block->type == HEAP_BLOCK_TYPE) */ - while(mem_block->type == HEAP_BLOCK_TYPE) - { + while (mem_block->type == HEAP_BLOCK_TYPE) { /* DBG_MM("Memblock %p of size %i is free %i\n",block, block->size, block->free); */ DBG_MM("Memblock %s (size %u) at %p", (mem_block->internals.heap_block.free == HEAP_BLOCK_FREE) ? "not in use" : "in use", mem_block->internals.heap_block.size, mem_block); - if(mem_block->internals.heap_block.free == HEAP_BLOCK_FREE && mem_block->internals.heap_block.size > maxfreespace) - { + if (mem_block->internals.heap_block.free == HEAP_BLOCK_FREE && mem_block->internals.heap_block.size > maxfreespace) { maxfreespace = mem_block->internals.heap_block.size; page->heap_max_free_space = maxfreespace; } @@ -807,8 +752,7 @@ static void _pico_mem_free_slab_block(struct pico_mem_block*slab_block) slab_node = pico_mem_page0_zalloc(sizeof(struct pico_mem_slab_node)); - if(slab_node == NULL) - { + if (slab_node == NULL) { /* Update the page householding without making the slab available again! */ DBG_MM_RED("No more space in the manager heap and no more space for extra pages!"); DBG_MM_RED("This slab will be leaked, but the leak will be plugged at the next cleanup, if and when the page is empty"); @@ -819,15 +763,13 @@ static void _pico_mem_free_slab_block(struct pico_mem_block*slab_block) slab_node->slab = slab_block; slab_block->internals.slab_block.slab_node = slab_node; tree_node = pico_tree_findNode(&manager->tree, slab_node); - if(tree_node != NULL) - { + if (tree_node != NULL) { first_slab_node = (struct pico_mem_slab_node*) tree_node->keyValue; tree_node->keyValue = slab_node; first_slab_node->prev = slab_node; slab_node->prev = NULL; slab_node->next = first_slab_node; - } - else{ + } else { DBG_MM_BLUE("No node found for size %i so calling pico_tree_insert", slab_node->slab->internals.slab_block.page->slab_size); slab_node->next = NULL; slab_node->prev = NULL; @@ -839,8 +781,7 @@ static void _pico_mem_free_slab_block(struct pico_mem_block*slab_block) temp = manager_tree_insert(&manager->tree, slab_node); /* if(pico_err == PICO_ERR_ENOMEM) */ - if(temp == &LEAF) - { + if (temp == &LEAF) { DBG_MM_RED("No more space in the manager heap and no more space for extra pages!"); DBG_MM_RED("This slab will be leaked, but the leak will be plugged at the next cleanup, if and when the page is empty"); pico_mem_page0_free(slab_node); @@ -860,14 +801,11 @@ static void _pico_mem_free_slab_block(struct pico_mem_block*slab_block) */ static void _pico_mem_zero_initialize(void*startOfData, size_t len) { - if(startOfData != NULL) - { + if (startOfData != NULL) { DBG_MM_YELLOW("Zero initializing user memory at %p of %u bytes", startOfData, len); memset(startOfData, 0, len); DBG_MM_GREEN("Zero initialized."); - } - else - { + } else { DBG_MM_RED("Got a NULL pointer to zero initialize!"); } } @@ -883,8 +821,7 @@ static void*_pico_mem_find_heap_block(struct pico_mem_page*page, size_t len) uint8_t*byteptr; DBG_MM_YELLOW("Searching for a heap block of length %u in page %p (largest free block size = %u)", len, page, page->heap_max_free_space); - if(page->heap_max_free_space < len ) - { + if (page->heap_max_free_space < len) { DBG_MM_RED("Size %u > max free space %u of the page. This should only happen when this page is newly created, and its heap space is not large enough for the heap length!", len, page->heap_max_free_space); return NULL; } @@ -895,16 +832,14 @@ static void*_pico_mem_find_heap_block(struct pico_mem_page*page, size_t len) /* If mem_block == NULL then a free block at the end of the list is found. */ /* Else, if the block is free and the size > len, an available block is also found. */ /* while(mem_block != NULL && mem_block->type == HEAP_BLOCK_TYPE && ( mem_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || mem_block->internals.heap_block.size < len)) */ - while(mem_block->type == HEAP_BLOCK_TYPE && (mem_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || mem_block->internals.heap_block.size < len)) - { + while (mem_block->type == HEAP_BLOCK_TYPE && (mem_block->internals.heap_block.free == HEAP_BLOCK_NOT_FREE || mem_block->internals.heap_block.size < len)) { /* DBG_MM_RED("Skipping heap block in use at %p of size %i", mem_block, mem_block->size); */ DBG_MM_BLUE("Skipping heap block %s (size %u) at %p", (mem_block->internals.heap_block.free == HEAP_BLOCK_FREE) ? "not in use" : "in use", mem_block->internals.heap_block.size, mem_block); byteptr = (uint8_t*) mem_block + sizeof(struct pico_mem_block); byteptr += mem_block->internals.heap_block.size; mem_block = (struct pico_mem_block*) byteptr; } - if(mem_block->type == SLAB_BLOCK_TYPE) - { + if (mem_block->type == SLAB_BLOCK_TYPE) { DBG_MM_RED("No free heap block of contiguous size %u could be found in page %p", len, page); /* exit(1); */ return NULL; @@ -915,8 +850,7 @@ static void*_pico_mem_find_heap_block(struct pico_mem_page*page, size_t len) page->timestamp = 0; /* Check to split the block into two smaller blocks */ - if(mem_block->internals.heap_block.size >= (len + sizeof(struct pico_mem_block) + PICO_MEM_MINIMUM_OBJECT_SIZE)) - { + if (mem_block->internals.heap_block.size >= (len + sizeof(struct pico_mem_block) + PICO_MEM_MINIMUM_OBJECT_SIZE)) { byteptr = (uint8_t*) mem_block + sizeof(struct pico_mem_block); byteptr += len; inserted_block = (struct pico_mem_block*) byteptr; @@ -956,14 +890,13 @@ static void*_pico_mem_find_slab(size_t len) /* The compare function takes an int*** length */ node = pico_tree_findNode(&manager->tree, &doublelenptr); - if(node != NULL) { + if (node != NULL) { /* DBG_MM_BLUE("Found node, size = %d ", ((pico_mem_slab_node*) node->keyValue)->slab->size); */ struct pico_mem_slab_node*slab_node = node->keyValue; slab_node->slab->internals.slab_block.page->slabs_free--; slab_node->slab->internals.slab_block.page->timestamp = 0; DBG_MM_BLUE("Found node, size = %u at page %p, %u free slabs left in page", slab_node->slab->internals.slab_block.page->slab_size, slab_node->slab->internals.slab_block.page, slab_node->slab->internals.slab_block.page->slabs_free); - if(slab_node->next == NULL) - { + if (slab_node->next == NULL) { DBG_MM_BLUE("This was the last available slab object. Deleting the tree node now."); /* if this is the last slab object of this size in the tree, then also delete the tree_node! */ @@ -972,9 +905,7 @@ static void*_pico_mem_find_slab(size_t len) manager_tree_delete(&manager->tree, &doublelenptr); - } - else - { + } else { /* Remove the pico_mem_slab_node by making the keyvalue of the pico_tree_node point to the next element. */ slab_node->next->prev = NULL; node->keyValue = slab_node->next; @@ -1007,26 +938,21 @@ void pico_mem_free(void*ptr) DBG_MM_YELLOW("Free called on %p", ptr); - if(ptr == NULL) return; + if (ptr == NULL)return; generic_block = (struct pico_mem_block*) ptr; generic_block--; - if(generic_block->type == SLAB_BLOCK_TYPE) - { - if(generic_block->internals.slab_block.slab_node) - { + if (generic_block->type == SLAB_BLOCK_TYPE) { + if (generic_block->internals.slab_block.slab_node) { DBG_MM_RED("ERROR: Double free on a slab block (recovered)!"); return; } DBG_MM_BLUE("Request to free a slab block"); _pico_mem_free_slab_block(generic_block); - } - else if(generic_block->type == HEAP_BLOCK_TYPE) - { - if(generic_block->internals.heap_block.free == HEAP_BLOCK_FREE) - { + } else if (generic_block->type == HEAP_BLOCK_TYPE) { + if (generic_block->internals.heap_block.free == HEAP_BLOCK_FREE) { DBG_MM_RED("ERROR: Double free on a heap block (recovered)!"); return; } @@ -1036,11 +962,9 @@ void pico_mem_free(void*ptr) /* Update the page housekeeping */ /* Update the housekeeping of the extra manager pages */ page = manager->first_page; - while(page != NULL) - { + while (page != NULL) { DBG_MM_BLUE("Checking page %i at %p", i++, page); - if(((uint8_t*) page < (uint8_t*) ptr) && ((uint8_t*) ptr < (uint8_t*) page + PICO_MEM_PAGE_SIZE)) - { + if (((uint8_t*) page < (uint8_t*) ptr) && ((uint8_t*) ptr < (uint8_t*) page + PICO_MEM_PAGE_SIZE)) { /* DBG_MM_RED("page < ptr < page + PICO_MEM_PAGE_SIZE"); */ /* DBG_MM_RED("%p < %p < %p", (uint8_t*) page, (uint8_t*) ptr, (uint8_t*) page + PICO_MEM_PAGE_SIZE); */ _pico_mem_free_and_merge_heap_block(page, generic_block); @@ -1050,9 +974,7 @@ void pico_mem_free(void*ptr) page = page->next_page; } - } - else - { + } else { DBG_MM_RED("ERROR: You tried to free a pointer from which the type ( heap block or slab object ) could not be determined!!"); } } @@ -1068,50 +990,37 @@ static void _pico_mem_reset_slab_statistics(void) static size_t _pico_mem_determine_slab_size(size_t len) { DBG_MM_YELLOW("Determining slab size to use, request for %u bytes", len); - if (len > slab_sizes[1]) - { + if (len > slab_sizes[1]) { slab_size_statistics[2]++; - if(slab_size_statistics[2] > 3) - { + if (slab_size_statistics[2] > 3) { _pico_mem_reset_slab_statistics(); - if(slab_size_global != slab_sizes[2]) - { + if (slab_size_global != slab_sizes[2]) { slab_size_global = slab_sizes[2]; } } - if(slab_size_global != slab_sizes[2]) - { + if (slab_size_global != slab_sizes[2]) { DBG_MM_RED("Using slab size %u, but we have to use a slab size of %u for the request of %u bytes", slab_size_global, slab_sizes[2], len); return slab_sizes[2]; } - } - else if(len > slab_sizes[0]) - { + } else if (len > slab_sizes[0]) { slab_size_statistics[1]++; - if (slab_size_statistics[1] > 3) - { + if (slab_size_statistics[1] > 3) { _pico_mem_reset_slab_statistics(); - if(slab_size_global != slab_sizes[1]) - { + if (slab_size_global != slab_sizes[1]) { slab_size_global = slab_sizes[1]; } } - if(len > slab_size_global) - { + if (len > slab_size_global) { DBG_MM_RED("Using slab size %u, but we have to use a slab size of %u for the request of %u bytes", slab_size_global, slab_sizes[1], len); return slab_sizes[1]; } - } - else - { + } else { slab_size_statistics[0]++; - if (slab_size_statistics[0] > 3) - { + if (slab_size_statistics[0] > 3) { _pico_mem_reset_slab_statistics(); - if(slab_size_global != slab_sizes[0]) - { + if (slab_size_global != slab_sizes[0]) { slab_size_global = slab_sizes[0]; } } @@ -1151,56 +1060,47 @@ void*pico_mem_zalloc(size_t len) len += (len % 4 == 0) ? 0 : 4 - len % 4; DBG_MM_YELLOW("Aligned size: %i", len); - if(manager == NULL) - { + if (manager == NULL) { DBG_MM_RED("Invalid alloc, a memory manager hasn't been instantiated yet!"); return NULL; } - if(len > PICO_MAX_SLAB_SIZE) - { + if (len > PICO_MAX_SLAB_SIZE) { DBG_MM_RED("Invalid alloc, the size you requested is larger than the maximum slab size! (%uB>%uB)", len, PICO_MAX_SLAB_SIZE); return NULL; } /* /////// FIND SLAB OBJECTS ///////// */ - if(len >= PICO_MIN_SLAB_SIZE) - { + if (len >= PICO_MIN_SLAB_SIZE) { /* feed the size into a statistic engine that determines the slabsize to use */ /* DBG_MM_RED("Placeholder: determine correct slab size to use!"); */ len = _pico_mem_determine_slab_size(len); ret = _pico_mem_find_slab(len); - if(ret != NULL) return ret; + if (ret != NULL)return ret; /* No slab object could be found. => Init new page? */ DBG_MM_BLUE("No free slab found, trying to create a new page (Used size = %u, max size = %u)", manager->used_size, manager->size); - if(manager->used_size + PICO_MEM_PAGE_SIZE <= manager->size) - { + if (manager->used_size + PICO_MEM_PAGE_SIZE <= manager->size) { struct pico_mem_page*newpage = pico_zalloc(PICO_MEM_PAGE_SIZE); - if(newpage != NULL) - { + if (newpage != NULL) { manager->used_size += PICO_MEM_PAGE_SIZE; DBG_MM_BLUE("Created new page at %p -> used size = %u", newpage, manager->used_size); _pico_mem_init_page(newpage, len); /* Return pointer to first slab in that page */ return _pico_mem_find_slab(len); /* Find the new slab object! */ - } - else - { + } else { DBG_MM_RED("Not enough space to allocate a new page, even though the max size hasn't been reached yet!"); return NULL; } - } - else - { + } else { DBG_MM_RED("Not enough space to allocate a new page!"); return NULL; } } /* /////// FIND HEAP BLOCKS ///////// */ - if(len < PICO_MEM_MINIMUM_OBJECT_SIZE) + if (len < PICO_MEM_MINIMUM_OBJECT_SIZE) len = PICO_MEM_MINIMUM_OBJECT_SIZE; DBG_MM_BLUE("Searching for heap space of length %u now.", len); @@ -1210,12 +1110,10 @@ void*pico_mem_zalloc(size_t len) /* The algorithm to find a heap block is based on first fit. */ /* But when the internal fragmentation is too big, the block is split. */ - while(page != NULL) - { + while (page != NULL) { /* DBG_MM_RED("Max free space in page %i = %i bytes", pagecounter+1, page->heap.max_free_space); */ DBG_MM_BLUE("Max free space in page %u = %uB (page=%p)", pagenr, page->heap_max_free_space, page); - if(len <= page->heap_max_free_space) - { + if (len <= page->heap_max_free_space) { return _pico_mem_find_heap_block(page, len); } @@ -1224,21 +1122,17 @@ void*pico_mem_zalloc(size_t len) } /* No free heap block could be found, try to alloc a new page */ DBG_MM_BLUE("No free heap block found, trying to create a new page (Used size = %u, max size = %u)", manager->used_size, manager->size); - if(manager->used_size + PICO_MEM_PAGE_SIZE <= manager->size) - { + if (manager->used_size + PICO_MEM_PAGE_SIZE <= manager->size) { struct pico_mem_page*newpage = pico_zalloc(PICO_MEM_PAGE_SIZE); - if(newpage != NULL) - { + if (newpage != NULL) { manager->used_size += PICO_MEM_PAGE_SIZE; DBG_MM_BLUE("Created new page at %p -> used size = %u", newpage, manager->used_size); /* TODO: Careful, if the current slabsize is determined in another way, this needs to change too */ _pico_mem_init_page(newpage, slab_size_global); returnCandidate = _pico_mem_find_heap_block(newpage, len); - if(returnCandidate != NULL) + if (returnCandidate != NULL) return returnCandidate; - } - else - { + } else { DBG_MM_RED("Not enough space to allocate a new page, even though the max size hasn't been reached yet!"); return NULL; } @@ -1269,11 +1163,9 @@ void pico_mem_page0_free(void*ptr) node->internals.heap_block.free = HEAP_BLOCK_FREE; /* Update the housekeeping of the extra manager pages */ heap_page = manager->manager_extra; - while(heap_page != NULL) - { + while (heap_page != NULL) { DBG_MM_BLUE("Checking extra heap page %i at %p", i++, heap_page); - if(((uint8_t*) heap_page < (uint8_t*) ptr) && ((uint8_t*) ptr < (uint8_t*) heap_page + PICO_MEM_PAGE_SIZE)) - { + if (((uint8_t*) heap_page < (uint8_t*) ptr) && ((uint8_t*) ptr < (uint8_t*) heap_page + PICO_MEM_PAGE_SIZE)) { /* DBG_MM_RED("heap_page < ptr < heap_page + PICO_MEM_PAGE_SIZE"); */ /* DBG_MM_RED("%p < %p < %p", (uint8_t*) heap_page, (uint8_t*) ptr, (uint8_t*) heap_page + PICO_MEM_PAGE_SIZE); */ heap_page->blocks--; @@ -1311,14 +1203,11 @@ void pico_mem_cleanup(uint32_t timestamp) /* Iterate over all pages */ page = manager->first_page; prev_page = NULL; - while(page != NULL) - { + while (page != NULL) { DBG_MM_BLUE("Checking page %i at %p", pagenr, page); /* Check the timestamp of the page. If it doesn't have one (0), update it with the new timestamp if the page is completely empty. */ - if(page->timestamp == 0) - { - if((page->heap_max_size == page->heap_max_free_space) && (page->slabs_free == page->slabs_max)) - { + if (page->timestamp == 0) { + if ((page->heap_max_size == page->heap_max_free_space) && (page->slabs_free == page->slabs_max)) { DBG_MM_BLUE("Page %i empty, updating timestamp", pagenr); page->timestamp = timestamp; } @@ -1328,10 +1217,8 @@ void pico_mem_cleanup(uint32_t timestamp) /* > Update the page list */ /* > Return the page to the system's control */ /* > Update manager housekeeping */ - else if(timestamp > page->timestamp) - { - if(timestamp - page->timestamp > PICO_MEM_PAGE_LIFETIME) - { + else if (timestamp > page->timestamp) { + if (timestamp - page->timestamp > PICO_MEM_PAGE_LIFETIME) { DBG_MM_BLUE("Page %i is empty and has exceeded the lifetime (%u > lifetime=%u)", pagenr, timestamp - page->timestamp, PICO_MEM_PAGE_LIFETIME); /* Remove all the slabs out of the RB tree */ byteptr = (uint8_t*) page + sizeof(struct pico_mem_page); /* byteptr points to the start of the heap (a pico_mem_block), after page housekeeping */ @@ -1341,11 +1228,9 @@ void pico_mem_cleanup(uint32_t timestamp) slab_node = slab_block->internals.slab_block.slab_node; /* The corresponding tree_node */ tree_node = pico_tree_findNode(&manager->tree, slab_node); - for(i = 0; i < page->slabs_max; i++) - { + for (i = 0; i < page->slabs_max; i++) { DBG_MM("Removing slab %i at %p", i, slab_block); - if(slab_node->prev == NULL && slab_node->next == NULL) - { + if (slab_node->prev == NULL && slab_node->next == NULL) { DBG_MM("This node is the last node in the tree_node, removing tree_node"); /* slab_node is the last node in the tree leaf, delete it */ @@ -1354,20 +1239,14 @@ void pico_mem_cleanup(uint32_t timestamp) manager_tree_delete(&manager->tree, slab_node); - } - else if(slab_node->prev == NULL) - { + } else if (slab_node->prev == NULL) { DBG_MM("This node is the first node in the linked list, adjusting tree_node"); tree_node->keyValue = slab_node->next; slab_node->next->prev = NULL; - } - else if(slab_node->next == NULL) - { + } else if (slab_node->next == NULL) { DBG_MM("This node is the last node in the linked list"); slab_node->prev->next = NULL; - } - else - { + } else { DBG_MM("This node is neither the first, nor the last node in the list"); slab_node->prev->next = slab_node->next; slab_node->next->prev = slab_node->prev; @@ -1380,13 +1259,10 @@ void pico_mem_cleanup(uint32_t timestamp) slab_node = slab_block->internals.slab_block.slab_node; } /* Update the page list */ - if(prev_page == NULL) /* prev_page == NULL when pagenr=1, or when previous pages were deleted */ - { + if (prev_page == NULL) { /* prev_page == NULL when pagenr=1, or when previous pages were deleted */ DBG_MM("Updating page list, manager->first_page = page->next_page"); manager->first_page = page->next_page; - } - else - { + } else { DBG_MM("Updating page list, prev_page->next_page = page->next_page"); prev_page->next_page = page->next_page; } @@ -1402,14 +1278,10 @@ void pico_mem_cleanup(uint32_t timestamp) page = next_page; pagenr++; continue; - } - else - { + } else { DBG_MM_BLUE("Page %i is empty, but has not exceeded the lifetime (%u < lifetime=%u)", pagenr, timestamp - page->timestamp, PICO_MEM_PAGE_LIFETIME); } - } - else /* timestamp < page->timestamp */ - { + } else { /* timestamp < page->timestamp */ DBG_MM_RED("Page %i is empty, but the system timestamp < page timestamp! (%u<%u)", pagenr, timestamp, page->timestamp); DBG_MM_RED("Updating page %i timestamp!", pagenr); page->timestamp = timestamp; @@ -1423,30 +1295,21 @@ void pico_mem_cleanup(uint32_t timestamp) heap_page = manager->manager_extra; prev_heap_page = NULL; pagenr = 1; - while(heap_page != NULL) - { + while (heap_page != NULL) { DBG_MM_BLUE("Checking extra manager page %i at %p", pagenr, heap_page); - if(heap_page->timestamp == 0) - { - if( heap_page->blocks == 0 ) - { + if (heap_page->timestamp == 0) { + if (heap_page->blocks == 0) { DBG_MM_BLUE("Extra manager page %i empty, updating timestamp", pagenr); heap_page->timestamp = timestamp; } - } - else if(timestamp > heap_page->timestamp) - { - if(timestamp - heap_page->timestamp > PICO_MEM_PAGE_LIFETIME) - { + } else if (timestamp > heap_page->timestamp) { + if (timestamp - heap_page->timestamp > PICO_MEM_PAGE_LIFETIME) { DBG_MM_BLUE("Extra manager page %i empty and has exceeded the lifetime (%u > lifetime=%u)", pagenr, timestamp - heap_page->timestamp, PICO_MEM_PAGE_LIFETIME); /* Update the page list */ - if(prev_heap_page == NULL) - { + if (prev_heap_page == NULL) { DBG_MM("Updating page list, manager->manager_extra = heap_page->next"); manager->manager_extra = heap_page->next; - } - else - { + } else { DBG_MM("Updating page list, prev_heap_page->next = heap_page->next"); prev_heap_page->next = heap_page->next; } @@ -1462,14 +1325,10 @@ void pico_mem_cleanup(uint32_t timestamp) heap_page = next; pagenr++; continue; - } - else - { + } else { DBG_MM_BLUE("Page %i is empty, but has not exceeded the lifetime (%u < lifetime=%u)", pagenr, timestamp - heap_page->timestamp, PICO_MEM_PAGE_LIFETIME); } - } - else - { + } else { DBG_MM_RED("Page %i is empty, but the system timestamp < page timestamp! (%u<%u)", pagenr, timestamp, heap_page->timestamp); DBG_MM_RED("Updating page %i timestamp!", pagenr); heap_page->timestamp = timestamp; @@ -1501,8 +1360,7 @@ static void _pico_mem_print_tree(struct pico_tree_node*root) struct pico_mem_slab_node*iterator; int j; - if (root == &LEAF || root == NULL) - { + if (root == &LEAF || root == NULL) { DBG_MM("No tree nodes at this time.\n"); return; } @@ -1510,8 +1368,7 @@ static void _pico_mem_print_tree(struct pico_tree_node*root) iterator = (struct pico_mem_slab_node*) root->keyValue; DBG_MM("Tree node for size %u:\n", iterator->slab->internals.slab_block.page->slab_size); j = 0; - while(iterator != NULL) - { + while (iterator != NULL) { DBG_MM("\tSlab_node %i at %p:\n", j, iterator); DBG_MM("\t\tPrev:%p\n", iterator->prev); DBG_MM("\t\tNext:%p\n", iterator->next); @@ -1519,21 +1376,18 @@ static void _pico_mem_print_tree(struct pico_tree_node*root) j++; iterator = iterator->next; } - if(root->leftChild != &LEAF && root->leftChild != NULL) + if (root->leftChild != &LEAF && root->leftChild != NULL) _pico_mem_print_tree(root->leftChild); - if(root->rightChild != &LEAF && root->rightChild != NULL) + if (root->rightChild != &LEAF && root->rightChild != NULL) _pico_mem_print_tree(root->rightChild); } void pico_mem_profile_scan_data() { - if(manager == NULL) - { + if (manager == NULL) { DBG_MM("No memory manager instantiated!\n"); - } - else - { + } else { int manager_pages = 0; int pages = 0; int counter = 0; @@ -1547,8 +1401,7 @@ void pico_mem_profile_scan_data() /* Iterate over every extra manager page: */ heap_page = manager->manager_extra; - while(heap_page != NULL) - { + while (heap_page != NULL) { manager_pages++; DBG_MM("Extra manager page %i:\n\tBlocks in use: %u\n\tTimestamp: %u\n", manager_pages, heap_page->blocks, heap_page->timestamp); heap_page = heap_page->next; @@ -1556,15 +1409,13 @@ void pico_mem_profile_scan_data() /* Iterate over every page: */ pages = (manager->used_size / PICO_MEM_PAGE_SIZE) - manager_pages - 1; page = manager->first_page; - while(page != NULL) - { + while (page != NULL) { counter++; DBG_MM("Page %i/%i:\n\tSlabsize: %u\n\tSlabs free: %u/%u\n\tTimestamp: %u\n", counter, pages, page->slab_size, page->slabs_free, page->slabs_max, page->timestamp); byteptr = (uint8_t*) page + sizeof(struct pico_mem_page); mem_block = (struct pico_mem_block*) byteptr; DBG_MM("\tHeap:\n"); - while(mem_block->type == HEAP_BLOCK_TYPE) - { + while (mem_block->type == HEAP_BLOCK_TYPE) { DBG_MM("\t\tBlock: size %u, %s\n", mem_block->internals.heap_block.size, (mem_block->internals.heap_block.free == HEAP_BLOCK_FREE) ? "free" : "not free"); byteptr = (uint8_t*) mem_block + sizeof(struct pico_mem_block); byteptr += mem_block->internals.heap_block.size; @@ -1584,25 +1435,19 @@ void pico_mem_profile_collect_data(struct profiling_data*profiling_struct) profiling_struct->free_slab_space = 0; profiling_struct->used_heap_space = 0; profiling_struct->used_slab_space = 0; - if(manager != NULL) - { + if (manager != NULL) { struct pico_mem_page*page = manager->first_page; - while(page != NULL) - { + while (page != NULL) { profiling_struct->free_slab_space += page->slab_size * page->slabs_free; profiling_struct->used_slab_space += page->slab_size * page->slabs_max; byteptr = (uint8_t*) page + sizeof(struct pico_mem_page); mem_block = (struct pico_mem_block*) byteptr; - while(mem_block->type == HEAP_BLOCK_TYPE) - { - if(mem_block->internals.heap_block.free == HEAP_BLOCK_FREE) - { + while (mem_block->type == HEAP_BLOCK_TYPE) { + if (mem_block->internals.heap_block.free == HEAP_BLOCK_FREE) { profiling_struct->free_heap_space += mem_block->internals.heap_block.size; - } - else - { + } else { /* dbg("Block: size=%u\n", mem_block->internals.heap_block.size); */ profiling_struct->used_heap_space += mem_block->internals.heap_block.size; } @@ -1617,12 +1462,9 @@ void pico_mem_profile_collect_data(struct profiling_data*profiling_struct) uint32_t pico_mem_profile_used_size() { - if(manager != NULL) - { + if (manager != NULL) { return manager->used_size; - } - else - { + } else { return 0; } } diff --git a/modules/pico_mm.h b/modules/pico_mm.h index 567dc9ce..25710a04 100644 --- a/modules/pico_mm.h +++ b/modules/pico_mm.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_nat.c b/modules/pico_nat.c index 52f15da9..dc07d105 100644 --- a/modules/pico_nat.c +++ b/modules/pico_nat.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -7,7 +7,7 @@ * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Kristof Roelants, Brecht Van Cauwenberghe, Simon Maes, Philippe Mariman - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -295,7 +295,7 @@ static struct pico_nat_tuple *pico_ipv4_nat_generate_tuple(struct pico_stack *S, return NULL; trans = pico_nat_generate_tuple_trans(net, f); - if(!trans) + if (!trans) return NULL; return pico_ipv4_nat_add(S, net->dst, trans->dport, net->src, trans->sport, nat_link->address, nport, net->proto); @@ -357,8 +357,7 @@ static void pico_ipv4_nat_table_cleanup(pico_time now, void *_stack) pico_tree_foreach_reverse_safe(index, &S->NATOutbound, _tmp) { t = index->keyValue; - switch (t->proto) - { + switch (t->proto) { case PICO_PROTO_TCP: if (t->portforward) break; @@ -413,8 +412,7 @@ int pico_ipv4_port_forward(struct pico_stack *S, struct pico_ip4 nat_addr, uint1 }; uint16_t any_port = 0; - switch (flag) - { + switch (flag) { case PICO_NAT_PORT_FORWARD_ADD: t = pico_ipv4_nat_add(S, any_addr, any_port, src_addr, src_port, nat_addr, nat_port, proto); if (!t) { diff --git a/modules/pico_nat.h b/modules/pico_nat.h index 3f1dc464..aa99734e 100644 --- a/modules/pico_nat.h +++ b/modules/pico_nat.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_olsr.c b/modules/pico_olsr.c index 9f15c08a..778c9c1f 100644 --- a/modules/pico_olsr.c +++ b/modules/pico_olsr.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2018-2020 Daniele Lacamera * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only @@ -47,7 +47,7 @@ int OOM(void); #define OLSR_MAXJITTER ((uint32_t)(OLSR_HELLO_INTERVAL >> 2)) #define OLSR_HELLO_INTERVAL_SECONDS (uint32_t)(OLSR_HELLO_INTERVAL/1000) -#define OLSR_TC_INTERVAL_SECONDS (uint32_t)(OLSR_TC_INTERVAL/1000) +#define OLSR_TC_INTERVAL_SECONDS (uint32_t)(OLSR_TC_INTERVAL/1000) static const struct pico_ip4 HOST_NETMASK = { 0xffffffff @@ -57,7 +57,7 @@ static const struct pico_ip4 HOST_NETMASK = { #endif #ifndef AVG -# define AVG(a,b) ((uint8_t)(((int)a + (int)b) >> 1u)) +# define AVG(a, b) ((uint8_t)(((int)a + (int)b) >> 1u)) #endif #define fresher(a, b) ((a > b) || ((b - a) > 32768)) @@ -140,7 +140,7 @@ PACKED_STRUCT_DEF olsrhdr static struct olsr_dev_entry *olsr_get_deventry(struct pico_device *dev) { struct olsr_dev_entry *cur = dev->stack->OLSRLocal_devices; - while(cur) { + while (cur) { if (cur->dev == dev) return cur; @@ -154,7 +154,7 @@ static inline void olsr_route_del(struct olsr_route_entry *r); struct olsr_route_entry *olsr_get_ethentry(struct pico_device *vif) { struct olsr_route_entry *cur = vif->stack->OLSRLocal_interfaces; - while(cur) { + while (cur) { if (cur->iface == vif) return cur; @@ -166,9 +166,9 @@ struct olsr_route_entry *olsr_get_ethentry(struct pico_device *vif) static struct olsr_route_entry *get_next_hop(struct olsr_route_entry *dst) { struct olsr_route_entry *hop = dst; - while(hop) { + while (hop) { /* olsr_dbg("Finding next hop to %08x m=%d", hop->destination.addr, hop->metric); */ - if(hop->metric <= 1) + if (hop->metric <= 1) return hop; hop = hop->gateway; @@ -180,7 +180,7 @@ static inline void olsr_route_add(struct olsr_route_entry *el) { struct olsr_route_entry *nexthop; - if(!el) + if (!el) return; el->iface->stack->pico_olsr_ansn++; @@ -241,7 +241,7 @@ static inline void olsr_route_del(struct olsr_route_entry *r) static struct olsr_route_entry *get_route_by_address(struct olsr_route_entry *lst, uint32_t ip) { struct olsr_route_entry *found; - while(lst) { + while (lst) { if (lst->destination.addr == ip) { return lst; } @@ -281,8 +281,7 @@ static uint8_t seconds2olsr(uint32_t seconds) { uint16_t den = ((uint16_t)(1u << b) >> 4u); /* olsr_dbg(" den=%u ", den); */ - if (den == 0) - { + if (den == 0) { /* olsr_dbg("div by 0!\n"); */ den = 1u; } @@ -301,7 +300,7 @@ static uint8_t seconds2olsr(uint32_t seconds) static void olsr_garbage_collector(struct olsr_route_entry *sublist) { struct pico_stack *S; - if(!sublist) + if (!sublist) return; S = sublist->iface->stack; olsr_garbage_collector(sublist->next); @@ -356,11 +355,11 @@ static void olsr_process_out(pico_time now, void *arg) else bcast.addr = 0xFFFFFFFFu; - if ( 0 > pico_socket_sendto(p->pdev->stack->pico_olsr_socket, p->buf, p->len, &bcast, OLSR_PORT)) { + if (0 > pico_socket_sendto(p->pdev->stack->pico_olsr_socket, p->buf, p->len, &bcast, OLSR_PORT)) { olsr_dbg("olsr send\n"); } } else { - while(pdev) { + while (pdev) { ohdr->seq = short_be((uint16_t)(pdev->pkt_counter++)); addr = pico_ipv4_link_by_dev(pdev->dev->stack, pdev->dev); if (!addr) @@ -371,7 +370,7 @@ static void olsr_process_out(pico_time now, void *arg) else bcast.addr = 0xFFFFFFFFu; - if ( 0 > pico_socket_sendto(p->pdev->stack->pico_olsr_socket, p->buf, p->len, &bcast, OLSR_PORT)) { + if (0 > pico_socket_sendto(p->pdev->stack->pico_olsr_socket, p->buf, p->len, &bcast, OLSR_PORT)) { olsr_dbg("olsr send\n"); } @@ -582,8 +581,8 @@ static void olsr_compose_tc_dgram(struct pico_device *pdev, struct pico_ipv4_lin r = olsr_build_tc_neighbors(pdev->stack, dgram + size, TC_DGRAM_MAX_SIZE - size, &last_neighbor); size += r; msg_tc->size = short_be((uint16_t)(sizeof(struct olsrmsg) + sizeof(struct olsr_hmsg_tc) + r)); - olsr_scheduled_output(OLSR_TC_INTERVAL, dgram, (uint16_t)size, pdev ); - } while(last_neighbor); + olsr_scheduled_output(OLSR_TC_INTERVAL, dgram, (uint16_t)size, pdev); + } while (last_neighbor); } static void olsr_compose_hello_dgram(struct pico_device *pdev, struct pico_ipv4_link *ep) @@ -627,8 +626,8 @@ static void olsr_compose_hello_dgram(struct pico_device *pdev, struct pico_ipv4_ size += r; msg_hello->size = short_be((uint16_t)(sizeof(struct olsrmsg) + sizeof(struct olsr_hmsg_hello) + r)); - olsr_scheduled_output(OLSR_HELLO_INTERVAL, dgram, (uint16_t)size, pdev ); - } while(last_neighbor); + olsr_scheduled_output(OLSR_HELLO_INTERVAL, dgram, (uint16_t)size, pdev); + } while (last_neighbor); } static void olsr_make_dgram(struct pico_device *pdev, int full) @@ -659,7 +658,7 @@ static int olsr_route_replace(struct olsr_route_entry*r, struct olsr_route_entry } /* Sort by metric first, then lq on same hops */ - if ( (new_metric < r->metric) || ((new_metric == r->metric) && (new_lq > r->lq +10 )) ) { + if ((new_metric < r->metric) || ((new_metric == r->metric) && (new_lq > r->lq + 10))) { struct olsr_route_entry *new = PICO_ZALLOC(sizeof (struct olsr_route_entry)); if (new) { memcpy(new, r, sizeof(struct olsr_dev_entry)); @@ -850,7 +849,7 @@ static int reconsider_topology(struct pico_stack *S, uint8_t *buf, uint32_t size rt->metric = (uint16_t)(e->metric + 1); rt->lq = n->lq; rt->nlq = n->lq; - rt->time_left =(DEFAULT_VTIME); + rt->time_left = (DEFAULT_VTIME); olsr_route_add(rt); } } @@ -896,7 +895,7 @@ static void olsr_recv(struct pico_stack *S, uint8_t *buffer, uint32_t len) struct olsr_route_entry *origin; msg = (struct olsrmsg *) (buffer + parsed); - if(pico_ipv4_link_find(S, &msg->orig) != NULL) { + if (pico_ipv4_link_find(S, &msg->orig) != NULL) { parsed += short_be(msg->size); continue; } @@ -944,52 +943,52 @@ static void olsr_recv(struct pico_stack *S, uint8_t *buffer, uint32_t len) origin->link_type = OLSRLINK_MPR; - switch(msg->type) { - case OLSRMSG_HELLO: { - uint32_t size = (uint32_t)short_be(msg->size); - uint8_t *pay = (uint8_t *) buffer + (uint32_t)parsed + (uint32_t)sizeof(struct olsrmsg) + (uint32_t)sizeof(struct olsr_hmsg_hello); - origin->time_left = (DEFAULT_VTIME); - recv_hello(pay, ((uint32_t) (size - (sizeof(struct olsrmsg)))) - (uint32_t)sizeof(struct olsr_hmsg_hello), origin, msg->hop); - msg->ttl = 0; - } - break; - case OLSRMSG_MID: - if ((origin->seq != 0) && (!fresher(short_be(msg->seq), origin->seq))) { - msg->ttl = 0; - } else { - recv_mid(buffer + parsed + sizeof(struct olsrmsg), (uint32_t)(short_be(msg->size) - (sizeof(struct olsrmsg))), origin); - /* olsr_dbg("MID forwarded from origin %08x (seq: %u)\n", long_be(msg->orig.addr), short_be(msg->seq)); */ - origin->seq = short_be(msg->seq); - } - - break; - case OLSRMSG_TC: - if(!pico_ipv4_link_find(S, &origin->destination)) { - if ((origin->seq != 0) && (!fresher(short_be(msg->seq), origin->seq))) { - msg->ttl = 0; - origin->seq = short_be(msg->seq); - PICO_FREE(datagram); - return; - } else { - /* Only parse valid messages */ - int ret = reconsider_topology(origin->iface->stack, buffer + parsed + sizeof(struct olsrmsg), - (uint32_t)(short_be(msg->size) - (sizeof(struct olsrmsg))), - origin); - if (ret == 0) { - msg->ttl = 0; - } - origin->seq = short_be(msg->seq); - } - } else { - /* We originated this TC. */ - msg->ttl = 0; - } - - - break; - default: - PICO_FREE(datagram); - return; + switch (msg->type) { + case OLSRMSG_HELLO: { + uint32_t size = (uint32_t)short_be(msg->size); + uint8_t *pay = (uint8_t *) buffer + (uint32_t)parsed + (uint32_t)sizeof(struct olsrmsg) + (uint32_t)sizeof(struct olsr_hmsg_hello); + origin->time_left = (DEFAULT_VTIME); + recv_hello(pay, ((uint32_t) (size - (sizeof(struct olsrmsg)))) - (uint32_t)sizeof(struct olsr_hmsg_hello), origin, msg->hop); + msg->ttl = 0; + } + break; + case OLSRMSG_MID: + if ((origin->seq != 0) && (!fresher(short_be(msg->seq), origin->seq))) { + msg->ttl = 0; + } else { + recv_mid(buffer + parsed + sizeof(struct olsrmsg), (uint32_t)(short_be(msg->size) - (sizeof(struct olsrmsg))), origin); + /* olsr_dbg("MID forwarded from origin %08x (seq: %u)\n", long_be(msg->orig.addr), short_be(msg->seq)); */ + origin->seq = short_be(msg->seq); + } + + break; + case OLSRMSG_TC: + if (!pico_ipv4_link_find(S, &origin->destination)) { + if ((origin->seq != 0) && (!fresher(short_be(msg->seq), origin->seq))) { + msg->ttl = 0; + origin->seq = short_be(msg->seq); + PICO_FREE(datagram); + return; + } else { + /* Only parse valid messages */ + int ret = reconsider_topology(origin->iface->stack, buffer + parsed + sizeof(struct olsrmsg), + (uint32_t)(short_be(msg->size) - (sizeof(struct olsrmsg))), + origin); + if (ret == 0) { + msg->ttl = 0; + } + origin->seq = short_be(msg->seq); + } + } else { + /* We originated this TC. */ + msg->ttl = 0; + } + + + break; + default: + PICO_FREE(datagram); + return; } if (msg->ttl > 1) { @@ -1053,7 +1052,7 @@ static void olsr_hello_tick(pico_time when, void *arg) struct pico_stack *S = (struct pico_stack *)arg; (void)when; d = S->OLSRLocal_devices; - while(d) { + while (d) { olsr_make_dgram(d->dev, 0); d = d->next; } @@ -1066,7 +1065,7 @@ static void olsr_tc_tick(pico_time when, void *arg) struct pico_stack *S = (struct pico_stack *)arg; (void)when; d = S->OLSRLocal_devices; - while(d) { + while (d) { olsr_make_dgram(d->dev, 1); d = d->next; } @@ -1155,7 +1154,7 @@ int pico_olsr_add(struct pico_device *dev) dev->stack->OLSRLocal_interfaces = e; } - } while(lnk); + } while (lnk); return 0; } @@ -1164,8 +1163,8 @@ struct olsr_route_entry kill_neighbour(struct pico_stack *S, uint32_t loc_add, u { struct olsr_route_entry *origin; origin = get_route_by_address(S->OLSRLocal_interfaces, rem_add); - if (origin){ - if (origin->gateway){ + if (origin) { + if (origin->gateway) { if (origin->gateway->destination.addr == loc_add) origin->time_left = 0; } diff --git a/modules/pico_olsr.h b/modules/pico_olsr.h index 212abcd2..daf7baf9 100644 --- a/modules/pico_olsr.h +++ b/modules/pico_olsr.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -43,7 +43,7 @@ struct olsr_route_entry uint16_t ansn; uint16_t seq; uint8_t lq, nlq; - uint8_t advertised_tc; + uint8_t advertised_tc; }; diff --git a/modules/pico_slaacv4.c b/modules/pico_slaacv4.c index bb594921..fe351a46 100644 --- a/modules/pico_slaacv4.c +++ b/modules/pico_slaacv4.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -83,13 +83,11 @@ static struct slaacv4_cookie slaacv4_local; static uint32_t pico_slaacv4_getip(struct pico_device *dev, uint8_t rand) { uint32_t seed = 0; - if (dev->eth != NULL) - { + if (dev->eth != NULL) { seed = pico_hash((const uint8_t *)dev->eth->mac.addr, PICO_SIZE_ETH); } - if (rand) - { + if (rand) { seed += pico_rand(); } @@ -124,8 +122,7 @@ static void pico_slaacv4_send_announce_timer(pico_time now, void *arg) (void)now; - if (tmp->announce_nb < ANNOUNCE_NB) - { + if (tmp->announce_nb < ANNOUNCE_NB) { pico_arp_request(tmp->device, &tmp->ip, PICO_ARP_ANNOUNCE); tmp->announce_nb++; tmp->timer = pico_timer_add(tmp->device->stack, ANNOUNCE_INTERVAL * 1000, pico_slaacv4_send_announce_timer, arg); @@ -135,9 +132,7 @@ static void pico_slaacv4_send_announce_timer(pico_time now, void *arg) if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } - } - else - { + } else { tmp->state = SLAACV4_CLAIMED; pico_ipv4_link_add(tmp->device->stack, tmp->device, tmp->ip, netmask); if (tmp->cb != NULL) @@ -150,8 +145,7 @@ static void pico_slaacv4_send_probe_timer(pico_time now, void *arg) struct slaacv4_cookie *tmp = (struct slaacv4_cookie *)arg; (void)now; - if (tmp->probe_try_nb < PROBE_NB) - { + if (tmp->probe_try_nb < PROBE_NB) { pico_arp_request(tmp->device, &tmp->ip, PICO_ARP_PROBE); tmp->probe_try_nb++; tmp->timer = pico_timer_add(tmp->device->stack, PROBE_WAIT * 1000, pico_slaacv4_send_probe_timer, tmp); @@ -161,9 +155,7 @@ static void pico_slaacv4_send_probe_timer(pico_time now, void *arg) if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } - } - else - { + } else { tmp->state = SLAACV4_ANNOUNCING; tmp->timer = pico_timer_add(tmp->device->stack, ANNOUNCE_WAIT * 1000, pico_slaacv4_send_announce_timer, arg); if (!tmp->timer) { @@ -182,16 +174,13 @@ static void pico_slaacv4_receive_ipconflict(struct pico_stack *S, int reason) tmp->conflict_nb++; pico_slaacv4_cancel_timers(tmp); - if(tmp->state == SLAACV4_CLAIMED) - { - if(reason == PICO_ARP_CONFLICT_REASON_CONFLICT) - { + if (tmp->state == SLAACV4_CLAIMED) { + if (reason == PICO_ARP_CONFLICT_REASON_CONFLICT) { pico_ipv4_link_del(tmp->device->stack, tmp->device, tmp->ip); } } - if (tmp->conflict_nb < MAX_CONFLICTS) - { + if (tmp->conflict_nb < MAX_CONFLICTS) { tmp->state = SLAACV4_CLAIMING; tmp->probe_try_nb = 0; tmp->announce_nb = 0; @@ -206,26 +195,21 @@ static void pico_slaacv4_receive_ipconflict(struct pico_stack *S, int reason) if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } - } - else if (tmp->conflict_nb < MAX_CONFLICTS_FAIL) - { + } else if (tmp->conflict_nb < MAX_CONFLICTS_FAIL) { tmp->state = SLAACV4_CLAIMING; tmp->probe_try_nb = 0; tmp->announce_nb = 0; tmp->ip.addr = pico_slaacv4_getip(tmp->device, (uint8_t)1); pico_arp_register_ipconflict(S, &tmp->ip, &tmp->device->eth->mac, pico_slaacv4_receive_ipconflict); - tmp->timer = pico_timer_add(S,RATE_LIMIT_INTERVAL * 1000, pico_slaacv4_send_probe_timer, tmp); + tmp->timer = pico_timer_add(S, RATE_LIMIT_INTERVAL * 1000, pico_slaacv4_send_probe_timer, tmp); if (!tmp->timer) { slaacv4_dbg("SLAACV4: Failed to start probe timer\n"); tmp->state = SLAACV4_ERROR; if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } - } - else - { - if (tmp->cb != NULL) - { + } else { + if (tmp->cb != NULL) { pico_hotplug_deregister(tmp->device, &pico_slaacv4_hotplug_cb); tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } @@ -239,8 +223,7 @@ static void pico_slaacv4_hotplug_cb(struct pico_device *dev, int event) { struct slaacv4_cookie *tmp = &slaacv4_local; - if (event == PICO_HOTPLUG_EVENT_UP ) - { + if (event == PICO_HOTPLUG_EVENT_UP) { slaacv4_local.state = SLAACV4_CLAIMING; tmp->probe_try_nb = 0; tmp->announce_nb = 0; @@ -255,10 +238,8 @@ static void pico_slaacv4_hotplug_cb(struct pico_device *dev, int event) if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } - } - else - { - if (tmp->state == SLAACV4_CLAIMED ) + } else { + if (tmp->state == SLAACV4_CLAIMED) pico_ipv4_link_del(dev->stack, tmp->device, tmp->ip); pico_slaacv4_cancel_timers(tmp); @@ -274,20 +255,16 @@ int pico_slaacv4_claimip(struct pico_device *dev, void (*cb)(struct pico_ip4 *ip return -1; } - if( dev->link_state != NULL ) - { + if (dev->link_state != NULL) { /* hotplug detect will work */ ip.addr = pico_slaacv4_getip(dev, 0); pico_slaacv4_init_cookie(&ip, dev, &slaacv4_local, cb); - if (pico_hotplug_register(dev, &pico_slaacv4_hotplug_cb)) - { + if (pico_hotplug_register(dev, &pico_slaacv4_hotplug_cb)) { return -1; } - } - else - { + } else { ip.addr = pico_slaacv4_getip(dev, 0); pico_slaacv4_init_cookie(&ip, dev, &slaacv4_local, cb); @@ -313,8 +290,7 @@ void pico_slaacv4_unregisterip(void) .addr = 0x00000000 }; - if (tmp->state == SLAACV4_CLAIMED) - { + if (tmp->state == SLAACV4_CLAIMED) { pico_ipv4_link_del(tmp->device->stack, tmp->device, tmp->ip); } diff --git a/modules/pico_slaacv4.h b/modules/pico_slaacv4.h index 5df5484c..3e2c60e2 100644 --- a/modules/pico_slaacv4.h +++ b/modules/pico_slaacv4.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_sntp_client.c b/modules/pico_sntp_client.c index e5498666..41bff199 100644 --- a/modules/pico_sntp_client.c +++ b/modules/pico_sntp_client.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -100,7 +100,7 @@ static union pico_address sntp_inaddr_any = { /* Converts a sntp time stamp to a pico_timeval struct */ static int timestamp_convert(const struct pico_sntp_ts *ts, struct pico_timeval *tv, pico_time delay) { - if(long_be(ts->sec) < SNTP_UNIX_OFFSET) { + if (long_be(ts->sec) < SNTP_UNIX_OFFSET) { pico_err = PICO_ERR_EINVAL; tv->tv_sec = 0; tv->tv_msec = 0; @@ -120,13 +120,13 @@ static int timestamp_convert(const struct pico_sntp_ts *ts, struct pico_timeval static void pico_sntp_cleanup(struct sntp_server_ns_cookie *ck, pico_err_t status) { sntp_dbg("Cleanup called\n"); - if(!ck) + if (!ck) return; pico_timer_cancel(ck->sock->stack, ck->timer); ck->cb_synced(status); - if(ck->sock) + if (ck->sock) ck->sock->priv = NULL; sntp_dbg("FREE!\n"); @@ -142,7 +142,7 @@ static int pico_sntp_parse(char *buf, struct sntp_server_ns_cookie *ck) struct pico_sntp_header *hp = (struct pico_sntp_header*) buf; struct pico_stack *S; - if(!ck) { + if (!ck) { sntp_dbg("pico_sntp_parse: invalid cookie\n"); return -1; } @@ -153,7 +153,7 @@ static int pico_sntp_parse(char *buf, struct sntp_server_ns_cookie *ck) S->sntp_tick_stamp = S->pico_tick; /* S->sntp_tick_stamp - ck->stamp is the delay between sending and receiving the ntp packet */ ret = timestamp_convert(&(hp->trs_ts), &S->sntp_server_time, (S->sntp_tick_stamp - ck->stamp) / 2); - if(ret != 0) { + if (ret != 0) { sntp_dbg("Conversion error!\n"); pico_sntp_cleanup(ck, PICO_ERR_EINVAL); return ret; @@ -175,7 +175,7 @@ static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s) uint32_t peer; uint16_t port; - if(!ck) { + if (!ck) { sntp_dbg("pico_sntp_client_wakeup: invalid cookie\n"); return; } @@ -190,19 +190,19 @@ static void pico_sntp_client_wakeup(uint16_t ev, struct pico_socket *s) do { read = pico_socket_recvfrom(s, recvbuf, PICO_SNTP_MAXBUF, &peer, &port); - } while(read > 0); + } while (read > 0); pico_sntp_parse(recvbuf, s->priv); s->priv = NULL; /* make sure UDP callback does not try to read from freed mem again */ PICO_FREE(recvbuf); } /* socket is closed */ - else if(ev == PICO_SOCK_EV_CLOSE) { + else if (ev == PICO_SOCK_EV_CLOSE) { sntp_dbg("Socket is closed. Bailing out.\n"); pico_sntp_cleanup(ck, PICO_ERR_ENOTCONN); return; } /* process error event, socket error occurred */ - else if(ev == PICO_SOCK_EV_ERR) { + else if (ev == PICO_SOCK_EV_ERR) { sntp_dbg("Socket Error received. Bailing out.\n"); pico_sntp_cleanup(ck, PICO_ERR_ENOTCONN); return; @@ -217,12 +217,12 @@ static void sntp_receive_timeout(pico_time now, void *arg) struct sntp_server_ns_cookie *ck = (struct sntp_server_ns_cookie *)arg; (void) now; - if(!ck) { + if (!ck) { sntp_dbg("sntp_timeout: invalid cookie\n"); return; } - if(!ck->rec) { + if (!ck->rec) { pico_sntp_cleanup(ck, PICO_ERR_ETIMEDOUT); } } @@ -235,7 +235,7 @@ static void pico_sntp_send(struct pico_socket *sock, union pico_address *dst) }; struct sntp_server_ns_cookie *ck = (struct sntp_server_ns_cookie *)sock->priv; - if(!ck) { + if (!ck) { sntp_dbg("pico_sntp_sent: invalid cookie\n"); return; } @@ -283,17 +283,15 @@ static void dnsCallback(char *ip, void *arg) union pico_address address; int retval = -1; - if(!ck) { + if (!ck) { sntp_dbg("dnsCallback: Invalid argument\n"); return; } - if (0) { - - } + if (0) {} #ifdef PICO_SUPPORT_IPV6 - else if(ck->proto == PICO_PROTO_IPV6) { + else if (ck->proto == PICO_PROTO_IPV6) { if (ip) { /* add the ip address to the client, and start a tcp connection socket */ sntp_dbg("using IPv6 address: %s\n", ip); @@ -307,8 +305,8 @@ static void dnsCallback(char *ip, void *arg) #endif #ifdef PICO_SUPPORT_IPV4 - else if(ck->proto == PICO_PROTO_IPV4) { - if(ip) { + else if (ck->proto == PICO_PROTO_IPV4) { + if (ip) { sntp_dbg("using IPv4 address: %s\n", ip); retval = pico_string_to_ipv4(ip, (uint32_t *)&address.ip4.addr); } else { @@ -358,7 +356,7 @@ static int pico_sntp_sync_start_dns_ipv4(struct pico_stack *S, const char *sntp_ strcpy(ck->hostname, sntp_server); - if(cb_synced == NULL) { + if (cb_synced == NULL) { PICO_FREE(ck->hostname); PICO_FREE(ck); pico_err = PICO_ERR_EINVAL; @@ -415,7 +413,7 @@ static int pico_sntp_sync_start_ipv4(struct pico_stack *S, union pico_address *a static int pico_sntp_sync_start_dns_ipv6(struct pico_stack *S, const char *sntp_server, void (*cb_synced)(pico_err_t status)) { struct sntp_server_ns_cookie *ck6; - int retval6 = -1; + int retval6 = -1; /* IPv6 query */ ck6 = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); if (!ck6) { @@ -451,7 +449,7 @@ static int pico_sntp_sync_start_dns_ipv6(struct pico_stack *S, const char *sntp_ static int pico_sntp_sync_start_ipv6(struct pico_stack *S, union pico_address *addr, void (*cb_synced)(pico_err_t status)) { struct sntp_server_ns_cookie *ck6; - int retval6 = -1; + int retval6 = -1; ck6 = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); if (!ck6) { pico_err = PICO_ERR_ENOMEM; @@ -499,7 +497,7 @@ int pico_sntp_sync(struct pico_stack *S, const char *sntp_server, void (*cb_sync return -1; } - if(cb_synced == NULL) { + if (cb_synced == NULL) { pico_err = PICO_ERR_EINVAL; return -1; } diff --git a/modules/pico_sntp_client.h b/modules/pico_sntp_client.h index f4958957..f5cf8368 100644 --- a/modules/pico_sntp_client.h +++ b/modules/pico_sntp_client.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_socket_ll.c b/modules/pico_socket_ll.c index 743f1c1c..9696434e 100644 --- a/modules/pico_socket_ll.c +++ b/modules/pico_socket_ll.c @@ -44,7 +44,7 @@ int pico_socket_ll_compare(void *ka, void *kb) return -1; if (a->id > b->id) return 1; - return (0); + return 0; } void pico_socket_set_raw(struct pico_socket *s) @@ -53,7 +53,8 @@ void pico_socket_set_raw(struct pico_socket *s) lls->type = PICO_PACKET_TYPE_RAW; } -struct pico_socket *pico_socket_ll_open(struct pico_stack *S, uint16_t proto) { +struct pico_socket *pico_socket_ll_open(struct pico_stack *S, uint16_t proto) +{ struct pico_ll_socket *s; s = PICO_ZALLOC(sizeof(struct pico_ll_socket)); if (!s) { @@ -72,7 +73,7 @@ struct pico_socket *pico_socket_ll_open(struct pico_stack *S, uint16_t proto) { struct pico_frame *pico_ll_frame_alloc(struct pico_stack *S, struct pico_protocol *self, struct pico_device *dev, uint16_t size) { - uint32_t overhead=0; + uint32_t overhead = 0; struct pico_frame *f; (void)S; (void)self; @@ -105,9 +106,8 @@ int pico_socket_ll_process_in(struct pico_stack *S, struct pico_protocol *self, continue; if ((s->sock.local_addr.ll.proto != ehdr->proto) && (s->sock.local_addr.ll.proto != PICO_IDETH_ALL)) continue; - if ( ((s->sock.state & PICO_SOCKET_STATE_BOUND) == 0) || - (memcmp(s->sock.local_addr.ll.hwaddr.addr, ehdr->daddr, 6) == 0) ) - { + if (((s->sock.state & PICO_SOCKET_STATE_BOUND) == 0) || + (memcmp(s->sock.local_addr.ll.hwaddr.addr, ehdr->daddr, 6) == 0)) { cp = pico_frame_copy(f); if (cp) { pico_enqueue(&s->sock.q_in, cp); diff --git a/modules/pico_socket_ll.h b/modules/pico_socket_ll.h index a9eddfd3..7f8cf25b 100644 --- a/modules/pico_socket_ll.h +++ b/modules/pico_socket_ll.h @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only diff --git a/modules/pico_socket_tcp.c b/modules/pico_socket_tcp.c index a4406204..7c289855 100644 --- a/modules/pico_socket_tcp.c +++ b/modules/pico_socket_tcp.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -57,12 +57,9 @@ int pico_getsockopt_tcp(struct pico_socket *s, int option, void *value) /* state of the NODELAY option */ *(int *)value = PICO_SOCKET_GETOPT(s, PICO_SOCKET_OPT_TCPNODELAY); return 0; - } - else if (option == PICO_SOCKET_OPT_RCVBUF) { + } else if (option == PICO_SOCKET_OPT_RCVBUF) { return pico_tcp_get_bufsize_in(s, (uint32_t *)value); - } - - else if (option == PICO_SOCKET_OPT_SNDBUF) { + } else if (option == PICO_SOCKET_OPT_SNDBUF) { return pico_tcp_get_bufsize_out(s, (uint32_t *)value); } @@ -91,33 +88,27 @@ int pico_setsockopt_tcp(struct pico_socket *s, int option, void *value) if (option == PICO_TCP_NODELAY) { tcp_set_nagle_option(s, value); return 0; - } - else if (option == PICO_SOCKET_OPT_RCVBUF) { + } else if (option == PICO_SOCKET_OPT_RCVBUF) { uint32_t *val = (uint32_t*)value; pico_tcp_set_bufsize_in(s, *val); return 0; - } - else if (option == PICO_SOCKET_OPT_SNDBUF) { + } else if (option == PICO_SOCKET_OPT_SNDBUF) { uint32_t *val = (uint32_t*)value; pico_tcp_set_bufsize_out(s, *val); return 0; - } - else if (option == PICO_SOCKET_OPT_KEEPCNT) { + } else if (option == PICO_SOCKET_OPT_KEEPCNT) { uint32_t *val = (uint32_t*)value; pico_tcp_set_keepalive_probes(s, *val); return 0; - } - else if (option == PICO_SOCKET_OPT_KEEPIDLE) { + } else if (option == PICO_SOCKET_OPT_KEEPIDLE) { uint32_t *val = (uint32_t*)value; pico_tcp_set_keepalive_time(s, *val); return 0; - } - else if (option == PICO_SOCKET_OPT_KEEPINTVL) { + } else if (option == PICO_SOCKET_OPT_KEEPINTVL) { uint32_t *val = (uint32_t*)value; pico_tcp_set_keepalive_intvl(s, *val); return 0; - } - else if (option == PICO_SOCKET_OPT_LINGER) { + } else if (option == PICO_SOCKET_OPT_LINGER) { uint32_t *val = (uint32_t*)value; pico_tcp_set_linger(s, *val); return 0; @@ -132,7 +123,7 @@ void pico_socket_tcp_cleanup(struct pico_socket *sock) { #ifdef PICO_SUPPORT_TCP /* for tcp sockets go further and clean the sockets inside queue */ - if(is_sock_tcp(sock)) + if (is_sock_tcp(sock)) pico_tcp_cleanup_queues(sock); #endif @@ -142,7 +133,7 @@ void pico_socket_tcp_cleanup(struct pico_socket *sock) void pico_socket_tcp_delete(struct pico_socket *s) { #ifdef PICO_SUPPORT_TCP - if(s->parent) + if (s->parent) s->parent->number_of_pending_conn--; #endif @@ -209,7 +200,7 @@ static int socket_tcp_do_deliver(struct pico_socket *s, struct pico_frame *f) pico_tcp_input(s, f); if ((s->ev_pending) && s->wakeup) { s->wakeup(s->ev_pending, s); - if(!s->parent) + if (!s->parent) s->ev_pending = 0; } @@ -239,10 +230,9 @@ int pico_socket_tcp_deliver(struct pico_sockport *sp, struct pico_frame *f) found = socket_tcp_deliver_ipv6(s, f); } - if (found) - { + if (found) { target = found; - if ( found->remote_port != 0) + if (found->remote_port != 0) /* only break if it's connected */ break; } @@ -291,7 +281,7 @@ int pico_socket_tcp_read(struct pico_socket *s, void *buf, uint32_t len) void transport_flags_update(struct pico_frame *f, struct pico_socket *s) { #ifdef PICO_SUPPORT_TCP - if(is_sock_tcp(s)) + if (is_sock_tcp(s)) pico_tcp_flags_update(f, s); #endif diff --git a/modules/pico_socket_tcp.h b/modules/pico_socket_tcp.h index 5b326690..f748d9a2 100644 --- a/modules/pico_socket_tcp.h +++ b/modules/pico_socket_tcp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_socket_udp.c b/modules/pico_socket_udp.c index 02d0b885..c7161577 100644 --- a/modules/pico_socket_udp.c +++ b/modules/pico_socket_udp.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -54,18 +54,17 @@ struct pico_socket *pico_socket_udp_open(struct pico_stack *S) #if defined (PICO_SUPPORT_IPV4) || defined (PICO_SUPPORT_IPV6) -static int pico_enqueue_and_wakeup_if_needed(struct pico_queue *q_in, struct pico_socket* s, struct pico_frame* cpy) +static int pico_enqueue_and_wakeup_if_needed(struct pico_queue *q_in, struct pico_socket*s, struct pico_frame*cpy) { - if (pico_enqueue(q_in, cpy) > 0) { - if (s->wakeup){ - s->wakeup(PICO_SOCK_EV_RD, s); - } + if (pico_enqueue(q_in, cpy) > 0) { + if (s->wakeup) { + s->wakeup(PICO_SOCK_EV_RD, s); } - else { - pico_frame_discard(cpy); - return -1; - } - return 0; + } else { + pico_frame_discard(cpy); + return -1; + } + return 0; } #endif @@ -164,8 +163,7 @@ static inline int pico_socket_udp_deliver_ipv6_mcast(struct pico_socket *s, stru if (pico_ipv6_is_unspecified(s->local_addr.ip6.addr) || /* If our local ip is ANY, or... */ (dev == f->dev)) { /* the source of the bcast packet is a neighbor... */ cpy = pico_frame_copy(f); - if (!cpy) - { + if (!cpy) { return -1; } @@ -189,12 +187,9 @@ static int pico_socket_udp_deliver_ipv6(struct pico_socket *s, struct pico_frame pico_frame_discard(f); return retval; #endif - } - else if (pico_ipv6_is_unspecified(s->local_addr.ip6.addr) || (pico_ipv6_compare(&s_local, &p_dst) == 0)) - { /* Either local socket is ANY, or matches dst */ + } else if (pico_ipv6_is_unspecified(s->local_addr.ip6.addr) || (pico_ipv6_compare(&s_local, &p_dst) == 0)) { /* Either local socket is ANY, or matches dst */ cpy = pico_frame_copy(f); - if (!cpy) - { + if (!cpy) { pico_frame_discard(f); return -1; } @@ -241,7 +236,7 @@ int pico_socket_udp_deliver(struct pico_sockport *sp, struct pico_frame *f) int pico_setsockopt_udp(struct pico_socket *s, int option, void *value) { - switch(option) { + switch (option) { case PICO_SOCKET_OPT_RCVBUF: s->q_in.max_size = (*(uint32_t*)value); return 0; @@ -262,7 +257,7 @@ int pico_setsockopt_udp(struct pico_socket *s, int option, void *value) int pico_getsockopt_udp(struct pico_socket *s, int option, void *value) { uint32_t *val = (uint32_t *)value; - switch(option) { + switch (option) { case PICO_SOCKET_OPT_RCVBUF: *val = s->q_in.max_size; return 0; diff --git a/modules/pico_socket_udp.h b/modules/pico_socket_udp.h index fb256679..3fe2055a 100644 --- a/modules/pico_socket_udp.h +++ b/modules/pico_socket_udp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_strings.c b/modules/pico_strings.c index 46a57e2e..73eccb4d 100644 --- a/modules/pico_strings.c +++ b/modules/pico_strings.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: diff --git a/modules/pico_strings.h b/modules/pico_strings.h index d5749035..58e2d585 100644 --- a/modules/pico_strings.h +++ b/modules/pico_strings.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_tcp.c b/modules/pico_tcp.c index e2d5999e..b30085d9 100644 --- a/modules/pico_tcp.c +++ b/modules/pico_tcp.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -123,8 +123,7 @@ static struct tcp_input_segment *segment_from_frame(struct pico_frame *f) return NULL; seg->payload = PICO_ZALLOC(f->payload_len); - if(!seg->payload) - { + if (!seg->payload) { PICO_FREE(seg); return NULL; } @@ -152,8 +151,7 @@ struct pico_tcp_queue static void tcp_discard_all_segments(struct pico_tcp_queue *tq); static void *peek_segment(struct pico_tcp_queue *tq, uint32_t seq) { - if(!IS_INPUT_QUEUE(tq)) - { + if (!IS_INPUT_QUEUE(tq)) { struct pico_tcp_hdr H; struct pico_frame f = { 0 @@ -162,9 +160,7 @@ static void *peek_segment(struct pico_tcp_queue *tq, uint32_t seq) H.seq = long_be(seq); return pico_tree_findKey(&tq->pool, &f); - } - else - { + } else { struct tcp_input_segment dummy = { 0 }; @@ -185,12 +181,9 @@ static void *next_segment(struct pico_tcp_queue *tq, void *cur) if (!cur) return NULL; - if(IS_INPUT_QUEUE(tq)) - { + if (IS_INPUT_QUEUE(tq)) { return peek_segment(tq, ((struct tcp_input_segment *)cur)->seq + ((struct tcp_input_segment *)cur)->payload_len); - } - else - { + } else { return peek_segment(tq, SEQN((struct pico_frame *)cur) + ((struct pico_frame *)cur)->payload_len); } } @@ -209,14 +202,12 @@ static int32_t do_enqueue_segment(struct pico_tcp_queue *tq, void *f, uint16_t p { int32_t ret = -1; PICOTCP_MUTEX_LOCK(Mutex); - if ((tq->size + payload_len) > tq->max_size) - { + if ((tq->size + payload_len) > tq->max_size) { ret = 0; goto out; } - if (pico_tree_insert(&tq->pool, f) != 0) - { + if (pico_tree_insert(&tq->pool, f) != 0) { ret = 0; goto out; } @@ -264,13 +255,11 @@ static void pico_discard_segment(struct pico_tcp_queue *tq, void *f) tq->frames--; } - if(f1 && IS_INPUT_QUEUE(tq)) - { + if (f1 && IS_INPUT_QUEUE(tq)) { struct tcp_input_segment *inp = f1; PICO_FREE(inp->payload); PICO_FREE(inp); - } - else + } else pico_frame_discard(f); PICOTCP_MUTEX_UNLOCK(Mutex); @@ -392,8 +381,7 @@ static int release_until(struct pico_tcp_queue *q, uint32_t seq) else seq_result = pico_seq_compare(SEQN((struct pico_frame *)head) + ((struct pico_frame *)head)->payload_len, seq); - if (seq_result <= 0) - { + if (seq_result <= 0) { head = next_segment(q, cur); /* tcp_dbg("Releasing %08x, len: %d\n", SEQN((struct pico_frame *)head), ((struct pico_frame *)head)->payload_len); */ pico_discard_segment(q, cur); @@ -587,7 +575,7 @@ static inline void tcp_add_sack_option(struct pico_socket_tcp *ts, struct pico_f f->start[(*ii)++] = PICO_TCP_OPTION_SACK; len_off = *ii; f->start[(*ii)++] = PICO_TCPOPTLEN_SACK; - while(ts->sacks) { + while (ts->sacks) { sb = ts->sacks; ts->sacks = sb->next; memcpy(f->start + *ii, sb, 2 * sizeof(uint32_t)); @@ -688,10 +676,9 @@ static inline void tcp_set_space_check_winupdate(struct pico_socket_tcp *t, int3 t->wnd = (uint16_t)space; t->wnd_scale = (uint16_t)shift; - if(t->wnd == 0) /* mark the entering to zero window state */ + if (t->wnd == 0)/* mark the entering to zero window state */ t->localZeroWindow = 1u; - else if(t->localZeroWindow) - { + else if (t->localZeroWindow) { t->localZeroWindow = 0u; tcp_send_windowUpdate(t); } @@ -712,7 +699,7 @@ static void tcp_set_space(struct pico_socket_tcp *t) if (space < 0) space = 0; - while(space > 0xFFFF) { + while (space > 0xFFFF) { space = (int32_t)(((uint32_t)space >> 1u)); shift++; } @@ -740,7 +727,7 @@ static uint16_t tcp_options_size(struct pico_socket_tcp *t, uint16_t flags) if ((flags & PICO_TCP_ACK) && (t->sack_ok && sb)) { size = (uint16_t)(size + 2); - while(sb) { + while (sb) { size = (uint16_t)(size + (2 * sizeof(uint32_t))); sb = sb->next; } @@ -858,7 +845,7 @@ static inline void tcp_parse_option_sack_ok(struct pico_socket_tcp *t, struct pi if (tcpopt_len_check(idx, len, PICO_TCPOPTLEN_SACK_OK) < 0) return; - if(((struct pico_tcp_hdr *)(f->transport_hdr))->flags & PICO_TCP_SYN ) + if (((struct pico_tcp_hdr *)(f->transport_hdr))->flags & PICO_TCP_SYN) t->sack_ok = 1; } @@ -906,7 +893,7 @@ static int tcp_parse_options(struct pico_frame *f) while (i < (f->transport_len - PICO_SIZE_TCPHDR)) { uint8_t type = opt[i++]; uint8_t len; - if(i < (f->transport_len - PICO_SIZE_TCPHDR) && (type > 1)) + if (i < (f->transport_len - PICO_SIZE_TCPHDR) && (type > 1)) len = opt[i++]; else len = 1; @@ -990,7 +977,7 @@ static inline int tcp_send_try_enqueue(struct pico_socket_tcp *ts, struct pico_f } tcp_dbg("DBG> [tcp output] state: %02x --> local port:%u remote port: %u seq: %08x ack: %08x flags: %02x = t_len: %u, hdr: %u payload: %d\n", - TCPSTATE(&ts->sock) >> 8, short_be(hdr->trans.sport), short_be(hdr->trans.dport), SEQN(f), ACKN(f), hdr->flags, f->transport_len, (hdr->len & 0xf0) >> 2, f->payload_len ); + TCPSTATE(&ts->sock) >> 8, short_be(hdr->trans.sport), short_be(hdr->trans.dport), SEQN(f), ACKN(f), hdr->flags, f->transport_len, (hdr->len & 0xf0) >> 2, f->payload_len); } else { pico_frame_discard(cpy); } @@ -1046,8 +1033,7 @@ static void pico_tcp_keepalive(pico_time now, void *arg) } if (t->ka_retries_count > t->ka_probes) { - if (t->sock.wakeup) - { + if (t->sock.wakeup) { pico_err = PICO_ERR_ECONNRESET; t->sock.wakeup(PICO_SOCK_EV_ERR, &t->sock); } @@ -1158,8 +1144,7 @@ static uint32_t tcp_read_finish(struct pico_socket *s, uint32_t tot_rd_len) static inline uint32_t tcp_read_in_frame_len(struct tcp_input_segment *f, int32_t in_frame_off, uint32_t tot_rd_len, uint32_t read_op_len) { uint32_t in_frame_len = 0; - if (in_frame_off > 0) - { + if (in_frame_off > 0) { if ((uint32_t)in_frame_off > f->payload_len) { tcp_dbg("FATAL TCP ERR: in_frame_off > f->payload_len\n"); } @@ -1224,12 +1209,10 @@ static void initconn_retry(pico_time when, void *arg) { struct pico_socket_tcp *t = (struct pico_socket_tcp *)arg; IGNORE_PARAMETER(when); - if (TCPSTATE(&t->sock) != PICO_SOCKET_STATE_TCP_ESTABLISHED) - { + if (TCPSTATE(&t->sock) != PICO_SOCKET_STATE_TCP_ESTABLISHED) { if (t->backoff > PICO_TCP_MAX_CONNECT_RETRIES) { tcp_dbg("TCP> Connection timeout. \n"); - if (t->sock.wakeup) - { + if (t->sock.wakeup) { pico_err = PICO_ERR_ECONNREFUSED; t->sock.wakeup(PICO_SOCK_EV_ERR, &t->sock); } @@ -1465,7 +1448,7 @@ static inline void tcp_fill_rst_payload(struct pico_frame *fr, struct pico_frame static inline void tcp_fill_rst_header(struct pico_frame *fr, struct pico_tcp_hdr *hdr1, struct pico_frame *f, struct pico_tcp_hdr *hdr) { - if(!(hdr1->flags & PICO_TCP_ACK)) + if (!(hdr1->flags & PICO_TCP_ACK)) hdr->flags |= PICO_TCP_ACK; hdr->rwnd = 0; @@ -1476,7 +1459,7 @@ static inline void tcp_fill_rst_header(struct pico_frame *fr, struct pico_tcp_hd } hdr->ack = 0; - if(!(hdr1->flags & PICO_TCP_ACK)) + if (!(hdr1->flags & PICO_TCP_ACK)) hdr->ack = long_be(long_be(((struct pico_tcp_hdr *)(fr->transport_hdr))->seq) + fr->payload_len); hdr->crc = short_be(pico_tcp_checksum(f)); @@ -1645,9 +1628,9 @@ static void tcp_sack_prepare(struct pico_socket_tcp *t) return; pkt = first_segment(&t->tcpq_in); - while(n < 3) { + while (n < 3) { if (!pkt) { - if(left) { + if (left) { sb = PICO_ZALLOC(sizeof(struct tcp_sack_block)); if (!sb) break; @@ -1676,7 +1659,7 @@ static void tcp_sack_prepare(struct pico_socket_tcp *t) continue; } - if(pkt->seq == right) { + if (pkt->seq == right) { right += pkt->payload_len; pkt = next_segment(&t->tcpq_in, pkt); continue; @@ -1709,8 +1692,7 @@ static inline int tcp_data_in_expected(struct pico_socket_tcp *t, struct pico_fr return -1; } - if(pico_enqueue_segment(&t->tcpq_in, input) <= 0) - { + if (pico_enqueue_segment(&t->tcpq_in, input) <= 0) { /* failed to enqueue, destroy segment */ PICO_FREE(input->payload); PICO_FREE(input); @@ -1718,7 +1700,7 @@ static inline int tcp_data_in_expected(struct pico_socket_tcp *t, struct pico_fr } else { t->rcv_nxt = SEQN(f) + f->payload_len; nxt = peek_segment(&t->tcpq_in, t->rcv_nxt); - while(nxt) { + while (nxt) { tcp_dbg("scrolling rcv_nxt...%08x\n", t->rcv_nxt); t->rcv_nxt += nxt->payload_len; nxt = peek_segment(&t->tcpq_in, t->rcv_nxt); @@ -1743,7 +1725,7 @@ static inline int tcp_data_in_high_segment(struct pico_socket_tcp *t, struct pic return -1; } - if(pico_enqueue_segment(&t->tcpq_in, input) <= 0) { + if (pico_enqueue_segment(&t->tcpq_in, input) <= 0) { /* failed to enqueue, destroy segment */ PICO_FREE(input->payload); PICO_FREE(input); @@ -1923,8 +1905,8 @@ static int tcp_is_allowed_to_send(struct pico_socket_tcp *t) { return t->sock.net && ( - ((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_ESTABLISHED) || - ((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT) + ((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_ESTABLISHED) || + ((t->sock.state & 0xFF00) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT) ) && ((t->backoff < PICO_TCP_MAX_RETRANS)); } @@ -1984,20 +1966,18 @@ static void tcp_retrans_timeout(pico_time val, void *sock) if (tcp_is_allowed_to_send(t)) { if (tcp_retrans_timeout_check_queue(t) < 0) return; - } - else if(t->backoff >= PICO_TCP_MAX_RETRANS && - ((t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_ESTABLISHED || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_FIN_WAIT1 || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_FIN_WAIT2 || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_TIME_WAIT || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_LAST_ACK || - (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSING)) - { + } else if (t->backoff >= PICO_TCP_MAX_RETRANS && + ((t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_ESTABLISHED || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_FIN_WAIT1 || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_FIN_WAIT2 || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_TIME_WAIT || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_LAST_ACK || + (t->sock.state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSING)) { tcp_dbg("Connection timeout!\n"); /* the retransmission timer, failed to get an ack for a frame, gives up on the connection */ tcp_discard_all_segments(&t->tcpq_out); - if(t->sock.wakeup) + if (t->sock.wakeup) t->sock.wakeup(PICO_SOCK_EV_FIN, &t->sock); /* delete socket */ @@ -2037,9 +2017,9 @@ static void add_retransmission_timer(struct pico_socket_tcp *t, pico_time next_t if (!t->retrans_tmr) { t->retrans_tmr = pico_timer_add(t->sock.stack, t->retrans_tmr_due - now, tcp_retrans_timeout, t); - if(!t->retrans_tmr) { + if (!t->retrans_tmr) { tcp_dbg("TCP: Failed to start retransmission timer\n"); - //TODO do something about this? + /*TODO do something about this? */ } else { tcp_dbg("Next timeout in %u msec\n", (uint32_t) (t->retrans_tmr_due - now)); } @@ -2066,7 +2046,7 @@ static int tcp_retrans(struct pico_socket_tcp *t, struct pico_frame *f) } add_retransmission_timer(t, TCP_TIME + t->rto); - return(f->payload_len); + return f->payload_len; } return 0; @@ -2163,8 +2143,7 @@ static int tcp_ack(struct pico_socket *s, struct pico_frame *f) t->x_mode = PICO_TCP_LOOKAHEAD; t->backoff = 0; - if((prev_mode == PICO_TCP_BLACKOUT) && (acked > 0) && una) - { + if ((prev_mode == PICO_TCP_BLACKOUT) && (acked > 0) && una) { t->snd_nxt = SEQN(una); /* restart the retrans timer */ if (t->retrans_tmr) { @@ -2184,11 +2163,11 @@ static int tcp_ack(struct pico_socket *s, struct pico_frame *f) /* Do rtt/rttvar/rto calculations */ /* First, try with timestamps, using the value from options */ - if(f->timestamp != 0) { + if (f->timestamp != 0) { rtt = time_diff(TCP_TIME, f->timestamp); if (rtt) tcp_rtt(t, rtt); - } else if(acked_timestamp) { + } else if (acked_timestamp) { /* If no timestamps are there, use conservative estimation on the una */ rtt = time_diff(TCP_TIME, acked_timestamp); if (rtt) @@ -2205,8 +2184,7 @@ static int tcp_ack(struct pico_socket *s, struct pico_frame *f) } else if ((t->snd_old_ack == ACKN(f)) && /* We've just seen this ack, and... */ ((0 == (hdr->flags & (PICO_TCP_PSH | PICO_TCP_SYN))) && (f->payload_len == 0)) && /* This is a pure ack, and... */ - (ACKN(f) != t->snd_nxt)) /* There is something in flight awaiting to be acked... */ - { + (ACKN(f) != t->snd_nxt)) { /* There is something in flight awaiting to be acked... */ /* Process incoming duplicate ack. */ if (t->x_mode < PICO_TCP_RECOVER) { t->x_mode++; @@ -2244,7 +2222,7 @@ static int tcp_ack(struct pico_socket *s, struct pico_frame *f) if (nxt && (pico_seq_compare(SEQN(nxt), SEQN((struct pico_frame *)first_segment(&t->tcpq_out))) > (int)(t->recv_wnd << t->recv_wnd_scale))) nxt = NULL; - if(!nxt) + if (!nxt) nxt = first_segment(&t->tcpq_out); if (nxt) { @@ -2269,8 +2247,7 @@ static int tcp_ack(struct pico_socket *s, struct pico_frame *f) /* Linux very special zero-window probe detection (see bug #107) */ if ((0 == (hdr->flags & (PICO_TCP_PSH | PICO_TCP_SYN))) && /* This is a pure ack, and... */ (ACKN(f) == t->snd_nxt) && /* it's acking our snd_nxt, and... */ - (pico_seq_compare(SEQN(f), t->rcv_nxt) < 0)) /* Has an old seq number */ - { + (pico_seq_compare(SEQN(f), t->rcv_nxt) < 0)) { /* Has an old seq number */ tcp_send_ack(t); } @@ -2428,7 +2405,7 @@ static int tcp_syn(struct pico_socket *s, struct pico_frame *f) struct pico_socket_tcp *new = NULL; struct pico_tcp_hdr *hdr = NULL; uint16_t mtu; - if(s->number_of_pending_conn >= s->max_backlog) + if (s->number_of_pending_conn >= s->max_backlog) return -1; new = (struct pico_socket_tcp *)pico_socket_clone(s); @@ -2575,7 +2552,7 @@ static int tcp_first_ack(struct pico_socket *s, struct pico_frame *f) s->state &= 0x00FFU; s->state |= PICO_SOCKET_STATE_TCP_ESTABLISHED; tcp_dbg("TCP: Established. State now: %04x\n", s->state); - if( !s->parent && s->wakeup) { /* If the socket has no parent, -> sending socket that has a sim_open */ + if (!s->parent && s->wakeup) { /* If the socket has no parent, -> sending socket that has a sim_open */ tcp_dbg("FIRST ACK - No parent found -> sending socket\n"); s->wakeup(PICO_SOCK_EV_CONN, s); } @@ -2648,8 +2625,7 @@ static int tcp_closewait(struct pico_socket *s, struct pico_frame *f) * */ if (((s->state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_CLOSE_WAIT) || - ((s->state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_ESTABLISHED)) - { + ((s->state & PICO_SOCKET_STATE_TCP) == PICO_SOCKET_STATE_TCP_ESTABLISHED)) { tcp_dbg("In closewait: Sending ack! (state is %08x)\n", s->state); tcp_send_ack(t); } @@ -2825,17 +2801,17 @@ static uint8_t invalid_flags(struct pico_socket *s, uint8_t flags) { /* PICO_SOCKET_STATE_TCP_CLOSING */ PICO_TCP_SYNACK, PICO_TCP_ACK, PICO_TCP_PSH, PICO_TCP_PSHACK, PICO_TCP_FIN, PICO_TCP_FINACK, PICO_TCP_FINPSHACK, PICO_TCP_RST}, { /* PICO_SOCKET_STATE_TCP_TIME_WAIT */ PICO_TCP_SYNACK, PICO_TCP_ACK, PICO_TCP_PSH, PICO_TCP_PSHACK, PICO_TCP_FIN, PICO_TCP_FINACK, PICO_TCP_FINPSHACK, PICO_TCP_RST}, }; - if(!flags) + if (!flags) return 1; - for(i = 0; i < MAX_VALID_FLAGS; i++) { - if(valid_flags[s->state >> 8u][i] == flags) + for (i = 0; i < MAX_VALID_FLAGS; i++) { + if (valid_flags[s->state >> 8u][i] == flags) return 0; } return 1; } -static void tcp_action_call(int (*call)(struct pico_socket *s, struct pico_frame *f), struct pico_socket *s, struct pico_frame *f ) +static void tcp_action_call(int (*call)(struct pico_socket *s, struct pico_frame *f), struct pico_socket *s, struct pico_frame *f) { if (call) call(s, f); @@ -2850,8 +2826,7 @@ static int tcp_action_by_flags(const struct tcp_action_entry *action, struct pic } if ((f->payload_len > 0 || (flags & PICO_TCP_PSH)) && - !(s->state & PICO_SOCKET_STATE_CLOSED) && !TCP_IS_STATE(s, PICO_SOCKET_STATE_TCP_LISTEN)) - { + !(s->state & PICO_SOCKET_STATE_CLOSED) && !TCP_IS_STATE(s, PICO_SOCKET_STATE_TCP_LISTEN)) { ret = f->payload_len; tcp_action_call(action->data, s, f); } @@ -2884,7 +2859,7 @@ int pico_tcp_input(struct pico_socket *s, struct pico_frame *f) tcp_dbg("[sam] TCP> [tcp input] t_len: %u\n", f->transport_len); tcp_dbg("[sam] TCP> flags = 0x%02x\n", hdr->flags); tcp_dbg("[sam] TCP> s->state >> 8 = %u\n", s->state >> 8); - tcp_dbg("[sam] TCP> [tcp input] socket: %p state: %d <-- local port:%u remote port: %u seq: 0x%08x ack: 0x%08x flags: 0x%02x t_len: %u, hdr: %u payload: %d\n", s, s->state >> 8, short_be(hdr->trans.dport), short_be(hdr->trans.sport), SEQN(f), ACKN(f), hdr->flags, f->transport_len, (hdr->len & 0xf0) >> 2, f->payload_len ); + tcp_dbg("[sam] TCP> [tcp input] socket: %p state: %d <-- local port:%u remote port: %u seq: 0x%08x ack: 0x%08x flags: 0x%02x t_len: %u, hdr: %u payload: %d\n", s, s->state >> 8, short_be(hdr->trans.dport), short_be(hdr->trans.sport), SEQN(f), ACKN(f), hdr->flags, f->transport_len, (hdr->len & 0xf0) >> 2, f->payload_len); if ((f->payload + f->payload_len) > (f->buffer + f->buffer_len)) { tcp_dbg("TCP> Invalid payload len %04x\n", f->payload_len); @@ -2897,10 +2872,9 @@ int pico_tcp_input(struct pico_socket *s, struct pico_frame *f) s->timestamp = TCP_TIME; /* Those are not supported at this time. */ /* flags &= (uint8_t) ~(PICO_TCP_CWR | PICO_TCP_URG | PICO_TCP_ECN); */ - if(invalid_flags(s, flags)) { + if (invalid_flags(s, flags)) { pico_tcp_reply_rst(s->stack, f); - } - else if (flags == PICO_TCP_SYN) { + } else if (flags == PICO_TCP_SYN) { tcp_action_call(action->syn, s, f); } else if (flags == (PICO_TCP_SYN | PICO_TCP_ACK)) { tcp_action_call(action->synack, s, f); @@ -2995,7 +2969,7 @@ int pico_tcp_output(struct pico_socket *s, int loop_score) una = first_segment(&t->tcpq_out); f = peek_segment(&t->tcpq_out, t->snd_nxt); - while((f) && (t->cwnd >= t->in_flight)) { + while ((f) && (t->cwnd >= t->in_flight)) { f->timestamp = TCP_TIME; add_retransmission_timer(t, t->rto + TCP_TIME); tcp_add_options_frame(t, f); @@ -3052,8 +3026,7 @@ int pico_tcp_output(struct pico_socket *s, int loop_score) } if ((t->tcpq_out.frames == 0) && (s->state & PICO_SOCKET_STATE_SHUT_LOCAL)) { /* if no more packets in queue, XXX replaced !f by tcpq check */ - if(!checkLocalClosing(&t->sock)) /* check if local closing started and send fin */ - { + if (!checkLocalClosing(&t->sock)) { /* check if local closing started and send fin */ checkRemoteClosing(&t->sock); /* check if remote closing started and send fin */ } } @@ -3071,12 +3044,11 @@ void pico_tcp_out_all(struct pico_stack *S, void *arg) pico_tcp_output(&t->sock, (int)t->tcpq_out.frames); if ((s->ev_pending) && s->wakeup) { s->wakeup(s->ev_pending, s); - if(!s->parent) + if (!s->parent) s->ev_pending = 0; } - if(pico_socket_sanity_check(s) < 0) - { + if (pico_socket_sanity_check(s) < 0) { pico_socket_del(s); } } @@ -3165,7 +3137,7 @@ static int pico_tcp_push_nagle_hold(struct pico_socket_tcp *t, struct pico_frame if ((total_len >= t->mss) && ((t->tcpq_out.max_size - t->tcpq_out.size) >= t->mss)) { /* IF enough data in hold (>mss) AND space in out queue (>mss) */ /* add current frame in hold and make new segment */ - if (pico_enqueue_segment(&t->tcpq_hold, f) > 0 ) { + if (pico_enqueue_segment(&t->tcpq_hold, f) > 0) { tcp_dbg_nagle("TCP_PUSH - NAGLE - Pushed into hold, make new (enqueued frames out %d)\n", t->tcpq_out.frames); t->snd_last += f->payload_len; /* XXX WATCH OUT */ f_new = pico_hold_segment_make(t); @@ -3251,17 +3223,15 @@ static void tcp_discard_all_segments(struct pico_tcp_queue *tq) pico_tree_foreach_safe(index, &tq->pool, index_safe) { void *f = index->keyValue; - if(!f) + if (!f) break; pico_tree_delete(&tq->pool, f); - if(IS_INPUT_QUEUE(tq)) - { + if (IS_INPUT_QUEUE(tq)) { struct tcp_input_segment *inp = (struct tcp_input_segment *)f; PICO_FREE(inp->payload); PICO_FREE(inp); - } - else + } else pico_frame_discard(f); } tq->frames = 0; @@ -3320,9 +3290,8 @@ static int checkRemoteClosing(struct pico_socket *s) void pico_tcp_notify_closing(struct pico_socket *sck) { struct pico_socket_tcp *t = (struct pico_socket_tcp *)sck; - if(t->tcpq_out.frames == 0) - { - if(!checkLocalClosing(sck)) + if (t->tcpq_out.frames == 0) { + if (!checkLocalClosing(sck)) checkRemoteClosing(sck); } } diff --git a/modules/pico_tcp.h b/modules/pico_tcp.h index 3f82eb0b..5d1e7ed7 100644 --- a/modules/pico_tcp.h +++ b/modules/pico_tcp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_tftp.c b/modules/pico_tftp.c index cecae325..1ca24458 100644 --- a/modules/pico_tftp.c +++ b/modules/pico_tftp.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -215,7 +215,6 @@ static struct pico_tftp_session *find_session_by_socket(struct pico_socket *tftp for (; pos; pos = pos->next) if (pos->socket == tftp_socket) return pos; - return NULL; } @@ -239,7 +238,6 @@ static void add_session(struct pico_stack *S, struct pico_tftp_session *idx) for (pos = S->tftp_sessions; pos; prev = pos, pos = pos->next) if (pos->localport > idx->localport) break; - if (prev) { idx->next = prev->next; prev->next = idx; @@ -1268,7 +1266,7 @@ int32_t pico_tftp_get(struct pico_tftp_session *session, uint8_t *data, int32_t { int synchro; - if (!session || len < session->len ) { + if (!session || len < session->len) { pico_err = PICO_ERR_EINVAL; return -1; } diff --git a/modules/pico_tftp.h b/modules/pico_tftp.h index b635590d..e060d0d3 100644 --- a/modules/pico_tftp.h +++ b/modules/pico_tftp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/modules/pico_udp.c b/modules/pico_udp.c index be44ac2e..81a897de 100644 --- a/modules/pico_udp.c +++ b/modules/pico_udp.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: @@ -197,7 +197,7 @@ uint16_t pico_udp_recv(struct pico_socket *s, void *buf, uint16_t len, void *src { struct pico_frame *f = pico_queue_peek(&s->q_in); if (f) { - if(!f->payload_len) { + if (!f->payload_len) { f->payload = f->transport_hdr + sizeof(struct pico_udp_hdr); f->payload_len = (uint16_t)(f->transport_len - sizeof(struct pico_udp_hdr)); } diff --git a/modules/pico_udp.h b/modules/pico_udp.h index 61cc659d..51065ce6 100644 --- a/modules/pico_udp.h +++ b/modules/pico_udp.h @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/stack/pico_device.c b/stack/pico_device.c index ca0c69c2..1e8333a0 100644 --- a/stack/pico_device.c +++ b/stack/pico_device.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -68,8 +68,8 @@ static struct pico_ipv6_link * pico_6lowpan_link_add(struct pico_device *dev, co newaddr.addr[8] = newaddr.addr[8] ^ 0x02; /* Toggle U/L bit */ /* RFC6775: No Duplicate Address Detection (DAD) is performed if - * EUI-64-based IPv6 addresses are used (as these addresses are assumed - * to be globally unique). */ + * EUI-64-based IPv6 addresses are used (as these addresses are assumed + * to be globally unique). */ if ((link = pico_ipv6_link_add_no_dad(dev, newaddr, netmask64))) { if (pico_ipv6_is_linklocal(newaddr.addr)) pico_6lp_nd_start_soliciting(link, NULL); @@ -225,7 +225,7 @@ int MOCKABLE pico_device_init(struct pico_stack *S, struct pico_device *dev, con uint32_t len = (uint32_t)strlen(name); int ret = 0; - if(len > MAX_DEVICE_NAME) + if (len > MAX_DEVICE_NAME) len = MAX_DEVICE_NAME; memcpy(dev->name, name, len); @@ -249,10 +249,10 @@ int MOCKABLE pico_device_init(struct pico_stack *S, struct pico_device *dev, con pico_queue_register_listener(dev->stack, dev->q_out, devloop_all_out, dev); if (pico_tree_insert(&S->Device_tree, dev)) { - PICO_FREE(dev->q_in); - PICO_FREE(dev->q_out); - return -1; - } + PICO_FREE(dev->q_in); + PICO_FREE(dev->q_out); + return -1; + } if (!dev->mtu) dev->mtu = PICO_DEVICE_DEFAULT_MTU; @@ -302,7 +302,7 @@ void MOCKABLE pico_device_destroy(struct pico_device *dev) pico_ipv6_cleanup_links(dev->stack, dev); #endif pico_tree_delete(&dev->stack->Device_tree, dev); - + dev->stack->Devices_rr_info.node_in = NULL; dev->stack->Devices_rr_info.node_out = NULL; @@ -334,7 +334,7 @@ static int check_dev_serve_polling(struct pico_device *dev, int loop_score) static int devloop_in(struct pico_device *dev, int loop_score) { struct pico_frame *f; - while(loop_score > 0) { + while (loop_score > 0) { if (dev->q_in->frames == 0) break; @@ -361,7 +361,7 @@ static int devloop_sendto_dev(struct pico_device *dev, struct pico_frame *f) static int devloop_out(struct pico_device *dev, int loop_score) { struct pico_frame *f; - while(loop_score > 0) { + while (loop_score > 0) { if (dev->q_out->frames == 0) break; @@ -374,10 +374,9 @@ static int devloop_out(struct pico_device *dev, int loop_score) f = pico_dequeue(dev->q_out); pico_frame_discard(f); /* SINGLE POINT OF DISCARD for OUTGOING FRAMES */ loop_score--; - } else + } else break; /* Don't discard */ } - return loop_score; } @@ -388,7 +387,7 @@ static void devloop_all_out(struct pico_stack *S, void *arg) struct pico_device *dev = (struct pico_device *)arg; struct pico_frame *f; (void)S; - while(1) { + while (1) { if (dev->q_out->frames <= 0) break; @@ -412,7 +411,7 @@ static void devloop_all_in(struct pico_stack *S, void *arg) struct pico_device *dev = (struct pico_device *)arg; struct pico_frame *f; (void)S; - while(1) { + while (1) { if (dev->q_in->frames <= 0) break; @@ -489,8 +488,7 @@ int pico_devices_loop(struct pico_stack *S, int loop_score, int direction) loop_score = devloop(next, loop_score, direction); next_node = pico_tree_next(next_node); next = next_node->keyValue; - if (next == NULL) - { + if (next == NULL) { next_node = pico_tree_firstNode(S->Device_tree.root); next = next_node->keyValue; } @@ -508,7 +506,7 @@ struct pico_device *pico_get_device(struct pico_stack *S, const char*name) struct pico_tree_node *index; pico_tree_foreach(index, &S->Device_tree){ dev = index->keyValue; - if(strcmp(name, dev->name) == 0) + if (strcmp(name, dev->name) == 0) return dev; } return NULL; @@ -522,19 +520,16 @@ int32_t pico_device_broadcast(struct pico_stack *S, struct pico_frame *f) pico_tree_foreach(index, &S->Device_tree) { struct pico_device *dev = index->keyValue; - if(dev != f->dev) - { + if (dev != f->dev) { struct pico_frame *copy = pico_frame_copy(f); - if(!copy) + if (!copy) break; copy->dev = dev; copy->dev->send(copy->dev, copy->start, (int)copy->len); pico_frame_discard(copy); - } - else - { + } else { ret = f->dev->send(f->dev, f->start, (int)f->len); } } diff --git a/stack/pico_frame.c b/stack/pico_frame.c index a845c833..03bf9db8 100644 --- a/stack/pico_frame.c +++ b/stack/pico_frame.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/stack/pico_jobs.c b/stack/pico_jobs.c index dad8af94..589861dd 100644 --- a/stack/pico_jobs.c +++ b/stack/pico_jobs.c @@ -1,5 +1,5 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only @@ -39,14 +39,14 @@ struct pico_job void pico_schedule_job(struct pico_stack *S, void (*exe)(struct pico_stack *, void*), void *arg) { struct pico_job *job = PICO_ZALLOC(sizeof(struct pico_job)); - if (!job) + if (!job) return; job->exe = exe; job->arg = arg; job->stack = S; if (!S->pico_jobs_backlog) { - S->pico_jobs_backlog = job; - S->pico_jobs_backlog_tail = job; + S->pico_jobs_backlog = job; + S->pico_jobs_backlog_tail = job; } else { S->pico_jobs_backlog_tail->next = job; S->pico_jobs_backlog_tail = job; @@ -57,7 +57,7 @@ void pico_execute_pending_jobs(struct pico_stack *S) { struct pico_job *job; /* int count = 0; */ - while(S->pico_jobs_backlog) { + while (S->pico_jobs_backlog) { job = S->pico_jobs_backlog; if (job->exe) { job->exe(job->stack, job->arg); @@ -69,11 +69,11 @@ void pico_execute_pending_jobs(struct pico_stack *S) S->pico_jobs_backlog_tail = NULL; } /* - if (count > max_jobs) { + if (count > max_jobs) { printf("Max jobs = %d\n", count); max_jobs = count; - } - */ + } + */ } #else void pico_schedule_job(struct pico_stack *S, void (*exe)(struct pico_stack *, void*), void *arg) diff --git a/stack/pico_md5.c b/stack/pico_md5.c index a4b4cfbd..8b98f56f 100644 --- a/stack/pico_md5.c +++ b/stack/pico_md5.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify diff --git a/stack/pico_protocol.c b/stack/pico_protocol.c index 814848b7..0b63d23a 100644 --- a/stack/pico_protocol.c +++ b/stack/pico_protocol.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -45,7 +45,7 @@ static int pico_proto_cmp(void *ka, void *kb) static int proto_loop_in(struct pico_stack *S, struct pico_protocol *proto, int loop_score) { struct pico_frame *f; - while(loop_score > 0) { + while (loop_score > 0) { if (proto->q_in->frames == 0) break; @@ -60,7 +60,7 @@ static int proto_loop_in(struct pico_stack *S, struct pico_protocol *proto, int static int proto_loop_out(struct pico_stack *S, struct pico_protocol *proto, int loop_score) { struct pico_frame *f; - while(loop_score > 0) { + while (loop_score > 0) { if (proto->q_out->frames == 0) break; @@ -77,7 +77,7 @@ void proto_full_loop_in(struct pico_stack *S, void *arg) { struct pico_protocol *proto = (struct pico_protocol *)arg; struct pico_frame *f; - while(1) { + while (1) { if (proto->q_in->frames <= 0) break; @@ -90,7 +90,7 @@ void proto_full_loop_out(struct pico_stack *S, void *arg) { struct pico_protocol *proto = (struct pico_protocol *)arg; struct pico_frame *f; - while(1) { + while (1) { if (proto->q_out->frames <= 0) break; @@ -157,8 +157,7 @@ static int pico_protocol_generic_loop(struct pico_stack *S, struct pico_proto_rr loop_score = proto_loop(S, next, loop_score, direction); next_node = pico_tree_next(next_node); next = next_node->keyValue; - if (next == NULL) - { + if (next == NULL) { next_node = pico_tree_firstNode(rr->t->root); next = next_node->keyValue; } @@ -234,25 +233,25 @@ void pico_protocol_init(struct pico_stack *S, struct pico_protocol *p) p->hash = pico_hash(p->name, (uint32_t)strlen(p->name)); switch (p->layer) { - case PICO_LAYER_DATALINK: - tree = &S->sched->Datalink_proto_tree; - proto = &S->sched->rr_datalink; - break; - case PICO_LAYER_NETWORK: - tree = &S->sched->Network_proto_tree; - proto = &S->sched->rr_network; - break; - case PICO_LAYER_TRANSPORT: - tree = &S->sched->Transport_proto_tree; - proto = &S->sched->rr_transport; - break; - case PICO_LAYER_SOCKET: - tree = &S->sched->Socket_proto_tree; - proto = &S->sched->rr_socket; - break; - default: - dbg("Unknown protocol: %s (layer: %d)\n", p->name, p->layer); - return; + case PICO_LAYER_DATALINK: + tree = &S->sched->Datalink_proto_tree; + proto = &S->sched->rr_datalink; + break; + case PICO_LAYER_NETWORK: + tree = &S->sched->Network_proto_tree; + proto = &S->sched->rr_network; + break; + case PICO_LAYER_TRANSPORT: + tree = &S->sched->Transport_proto_tree; + proto = &S->sched->rr_transport; + break; + case PICO_LAYER_SOCKET: + tree = &S->sched->Socket_proto_tree; + proto = &S->sched->rr_socket; + break; + default: + dbg("Unknown protocol: %s (layer: %d)\n", p->name, p->layer); + return; } dbg("Protocol %s registered (layer: %d).\n", p->name, p->layer); diff --git a/stack/pico_socket.c b/stack/pico_socket.c index 5f5fea1f..f97b66bc 100644 --- a/stack/pico_socket.c +++ b/stack/pico_socket.c @@ -314,8 +314,7 @@ static int pico_port_in_use_ipv6(struct pico_sockport *sp, void *addr) static int pico_generic_port_in_use(uint16_t proto, uint16_t port, struct pico_sockport *sp, void *addr, void *net) { #ifdef PICO_SUPPORT_IPV4 - if (net == &pico_proto_ipv4) - { + if (net == &pico_proto_ipv4) { if (sp && pico_port_in_use_by_nat(sp->stack, proto, port)) { return 1; } @@ -328,8 +327,7 @@ static int pico_generic_port_in_use(uint16_t proto, uint16_t port, struct pico_s #endif #ifdef PICO_SUPPORT_IPV6 - if (net == &pico_proto_ipv6) - { + if (net == &pico_proto_ipv6) { if (sp && pico_port_in_use_ipv6(sp, addr)) { return 1; } @@ -380,12 +378,10 @@ struct pico_socket *pico_sockets_find(struct pico_stack *S, uint16_t local, uint struct pico_sockport *sp = NULL; sp = pico_get_sockport(S, PICO_PROTO_TCP, local); - if(sp) - { + if (sp) { pico_tree_foreach(index, &sp->socks) { - if(((struct pico_socket *)index->keyValue)->remote_port == remote) - { + if (((struct pico_socket *)index->keyValue)->remote_port == remote) { sock = (struct pico_socket *)index->keyValue; break; } @@ -416,33 +412,31 @@ int8_t pico_socket_add(struct pico_socket *s) sp->socks.compare = socket_cmp; #ifdef PICO_SUPPORT_UDP - if (PROTO(s) == PICO_PROTO_UDP) - { + if (PROTO(s) == PICO_PROTO_UDP) { if (pico_tree_insert(&s->stack->UDPTable, sp)) { - PICO_FREE(sp); - PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); - return -1; - } + PICO_FREE(sp); + PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); + return -1; + } } #endif #ifdef PICO_SUPPORT_TCP - if (PROTO(s) == PICO_PROTO_TCP) - { + if (PROTO(s) == PICO_PROTO_TCP) { if (pico_tree_insert(&s->stack->TCPTable, sp)) { - PICO_FREE(sp); - PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); - return -1; - } + PICO_FREE(sp); + PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); + return -1; + } } #endif } if (pico_tree_insert(&sp->socks, s)) { - PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); - return -1; - } + PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); + return -1; + } s->state |= PICO_SOCKET_STATE_BOUND; PICOTCP_MUTEX_UNLOCK(s->stack->SockMutex); #ifdef DEBUG_SOCKET_TREE @@ -463,16 +457,13 @@ static void socket_clean_queues(struct pico_socket *sock) { struct pico_frame *f_in = pico_dequeue(&sock->q_in); struct pico_frame *f_out = pico_dequeue(&sock->q_out); - while(f_in || f_out) - { - if(f_in) - { + while (f_in || f_out) { + if (f_in) { pico_frame_discard(f_in); f_in = pico_dequeue(&sock->q_in); } - if(f_out) - { + if (f_out) { pico_frame_discard(f_out); f_out = pico_dequeue(&sock->q_out); } @@ -494,24 +485,22 @@ static void socket_garbage_collect(pico_time now, void *arg) static void pico_socket_check_empty_sockport(struct pico_socket *s, struct pico_sockport *sp) { - if(pico_tree_empty(&sp->socks)) { + if (pico_tree_empty(&sp->socks)) { #ifdef PICO_SUPPORT_UDP - if (PROTO(s) == PICO_PROTO_UDP) - { + if (PROTO(s) == PICO_PROTO_UDP) { pico_tree_delete(&s->stack->UDPTable, sp); } #endif #ifdef PICO_SUPPORT_TCP - if (PROTO(s) == PICO_PROTO_TCP) - { + if (PROTO(s) == PICO_PROTO_TCP) { pico_tree_delete(&s->stack->TCPTable, sp); } #endif - if(s->stack->sp_tcp == sp) + if (s->stack->sp_tcp == sp) s->stack->sp_tcp = NULL; - if(s->stack->sp_udp == sp) + if (s->stack->sp_udp == sp) s->stack->sp_udp = NULL; PICO_FREE(sp); @@ -752,17 +741,15 @@ struct pico_socket *pico_socket_clone(struct pico_socket *facsimile) static int pico_socket_transport_read(struct pico_socket *s, void *buf, int len) { - if (PROTO(s) == PICO_PROTO_UDP) - { + if (PROTO(s) == PICO_PROTO_UDP) { /* make sure cast to uint16_t doesn't give unexpected results */ - if(len > 0xFFFF) { + if (len > 0xFFFF) { pico_err = PICO_ERR_EINVAL; return -1; } return pico_socket_udp_recv(s, buf, (uint16_t)len, NULL, NULL); - } - else if (PROTO(s) == PICO_PROTO_TCP) + } else if (PROTO(s) == PICO_PROTO_TCP) return pico_socket_tcp_read(s, buf, (uint32_t)len); #ifdef PICO_SUPPORT_RAWSOCKETS else if (PROTO(s) == PICO_PROTO_IPV4) @@ -857,9 +844,8 @@ static uint16_t pico_socket_high_port(struct pico_stack *S, uint16_t proto) if (pico_is_port_free(S, proto, port, NULL, NULL)) { return short_be(port); } - } while(1); - } - else return 0U; + } while (1); + } else return 0U; } static void *pico_socket_sendto_get_ip4_src(struct pico_socket *s, struct pico_ip4 *dst) @@ -872,7 +858,7 @@ static void *pico_socket_sendto_get_ip4_src(struct pico_socket *s, struct pico_i */ if ((s->state & PICO_SOCKET_STATE_CONNECTED)) { src4 = &s->local_addr.ip4; - if (s->remote_addr.ip4.addr != ((struct pico_ip4 *)dst)->addr ) { + if (s->remote_addr.ip4.addr != ((struct pico_ip4 *)dst)->addr) { pico_err = PICO_ERR_EADDRNOTAVAIL; return NULL; } @@ -1234,7 +1220,7 @@ static int pico_socket_xmit_fragments(struct pico_socket *s, const void *buf, co #endif #ifdef PICO_SUPPORT_IPV4FRAG - while(total_payload_written < len) { + while (total_payload_written < len) { /* Always allocate the max space available: space + offset */ if (len < space) space = len; @@ -1335,17 +1321,17 @@ static uint32_t pico_socket_pmtu_check(struct pico_socket *s, uint32_t mss) #if defined(PICO_SUPPORT_IPV6) && defined(PICO_SUPPORT_IPV6PMTU) if (is_sock_ipv6(s)) { - uint32_t pmtu = 0; - const struct pico_ipv6_path_id destination = {s->remote_addr.ip6}; - pmtu = pico_ipv6_pmtu_get(s->stack, &destination); - if (pmtu == 0) { - pico_ipv6_path_add(s->stack, &destination, mss); - } else { - if (pmtu < mss) { - mss = pmtu; - } - } - } + uint32_t pmtu = 0; + const struct pico_ipv6_path_id destination = {s->remote_addr.ip6}; + pmtu = pico_ipv6_pmtu_get(s->stack, &destination); + if (pmtu == 0) { + pico_ipv6_path_add(s->stack, &destination, mss); + } else { + if (pmtu < mss) { + mss = pmtu; + } + } + } #else IGNORE_PARAMETER(s); #endif @@ -1362,7 +1348,7 @@ uint32_t pico_socket_get_mss(struct pico_socket *s) get_sock_dev(s); } if (s->dev) { - mss = pico_socket_pmtu_check(s, s->dev->mtu); + mss = pico_socket_pmtu_check(s, s->dev->mtu); } return pico_socket_adapt_mss_to_proto(s, mss); } @@ -1440,7 +1426,7 @@ int MOCKABLE pico_socket_sendto_extended(struct pico_socket *s, const void *buf, return -1; } - if(len == 0) + if (len == 0) return 0; #ifdef PICO_SUPPORT_PACKET_SOCKETS @@ -1461,13 +1447,11 @@ int MOCKABLE pico_socket_sendto_extended(struct pico_socket *s, const void *buf, src = pico_socket_sendto_get_src(s, dst); if (!src) { #ifdef PICO_SUPPORT_IPV6 - if((s->net->proto_number == PICO_PROTO_IPV6) - && msginfo && msginfo->dev - && pico_ipv6_is_multicast(((struct pico_ip6 *)dst)->addr)) - { + if ((s->net->proto_number == PICO_PROTO_IPV6) + && msginfo && msginfo->dev + && pico_ipv6_is_multicast(((struct pico_ip6 *)dst)->addr)) { src = &(pico_ipv6_linklocal_get(msginfo->dev)->address); - } - else + } else #endif return -1; } @@ -1536,7 +1520,7 @@ int pico_socket_recvfrom_extended(struct pico_socket *s, void *buf, int len, voi #ifdef PICO_SUPPORT_ICMP4 /* forward request to icmp layer */ if (PROTO(s) == PICO_PROTO_ICMP4) { - if(len > 0xFFFF) { + if (len > 0xFFFF) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -1559,7 +1543,7 @@ int pico_socket_recvfrom_extended(struct pico_socket *s, void *buf, int len, voi #ifdef PICO_SUPPORT_UDP if (PROTO(s) == PICO_PROTO_UDP) { /* make sure cast to uint16_t doesn't give unexpected results */ - if(len > 0xFFFF) { + if (len > 0xFFFF) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -1614,12 +1598,11 @@ int pico_socket_fionread(struct pico_socket *s) pico_err = PICO_ERR_EIO; return -1; } - if (PROTO(s) == PICO_PROTO_UDP) - { + if (PROTO(s) == PICO_PROTO_UDP) { f = pico_queue_peek(&s->q_in); if (!f) return 0; - if(!f->payload_len) { + if (!f->payload_len) { f->payload = f->transport_hdr + sizeof(struct pico_udp_hdr); f->payload_len = (f->transport_len > sizeof(struct pico_udp_hdr)) ? @@ -1634,7 +1617,7 @@ int pico_socket_fionread(struct pico_socket *s) f = pico_queue_peek(&s->q_in); if (!f) return 0; - if(!f->payload_len) { + if (!f->payload_len) { f->payload = f->net_hdr + f->net_len; f->payload_len = (uint16_t)(f->len); if (!s4->hdr_included) @@ -1821,8 +1804,7 @@ int pico_socket_connect(struct pico_socket *s, const void *remote_addr, uint16_t return -1; } - if (PROTO(s) == PICO_PROTO_IPV4) - { + if (PROTO(s) == PICO_PROTO_IPV4) { pico_err = PICO_ERR_EOPNOTSUPP; return -1; } @@ -2073,8 +2055,7 @@ int pico_socket_shutdown(struct pico_socket *s, int mode) } /* unbound sockets can be deleted immediately */ - if (!(s->state & PICO_SOCKET_STATE_BOUND)) - { + if (!(s->state & PICO_SOCKET_STATE_BOUND)) { socket_garbage_collect((pico_time)10, s); return 0; } @@ -2090,12 +2071,10 @@ int pico_socket_shutdown(struct pico_socket *s, int mode) #endif #ifdef PICO_SUPPORT_TCP if (PROTO(s) == PICO_PROTO_TCP) { - if ((mode & PICO_SHUT_RDWR) == PICO_SHUT_RDWR) - { + if ((mode & PICO_SHUT_RDWR) == PICO_SHUT_RDWR) { pico_socket_alter_state(s, PICO_SOCKET_STATE_SHUT_LOCAL | PICO_SOCKET_STATE_SHUT_REMOTE, 0, 0); pico_tcp_notify_closing(s); - } - else if (mode & PICO_SHUT_WR) { + } else if (mode & PICO_SHUT_WR) { pico_socket_alter_state(s, PICO_SOCKET_STATE_SHUT_LOCAL, 0, 0); pico_tcp_notify_closing(s); } else if (mode & PICO_SHUT_RD) @@ -2195,8 +2174,7 @@ static inline int pico_transport_crc_check(struct pico_frame *f) struct pico_udp_hdr *udp_hdr = NULL; uint16_t checksum_invalid = 1; - switch (net_hdr->proto) - { + switch (net_hdr->proto) { #ifdef PICO_SUPPORT_TCP case PICO_PROTO_TCP: checksum_invalid = short_be(pico_tcp_checksum(f)); @@ -2286,8 +2264,8 @@ int pico_socket_sanity_check(struct pico_socket *s) { /* checking for pending connections */ - if(TCP_STATE(s) == PICO_SOCKET_STATE_TCP_SYN_RECV) { - if((PICO_TIME_MS() - s->timestamp) >= PICO_SOCKET_BOUND_TIMEOUT) + if (TCP_STATE(s) == PICO_SOCKET_STATE_TCP_SYN_RECV) { + if ((PICO_TIME_MS() - s->timestamp) >= PICO_SOCKET_BOUND_TIMEOUT) return -1; } @@ -2304,8 +2282,7 @@ static int pico_sockets_loop_udp(struct pico_stack *S, int loop_score) struct pico_socket *s; struct pico_frame *f; - if (S->sp_udp == NULL) - { + if (S->sp_udp == NULL) { S->udp_loop_index = pico_tree_firstNode(S->UDPTable.root); S->sp_udp = S->udp_loop_index->keyValue; } @@ -2331,8 +2308,7 @@ static int pico_sockets_loop_udp(struct pico_stack *S, int loop_score) S->udp_loop_index = pico_tree_next(S->udp_loop_index); S->sp_udp = S->udp_loop_index->keyValue; - if (S->sp_udp == NULL) - { + if (S->sp_udp == NULL) { S->udp_loop_index = pico_tree_firstNode(S->UDPTable.root); S->sp_udp = S->udp_loop_index->keyValue; } @@ -2349,8 +2325,7 @@ static int pico_sockets_loop_tcp(struct pico_stack *S, int loop_score) #ifdef PICO_SUPPORT_TCP struct pico_sockport *start; struct pico_socket *s; - if (S->sp_tcp == NULL) - { + if (S->sp_tcp == NULL) { S->tcp_loop_index = pico_tree_firstNode(S->TCPTable.root); S->sp_tcp = S->tcp_loop_index->keyValue; } @@ -2365,7 +2340,7 @@ static int pico_sockets_loop_tcp(struct pico_stack *S, int loop_score) loop_score = pico_tcp_output(s, loop_score); if ((s->ev_pending) && s->wakeup) { s->wakeup(s->ev_pending, s); - if(!s->parent) + if (!s->parent) s->ev_pending = 0; } @@ -2374,8 +2349,7 @@ static int pico_sockets_loop_tcp(struct pico_stack *S, int loop_score) break; } - if(pico_socket_sanity_check(s) < 0) - { + if (pico_socket_sanity_check(s) < 0) { pico_socket_del(s); S->tcp_loop_index = NULL; /* forcing the restart of loop */ S->sp_tcp = NULL; @@ -2390,8 +2364,7 @@ static int pico_sockets_loop_tcp(struct pico_stack *S, int loop_score) S->tcp_loop_index = pico_tree_next(S->tcp_loop_index); S->sp_tcp = S->tcp_loop_index->keyValue; - if (S->sp_tcp == NULL) - { + if (S->sp_tcp == NULL) { S->tcp_loop_index = pico_tree_firstNode(S->TCPTable.root); S->sp_tcp = S->tcp_loop_index->keyValue; } @@ -2475,7 +2448,7 @@ struct pico_frame *pico_socket_frame_alloc(struct pico_socket *s, struct pico_de static void pico_transport_error_set_picoerr(int code) { /* dbg("SOCKET ERROR FROM ICMP NOTIFICATION. (icmp code= %d)\n\n", code); */ - switch(code) { + switch (code) { case PICO_ICMP_UNREACH_NET: pico_err = PICO_ERR_ENETUNREACH; break; diff --git a/stack/pico_socket_multicast.c b/stack/pico_socket_multicast.c index 8ad84f2a..7eeb0398 100644 --- a/stack/pico_socket_multicast.c +++ b/stack/pico_socket_multicast.c @@ -1,11 +1,11 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -102,7 +102,7 @@ static int mcast_listen_grp_cmp(struct pico_mcast_listen *a, struct pico_mcast_l static int mcast_listen_grp_cmp_ipv6(struct pico_mcast_listen *a, struct pico_mcast_listen *b) { int tmp = memcmp(&a->mcast_group.ip6, &b->mcast_group.ip6, sizeof(struct pico_ip6)); - if(!tmp) + if (!tmp) return mcast_listen_link_cmp(a, b); return tmp; @@ -184,13 +184,13 @@ int mcast_filter_cmp_ipv6(void *ka, void *kb) inline static struct pico_tree *mcast_get_src_tree(struct pico_socket *s, struct pico_mcast *mcast) { - if( IS_SOCK_IPV4(s)) { + if (IS_SOCK_IPV4(s)) { mcast->listen->MCASTSources.compare = mcast_sources_cmp; return &mcast->listen->MCASTSources; } #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) { + else if (IS_SOCK_IPV6(s)) { mcast->listen->MCASTSources_ipv6.compare = mcast_sources_cmp_ipv6; return &mcast->listen->MCASTSources_ipv6; } @@ -199,22 +199,22 @@ inline static struct pico_tree *mcast_get_src_tree(struct pico_socket *s, struct } inline static struct pico_tree *mcast_get_listen_tree(struct pico_socket *s) { - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return s->MCASTListen; #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) return s->MCASTListen_ipv6; #endif return NULL; } inline static void mcast_set_listen_tree_p_null(struct pico_socket *s) { - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) s->MCASTListen = NULL; #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) s->MCASTListen_ipv6 = NULL; #endif } @@ -226,11 +226,11 @@ static struct pico_mcast_listen *listen_find(struct pico_socket *s, union pico_a ltest.mcast_link = *lnk; ltest.mcast_group = *grp; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_tree_findKey(s->MCASTListen, <est); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { + else if (IS_SOCK_IPV6(s)) { ltest.proto = PICO_PROTO_IPV6; return pico_tree_findKey(s->MCASTListen_ipv6, <est); } @@ -239,11 +239,11 @@ static struct pico_mcast_listen *listen_find(struct pico_socket *s, union pico_a } static union pico_address *pico_mcast_get_link_address(struct pico_socket *s, union pico_link *mcast_link) { - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return (union pico_address *) &mcast_link->ipv4.address; #ifdef PICO_SUPPORT_IPV6 - if( IS_SOCK_IPV6(s)) + if (IS_SOCK_IPV6(s)) return (union pico_address *) &mcast_link->ipv6.address; #endif @@ -256,7 +256,7 @@ static int8_t pico_mcast_filter_excl_excl(struct pico_mcast_listen *listen) /* remove from the interface EXCLUDE filter any source not in the socket EXCLUDE filter */ struct pico_tree_node *index = NULL, *_tmp = NULL; union pico_address *source = NULL; - if(!pico_tree_empty(&listen->stack->MCASTFilter)) { + if (!pico_tree_empty(&listen->stack->MCASTFilter)) { pico_tree_foreach_safe(index, &listen->stack->MCASTFilter, _tmp) { source = pico_tree_findKey(&listen->MCASTSources, index->keyValue); @@ -266,7 +266,7 @@ static int8_t pico_mcast_filter_excl_excl(struct pico_mcast_listen *listen) } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->stack->MCASTFilter_ipv6)) { + if (!pico_tree_empty(&listen->stack->MCASTFilter_ipv6)) { pico_tree_foreach_safe(index, &listen->stack->MCASTFilter_ipv6, _tmp) { source = pico_tree_findKey(&listen->MCASTSources_ipv6, index->keyValue); @@ -286,7 +286,7 @@ static int8_t pico_mcast_filter_excl_incl(struct pico_mcast_listen *listen) /* remove from the interface EXCLUDE filter any source in the socket INCLUDE filter */ struct pico_tree_node *index = NULL, *_tmp = NULL; union pico_address *source = NULL; - if(!pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach_safe(index, &listen->MCASTSources, _tmp) { source = pico_tree_findKey(&listen->stack->MCASTFilter, index->keyValue); @@ -296,7 +296,7 @@ static int8_t pico_mcast_filter_excl_incl(struct pico_mcast_listen *listen) } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach_safe(index, &listen->MCASTSources_ipv6, _tmp) { source = pico_tree_findKey(&listen->stack->MCASTFilter_ipv6, index->keyValue); @@ -315,7 +315,7 @@ static int8_t pico_mcast_filter_incl_excl(struct pico_mcast_listen *listen) /* delete from the interface INCLUDE filter any source NOT in the socket EXCLUDE filter */ struct pico_tree_node *index = NULL, *_tmp = NULL; union pico_address *source = NULL; - if(!pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach_safe(index, &listen->stack->MCASTFilter, _tmp) { source = pico_tree_findKey(&listen->MCASTSources, index->keyValue); @@ -325,7 +325,7 @@ static int8_t pico_mcast_filter_incl_excl(struct pico_mcast_listen *listen) } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach_safe(index, &listen->stack->MCASTFilter_ipv6, _tmp) { source = pico_tree_findKey(&listen->MCASTSources_ipv6, index->keyValue); @@ -338,7 +338,7 @@ static int8_t pico_mcast_filter_incl_excl(struct pico_mcast_listen *listen) /* any record with filter mode EXCLUDE, causes the interface mode to be EXCLUDE */ /* add to the interface EXCLUDE filter any socket source NOT in the former interface INCLUDE filter */ - if(!pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach_safe(index, &listen->MCASTSources, _tmp) { source = pico_tree_insert(&listen->stack->MCASTFilter, index->keyValue); @@ -352,7 +352,7 @@ static int8_t pico_mcast_filter_incl_excl(struct pico_mcast_listen *listen) } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach_safe(index, &listen->MCASTSources_ipv6, _tmp) { source = pico_tree_insert(&listen->stack->MCASTFilter_ipv6, index->keyValue); @@ -376,7 +376,7 @@ static int8_t pico_mcast_filter_incl_incl(struct pico_mcast_listen *listen) struct pico_tree_node *index = NULL, *_tmp = NULL; union pico_address *source = NULL; - if( !pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach_safe(index, &listen->MCASTSources, _tmp) { source = index->keyValue; @@ -386,7 +386,7 @@ static int8_t pico_mcast_filter_incl_incl(struct pico_mcast_listen *listen) } #ifdef PICO_SUPPORT_IPV6 - if( !pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach_safe(index, &listen->MCASTSources_ipv6, _tmp) { source = index->keyValue; @@ -404,8 +404,7 @@ struct pico_mcast_filter_aggregation int8_t (*call)(struct pico_mcast_listen *); }; -static const struct pico_mcast_filter_aggregation mcast_filter_aggr_call[2][2] = -{ +static const struct pico_mcast_filter_aggregation mcast_filter_aggr_call[2][2] = { { /* EXCL + EXCL */ {.call = pico_mcast_filter_excl_excl}, /* EXCL + INCL */ {.call = pico_mcast_filter_excl_incl} @@ -441,7 +440,7 @@ static int pico_socket_aggregate_mcastfilters(struct pico_stack *S, union pico_a struct pico_tree_node *index = NULL, *_tmp = NULL; /* cleanup old filter */ - if(!pico_tree_empty(&S->MCASTFilter)) { + if (!pico_tree_empty(&S->MCASTFilter)) { pico_tree_foreach_safe(index, &S->MCASTFilter, _tmp) { pico_tree_delete(&S->MCASTFilter, index->keyValue); @@ -449,7 +448,7 @@ static int pico_socket_aggregate_mcastfilters(struct pico_stack *S, union pico_a } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&S->MCASTFilter_ipv6)) { + if (!pico_tree_empty(&S->MCASTFilter_ipv6)) { pico_tree_foreach_safe(index, &S->MCASTFilter_ipv6, _tmp) { pico_tree_delete(&S->MCASTFilter_ipv6, index->keyValue); @@ -484,7 +483,7 @@ static int pico_socket_mcast_filter_include(struct pico_mcast_listen *listen, un #ifdef PICO_DEBUG_MCAST char tmp_string[PICO_IPV6_STRING]; #endif - if(!pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach(index, &listen->MCASTSources) { if (src->ip4.addr == ((union pico_address *)index->keyValue)->ip4.addr) { @@ -495,7 +494,7 @@ static int pico_socket_mcast_filter_include(struct pico_mcast_listen *listen, un } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach(index, &listen->MCASTSources_ipv6) { if (memcmp(&src->ip6, &((union pico_address *)index->keyValue)->ip6, sizeof(struct pico_ip6))) { @@ -521,7 +520,7 @@ static int pico_socket_mcast_filter_exclude(struct pico_mcast_listen *listen, un #ifdef PICO_DEBUG_MCAST char tmp_string[PICO_IPV6_STRING]; #endif - if(!pico_tree_empty(&listen->MCASTSources)) { + if (!pico_tree_empty(&listen->MCASTSources)) { pico_tree_foreach(index, &listen->MCASTSources) { if (src->ip4.addr == ((union pico_address *)index->keyValue)->ip4.addr) { @@ -532,7 +531,7 @@ static int pico_socket_mcast_filter_exclude(struct pico_mcast_listen *listen, un } #ifdef PICO_SUPPORT_IPV6 - if(!pico_tree_empty(&listen->MCASTSources_ipv6)) { + if (!pico_tree_empty(&listen->MCASTSources_ipv6)) { pico_tree_foreach(index, &listen->MCASTSources_ipv6) { if (memcmp(&src->ip6, &((union pico_address *)index->keyValue)->ip6, sizeof(struct pico_ip6))) { @@ -569,7 +568,7 @@ static void *pico_socket_mcast_filter_link_get(struct pico_socket *s) if (!s->MCASTListen) return NULL; - if( IS_SOCK_IPV4(s)) { + if (IS_SOCK_IPV4(s)) { if (!s->local_addr.ip4.addr) return pico_ipv4_get_default_mcastlink(s->stack); @@ -577,7 +576,7 @@ static void *pico_socket_mcast_filter_link_get(struct pico_socket *s) } #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) { + else if (IS_SOCK_IPV6(s)) { if (pico_ipv6_is_null_address(&s->local_addr.ip6)) return pico_ipv6_get_default_mcastlink(s->stack); @@ -595,11 +594,11 @@ int pico_socket_mcast_filter(struct pico_socket *s, union pico_address *mcast_gr if (!mcast_link) return -1; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) listen = listen_find(s, (union pico_address *) &((struct pico_ipv4_link*)(mcast_link))->address, mcast_group); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) listen = listen_find(s, (union pico_address *)&((struct pico_ipv6_link*)(mcast_link))->address, mcast_group); #endif if (!listen) @@ -796,10 +795,10 @@ static struct pico_ipv6_link *setop_multicast_link_search_ipv6(struct pico_stack #endif static int setop_verify_listen_tree(struct pico_socket *s, int alloc) { - if(!alloc) + if (!alloc) return -1; - if( IS_SOCK_IPV4(s)) { + if (IS_SOCK_IPV4(s)) { s->MCASTListen = PICO_ZALLOC(sizeof(struct pico_tree)); if (!s->MCASTListen) { @@ -812,7 +811,7 @@ static int setop_verify_listen_tree(struct pico_socket *s, int alloc) } #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) { + else if (IS_SOCK_IPV6(s)) { s->MCASTListen_ipv6 = PICO_ZALLOC(sizeof(struct pico_tree)); if (!s->MCASTListen_ipv6) { pico_err = PICO_ERR_ENOMEM; @@ -837,11 +836,11 @@ static void *setopt_multicast_check(struct pico_socket *s, void *value, int allo return NULL; } - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) mcast_link = setop_multicast_link_search(s->stack, value, bysource); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) mcast_link = setop_multicast_link_search_ipv6(s->stack, value, bysource); #endif if (!mcast_link) { @@ -867,7 +866,7 @@ void pico_multicast_delete(struct pico_socket *s) struct pico_tree *tree, *listen_tree; struct pico_mcast mcast; listen_tree = mcast_get_listen_tree(s); - if(listen_tree) { + if (listen_tree) { pico_tree_delete(&s->stack->MCASTSockets, s); pico_tree_foreach_safe(index, listen_tree, _tmp) { @@ -885,11 +884,11 @@ void pico_multicast_delete(struct pico_socket *s) filter_mode = pico_socket_aggregate_mcastfilters(s->stack, (union pico_address *)&listen->mcast_link, (union pico_address *)&listen->mcast_group); if (filter_mode >= 0) { - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) pico_ipv4_mcast_leave(s->stack, &listen->mcast_link.ip4, &listen->mcast_group.ip4, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) pico_ipv6_mcast_leave(s->stack, &listen->mcast_link.ip6, &listen->mcast_group.ip6, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif } @@ -905,7 +904,7 @@ void pico_multicast_delete(struct pico_socket *s) int pico_getsockopt_mcast(struct pico_socket *s, int option, void *value) { - switch(option) { + switch (option) { case PICO_IP_MULTICAST_IF: pico_err = PICO_ERR_EOPNOTSUPP; return -1; @@ -955,7 +954,7 @@ static int mcast_so_loop(struct pico_socket *s, void *value) } static int mcast_get_param(struct pico_mcast *mcast, struct pico_socket *s, void *value, int alloc, int by_source) { - if(by_source) + if (by_source) mcast->mreq_s = (struct pico_ip_mreq_source *)value; else mcast->mreq = (struct pico_ip_mreq *)value; @@ -965,7 +964,7 @@ static int mcast_get_param(struct pico_mcast *mcast, struct pico_socket *s, void return -1; mcast->address = pico_mcast_get_link_address(s, mcast->mcast_link); - if(by_source) + if (by_source) mcast->listen = listen_find(s, &(mcast->mreq_s)->mcast_link_addr, &mcast->mreq_s->mcast_group_addr); else mcast->listen = listen_find(s, &(mcast->mreq)->mcast_link_addr, &mcast->mreq->mcast_group_addr); @@ -977,7 +976,7 @@ static int mcast_so_addm(struct pico_socket *s, void *value) int filter_mode = 0; struct pico_mcast mcast; struct pico_tree *tree, *listen_tree; - if(mcast_get_param(&mcast, s, value, 1, 0) < 0) + if (mcast_get_param(&mcast, s, value, 1, 0) < 0) return -1; if (mcast.listen) { @@ -1005,32 +1004,32 @@ static int mcast_so_addm(struct pico_socket *s, void *value) tree = mcast_get_src_tree(s, &mcast); listen_tree = mcast_get_listen_tree(s); #ifdef PICO_SUPPORT_IPV6 - if( IS_SOCK_IPV6(s)) + if (IS_SOCK_IPV6(s)) mcast.listen->proto = PICO_PROTO_IPV6; #endif tree->root = &LEAF; if (pico_tree_insert(listen_tree, mcast.listen)) { - PICO_FREE(mcast.listen); - return -1; - } + PICO_FREE(mcast.listen); + return -1; + } if (pico_tree_insert(&s->stack->MCASTSockets, s) == &LEAF) { pico_tree_delete(listen_tree, mcast.listen); PICO_FREE(mcast.listen); - return -1; - } + return -1; + } filter_mode = pico_socket_aggregate_mcastfilters(s->stack, mcast.address, &mcast.mreq->mcast_group_addr); if (filter_mode < 0) return -1; so_mcast_dbg("PICO_IP_ADD_MEMBERSHIP - success, added %p\n", s); - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_join(s->stack, (struct pico_ip4*)&mcast.mreq->mcast_link_addr, (struct pico_ip4*) &mcast.mreq->mcast_group_addr, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { + else if (IS_SOCK_IPV6(s)) { return pico_ipv6_mcast_join(s->stack, (struct pico_ip6*)&mcast.mreq->mcast_link_addr, (struct pico_ip6*)&mcast.mreq->mcast_group_addr, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); } #endif @@ -1044,7 +1043,7 @@ static int mcast_so_dropm(struct pico_socket *s, void *value) struct pico_tree_node *_tmp, *index; struct pico_mcast mcast; struct pico_tree *listen_tree, *tree; - if(mcast_get_param(&mcast, s, value, 0, 0) < 0) + if (mcast_get_param(&mcast, s, value, 0, 0) < 0) return -1; if (!mcast.listen) { @@ -1073,11 +1072,11 @@ static int mcast_so_dropm(struct pico_socket *s, void *value) if (filter_mode < 0) return -1; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_leave(s->stack, (struct pico_ip4*) &mcast.mreq->mcast_link_addr, (struct pico_ip4 *) &mcast.mreq->mcast_group_addr, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { } + else if (IS_SOCK_IPV6(s)) { } return pico_ipv6_mcast_leave(s->stack, (struct pico_ip6*)&mcast.mreq->mcast_link_addr, (struct pico_ip6*)&mcast.mreq->mcast_group_addr, 1, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif return -1; @@ -1088,7 +1087,7 @@ static int mcast_so_unblock_src(struct pico_socket *s, void *value) int filter_mode = 0; union pico_address stest, *source = NULL; struct pico_mcast mcast; - if(mcast_get_param(&mcast, s, value, 0, 1) < 0) + if (mcast_get_param(&mcast, s, value, 0, 1) < 0) return -1; memset(&stest, 0, sizeof(union pico_address)); @@ -1105,11 +1104,11 @@ static int mcast_so_unblock_src(struct pico_socket *s, void *value) } stest = mcast.mreq_s->mcast_source_addr; - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) source = pico_tree_findKey(&mcast.listen->MCASTSources, &stest); #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) source = pico_tree_findKey(&mcast.listen->MCASTSources_ipv6, &stest); #endif if (!source) { @@ -1118,11 +1117,11 @@ static int mcast_so_unblock_src(struct pico_socket *s, void *value) return -1; } - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) pico_tree_delete(&mcast.listen->MCASTSources, source); #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) pico_tree_delete(&mcast.listen->MCASTSources_ipv6, source); #endif @@ -1130,11 +1129,11 @@ static int mcast_so_unblock_src(struct pico_socket *s, void *value) if (filter_mode < 0) return -1; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_leave(s->stack, (struct pico_ip4 *)&mcast.mreq_s->mcast_link_addr, (struct pico_ip4*) &mcast.mreq_s->mcast_group_addr, 0, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { } + else if (IS_SOCK_IPV6(s)) { } return pico_ipv6_mcast_leave(s->stack, (struct pico_ip6*)&mcast.mreq_s->mcast_link_addr, (struct pico_ip6*)&mcast.mreq_s->mcast_group_addr, 0, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif return -1; @@ -1145,7 +1144,7 @@ static int mcast_so_block_src(struct pico_socket *s, void *value) int filter_mode = 0; union pico_address stest, *source = NULL; struct pico_mcast mcast; - if(mcast_get_param(&mcast, s, value, 0, 1) < 0) + if (mcast_get_param(&mcast, s, value, 0, 1) < 0) return -1; memset(&stest, 0, sizeof(union pico_address)); @@ -1162,11 +1161,11 @@ static int mcast_so_block_src(struct pico_socket *s, void *value) } stest = mcast.mreq_s->mcast_source_addr; - if( IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) source = pico_tree_findKey(&mcast.listen->MCASTSources, &stest); #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) source = pico_tree_findKey(&mcast.listen->MCASTSources_ipv6, &stest); #endif if (source) { @@ -1182,30 +1181,30 @@ static int mcast_so_block_src(struct pico_socket *s, void *value) } *source = mcast.mreq_s->mcast_source_addr; - if( IS_SOCK_IPV4(s)) { - if (pico_tree_insert(&mcast.listen->MCASTSources, source)) { - PICO_FREE(source); - return -1; - } + if (IS_SOCK_IPV4(s)) { + if (pico_tree_insert(&mcast.listen->MCASTSources, source)) { + PICO_FREE(source); + return -1; + } } #ifdef PICO_SUPPORT_IPV6 - else if( IS_SOCK_IPV6(s)) - if (pico_tree_insert(&mcast.listen->MCASTSources_ipv6, source)) { - PICO_FREE(source); - return -1; - } + else if (IS_SOCK_IPV6(s)) + if (pico_tree_insert(&mcast.listen->MCASTSources_ipv6, source)) { + PICO_FREE(source); + return -1; + } #endif filter_mode = pico_socket_aggregate_mcastfilters(s->stack, mcast.address, &mcast.mreq_s->mcast_group_addr); if (filter_mode < 0) return -1; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_join(s->stack, (struct pico_ip4 *) &mcast.mreq_s->mcast_link_addr, (struct pico_ip4*)&mcast.mreq_s->mcast_group_addr, 0, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { } + else if (IS_SOCK_IPV6(s)) { } return pico_ipv6_mcast_join(s->stack, (struct pico_ip6 *)&mcast.mreq_s->mcast_link_addr, (struct pico_ip6*)&mcast.mreq_s->mcast_group_addr, 0, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif return -1; @@ -1217,7 +1216,7 @@ static int mcast_so_addsrcm(struct pico_socket *s, void *value) union pico_address stest, *source = NULL; struct pico_mcast mcast; struct pico_tree *tree, *listen_tree; - if(mcast_get_param(&mcast, s, value, 1, 1) < 0) + if (mcast_get_param(&mcast, s, value, 1, 1) < 0) return -1; memset(&stest, 0, sizeof(union pico_address)); @@ -1246,9 +1245,9 @@ static int mcast_so_addsrcm(struct pico_socket *s, void *value) *source = mcast.mreq_s->mcast_source_addr; if (pico_tree_insert(tree, source)) { - PICO_FREE(source); - return -1; - } + PICO_FREE(source); + return -1; + } } else { mcast.listen = PICO_ZALLOC(sizeof(struct pico_mcast_listen)); @@ -1270,38 +1269,38 @@ static int mcast_so_addsrcm(struct pico_socket *s, void *value) } #ifdef PICO_SUPPORT_IPV6 - if( IS_SOCK_IPV6(s)) + if (IS_SOCK_IPV6(s)) mcast.listen->proto = PICO_PROTO_IPV6; #endif *source = mcast.mreq_s->mcast_source_addr; if (pico_tree_insert(tree, source)) { - PICO_FREE(mcast.listen); - PICO_FREE(source); - return -1; - } + PICO_FREE(mcast.listen); + PICO_FREE(source); + return -1; + } if (pico_tree_insert(listen_tree, mcast.listen)) { pico_tree_delete(tree, source); PICO_FREE(source); PICO_FREE(mcast.listen); - return -1; - } + return -1; + } reference_count = 1; } if (pico_tree_insert(&s->stack->MCASTSockets, s) == &LEAF) { - return -1; - } + return -1; + } filter_mode = pico_socket_aggregate_mcastfilters(s->stack, mcast.address, &mcast.mreq_s->mcast_group_addr); if (filter_mode < 0) return -1; - if(IS_SOCK_IPV4(s)) + if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_join(s->stack, (struct pico_ip4 *)&mcast.mreq_s->mcast_link_addr, (struct pico_ip4*)&mcast.mreq_s->mcast_group_addr, (uint8_t)reference_count, (uint8_t)filter_mode, &s->stack->MCASTFilter); #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) { } + else if (IS_SOCK_IPV6(s)) { } return pico_ipv6_mcast_join(s->stack, (struct pico_ip6 *) &mcast.mreq_s->mcast_link_addr, (struct pico_ip6*)&mcast.mreq_s->mcast_group_addr, (uint8_t)reference_count, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif return -1; @@ -1313,7 +1312,7 @@ static int mcast_so_dropsrcm(struct pico_socket *s, void *value) union pico_address stest, *source = NULL; struct pico_mcast mcast; struct pico_tree *tree, *listen_tree; - if(mcast_get_param(&mcast, s, value, 0, 1) < 0) + if (mcast_get_param(&mcast, s, value, 0, 1) < 0) return -1; memset(&stest, 0, sizeof(union pico_address)); @@ -1355,11 +1354,11 @@ static int mcast_so_dropsrcm(struct pico_socket *s, void *value) if (filter_mode < 0) return -1; #ifdef PICO_SUPPORT_IPV4 - else if(IS_SOCK_IPV4(s)) + else if (IS_SOCK_IPV4(s)) return pico_ipv4_mcast_leave(s->stack, (struct pico_ip4 *) &mcast.mreq_s->mcast_link_addr, (struct pico_ip4*)&mcast.mreq_s->mcast_group_addr, (uint8_t)reference_count, (uint8_t)filter_mode, &s->stack->MCASTFilter); #endif #ifdef PICO_SUPPORT_IPV6 - else if(IS_SOCK_IPV6(s)) + else if (IS_SOCK_IPV6(s)) return pico_ipv6_mcast_leave(s->stack, (struct pico_ip6 *)&mcast.mreq_s->mcast_link_addr, (struct pico_ip6*)&mcast.mreq_s->mcast_group_addr, (uint8_t)reference_count, (uint8_t)filter_mode, &s->stack->MCASTFilter_ipv6); #endif return -1; @@ -1372,8 +1371,7 @@ struct pico_setsockopt_mcast_call int (*call)(struct pico_socket *, void *); }; -static const struct pico_setsockopt_mcast_call mcast_so_calls[1 + PICO_IP_DROP_SOURCE_MEMBERSHIP - PICO_IP_MULTICAST_IF] = -{ +static const struct pico_setsockopt_mcast_call mcast_so_calls[1 + PICO_IP_DROP_SOURCE_MEMBERSHIP - PICO_IP_MULTICAST_IF] = { { PICO_IP_MULTICAST_IF, NULL }, { PICO_IP_MULTICAST_TTL, pico_udp_set_mc_ttl }, { PICO_IP_MULTICAST_LOOP, mcast_so_loop }, @@ -1425,7 +1423,7 @@ int pico_udp_set_mc_ttl(struct pico_socket *s, void *_ttl) { struct pico_socket_udp *u; uint8_t ttl = *(uint8_t *)_ttl; - if(!s) { + if (!s) { pico_err = PICO_ERR_EINVAL; return -1; } @@ -1438,7 +1436,7 @@ int pico_udp_set_mc_ttl(struct pico_socket *s, void *_ttl) int pico_udp_get_mc_ttl(struct pico_socket *s, uint8_t *ttl) { struct pico_socket_udp *u; - if(!s) + if (!s) return -1; u = (struct pico_socket_udp *) s; diff --git a/stack/pico_stack.c b/stack/pico_stack.c index 4244ddc2..45c57409 100644 --- a/stack/pico_stack.c +++ b/stack/pico_stack.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Authors: Daniele Lacamera - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -77,7 +77,7 @@ void pico_to_lowercase(char *str) if (!str) return; - while(str[i]) { + while (str[i]) { if ((str[i] <= 'Z') && (str[i] >= 'A')) str[i] = (char) (str[i] - (char)('A' - 'a')); @@ -268,7 +268,7 @@ MOCKABLE int32_t pico_network_receive(struct pico_frame *f) return (int32_t)f->buffer_len; } -/// Interface towards socket for frame sending +/*/ Interface towards socket for frame sending */ int32_t pico_network_send(struct pico_frame *f) { if (!f || !f->sock || !f->sock->net) { @@ -395,16 +395,16 @@ int pico_datalink_receive(struct pico_frame *f) /* If device has stack with datalink-layer pass frame through it */ switch (f->dev->mode) { #ifdef PICO_SUPPORT_802154 - case LL_MODE_IEEE802154: - f->datalink_hdr = f->buffer; - return pico_enqueue(pico_proto_6lowpan_ll.q_in, f); + case LL_MODE_IEEE802154: + f->datalink_hdr = f->buffer; + return pico_enqueue(pico_proto_6lowpan_ll.q_in, f); #endif - default: + default: #ifdef PICO_SUPPORT_ETH - f->datalink_hdr = f->buffer; - return pico_enqueue(pico_proto_ethernet.q_in,f); + f->datalink_hdr = f->buffer; + return pico_enqueue(pico_proto_ethernet.q_in, f); #else - return -1; + return -1; #endif } } else { @@ -421,14 +421,14 @@ MOCKABLE int pico_datalink_send(struct pico_frame *f) if (f->dev->eth) { switch (f->dev->mode) { #ifdef PICO_SUPPORT_802154 - case LL_MODE_IEEE802154: - return pico_enqueue(pico_proto_6lowpan.q_out, f); + case LL_MODE_IEEE802154: + return pico_enqueue(pico_proto_6lowpan.q_out, f); #endif - default: + default: #ifdef PICO_SUPPORT_ETH - return pico_enqueue(pico_proto_ethernet.q_out, f); + return pico_enqueue(pico_proto_ethernet.q_out, f); #else - return -1; + return -1; #endif } } else { @@ -448,8 +448,7 @@ struct pico_frame *pico_stack_recv_new_frame(struct pico_device *dev, uint8_t *b return NULL; f = pico_frame_alloc(len); - if (!f) - { + if (!f) { dbg("Cannot alloc incoming frame!\n"); return NULL; } @@ -476,7 +475,7 @@ struct pico_frame *pico_stack_recv_new_frame(struct pico_device *dev, uint8_t *b */ int32_t MOCKABLE pico_stack_recv(struct pico_device *dev, uint8_t *buffer, uint32_t len) { - struct pico_frame *f = pico_stack_recv_new_frame (dev, buffer, len); + struct pico_frame *f = pico_stack_recv_new_frame(dev, buffer, len); int32_t ret; if (!f) @@ -497,14 +496,12 @@ static int32_t _pico_stack_recv_zerocopy(struct pico_device *dev, uint8_t *buffe return -1; f = pico_frame_alloc_skeleton(len, ext_buffer); - if (!f) - { + if (!f) { dbg("Cannot alloc incoming frame!\n"); return -1; } - if (pico_frame_skeleton_set_buffer(f, buffer) < 0) - { + if (pico_frame_skeleton_set_buffer(f, buffer) < 0) { dbg("Invalid zero-copy buffer!\n"); PICO_FREE(f->usage_count); PICO_FREE(f); @@ -559,8 +556,7 @@ int32_t pico_seq_compare(uint32_t a, uint32_t b) { uint32_t thresh = ((uint32_t)(-1)) >> 1; - if (a > b) /* return positive number, if not wrapped */ - { + if (a > b) { /* return positive number, if not wrapped */ if ((a - b) > thresh) /* b wrapped */ return -(int32_t)(b - a); /* b = very small, a = very big */ else @@ -568,8 +564,7 @@ int32_t pico_seq_compare(uint32_t a, uint32_t b) } - if (a < b) /* return negative number, if not wrapped */ - { + if (a < b) { /* return negative number, if not wrapped */ if ((b - a) > thresh) /* a wrapped */ return (int32_t)(a - b); /* a = very small, b = very big */ else @@ -585,13 +580,12 @@ static void pico_check_timers(struct pico_stack *S) struct pico_timer *t; struct pico_timer_ref tref_unused, *tref = heap_first(S->Timers); S->pico_tick = PICO_TIME_MS(); - while((tref) && (tref->expire <= S->pico_tick)) { + while ((tref) && (tref->expire <= S->pico_tick)) { t = tref->tmr; if (t && t->timer) t->timer(S->pico_tick, t->arg); - if (t) - { + if (t) { PICO_FREE(t); } @@ -611,7 +605,7 @@ long long int pico_stack_go(struct pico_stack *S) return -1; /* Execute jobs again, in case they were scheduled in timer execution */ pico_execute_pending_jobs(S); - return(long long int)((tref->expire - S->pico_tick) + 1); + return (long long int)((tref->expire - S->pico_tick) + 1); } #endif @@ -625,8 +619,7 @@ void MOCKABLE pico_timer_cancel(struct pico_stack *S, uint32_t id) for (i = 1; i <= S->Timers->n; i++) { tref = heap_get_element(S->Timers, i); if (tref->id == id) { - if (tref->tmr) - { + if (tref->tmr) { PICO_FREE(tref->tmr); tref->tmr = NULL; tref->id = 0; @@ -646,8 +639,7 @@ void pico_timer_cancel_hashed(struct pico_stack *S, uint32_t hash) for (i = 1; i <= S->Timers->n; i++) { tref = heap_get_element(S->Timers, i); if (tref->hash == hash) { - if (tref->tmr) - { + if (tref->tmr) { PICO_FREE(tref->tmr); tref->tmr = NULL; tref[i].id = 0; @@ -708,8 +700,7 @@ static int calc_score(struct pico_stack *S) /* also add non-changed S->scores */ total += S->score[i]; - } - else if (S->ret[i] == S->score[i]) { + } else if (S->ret[i] == S->score[i]) { /* no used loop S->score - gradually decrease */ /* dbg("%3d - ",0); */ @@ -878,12 +869,12 @@ int MOCKABLE pico_stack_init(struct pico_stack **S) #ifdef PICO_SUPPORT_IPV6 pico_protocol_init(*S, &pico_proto_ipv6); ATTACH_QUEUES(*S, ipv6, pico_proto_ipv6); - EMPTY_TREE((*S)->Tree_dev_ip6_link, ipv6_link_compare); - EMPTY_TREE((*S)->IPV6Routes, ipv6_route_compare); - EMPTY_TREE((*S)->IPV6Links, ipv6_link_compare); - EMPTY_TREE((*S)->IPV6NQueue, pico_ipv6_nd_qcompare); - EMPTY_TREE((*S)->IPV6NCache, pico_ipv6_neighbor_compare); - EMPTY_TREE((*S)->IPV6RCache, pico_ipv6_router_compare); + EMPTY_TREE((*S)->Tree_dev_ip6_link, ipv6_link_compare); + EMPTY_TREE((*S)->IPV6Routes, ipv6_route_compare); + EMPTY_TREE((*S)->IPV6Links, ipv6_link_compare); + EMPTY_TREE((*S)->IPV6NQueue, pico_ipv6_nd_qcompare); + EMPTY_TREE((*S)->IPV6NCache, pico_ipv6_neighbor_compare); + EMPTY_TREE((*S)->IPV6RCache, pico_ipv6_router_compare); # ifdef PICO_SUPPORT_IPV6FRAG EMPTY_TREE((*S)->ipv6_fragments, pico_ipv6_frag_compare); # endif @@ -905,7 +896,7 @@ int MOCKABLE pico_stack_init(struct pico_stack **S) #ifdef PICO_SUPPORT_ICMP6 pico_protocol_init(*S, &pico_proto_icmp6); ATTACH_QUEUES(*S, icmp6, pico_proto_icmp6); - EMPTY_TREE((*S)->IPV6Pings, icmp6_cookie_compare); + EMPTY_TREE((*S)->IPV6Pings, icmp6_cookie_compare); #endif #if defined(PICO_SUPPORT_IGMP) && defined(PICO_SUPPORT_MCAST) @@ -946,7 +937,7 @@ int MOCKABLE pico_stack_init(struct pico_stack **S) EMPTY_TREE((*S)->NSTable, dns_nameserver_cmp); pico_dns_client_init((*S)); #endif - + #ifdef PICO_SUPPORT_MDNS # if PICO_MDNS_ALLOW_CACHING == 1 @@ -974,7 +965,7 @@ int MOCKABLE pico_stack_init(struct pico_stack **S) #ifdef PICO_SUPPORT_IPV6PMTU pico_ipv6_path_init((*S), PICO_PMTU_CACHE_CLEANUP_INTERVAL); - EMPTY_TREE((*S)->IPV6PathCache, pico_ipv6_path_compare); + EMPTY_TREE((*S)->IPV6PathCache, pico_ipv6_path_compare); (*S)->ipv6_path_cache_gc_timer.interval = PICO_PMTU_CACHE_CLEANUP_INTERVAL; #endif @@ -996,7 +987,7 @@ int MOCKABLE pico_stack_init(struct pico_stack **S) #endif #ifdef PICO_SUPPORT_6LOWPAN if (pico_6lowpan_init(*S)) - return -1; + return -1; #endif #ifdef PICO_SUPPORT_SNTP_CLIENT (*S)->sntp_port = 123u; @@ -1062,10 +1053,9 @@ static void pico_terminate_timers(struct pico_stack *S) struct pico_timer *t; struct pico_timer_ref tref_unused, *tref = heap_first(S->Timers); S->pico_tick = PICO_TIME_MS(); - while(tref) { + while (tref) { t = tref->tmr; - if (t) - { + if (t) { PICO_FREE(t); } @@ -1106,7 +1096,7 @@ void pico_stack_deinit(struct pico_stack *S) pico_socket_destroy_all(S); /* Cleanup: queues */ - + #ifdef PICO_SUPPORT_ETH DETACH_QUEUES(S, ethernet); #endif diff --git a/stack/pico_tree.c b/stack/pico_tree.c index e0ebaea7..3102370b 100644 --- a/stack/pico_tree.c +++ b/stack/pico_tree.c @@ -1,12 +1,12 @@ /********************************************************************* - * PicoTCP-NG + * PicoTCP-NG * Copyright (c) 2020 Daniele Lacamera * * This file also includes code from: * PicoTCP * Copyright (c) 2012-2017 Altran Intelligent Systems * Author: Andrei Carp - * + * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only * * PicoTCP-NG is free software; you can redistribute it and/or modify @@ -81,14 +81,14 @@ extern void pico_mem_page0_free(void*ptr); struct pico_tree_node *pico_tree_firstNode(struct pico_tree_node *node) { - while(IS_NOT_LEAF(node->leftChild)) + while (IS_NOT_LEAF(node->leftChild)) node = node->leftChild; return node; } struct pico_tree_node *pico_tree_lastNode(struct pico_tree_node *node) { - while(IS_NOT_LEAF(node->rightChild)) + while (IS_NOT_LEAF(node->rightChild)) node = node->rightChild; return node; } @@ -98,14 +98,11 @@ struct pico_tree_node *pico_tree_next(struct pico_tree_node *node) if (!node) return NULL; - if(IS_NOT_LEAF(node->rightChild)) - { + if (IS_NOT_LEAF(node->rightChild)) { node = node->rightChild; - while(IS_NOT_LEAF(node->leftChild)) + while (IS_NOT_LEAF(node->leftChild)) node = node->leftChild; - } - else - { + } else { if (IS_NOT_LEAF(node->parent) && AM_I_LEFT_CHILD(node)) node = node->parent; else { @@ -155,8 +152,7 @@ static void pico_tree_insert_node(struct pico_tree *tree, struct pico_tree_node int result = 0; /* search for the place to insert the new node */ - while(IS_NOT_LEAF(temp)) - { + while (IS_NOT_LEAF(temp)) { last_node = temp; result = tree->compare(insert->keyValue, temp->keyValue); @@ -165,11 +161,11 @@ static void pico_tree_insert_node(struct pico_tree *tree, struct pico_tree_node /* make the needed connections */ insert->parent = last_node; - if(IS_LEAF(last_node)) + if (IS_LEAF(last_node)) tree->root = insert; - else{ + else { result = tree->compare(insert->keyValue, last_node->keyValue); - if(result < 0) + if (result < 0) last_node->leftChild = insert; else last_node->rightChild = insert; @@ -184,15 +180,14 @@ void *pico_tree_insert_implementation(struct pico_tree *tree, void *key, uint8_t LocalKey = (IS_NOT_LEAF(tree->root) ? pico_tree_findKey(tree, key) : NULL); /* if node already in, bail out */ - if(LocalKey) { + if (LocalKey) { pico_err = PICO_ERR_EEXIST; return LocalKey; } insert = create_node(tree, key, allocator); - if(!insert) - { + if (!insert) { pico_err = PICO_ERR_ENOMEM; /* to let the user know that it couldn't insert */ return &LEAF; @@ -212,13 +207,12 @@ struct pico_tree_node *pico_tree_findNode(struct pico_tree *tree, void *key) found = tree->root; - while(IS_NOT_LEAF(found)) - { + while (IS_NOT_LEAF(found)) { int result; result = tree->compare(found->keyValue, key); - if(result == 0) + if (result == 0) return found; - else if(result < 0) + else if (result < 0) found = found->rightChild; else found = found->leftChild; @@ -255,18 +249,18 @@ static uint8_t pico_tree_delete_node(struct pico_tree *tree, struct pico_tree_no nodeColor = min->color; *temp = min->rightChild; - if(min->parent == ltemp && IS_NOT_LEAF(*temp)) + if (min->parent == ltemp && IS_NOT_LEAF(*temp)) (*temp)->parent = min; - else{ + else { switchNodes(tree, min, min->rightChild); min->rightChild = ltemp->rightChild; - if(IS_NOT_LEAF(min->rightChild)) min->rightChild->parent = min; + if (IS_NOT_LEAF(min->rightChild))min->rightChild->parent = min; } switchNodes(tree, ltemp, min); min->leftChild = ltemp->leftChild; - if(IS_NOT_LEAF(min->leftChild)) + if (IS_NOT_LEAF(min->leftChild)) min->leftChild->parent = min; min->color = ltemp->color; @@ -277,19 +271,14 @@ static uint8_t pico_tree_delete_check_switch(struct pico_tree *tree, struct pico { struct pico_tree_node *ltemp = delete; uint8_t nodeColor = delete->color; - if(IS_LEAF(delete->leftChild)) - { + if (IS_LEAF(delete->leftChild)) { *temp = ltemp->rightChild; switchNodes(tree, ltemp, ltemp->rightChild); - } - else - if(IS_LEAF(delete->rightChild)) - { + } else if (IS_LEAF(delete->rightChild)) { struct pico_tree_node *_ltemp = delete; *temp = _ltemp->leftChild; switchNodes(tree, _ltemp, _ltemp->leftChild); - } - else{ + } else { nodeColor = pico_tree_delete_node(tree, delete, temp); } @@ -311,7 +300,7 @@ void *pico_tree_delete(struct pico_tree *tree, void *key) static inline void if_nodecolor_black_fix_collisions(struct pico_tree *tree, struct pico_tree_node *temp, uint8_t nodeColor) { /* deleted node is black, this will mess up the black path property */ - if(nodeColor == BLACK) + if (nodeColor == BLACK) fix_delete_collisions(tree, temp); } @@ -327,7 +316,7 @@ void *pico_tree_delete_implementation(struct pico_tree *tree, void *key, uint8_t delete = pico_tree_findNode(tree, key); /* this key isn't in the tree, bail out */ - if(!delete) + if (!delete) return NULL; lkey = delete->keyValue; @@ -335,7 +324,7 @@ void *pico_tree_delete_implementation(struct pico_tree *tree, void *key, uint8_t if_nodecolor_black_fix_collisions(tree, temp, nodeColor); - if(allocator == USE_PICO_ZALLOC) + if (allocator == USE_PICO_ZALLOC) PICO_FREE(delete); #ifdef PICO_SUPPORT_MM @@ -359,19 +348,18 @@ static void rotateToLeft(struct pico_tree*tree, struct pico_tree_node*node) temp = node->rightChild; - if(temp == &LEAF) return; + if (temp == &LEAF)return; node->rightChild = temp->leftChild; - if(IS_NOT_LEAF(temp->leftChild)) + if (IS_NOT_LEAF(temp->leftChild)) temp->leftChild->parent = node; temp->parent = node->parent; - if(IS_LEAF(node->parent)) + if (IS_LEAF(node->parent)) tree->root = temp; - else - if(node == node->parent->leftChild) + else if (node == node->parent->leftChild) node->parent->leftChild = temp; else node->parent->rightChild = temp; @@ -388,17 +376,16 @@ static void rotateToRight(struct pico_tree *tree, struct pico_tree_node *node) temp = node->leftChild; node->leftChild = temp->rightChild; - if(temp == &LEAF) return; + if (temp == &LEAF)return; - if(IS_NOT_LEAF(temp->rightChild)) + if (IS_NOT_LEAF(temp->rightChild)) temp->rightChild->parent = node; temp->parent = node->parent; - if(IS_LEAF(node->parent)) + if (IS_LEAF(node->parent)) tree->root = temp; - else - if(node == node->parent->rightChild) + else if (node == node->parent->rightChild) node->parent->rightChild = temp; else node->parent->leftChild = temp; @@ -412,7 +399,7 @@ static struct pico_tree_node *create_node(struct pico_tree *tree, void*key, uint { struct pico_tree_node *temp = NULL; IGNORE_PARAMETER(tree); - if(allocator == USE_PICO_ZALLOC) + if (allocator == USE_PICO_ZALLOC) temp = (struct pico_tree_node *)PICO_ZALLOC(sizeof(struct pico_tree_node)); #ifdef PICO_SUPPORT_MM @@ -420,7 +407,7 @@ static struct pico_tree_node *create_node(struct pico_tree *tree, void*key, uint temp = (struct pico_tree_node *)pico_mem_page0_zalloc(sizeof(struct pico_tree_node)); #endif - if(!temp) + if (!temp) return NULL; temp->keyValue = key; @@ -440,19 +427,16 @@ static void fix_insert_collisions(struct pico_tree*tree, struct pico_tree_node*n { struct pico_tree_node*temp; - while(node->parent->color == RED && IS_NOT_LEAF(GRANPA(node))) - { - if(AM_I_RIGHT_CHILD(node->parent)) - { + while (node->parent->color == RED && IS_NOT_LEAF(GRANPA(node))) { + if (AM_I_RIGHT_CHILD(node->parent)) { temp = GRANPA(node)->leftChild; - if(temp->color == RED) { + if (temp->color == RED) { node->parent->color = BLACK; temp->color = BLACK; GRANPA(node)->color = RED; node = GRANPA(node); - } - else if(temp->color == BLACK) { - if(AM_I_LEFT_CHILD(node)) { + } else if (temp->color == BLACK) { + if (AM_I_LEFT_CHILD(node)) { node = node->parent; rotateToRight(tree, node); } @@ -461,18 +445,15 @@ static void fix_insert_collisions(struct pico_tree*tree, struct pico_tree_node*n GRANPA(node)->color = RED; rotateToLeft(tree, GRANPA(node)); } - } - else if(AM_I_LEFT_CHILD(node->parent)) - { + } else if (AM_I_LEFT_CHILD(node->parent)) { temp = GRANPA(node)->rightChild; - if(temp->color == RED) { + if (temp->color == RED) { node->parent->color = BLACK; temp->color = BLACK; GRANPA(node)->color = RED; node = GRANPA(node); - } - else if(temp->color == BLACK) { - if(AM_I_RIGHT_CHILD(node)) { + } else if (temp->color == BLACK) { + if (AM_I_RIGHT_CHILD(node)) { node = node->parent; rotateToLeft(tree, node); } @@ -490,18 +471,16 @@ static void fix_insert_collisions(struct pico_tree*tree, struct pico_tree_node*n static void switchNodes(struct pico_tree*tree, struct pico_tree_node*nodeA, struct pico_tree_node*nodeB) { - if(IS_LEAF(nodeA->parent)) + if (IS_LEAF(nodeA->parent)) tree->root = nodeB; - else - if(IS_NOT_LEAF(nodeA)) - { - if(AM_I_LEFT_CHILD(nodeA)) + else if (IS_NOT_LEAF(nodeA)) { + if (AM_I_LEFT_CHILD(nodeA)) nodeA->parent->leftChild = nodeB; else nodeA->parent->rightChild = nodeB; } - if(IS_NOT_LEAF(nodeB)) nodeB->parent = nodeA->parent; + if (IS_NOT_LEAF(nodeB))nodeB->parent = nodeA->parent; } @@ -514,28 +493,22 @@ static void fix_delete_collisions(struct pico_tree*tree, struct pico_tree_node * { struct pico_tree_node*temp; - while( node != tree->root && node->color == BLACK && IS_NOT_LEAF(node)) - { - if(AM_I_LEFT_CHILD(node)) { + while (node != tree->root && node->color == BLACK && IS_NOT_LEAF(node)) { + if (AM_I_LEFT_CHILD(node)) { temp = node->parent->rightChild; - if(temp->color == RED) - { + if (temp->color == RED) { temp->color = BLACK; node->parent->color = RED; rotateToLeft(tree, node->parent); temp = node->parent->rightChild; } - if(temp->leftChild->color == BLACK && temp->rightChild->color == BLACK) - { + if (temp->leftChild->color == BLACK && temp->rightChild->color == BLACK) { temp->color = RED; node = node->parent; - } - else - { - if(temp->rightChild->color == BLACK) - { + } else { + if (temp->rightChild->color == BLACK) { temp->leftChild->color = BLACK; temp->color = RED; rotateToRight(tree, temp); @@ -548,25 +521,20 @@ static void fix_delete_collisions(struct pico_tree*tree, struct pico_tree_node * rotateToLeft(tree, node->parent); node = tree->root; } - } - else{ + } else { temp = node->parent->leftChild; - if(temp->color == RED) - { + if (temp->color == RED) { temp->color = BLACK; node->parent->color = RED; rotateToRight(tree, node->parent); temp = node->parent->leftChild; } - if(temp->rightChild->color == BLACK && temp->leftChild->color == BLACK) - { + if (temp->rightChild->color == BLACK && temp->leftChild->color == BLACK) { temp->color = RED; node = node->parent; - } - else{ - if(temp->leftChild->color == BLACK) - { + } else { + if (temp->leftChild->color == BLACK) { temp->rightChild->color = BLACK; temp->color = RED; rotateToLeft(tree, temp); diff --git a/test/examples/dhcp_client.c b/test/examples/dhcp_client.c index 2164b4e7..dbf57584 100644 --- a/test/examples/dhcp_client.c +++ b/test/examples/dhcp_client.c @@ -72,13 +72,13 @@ void app_dhcp_client(struct pico_stack *S, char *arg) while (nxt) { if (nxt) { nxt = cpy_arg(&sdev, nxt); - if(!sdev) { + if (!sdev) { goto out; } } dev = pico_get_device(S, sdev); - if(dev == NULL) { + if (dev == NULL) { if (sdev) free(sdev); diff --git a/test/examples/dns_sd.c b/test/examples/dns_sd.c index 7e800ea2..16bfac2f 100644 --- a/test/examples/dns_sd.c +++ b/test/examples/dns_sd.c @@ -15,9 +15,9 @@ static int fully_initialized = 0; static char *service_name = NULL; static pico_stack *stack = NULL; -void dns_sd_claimed_callback( pico_mdns_rtree *tree, - char *str, - void *arg ) +void dns_sd_claimed_callback(pico_mdns_rtree *tree, + char *str, + void *arg) { printf("DONE - Registering DNS-SD Service\n"); @@ -26,9 +26,9 @@ void dns_sd_claimed_callback( pico_mdns_rtree *tree, IGNORE_PARAMETER(arg); } -void dns_sd_init_callback( pico_mdns_rtree *tree, - char *str, - void *arg ) +void dns_sd_init_callback(pico_mdns_rtree *tree, + char *str, + void *arg) { PICO_DNS_SD_KV_VECTOR_DECLARE(key_value_pair_vector); @@ -63,17 +63,17 @@ void app_dns_sd(struct pico_stack *S, char *arg, struct pico_ip4 address) } nxt = cpy_arg(&hostname, nxt); - if(!hostname) { + if (!hostname) { exit(255); } - if(!nxt) { + if (!nxt) { printf("Not enough args supplied!\n"); exit(255); } nxt = cpy_arg(&service_name, nxt); - if(!service_name) { + if (!service_name) { exit(255); } @@ -94,7 +94,7 @@ void app_dns_sd(struct pico_stack *S, char *arg, struct pico_ip4 address) starttime = PICO_TIME_MS(); printf("Starting time: %d\n", starttime); - while(1) { + while (1) { pico_stack_tick(stack); usleep(2000); diff --git a/test/examples/iperfc.c b/test/examples/iperfc.c index be60ff55..709b37b1 100644 --- a/test/examples/iperfc.c +++ b/test/examples/iperfc.c @@ -29,7 +29,7 @@ static struct pico_stack *stack = NULL; static void panic(void) { - for(;; ) ; + for (;;); } static char buf[MTU] = {}; diff --git a/test/examples/mdns.c b/test/examples/mdns.c index 6aa5da07..b309613b 100644 --- a/test/examples/mdns.c +++ b/test/examples/mdns.c @@ -15,9 +15,9 @@ static struct pico_stack *stack = NULL; static int fully_initialized = 0; -void mdns_init_callback( pico_mdns_rtree *rtree, - char *str, - void *arg ) +void mdns_init_callback(pico_mdns_rtree *rtree, + char *str, + void *arg) { printf("\nInitialised with hostname: %s\n\n", str); @@ -36,17 +36,17 @@ void app_mdns(struct pico_stack *S, char *arg, struct pico_ip4 address) exit(255); nxt = cpy_arg(&hostname, nxt); - if(!hostname) { + if (!hostname) { exit(255); } - if(!nxt) { + if (!nxt) { printf("Not enough args supplied!\n"); exit(255); } nxt = cpy_arg(&peername, nxt); - if(!peername) { + if (!peername) { exit(255); } @@ -67,7 +67,7 @@ void app_mdns(struct pico_stack *S, char *arg, struct pico_ip4 address) starttime = PICO_TIME_MS(); printf("Starting time: %d\n", starttime); - while(1) { + while (1) { pico_stack_tick(S); usleep(2000); diff --git a/test/examples/multicast_ip6_recv.c b/test/examples/multicast_ip6_recv.c index a360d0a3..2ca87214 100644 --- a/test/examples/multicast_ip6_recv.c +++ b/test/examples/multicast_ip6_recv.c @@ -102,7 +102,7 @@ void app_mcastreceive_ipv6(struct pico_stack *S, char *arg) p = strcat(p + strlen(sport), ",64,"); /* DAD needs to verify the link address before we can continue */ - while(!pico_ipv6_link_get(stack, &inaddr_link.ip6)) { + while (!pico_ipv6_link_get(stack, &inaddr_link.ip6)) { pico_stack_tick(stack); usleep(2000); } @@ -113,58 +113,58 @@ void app_mcastreceive_ipv6(struct pico_stack *S, char *arg) memcpy(&mreq.mcast_link_addr, &inaddr_link, sizeof(struct pico_ip6)); memcpy(&mreq_source.mcast_link_addr, &inaddr_link, sizeof(struct pico_ip6)); memcpy(&mreq_source.mcast_source_addr, &src[0], sizeof(struct pico_ip6)); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_BLOCK_SOURCE, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_BLOCK_SOURCE, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_BLOCK_SOURCE failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_UNBLOCK_SOURCE, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_UNBLOCK_SOURCE, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_UNBLOCK_SOURCE failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_DROP_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } memcpy(&mreq_source.mcast_source_addr, &src[1], sizeof(struct pico_ip6)); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } memcpy(&mreq_source.mcast_source_addr, &src[2], sizeof(struct pico_ip6)); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } memcpy(&mreq_source.mcast_group_addr, &src[3], sizeof(struct pico_ip6)); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } diff --git a/test/examples/multicast_ip6_send.c b/test/examples/multicast_ip6_send.c index bb3e2139..f6c64d9b 100644 --- a/test/examples/multicast_ip6_send.c +++ b/test/examples/multicast_ip6_send.c @@ -95,7 +95,7 @@ void app_mcastsend_ipv6(struct pico_stack *S, char *arg) p = strcat(p + strlen(lport), ",64,10,5,"); /* DAD needs to verify the link address before we can continue */ - while(!pico_ipv6_link_get(stack, &inaddr_link)) { + while (!pico_ipv6_link_get(stack, &inaddr_link)) { pico_stack_tick(stack); usleep(2000); } @@ -103,7 +103,7 @@ void app_mcastsend_ipv6(struct pico_stack *S, char *arg) memcpy(&mreq.mcast_group_addr, &inaddr_mcast, sizeof(struct pico_ip6)); memcpy(&mreq.mcast_link_addr, &inaddr_link, sizeof(struct pico_ip6)); - if(pico_socket_setoption(udpclient_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpclient_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { picoapp_dbg("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); retval = 1; } diff --git a/test/examples/multicast_recv.c b/test/examples/multicast_recv.c index 045a9b2c..96508583 100644 --- a/test/examples/multicast_recv.c +++ b/test/examples/multicast_recv.c @@ -100,58 +100,58 @@ void app_mcastreceive(struct pico_stack *S, char *arg) mreq.mcast_group_addr = mreq_source.mcast_group_addr = inaddr_mcast; mreq.mcast_link_addr = mreq_source.mcast_link_addr = inaddr_link; mreq_source.mcast_source_addr.ip4.addr = long_be(0XAC100101); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_BLOCK_SOURCE, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_BLOCK_SOURCE, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_BLOCK_SOURCE failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_UNBLOCK_SOURCE, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_UNBLOCK_SOURCE, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_UNBLOCK_SOURCE failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_DROP_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } mreq_source.mcast_source_addr.ip4.addr = long_be(0XAC10010A); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_DROP_MEMBERSHIP, &mreq) < 0) { printf("%s: socket_setoption PICO_IP_DROP_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); } mreq_source.mcast_source_addr.ip4.addr = long_be(0XAC100101); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } mreq_source.mcast_group_addr.ip4.addr = long_be(0XE0010101); - if(pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { + if (pico_socket_setoption(udpecho_pas->s, PICO_IP_ADD_SOURCE_MEMBERSHIP, &mreq_source) < 0) { printf("%s: socket_setoption PICO_IP_ADD_SOURCE_MEMBERSHIP: %s\n", __FUNCTION__, strerror(pico_err)); } diff --git a/test/examples/multicast_send.c b/test/examples/multicast_send.c index 92daeac9..c343df22 100644 --- a/test/examples/multicast_send.c +++ b/test/examples/multicast_send.c @@ -97,7 +97,7 @@ void app_mcastsend(struct pico_stack *S, char *arg) mreq.mcast_group_addr = inaddr_mcast; mreq.mcast_link_addr = inaddr_link; - if(pico_socket_setoption(udpclient_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { + if (pico_socket_setoption(udpclient_pas->s, PICO_IP_ADD_MEMBERSHIP, &mreq) < 0) { picoapp_dbg("%s: socket_setoption PICO_IP_ADD_MEMBERSHIP failed: %s\n", __FUNCTION__, strerror(pico_err)); exit(1); } diff --git a/test/examples/noop.c b/test/examples/noop.c index 874c86a0..6275cbc7 100644 --- a/test/examples/noop.c +++ b/test/examples/noop.c @@ -3,7 +3,7 @@ void app_noop(struct pico_stack *S) { printf("-~-~-~-~-~-~-~-~-~ %s: launching PicoTCP NOOP loop -~-~-~-~-~-~-~-~-~\n", __FUNCTION__); - while(1) { + while (1) { pico_stack_tick(S); usleep(2000); } diff --git a/test/examples/slaacv4.c b/test/examples/slaacv4.c index 886511d2..7b383d41 100644 --- a/test/examples/slaacv4.c +++ b/test/examples/slaacv4.c @@ -28,16 +28,13 @@ void slaacv4_cb(struct pico_ip4 *ip, uint8_t code) { char dst[16] = "169.254.22.5"; printf("SLAACV4 CALLBACK ip:0x%X code:%d \n", ip->addr, code); - if (code == 0) - { + if (code == 0) { #ifdef PICO_SUPPORT_PING pico_icmp4_ping(stack, dst, 3, 1000, 5000, 32, ping_callback_slaacv4); #else exit(0); #endif - } - else - { + } else { exit(255); } @@ -57,14 +54,14 @@ void app_slaacv4(struct pico_stack *S, char *arg) while (nxt) { if (nxt) { nxt = cpy_arg(&sdev, nxt); - if(!sdev) { + if (!sdev) { exit(255); } } } dev = pico_get_device(stack, sdev); free(sdev); - if(dev == NULL) { + if (dev == NULL) { printf("%s: error getting device %s: %s\n", __FUNCTION__, dev->name, strerror(pico_err)); exit(255); } diff --git a/test/examples/sntp.c b/test/examples/sntp.c index b7756c2a..360692a8 100644 --- a/test/examples/sntp.c +++ b/test/examples/sntp.c @@ -19,7 +19,7 @@ void sntp_timeout(pico_time __attribute__((unused)) now, void *arg) void cb_synced(pico_err_t status) { - if(status == PICO_ERR_ENETDOWN) { + if (status == PICO_ERR_ENETDOWN) { printf("SNTP: Cannot resolve ntp server name\n"); exit(1); } else if (status == PICO_ERR_ETIMEDOUT) { @@ -47,12 +47,12 @@ void app_sntp(struct pico_stack *S, char *servername) struct pico_timeval tv; stack = S; printf("Starting SNTP query towards %s\n", servername); - if(pico_sntp_gettimeofday(stack, &tv) == 0) + if (pico_sntp_gettimeofday(stack, &tv) == 0) printf("Wrongly successful gettimeofday\n"); else printf("Unsuccessful gettimeofday (not synced)\n"); - if(pico_sntp_sync(stack, servername, &cb_synced) == 0) + if (pico_sntp_sync(stack, servername, &cb_synced) == 0) printf("Successful sync call!\n"); else printf("Error in sync\n"); diff --git a/test/examples/tcpbench.c b/test/examples/tcpbench.c index 683ac8aa..0df247d2 100644 --- a/test/examples/tcpbench.c +++ b/test/examples/tcpbench.c @@ -95,8 +95,7 @@ void cb_tcpbench(uint16_t ev, struct pico_socket *s) printf("tcpbench> Failed to start exit timer, exiting now\n"); exit(1); } - } - else { + } else { printf("tcpbench> ---- Socket Error: '%s'. Was unexpected! Something went wrong.\n", strerror(pico_err)); exit(2); } @@ -126,7 +125,7 @@ void cb_tcpbench(uint16_t ev, struct pico_socket *s) if (tcpbench_time_start == 0) tcpbench_time_start = PICO_TIME_MS(); - } while(tcpbench_w > 0); + } while (tcpbench_w > 0); printf("tcpbench_wr_size = %d \r", tcpbench_wr_size); } else { if (!closed && tcpbench_mode == TCP_BENCH_TX) { @@ -179,7 +178,7 @@ void app_tcpbench(struct pico_stack *S, char *arg) exit(255); } - printf ("+++ Dest is %s\n", dest); + printf("+++ Dest is %s\n", dest); if (nxt) { printf("Next arg: %s\n", nxt); nxt = cpy_arg(&dport, nxt); @@ -309,13 +308,13 @@ void app_tcpbench(struct pico_stack *S, char *arg) free(dport); if (dest) - free (dest); + free(dest); if (mode) - free (mode); + free(mode); if (nagle) - free (nagle); + free(nagle); return; } diff --git a/test/examples/tcpclient.c b/test/examples/tcpclient.c index d77754f8..01726754 100644 --- a/test/examples/tcpclient.c +++ b/test/examples/tcpclient.c @@ -48,7 +48,7 @@ void cb_tcpclient(uint16_t ev, struct pico_socket *s) if (r < 0) exit(5); - } while(r > 0); + } while (r > 0); } if (ev & PICO_SOCK_EV_CONN) { @@ -84,7 +84,7 @@ void cb_tcpclient(uint16_t ev, struct pico_socket *s) if (w < 0) exit(5); } - } while(w > 0); + } while (w > 0); } else { #ifdef INFINITE_TCPTEST w_size = 0; diff --git a/test/examples/tcpecho.c b/test/examples/tcpecho.c index 94cf073a..7a71c7c3 100644 --- a/test/examples/tcpecho.c +++ b/test/examples/tcpecho.c @@ -21,7 +21,7 @@ int send_tcpecho(struct pico_socket *s) len = 0; } } - } while((w > 0) && (pos < len)); + } while ((w > 0) && (pos < len)); } return ww; diff --git a/test/examples/tftp.c b/test/examples/tftp.c index 85c7ac74..cf046cf0 100644 --- a/test/examples/tftp.c +++ b/test/examples/tftp.c @@ -58,11 +58,10 @@ void del_note(struct note_t *note) { struct note_t *prev; - if (note == clipboard) - { + if (note == clipboard) { clipboard = clipboard->next; if (note->filename) - free (note->filename); + free(note->filename); PICO_FREE(note); } else { @@ -70,12 +69,11 @@ void del_note(struct note_t *note) if (prev->next == note) { prev->next = note->next; if (note->filename) - free (note->filename); + free(note->filename); PICO_FREE(note); break; } - } } @@ -400,7 +398,7 @@ struct command_t *parse_arguments_recursive(struct command_t *commands, char *ar default: fprintf(stderr, "Invalid command %s\n", operation); return NULL; - }; + } new_cmd = add_command(commands, *operation, filename, &remote_address); free(operation); diff --git a/test/examples/udp_client.c b/test/examples/udp_client.c index 7e625ddb..eb4e9ec6 100644 --- a/test/examples/udp_client.c +++ b/test/examples/udp_client.c @@ -96,7 +96,7 @@ void cb_udpclient(uint16_t ev, struct pico_socket *s) do { r = pico_socket_recv(s, recvbuf, udpclient_pas->datasize); - } while ( r > 0); + } while (r > 0); free(recvbuf); } @@ -265,22 +265,22 @@ void app_udpclient(struct pico_stack *S, char *arg) /* free strdups */ if (daddr) - free (daddr); + free(daddr); if (lport) - free (lport); + free(lport); if (sport) - free (sport); + free(sport); if (s_datasize) - free (s_datasize); + free(s_datasize); if (s_loops) - free (s_loops); + free(s_loops); if (s_subloops) - free (s_subloops); + free(s_subloops); return; diff --git a/test/examples/udp_echo.c b/test/examples/udp_echo.c index 4a0e8b35..f907e477 100644 --- a/test/examples/udp_echo.c +++ b/test/examples/udp_echo.c @@ -197,16 +197,16 @@ void app_udpecho(struct pico_stack *S, char *arg) /* free strdups */ if (baddr) - free (baddr); + free(baddr); if (lport) - free (lport); + free(lport); if (sport) - free (sport); + free(sport); if (s_datasize) - free (s_datasize); + free(s_datasize); return; diff --git a/test/examples/udpnat.c b/test/examples/udpnat.c index f7ca9e96..3a46d0b3 100644 --- a/test/examples/udpnat.c +++ b/test/examples/udpnat.c @@ -44,7 +44,7 @@ void cb_udpnatclient(uint16_t ev, struct pico_socket *s) if (ev & PICO_SOCK_EV_RD) { do { r = pico_socket_recv(s, recvbuf, 1400); - } while(r > 0); + } while (r > 0); } if (ev == PICO_SOCK_EV_ERR) { @@ -73,8 +73,7 @@ void udpnatclient_open_socket(pico_time __attribute__((unused)) now, void __attr if (!s) exit(1); - if (pico_socket_connect(s, &udpnatclient_inaddr_dst, udpnatclient_port_be) != 0) - { + if (pico_socket_connect(s, &udpnatclient_inaddr_dst, udpnatclient_port_be) != 0) { printf("Error connecting\n"); exit(1); } @@ -129,8 +128,7 @@ void app_udpnatclient(struct pico_stack *S, char *arg) pico_string_to_ipv4(daddr, &inaddr_dst.addr); - if (pico_socket_connect(s, &inaddr_dst, port_be) != 0) - { + if (pico_socket_connect(s, &inaddr_dst, port_be) != 0) { printf("Error binding the port \n"); exit(1); } diff --git a/test/pico_faulty.h b/test/pico_faulty.h index 29226e83..70ecf796 100644 --- a/test/pico_faulty.h +++ b/test/pico_faulty.h @@ -34,7 +34,7 @@ extern uint32_t max_mem; extern uint32_t cur_mem; /* - #define TIME_PRESCALE + #define TIME_PRESCALE */ #define dbg printf diff --git a/test/picoapp.c b/test/picoapp.c index 3f9ca7a9..1b6df284 100644 --- a/test/picoapp.c +++ b/test/picoapp.c @@ -159,17 +159,17 @@ void deferred_exit(pico_time __attribute__((unused)) now, void *arg) #ifdef PICO_SUPPORT_TICKLESS #include "pico_jobs.h" pthread_mutex_t IRQ_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t IRQ_condition = PTHREAD_COND_INITIALIZER; +pthread_cond_t IRQ_condition = PTHREAD_COND_INITIALIZER; struct pico_device *irqdev = NULL; /* Called by main loop when an IRQ occurs */ -static void IRQ_dispatcher(void) +static void IRQ_dispatcher(void) { if (irqdev) pico_schedule_job(irqdev->stack, pico_vde_dsr, irqdev); } -/* Thread body, to emulate IRQ emission from a vde device +/* Thread body, to emulate IRQ emission from a vde device * * The IRQ line is in fact the pthead_cond_t IRQ_condition * @@ -240,7 +240,7 @@ static void usage(char *arg0) exit(255); } -#define IF_APPNAME(x) if(strcmp(x, name) == 0) +#define IF_APPNAME(x) if (strcmp(x, name) == 0) int main(int argc, char **argv) { @@ -277,8 +277,7 @@ int main(int argc, char **argv) app = p + 1; else if (*p == '\0') break; - else - {} /* do nothing */ + else {} /* do nothing */ p++; } @@ -292,17 +291,16 @@ int main(int argc, char **argv) #ifdef PICO_SUPPORT_MM pico_mem_init(128 * 1024); #endif - if (pico_stack_init(&stack) < 0) - { + if (pico_stack_init(&stack) < 0) { fprintf(stderr, "PicoTCP: cannot initialize stack. %s\n", strerror(pico_err)); } /* Parse args */ - while(1) { + while (1) { c = getopt_long(argc, argv, "v:b:t:T:a:r:hl", long_options, &option_idx); if (c < 0) break; - switch(c) { + switch (c) { case 'h': usage(argv[0]); break; @@ -321,7 +319,7 @@ int main(int argc, char **argv) if (!nxt) break; cpy_arg(&gw, nxt); - } while(0); + } while (0); if (!nm) { fprintf(stderr, "Tun: bad configuration...\n"); exit(1); @@ -375,7 +373,7 @@ int main(int argc, char **argv) if (!nxt) break; cpy_arg(&gw, nxt); - } while(0); + } while (0); if (!nm) { fprintf(stderr, "Tun: bad configuration...\n"); exit(1); @@ -465,7 +463,7 @@ int main(int argc, char **argv) nxt = cpy_arg(&loss_out, nxt); if (!nxt) break; } - } while(0); + } while (0); if (!nm && !nm6) { fprintf(stderr, "Vde: bad configuration...\n"); exit(1); @@ -596,7 +594,7 @@ check: if (!name || !area0 || !area1) { if (!nxt) break; nxt = cpy_arg(&sock, nxt); - } while(0); + } while (0); if (!sock) { fprintf(stderr, "Vde: bad configuration...\n"); exit(1); @@ -668,7 +666,7 @@ check: if (!name || !area0 || !area1) { if (!nxt) break; nxt = cpy_arg(&gw, nxt); - } while(0); + } while (0); if (!addr || !nm || !gw) { fprintf(stderr, "--route expects addr:nm:gw:\n"); usage(argv[0]); @@ -702,39 +700,38 @@ check: if (!name || !area0 || !area1) { args = cpy_arg(&name, optarg); printf("+++ NAME: %s ARGS: %s\n", name, args); - IF_APPNAME("udpecho") { + IF_APPNAME ("udpecho") { app_udpecho(stack, args); - } else IF_APPNAME("tcpecho") { + } else IF_APPNAME ("tcpecho") { app_tcpecho(stack, args); - } else IF_APPNAME("udpclient") { + } else IF_APPNAME ("udpclient") { app_udpclient(stack, args); - } else IF_APPNAME("tcpclient") { + } else IF_APPNAME ("tcpclient") { app_tcpclient(stack, args); - } else IF_APPNAME("tcpbench") { + } else IF_APPNAME ("tcpbench") { app_tcpbench(stack, args); - } else IF_APPNAME("natbox") { + } else IF_APPNAME ("natbox") { app_natbox(stack, args); - } else IF_APPNAME("udpdnsclient") { + } else IF_APPNAME ("udpdnsclient") { app_udpdnsclient(stack, args); - } else IF_APPNAME("udpnatclient") { + } else IF_APPNAME ("udpnatclient") { app_udpnatclient(stack, args); - } else IF_APPNAME("mcastsend") { + } else IF_APPNAME ("mcastsend") { #ifndef PICO_SUPPORT_MCAST return 0; #endif app_mcastsend(stack, args); - } else IF_APPNAME("mcastreceive") { + } else IF_APPNAME ("mcastreceive") { #ifndef PICO_SUPPORT_MCAST return 0; #endif app_mcastreceive(stack, args); - } - else IF_APPNAME("mcastsend_ipv6") { + } else IF_APPNAME ("mcastsend_ipv6") { #ifndef PICO_SUPPORT_MCAST return 0; #endif app_mcastsend_ipv6(stack, args); - } else IF_APPNAME("mcastreceive_ipv6") { + } else IF_APPNAME ("mcastreceive_ipv6") { #ifndef PICO_SUPPORT_MCAST return 0; #endif @@ -742,39 +739,39 @@ check: if (!name || !area0 || !area1) { } #ifdef PICO_SUPPORT_PING - else IF_APPNAME("ping") { + else IF_APPNAME ("ping") { app_ping(stack, args); } #endif - else IF_APPNAME("dhcpserver") { + else IF_APPNAME ("dhcpserver") { #ifndef PICO_SUPPORT_DHCPD return 0; #else app_dhcp_server(stack, args); #endif - } else IF_APPNAME("dhcpclient") { + } else IF_APPNAME ("dhcpclient") { #ifndef PICO_SUPPORT_DHCPC return 0; #else app_dhcp_client(stack, args); #endif - } else IF_APPNAME("dns_sd") { + } else IF_APPNAME ("dns_sd") { #ifndef PICO_SUPPORT_DNS_SD return 0; #else app_dns_sd(stack, args, addr4); #endif - } else IF_APPNAME("mdns") { + } else IF_APPNAME ("mdns") { #ifndef PICO_SUPPORT_MDNS return 0; #else app_mdns(stack, args, addr4); #endif #ifdef PICO_SUPPORT_SNTP_CLIENT - } else IF_APPNAME("sntp") { + } else IF_APPNAME ("sntp") { app_sntp(stack, args); #endif - } else IF_APPNAME("bcast") { + } else IF_APPNAME ("bcast") { struct pico_ip4 any = { .addr = 0xFFFFFFFFu }; @@ -784,29 +781,29 @@ check: if (!name || !area0 || !area1) { pico_socket_sendto(s, "abcd", 5u, &bcastAddr, 1000); #ifdef PICO_SUPPORT_TFTP - } else IF_APPNAME("tftp") { + } else IF_APPNAME ("tftp") { app_tftp(stack, args); #endif - } else IF_APPNAME("noop") { + } else IF_APPNAME ("noop") { #ifdef PICO_SUPPORT_OLSR - } else IF_APPNAME("olsr") { + } else IF_APPNAME ("olsr") { dev = pico_get_device(stack, "pic0"); - if(dev) { + if (dev) { pico_olsr_add(dev); } dev = pico_get_device(stack, "pic1"); - if(dev) { + if (dev) { pico_olsr_add(dev); } #endif - } else IF_APPNAME("slaacv4") { + } else IF_APPNAME ("slaacv4") { #ifndef PICO_SUPPORT_SLAACV4 return 0; #else app_slaacv4(stack, args); #endif - } else IF_APPNAME("udp_sendto_test") { + } else IF_APPNAME ("udp_sendto_test") { app_sendto_test(stack, args); } else { fprintf(stderr, "Unknown application %s\n", name); @@ -832,7 +829,7 @@ check: if (!name || !area0 || !area1) { if (uses_vde) { struct timespec idle_time = {0, 0}; printf("%s: launching PicoTCP loop in TICKLESS mode\n", __FUNCTION__); - while(1) { + while (1) { interval = pico_stack_go(stack); if (interval != 0) { int ret; @@ -843,12 +840,11 @@ check: if (!name || !area0 || !area1) { idle_time.tv_nsec -= 1000000000; idle_time.tv_sec++; } - pthread_mutex_lock(&IRQ_mutex); ret = pthread_cond_timedwait(&IRQ_condition, &IRQ_mutex, &idle_time); - //printf("Unlocked PicoTCP! ret = %d was idle=%llu\n", ret, interval); + /*printf("Unlocked PicoTCP! ret = %d was idle=%llu\n", ret, interval); */ pthread_mutex_unlock(&IRQ_mutex); - if (ret == 0) { + if (ret == 0) { IRQ_dispatcher(); } @@ -856,14 +852,14 @@ check: if (!name || !area0 || !area1) { } } } else { - while(1) { + while (1) { interval = pico_stack_go(stack); } } exit(0); #endif printf("-~-~-~-~-~-~-~-~-~ %s: launching PicoTCP loop -~-~-~-~-~-~-~-~-~\n", __FUNCTION__); - while(1) { + while (1) { pico_stack_tick(stack); global_pico_tick = stack->pico_tick; usleep(2000); diff --git a/test/ppp.c b/test/ppp.c index b0510c5a..9021d1d2 100644 --- a/test/ppp.c +++ b/test/ppp.c @@ -95,7 +95,7 @@ int modem_read(struct pico_device *dev, void *data, int len) #ifdef DEBUG_FLOW if (r > 0) { printf(" <<< "); - for(idx = 0; idx < r; idx++) { + for (idx = 0; idx < r; idx++) { printf(" %02x", ((uint8_t*)data)[idx]); } printf("\n"); @@ -111,7 +111,7 @@ int modem_write(struct pico_device *dev, const void *data, int len) int r; #ifdef DEBUG_FLOW printf(" >>> "); - for(idx = 0; idx < len; idx++) { + for (idx = 0; idx < len; idx++) { printf(" %02x", ((uint8_t*)data)[idx]); } printf("\n"); @@ -211,7 +211,7 @@ int main(int argc, const char *argv[]) pico_ppp_connect(ppp); - while(1 < 2) { + while (1 < 2) { pico_stack_tick(ppp->stack); usleep(1000); if (ppp->link_state(ppp) && !ping_on) { diff --git a/test/test_tftp_app_client.c b/test/test_tftp_app_client.c index 8f71cc8a..592c8d43 100644 --- a/test/test_tftp_app_client.c +++ b/test/test_tftp_app_client.c @@ -58,7 +58,7 @@ void start_rx(struct pico_stack *stack, struct pico_tftp_session *session, int * countdown = 1; } - for(; left; left -= countdown) { + for (; left; left -= countdown) { usleep(2000); /* PICO_IDLE(); */ pico_stack_tick(stack); if (countdown) @@ -131,7 +131,7 @@ void start_tx(struct pico_stack *stack, struct pico_tftp_session *session, int * countdown = 1; } - for(; left; left -= countdown) { + for (; left; left -= countdown) { usleep(2000); /* PICO_IDLE(); */ pico_stack_tick(stack); if (countdown) @@ -225,7 +225,7 @@ int main(int argc, char**argv) pico_stack_init(&stack); pico_dev = (struct pico_device *) pico_vde_create(stack, "/tmp/vde_switch", "tap0", macaddr); - if(!pico_dev) { + if (!pico_dev) { fprintf(stderr, "Error creating pico device, got enough privileges? Exiting...\n"); exit(1); } diff --git a/test/tickless.c b/test/tickless.c index 6e9abd9f..520289db 100644 --- a/test/tickless.c +++ b/test/tickless.c @@ -24,7 +24,7 @@ static pico_time deadline; static void panic(void) { - for(;;); + for (;;); } static char buf[MTU] = {}; @@ -40,7 +40,7 @@ static void buf_paint(void) static void send_hdr(struct pico_socket *s) { - struct iperf_hdr hdr = {} ; + struct iperf_hdr hdr = {}; hdr.numThreads = long_be(1); hdr.mPort = long_be(5001); hdr.mAmount = long_be(0xfffffc18); @@ -69,7 +69,7 @@ static void iperf_cb(uint16_t ev, struct pico_socket *s) static void socket_setup(struct pico_stack *stack) { - int yes = 1; + int yes = 1; uint16_t send_port = 0; struct pico_socket *s = NULL; union pico_address dst = { @@ -86,11 +86,11 @@ static void socket_setup(struct pico_stack *stack) int main(void) { long long interval = 0; - char ipaddr[]="192.168.2.150"; + char ipaddr[] = "192.168.2.150"; struct pico_ip4 my_eth_addr, netmask; struct pico_device *tap; - uint8_t mac[6] = {0x00,0x00,0x00,0x12,0x34,0x56}; + uint8_t mac[6] = {0x00, 0x00, 0x00, 0x12, 0x34, 0x56}; struct pico_socket *s; struct pico_stack *stack; @@ -99,25 +99,24 @@ int main(void) tap = (struct pico_device *) pico_tap_create(stack, "tap0"); if (!tap) while (1); - pico_string_to_ipv4(ipaddr, &my_eth_addr.addr); pico_string_to_ipv4("255.255.255.0", &netmask.addr); pico_ipv4_link_add(stack, tap, my_eth_addr, netmask); #ifdef PICO_SUPPORT_IPV6 { - struct pico_ip6 my_addr6, netmask6; - pico_string_to_ipv6("3ffe:501:ffff:100:260:37ff:fe12:3456", my_addr6.addr); - pico_string_to_ipv6("ffff:ffff:ffff:ffff::0", netmask6.addr); - pico_ipv6_link_add(tap, my_addr6, netmask6); + struct pico_ip6 my_addr6, netmask6; + pico_string_to_ipv6("3ffe:501:ffff:100:260:37ff:fe12:3456", my_addr6.addr); + pico_string_to_ipv6("ffff:ffff:ffff:ffff::0", netmask6.addr); + pico_ipv6_link_add(tap, my_addr6, netmask6); } #endif socket_setup(stack); - while(1) { + while (1) { interval = pico_stack_go(stack); if (interval != 0) { -// printf("Interval: %lld\n", interval); +/* printf("Interval: %lld\n", interval); */ pico_tap_WFI(tap, interval); } } diff --git a/test/unit/modunit_pico_6lowpan.c b/test/unit/modunit_pico_6lowpan.c index 24ef4bbd..7ad68e01 100644 --- a/test/unit/modunit_pico_6lowpan.c +++ b/test/unit/modunit_pico_6lowpan.c @@ -42,8 +42,8 @@ #include /******************************************************************************* -* MACROS -******************************************************************************/ + * MACROS + ******************************************************************************/ #define STARTING() \ printf("*********************** STARTING %s ***\n", __func__); \ @@ -108,8 +108,8 @@ dbg_buffer(uint8_t *buf, size_t len) } /******************************************************************************* -* CTX -******************************************************************************/ + * CTX + ******************************************************************************/ START_TEST(tc_compare_prefix) { @@ -124,17 +124,17 @@ START_TEST(tc_compare_prefix) TRYING("With 2 equal prefixes\n"); ret = compare_prefix(a.addr, b.addr, 54); RESULTS(); - FAIL_UNLESS(0 == ret, test, "Prefixes are equal, should've returned 0, ret = %d",ret); + FAIL_UNLESS(0 == ret, test, "Prefixes are equal, should've returned 0, ret = %d", ret); TRYING("With b > a\n"); ret = compare_prefix(a.addr, b.addr, 60); RESULTS(); - FAIL_UNLESS(ret, test, "Prefixes are not equal, shouldn't have returned 0, ret = %d",ret); + FAIL_UNLESS(ret, test, "Prefixes are not equal, shouldn't have returned 0, ret = %d", ret); TRYING("With c > b\n"); ret = compare_prefix(b.addr, c.addr, 64); RESULTS(); - FAIL_UNLESS(ret, test, "Prefixes are not equal, shouldn't have returned 0, ret = %d",ret); + FAIL_UNLESS(ret, test, "Prefixes are not equal, shouldn't have returned 0, ret = %d", ret); ENDING(test); } @@ -205,22 +205,22 @@ START_TEST(tc_ctx_lookup) END_TEST /******************************************************************************* -* IPHC -******************************************************************************/ + * IPHC + ******************************************************************************/ #ifdef PICO_6LOWPAN_IPHC_ENABLED START_TEST(tc_compressor_vtf) { int test = 1, ret = 0; - uint8_t ori_fl[] = {0x64,0x00,0x00,0x00}; - uint8_t ori_dscp[] = {0x62,0x00,0x00,0x00}; - uint8_t ori_notc[] = {0x60,0x0f,0xed,0xcb}; - uint8_t ori_inline[] = {0x6f,0xaf,0xed,0xcb}; + uint8_t ori_fl[] = {0x64, 0x00, 0x00, 0x00}; + uint8_t ori_dscp[] = {0x62, 0x00, 0x00, 0x00}; + uint8_t ori_notc[] = {0x60, 0x0f, 0xed, 0xcb}; + uint8_t ori_inline[] = {0x6f, 0xaf, 0xed, 0xcb}; uint8_t comp_fl[] = {0x40}; uint8_t comp_dscp[] = {0x20}; - uint8_t comp_notc[] = {0x0f,0xed,0xcb}; - uint8_t comp_inline[] = {0xfa,0x0f,0xed,0xcb}; + uint8_t comp_notc[] = {0x0f, 0xed, 0xcb}; + uint8_t comp_inline[] = {0xfa, 0x0f, 0xed, 0xcb}; uint8_t comp[4] = {0, 0, 0, 0}; uint8_t iphc[3] = {0, 0, 0}; @@ -277,19 +277,19 @@ END_TEST START_TEST(tc_decompressor_vtf) { int test = 1, ret = 0; - uint8_t ori_fl[] = {0x64,0x00,0x00,0x00}; - uint8_t ori_dscp[] = {0x62,0x00,0x00,0x00}; - uint8_t ori_notc[] = {0x60,0x0f,0xed,0xcb}; - uint8_t ori_inline[] = {0x6f,0xaf,0xed,0xcb}; + uint8_t ori_fl[] = {0x64, 0x00, 0x00, 0x00}; + uint8_t ori_dscp[] = {0x62, 0x00, 0x00, 0x00}; + uint8_t ori_notc[] = {0x60, 0x0f, 0xed, 0xcb}; + uint8_t ori_inline[] = {0x6f, 0xaf, 0xed, 0xcb}; uint8_t comp_fl[] = {0x40}; uint8_t comp_dscp[] = {0x20}; - uint8_t comp_notc[] = {0x0f,0xed,0xcb}; - uint8_t comp_inline[] = {0xfa,0x0f,0xed,0xcb}; + uint8_t comp_notc[] = {0x0f, 0xed, 0xcb}; + uint8_t comp_inline[] = {0xfa, 0x0f, 0xed, 0xcb}; uint8_t ori[4] = {0}; - uint8_t iphc_fl[3] = {TF_ELIDED_FL, 0,0}; - uint8_t iphc_dscp[3] = {TF_ELIDED_FL, 0,0}; - uint8_t iphc_notc[3] = {TF_ELIDED_DSCP, 0,0}; - uint8_t iphc_inline[3] = {TF_INLINE, 0,0}; + uint8_t iphc_fl[3] = {TF_ELIDED_FL, 0, 0}; + uint8_t iphc_dscp[3] = {TF_ELIDED_FL, 0, 0}; + uint8_t iphc_notc[3] = {TF_ELIDED_DSCP, 0, 0}; + uint8_t iphc_inline[3] = {TF_INLINE, 0, 0}; STARTING(); @@ -466,7 +466,7 @@ START_TEST(tc_compressor_hl) ori = 153; ret = compressor_hl(&ori, &comp, &iphc, NULL, NULL, NULL); RESULTS(); - FAIL_UNLESS(1 == ret, test, "Should've returned 1, ret = %d",ret); + FAIL_UNLESS(1 == ret, test, "Should've returned 1, ret = %d", ret); FAIL_UNLESS(0 == iphc, test, "Should've set IPHC bits correctly"); ENDING(test); @@ -486,21 +486,21 @@ START_TEST(tc_decompressor_hl) TRYING("HL 1 compressed\n"); ret = decompressor_hl(&ori, &comp, &iphc, NULL, NULL, NULL); RESULTS(); - FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d",ret ); + FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d", ret); FAIL_UNLESS(1 == ori, test, "Should filled in correct hop limit"); TRYING("HL 64 compressed\n"); iphc = HL_COMPRESSED_64; ret = decompressor_hl(&ori, &comp, &iphc, NULL, NULL, NULL); RESULTS(); - FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d",ret ); + FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d", ret); FAIL_UNLESS(64 == ori, test, "Should filled in correct hop limit"); TRYING("HL 255 compressed\n"); iphc = HL_COMPRESSED_255; ret = decompressor_hl(&ori, &comp, &iphc, NULL, NULL, NULL); RESULTS(); - FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d",ret ); + FAIL_UNLESS(0 == ret, test, "Should've returned 0, ret = %d", ret); FAIL_UNLESS(255 == ori, test, "Should filled in correct hop limit"); TRYING("HL not compressed\n"); @@ -508,7 +508,7 @@ START_TEST(tc_decompressor_hl) comp = 125; ret = decompressor_hl(&ori, &comp, &iphc, NULL, NULL, NULL); RESULTS(); - FAIL_UNLESS(1 == ret, test, "Should've returned 0, ret = %d",ret ); + FAIL_UNLESS(1 == ret, test, "Should've returned 0, ret = %d", ret); FAIL_UNLESS(125 == ori, test, "Should filled in correct hop limit"); ENDING(test); @@ -523,7 +523,7 @@ START_TEST(tc_addr_comp_mode) struct pico_ip6 local; struct pico_ip6 local2; struct pico_ip6 local3; - union pico_ll_addr addr = { .pan = { .addr.data = {1,2,3,4,5,6,7,8}, .mode = AM_6LOWPAN_SHORT }}; + union pico_ll_addr addr = { .pan = { .addr.data = {1, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_SHORT }}; struct pico_device dev = { .mode = LL_MODE_IEEE802154 }; struct pico_stack *S = NULL; pico_string_to_ipv6("ff00:0:0:0:0:0:e801:100", ip.addr); @@ -605,7 +605,7 @@ START_TEST(tc_addr_comp_prefix) RESULTS(); FAIL_UNLESS(COMP_STATELESS == ret, test, "Should've return COMP_STATELESS, ret = %d", ret); FAIL_UNLESS(!iphc[1], test, "Shouldn't have set any IPHC bytes, iphc = %02X", iphc[1]); - memset(iphc, 0,3); + memset(iphc, 0, 3); TRYING("With a unicast address where there's context available for\n"); ctx_insert(local3, 13, 64, 0, PICO_IPHC_CTX_COMPRESS, dev); @@ -622,12 +622,12 @@ START_TEST(tc_compressor_src) { int test = 1; struct pico_ip6 unspec = {{ 0 }}; - struct pico_ip6 ll_mac = {{0xfe,0x80,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; - struct pico_ip6 ll_nmac_16 = {{0xfe,0x80,0,0,0,0,0,0 ,0,0,0,0xff,0xfe,0,0x12,0x34}}; - struct pico_ip6 ll_nmac_64 = {{0xfe,0x80,0,0,0,0,0,0 ,8,7,6,5,4,3,2,1}}; - struct pico_ip6 ip_ctx = {{0x2a,0xaa,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; - struct pico_ip6 ip_stateless = {{0x2a,0xbb,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; - union pico_ll_addr mac = { .pan = {.addr.data = {3,2,3,4,5,6,7,8}, .mode = AM_6LOWPAN_EXT } }; + struct pico_ip6 ll_mac = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; + struct pico_ip6 ll_nmac_16 = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0x12, 0x34}}; + struct pico_ip6 ll_nmac_64 = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 8, 7, 6, 5, 4, 3, 2, 1}}; + struct pico_ip6 ip_ctx = {{0x2a, 0xaa, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; + struct pico_ip6 ip_stateless = {{0x2a, 0xbb, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; + union pico_ll_addr mac = { .pan = {.addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }}; struct pico_device *dev = NULL; struct pico_stack *S = NULL; int ret = 0; @@ -656,13 +656,13 @@ START_TEST(tc_compressor_src) dev->mode = LL_MODE_ETHERNET; ret = compressor_src(ll_mac.addr, buf, iphc, &mac, NULL, dev); RESULTS(); - FAIL_UNLESS(-1 == ret, test, "Should've indicated error, invalid device, ret = %d",ret); + FAIL_UNLESS(-1 == ret, test, "Should've indicated error, invalid device, ret = %d", ret); TRYING("With mac derived address, should elide fully\n"); dev->mode = LL_MODE_IEEE802154; ret = compressor_src(ll_mac.addr, buf, iphc, &mac, NULL, dev); OUTPUT(); - dbg_buffer(iphc,3); + dbg_buffer(iphc, 3); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); FAIL_UNLESS(0 == ret, test, "Should've returned compressed size of 0, ret = %d", ret); @@ -672,7 +672,7 @@ START_TEST(tc_compressor_src) TRYING("With non mac derived 16-bit derivable address\n"); ret = compressor_src(ll_nmac_16.addr, buf, iphc, &mac, NULL, dev); OUTPUT(); - dbg_buffer(iphc,3); + dbg_buffer(iphc, 3); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); FAIL_UNLESS(2 == ret, test, "Should've returned compressed size of 2, ret = %d", ret); @@ -683,7 +683,7 @@ START_TEST(tc_compressor_src) TRYING("With non mac derived 64-bit derivable address\n"); ret = compressor_src(ll_nmac_64.addr, buf, iphc, &mac, NULL, dev); OUTPUT(); - dbg_buffer(iphc,3); + dbg_buffer(iphc, 3); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); FAIL_UNLESS(8 == ret, test, "Should've returned compressed size of 8, ret = %d", ret); @@ -709,7 +709,7 @@ START_TEST(tc_compressor_src) dbg_buffer(iphc, 3); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); - FAIL_UNLESS(PICO_SIZE_IP6 == ret, test, "Should've returned compressed size of 16, ret = %d",ret); + FAIL_UNLESS(PICO_SIZE_IP6 == ret, test, "Should've returned compressed size of 16, ret = %d", ret); FAIL_UNLESS((iphc[1] & SRC_STATEFUL) == 0, test, "Shouldn't have set SAC"); FAIL_UNLESS((iphc[1] & SRC_COMPRESSED) == 0, test, "Should've set SAM to '00', iphc = %02X", iphc[1]); FAIL_UNLESS(0 == memcmp(buf, ip_stateless.addr, PICO_SIZE_IP6), test, "Should've copied the source address inline"); @@ -723,42 +723,42 @@ START_TEST(tc_decompressor_src) int test = 1; int ret = 0; - union pico_ll_addr mac = { .pan = {.addr.data = {3,2,3,4,5,6,7,8}, .mode = AM_6LOWPAN_EXT } }; + union pico_ll_addr mac = { .pan = {.addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }}; struct pico_device *dev = NULL; struct pico_stack *S = NULL; /* Stateless compression */ uint8_t iphc1[] = {0x00, 0x00, 0x00}; uint8_t buf1[] = {0x2a, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; - struct pico_ip6 ip1 = {{0x2a,0xbb,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; + struct pico_ip6 ip1 = {{0x2a, 0xbb, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; /* With context */ uint8_t iphc2[] = {0x00, 0xf0, 0xd0}; uint8_t buf2[] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - struct pico_ip6 ip2 = {{0x2a,0xaa,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; + struct pico_ip6 ip2 = {{0x2a, 0xaa, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; /* Link-local non-mac 64-bit derivable address */ uint8_t iphc4[] = {0x00, 0x10, 0x00}; uint8_t buf4[] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - struct pico_ip6 ip4 = {{0xfe,0x80,0,0,0,0,0,0 ,8,7,6,5,4,3,2,1}}; + struct pico_ip6 ip4 = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 8, 7, 6, 5, 4, 3, 2, 1}}; /* Link-local non-mac 16-bit derivable address */ uint8_t iphc3[] = {0x00, 0x20, 0x00}; uint8_t buf3[] = {0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - struct pico_ip6 ip3 = {{0xfe,0x80,0,0,0,0,0,0 ,0,0,0,0xff,0xfe,0,0x12,0x34}}; + struct pico_ip6 ip3 = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0x12, 0x34}}; /* Link-local mac derivable address */ uint8_t iphc5[] = {0x00, 0x30, 0x00}; uint8_t buf5[] = {0}; - struct pico_ip6 ip5 = {{0xfe,0x80,0,0,0,0,0,0 ,1,2,3,4,5,6,7,8}}; + struct pico_ip6 ip5 = {{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}}; /* Context non-mac 16-bit derivable address */ uint8_t iphc6[] = {0x00, 0xE0, 0xd0}; uint8_t buf6[] = {0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - struct pico_ip6 ip6 = {{0x2a,0xaa,0,0,0,0,0,0 ,0,0,0,0xff,0xfe,0,0x12,0x34}}; + struct pico_ip6 ip6 = {{0x2a, 0xaa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0x12, 0x34}}; uint8_t buf[PICO_SIZE_IP6] = { 0 }; - + pico_stack_init(&S); dev = pico_null_create(S, "dummy"); @@ -830,19 +830,19 @@ START_TEST(tc_compressor_dst) int test = 1; int ret = 0; - union pico_ll_addr mac = { .pan = {.addr.data = {3,2,3,4,5,6,7,8}, .mode = AM_6LOWPAN_EXT } }; + union pico_ll_addr mac = { .pan = {.addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }}; struct pico_device dev; /* Multicast 48-bit */ - struct pico_ip6 mcast1 = {{0xff,0x12,0,0,0,0,0,0 ,0,0,0,5,4,3,2,1}}; - uint8_t buf1[] = {0x12,5,4,3,2,1}; + struct pico_ip6 mcast1 = {{0xff, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 3, 2, 1}}; + uint8_t buf1[] = {0x12, 5, 4, 3, 2, 1}; /* Multicast 32-bit */ - struct pico_ip6 mcast2 = {{0xFF,0x34,0,0,0,0,0,0 ,0,0,0,0,0,1,2,3}}; - uint8_t buf2[] = {0x34,1,2,3}; + struct pico_ip6 mcast2 = {{0xFF, 0x34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}}; + uint8_t buf2[] = {0x34, 1, 2, 3}; /* Multicast 8-bit */ - struct pico_ip6 mcast3 = {{0xFF,0x02,0,0,0,0,0,0 ,0,0,0,0,0,0,0,5}}; + struct pico_ip6 mcast3 = {{0xFF, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5}}; uint8_t buf3 = 5; uint8_t iphc[3] = { 0 }; @@ -896,22 +896,22 @@ START_TEST(tc_decompressor_dst) int test = 1; int ret = 0; - union pico_ll_addr mac = { .pan = {.addr.data = {3,2,3,4,5,6,7,8}, .mode = AM_6LOWPAN_EXT } }; + union pico_ll_addr mac = { .pan = {.addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }}; struct pico_device dev; /* Multicast 48-bit */ uint8_t iphc1[3] = {0x00, 0x09, 0x00}; - struct pico_ip6 mcast1 = {{0xff,0x12,0,0,0,0,0,0 ,0,0,0,5,4,3,2,1}}; - uint8_t buf1[] = {0x12,5,4,3,2,1}; + struct pico_ip6 mcast1 = {{0xff, 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 4, 3, 2, 1}}; + uint8_t buf1[] = {0x12, 5, 4, 3, 2, 1}; /* Multicast 32-bit */ uint8_t iphc2[3] = {0x00, 0x0a, 0x00}; - struct pico_ip6 mcast2 = {{0xFF,0x34,0,0,0,0,0,0 ,0,0,0,0,0,1,2,3}}; - uint8_t buf2[] = {0x34,1,2,3}; + struct pico_ip6 mcast2 = {{0xFF, 0x34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}}; + uint8_t buf2[] = {0x34, 1, 2, 3}; /* Multicast 8-bit */ uint8_t iphc3[3] = {0x00, 0x0b, 0x00}; - struct pico_ip6 mcast3 = {{0xFF,0x02,0,0,0,0,0,0 ,0,0,0,0,0,0,0,5}}; + struct pico_ip6 mcast3 = {{0xFF, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5}}; uint8_t buf3[] = {5}; uint8_t buf[PICO_SIZE_IP6] = { 0 }; @@ -920,7 +920,7 @@ START_TEST(tc_decompressor_dst) STARTING(); TRYING("48-bit compressed address\n"); - ret = decompressor_dst(buf,buf1,iphc1,NULL, &mac,&dev); + ret = decompressor_dst(buf, buf1, iphc1, NULL, &mac, &dev); OUTPUT(); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); @@ -928,15 +928,15 @@ START_TEST(tc_decompressor_dst) FAIL_UNLESS(0 == memcmp(mcast1.addr, buf, PICO_SIZE_IP6), test, "Should've correctly decompressed the mcast address"); TRYING("32-bit compressed address\n"); - ret = decompressor_dst(buf,buf2,iphc2,NULL, &mac,&dev); + ret = decompressor_dst(buf, buf2, iphc2, NULL, &mac, &dev); OUTPUT(); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); - FAIL_UNLESS(4 == ret, test, "Should've returned compressed length of 4, ret = %d",ret); + FAIL_UNLESS(4 == ret, test, "Should've returned compressed length of 4, ret = %d", ret); FAIL_UNLESS(0 == memcmp(mcast2.addr, buf, PICO_SIZE_IP6), test, "Should've correctly decompressed 32-bit mcast address"); TRYING("8-bit compressed address\n"); - ret = decompressor_dst(buf,buf3, iphc3, NULL, &mac, &dev); + ret = decompressor_dst(buf, buf3, iphc3, NULL, &mac, &dev); OUTPUT(); dbg_buffer(buf, PICO_SIZE_IP6); RESULTS(); @@ -947,34 +947,34 @@ START_TEST(tc_decompressor_dst) } END_TEST static const unsigned char ipv6_frame[61] = { -0x60, 0x00, 0x00, 0x00, 0x00, 0x15, 0x3c, 0xff, /* `.....<. */ -0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x02, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00, /* ........ */ -0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ -0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x65, 0x63, /* ......ec */ -0x11, 0x00, 0x1e, 0x00, 0x01, 0x02, 0x00, 0x00, /* ........ */ -0x4d, 0x4c, 0x4d, 0x4c, 0x00, 0x0d, 0x7b, 0x50, /* MLML..{P */ -0xff, 0x00, 0x01, 0x01, 0x08 /* ..... */ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x15, 0x3c, 0xff, /* `.....<. */ + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ + 0x02, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00, /* ........ */ + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x65, 0x63, /* ......ec */ + 0x11, 0x00, 0x1e, 0x00, 0x01, 0x02, 0x00, 0x00, /* ........ */ + 0x4d, 0x4c, 0x4d, 0x4c, 0x00, 0x0d, 0x7b, 0x50, /* MLML..{P */ + 0xff, 0x00, 0x01, 0x01, 0x08 /* ..... */ }; static const unsigned char lowpan_frame[18] = { -0x7f, 0x33, 0xe7, 0x02, 0x1e, 0x00, 0xf0, -0x4d, 0x4c, 0x4d, 0x4c, 0x7b, 0x50, 0xff, 0x00, -0x01, 0x01, 0x08 + 0x7f, 0x33, 0xe7, 0x02, 0x1e, 0x00, 0xf0, + 0x4d, 0x4c, 0x4d, 0x4c, 0x7b, 0x50, 0xff, 0x00, + 0x01, 0x01, 0x08 }; static const unsigned char comp_frame[22] = { -0x7f, 0x33, 0xe7, 0x06, 0x1e, 0x00, 0x01, 0x02, -0x00, 0x00, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x7b, -0x50, 0xff, 0x00, 0x01, 0x01, 0x08 + 0x7f, 0x33, 0xe7, 0x06, 0x1e, 0x00, 0x01, 0x02, + 0x00, 0x00, 0xf0, 0x4d, 0x4c, 0x4d, 0x4c, 0x7b, + 0x50, 0xff, 0x00, 0x01, 0x01, 0x08 }; START_TEST(tc_compressor_iphc) { int test = 1; struct pico_frame *f = pico_frame_alloc(61); - union pico_ll_addr src = { .pan = {.addr.data = {0x00,0x80,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_EXT } }; - union pico_ll_addr dst = { .pan = {.addr.data = {0x65,0x63,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_SHORT } }; + union pico_ll_addr src = { .pan = {.addr.data = {0x00, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_EXT }}; + union pico_ll_addr dst = { .pan = {.addr.data = {0x65, 0x63, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_SHORT }}; int compressed_len = 0; struct pico_device *dev = NULL; struct pico_stack *S = NULL; @@ -1013,24 +1013,25 @@ START_TEST(tc_decompressor_iphc) { int test = 1; struct pico_frame *f = pico_frame_alloc(2); - union pico_ll_addr src = { .pan = {.addr.data = {0x00,0x80,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_EXT } }; - union pico_ll_addr dst = { .pan = {.addr.data = {0x65,0x63,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_SHORT } }; + union pico_ll_addr src = { .pan = {.addr.data = {0x00, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_EXT }}; + union pico_ll_addr dst = { .pan = {.addr.data = {0x65, 0x63, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_SHORT }}; struct pico_device *dev = NULL; struct pico_stack *S = NULL; int compressed_len = 0; uint8_t *buf = NULL; uint8_t hdr[40] = { - 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* `.....<. */ - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ - 0x02, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00, /* ........ */ - 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ - 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x65, 0x63 }; + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* `.....<. */ + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ + 0x02, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00, /* ........ */ + 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */ + 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x65, 0x63 + }; pico_stack_init(&S); dev = pico_null_create(S, "dummy"); dev->mode = LL_MODE_IEEE802154; - + memcpy(f->buffer, lowpan_frame, 2); f->net_hdr = f->buffer; f->dev = dev; @@ -1257,8 +1258,8 @@ START_TEST(tc_pico_iphc_compress) { int test = 1; struct pico_frame *f = pico_frame_alloc(61); - union pico_ll_addr src = { .pan = {.addr.data = {0x00,0x80,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_EXT } }; - union pico_ll_addr dst = { .pan = {.addr.data = {0x65,0x63,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_SHORT } }; + union pico_ll_addr src = { .pan = {.addr.data = {0x00, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_EXT }}; + union pico_ll_addr dst = { .pan = {.addr.data = {0x65, 0x63, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_SHORT }}; struct pico_device *dev = NULL; struct pico_stack *S = NULL; struct pico_frame *new = NULL; @@ -1267,7 +1268,7 @@ START_TEST(tc_pico_iphc_compress) dev = pico_null_create(S, "dummy"); dev->mode = LL_MODE_IEEE802154; - + memcpy(f->buffer, ipv6_frame, 61); f->net_hdr = f->buffer; f->net_len = 48; @@ -1297,8 +1298,8 @@ START_TEST(tc_pico_iphc_decompress) { int test = 0; struct pico_frame *f = pico_frame_alloc(61); - union pico_ll_addr src = { .pan = {.addr.data = {0x00,0x80,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_EXT } }; - union pico_ll_addr dst = { .pan = {.addr.data = {0x65,0x63,0xe1,0x03,0x00,0x00,0x9d,0x00}, .mode = AM_6LOWPAN_SHORT } }; + union pico_ll_addr src = { .pan = {.addr.data = {0x00, 0x80, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_EXT }}; + union pico_ll_addr dst = { .pan = {.addr.data = {0x65, 0x63, 0xe1, 0x03, 0x00, 0x00, 0x9d, 0x00}, .mode = AM_6LOWPAN_SHORT }}; struct pico_device *dev = NULL; struct pico_stack *S = NULL; struct pico_frame *new = NULL; @@ -1340,7 +1341,8 @@ static int rx_called = 0; static int tx_called = 0; static uint8_t tx_len = 0; -int pico_datalink_send(struct pico_frame *f) { +int pico_datalink_send(struct pico_frame *f) +{ dbg("Datalink_send called!\n"); if (++tx_called == 2) { memcpy(tx, f->start, f->len); @@ -1549,7 +1551,7 @@ START_TEST(tc_tx_rx) app_ping(S, (char *)arg); printf("%s: launching PicoTCP loop\n", __FUNCTION__); - while(!rx) { + while (!rx) { pico_stack_tick(S); usleep(2000); } @@ -1602,9 +1604,9 @@ static Suite *pico_suite(void) tcase_add_test(TCase_compare_prefix, tc_compare_prefix); suite_add_tcase(s, TCase_compare_prefix); - tcase_add_test(TCase_compare_6lowpan_ctx ,tc_compare_6lowpan_ctx); + tcase_add_test(TCase_compare_6lowpan_ctx, tc_compare_6lowpan_ctx); suite_add_tcase(s, TCase_compare_6lowpan_ctx); - tcase_add_test(TCase_ctx_lookup ,tc_ctx_lookup); + tcase_add_test(TCase_ctx_lookup, tc_ctx_lookup); suite_add_tcase(s, TCase_ctx_lookup); /******************************************************************************* @@ -1653,7 +1655,7 @@ static Suite *pico_suite(void) suite_add_tcase(s, TCase_pico_iphc_decompress); #endif - tcase_add_test(TCase_tx_rx ,tc_tx_rx); + tcase_add_test(TCase_tx_rx, tc_tx_rx); suite_add_tcase(s, TCase_tx_rx); return s; diff --git a/test/unit/modunit_pico_802154.c b/test/unit/modunit_pico_802154.c index 65846f29..91f95d6b 100644 --- a/test/unit/modunit_pico_802154.c +++ b/test/unit/modunit_pico_802154.c @@ -57,7 +57,7 @@ static void dbg_addr_ext(const char *msg, uint8_t a[SIZE_6LOWPAN_EXT]) { DBG("%s: (64-bit extended address): ", msg); DBG("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", - a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]); + a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); } /******************************************************************************* @@ -72,7 +72,7 @@ START_TEST(tc_swap) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("With a = %d and b = %d\n", a, b); pico_swap(&a, &b); CHECKING(test); @@ -86,14 +86,14 @@ START_TEST(tc_802154_to_ietf) { int test = 1; struct pico_802154 a = { - .addr.data = { 1,2,3,4,5,6,7,8 }, + .addr.data = { 1, 2, 3, 4, 5, 6, 7, 8 }, .mode = AM_6LOWPAN_EXT }; - uint8_t buf[] = {8,7,6,5,4,3,2,1}; + uint8_t buf[] = {8, 7, 6, 5, 4, 3, 2, 1}; STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("Extended address mode\n"); addr_802154_to_ietf(&a); dbg_addr_ext("After", a.addr.data); @@ -101,7 +101,7 @@ START_TEST(tc_802154_to_ietf) FAIL_UNLESS(0 == memcmp(a.addr.data, buf, SIZE_6LOWPAN_EXT), "Failed converting to IETF endianness\n"); - // TEST 2 + /* TEST 2 */ TRYING("Short address mode\n"); a.mode = AM_6LOWPAN_SHORT; addr_802154_to_ietf(&a); @@ -110,7 +110,7 @@ START_TEST(tc_802154_to_ietf) FAIL_UNLESS(a.addr._short.addr == short_be(0x0708), "Failed converting short to IETF endianness\n"); - // TEST 3 + /* TEST 3 */ TRYING("Wrong address mode\n"); a.mode = AM_6LOWPAN_NONE; addr_802154_to_ietf(&a); @@ -130,14 +130,14 @@ START_TEST(tc_802154_ll_src) { int test = 1; struct pico_ip6 ip = { - .addr = {0,0,0,0,0,0,0,0, 3,2,3,4,5,6,7,8} + .addr = {0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 3, 4, 5, 6, 7, 8} }; struct pico_ip6 ip2 = { - .addr = {0,0,0,0,0,0,0,0, 0,0,0,0xff,0xfe,0,0x12,0x34} + .addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0x12, 0x34} }; struct pico_6lowpan_info info = { .addr_short.addr = short_be(0x1234), - .addr_ext.addr = {3,2,3,4,5,6,7,8} + .addr_ext.addr = {3, 2, 3, 4, 5, 6, 7, 8} }; struct pico_device dev; struct pico_802154 addr; @@ -151,7 +151,7 @@ START_TEST(tc_802154_ll_src) f->dev = &dev; dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; - // TEST 3 + /* TEST 3 */ TRYING("With an IPv6 address that is derived from MAC short address\n"); info.addr_short.addr = short_be(0x1234); hdr->src = ip2; @@ -163,7 +163,7 @@ START_TEST(tc_802154_ll_src) FAIL_UNLESS(short_be(0x1234) == addr.addr._short.addr, "Should've copied the short address from the device\n"); - // TEST 4 + /* TEST 4 */ TRYING("With an IPv6 address that is derived from MAC extended address\n"); ip.addr[8] = 1; hdr->src = ip; @@ -189,7 +189,7 @@ START_TEST(tc_802154_ll_dst) struct pico_frame *f = pico_frame_alloc(sizeof(struct pico_ipv6_hdr)); struct pico_ipv6_hdr *hdr = (struct pico_ipv6_hdr *)f->buffer; struct pico_device dev; - uint8_t buf[] = {3,2,3,4,5,6,7,8}; + uint8_t buf[] = {3, 2, 3, 4, 5, 6, 7, 8}; pico_string_to_ipv6("ff00:0:0:0:0:0:e801:100", ip.addr); pico_string_to_ipv6("fe80:0:0:0:0102:0304:0506:0708", local.addr); pico_string_to_ipv6("fe80:0:0:0:0:0ff:fe00:1234", local2.addr); @@ -200,7 +200,7 @@ START_TEST(tc_802154_ll_dst) f->dev = &dev; dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; - // TEST 1 + /* TEST 1 */ TRYING("With a MCAST IPv6 address, should return 0xFFFF\n"); hdr->dst = ip; addr = addr_802154_ll_dst(f); @@ -211,7 +211,7 @@ START_TEST(tc_802154_ll_dst) FAIL_UNLESS(short_be(ADDR_802154_BCAST) == addr.addr._short.addr, "Should've set address to BCAST\n"); - // TEST 2 + /* TEST 2 */ TRYING("With a link local IPv6 address derived from an extended L2 address\n"); hdr->dst = local; addr = addr_802154_ll_dst(f); @@ -223,7 +223,7 @@ START_TEST(tc_802154_ll_dst) FAIL_UNLESS(0 == memcmp(buf, addr.addr._ext.addr, SIZE_6LOWPAN_EXT), "Should've copied the extended address from the IP address\n"); - // TEST 3 + /* TEST 3 */ TRYING("With a link local IPv6 address derived from a short L2 address\n"); hdr->dst = local2; addr = addr_802154_ll_dst(f); @@ -246,22 +246,22 @@ END_TEST /* Frame (123 bytes) */ static uint8_t pkt[] = { -0x41, 0xcc, 0xa6, 0xff, 0xff, 0x8a, /* A..... */ -0x18, 0x00, 0xff, 0xff, 0xda, 0x1c, 0x00, 0x88, /* ........ */ -0x18, 0x00, 0xff, 0xff, 0xda, 0x1c, 0x00, 0xc1, /* ........ */ -0x09, 0x00, 0x02, 0x42, 0xfa, 0x40, 0x04, 0x01, /* ...B.@.. */ -0xf0, 0xb1, 0x01, 0x06, 0x6f, 0xaf, 0x48, 0x65, /* ....o.He */ -0x6c, 0x6c, 0x6f, 0x20, 0x30, 0x30, 0x36, 0x20, /* llo 006 */ -0x30, 0x78, 0x46, 0x46, 0x33, 0x43, 0x0a, 0x00, /* 0xFF3C.. */ -0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, /* ........ */ -0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, /* ...... ! */ -0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, /* "#$%&'() */ -0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, /* *+,-./01 */ -0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, /* 23456789 */ -0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, /* :;<=>?@A */ -0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, /* BCDEFGHI */ -0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, /* JKLMNOPQ */ -0x52, 0x53, 0x54, 0x68, 0x79 /* RSThy */ + 0x41, 0xcc, 0xa6, 0xff, 0xff, 0x8a, /* A..... */ + 0x18, 0x00, 0xff, 0xff, 0xda, 0x1c, 0x00, 0x88, /* ........ */ + 0x18, 0x00, 0xff, 0xff, 0xda, 0x1c, 0x00, 0xc1, /* ........ */ + 0x09, 0x00, 0x02, 0x42, 0xfa, 0x40, 0x04, 0x01, /* ...B.@.. */ + 0xf0, 0xb1, 0x01, 0x06, 0x6f, 0xaf, 0x48, 0x65, /* ....o.He */ + 0x6c, 0x6c, 0x6f, 0x20, 0x30, 0x30, 0x36, 0x20, /* llo 006 */ + 0x30, 0x78, 0x46, 0x46, 0x33, 0x43, 0x0a, 0x00, /* 0xFF3C.. */ + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, /* ........ */ + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, /* ...... ! */ + 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, /* "#$%&'() */ + 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, /* *+,-./01 */ + 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, /* 23456789 */ + 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, /* :;<=>?@A */ + 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, /* BCDEFGHI */ + 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, /* JKLMNOPQ */ + 0x52, 0x53, 0x54, 0x68, 0x79 /* RSThy */ }; START_TEST(tc_dst_am) @@ -271,7 +271,7 @@ START_TEST(tc_dst_am) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("Trying to determine AM of destination addr from buffer \n"); ret = dst_am((struct pico_802154_hdr *)pkt); DBG("ret = %d\n", ret); @@ -290,7 +290,7 @@ START_TEST(tc_src_am) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("Trying to determine AM of source addr from buffer \n"); ret = src_am((struct pico_802154_hdr *)pkt); DBG("ret = %d\n", ret); @@ -309,7 +309,7 @@ START_TEST(tc_802154_hdr_len) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("Trying to determine length of the header from buffer\n"); ret = frame_802154_hdr_len((struct pico_802154_hdr *)pkt); DBG("ret = %d\n", ret); @@ -331,7 +331,7 @@ START_TEST(tc_802154_src) hdr = (struct pico_802154_hdr *)pkt; - // TEST 1 + /* TEST 1 */ TRYING("To receive the source address from a mapped buffer\n"); addr = frame_802154_src(hdr); CHECKING(test); @@ -355,7 +355,7 @@ START_TEST(tc_802154_dst) STARTING(); hdr = (struct pico_802154_hdr *)pkt; - // TEST 1 + /* TEST 1 */ TRYING("To receive the source address from a mapped buffer\n"); addr = frame_802154_dst(hdr); CHECKING(test); @@ -386,7 +386,7 @@ START_TEST(tc_802154_format) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("To format a frame like sample capture\n"); frame_802154_format(buf, 166, FCF_INTRA_PAN, FCF_NO_ACK_REQ, FCF_NO_SEC, pan, src, dst); @@ -415,7 +415,7 @@ START_TEST(tc_802154_process_out) int ret = 0; int test = 1; struct pico_802154 src = { - .addr.data = {3,2,3,4,5,6,7,8}, + .addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }; struct pico_802154 dst = { @@ -425,13 +425,13 @@ START_TEST(tc_802154_process_out) struct pico_frame *f = pico_frame_alloc(0); struct pico_6lowpan_info info = { .addr_short.addr = short_be(0x1234), - .addr_ext.addr = {3,2,3,4,5,6,7,8}, + .addr_ext.addr = {3, 2, 3, 4, 5, 6, 7, 8}, .pan_id.addr = short_be(0x1234) }; struct pico_device dev; - uint8_t buf[] = {0x41,0xcc,0x00,0x34,0x12,0x8a,0x18,0x00, - 0xff,0xff,0xda,0x1c,0x00,0x08,0x07,0x06, - 0x05,0x04,0x03,0x02,0x03}; + uint8_t buf[] = {0x41, 0xcc, 0x00, 0x34, 0x12, 0x8a, 0x18, 0x00, + 0xff, 0xff, 0xda, 0x1c, 0x00, 0x08, 0x07, 0x06, + 0x05, 0x04, 0x03, 0x02, 0x03}; dev.eth = (struct pico_ethdev *)&info; dev.q_out = PICO_ZALLOC(sizeof(struct pico_queue)); f->dev = &dev; @@ -439,7 +439,7 @@ START_TEST(tc_802154_process_out) STARTING(); - // TEST 1 + /* TEST 1 */ TRYING("Trying with bare frame\n"); f->src.pan = src; f->dst.pan = dst; @@ -469,7 +469,7 @@ START_TEST(tc_802154_process_in) int ret = 0; int test = 1; struct pico_802154 src = { - .addr.data = {3,2,3,4,5,6,7,8}, + .addr.data = {3, 2, 3, 4, 5, 6, 7, 8}, .mode = AM_6LOWPAN_EXT }; struct pico_802154 dst = { @@ -477,9 +477,9 @@ START_TEST(tc_802154_process_in) .mode = AM_6LOWPAN_EXT }; struct pico_frame *f = pico_frame_alloc(22); - uint8_t buf[] = {0x41,0xcc,0x00,0x34,0x12,0x8a,0x18,0x00, - 0xff,0xff,0xda,0x1c,0x00,0x08,0x07,0x06, - 0x05,0x04,0x03,0x02,0x03,0x60}; + uint8_t buf[] = {0x41, 0xcc, 0x00, 0x34, 0x12, 0x8a, 0x18, 0x00, + 0xff, 0xff, 0xda, 0x1c, 0x00, 0x08, 0x07, 0x06, + 0x05, 0x04, 0x03, 0x02, 0x03, 0x60}; memcpy(f->buffer, buf, 22); f->src.pan = src; f->dst.pan = dst; diff --git a/test/unit/modunit_pico_aodv.c b/test/unit/modunit_pico_aodv.c index 2461fe1f..cd09f3bb 100644 --- a/test/unit/modunit_pico_aodv.c +++ b/test/unit/modunit_pico_aodv.c @@ -218,7 +218,7 @@ int pico_socket_sendto(struct pico_socket *s, const void *buf, const int len, vo printf("Sendto called!\n"); pico_socket_sendto_called++; fail_if(remote_port != short_be(PICO_AODV_PORT)); - fail_if (s != s->stack->aodv_socket); + fail_if(s != s->stack->aodv_socket); fail_if(pkt[0] > 4); fail_if(pkt[0] < 1); sent_pkt_type = pkt[0]; @@ -226,8 +226,7 @@ int pico_socket_sendto(struct pico_socket *s, const void *buf, const int len, vo if (sent_pkt_type == AODV_TYPE_RREQ) { /* struct pico_aodv_rreq *req = (struct pico_aodv_rreq *)(uintptr_t)buf; */ fail_if(len != sizeof(struct pico_aodv_rreq)); - } - else if (sent_pkt_type == AODV_TYPE_RREP) { + } else if (sent_pkt_type == AODV_TYPE_RREP) { struct pico_aodv_rrep *rep = (struct pico_aodv_rrep *)(uintptr_t)buf; fail_if(len != sizeof(struct pico_aodv_rrep)); fail_if(rep->dest != 0x11111111); diff --git a/test/unit/modunit_pico_dev_ppp.c b/test/unit/modunit_pico_dev_ppp.c index faa1ce5e..8aef4dfe 100644 --- a/test/unit/modunit_pico_dev_ppp.c +++ b/test/unit/modunit_pico_dev_ppp.c @@ -216,7 +216,7 @@ START_TEST(tc_ppp_fcs_finish) { uint16_t fcs = 36440; fcs = ppp_fcs_finish(fcs); - fail_if (fcs != 29095); + fail_if(fcs != 29095); } END_TEST START_TEST(tc_ppp_fcs_start) @@ -607,13 +607,13 @@ START_TEST(tc_pap_process_in) ppp_auth_ev = 0; hdr.code = PAP_AUTH_ACK; pap_process_in(&_ppp, (uint8_t *)&hdr, sizeof(hdr)); - fail_if (ppp_auth_ev != PPP_AUTH_EVENT_RAA); + fail_if(ppp_auth_ev != PPP_AUTH_EVENT_RAA); /* Receive FAILURE (RAN) */ ppp_auth_ev = 0; hdr.code = PAP_AUTH_NAK; pap_process_in(&_ppp, (uint8_t *)&hdr, sizeof(hdr)); - fail_if (ppp_auth_ev != PPP_AUTH_EVENT_RAN); + fail_if(ppp_auth_ev != PPP_AUTH_EVENT_RAN); } END_TEST START_TEST(tc_chap_process_in) @@ -626,19 +626,19 @@ START_TEST(tc_chap_process_in) _ppp.auth = 0xc223; hdr.code = CHAP_CHALLENGE; chap_process_in(&_ppp, (uint8_t *)&hdr, sizeof(hdr)); - fail_if (ppp_auth_ev != PPP_AUTH_EVENT_RAC); + fail_if(ppp_auth_ev != PPP_AUTH_EVENT_RAC); /* Receive SUCCESS (RAA) */ ppp_auth_ev = 0; hdr.code = CHAP_SUCCESS; chap_process_in(&_ppp, (uint8_t *)&hdr, sizeof(hdr)); - fail_if (ppp_auth_ev != PPP_AUTH_EVENT_RAA); + fail_if(ppp_auth_ev != PPP_AUTH_EVENT_RAA); /* Receive FAILURE (RAN) */ ppp_auth_ev = 0; hdr.code = CHAP_FAILURE; chap_process_in(&_ppp, (uint8_t *)&hdr, sizeof(hdr)); - fail_if (ppp_auth_ev != PPP_AUTH_EVENT_RAN); + fail_if(ppp_auth_ev != PPP_AUTH_EVENT_RAN); } END_TEST @@ -751,7 +751,6 @@ START_TEST(tc_ipcp_process_in) /* TODO: test this: static void ipcp_process_in(struct pico_device_ppp *ppp, uint8_t *pkt, uint32_t len) */ uint8_t req[sizeof(struct pico_ipcp_hdr) + 5 * IPCP_ADDR_LEN]; uint8_t *p = req + sizeof(struct pico_ipcp_hdr); - ; memset(&_ppp, 0, sizeof(_ppp)); _ppp.serial_send = unit_serial_send; @@ -1025,7 +1024,7 @@ END_TEST START_TEST(tc_ipcp_bring_up) { struct pico_stack *S; - + pico_stack_init(&S); memset(&_ppp, 0, sizeof(_ppp)); @@ -1049,8 +1048,8 @@ START_TEST(tc_ipcp_start_timer) { memset(&_ppp, 0, sizeof(_ppp)); ipcp_start_timer(&_ppp); - fail_if (_ppp.timer_on != PPP_TIMER_ON_IPCP); - fail_if (_ppp.timer_val != PICO_PPP_DEFAULT_TIMER * PICO_PPP_DEFAULT_MAX_FAILURE); + fail_if(_ppp.timer_on != PPP_TIMER_ON_IPCP); + fail_if(_ppp.timer_val != PICO_PPP_DEFAULT_TIMER * PICO_PPP_DEFAULT_MAX_FAILURE); } END_TEST START_TEST(tc_pico_ppp_poll) diff --git a/test/unit/modunit_pico_dns_client.c b/test/unit/modunit_pico_dns_client.c index 0d8b736a..8548a5d9 100644 --- a/test/unit/modunit_pico_dns_client.c +++ b/test/unit/modunit_pico_dns_client.c @@ -23,7 +23,7 @@ START_TEST(tc_pico_dns_client_callback) s = pico_udp_open(); fail_if(!s); - + s->proto = &pico_proto_udp; s->stack = S; diff --git a/test/unit/modunit_pico_dns_common.c b/test/unit/modunit_pico_dns_common.c index ff001e4b..95000fb5 100644 --- a/test/unit/modunit_pico_dns_common.c +++ b/test/unit/modunit_pico_dns_common.c @@ -1012,7 +1012,7 @@ START_TEST(tc_pico_dns_answer_create) /* MARK: dns_answer_create */ /* Try to create an answer packet */ packet = pico_dns_answer_create(&rtree, NULL, NULL, &len); - fail_if (packet == NULL, "dns_answer_create returned NULL!\n"); + fail_if(packet == NULL, "dns_answer_create returned NULL!\n"); fail_unless(0 == memcmp((void *)packet, (void *)buf, len), "dns_answer_create failed!\n"); diff --git a/test/unit/modunit_pico_dns_sd.c b/test/unit/modunit_pico_dns_sd.c index c3ce8865..926e8ae0 100644 --- a/test/unit/modunit_pico_dns_sd.c +++ b/test/unit/modunit_pico_dns_sd.c @@ -13,16 +13,14 @@ #include Suite *pico_suite(void); -void callback( pico_mdns_rtree *tree, char *str, void *arg); +void callback(pico_mdns_rtree *tree, char *str, void *arg); int dns_sd_init(struct pico_stack *S); char text[] = "textvers"; char text2[] = "pass"; char text3[] = "color"; char value[] = "1"; char value3[] = ""; -void callback( pico_mdns_rtree *tree, - char *str, - void *arg ) +void callback(pico_mdns_rtree *tree, char *str, void *arg) { struct pico_stack *S = NULL; kv_vector vector = { @@ -186,7 +184,7 @@ START_TEST(tc_dns_sd_txt_record_create) /* Pair with an empty value */ pico_dns_sd_kv_vector_add(&pairs, text, NULL); record = pico_dns_sd_txt_record_create(S, "test.local", pairs, 10, - PICO_MDNS_RECORD_UNIQUE); + PICO_MDNS_RECORD_UNIQUE); fail_unless(record != NULL, "pico_dns_sd_txt_record_create should have a record!\n"); pico_dns_sd_kv_vector_erase(&pairs); @@ -200,7 +198,7 @@ START_TEST(tc_dns_sd_txt_record_create) long_value[PICO_DNS_SD_KV_MAXLEN] = '\0'; pico_dns_sd_kv_vector_add(&pairs, text, long_value); record = pico_dns_sd_txt_record_create(S, "test.local", pairs, 10, - PICO_MDNS_RECORD_UNIQUE); + PICO_MDNS_RECORD_UNIQUE); fail_unless(record == NULL, "pico_dns_sd_txt_record_create shouldn't have a record!\n"); pico_dns_sd_kv_vector_erase(&pairs); diff --git a/test/unit/modunit_pico_ethernet.c b/test/unit/modunit_pico_ethernet.c index caf04df9..51eed30f 100644 --- a/test/unit/modunit_pico_ethernet.c +++ b/test/unit/modunit_pico_ethernet.c @@ -155,7 +155,7 @@ START_TEST(tc_destination_is_mcast) END_TEST START_TEST(tc_pico_ipv4_ethernet_receive) { - /* test this: static int32_t pico_ipv4_ethernet_receive(struct pico_frame *f) */ + /* test this: static int32_t pico_ipv4_ethernet_receive(struct pico_frame *f) */ struct pico_frame *f = NULL; struct pico_ipv4_hdr *h4 = NULL; int ret = 0, count = 0; @@ -185,7 +185,7 @@ START_TEST(tc_pico_ipv4_ethernet_receive) END_TEST START_TEST(tc_pico_ipv6_ethernet_receive) { - /* test this: static int32_t pico_ipv6_ethernet_receive(struct pico_frame *f) */ + /* test this: static int32_t pico_ipv6_ethernet_receive(struct pico_frame *f) */ struct pico_frame *f = NULL; struct pico_ipv6_hdr *h = NULL; struct pico_stack *S = NULL; diff --git a/test/unit/modunit_pico_fragments.c b/test/unit/modunit_pico_fragments.c index 17ec43a0..6d0c767f 100644 --- a/test/unit/modunit_pico_fragments.c +++ b/test/unit/modunit_pico_fragments.c @@ -837,7 +837,7 @@ END_TEST START_TEST(tc_pico_fragments_get_offset) { - struct pico_frame *a=NULL, *b = NULL; + struct pico_frame *a = NULL, *b = NULL; b = pico_frame_alloc(sizeof(struct pico_ipv4_hdr)); fail_if(!b); @@ -1049,7 +1049,7 @@ START_TEST(tc_pico_ipv6_process_frag) /* init hdr */ hdr = PICO_ZALLOC(sizeof(struct pico_ipv6_exthdr)); - hdr->ext.frag.id[0]= 0xF; + hdr->ext.frag.id[0] = 0xF; /* NULL frame provided */ S->ipv6_cur_frag_id = 0; diff --git a/test/unit/modunit_pico_frame.c b/test/unit/modunit_pico_frame.c index cf677fe9..c74d9174 100644 --- a/test/unit/modunit_pico_frame.c +++ b/test/unit/modunit_pico_frame.c @@ -130,7 +130,7 @@ START_TEST(tc_pico_frame_grow) f->buffer = PICO_ZALLOC(10); fail_if(pico_frame_grow(f, 22) != 0); - fail_if (f->flags); + fail_if(f->flags); pico_frame_discard(f); } @@ -151,7 +151,7 @@ START_TEST(tc_pico_frame_copy) fail_if(!c1->buffer); fail_if(!c1->usage_count); - fail_if (c1->buffer != f->buffer); + fail_if(c1->buffer != f->buffer); fail_if(c1->usage_count != f->usage_count); fail_if(*c1->usage_count != 2); fail_if(*f->usage_count != 2); @@ -161,7 +161,7 @@ START_TEST(tc_pico_frame_copy) /* Second copy */ c2 = pico_frame_copy(f); - fail_if (c2->buffer != f->buffer); + fail_if(c2->buffer != f->buffer); fail_if(c2->usage_count != f->usage_count); fail_if(*c2->usage_count != 3); fail_if(*f->usage_count != 3); diff --git a/test/unit/modunit_pico_hotplug_detection.c b/test/unit/modunit_pico_hotplug_detection.c index d0159d86..9386c11c 100644 --- a/test/unit/modunit_pico_hotplug_detection.c +++ b/test/unit/modunit_pico_hotplug_detection.c @@ -157,18 +157,18 @@ START_TEST(tc_pico_hotplug_callbacks) timer_cb_function(0, S); fail_unless(timer_active == 1); fail_unless(cb_one_cntr == 2); - fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_UP ); + fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_UP); fail_unless(cb_two_cntr == 3); - fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_UP ); + fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_UP); state_b = 1; timer_active = 0; timer_cb_function(0, S); fail_unless(timer_active == 1); fail_unless(cb_one_cntr == 2); - fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_UP ); + fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_UP); fail_unless(cb_two_cntr == 4); - fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_UP ); + fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_UP); state_a = 0; state_b = 0; @@ -176,9 +176,9 @@ START_TEST(tc_pico_hotplug_callbacks) timer_cb_function(0, S); fail_unless(timer_active == 1); fail_unless(cb_one_cntr == 3); - fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_DOWN ); + fail_unless(cb_one_last_event == PICO_HOTPLUG_EVENT_DOWN); fail_unless(cb_two_cntr == 6); - fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_DOWN ); + fail_unless(cb_two_last_event == PICO_HOTPLUG_EVENT_DOWN); } END_TEST diff --git a/test/unit/modunit_pico_igmp.c b/test/unit/modunit_pico_igmp.c index e413fb57..58450314 100644 --- a/test/unit/modunit_pico_igmp.c +++ b/test/unit/modunit_pico_igmp.c @@ -107,14 +107,14 @@ START_TEST(tc_pico_igmp_timer_expired) pico_igmp_timer_expired(0, (void *)t); pico_tree_insert(&S->IGMPTimers, t); s = PICO_ZALLOC(sizeof(struct igmp_timer)); - memcpy(s,t,sizeof(struct igmp_timer)); // t will be freed next test + memcpy(s, t, sizeof(struct igmp_timer)); /* t will be freed next test */ pico_igmp_timer_expired(0, (void *)t); /* t is freed here */ s->stopped++; - s->start = PICO_TIME_MS()*2; + s->start = PICO_TIME_MS() * 2; s->type++; pico_tree_insert(&S->IGMPTimers, s); t = PICO_ZALLOC(sizeof(struct igmp_timer)); - memcpy(t,s,sizeof(struct igmp_timer)); // s will be freed next test + memcpy(t, s, sizeof(struct igmp_timer)); /* s will be freed next test */ pico_igmp_timer_expired(0, (void *)s); /* s is freed here */ t->callback = mock_callback; pico_igmp_timer_expired(0, (void *)t); @@ -184,23 +184,23 @@ START_TEST(tc_pico_igmp_process_in) link->mcast_compatibility = PICO_IGMPV2; fail_if(pico_igmp_generate_report(p) != 0); link->mcast_compatibility = PICO_IGMPV3; - for(l = 0; l < 3; l++) { /* FILTER */ + for (l = 0; l < 3; l++) { /* FILTER */ (l == 2) ? (result = -1) : (result = 0); - for(k = 0; k < 3; k++) { /* FILTER */ - if(k == 2) result = -1; + for (k = 0; k < 3; k++) { /* FILTER */ + if (k == 2)result = -1; - for(i = 0; i < 3; i++) { /* STATES */ - for(j = 0; j < 6; j++) { /* EVENTS */ + for (i = 0; i < 3; i++) { /* STATES */ + for (j = 0; j < 6; j++) { /* EVENTS */ p->MCASTFilter = &_MCASTFilter; p->filter_mode = k; g.filter_mode = l; - if(p->event == IGMP_EVENT_DELETE_GROUP || p->event == IGMP_EVENT_QUERY_RECV) + if (p->event == IGMP_EVENT_DELETE_GROUP || p->event == IGMP_EVENT_QUERY_RECV) p->event++; fail_if(pico_igmp_generate_report(p) != result); p->state = i; p->event = j; - if(result != -1 && p->f) /* in some combinations, no frame is created */ + if (result != -1 && p->f) /* in some combinations, no frame is created */ fail_if(pico_igmp_process_in(S, NULL, p->f) != 0); } } diff --git a/test/unit/modunit_pico_ipv6_nd.c b/test/unit/modunit_pico_ipv6_nd.c index 966c81b3..ae2b0f4a 100644 --- a/test/unit/modunit_pico_ipv6_nd.c +++ b/test/unit/modunit_pico_ipv6_nd.c @@ -18,13 +18,13 @@ #define VALUE_BETWEEN_RANGE(val, min, max) \ (((val) > (min)) && ((val) < (max))) -#define EXPIRE_TIME_RANGE_MS (10) +#define EXPIRE_TIME_RANGE_MS (10) #define TIME_CHECK(time, expected) VALUE_BETWEEN_RANGE(time, expected-EXPIRE_TIME_RANGE_MS, expected+EXPIRE_TIME_RANGE_MS) enum ND_PACKET_TYPE { - PACKET_TYPE_NORMAL = 0, - PACKET_TYPE_BAD_LEN, - PACKET_TYPE_DOUBLE_OPTION, + PACKET_TYPE_NORMAL = 0, + PACKET_TYPE_BAD_LEN, + PACKET_TYPE_DOUBLE_OPTION, }; static char all_node_multicast_addr_s[] = "ff02::1"; @@ -34,2111 +34,2081 @@ static int pico_icmp6_checksum_success_flag = 1; static int pico_ns_solicited_count = 0, pico_ns_unicast_count = 0, pico_ns_count = 0; const uint8_t router_adv_mac[PICO_SIZE_ETH] = { - 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 + 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 }; const char router_adv_prefix[] = "3ffe:501:ffff:100::"; static struct pico_icmp6_opt_prefix router_prefix_option = { - .type = PICO_ND_OPT_PREFIX, - .len = sizeof(struct pico_icmp6_opt_prefix) >> 3, - .prefix_len = 64, /* Only /64 are forwarded */ - .res = 0, - .aac = 1, - .onlink = 1, - .val_lifetime = 86400, - .pref_lifetime = 14400, - .reserved = 0, + .type = PICO_ND_OPT_PREFIX, + .len = sizeof(struct pico_icmp6_opt_prefix) >> 3, + .prefix_len = 64, /* Only /64 are forwarded */ + .res = 0, + .aac = 1, + .onlink = 1, + .val_lifetime = 86400, + .pref_lifetime = 14400, + .reserved = 0, }; Suite *pico_suite(void); uint16_t pico_icmp6_checksum(struct pico_frame *f) { - IGNORE_PARAMETER(f); + IGNORE_PARAMETER(f); - if (pico_icmp6_checksum_success_flag) - return 0; + if (pico_icmp6_checksum_success_flag) + return 0; - return 1; + return 1; } int pico_icmp6_router_solicitation(struct pico_device *dev, struct pico_ip6 *src, struct pico_ip6 *dst) { - IGNORE_PARAMETER(dev); - IGNORE_PARAMETER(src); - IGNORE_PARAMETER(dst); + IGNORE_PARAMETER(dev); + IGNORE_PARAMETER(src); + IGNORE_PARAMETER(dst); - return 0; + return 0; } int pico_icmp6_neighbor_solicitation(struct pico_device *dev, struct pico_ip6 *tgt, uint8_t type, struct pico_ip6 *dst) { - IGNORE_PARAMETER(dev); - IGNORE_PARAMETER(tgt); - IGNORE_PARAMETER(type); - IGNORE_PARAMETER(dst); + IGNORE_PARAMETER(dev); + IGNORE_PARAMETER(tgt); + IGNORE_PARAMETER(type); + IGNORE_PARAMETER(dst); - if (type == PICO_ICMP6_ND_UNICAST) { - pico_ns_unicast_count++; - } else if (type == PICO_ICMP6_ND_SOLICITED) { - pico_ns_solicited_count++; - } + if (type == PICO_ICMP6_ND_UNICAST) { + pico_ns_unicast_count++; + } else if (type == PICO_ICMP6_ND_SOLICITED) { + pico_ns_solicited_count++; + } - pico_ns_count++; + pico_ns_count++; - return 0; + return 0; } -int pico_datalink_send(struct pico_frame *f) { - IGNORE_PARAMETER(f); +int pico_datalink_send(struct pico_frame *f) +{ + IGNORE_PARAMETER(f); - /* Always return success */ - return 1; + /* Always return success */ + return 1; } static struct pico_frame *make_router_adv(struct pico_device *dev, enum ND_PACKET_TYPE packet_type) { - /* - * Router solicitation from ND tahi tests v6LC.2.2.2 Part B - * has link layer addr option + prefix option - */ - struct pico_frame *adv = NULL; - struct pico_icmp6_hdr *icmp6_hdr = NULL; - struct pico_icmp6_opt_lladdr *lladdr = NULL; - struct pico_icmp6_opt_prefix *prefix = NULL; - uint16_t len = 0; - uint8_t *nxt_opt = NULL; - uint8_t number_of_lladdr_options = 1; - int i = 0; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - if (packet_type == PACKET_TYPE_DOUBLE_OPTION) { - len = PICO_ICMP6HDR_ROUTER_ADV_SIZE + 2 * PICO_ICMP6_OPT_LLADDR_SIZE + sizeof(struct pico_icmp6_opt_prefix); - number_of_lladdr_options = 2; - } else { - len = PICO_ICMP6HDR_ROUTER_ADV_SIZE + PICO_ICMP6_OPT_LLADDR_SIZE + sizeof(struct pico_icmp6_opt_prefix); - number_of_lladdr_options = 1; - } - - adv = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dev, len); - fail_if(!adv); - - adv->payload = adv->transport_hdr + len; - adv->payload_len = 0; - - icmp6_hdr = (struct pico_icmp6_hdr *)adv->transport_hdr; - icmp6_hdr->type = PICO_ICMP6_ROUTER_ADV; - icmp6_hdr->code = 0; - icmp6_hdr->msg.info.router_adv.life_time = short_be(45); - icmp6_hdr->msg.info.router_adv.hop = 64; - nxt_opt = (uint8_t *)&icmp6_hdr->msg.info.router_adv + sizeof(struct router_adv_s); - - prefix = (struct pico_icmp6_opt_prefix *)nxt_opt; - prefix->type = router_prefix_option.type; - if (packet_type == PACKET_TYPE_BAD_LEN) { - prefix->len = 0; - } else { - prefix->len = router_prefix_option.len; - } - prefix->prefix_len = router_prefix_option.prefix_len; - prefix->aac = router_prefix_option.aac; - prefix->onlink = router_prefix_option.onlink; - prefix->val_lifetime = router_prefix_option.val_lifetime; - prefix->pref_lifetime = router_prefix_option.pref_lifetime; - - pico_string_to_ipv6(router_adv_prefix, prefix->prefix.addr); - nxt_opt += (sizeof (struct pico_icmp6_opt_prefix)); - - for (i = 0; i < number_of_lladdr_options; i++) { - lladdr = (struct pico_icmp6_opt_lladdr *)nxt_opt; - - lladdr->type = PICO_ND_OPT_LLADDR_SRC; /* - * lladdr option is 8 bytes long - * sizeof(struct pico_icmp6_opt_lladdr) is 10 bytes big - * but actually the size of this option should be 8 bytes - * but below method works because: !!! 10/8 == 1 !!! + * Router solicitation from ND tahi tests v6LC.2.2.2 Part B + * has link layer addr option + prefix option */ - lladdr->len = sizeof(struct pico_icmp6_opt_lladdr) >> 3; + struct pico_frame *adv = NULL; + struct pico_icmp6_hdr *icmp6_hdr = NULL; + struct pico_icmp6_opt_lladdr *lladdr = NULL; + struct pico_icmp6_opt_prefix *prefix = NULL; + uint16_t len = 0; + uint8_t *nxt_opt = NULL; + uint8_t number_of_lladdr_options = 1; + int i = 0; + struct pico_stack *S = NULL; - memcpy(&lladdr->addr, &router_adv_mac, PICO_SIZE_ETH); - /* - * see above comment - */ - nxt_opt += lladdr->len << 3; - } + pico_stack_init(&S); + + if (packet_type == PACKET_TYPE_DOUBLE_OPTION) { + len = PICO_ICMP6HDR_ROUTER_ADV_SIZE + 2 * PICO_ICMP6_OPT_LLADDR_SIZE + sizeof(struct pico_icmp6_opt_prefix); + number_of_lladdr_options = 2; + } else { + len = PICO_ICMP6HDR_ROUTER_ADV_SIZE + PICO_ICMP6_OPT_LLADDR_SIZE + sizeof(struct pico_icmp6_opt_prefix); + number_of_lladdr_options = 1; + } + + adv = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dev, len); + fail_if(!adv); - icmp6_hdr->crc = short_be(pico_icmp6_checksum(adv)); + adv->payload = adv->transport_hdr + len; + adv->payload_len = 0; - return adv; + icmp6_hdr = (struct pico_icmp6_hdr *)adv->transport_hdr; + icmp6_hdr->type = PICO_ICMP6_ROUTER_ADV; + icmp6_hdr->code = 0; + icmp6_hdr->msg.info.router_adv.life_time = short_be(45); + icmp6_hdr->msg.info.router_adv.hop = 64; + nxt_opt = (uint8_t *)&icmp6_hdr->msg.info.router_adv + sizeof(struct router_adv_s); + + prefix = (struct pico_icmp6_opt_prefix *)nxt_opt; + prefix->type = router_prefix_option.type; + if (packet_type == PACKET_TYPE_BAD_LEN) { + prefix->len = 0; + } else { + prefix->len = router_prefix_option.len; + } + prefix->prefix_len = router_prefix_option.prefix_len; + prefix->aac = router_prefix_option.aac; + prefix->onlink = router_prefix_option.onlink; + prefix->val_lifetime = router_prefix_option.val_lifetime; + prefix->pref_lifetime = router_prefix_option.pref_lifetime; + + pico_string_to_ipv6(router_adv_prefix, prefix->prefix.addr); + nxt_opt += (sizeof (struct pico_icmp6_opt_prefix)); + + for (i = 0; i < number_of_lladdr_options; i++) { + lladdr = (struct pico_icmp6_opt_lladdr *)nxt_opt; + + lladdr->type = PICO_ND_OPT_LLADDR_SRC; + /* + * lladdr option is 8 bytes long + * sizeof(struct pico_icmp6_opt_lladdr) is 10 bytes big + * but actually the size of this option should be 8 bytes + * but below method works because: !!! 10/8 == 1 !!! + */ + lladdr->len = sizeof(struct pico_icmp6_opt_lladdr) >> 3; + + memcpy(&lladdr->addr, &router_adv_mac, PICO_SIZE_ETH); + /* + * see above comment + */ + nxt_opt += lladdr->len << 3; + } + icmp6_hdr->crc = short_be(pico_icmp6_checksum(adv)); + + return adv; } START_TEST(tc_pico_ipv6_neighbor_compare) { - struct pico_ipv6_neighbor a = { 0 }, b = { 0 }; - struct pico_ip6 address_a = { 0 }, address_b = { 0 }; + struct pico_ipv6_neighbor a = { 0 }, b = { 0 }; + struct pico_ip6 address_a = { 0 }, address_b = { 0 }; - /* Same addresses */ - a.address = address_a; - b.address = address_b; - fail_if(pico_ipv6_neighbor_compare(&a, &b) != 0, "Neighbours A and B have same ipv6 addr, not true?"); + /* Same addresses */ + a.address = address_a; + b.address = address_b; + fail_if(pico_ipv6_neighbor_compare(&a, &b) != 0, "Neighbours A and B have same ipv6 addr, not true?"); - /* a has different address */ - a.address.addr[0] = 1; - fail_if(pico_ipv6_neighbor_compare(&a, &b) != 1, "Neighbour A has different ipv6 addr, not detected?"); + /* a has different address */ + a.address.addr[0] = 1; + fail_if(pico_ipv6_neighbor_compare(&a, &b) != 1, "Neighbour A has different ipv6 addr, not detected?"); - /* Reset */ - a.address = address_a; - b.address = address_b; + /* Reset */ + a.address = address_a; + b.address = address_b; - /* b has different address */ - b.address.addr[0] = 1; - fail_if(pico_ipv6_neighbor_compare(&a, &b) != -1, "Neighbour B has different ipv6 addr, not detected?"); + /* b has different address */ + b.address.addr[0] = 1; + fail_if(pico_ipv6_neighbor_compare(&a, &b) != -1, "Neighbour B has different ipv6 addr, not detected?"); } END_TEST START_TEST(tc_pico_ipv6_router_compare) { - struct pico_ipv6_router a = { 0 }, b = { 0 }; - struct pico_ipv6_neighbor neighbor_a = { 0 }, neighbor_b = { 0 }; - struct pico_ip6 address_a = { 0 }, address_b = { 0 }; + struct pico_ipv6_router a = { 0 }, b = { 0 }; + struct pico_ipv6_neighbor neighbor_a = { 0 }, neighbor_b = { 0 }; + struct pico_ip6 address_a = { 0 }, address_b = { 0 }; - /* Same addresses */ - neighbor_a.address = address_a; - neighbor_b.address = address_b; - a.router = &neighbor_a; - b.router = &neighbor_b; - fail_if(pico_ipv6_router_compare(&a, &b) != 0, "Routers A and B have same ipv6 addr, not true?"); + /* Same addresses */ + neighbor_a.address = address_a; + neighbor_b.address = address_b; + a.router = &neighbor_a; + b.router = &neighbor_b; + fail_if(pico_ipv6_router_compare(&a, &b) != 0, "Routers A and B have same ipv6 addr, not true?"); - /* a has different address */ - neighbor_a.address.addr[0] = 1; - fail_if(pico_ipv6_router_compare(&a, &b) != 1, "Router A has different ipv6 addr, not detected?"); + /* a has different address */ + neighbor_a.address.addr[0] = 1; + fail_if(pico_ipv6_router_compare(&a, &b) != 1, "Router A has different ipv6 addr, not detected?"); - /* Reset */ - neighbor_a.address = address_a; - neighbor_b.address = address_b; + /* Reset */ + neighbor_a.address = address_a; + neighbor_b.address = address_b; - /* b has different address */ - neighbor_b.address.addr[0] = 1; - fail_if(pico_ipv6_router_compare(&a, &b) != -1, "Router B has different ipv6 addr, not detected?"); + /* b has different address */ + neighbor_b.address.addr[0] = 1; + fail_if(pico_ipv6_router_compare(&a, &b) != -1, "Router B has different ipv6 addr, not detected?"); } END_TEST START_TEST(tc_pico_ipv6_nd_qcompare) { - struct pico_frame a = { 0 }, b = { 0 }; - struct pico_ipv6_hdr a_hdr = { 0 }, b_hdr = { 0 }; - struct pico_ip6 a_dest_addr = { 0 }, b_dest_addr = { 0 }; + struct pico_frame a = { 0 }, b = { 0 }; + struct pico_ipv6_hdr a_hdr = { 0 }, b_hdr = { 0 }; + struct pico_ip6 a_dest_addr = { 0 }, b_dest_addr = { 0 }; - /* Same packets */ - a_hdr.dst = a_dest_addr; - b_hdr.dst = b_dest_addr; + /* Same packets */ + a_hdr.dst = a_dest_addr; + b_hdr.dst = b_dest_addr; - a.net_hdr = (uint8_t *)&a_hdr; - b.net_hdr = (uint8_t *)&b_hdr; + a.net_hdr = (uint8_t *)&a_hdr; + b.net_hdr = (uint8_t *)&b_hdr; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != 0, "Frames A and B have same ipv6 addr, not true?"); + fail_if(pico_ipv6_nd_qcompare(&a, &b) != 0, "Frames A and B have same ipv6 addr, not true?"); - /* a has different address */ - a_hdr.dst.addr[0] = 1; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != 1, "Frame A has different ipv6 addr, not detected?"); + /* a has different address */ + a_hdr.dst.addr[0] = 1; + fail_if(pico_ipv6_nd_qcompare(&a, &b) != 1, "Frame A has different ipv6 addr, not detected?"); - /* Reset */ - a_hdr.dst = a_dest_addr; - b_hdr.dst = b_dest_addr; + /* Reset */ + a_hdr.dst = a_dest_addr; + b_hdr.dst = b_dest_addr; - /* b has different address */ - b_hdr.dst.addr[0] = 1; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != -1, "Frame B has different ipv6 addr, not detected?"); + /* b has different address */ + b_hdr.dst.addr[0] = 1; + fail_if(pico_ipv6_nd_qcompare(&a, &b) != -1, "Frame B has different ipv6 addr, not detected?"); - /* Reset */ - a_hdr.dst = a_dest_addr; - b_hdr.dst = b_dest_addr; + /* Reset */ + a_hdr.dst = a_dest_addr; + b_hdr.dst = b_dest_addr; - /* ------------------------------------------ */ - /* Timestamps */ - /* Same timestamp */ - a.timestamp = 0; - b.timestamp = 0; + /* ------------------------------------------ */ + /* Timestamps */ + /* Same timestamp */ + a.timestamp = 0; + b.timestamp = 0; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != 0, "Frames A and B have same timestamp, not true?"); + fail_if(pico_ipv6_nd_qcompare(&a, &b) != 0, "Frames A and B have same timestamp, not true?"); - /* a has different timestamp */ - a.timestamp = 1; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != 1, "Frame A has different timestamp, not detected?"); + /* a has different timestamp */ + a.timestamp = 1; + fail_if(pico_ipv6_nd_qcompare(&a, &b) != 1, "Frame A has different timestamp, not detected?"); - /* Reset */ - a.timestamp = 0; - b.timestamp = 0; + /* Reset */ + a.timestamp = 0; + b.timestamp = 0; - /* b has different timestamp */ - b.timestamp = 1; - fail_if(pico_ipv6_nd_qcompare(&a, &b) != -1, "Frame B has different timestamp, not detected?"); + /* b has different timestamp */ + b.timestamp = 1; + fail_if(pico_ipv6_nd_qcompare(&a, &b) != -1, "Frame B has different timestamp, not detected?"); } END_TEST START_TEST(tc_icmp6_initial_checks) { - struct pico_frame a = { 0 }; - struct pico_ipv6_hdr ipv6_hdr = { 0 }; - struct pico_icmp6_hdr icmp6_hdr = { 0 }; + struct pico_frame a = { 0 }; + struct pico_ipv6_hdr ipv6_hdr = { 0 }; + struct pico_icmp6_hdr icmp6_hdr = { 0 }; - fail_if(icmp6_initial_checks(NULL) != -1, "NULL arg gives bad return value"); + fail_if(icmp6_initial_checks(NULL) != -1, "NULL arg gives bad return value"); - a.net_hdr = (uint8_t *)&ipv6_hdr; - a.transport_hdr = (uint8_t *)&icmp6_hdr; + a.net_hdr = (uint8_t *)&ipv6_hdr; + a.transport_hdr = (uint8_t *)&icmp6_hdr; - /* Valid headers */ - ipv6_hdr.hop = 255; - icmp6_hdr.code = 0; - pico_icmp6_checksum_success_flag = 1; + /* Valid headers */ + ipv6_hdr.hop = 255; + icmp6_hdr.code = 0; + pico_icmp6_checksum_success_flag = 1; - fail_if(icmp6_initial_checks(&a) != 0, "Valid headers should return success"); + fail_if(icmp6_initial_checks(&a) != 0, "Valid headers should return success"); - /* Invalid checksum */ - pico_icmp6_checksum_success_flag = 0; - fail_if(icmp6_initial_checks(&a) != -1, "Invalid checksum should return failure"); + /* Invalid checksum */ + pico_icmp6_checksum_success_flag = 0; + fail_if(icmp6_initial_checks(&a) != -1, "Invalid checksum should return failure"); - /* Reset to valid */ - ipv6_hdr.hop = 255; - icmp6_hdr.code = 0; - pico_icmp6_checksum_success_flag = 1; + /* Reset to valid */ + ipv6_hdr.hop = 255; + icmp6_hdr.code = 0; + pico_icmp6_checksum_success_flag = 1; - /* Invalid icmp6 hdr code */ - icmp6_hdr.code = 1; /* Anything but 0 is invalid */ - fail_if(icmp6_initial_checks(&a) != -1, "Invalid icmp6 code should return failure"); + /* Invalid icmp6 hdr code */ + icmp6_hdr.code = 1; /* Anything but 0 is invalid */ + fail_if(icmp6_initial_checks(&a) != -1, "Invalid icmp6 code should return failure"); - /* Reset to valid */ - ipv6_hdr.hop = 255; - icmp6_hdr.code = 0; - pico_icmp6_checksum_success_flag = 1; + /* Reset to valid */ + ipv6_hdr.hop = 255; + icmp6_hdr.code = 0; + pico_icmp6_checksum_success_flag = 1; - /* Invalid hop count */ - ipv6_hdr.hop = 254; /* Anything but 255 is invalid */ - fail_if(icmp6_initial_checks(&a) != -1, "Invalid hop count should return failure"); + /* Invalid hop count */ + ipv6_hdr.hop = 254; /* Anything but 255 is invalid */ + fail_if(icmp6_initial_checks(&a) != -1, "Invalid hop count should return failure"); } END_TEST START_TEST(tc_pico_hw_addr_len) { - struct pico_device dummy_dev = { 0 }; - struct pico_icmp6_opt_lladdr opt = { 0 }; + struct pico_device dummy_dev = { 0 }; + struct pico_icmp6_opt_lladdr opt = { 0 }; - dummy_dev.hostvars.lowpan_flags &= (uint8_t)(~PICO_6LP_FLAG_LOWPAN); /* Not a 6LP device */ - fail_if(pico_hw_addr_len(&dummy_dev, &opt) != PICO_SIZE_ETH, "HW addr len is different from ETH for non 6LP device"); + dummy_dev.hostvars.lowpan_flags &= (uint8_t)(~PICO_6LP_FLAG_LOWPAN); /* Not a 6LP device */ + fail_if(pico_hw_addr_len(&dummy_dev, &opt) != PICO_SIZE_ETH, "HW addr len is different from ETH for non 6LP device"); - dummy_dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; /* a 6LP device */ - opt.len = 1; /* short 6lowpan option */ - fail_if(pico_hw_addr_len(&dummy_dev, &opt) != SIZE_6LOWPAN_SHORT, "HW addr len is different from SIZE_6LOWPAN_SHORT for a 6LP device with optlen == 1"); + dummy_dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; /* a 6LP device */ + opt.len = 1; /* short 6lowpan option */ + fail_if(pico_hw_addr_len(&dummy_dev, &opt) != SIZE_6LOWPAN_SHORT, "HW addr len is different from SIZE_6LOWPAN_SHORT for a 6LP device with optlen == 1"); - dummy_dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; /* a 6LP device */ - opt.len = 0; /* extended 6lowpan option */ - fail_if(pico_hw_addr_len(&dummy_dev, &opt) != SIZE_6LOWPAN_EXT, "HW addr len is different from SIZE_6LOWPAN_SHORT for a 6LP device with optlen == 1"); + dummy_dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN; /* a 6LP device */ + opt.len = 0; /* extended 6lowpan option */ + fail_if(pico_hw_addr_len(&dummy_dev, &opt) != SIZE_6LOWPAN_EXT, "HW addr len is different from SIZE_6LOWPAN_SHORT for a 6LP device with optlen == 1"); } END_TEST START_TEST(tc_pico_nd_get_oldest_queued_frame) { - struct pico_frame a, b, c; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_ip6 addr_1 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b - } - }; - struct pico_ipv6_hdr hdr_0 = {0}; - struct pico_ipv6_hdr hdr_1 = {0}; - struct pico_stack *S = NULL; + struct pico_frame a, b, c; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_ip6 addr_1 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b + } + }; + struct pico_ipv6_hdr hdr_0 = {0}; + struct pico_ipv6_hdr hdr_1 = {0}; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - hdr_0.dst = addr_0; - hdr_1.dst = addr_1; + hdr_0.dst = addr_0; + hdr_1.dst = addr_1; - /* No queued frames yet */ - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != NULL, "No queued frames yet, should have returned NULL"); - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames yet, should have returned NULL"); + /* No queued frames yet */ + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != NULL, "No queued frames yet, should have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames yet, should have returned NULL"); - a.timestamp = 0; - b.timestamp = 1; - c.timestamp = 2; + a.timestamp = 0; + b.timestamp = 1; + c.timestamp = 2; - a.net_hdr = (uint8_t *)&hdr_0; - b.net_hdr = (uint8_t *)&hdr_0; - c.net_hdr = (uint8_t *)&hdr_0; + a.net_hdr = (uint8_t *)&hdr_0; + b.net_hdr = (uint8_t *)&hdr_0; + c.net_hdr = (uint8_t *)&hdr_0; - pico_tree_insert(&S->IPV6NQueue, &a); - pico_tree_insert(&S->IPV6NQueue, &b); - pico_tree_insert(&S->IPV6NQueue, &c); + pico_tree_insert(&S->IPV6NQueue, &a); + pico_tree_insert(&S->IPV6NQueue, &b); + pico_tree_insert(&S->IPV6NQueue, &c); - /* Frames queued with same dest addresses */ - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &a, "Queued frames in, shouldn't have returned NULL"); - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames for this dest yet, should have returned NULL"); + /* Frames queued with same dest addresses */ + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &a, "Queued frames in, shouldn't have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames for this dest yet, should have returned NULL"); - /* 2 packets with same timestamp */ - a.timestamp = 1; - b.timestamp = 1; - c.timestamp = 2; + /* 2 packets with same timestamp */ + a.timestamp = 1; + b.timestamp = 1; + c.timestamp = 2; - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &a && pico_nd_get_oldest_queued_frame(S, &addr_0) != &b, "Queued frames in, shouldn't have returned NULL"); - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames for this dest yet, should have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &a && pico_nd_get_oldest_queued_frame(S, &addr_0) != &b, "Queued frames in, shouldn't have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != NULL, "No queued frames for this dest yet, should have returned NULL"); - /* Frames queued with different dest addresses */ - a.timestamp = 0; - b.timestamp = 1; - c.timestamp = 2; + /* Frames queued with different dest addresses */ + a.timestamp = 0; + b.timestamp = 1; + c.timestamp = 2; - a.net_hdr = (uint8_t *)&hdr_1; - b.net_hdr = (uint8_t *)&hdr_0; - c.net_hdr = (uint8_t *)&hdr_0; + a.net_hdr = (uint8_t *)&hdr_1; + b.net_hdr = (uint8_t *)&hdr_0; + c.net_hdr = (uint8_t *)&hdr_0; - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != &a, "No queued frames for this dest yet, should have returned NULL"); - fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &b, "Queued frames in, shouldn't have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_1) != &a, "No queued frames for this dest yet, should have returned NULL"); + fail_if(pico_nd_get_oldest_queued_frame(S, &addr_0) != &b, "Queued frames in, shouldn't have returned NULL"); - pico_tree_delete(&S->IPV6NQueue, &a); - pico_tree_delete(&S->IPV6NQueue, &b); - pico_tree_delete(&S->IPV6NQueue, &c); + pico_tree_delete(&S->IPV6NQueue, &a); + pico_tree_delete(&S->IPV6NQueue, &b); + pico_tree_delete(&S->IPV6NQueue, &c); } END_TEST START_TEST(tc_ipv6_duplicate_detected) { - /* TODO: test this: static void ipv6_duplicate_detected(struct pico_ipv6_link *l) */ + /* TODO: test this: static void ipv6_duplicate_detected(struct pico_ipv6_link *l) */ } END_TEST START_TEST(tc_pico_get_neighbor_from_ncache) { - struct pico_ipv6_neighbor a = { 0 }; - struct pico_ipv6_neighbor b = { 0 }; - struct pico_ip6 a_addr = { 0 }; - struct pico_ip6 b_addr = { 0 }; - struct pico_ip6 c_addr = { 0 }; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor a = { 0 }; + struct pico_ipv6_neighbor b = { 0 }; + struct pico_ip6 a_addr = { 0 }; + struct pico_ip6 b_addr = { 0 }; + struct pico_ip6 c_addr = { 0 }; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - /* Init */ - a.address = a_addr; + /* Init */ + a.address = a_addr; - /* neighbor not in neighbour cache */ - fail_if(pico_get_neighbor_from_ncache(S, &a_addr) != NULL, "Neighbor not registered yet but still found?"); + /* neighbor not in neighbour cache */ + fail_if(pico_get_neighbor_from_ncache(S, &a_addr) != NULL, "Neighbor not registered yet but still found?"); - /* Neighbor in neighbour cache*/ - pico_tree_insert(&S->IPV6NCache, &a); - fail_if(pico_get_neighbor_from_ncache(S, &a_addr) != &a, "Neighbor registered in ncache but NOT found?"); + /* Neighbor in neighbour cache*/ + pico_tree_insert(&S->IPV6NCache, &a); + fail_if(pico_get_neighbor_from_ncache(S, &a_addr) != &a, "Neighbor registered in ncache but NOT found?"); - /* Look for different neighbour */ - b_addr.addr[0] = 1; - b.address = b_addr; - fail_if(pico_get_neighbor_from_ncache(S, &b_addr) != NULL, "Neighbor not registered in ncache but found?"); + /* Look for different neighbour */ + b_addr.addr[0] = 1; + b.address = b_addr; + fail_if(pico_get_neighbor_from_ncache(S, &b_addr) != NULL, "Neighbor not registered in ncache but found?"); - /* Insert other neigbhour */ - pico_tree_insert(&S->IPV6NCache, &b); - fail_if(pico_get_neighbor_from_ncache(S, &b_addr) != &b, "Neighbor registered in ncache but NOT found?"); + /* Insert other neigbhour */ + pico_tree_insert(&S->IPV6NCache, &b); + fail_if(pico_get_neighbor_from_ncache(S, &b_addr) != &b, "Neighbor registered in ncache but NOT found?"); - /* Look for different neighbour when multiple neighbours in neigbhour cache*/ - c_addr.addr[0] = 2; - fail_if(pico_get_neighbor_from_ncache(S, &c_addr) != NULL, "Neighbor not registered in ncache but found?"); + /* Look for different neighbour when multiple neighbours in neigbhour cache*/ + c_addr.addr[0] = 2; + fail_if(pico_get_neighbor_from_ncache(S, &c_addr) != NULL, "Neighbor not registered in ncache but found?"); - /* Cleanup */ - pico_tree_delete(&S->IPV6NCache, &a); - pico_tree_delete(&S->IPV6NCache, &b); + /* Cleanup */ + pico_tree_delete(&S->IPV6NCache, &a); + pico_tree_delete(&S->IPV6NCache, &b); } END_TEST START_TEST(tc_pico_get_router_from_rcache) { - struct pico_ipv6_router a = { 0 }; - struct pico_ipv6_router b = { 0 }; - struct pico_ipv6_neighbor a_nb = { 0 }; - struct pico_ipv6_neighbor b_nb = { 0 }; - struct pico_ip6 a_addr = { 0 }; - struct pico_ip6 b_addr = { 0 }; - struct pico_ip6 c_addr = { 0 }; - struct pico_stack *S = NULL; + struct pico_ipv6_router a = { 0 }; + struct pico_ipv6_router b = { 0 }; + struct pico_ipv6_neighbor a_nb = { 0 }; + struct pico_ipv6_neighbor b_nb = { 0 }; + struct pico_ip6 a_addr = { 0 }; + struct pico_ip6 b_addr = { 0 }; + struct pico_ip6 c_addr = { 0 }; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - /* Init */ - a.router = &a_nb; - b.router = &b_nb; - a_nb.address = a_addr; + /* Init */ + a.router = &a_nb; + b.router = &b_nb; + a_nb.address = a_addr; - /* Router not in router cache */ - fail_if(pico_get_router_from_rcache(S, &a_addr) != NULL, "Router not registered yet but still found?"); + /* Router not in router cache */ + fail_if(pico_get_router_from_rcache(S, &a_addr) != NULL, "Router not registered yet but still found?"); - /* Router in router cache*/ - pico_tree_insert(&S->IPV6RCache, &a); - fail_if(pico_get_router_from_rcache(S, &a_addr) != &a, "Router registered in rcache but NOT found?"); + /* Router in router cache*/ + pico_tree_insert(&S->IPV6RCache, &a); + fail_if(pico_get_router_from_rcache(S, &a_addr) != &a, "Router registered in rcache but NOT found?"); - /* Look for different router */ - b_addr.addr[0] = 1; - b_nb.address = b_addr; - fail_if(pico_get_router_from_rcache(S, &b_addr) != NULL, "Router not registered in rcache but found?"); + /* Look for different router */ + b_addr.addr[0] = 1; + b_nb.address = b_addr; + fail_if(pico_get_router_from_rcache(S, &b_addr) != NULL, "Router not registered in rcache but found?"); - /* Insert other router */ - pico_tree_insert(&S->IPV6RCache, &b); - fail_if(pico_get_router_from_rcache(S, &b_addr) != &b, "Router registered in rcache but NOT found?"); + /* Insert other router */ + pico_tree_insert(&S->IPV6RCache, &b); + fail_if(pico_get_router_from_rcache(S, &b_addr) != &b, "Router registered in rcache but NOT found?"); - /* Look for different router when multiple router in router cache*/ - c_addr.addr[0] = 2; - fail_if(pico_get_router_from_rcache(S, &c_addr) != NULL, "Router not registered in rcache but found?"); + /* Look for different router when multiple router in router cache*/ + c_addr.addr[0] = 2; + fail_if(pico_get_router_from_rcache(S, &c_addr) != NULL, "Router not registered in rcache but found?"); - /* Failing malloc */ - pico_set_mm_failure(1); - fail_if(pico_get_router_from_rcache(S, &b_addr) != NULL, "Router registered in rcache but malloc failed and we don't return NULL?"); + /* Failing malloc */ + pico_set_mm_failure(1); + fail_if(pico_get_router_from_rcache(S, &b_addr) != NULL, "Router registered in rcache but malloc failed and we don't return NULL?"); - pico_set_mm_failure(1); - fail_if(pico_get_router_from_rcache(S, &c_addr) != NULL, "Router not registered in rcache and malloc failed, but we don't return NULL?"); + pico_set_mm_failure(1); + fail_if(pico_get_router_from_rcache(S, &c_addr) != NULL, "Router not registered in rcache and malloc failed, but we don't return NULL?"); - /* Cleanup */ - pico_tree_delete(&S->IPV6RCache, &a); - pico_tree_delete(&S->IPV6RCache, &b); + /* Cleanup */ + pico_tree_delete(&S->IPV6RCache, &a); + pico_tree_delete(&S->IPV6RCache, &b); } END_TEST START_TEST(tc_pico_nd_get_default_router) { - struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }; - struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }; - struct pico_ipv6_link link = { 0 }; - char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; - char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; - char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - /* Setup of routers */ - r0.router = &n0; - r1.router = &n1; - r2.router = &n2; - r0.link = &link; - r1.link = &link; - r2.link = &link; - pico_string_to_ipv6(ipstr0, r0.router->address.addr); - pico_string_to_ipv6(ipstr1, r1.router->address.addr); - pico_string_to_ipv6(ipstr2, r2.router->address.addr); - - /* No routers in Cache */ - fail_if(pico_nd_get_default_router(S) != NULL, "No router in RCache, should have returned NULL"); - - /* Routers in rcache, but don't flag it as default router */ - pico_tree_insert(&S->IPV6RCache, &r0); - pico_tree_insert(&S->IPV6RCache, &r1); - pico_tree_insert(&S->IPV6RCache, &r2); - fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); - - /* Flag one router as default */ - r1.is_default = 1; - fail_if(pico_nd_get_default_router(S) != &r1, "Default router in RCache, should have been returned"); - - /* Cleanup */ - pico_tree_delete(&S->IPV6RCache, &r0); - pico_tree_delete(&S->IPV6RCache, &r1); - pico_tree_delete(&S->IPV6RCache, &r2); + struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }; + struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }; + struct pico_ipv6_link link = { 0 }; + char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; + char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; + char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + /* Setup of routers */ + r0.router = &n0; + r1.router = &n1; + r2.router = &n2; + r0.link = &link; + r1.link = &link; + r2.link = &link; + pico_string_to_ipv6(ipstr0, r0.router->address.addr); + pico_string_to_ipv6(ipstr1, r1.router->address.addr); + pico_string_to_ipv6(ipstr2, r2.router->address.addr); + + /* No routers in Cache */ + fail_if(pico_nd_get_default_router(S) != NULL, "No router in RCache, should have returned NULL"); + + /* Routers in rcache, but don't flag it as default router */ + pico_tree_insert(&S->IPV6RCache, &r0); + pico_tree_insert(&S->IPV6RCache, &r1); + pico_tree_insert(&S->IPV6RCache, &r2); + fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); + + /* Flag one router as default */ + r1.is_default = 1; + fail_if(pico_nd_get_default_router(S) != &r1, "Default router in RCache, should have been returned"); + + /* Cleanup */ + pico_tree_delete(&S->IPV6RCache, &r0); + pico_tree_delete(&S->IPV6RCache, &r1); + pico_tree_delete(&S->IPV6RCache, &r2); } END_TEST START_TEST(tc_pico_nd_set_new_expire_time) { - struct pico_ipv6_neighbor n = { - 0 - }; - struct pico_device d = { {0} }; - pico_time now = 0; - - n.dev = &d; - - d.hostvars.retranstime = 666; - d.hostvars.reachabletime = PICO_ND_REACHABLE_TIME; - /* - * We will test if the expire time is between a certain range, - * instead of comparing with the exact value set in the function - * - * This is to reduce machine/test-run dependency because of the use of PICO_TIME_MS() - */ - - n.state = PICO_ND_STATE_INCOMPLETE; - pico_nd_set_new_expire_time(&n); - now = PICO_TIME_MS(); - fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); - - n.state = PICO_ND_STATE_REACHABLE; - pico_nd_set_new_expire_time(&n); - now = PICO_TIME_MS(); - fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.reachabletime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.reachabletime + EXPIRE_TIME_RANGE_MS)); - - n.state = PICO_ND_STATE_STALE; - pico_nd_set_new_expire_time(&n); - now = PICO_TIME_MS(); - fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + PICO_ND_DELAY_FIRST_PROBE_TIME - EXPIRE_TIME_RANGE_MS, now + PICO_ND_DELAY_FIRST_PROBE_TIME + EXPIRE_TIME_RANGE_MS)); - - n.state = PICO_ND_STATE_DELAY; - pico_nd_set_new_expire_time(&n); - now = PICO_TIME_MS(); - fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + PICO_ND_DELAY_FIRST_PROBE_TIME - EXPIRE_TIME_RANGE_MS, now + PICO_ND_DELAY_FIRST_PROBE_TIME + EXPIRE_TIME_RANGE_MS)); - - n.state = PICO_ND_STATE_PROBE; - pico_nd_set_new_expire_time(&n); - now = PICO_TIME_MS(); - fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); + struct pico_ipv6_neighbor n = { + 0 + }; + struct pico_device d = { {0}}; + pico_time now = 0; + + n.dev = &d; + + d.hostvars.retranstime = 666; + d.hostvars.reachabletime = PICO_ND_REACHABLE_TIME; + /* + * We will test if the expire time is between a certain range, + * instead of comparing with the exact value set in the function + * + * This is to reduce machine/test-run dependency because of the use of PICO_TIME_MS() + */ + + n.state = PICO_ND_STATE_INCOMPLETE; + pico_nd_set_new_expire_time(&n); + now = PICO_TIME_MS(); + fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); + + n.state = PICO_ND_STATE_REACHABLE; + pico_nd_set_new_expire_time(&n); + now = PICO_TIME_MS(); + fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.reachabletime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.reachabletime + EXPIRE_TIME_RANGE_MS)); + + n.state = PICO_ND_STATE_STALE; + pico_nd_set_new_expire_time(&n); + now = PICO_TIME_MS(); + fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + PICO_ND_DELAY_FIRST_PROBE_TIME - EXPIRE_TIME_RANGE_MS, now + PICO_ND_DELAY_FIRST_PROBE_TIME + EXPIRE_TIME_RANGE_MS)); + + n.state = PICO_ND_STATE_DELAY; + pico_nd_set_new_expire_time(&n); + now = PICO_TIME_MS(); + fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + PICO_ND_DELAY_FIRST_PROBE_TIME - EXPIRE_TIME_RANGE_MS, now + PICO_ND_DELAY_FIRST_PROBE_TIME + EXPIRE_TIME_RANGE_MS)); + + n.state = PICO_ND_STATE_PROBE; + pico_nd_set_new_expire_time(&n); + now = PICO_TIME_MS(); + fail_unless(VALUE_BETWEEN_RANGE(n.expire, now + d.hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + d.hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); } END_TEST START_TEST(tc_pico_ipv6_assign_default_router_on_link) { - struct pico_ipv6_router *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; - struct pico_ipv6_neighbor *n0 = NULL, *n1 = NULL, *n2 = NULL, *n3 = NULL; - struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_ip6 addr_1 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b - } - }; - struct pico_ip6 addr_2 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x2b - } - }; - struct pico_ip6 addr_3 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x3b - } - }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - struct pico_stack *S = NULL; + struct pico_ipv6_router *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL; + struct pico_ipv6_neighbor *n0 = NULL, *n1 = NULL, *n2 = NULL, *n3 = NULL; + struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_ip6 addr_1 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b + } + }; + struct pico_ip6 addr_2 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x2b + } + }; + struct pico_ip6 addr_3 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x3b + } + }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); - link0.dev = dummy_dev; + link0.dev = dummy_dev; - /* Setup of routers */ - n0 = pico_nd_create_entry(S, &addr_0, dummy_dev); - n1 = pico_nd_create_entry(S, &addr_1, dummy_dev); - n2 = pico_nd_create_entry(S, &addr_2, dummy_dev); - n3 = pico_nd_create_entry(S, &addr_3, dummy_dev); + /* Setup of routers */ + n0 = pico_nd_create_entry(S, &addr_0, dummy_dev); + n1 = pico_nd_create_entry(S, &addr_1, dummy_dev); + n2 = pico_nd_create_entry(S, &addr_2, dummy_dev); + n3 = pico_nd_create_entry(S, &addr_3, dummy_dev); - r0 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r1 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r2 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r3 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + r0 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + r1 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + r2 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + r3 = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r0->router = n0; - r1->router = n1; - r2->router = n2; - r3->router = n3; - r0->link = &link0; - r1->link = &link0; - r2->link = &link0; - r3->link = &link1; /* One router with different link */ + r0->router = n0; + r1->router = n1; + r2->router = n2; + r3->router = n3; + r0->link = &link0; + r1->link = &link0; + r2->link = &link0; + r3->link = &link1; /* One router with different link */ - /* No routers in Cache */ - fail_if(pico_nd_get_default_router(S) != NULL, "No router in RCache, should have returned NULL"); + /* No routers in Cache */ + fail_if(pico_nd_get_default_router(S) != NULL, "No router in RCache, should have returned NULL"); - /* Routers in rcache, but don't flag it as default router */ - pico_tree_insert(&S->IPV6RCache, r0); - pico_tree_insert(&S->IPV6RCache, r1); - pico_tree_insert(&S->IPV6RCache, r2); - pico_tree_insert(&S->IPV6RCache, r3); - fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); + /* Routers in rcache, but don't flag it as default router */ + pico_tree_insert(&S->IPV6RCache, r0); + pico_tree_insert(&S->IPV6RCache, r1); + pico_tree_insert(&S->IPV6RCache, r2); + pico_tree_insert(&S->IPV6RCache, r3); + fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); - pico_ipv6_assign_router_on_link(S, 0, &link0); /* Don't assign default router */ + pico_ipv6_assign_router_on_link(S, 0, &link0); /* Don't assign default router */ - fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); + fail_if(pico_nd_get_default_router(S) != NULL, "No default router in RCache, should have returned NULL"); - pico_ipv6_assign_router_on_link(S, 1, &link0); /* Assign default router */ + pico_ipv6_assign_router_on_link(S, 1, &link0); /* Assign default router */ - fail_if(pico_nd_get_default_router(S) == NULL, "Default router in RCache with link0, shouldn't have returned NULL"); - fail_if(pico_nd_get_default_router(S) == r3, "Default router in RCache with link0, shouldn't have returned router with link1"); + fail_if(pico_nd_get_default_router(S) == NULL, "Default router in RCache with link0, shouldn't have returned NULL"); + fail_if(pico_nd_get_default_router(S) == r3, "Default router in RCache with link0, shouldn't have returned router with link1"); - /* Cleanup */ - pico_nd_delete_entry(n0); - pico_nd_delete_entry(n1); - pico_nd_delete_entry(n2); - pico_nd_delete_entry(n3); - pico_device_destroy(dummy_dev); + /* Cleanup */ + pico_nd_delete_entry(n0); + pico_nd_delete_entry(n1); + pico_nd_delete_entry(n2); + pico_nd_delete_entry(n3); + pico_device_destroy(dummy_dev); } END_TEST START_TEST(tc_pico_ipv6_set_router_link) { - struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }, r3 = { 0 }; - struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }, n3 = { 0 }; - struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; - char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; - char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; - char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; - char ipstr3[] = "2001:8:130f:0000:0000:09c0:876a:130b"; - struct pico_device *dev = NULL; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dev = pico_null_create(S, "dummy"); - - link0.dev = dev; - link1.dev = dev; - - /* Setup of routers */ - r0.router = &n0; - r1.router = &n1; - r2.router = &n2; - r3.router = &n3; - pico_string_to_ipv6(ipstr0, r0.router->address.addr); - pico_string_to_ipv6(ipstr1, r1.router->address.addr); - pico_string_to_ipv6(ipstr2, r2.router->address.addr); - pico_string_to_ipv6(ipstr3, r3.router->address.addr); - - /* NULL arg */ - pico_ipv6_set_router_link(NULL, &link0); - - /* No routers in RCache */ - pico_ipv6_set_router_link(&r0.router->address, &link0); - - fail_if(r0.link == &link0, "Router not yet in RCache, link should not have been set"); - - /* Routers in RCache */ - pico_tree_insert(&S->IPV6RCache, &r0); - pico_tree_insert(&S->IPV6RCache, &r1); - pico_tree_insert(&S->IPV6RCache, &r2); - pico_tree_insert(&S->IPV6RCache, &r3); - - /* Setting router links */ - pico_ipv6_set_router_link(&r0.router->address, &link0); - pico_ipv6_set_router_link(&r1.router->address, &link1); - pico_ipv6_set_router_link(&r2.router->address, &link0); - pico_ipv6_set_router_link(&r3.router->address, &link1); - - fail_if(r0.link != &link0, "Router in RCache, link should have been set"); - fail_if(r1.link != &link1, "Router in RCache, link should have been set"); - fail_if(r2.link != &link0, "Router in RCache, link should have been set"); - fail_if(r3.link != &link1, "Router in RCache, link should have been set"); - - /* Cleanup */ - pico_tree_delete(&S->IPV6RCache, &r0); - pico_tree_delete(&S->IPV6RCache, &r1); - pico_tree_delete(&S->IPV6RCache, &r2); - pico_tree_delete(&S->IPV6RCache, &r3); + struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }, r3 = { 0 }; + struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }, n3 = { 0 }; + struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; + char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; + char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; + char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; + char ipstr3[] = "2001:8:130f:0000:0000:09c0:876a:130b"; + struct pico_device *dev = NULL; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + dev = pico_null_create(S, "dummy"); + + link0.dev = dev; + link1.dev = dev; + + /* Setup of routers */ + r0.router = &n0; + r1.router = &n1; + r2.router = &n2; + r3.router = &n3; + pico_string_to_ipv6(ipstr0, r0.router->address.addr); + pico_string_to_ipv6(ipstr1, r1.router->address.addr); + pico_string_to_ipv6(ipstr2, r2.router->address.addr); + pico_string_to_ipv6(ipstr3, r3.router->address.addr); + + /* NULL arg */ + pico_ipv6_set_router_link(NULL, &link0); + + /* No routers in RCache */ + pico_ipv6_set_router_link(&r0.router->address, &link0); + + fail_if(r0.link == &link0, "Router not yet in RCache, link should not have been set"); + + /* Routers in RCache */ + pico_tree_insert(&S->IPV6RCache, &r0); + pico_tree_insert(&S->IPV6RCache, &r1); + pico_tree_insert(&S->IPV6RCache, &r2); + pico_tree_insert(&S->IPV6RCache, &r3); + + /* Setting router links */ + pico_ipv6_set_router_link(&r0.router->address, &link0); + pico_ipv6_set_router_link(&r1.router->address, &link1); + pico_ipv6_set_router_link(&r2.router->address, &link0); + pico_ipv6_set_router_link(&r3.router->address, &link1); + + fail_if(r0.link != &link0, "Router in RCache, link should have been set"); + fail_if(r1.link != &link1, "Router in RCache, link should have been set"); + fail_if(r2.link != &link0, "Router in RCache, link should have been set"); + fail_if(r3.link != &link1, "Router in RCache, link should have been set"); + + /* Cleanup */ + pico_tree_delete(&S->IPV6RCache, &r0); + pico_tree_delete(&S->IPV6RCache, &r1); + pico_tree_delete(&S->IPV6RCache, &r2); + pico_tree_delete(&S->IPV6RCache, &r3); } END_TEST START_TEST(tc_pico_ipv6_set_router_mtu) { - struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }, r3 = { 0 }; - struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }, n3 = { 0 }; - struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; - uint32_t r0_mtu = 1500, r1_mtu = 2000, r2_mtu = 2500, r3_mtu = 3000; - char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; - char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; - char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; - char ipstr3[] = "2001:8:130f:0000:0000:09c0:876a:130b"; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - /* Setup of routers */ - r0.router = &n0; - r1.router = &n1; - r2.router = &n2; - r3.router = &n3; - /* Setting router links */ - r0.link = &link0; - r1.link = &link0; - r2.link = &link0; - r3.link = &link1; /* One router with different link */ - pico_string_to_ipv6(ipstr0, r0.router->address.addr); - pico_string_to_ipv6(ipstr1, r1.router->address.addr); - pico_string_to_ipv6(ipstr2, r2.router->address.addr); - pico_string_to_ipv6(ipstr3, r3.router->address.addr); - - /* NULL args */ - pico_ipv6_set_router_mtu(S, NULL, 0); - - /* No routers in RCache */ - pico_ipv6_set_router_mtu(S, &r0.router->address, r0_mtu); - - fail_if(r0.link->mtu == r0_mtu, "Router not yet in RCache, mtu should not have been set"); - - /* Routers in RCache */ - pico_tree_insert(&S->IPV6RCache, &r0); - pico_tree_insert(&S->IPV6RCache, &r1); - pico_tree_insert(&S->IPV6RCache, &r2); - pico_tree_insert(&S->IPV6RCache, &r3); - - /* Setting router mtu */ - /* TODO: should link->mtu change if we change mtu of non-default router? */ - pico_ipv6_set_router_mtu(S, &r0.router->address, r0_mtu); - fail_if(r0.link->mtu != r0_mtu, "Router in RCache, mtu should have been set"); - pico_ipv6_set_router_mtu(S, &r1.router->address, r1_mtu); - fail_if(r1.link->mtu != r1_mtu, "Router in RCache, mtu should have been set"); - pico_ipv6_set_router_mtu(S, &r2.router->address, r2_mtu); - fail_if(r2.link->mtu != r2_mtu, "Router in RCache, mtu should have been set"); - pico_ipv6_set_router_mtu(S, &r3.router->address, r3_mtu); - fail_if(r3.link->mtu != r3_mtu, "Router in RCache, mtu should have been set"); - /* r3 and r2 have different links so setting mtu for r3 shouldn't affect r2 */ - fail_if(r2.link->mtu != r2_mtu, "Router in RCache, mtu should have been set"); - - /* Cleanup */ - pico_tree_delete(&S->IPV6RCache, &r0); - pico_tree_delete(&S->IPV6RCache, &r1); - pico_tree_delete(&S->IPV6RCache, &r2); - pico_tree_delete(&S->IPV6RCache, &r3); + struct pico_ipv6_router r0 = { 0 }, r1 = { 0 }, r2 = { 0 }, r3 = { 0 }; + struct pico_ipv6_neighbor n0 = { 0 }, n1 = { 0 }, n2 = { 0 }, n3 = { 0 }; + struct pico_ipv6_link link0 = { 0 }, link1 = { 0 }; + uint32_t r0_mtu = 1500, r1_mtu = 2000, r2_mtu = 2500, r3_mtu = 3000; + char ipstr0[] = "2001:0db8:130f:0000:0000:09c0:876a:130b"; + char ipstr1[] = "2001:1db8:130f:0000:0000:09c0:876a:130b"; + char ipstr2[] = "2001:b8:130f:0000:0000:09c0:876a:130b"; + char ipstr3[] = "2001:8:130f:0000:0000:09c0:876a:130b"; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + /* Setup of routers */ + r0.router = &n0; + r1.router = &n1; + r2.router = &n2; + r3.router = &n3; + /* Setting router links */ + r0.link = &link0; + r1.link = &link0; + r2.link = &link0; + r3.link = &link1; /* One router with different link */ + pico_string_to_ipv6(ipstr0, r0.router->address.addr); + pico_string_to_ipv6(ipstr1, r1.router->address.addr); + pico_string_to_ipv6(ipstr2, r2.router->address.addr); + pico_string_to_ipv6(ipstr3, r3.router->address.addr); + + /* NULL args */ + pico_ipv6_set_router_mtu(S, NULL, 0); + + /* No routers in RCache */ + pico_ipv6_set_router_mtu(S, &r0.router->address, r0_mtu); + + fail_if(r0.link->mtu == r0_mtu, "Router not yet in RCache, mtu should not have been set"); + + /* Routers in RCache */ + pico_tree_insert(&S->IPV6RCache, &r0); + pico_tree_insert(&S->IPV6RCache, &r1); + pico_tree_insert(&S->IPV6RCache, &r2); + pico_tree_insert(&S->IPV6RCache, &r3); + + /* Setting router mtu */ + /* TODO: should link->mtu change if we change mtu of non-default router? */ + pico_ipv6_set_router_mtu(S, &r0.router->address, r0_mtu); + fail_if(r0.link->mtu != r0_mtu, "Router in RCache, mtu should have been set"); + pico_ipv6_set_router_mtu(S, &r1.router->address, r1_mtu); + fail_if(r1.link->mtu != r1_mtu, "Router in RCache, mtu should have been set"); + pico_ipv6_set_router_mtu(S, &r2.router->address, r2_mtu); + fail_if(r2.link->mtu != r2_mtu, "Router in RCache, mtu should have been set"); + pico_ipv6_set_router_mtu(S, &r3.router->address, r3_mtu); + fail_if(r3.link->mtu != r3_mtu, "Router in RCache, mtu should have been set"); + /* r3 and r2 have different links so setting mtu for r3 shouldn't affect r2 */ + fail_if(r2.link->mtu != r2_mtu, "Router in RCache, mtu should have been set"); + + /* Cleanup */ + pico_tree_delete(&S->IPV6RCache, &r0); + pico_tree_delete(&S->IPV6RCache, &r1); + pico_tree_delete(&S->IPV6RCache, &r2); + pico_tree_delete(&S->IPV6RCache, &r3); } END_TEST static int frame_in_queued_frames(struct pico_stack *S, struct pico_frame *f) { - struct pico_tree_node *index = NULL; - struct pico_frame *frame = NULL; - int occurrences = 0; + struct pico_tree_node *index = NULL; + struct pico_frame *frame = NULL; + int occurrences = 0; - pico_tree_foreach(index,&S->IPV6NQueue) { - frame = index->keyValue; - if (memcmp(frame, f, sizeof(*f)) == 0) { - occurrences++; + pico_tree_foreach(index, &S->IPV6NQueue) { + frame = index->keyValue; + if (memcmp(frame, f, sizeof(*f)) == 0) { + occurrences++; + } } - } - return occurrences; + return occurrences; } START_TEST(tc_pico_ipv6_nd_postpone) { - struct pico_frame *frames[PICO_ND_MAX_FRAMES_QUEUED * 2] = { 0 }; - struct pico_ipv6_hdr hdrs[sizeof(frames)/sizeof(frames[0])] = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_ip6 addr_1 = { - .addr = { - 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b - } - }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - int i = 0; - struct pico_ipv6_neighbor *n0, *n1; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - - /* - * Init frames - */ - - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); - frames[i]->timestamp = (pico_time)i; - frames[i]->net_hdr = (uint8_t *)&hdrs[i]; - hdrs[i].dst = addr_0; - } - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); - fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); - - { + struct pico_frame *frames[PICO_ND_MAX_FRAMES_QUEUED * 2] = { 0 }; + struct pico_ipv6_hdr hdrs[sizeof(frames) / sizeof(frames[0])] = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_ip6 addr_1 = { + .addr = { + 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b + } + }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + int i = 0; + struct pico_ipv6_neighbor *n0, *n1; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); + /* - * First testcase: - * - No NCE yet - * - Postpone MAX frames - * - Postpone MAX frames again (check if overwritten properly) + * Init frames */ - /* Postpone first PICO_ND_MAX_FRAMES_QUEUED */ - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - pico_ipv6_nd_postpone(S, frames[i]); + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); + frames[i]->timestamp = (pico_time)i; + frames[i]->net_hdr = (uint8_t *)&hdrs[i]; + hdrs[i].dst = addr_0; } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); + fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should just be in queued frames tree once"); + { + /* + * First testcase: + * - No NCE yet + * - Postpone MAX frames + * - Postpone MAX frames again (check if overwritten properly) + */ + + /* Postpone first PICO_ND_MAX_FRAMES_QUEUED */ + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + pico_ipv6_nd_postpone(S, frames[i]); + } + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should just be in queued frames tree once"); + } + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); + } + /* Postpone next PICO_ND_MAX_FRAMES_QUEUED */ + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + pico_ipv6_nd_postpone(S, frames[i]); + } + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); + } + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree only once"); + } + n0 = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n0->address = addr_0; + n0->stack = S; + pico_nd_delete_entry(n0); } - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); + fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); + + { + /* + * Second testcase: + * - multiple NCEs already exists + * - Postpone MAX frames for NCE 1 + * - Postpone MAX frames for NCE 2 + */ + n0 = pico_nd_create_entry(S, &addr_0, dummy_dev); + n1 = pico_nd_create_entry(S, &addr_1, dummy_dev); + + fail_if(n0 == NULL); + fail_if(n1 == NULL); + + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + hdrs[i].dst = addr_0; + } + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + hdrs[i].dst = addr_1; + } + /* Postpone all frames */ + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + pico_ipv6_nd_postpone(S, frames[i]); + } + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + } + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + } + pico_nd_delete_entry(n0); + pico_nd_delete_entry(n1); } - /* Postpone next PICO_ND_MAX_FRAMES_QUEUED */ - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - pico_ipv6_nd_postpone(S, frames[i]); + /* Cleanup */ + pico_device_destroy(dummy_dev); + + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + pico_frame_discard(frames[i]); + } +} +END_TEST +START_TEST(tc_pico_nd_clear_queued_packets) +{ + struct pico_frame *frames[2 * PICO_ND_MAX_FRAMES_QUEUED] = { 0 }; + struct pico_ipv6_hdr hdrs[sizeof(frames) / sizeof(frames[0])] = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_ip6 addr_1 = { + .addr = { + 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b + } + }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + int i = 0; + struct pico_ipv6_neighbor *n0, *n1; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); + + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); + + /* + * Init frames + */ + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); + frames[i]->timestamp = (pico_time)i; + frames[i]->net_hdr = (uint8_t *)&hdrs[i]; + if (i < PICO_ND_MAX_FRAMES_QUEUED) { + hdrs[i].dst = addr_0; + } else { + hdrs[i].dst = addr_1; + } + pico_tree_insert(&S->IPV6NQueue, frames[i]); } + fail_if(pico_tree_empty(&S->IPV6NQueue), "Test started, tree shouldn't be empty!"); for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); } - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree only once"); + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); } - n0 = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); n0->address = addr_0; n0->stack = S; - pico_nd_delete_entry(n0); - } + pico_nd_clear_queued_packets(n0); + + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + } + n1 = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n1->address = addr_1; + n1->stack = S; + pico_nd_clear_queued_packets(n1); + + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test is done, tree should be empty!"); - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); - fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); + pico_device_destroy(dummy_dev); + + /* If a packet is not freed properly, asan should complain */ +} +END_TEST +START_TEST(tc_pico_ipv6_nd_trigger_queued_packets) +{ + struct pico_frame *frames[2 * PICO_ND_MAX_FRAMES_QUEUED] = { 0 }; + struct pico_ipv6_hdr hdrs[sizeof(frames) / sizeof(frames[0])] = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_ip6 addr_1 = { + .addr = { + 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b + } + }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + int i = 0; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); + + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); - { /* - * Second testcase: - * - multiple NCEs already exists - * - Postpone MAX frames for NCE 1 - * - Postpone MAX frames for NCE 2 + * Init frames */ - n0 = pico_nd_create_entry(S, &addr_0, dummy_dev); - n1 = pico_nd_create_entry(S, &addr_1, dummy_dev); - - fail_if(n0 == NULL); - fail_if(n1 == NULL); + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); + frames[i]->timestamp = (pico_time)i; + frames[i]->net_hdr = (uint8_t *)&hdrs[i]; + if (i < PICO_ND_MAX_FRAMES_QUEUED) { + hdrs[i].dst = addr_0; + } else { + hdrs[i].dst = addr_1; + } + pico_tree_insert(&S->IPV6NQueue, frames[i]); + } + fail_if(pico_tree_empty(&S->IPV6NQueue), "Test started, tree shouldn't be empty!"); for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - hdrs[i].dst = addr_0; + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); } - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - hdrs[i].dst = addr_1; + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); } + pico_nd_trigger_queued_packets(S, &addr_0); - /* Postpone all frames */ - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - pico_ipv6_nd_postpone(S, frames[i]); + for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); } + for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + } + pico_nd_trigger_queued_packets(S, &addr_1); for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); } - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); + fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test is done, tree should be empty!"); - pico_nd_delete_entry(n0); - pico_nd_delete_entry(n1); - } - - /* Cleanup */ - pico_device_destroy(dummy_dev); + pico_device_destroy(dummy_dev); - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - pico_frame_discard(frames[i]); - } + for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { + pico_frame_discard(frames[i]); + } } END_TEST -START_TEST(tc_pico_nd_clear_queued_packets) +START_TEST(tc_pico_nd_create_entry) { - struct pico_frame *frames[2 * PICO_ND_MAX_FRAMES_QUEUED] = { 0 }; - struct pico_ipv6_hdr hdrs[sizeof(frames)/sizeof(frames[0])] = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_ip6 addr_1 = { - .addr = { - 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b - } - }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - int i = 0; - struct pico_ipv6_neighbor *n0, *n1; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); - - /* - * Init frames - */ - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); - frames[i]->timestamp = (pico_time)i; - frames[i]->net_hdr = (uint8_t *)&hdrs[i]; - if (i < PICO_ND_MAX_FRAMES_QUEUED) { - hdrs[i].dst = addr_0; - } else { - hdrs[i].dst = addr_1; - } - pico_tree_insert(&S->IPV6NQueue, frames[i]); - } +#define NUMBER_OF_NEIGHBORS (3) + struct pico_ipv6_neighbor *n = NULL; + struct pico_ip6 addr[NUMBER_OF_NEIGHBORS]; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + int number_of_nce = 0, number_of_valid_nce = 0; + struct pico_tree_node *index = NULL, *_tmp = NULL; + int i = 0; + pico_time expected; + struct pico_stack *S = NULL; + + pico_stack_init(&S); - fail_if(pico_tree_empty(&S->IPV6NQueue), "Test started, tree shouldn't be empty!"); + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + /* Failing malloc */ + pico_set_mm_failure(1); + fail_if(pico_nd_create_entry(S, &addr[i], dummy_dev) != NULL, "Created entry but malloc failed, should have returned NULL?"); - n0 = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n0->address = addr_0; - n0->stack = S; - pico_nd_clear_queued_packets(n0); + /* Sanity check, tree must still be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "Test started, but attempt to create NCE failed, tree should still be empty"); - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + addr[i].addr[0] = (uint8_t)i; + pico_nd_create_entry(S, &addr[i], dummy_dev); + } + expected = PICO_TIME_MS() + ONE_MINUTE_MS; - n1 = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n1->address = addr_1; - n1->stack = S; - pico_nd_clear_queued_packets(n1); + pico_tree_foreach(index, &S->IPV6NCache) { + n = index->keyValue; - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test is done, tree should be empty!"); + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + if (pico_ipv6_compare(&n->address, &addr[i]) == 0) { + if (n->dev == dummy_dev && n->state == PICO_ND_STATE_INCOMPLETE && TIME_CHECK(n->expire, expected)) { + number_of_valid_nce++; + } + } + } + number_of_nce++; + } - pico_device_destroy(dummy_dev); + fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "We created NCEs, should be in the NCache tree"); + fail_unless(number_of_valid_nce == NUMBER_OF_NEIGHBORS, "We created NCEs, should all be in the NCache tree"); - /* If a packet is not freed properly, asan should complain */ + /* Cleanup */ + pico_device_destroy(dummy_dev); + pico_tree_foreach_safe(index, &S->IPV6NCache, _tmp) + { + n = index->keyValue; + pico_tree_delete(&S->IPV6NCache, n); + PICO_FREE(n); + } + + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "End of test, NCache should be empty"); } END_TEST -START_TEST(tc_pico_ipv6_nd_trigger_queued_packets) +START_TEST(tc_pico_nd_delete_entry) { - struct pico_frame *frames[2 * PICO_ND_MAX_FRAMES_QUEUED] = { 0 }; - struct pico_ipv6_hdr hdrs[sizeof(frames)/sizeof(frames[0])] = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_ip6 addr_1 = { - .addr = { - 0x21, 0x21, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x1b - } - }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - int i = 0; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, tree should be empty!"); - - /* - * Init frames - */ - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); - frames[i]->timestamp = (pico_time)i; - frames[i]->net_hdr = (uint8_t *)&hdrs[i]; - if (i < PICO_ND_MAX_FRAMES_QUEUED) { - hdrs[i].dst = addr_0; - } else { - hdrs[i].dst = addr_1; - } - pico_tree_insert(&S->IPV6NQueue, frames[i]); - } +#define NUMBER_OF_NEIGHBORS (3) + struct pico_ipv6_neighbor *neighbors[NUMBER_OF_NEIGHBORS] = { 0 }; + struct pico_ipv6_router *routers[NUMBER_OF_NEIGHBORS] = { 0 }; + struct pico_frame *frames[NUMBER_OF_NEIGHBORS] = { 0 }; + struct pico_ipv6_hdr hdrs[NUMBER_OF_NEIGHBORS] = { 0 }; + struct pico_ip6 addr[NUMBER_OF_NEIGHBORS] = { 0 }; + struct pico_tree_node *index = NULL; + int i = 0, number_of_nce = 0, number_of_rce = 0, number_of_frames = 0; + + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + struct pico_stack *S = NULL; - fail_if(pico_tree_empty(&S->IPV6NQueue), "Test started, tree shouldn't be empty!"); + pico_stack_init(&S); - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, no RCE should exist"); + fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, no queued frames should exist"); - pico_nd_trigger_queued_packets(S, &addr_0); + /* Test 1 + * Create NUMBER_OF_NEIGHBORS NCE entries, then delete them + */ + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + addr[i].addr[0] = (uint8_t)i; + neighbors[i]->address = addr[i]; + neighbors[i]->stack = S; - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); - } + pico_tree_insert(&S->IPV6NCache, neighbors[i]); + } + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + pico_nd_delete_entry(neighbors[i]); + } + pico_tree_foreach(index, &S->IPV6NCache) + { + number_of_nce++; + } - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 1, "Frame should be in queued frames tree"); - } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE created and deleted, NCache should be empty"); + fail_if(number_of_nce, "All NCE should have been deleted"); - pico_nd_trigger_queued_packets(S, &addr_1); + /* Reset */ + number_of_nce = 0; + number_of_rce = 0; - for (i = 0; i < PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); - } + /* Test 2 + * Create NUMBER_OF_NEIGHBORS NCE, + * Also create some RCE + * then delete them + */ + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + routers[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - for (i = PICO_ND_MAX_FRAMES_QUEUED; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - fail_unless(frame_in_queued_frames(S, frames[i]) == 0, "Frame shouldn't be in queued frames tree"); - } + routers[i]->router = neighbors[i]; - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test is done, tree should be empty!"); + addr[i].addr[0] = (uint8_t)i; + neighbors[i]->address = addr[i]; + neighbors[i]->is_router = 1; + neighbors[i]->stack = S; - pico_device_destroy(dummy_dev); + pico_tree_insert(&S->IPV6NCache, neighbors[i]); + pico_tree_insert(&S->IPV6RCache, routers[i]); + } + pico_tree_foreach(index, &S->IPV6NCache) + { + number_of_nce++; + } + pico_tree_foreach(index, &S->IPV6RCache) + { + number_of_rce++; + } - for (i = 0; i < 2 * PICO_ND_MAX_FRAMES_QUEUED; ++i) { - pico_frame_discard(frames[i]); - } -} -END_TEST -START_TEST(tc_pico_nd_create_entry) -{ -#define NUMBER_OF_NEIGHBORS (3) - struct pico_ipv6_neighbor *n = NULL; - struct pico_ip6 addr[NUMBER_OF_NEIGHBORS]; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - int number_of_nce = 0, number_of_valid_nce = 0; - struct pico_tree_node *index = NULL, *_tmp = NULL; - int i = 0; - pico_time expected; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); - - /* Failing malloc */ - pico_set_mm_failure(1); - fail_if(pico_nd_create_entry(S, &addr[i], dummy_dev) != NULL, "Created entry but malloc failed, should have returned NULL?"); - - /* Sanity check, tree must still be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "Test started, but attempt to create NCE failed, tree should still be empty"); - - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - addr[i].addr[0] = (uint8_t)i; - pico_nd_create_entry(S, &addr[i], dummy_dev); - } - expected = PICO_TIME_MS() + ONE_MINUTE_MS; - - pico_tree_foreach(index,&S->IPV6NCache) { - n = index->keyValue; + fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "NCEs should have been created"); + fail_unless(number_of_rce == NUMBER_OF_NEIGHBORS, "RCEs should have been created"); for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - if (pico_ipv6_compare(&n->address, &addr[i]) == 0) { - if (n->dev == dummy_dev && n->state == PICO_ND_STATE_INCOMPLETE && TIME_CHECK(n->expire, expected)) { - number_of_valid_nce++; - } - } + pico_nd_delete_entry(neighbors[i]); } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE created and deleted, NCache should be empty"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE created and deleted, NCache should be empty"); + + /* Reset */ + number_of_nce = 0; + number_of_rce = 0; + + /* Test 3 + * Create NUMBER_OF_NEIGHBORS NCE, + * Also create some queued frames + * then delete NCE + */ - number_of_nce++; - } + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "We created NCEs, should be in the NCache tree"); - fail_unless(number_of_valid_nce == NUMBER_OF_NEIGHBORS, "We created NCEs, should all be in the NCache tree"); + addr[i].addr[0] = (uint8_t)i; + neighbors[i]->address = addr[i]; + neighbors[i]->stack = S; - /* Cleanup */ - pico_device_destroy(dummy_dev); - pico_tree_foreach_safe(index, &S->IPV6NCache, _tmp) - { - n = index->keyValue; - pico_tree_delete(&S->IPV6NCache, n); - PICO_FREE(n); - } + pico_tree_insert(&S->IPV6NCache, neighbors[i]); - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "End of test, NCache should be empty"); -} -END_TEST -START_TEST(tc_pico_nd_delete_entry) -{ -#define NUMBER_OF_NEIGHBORS (3) - struct pico_ipv6_neighbor *neighbors[NUMBER_OF_NEIGHBORS] = { 0 }; - struct pico_ipv6_router *routers[NUMBER_OF_NEIGHBORS] = { 0 }; - struct pico_frame *frames[NUMBER_OF_NEIGHBORS] = { 0 }; - struct pico_ipv6_hdr hdrs[NUMBER_OF_NEIGHBORS] = { 0 }; - struct pico_ip6 addr[NUMBER_OF_NEIGHBORS] = { 0 }; - struct pico_tree_node *index = NULL; - int i = 0, number_of_nce = 0, number_of_rce = 0, number_of_frames = 0; - - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "Test hasn't started, no NCE should exist"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, no RCE should exist"); - fail_unless(pico_tree_empty(&S->IPV6NQueue), "Test hasn't started, no queued frames should exist"); - - /* Test 1 - * Create NUMBER_OF_NEIGHBORS NCE entries, then delete them - */ - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - addr[i].addr[0] = (uint8_t)i; - neighbors[i]->address = addr[i]; - neighbors[i]->stack = S; - - pico_tree_insert(&S->IPV6NCache, neighbors[i]); - } - - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - pico_nd_delete_entry(neighbors[i]); - } - - pico_tree_foreach(index, &S->IPV6NCache) - { - number_of_nce++; - } - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE created and deleted, NCache should be empty"); - fail_if(number_of_nce, "All NCE should have been deleted"); - - /* Reset */ - number_of_nce = 0; - number_of_rce = 0; - - /* Test 2 - * Create NUMBER_OF_NEIGHBORS NCE, - * Also create some RCE - * then delete them - */ - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - routers[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - - routers[i]->router = neighbors[i]; - - addr[i].addr[0] = (uint8_t)i; - neighbors[i]->address = addr[i]; - neighbors[i]->is_router = 1; - neighbors[i]->stack = S; - - pico_tree_insert(&S->IPV6NCache, neighbors[i]); - pico_tree_insert(&S->IPV6RCache, routers[i]); - } - - pico_tree_foreach(index, &S->IPV6NCache) - { - number_of_nce++; - } - pico_tree_foreach(index, &S->IPV6RCache) - { - number_of_rce++; - } - - fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "NCEs should have been created"); - fail_unless(number_of_rce == NUMBER_OF_NEIGHBORS, "RCEs should have been created"); - - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - pico_nd_delete_entry(neighbors[i]); - } - - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE created and deleted, NCache should be empty"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE created and deleted, NCache should be empty"); - - /* Reset */ - number_of_nce = 0; - number_of_rce = 0; - - /* Test 3 - * Create NUMBER_OF_NEIGHBORS NCE, - * Also create some queued frames - * then delete NCE - */ - - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - neighbors[i] = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - - addr[i].addr[0] = (uint8_t)i; - neighbors[i]->address = addr[i]; - neighbors[i]->stack = S; - - pico_tree_insert(&S->IPV6NCache, neighbors[i]); + frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); + frames[i]->timestamp = (pico_time)i; + frames[i]->net_hdr = (uint8_t *)&hdrs[i]; + hdrs[i].dst = addr[i]; - frames[i] = pico_proto_ipv6.alloc(S, &pico_proto_ipv6, dummy_dev, 1); - frames[i]->timestamp = (pico_time)i; - frames[i]->net_hdr = (uint8_t *)&hdrs[i]; - hdrs[i].dst = addr[i]; - - pico_tree_insert(&S->IPV6NQueue, frames[i]); - } - - pico_tree_foreach(index, &S->IPV6NCache) - { - number_of_nce++; - } - - pico_tree_foreach(index, &S->IPV6NQueue) - { - number_of_frames++; - } + pico_tree_insert(&S->IPV6NQueue, frames[i]); + } + pico_tree_foreach(index, &S->IPV6NCache) + { + number_of_nce++; + } - fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "NCEs should have been created"); - fail_unless(number_of_frames == NUMBER_OF_NEIGHBORS, "Frames should be in Queue tree"); + pico_tree_foreach(index, &S->IPV6NQueue) + { + number_of_frames++; + } - for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { - pico_nd_delete_entry(neighbors[i]); - } + fail_unless(number_of_nce == NUMBER_OF_NEIGHBORS, "NCEs should have been created"); + fail_unless(number_of_frames == NUMBER_OF_NEIGHBORS, "Frames should be in Queue tree"); - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "All NCEs should have been deleted"); - fail_unless(pico_tree_empty(&S->IPV6NQueue), "All queued frames should have been deleted"); + for (i = 0; i < NUMBER_OF_NEIGHBORS; ++i) { + pico_nd_delete_entry(neighbors[i]); + } + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "All NCEs should have been deleted"); + fail_unless(pico_tree_empty(&S->IPV6NQueue), "All queued frames should have been deleted"); - pico_device_destroy(dummy_dev); + pico_device_destroy(dummy_dev); } END_TEST START_TEST(tc_pico_nd_create_rce) { - struct pico_ipv6_neighbor *n = NULL; - struct pico_ipv6_router *r = NULL; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor *n = NULL; + struct pico_ipv6_router *r = NULL; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - /* Test 1: NULL args */ - fail_unless(pico_nd_create_rce(NULL) == NULL, "Providing NULL should return NULL"); + /* Test 1: NULL args */ + fail_unless(pico_nd_create_rce(NULL) == NULL, "Providing NULL should return NULL"); - /* Test 2: Normal case */ - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); + /* Test 2: Normal case */ + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n->stack = S; + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n->stack = S; - r = pico_nd_create_rce(n); + r = pico_nd_create_rce(n); - fail_unless(r, "RCE should have been created"); - fail_unless(n->is_router, "is_router flag should have been set"); - fail_if(pico_tree_empty(&S->IPV6RCache), "Test done, RCE should have been created"); + fail_unless(r, "RCE should have been created"); + fail_unless(n->is_router, "is_router flag should have been set"); + fail_if(pico_tree_empty(&S->IPV6RCache), "Test done, RCE should have been created"); - /* Cleanup */ - pico_tree_delete(&S->IPV6RCache, r); - PICO_FREE(r); - n->is_router = 0; + /* Cleanup */ + pico_tree_delete(&S->IPV6RCache, r); + PICO_FREE(r); + n->is_router = 0; - /* Test 3: Malloc failure - 1 */ - pico_set_mm_failure(1); + /* Test 3: Malloc failure - 1 */ + pico_set_mm_failure(1); - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); - r = pico_nd_create_rce(n); + r = pico_nd_create_rce(n); - fail_if(r, "RCE shouldn't have been created"); - fail_if(n->is_router, "is_router flag shouldn't have been set"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, RCE shouldn't have been created"); + fail_if(r, "RCE shouldn't have been created"); + fail_if(n->is_router, "is_router flag shouldn't have been set"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, RCE shouldn't have been created"); - /* Cleanup */ - n->is_router = 0; + /* Cleanup */ + n->is_router = 0; - /* Test 4: Malloc failure - 2 */ - pico_set_mm_failure(2); + /* Test 4: Malloc failure - 2 */ + pico_set_mm_failure(2); - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); - r = pico_nd_create_rce(n); + r = pico_nd_create_rce(n); - fail_if(n->is_router, "is_router flag shouldn't have been set"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, RCE shouldn't have been created"); + fail_if(n->is_router, "is_router flag shouldn't have been set"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, RCE shouldn't have been created"); - PICO_FREE(n); + PICO_FREE(n); } END_TEST START_TEST(tc_pico_nd_delete_rce) { - struct pico_ipv6_neighbor *n = NULL; - struct pico_ipv6_router *r = NULL; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor *n = NULL; + struct pico_ipv6_router *r = NULL; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - /* Test 1: NULL args - * This mustn't produce any side-effects - */ - pico_nd_delete_rce(NULL); + /* Test 1: NULL args + * This mustn't produce any side-effects + */ + pico_nd_delete_rce(NULL); - /* Test 2: Normal case */ - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); + /* Test 2: Normal case */ + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, tree should be empty"); - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - r = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + r = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r->router = n; - n->is_router = 1; - n->stack = S; - pico_tree_insert(&S->IPV6RCache, r); + r->router = n; + n->is_router = 1; + n->stack = S; + pico_tree_insert(&S->IPV6RCache, r); - /* Sanity check */ - fail_if(pico_tree_empty(&S->IPV6RCache), "Test started, RCE should have been created"); + /* Sanity check */ + fail_if(pico_tree_empty(&S->IPV6RCache), "Test started, RCE should have been created"); - pico_nd_delete_rce(r); + pico_nd_delete_rce(r); - fail_if(n->is_router, "is_router flag should have been cleared"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, tree should be empty"); + fail_if(n->is_router, "is_router flag should have been cleared"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test done, tree should be empty"); - PICO_FREE(n); + PICO_FREE(n); } END_TEST START_TEST(tc_pico_nd_discover) { - /* TODO: */ - /* TODO: test this: static void pico_nd_discover(struct pico_ipv6_neighbor *n) */ + /* TODO: */ + /* TODO: test this: static void pico_nd_discover(struct pico_ipv6_neighbor *n) */ } END_TEST START_TEST(tc_pico_nd_get_neighbor) { - /* TODO: */ - /* TODO: test this: static struct pico_eth *pico_nd_get_neighbor(struct pico_ip6 *addr, struct pico_device *dev) */ + /* TODO: */ + /* TODO: test this: static struct pico_eth *pico_nd_get_neighbor(struct pico_ip6 *addr, struct pico_device *dev) */ } END_TEST START_TEST(tc_pico_nd_get) { - /* TODO: test this: static struct pico_eth *pico_nd_get(struct pico_ip6 *address, struct pico_device *dev) */ + /* TODO: test this: static struct pico_eth *pico_nd_get(struct pico_ip6 *address, struct pico_device *dev) */ } END_TEST START_TEST(tc_pico_nd_get_length_of_options) { - struct pico_frame a = { 0 }; - struct pico_icmp6_hdr a_hdr = { 0 }; - uint8_t *option = NULL; - const uint16_t dummy_transport_len = sizeof(*(&a_hdr)); + struct pico_frame a = { 0 }; + struct pico_icmp6_hdr a_hdr = { 0 }; + uint8_t *option = NULL; + const uint16_t dummy_transport_len = sizeof(*(&a_hdr)); - /* Init */ - a.transport_hdr = (uint8_t *)&a_hdr; - a.transport_len = dummy_transport_len; + /* Init */ + a.transport_hdr = (uint8_t *)&a_hdr; + a.transport_len = dummy_transport_len; - a_hdr.type = PICO_ICMP6_ROUTER_SOL; - fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_SOL_SIZE); - fail_unless(option == (uint8_t *)&(a_hdr.msg.info.router_sol) + sizeof(struct router_sol_s)); + a_hdr.type = PICO_ICMP6_ROUTER_SOL; + fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_SOL_SIZE); + fail_unless(option == (uint8_t *)&(a_hdr.msg.info.router_sol) + sizeof(struct router_sol_s)); - a_hdr.type = PICO_ICMP6_ROUTER_ADV; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_ADV_SIZE); - fail_unless(option == (uint8_t *)&(a_hdr.msg.info.router_adv) + sizeof(struct router_adv_s)); + a_hdr.type = PICO_ICMP6_ROUTER_ADV; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_ADV_SIZE); + fail_unless(option == (uint8_t *)&(a_hdr.msg.info.router_adv) + sizeof(struct router_adv_s)); - a_hdr.type = PICO_ICMP6_NEIGH_SOL; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_NEIGH_SOL_SIZE); - fail_unless(option == (uint8_t *)&(a_hdr.msg.info.neigh_sol) + sizeof(struct neigh_sol_s)); + a_hdr.type = PICO_ICMP6_NEIGH_SOL; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_NEIGH_SOL_SIZE); + fail_unless(option == (uint8_t *)&(a_hdr.msg.info.neigh_sol) + sizeof(struct neigh_sol_s)); - a_hdr.type = PICO_ICMP6_NEIGH_ADV; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_NEIGH_ADV_SIZE); - fail_unless(option == (uint8_t *)&(a_hdr.msg.info.neigh_adv) + sizeof(struct neigh_adv_s)); + a_hdr.type = PICO_ICMP6_NEIGH_ADV; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_NEIGH_ADV_SIZE); + fail_unless(option == (uint8_t *)&(a_hdr.msg.info.neigh_adv) + sizeof(struct neigh_adv_s)); - a_hdr.type = PICO_ICMP6_REDIRECT; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_REDIRECT_SIZE); - fail_unless(option == (uint8_t *)&(a_hdr.msg.info.redirect) + sizeof(struct redirect_s)); + a_hdr.type = PICO_ICMP6_REDIRECT; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, &option) == dummy_transport_len - PICO_ICMP6HDR_REDIRECT_SIZE); + fail_unless(option == (uint8_t *)&(a_hdr.msg.info.redirect) + sizeof(struct redirect_s)); - a_hdr.type = 0; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, &option) == 0); - fail_unless(!option); + a_hdr.type = 0; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, &option) == 0); + fail_unless(!option); - /* test if we can just get the length of the options */ - a_hdr.type = PICO_ICMP6_ROUTER_SOL; - a.transport_len = dummy_transport_len; - fail_unless(pico_nd_get_length_of_options(&a, NULL) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_SOL_SIZE); + /* test if we can just get the length of the options */ + a_hdr.type = PICO_ICMP6_ROUTER_SOL; + a.transport_len = dummy_transport_len; + fail_unless(pico_nd_get_length_of_options(&a, NULL) == dummy_transport_len - PICO_ICMP6HDR_ROUTER_SOL_SIZE); } END_TEST START_TEST(tc_get_neigh_option) { - struct pico_frame *f = NULL; - struct pico_device *dummy_device = NULL; - struct pico_ipv6_hdr ipv6_hdr = { 0 }; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - const char router_addr_s[] = "fe80::200:ff:fe00:a0a0"; - struct pico_icmp6_opt_lladdr opt_lladdr = { - 0 - }; - struct pico_icmp6_opt_prefix opt_prefix = { - 0 - }; - struct pico_ip6 temp = { 0 }; - struct redirect_s opt_redirect = { 0 }; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - pico_string_to_ipv6(router_addr_s, ipv6_hdr.src.addr); - pico_string_to_ipv6(all_node_multicast_addr_s, ipv6_hdr.dst.addr); - ipv6_hdr.hop = 255; - - dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_device, name, mac); - - /* Setup */ - f = make_router_adv(dummy_device, PACKET_TYPE_NORMAL); - f->net_hdr = (uint8_t *)&ipv6_hdr; - f->net_len = sizeof(struct pico_ipv6_hdr); - - /* Get neigh options from our RA (which has LL addr option and prefix option) */ - fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) == 1, "our RA should have a valid LL addr option"); - fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) == 1, "our RA should have a valid prefix option"); - fail_unless(get_neigh_option(f, &opt_redirect, PICO_ND_OPT_REDIRECT) == 0, "our RA doesn't have a redirect option"); - - /* Check if ll addr is valid */ - /* len is stored as a number of bytes */ - fail_unless(opt_lladdr.type == PICO_ND_OPT_LLADDR_SRC, "We didn't extract the LL addr properly"); - fail_unless(opt_lladdr.len == sizeof(struct pico_icmp6_opt_lladdr) >> 3, "We didn't extract the LL addr option properly"); - fail_if(memcmp(&router_adv_mac, opt_lladdr.addr.data, pico_hw_addr_len(dummy_device, &opt_lladdr)), "We didn't extract the LL addr properly"); - - /* Check if prefix option is valid */ - fail_unless(opt_prefix.type == router_prefix_option.type); - fail_unless(opt_prefix.len == router_prefix_option.len); - fail_unless(opt_prefix.prefix_len == router_prefix_option.prefix_len); - fail_unless(opt_prefix.res == router_prefix_option.res); - fail_unless(opt_prefix.aac == router_prefix_option.aac); - fail_unless(opt_prefix.onlink == router_prefix_option.onlink); - fail_unless(opt_prefix.val_lifetime == router_prefix_option.val_lifetime); - fail_unless(opt_prefix.reserved == router_prefix_option.reserved); - - pico_string_to_ipv6(router_adv_prefix, temp.addr); - fail_unless(memcmp(&opt_prefix.prefix, &temp, sizeof(opt_prefix.prefix)) == 0); - - /* Cleanup */ - pico_frame_discard(f); - - /* Setup */ - f = make_router_adv(dummy_device, PACKET_TYPE_BAD_LEN); - f->net_hdr = (uint8_t *)&ipv6_hdr; - f->net_len = sizeof(struct pico_ipv6_hdr); - - /* Get neigh options from our RA (which has LL addr option and prefix option, one option has bad length field) */ - fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) < 0, "our RA has a bad len field, should have returned failure"); - fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) < 0, "our RA has a bad len field, should have returned failure"); - - /* Cleanup */ - pico_frame_discard(f); - - /* Setup */ - f = make_router_adv(dummy_device, PACKET_TYPE_DOUBLE_OPTION); - f->net_hdr = (uint8_t *)&ipv6_hdr; - f->net_len = sizeof(struct pico_ipv6_hdr); - - /* Get neigh options from our RA (which has 2 * LL addr option and prefix option) */ - fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) == 1, "our RA has a double option, but not the prefix option. So retrieving this should have returned success"); - fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) < 0, "our RA has a double option, should have returned failure"); - - pico_frame_discard(f); - pico_device_destroy(dummy_device); + struct pico_frame *f = NULL; + struct pico_device *dummy_device = NULL; + struct pico_ipv6_hdr ipv6_hdr = { 0 }; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + const char router_addr_s[] = "fe80::200:ff:fe00:a0a0"; + struct pico_icmp6_opt_lladdr opt_lladdr = { + 0 + }; + struct pico_icmp6_opt_prefix opt_prefix = { + 0 + }; + struct pico_ip6 temp = { 0 }; + struct redirect_s opt_redirect = { 0 }; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + pico_string_to_ipv6(router_addr_s, ipv6_hdr.src.addr); + pico_string_to_ipv6(all_node_multicast_addr_s, ipv6_hdr.dst.addr); + ipv6_hdr.hop = 255; + + dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_device, name, mac); + + /* Setup */ + f = make_router_adv(dummy_device, PACKET_TYPE_NORMAL); + f->net_hdr = (uint8_t *)&ipv6_hdr; + f->net_len = sizeof(struct pico_ipv6_hdr); + + /* Get neigh options from our RA (which has LL addr option and prefix option) */ + fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) == 1, "our RA should have a valid LL addr option"); + fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) == 1, "our RA should have a valid prefix option"); + fail_unless(get_neigh_option(f, &opt_redirect, PICO_ND_OPT_REDIRECT) == 0, "our RA doesn't have a redirect option"); + + /* Check if ll addr is valid */ + /* len is stored as a number of bytes */ + fail_unless(opt_lladdr.type == PICO_ND_OPT_LLADDR_SRC, "We didn't extract the LL addr properly"); + fail_unless(opt_lladdr.len == sizeof(struct pico_icmp6_opt_lladdr) >> 3, "We didn't extract the LL addr option properly"); + fail_if(memcmp(&router_adv_mac, opt_lladdr.addr.data, pico_hw_addr_len(dummy_device, &opt_lladdr)), "We didn't extract the LL addr properly"); + + /* Check if prefix option is valid */ + fail_unless(opt_prefix.type == router_prefix_option.type); + fail_unless(opt_prefix.len == router_prefix_option.len); + fail_unless(opt_prefix.prefix_len == router_prefix_option.prefix_len); + fail_unless(opt_prefix.res == router_prefix_option.res); + fail_unless(opt_prefix.aac == router_prefix_option.aac); + fail_unless(opt_prefix.onlink == router_prefix_option.onlink); + fail_unless(opt_prefix.val_lifetime == router_prefix_option.val_lifetime); + fail_unless(opt_prefix.reserved == router_prefix_option.reserved); + + pico_string_to_ipv6(router_adv_prefix, temp.addr); + fail_unless(memcmp(&opt_prefix.prefix, &temp, sizeof(opt_prefix.prefix)) == 0); + + /* Cleanup */ + pico_frame_discard(f); + + /* Setup */ + f = make_router_adv(dummy_device, PACKET_TYPE_BAD_LEN); + f->net_hdr = (uint8_t *)&ipv6_hdr; + f->net_len = sizeof(struct pico_ipv6_hdr); + + /* Get neigh options from our RA (which has LL addr option and prefix option, one option has bad length field) */ + fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) < 0, "our RA has a bad len field, should have returned failure"); + fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) < 0, "our RA has a bad len field, should have returned failure"); + + /* Cleanup */ + pico_frame_discard(f); + + /* Setup */ + f = make_router_adv(dummy_device, PACKET_TYPE_DOUBLE_OPTION); + f->net_hdr = (uint8_t *)&ipv6_hdr; + f->net_len = sizeof(struct pico_ipv6_hdr); + + /* Get neigh options from our RA (which has 2 * LL addr option and prefix option) */ + fail_unless(get_neigh_option(f, &opt_prefix, PICO_ND_OPT_PREFIX) == 1, "our RA has a double option, but not the prefix option. So retrieving this should have returned success"); + fail_unless(get_neigh_option(f, &opt_lladdr, PICO_ND_OPT_LLADDR_SRC) < 0, "our RA has a double option, should have returned failure"); + + pico_frame_discard(f); + pico_device_destroy(dummy_device); } END_TEST START_TEST(tc_pico_ipv6_neighbor_update) { - struct pico_ipv6_neighbor n = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - uint8_t initial_mac[PICO_SIZE_ETH] = { - 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 - }; - uint8_t new_mac[PICO_SIZE_ETH] = { - 0x00, 0x00, 0x00, 0x00, 0xab, 0xab - }; - struct pico_icmp6_opt_lladdr lladdr = { 0 }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor n = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + uint8_t initial_mac[PICO_SIZE_ETH] = { + 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 + }; + uint8_t new_mac[PICO_SIZE_ETH] = { + 0x00, 0x00, 0x00, 0x00, 0xab, 0xab + }; + struct pico_icmp6_opt_lladdr lladdr = { 0 }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); - n.address = addr_0; - memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); - memcpy(&lladdr.addr, &new_mac, PICO_SIZE_ETH); + n.address = addr_0; + memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); + memcpy(&lladdr.addr, &new_mac, PICO_SIZE_ETH); - /* Sanity check */ - fail_unless(memcmp(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); + /* Sanity check */ + fail_unless(memcmp(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); - pico_ipv6_neighbor_update(&n, &lladdr, dummy_dev); + pico_ipv6_neighbor_update(&n, &lladdr, dummy_dev); - fail_unless(memcmp(&n.hwaddr.mac, &new_mac, PICO_SIZE_ETH) == 0, "Mac addr should have been updated"); + fail_unless(memcmp(&n.hwaddr.mac, &new_mac, PICO_SIZE_ETH) == 0, "Mac addr should have been updated"); - pico_device_destroy(dummy_dev); + pico_device_destroy(dummy_dev); - /* TODO: 6LOWPAN testing */ + /* TODO: 6LOWPAN testing */ } END_TEST START_TEST(tc_pico_ipv6_neighbor_compare_stored) { - struct pico_ipv6_neighbor n = { 0 }; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - uint8_t initial_mac[PICO_SIZE_ETH] = { - 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 - }; - uint8_t new_mac[PICO_SIZE_ETH] = { - 0x00, 0x00, 0x00, 0x00, 0xab, 0xab - }; - struct pico_icmp6_opt_lladdr lladdr = { 0 }; - struct pico_device *dummy_dev = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor n = { 0 }; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + uint8_t initial_mac[PICO_SIZE_ETH] = { + 0x00, 0x00, 0x00, 0x00, 0xa0, 0xa0 + }; + uint8_t new_mac[PICO_SIZE_ETH] = { + 0x00, 0x00, 0x00, 0x00, 0xab, 0xab + }; + struct pico_icmp6_opt_lladdr lladdr = { 0 }; + struct pico_device *dummy_dev = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); - n.address = addr_0; - memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); - memcpy(&lladdr.addr, &initial_mac, PICO_SIZE_ETH); + n.address = addr_0; + memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); + memcpy(&lladdr.addr, &initial_mac, PICO_SIZE_ETH); - /* Sanity check */ - fail_unless(memcmp(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); - fail_unless(memcmp(&lladdr.addr, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); + /* Sanity check */ + fail_unless(memcmp(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); + fail_unless(memcmp(&lladdr.addr, &initial_mac, PICO_SIZE_ETH) == 0, "Setup of mac addr failed?"); - fail_unless(pico_ipv6_neighbor_compare_stored(&n, &lladdr, dummy_dev) == 0, "Neighbor and lladdr opt have the same mac addr"); + fail_unless(pico_ipv6_neighbor_compare_stored(&n, &lladdr, dummy_dev) == 0, "Neighbor and lladdr opt have the same mac addr"); - memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); - memcpy(&lladdr.addr, &new_mac, PICO_SIZE_ETH); + memcpy(&n.hwaddr.mac, &initial_mac, PICO_SIZE_ETH); + memcpy(&lladdr.addr, &new_mac, PICO_SIZE_ETH); - fail_unless(pico_ipv6_neighbor_compare_stored(&n, &lladdr, dummy_dev) != 0, "Neighbor and lladdr opt do not have the same mac addr"); + fail_unless(pico_ipv6_neighbor_compare_stored(&n, &lladdr, dummy_dev) != 0, "Neighbor and lladdr opt do not have the same mac addr"); - pico_device_destroy(dummy_dev); + pico_device_destroy(dummy_dev); - /* TODO: 6LOWPAN testing */ + /* TODO: 6LOWPAN testing */ } END_TEST START_TEST(tc_neigh_adv_reconfirm_router_option) { - struct pico_ipv6_neighbor *n = NULL; - struct pico_ipv6_router *r = NULL; - struct pico_ip6 addr_0 = { - .addr = { - 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b - } - }; - struct pico_stack *S = NULL; + struct pico_ipv6_neighbor *n = NULL; + struct pico_ipv6_router *r = NULL; + struct pico_ip6 addr_0 = { + .addr = { + 0x20, 0x01, 0x0d, 0xb8, 0x13, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc0, 0x87, 0x6a, 0x13, 0x0b + } + }; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n->address = addr_0; - n->is_router = 1; - n->stack = S; + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n->address = addr_0; + n->is_router = 1; + n->stack = S; - r = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); - r->router = n; + r = PICO_ZALLOC(sizeof(struct pico_ipv6_router)); + r->router = n; - /* Test 1: clearing of is_router flag, not in RCache */ - neigh_adv_reconfirm_router_option(n, 0); + /* Test 1: clearing of is_router flag, not in RCache */ + neigh_adv_reconfirm_router_option(n, 0); - fail_if(n->is_router, "is_router flag should be cleared"); + fail_if(n->is_router, "is_router flag should be cleared"); - /* Test 2: clearing of is_router flag, in RCache */ + /* Test 2: clearing of is_router flag, in RCache */ - n->is_router = 1; + n->is_router = 1; - /* Sanity check, tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, RCache should be empty"); - pico_tree_insert(&S->IPV6RCache, r); - fail_if(pico_tree_empty(&S->IPV6RCache), "Test started, RCache shouldn't be empty"); + /* Sanity check, tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, RCache should be empty"); + pico_tree_insert(&S->IPV6RCache, r); + fail_if(pico_tree_empty(&S->IPV6RCache), "Test started, RCache shouldn't be empty"); - neigh_adv_reconfirm_router_option(n, 0); + neigh_adv_reconfirm_router_option(n, 0); - fail_if(n->is_router, "is_router flag should be cleared"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE should be deleted"); + fail_if(n->is_router, "is_router flag should be cleared"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE should be deleted"); - /* Test 3: Setting of is_router flag */ - n->is_router = 0; + /* Test 3: Setting of is_router flag */ + n->is_router = 0; - fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, RCache should be empty"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "Test hasn't started, RCache should be empty"); - neigh_adv_reconfirm_router_option(n, 1); + neigh_adv_reconfirm_router_option(n, 1); - fail_unless(n->is_router, "is_router flag should be set"); - fail_if(pico_tree_empty(&S->IPV6RCache), "RCE should have been created"); + fail_unless(n->is_router, "is_router flag should be set"); + fail_if(pico_tree_empty(&S->IPV6RCache), "RCE should have been created"); - /* Test 4 (cleanup): clearing of is_router flag */ - neigh_adv_reconfirm_router_option(n, 0); + /* Test 4 (cleanup): clearing of is_router flag */ + neigh_adv_reconfirm_router_option(n, 0); - fail_if(n->is_router, "is_router flag should be cleared"); - fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE should have been deleted"); + fail_if(n->is_router, "is_router flag should be cleared"); + fail_unless(pico_tree_empty(&S->IPV6RCache), "RCE should have been deleted"); - PICO_FREE(n); + PICO_FREE(n); } END_TEST START_TEST(tc_neigh_adv_reconfirm_no_tlla) { - /* TODO: */ - /* TODO: test this: static int neigh_adv_reconfirm_no_tlla(struct pico_ipv6_neighbor *n, struct pico_icmp6_hdr *hdr) */ + /* TODO: */ + /* TODO: test this: static int neigh_adv_reconfirm_no_tlla(struct pico_ipv6_neighbor *n, struct pico_icmp6_hdr *hdr) */ } END_TEST START_TEST(tc_neigh_adv_reconfirm) { - /* TODO: test this: static int neigh_adv_reconfirm(struct pico_ipv6_neighbor *n, struct pico_icmp6_opt_lladdr *opt, struct pico_icmp6_hdr *hdr) */ + /* TODO: test this: static int neigh_adv_reconfirm(struct pico_ipv6_neighbor *n, struct pico_icmp6_opt_lladdr *opt, struct pico_icmp6_hdr *hdr) */ } END_TEST START_TEST(tc_neigh_adv_process_incomplete) { - /* TODO: test this: static void neigh_adv_process_incomplete(struct pico_ipv6_neighbor *n, struct pico_frame *f, struct pico_icmp6_opt_lladdr *opt) */ + /* TODO: test this: static void neigh_adv_process_incomplete(struct pico_ipv6_neighbor *n, struct pico_frame *f, struct pico_icmp6_opt_lladdr *opt) */ } END_TEST START_TEST(tc_pico_ipv6_neighbor_from_sol_new) { - /* TODO: */ - /* TODO: test this: static struct pico_ipv6_neighbor *pico_ipv6_neighbor_from_sol_new(struct pico_ip6 *ip, struct pico_icmp6_opt_lladdr *opt, struct pico_device *dev) */ + /* TODO: */ + /* TODO: test this: static struct pico_ipv6_neighbor *pico_ipv6_neighbor_from_sol_new(struct pico_ip6 *ip, struct pico_icmp6_opt_lladdr *opt, struct pico_device *dev) */ } END_TEST START_TEST(tc_pico_ipv6_neighbor_from_unsolicited) { - /* TODO: */ - /* TODO: test this: static void pico_ipv6_neighbor_from_unsolicited(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static void pico_ipv6_neighbor_from_unsolicited(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_ipv6_router_from_unsolicited) { - /* TODO: */ - /* TODO: test this: static void pico_ipv6_router_from_unsolicited(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static void pico_ipv6_router_from_unsolicited(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_detect_dad) { - /* TODO: test this: static int neigh_sol_detect_dad(struct pico_frame *f) */ + /* TODO: test this: static int neigh_sol_detect_dad(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_mcast_validity_check) { - /* TODO: test this: static int neigh_sol_mcast_validity_check(struct pico_frame *f) */ + /* TODO: test this: static int neigh_sol_mcast_validity_check(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_unicast_validity_check) { - /* TODO: test this: static int neigh_sol_unicast_validity_check(struct pico_frame *f) */ + /* TODO: test this: static int neigh_sol_unicast_validity_check(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_validate_unspec) { - /* TODO: test this: static int neigh_sol_validate_unspec(struct pico_frame *f) */ + /* TODO: test this: static int neigh_sol_validate_unspec(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_validity_checks) { - /* TODO: */ - /* TODO: test this: static int neigh_sol_validity_checks(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static int neigh_sol_validity_checks(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_sol_process) { - /* TODO: test this: static int neigh_sol_process(struct pico_frame *f) */ + /* TODO: test this: static int neigh_sol_process(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_neigh_sol_recv) { - /* TODO: test this: static int pico_nd_neigh_sol_recv(struct pico_frame *f) */ + /* TODO: test this: static int pico_nd_neigh_sol_recv(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_router_prefix_option_valid) { - /* TODO: */ - /* TODO: test this: static int pico_nd_router_prefix_option_valid(struct pico_device *dev, struct pico_icmp6_opt_prefix *prefix) */ + /* TODO: */ + /* TODO: test this: static int pico_nd_router_prefix_option_valid(struct pico_device *dev, struct pico_icmp6_opt_prefix *prefix) */ } END_TEST START_TEST(tc_pico_nd_router_sol_recv) { - /* TODO: */ - /* TODO: test this: static int pico_nd_router_sol_recv(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static int pico_nd_router_sol_recv(struct pico_frame *f) */ } END_TEST START_TEST(tc_router_adv_validity_checks) { - /* TODO: */ - /* TODO: test this: static int router_adv_validity_checks(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static int router_adv_validity_checks(struct pico_frame *f) */ } END_TEST START_TEST(tc_radv_process) { - /* TODO: test this: static int radv_process(struct pico_frame *f) */ + /* TODO: test this: static int radv_process(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_router_adv_recv) { - /* TODO: test this: static int pico_nd_router_adv_recv(struct pico_frame *f) */ + /* TODO: test this: static int pico_nd_router_adv_recv(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_adv_option_len_validity_check) { - /* TODO: */ - /* TODO: test this: static int neigh_adv_option_len_validity_check(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static int neigh_adv_option_len_validity_check(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_adv_mcast_validity_check) { - /* TODO: test this: static int neigh_adv_mcast_validity_check(struct pico_frame *f) */ + /* TODO: test this: static int neigh_adv_mcast_validity_check(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_adv_validity_checks) { - /* TODO: test this: static int neigh_adv_validity_checks(struct pico_frame *f) */ + /* TODO: test this: static int neigh_adv_validity_checks(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_adv_checks) { - /* TODO: test this: static int neigh_adv_checks(struct pico_frame *f) */ + /* TODO: test this: static int neigh_adv_checks(struct pico_frame *f) */ } END_TEST START_TEST(tc_neigh_adv_process) { - /* TODO: test this: static int neigh_adv_process(struct pico_frame *f) */ + /* TODO: test this: static int neigh_adv_process(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_neigh_adv_recv) { - /* TODO: test this: static int pico_nd_neigh_adv_recv(struct pico_frame *f) */ + /* TODO: test this: static int pico_nd_neigh_adv_recv(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_redirect_is_valid) { - /* TODO: */ - /* TODO: test this: static int pico_nd_redirect_is_valid(struct pico_frame *f) */ + /* TODO: */ + /* TODO: test this: static int pico_nd_redirect_is_valid(struct pico_frame *f) */ } END_TEST START_TEST(tc_redirect_process) { - /* TODO: test this: static int redirect_process(struct pico_frame *f) */ + /* TODO: test this: static int redirect_process(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_nd_redirect_recv) { - /* TODO: test this: static int pico_nd_redirect_recv(struct pico_frame *f) */ + /* TODO: test this: static int pico_nd_redirect_recv(struct pico_frame *f) */ } END_TEST START_TEST(tc_pico_ipv6_check_nce_callback) { - /* TODO: test this: static void pico_ipv6_check_nce_callback(pico_time now, struct pico_ipv6_neighbor *n) */ + /* TODO: test this: static void pico_ipv6_check_nce_callback(pico_time now, struct pico_ipv6_neighbor *n) */ } END_TEST START_TEST(tc_pico_ipv6_router_adv_timer_callback) { - /* TODO: test this: static void pico_ipv6_router_adv_timer_callback(pico_time now, void *arg) */ + /* TODO: test this: static void pico_ipv6_router_adv_timer_callback(pico_time now, void *arg) */ } END_TEST START_TEST(tc_pico_ipv6_check_router_lifetime_callback) { - /* TODO: test this: static void pico_ipv6_check_router_lifetime_callback(pico_time now, void *arg) */ + /* TODO: test this: static void pico_ipv6_check_router_lifetime_callback(pico_time now, void *arg) */ } END_TEST START_TEST(tc_pico_ipv6_check_link_lifetime_expired) { - /* TODO: test this: static void pico_ipv6_check_link_lifetime_expired(pico_time now, void *arg) */ + /* TODO: test this: static void pico_ipv6_check_link_lifetime_expired(pico_time now, void *arg) */ } END_TEST START_TEST(tc_pico_ipv6_router_sol_timer) { - /* TODO: test this: static void pico_ipv6_router_sol_timer(pico_time now, void *arg){ */ + /* TODO: test this: static void pico_ipv6_router_sol_timer(pico_time now, void *arg){ */ } END_TEST START_TEST(tc_pico_ipv6_nd_timer_elapsed) { - struct pico_ipv6_neighbor *n = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - struct pico_device *dummy_dev = NULL; - pico_time now = 0; - pico_time expected; - struct pico_stack *S = NULL; - - pico_stack_init(&S); - - dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_dev, name, mac); - dummy_dev->hostvars.retranstime = 1000; - - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - - /* Test case 1 - * PICO_ND_STATE_INCOMPLETE - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_INCOMPLETE; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - now = PICO_TIME_MS(); - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_solicited_count == 1, "When in state INCOMPLETE (and failure counters of NCE==0), NS should have been sent"); - fail_unless(pico_ns_count == 1, "When in state INCOMPLETE (and failure counters of NCE==0), NS should have been sent only once"); - fail_unless(n->state == PICO_ND_STATE_INCOMPLETE, "State of NCE shouldn't have changed when INCOMPLETE"); - fail_unless(VALUE_BETWEEN_RANGE(n->expire, now + n->dev->hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + n->dev->hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 2 - * PICO_ND_STATE_INCOMPLETE_SEARCHING - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_INCOMPLETE_SEARCHING; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - pico_ipv6_nd_timer_elapsed(0, n); - expected = PICO_TIME_MS() + n->dev->hostvars.retranstime; - - fail_unless(pico_ns_solicited_count == 1, "When in state INCOMPLETE_SEARCHING (and failure counters of NCE==0), NS should have been sent"); - fail_unless(pico_ns_count == 1, "When in state INCOMPLETE_SEARCHING (and failure counters of NCE==0), NS should have been sent only once"); - fail_unless(n->state == PICO_ND_STATE_INCOMPLETE_SEARCHING, "State of NCE shouldn't have changed when INCOMPLETE_SEARCHING"); - fail_unless(TIME_CHECK(n->expire, expected)); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 3 - * PICO_ND_STATE_REACHABLE - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_REACHABLE; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_unicast_count == 0, "When in state REACHABLE (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(pico_ns_count == 0, "When in state REACHABLE (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(n->state == PICO_ND_STATE_STALE, "State of NCE should have changed from REACHABLE to STALE"); - fail_if(n->expire != 0, "After switching from REACHABLE to STALE, expire time of NCE shouldn't have changed"); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 4 - * PICO_ND_STATE_STALE - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_STALE; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - pico_ipv6_nd_timer_elapsed(0, n); - expected = PICO_TIME_MS() + PICO_ND_DELAY_FIRST_PROBE_TIME; - - fail_unless(pico_ns_unicast_count == 0, "When in state STALE (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(pico_ns_count == 0, "When in state STALE (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(n->state == PICO_ND_STATE_STALE, "State of NCE shouldn't have changed when STALE"); - fail_unless(TIME_CHECK(n->expire, expected)); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 5 - * PICO_ND_STATE_DELAY - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_DELAY; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_unicast_count == 0, "When in state DELAY (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(pico_ns_count == 0, "When in state DELAY (and failure counters of NCE==0), NS shouldn't have been sent"); - fail_unless(n->state == PICO_ND_STATE_PROBE, "State of NCE should have changed from DELAY to PROBE"); - fail_if(n->expire != 0, "After switching from DELAY to PROBE, expire time of NCE shouldn't have changed"); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 6 - * PICO_ND_STATE_PROBE - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_PROBE; - n->failure_uni_count = 0; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - - pico_ipv6_nd_timer_elapsed(0, n); - expected = PICO_TIME_MS() + n->dev->hostvars.retranstime; - - fail_unless(pico_ns_unicast_count == 1, "When in state PROBE (and failure counters of NCE==0), NS should have been sent"); - fail_unless(pico_ns_count == 1, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); - fail_unless(n->state == PICO_ND_STATE_PROBE, "State of NCE shouldn't have changed when PROBE"); - fail_unless(TIME_CHECK(n->expire, expected)); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 7 - * PICO_ND_STATE_INCOMPLETE - * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT - * NCE should be deleted - */ - /* Setup of neighbor */ - n->dev = dummy_dev; - n->state = PICO_ND_STATE_INCOMPLETE; - n->failure_uni_count = 0; - n->failure_multi_count = PICO_ND_MAX_MULTICAST_SOLICIT; - n->expire = 0; - n->stack = S; - pico_tree_insert(&S->IPV6NCache, n); - - /* Sanity check, tree must NOT be empty */ - fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); - - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); - - /* Tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - - /* Test case 8 - * PICO_ND_STATE_INCOMPLETE_SEARCHING - * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT - * NCE should be deleted - */ - /* Setup of neighbor */ - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n->dev = dummy_dev; - n->state = PICO_ND_STATE_INCOMPLETE_SEARCHING; - n->failure_uni_count = 0; - n->failure_multi_count = PICO_ND_MAX_MULTICAST_SOLICIT; - n->expire = 0; - n->stack = S; - pico_tree_insert(&S->IPV6NCache, n); - - /* Sanity check, tree must NOT be empty */ - fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); - - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); - - /* Tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* Test case 9 - * PICO_ND_STATE_PROBE - * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT - * NCE should be deleted - */ - /* Setup of neighbor */ - n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); - n->dev = dummy_dev; - n->state = PICO_ND_STATE_PROBE; - n->failure_uni_count = PICO_ND_MAX_MULTICAST_SOLICIT; - n->failure_multi_count = 0; - n->expire = 0; - n->stack = S; - pico_tree_insert(&S->IPV6NCache, n); - - /* Sanity check, tree must NOT be empty */ - fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); - - pico_ipv6_nd_timer_elapsed(0, n); - - fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); - - /* Tree must be empty */ - fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); - - /* Reset */ - pico_ns_solicited_count = 0; - pico_ns_unicast_count = 0; - pico_ns_count = 0; - - /* PICO_FREE(n); */ - pico_device_destroy(dummy_dev); + struct pico_ipv6_neighbor *n = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + struct pico_device *dummy_dev = NULL; + pico_time now = 0; + pico_time expected; + struct pico_stack *S = NULL; + + pico_stack_init(&S); + + dummy_dev = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_dev, name, mac); + dummy_dev->hostvars.retranstime = 1000; + + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + + /* Test case 1 + * PICO_ND_STATE_INCOMPLETE + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_INCOMPLETE; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + now = PICO_TIME_MS(); + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_solicited_count == 1, "When in state INCOMPLETE (and failure counters of NCE==0), NS should have been sent"); + fail_unless(pico_ns_count == 1, "When in state INCOMPLETE (and failure counters of NCE==0), NS should have been sent only once"); + fail_unless(n->state == PICO_ND_STATE_INCOMPLETE, "State of NCE shouldn't have changed when INCOMPLETE"); + fail_unless(VALUE_BETWEEN_RANGE(n->expire, now + n->dev->hostvars.retranstime - EXPIRE_TIME_RANGE_MS, now + n->dev->hostvars.retranstime + EXPIRE_TIME_RANGE_MS)); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 2 + * PICO_ND_STATE_INCOMPLETE_SEARCHING + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_INCOMPLETE_SEARCHING; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + pico_ipv6_nd_timer_elapsed(0, n); + expected = PICO_TIME_MS() + n->dev->hostvars.retranstime; + + fail_unless(pico_ns_solicited_count == 1, "When in state INCOMPLETE_SEARCHING (and failure counters of NCE==0), NS should have been sent"); + fail_unless(pico_ns_count == 1, "When in state INCOMPLETE_SEARCHING (and failure counters of NCE==0), NS should have been sent only once"); + fail_unless(n->state == PICO_ND_STATE_INCOMPLETE_SEARCHING, "State of NCE shouldn't have changed when INCOMPLETE_SEARCHING"); + fail_unless(TIME_CHECK(n->expire, expected)); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 3 + * PICO_ND_STATE_REACHABLE + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_REACHABLE; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_unicast_count == 0, "When in state REACHABLE (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(pico_ns_count == 0, "When in state REACHABLE (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(n->state == PICO_ND_STATE_STALE, "State of NCE should have changed from REACHABLE to STALE"); + fail_if(n->expire != 0, "After switching from REACHABLE to STALE, expire time of NCE shouldn't have changed"); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 4 + * PICO_ND_STATE_STALE + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_STALE; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + pico_ipv6_nd_timer_elapsed(0, n); + expected = PICO_TIME_MS() + PICO_ND_DELAY_FIRST_PROBE_TIME; + + fail_unless(pico_ns_unicast_count == 0, "When in state STALE (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(pico_ns_count == 0, "When in state STALE (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(n->state == PICO_ND_STATE_STALE, "State of NCE shouldn't have changed when STALE"); + fail_unless(TIME_CHECK(n->expire, expected)); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 5 + * PICO_ND_STATE_DELAY + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_DELAY; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_unicast_count == 0, "When in state DELAY (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(pico_ns_count == 0, "When in state DELAY (and failure counters of NCE==0), NS shouldn't have been sent"); + fail_unless(n->state == PICO_ND_STATE_PROBE, "State of NCE should have changed from DELAY to PROBE"); + fail_if(n->expire != 0, "After switching from DELAY to PROBE, expire time of NCE shouldn't have changed"); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 6 + * PICO_ND_STATE_PROBE + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_PROBE; + n->failure_uni_count = 0; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + + pico_ipv6_nd_timer_elapsed(0, n); + expected = PICO_TIME_MS() + n->dev->hostvars.retranstime; + + fail_unless(pico_ns_unicast_count == 1, "When in state PROBE (and failure counters of NCE==0), NS should have been sent"); + fail_unless(pico_ns_count == 1, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); + fail_unless(n->state == PICO_ND_STATE_PROBE, "State of NCE shouldn't have changed when PROBE"); + fail_unless(TIME_CHECK(n->expire, expected)); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 7 + * PICO_ND_STATE_INCOMPLETE + * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT + * NCE should be deleted + */ + /* Setup of neighbor */ + n->dev = dummy_dev; + n->state = PICO_ND_STATE_INCOMPLETE; + n->failure_uni_count = 0; + n->failure_multi_count = PICO_ND_MAX_MULTICAST_SOLICIT; + n->expire = 0; + n->stack = S; + pico_tree_insert(&S->IPV6NCache, n); + + /* Sanity check, tree must NOT be empty */ + fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); + + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); + + /* Tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + + /* Test case 8 + * PICO_ND_STATE_INCOMPLETE_SEARCHING + * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT + * NCE should be deleted + */ + /* Setup of neighbor */ + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n->dev = dummy_dev; + n->state = PICO_ND_STATE_INCOMPLETE_SEARCHING; + n->failure_uni_count = 0; + n->failure_multi_count = PICO_ND_MAX_MULTICAST_SOLICIT; + n->expire = 0; + n->stack = S; + pico_tree_insert(&S->IPV6NCache, n); + + /* Sanity check, tree must NOT be empty */ + fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); + + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); + + /* Tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* Test case 9 + * PICO_ND_STATE_PROBE + * - failure count is set to PICO_ND_MAX_MULTICAST_SOLICIT + * NCE should be deleted + */ + /* Setup of neighbor */ + n = PICO_ZALLOC(sizeof(struct pico_ipv6_neighbor)); + n->dev = dummy_dev; + n->state = PICO_ND_STATE_PROBE; + n->failure_uni_count = PICO_ND_MAX_MULTICAST_SOLICIT; + n->failure_multi_count = 0; + n->expire = 0; + n->stack = S; + pico_tree_insert(&S->IPV6NCache, n); + + /* Sanity check, tree must NOT be empty */ + fail_if(pico_tree_empty(&S->IPV6NCache), "There should be an NCE"); + + pico_ipv6_nd_timer_elapsed(0, n); + + fail_unless(pico_ns_count == 0, "When in state PROBE (and failure counters of NCE==0), NS should have been sent only once"); + + /* Tree must be empty */ + fail_unless(pico_tree_empty(&S->IPV6NCache), "NCE should have been deleted"); + + /* Reset */ + pico_ns_solicited_count = 0; + pico_ns_unicast_count = 0; + pico_ns_count = 0; + + /* PICO_FREE(n); */ + pico_device_destroy(dummy_dev); } END_TEST START_TEST(tc_pico_nd_mtu) @@ -2146,26 +2116,26 @@ START_TEST(tc_pico_nd_mtu) struct pico_device *dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); struct pico_frame *f = NULL; const uint8_t mac[PICO_SIZE_ETH] = { - 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 + 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 }; - const char * name = "nd_mtu"; + const char *name = "nd_mtu"; /* Packet 15 from IPv6_NDP.cap */ const unsigned char pkt15[118] = { - 0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xc2, 0x00, - 0x54, 0xf5, 0x00, 0x00, 0x86, 0xdd, 0x6e, 0x00, - 0x00, 0x00, 0x00, 0x40, 0x3a, 0xff, 0xfe, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, - 0x54, 0xff, 0xfe, 0xf5, 0x00, 0x00, 0xff, 0x02, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x00, - 0xc4, 0xfe, 0x40, 0x00, 0x07, 0x08, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, - 0xc2, 0x00, 0x54, 0xf5, 0x00, 0x00, 0x05, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc, 0x03, 0x04, - 0x40, 0xc0, 0x00, 0x27, 0x8d, 0x00, 0x00, 0x09, - 0x3a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, - 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0xc2, 0x00, + 0x54, 0xf5, 0x00, 0x00, 0x86, 0xdd, 0x6e, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x3a, 0xff, 0xfe, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, + 0x54, 0xff, 0xfe, 0xf5, 0x00, 0x00, 0xff, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x00, + 0xc4, 0xfe, 0x40, 0x00, 0x07, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, + 0xc2, 0x00, 0x54, 0xf5, 0x00, 0x00, 0x05, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc, 0x03, 0x04, + 0x40, 0xc0, 0x00, 0x27, 0x8d, 0x00, 0x00, 0x09, + 0x3a, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, + 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; struct pico_stack *S = NULL; @@ -2183,59 +2153,59 @@ START_TEST(tc_pico_nd_mtu) pico_ipv6_nd_recv(f); { - const struct pico_ipv6_hdr *hdr = (const struct pico_ipv6_hdr *)(pkt15 + PICO_SIZE_ETHHDR); - struct pico_ipv6_router *test_router = pico_get_router_from_rcache(S, &(hdr->src)); - fail_if(test_router->link->mtu != 1500); + const struct pico_ipv6_hdr *hdr = (const struct pico_ipv6_hdr *)(pkt15 + PICO_SIZE_ETHHDR); + struct pico_ipv6_router *test_router = pico_get_router_from_rcache(S, &(hdr->src)); + fail_if(test_router->link->mtu != 1500); - /* Cleanup */ - pico_nd_delete_entry(test_router->router); - pico_device_destroy(dummy_device); + /* Cleanup */ + pico_nd_delete_entry(test_router->router); + pico_device_destroy(dummy_device); } } END_TEST START_TEST(tc_pico_recv_ra) { - /* Context: - * Clean env, no NCEs, no RCEs - * We recv a RA, NCE has to be created, RCE has to be created, default router has to be set - */ - struct pico_frame *f = NULL; - struct pico_device *dummy_device = NULL; - struct pico_ipv6_hdr ipv6_hdr = { 0 }; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "nd_test"; - const char router_addr_s[] = "fe80::200:ff:fe00:a0a0"; - struct pico_ipv6_neighbor *n = NULL; - struct pico_stack *S = NULL; + /* Context: + * Clean env, no NCEs, no RCEs + * We recv a RA, NCE has to be created, RCE has to be created, default router has to be set + */ + struct pico_frame *f = NULL; + struct pico_device *dummy_device = NULL; + struct pico_ipv6_hdr ipv6_hdr = { 0 }; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x08, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "nd_test"; + const char router_addr_s[] = "fe80::200:ff:fe00:a0a0"; + struct pico_ipv6_neighbor *n = NULL; + struct pico_stack *S = NULL; - pico_stack_init(&S); + pico_stack_init(&S); - pico_string_to_ipv6(router_addr_s, ipv6_hdr.src.addr); - pico_string_to_ipv6(all_node_multicast_addr_s, ipv6_hdr.dst.addr); - ipv6_hdr.hop = 255; + pico_string_to_ipv6(router_addr_s, ipv6_hdr.src.addr); + pico_string_to_ipv6(all_node_multicast_addr_s, ipv6_hdr.dst.addr); + ipv6_hdr.hop = 255; - dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_device, name, mac); + dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_device, name, mac); - f = make_router_adv(dummy_device, PACKET_TYPE_NORMAL); - f->net_hdr = (uint8_t *)&ipv6_hdr; - f->net_len = sizeof(struct pico_ipv6_hdr); + f = make_router_adv(dummy_device, PACKET_TYPE_NORMAL); + f->net_hdr = (uint8_t *)&ipv6_hdr; + f->net_len = sizeof(struct pico_ipv6_hdr); - /* Flag success */ - pico_icmp6_checksum_success_flag = 1; + /* Flag success */ + pico_icmp6_checksum_success_flag = 1; - fail_if(pico_ipv6_nd_recv(f) != 0, "We passed a valid packet, should have returned SUCCESS"); + fail_if(pico_ipv6_nd_recv(f) != 0, "We passed a valid packet, should have returned SUCCESS"); - n = pico_get_neighbor_from_ncache(S, &ipv6_hdr.src); - fail_if(n == NULL, "RA recvd, NCE should have been created"); - fail_if(pico_get_router_from_rcache(S, &ipv6_hdr.src) == NULL, "RA recvd, RCE should have been created"); - fail_if(pico_nd_get_default_router(S) == NULL, "RA recvd, default router should have been set"); + n = pico_get_neighbor_from_ncache(S, &ipv6_hdr.src); + fail_if(n == NULL, "RA recvd, NCE should have been created"); + fail_if(pico_get_router_from_rcache(S, &ipv6_hdr.src) == NULL, "RA recvd, RCE should have been created"); + fail_if(pico_nd_get_default_router(S) == NULL, "RA recvd, default router should have been set"); - /* Cleanup */ - pico_nd_delete_entry(n); - pico_device_destroy(dummy_device); + /* Cleanup */ + pico_nd_delete_entry(n); + pico_device_destroy(dummy_device); } END_TEST @@ -2466,7 +2436,7 @@ int main(void) int main(void) { - return 0; + return 0; } #endif diff --git a/test/unit/modunit_pico_ipv6_pmtu.c b/test/unit/modunit_pico_ipv6_pmtu.c index 8479c7a8..b03df445 100644 --- a/test/unit/modunit_pico_ipv6_pmtu.c +++ b/test/unit/modunit_pico_ipv6_pmtu.c @@ -61,359 +61,359 @@ START_TEST(pico_ipv6_pkt_too_big_ignorecode) const int dst_offset = 86; const uint32_t pkt1_mtu = 1280; static const unsigned char pkt17[1294] = { - 0x00, 0x00, 0x42, 0x42, 0x42, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, - 0x00, 0x00, 0x04, 0xd8, 0x3a, 0x40, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, - 0x00, 0xff, 0xfe, 0x00, 0x01, 0x00, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, - 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x02, 0xff, - 0x87, 0xe8, 0x00, 0x00, 0x05, 0x00, 0x60, 0x00, - 0x00, 0x00, 0x05, 0x78, 0x3a, 0x40, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, - 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x02, 0x02, 0x00, - 0x00, 0xff, 0xfe, 0x00, 0xa2, 0xa2, 0x81, 0x00, - 0xeb, 0x8c, 0xff, 0xff, 0x00, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 + 0x00, 0x00, 0x42, 0x42, 0x42, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, + 0x00, 0x00, 0x04, 0xd8, 0x3a, 0x40, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, + 0x00, 0xff, 0xfe, 0x00, 0x01, 0x00, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, + 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x02, 0xff, + 0x87, 0xe8, 0x00, 0x00, 0x05, 0x00, 0x60, 0x00, + 0x00, 0x00, 0x05, 0x78, 0x3a, 0x40, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, + 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x02, 0x02, 0x00, + 0x00, 0xff, 0xfe, 0x00, 0xa2, 0xa2, 0x81, 0x00, + 0xeb, 0x8c, 0xff, 0xff, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 }; static const unsigned char pkt19[1454] = { - 0x00, 0x00, 0x42, 0x42, 0x42, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, - 0x00, 0x00, 0x05, 0x78, 0x3a, 0xff, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x02, 0x02, 0x00, - 0x00, 0xff, 0xfe, 0x00, 0xa2, 0xa2, 0x3f, 0xfe, - 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, - 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x80, 0x00, - 0xec, 0x8c, 0xff, 0xff, 0x00, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06 + 0x00, 0x00, 0x42, 0x42, 0x42, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, + 0x00, 0x00, 0x05, 0x78, 0x3a, 0xff, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x02, 0x02, 0x00, + 0x00, 0xff, 0xfe, 0x00, 0xa2, 0xa2, 0x3f, 0xfe, + 0x05, 0x01, 0xff, 0xff, 0x01, 0x00, 0x02, 0x00, + 0x42, 0xff, 0xfe, 0x42, 0x42, 0x01, 0x80, 0x00, + 0xec, 0x8c, 0xff, 0xff, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06 }; struct pico_stack *S = NULL; struct mock_device *dummy_device; pico_stack_init(&S); - dummy_device= pico_mock_create(S, NULL); + dummy_device = pico_mock_create(S, NULL); dummy_device->dev->mtu = default_mtu; f_echo_request = pico_frame_alloc(sizeof(pkt19)); @@ -527,7 +527,7 @@ END_TEST START_TEST(pico_ipv6_path_cache) { uint8_t i; - struct pico_ipv6_path_id path_id = {{{ + struct pico_ipv6_path_id path_id = {{{ 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x50, 0x56, 0xff, 0xfe, 0x87, 0x06, 0xb6 }}}; struct pico_stack *S = NULL; diff --git a/test/unit/modunit_pico_mdns.c b/test/unit/modunit_pico_mdns.c index e56e8fb9..bfac90bf 100644 --- a/test/unit/modunit_pico_mdns.c +++ b/test/unit/modunit_pico_mdns.c @@ -15,14 +15,12 @@ #include Suite *pico_suite(void); -void add_records( struct pico_stack *S ); /* MARK: helper to add records to MyRecords s*/ -int mdns_init( struct pico_stack *S ); /* MARK: Initialise mDNS module */ +void add_records(struct pico_stack *S); /* MARK: helper to add records to MyRecords s*/ +int mdns_init(struct pico_stack *S); /* MARK: Initialise mDNS module */ static int amount_callback_executed = 0; -void callback( pico_mdns_rtree *tree, char *str, void *arg); -void callback( pico_mdns_rtree *tree, - char *str, - void *arg ) /* MARK: Generic callback */ +void callback(pico_mdns_rtree *tree, char *str, void *arg); +void callback(pico_mdns_rtree *tree, char *str, void *arg) /* MARK: Generic callback */ { IGNORE_PARAMETER(tree); IGNORE_PARAMETER(str); @@ -31,7 +29,7 @@ void callback( pico_mdns_rtree *tree, amount_callback_executed++; } -int mdns_init( struct pico_stack *S ) /* MARK: Initialise mDNS module */ +int mdns_init(struct pico_stack *S) /* MARK: Initialise mDNS module */ { struct mock_device *mock = NULL; @@ -1069,10 +1067,10 @@ START_TEST(tc_mdns_record_delete) /* MARK: mdns_record_delete */ printf("*********************** ending %s * \n", __func__); } END_TEST -void add_records( struct pico_stack *S ) /* MARK: helper to add records to MyRecords s*/ +void add_records(struct pico_stack *S) /* MARK: helper to add records to MyRecords s*/ { struct pico_mdns_record *record = NULL, *record1 = NULL, *record2 = NULL, - *record3 = NULL; + *record3 = NULL; struct pico_ip4 rdata = { long_be(0x00FFFFFF) }; @@ -1202,7 +1200,7 @@ START_TEST(tc_mdns_record_tree_del_name) /* MARK: mdns_record_tree_del_name */ { PICO_MDNS_RTREE_DECLARE(hits); struct pico_mdns_record *record = NULL, *record1 = NULL, *record2 = NULL, - *record3 = NULL; + *record3 = NULL; struct pico_ip4 rdata = { long_be(0x00FFFFFF) }; @@ -1252,7 +1250,7 @@ START_TEST(tc_mdns_record_tree_del_name) /* MARK: mdns_record_tree_del_name */ fail_unless(0 == pico_tree_count(&hits), "mdns_record_tree_find_name should find 3 records here!\n"); - hits = pico_mdns_rtree_find_name( &S->MDNSOwnRecords, "\3bar\5local", 0); + hits = pico_mdns_rtree_find_name(&S->MDNSOwnRecords, "\3bar\5local", 0); fail_unless(1 == pico_tree_count(&hits), "mdns_record_tree_find_name should find 1 record here!\n"); record = pico_tree_first(&hits); @@ -1300,7 +1298,7 @@ START_TEST(tc_mdns_my_records_add) /* MARK: mdns_my_records_add */ { PICO_MDNS_RTREE_DECLARE(rtree); struct pico_mdns_record *record = NULL, *record1 = NULL, *record2 = NULL, - *record3 = NULL; + *record3 = NULL; struct pico_ip4 rdata = { long_be(0x00FFFFFF) }; @@ -1391,7 +1389,7 @@ START_TEST(tc_mdns_my_records_claimed_id) /* MARK: mdns_my_records_claimed_id */ { PICO_MDNS_RTREE_DECLARE(hits); struct pico_mdns_record *record = NULL, *record1 = NULL, *record2 = NULL, - *record3 = NULL; + *record3 = NULL; struct pico_ip4 rdata = { long_be(0x00FFFFFF) }; @@ -1453,7 +1451,7 @@ START_TEST(tc_mdns_my_records_claimed) /* MARK: mdns_my_records_claimed */ { PICO_MDNS_RTREE_DECLARE(rtree); struct pico_mdns_record *record = NULL, *record1 = NULL, *record2 = NULL, - *record3 = NULL; + *record3 = NULL; struct pico_ip4 rdata = { long_be(0x00FFFFFF) }; @@ -1659,7 +1657,7 @@ START_TEST(tc_mdns_handle_data_as_answers) /* MARK: handle_data_as_answers */ /* Try to create an answer packet */ packet = pico_dns_answer_create(&rtree, NULL, NULL, &len); - fail_if (packet == NULL, "mdns_answer_create returned NULL!\n"); + fail_if(packet == NULL, "mdns_answer_create returned NULL!\n"); ptr = ((uint8_t *)packet + 12); @@ -1699,7 +1697,7 @@ START_TEST(tc_mdns_handle_data_as_authorities) /* MARK: handle_data_as_authoriti /* Try to create an answer packet */ packet = pico_dns_answer_create(&rtree, NULL, NULL, &len); - fail_if (packet == NULL, "mdns_answer_create returned NULL!\n"); + fail_if(packet == NULL, "mdns_answer_create returned NULL!\n"); ptr = ((uint8_t *)packet + 12); @@ -1835,7 +1833,7 @@ START_TEST(tc_mdns_apply_known_answer_suppression) /* MARK: apply_k_a_s */ /* Try to create an answer packet */ packet = pico_dns_answer_create(&antree, NULL, NULL, &len); - fail_if (packet == NULL, "mdns_answer_create returned NULL!\n"); + fail_if(packet == NULL, "mdns_answer_create returned NULL!\n"); ptr = ((uint8_t *)packet + 12); diff --git a/test/unit/modunit_pico_mld.c b/test/unit/modunit_pico_mld.c index a28e0e46..0fa2e4cf 100644 --- a/test/unit/modunit_pico_mld.c +++ b/test/unit/modunit_pico_mld.c @@ -74,15 +74,15 @@ START_TEST(tc_pico_mld_check_hopbyhop) hbh = (struct pico_ipv6_hbhoption *) PICO_ZALLOC(sizeof(struct pico_ipv6_hbhoption) + 7); hbh->type = PICO_PROTO_ICMP6; hbh->len = 0; - for(test = 0; test < 7; test++) { + for (test = 0; test < 7; test++) { p = (uint8_t *)hbh + sizeof(struct pico_ipv6_hbhoption); - for(i = 0; i < 6; i++ ) { - if(i != test) + for (i = 0; i < 6; i++ ) { + if (i != test) *(p++) = options[i + 2]; else *(p++) = 9; } - if(test != 6) + if (test != 6) fail_if(pico_mld_check_hopbyhop(hbh) != -1); else fail_if(pico_mld_check_hopbyhop(hbh) != 0); @@ -380,23 +380,23 @@ START_TEST(tc_pico_mld_process_in) link->mcast_compatibility = PICO_MLDV1; fail_if(pico_mld_generate_report(p) != 0); link->mcast_compatibility = PICO_MLDV2; - for(l = 0; l < 3; l++) { /* FILTER */ + for (l = 0; l < 3; l++) { /* FILTER */ (l == 2) ? (result = -1) : (result = 0); - for(k = 0; k < 3; k++) { /* FILTER */ - if(k == 2) result = -1; + for (k = 0; k < 3; k++) { /* FILTER */ + if (k == 2)result = -1; - for(i = 0; i < 3; i++) { /* STATES */ - for(j = 0; j < 6; j++) { /* EVENTS */ + for (i = 0; i < 3; i++) { /* STATES */ + for (j = 0; j < 6; j++) { /* EVENTS */ p->MCASTFilter = &_MCASTFilter; p->filter_mode = k; g.filter_mode = l; - if(p->event == MLD_EVENT_DELETE_GROUP || p->event == MLD_EVENT_QUERY_RECV) + if (p->event == MLD_EVENT_DELETE_GROUP || p->event == MLD_EVENT_QUERY_RECV) p->event++; fail_if(pico_mld_generate_report(p) != result); p->state = i; p->event = j; - if(result != -1 && p->f) { /* in some combinations, no frame is created */ + if (result != -1 && p->f) { /* in some combinations, no frame is created */ report = (struct mldv2_report *)(p->f->transport_hdr + MLD_ROUTER_ALERT_LEN); report->crc = short_be(pico_icmp6_checksum(p->f)); fail_if(pico_mld_process_in(S, p->f) != 0); diff --git a/test/unit/modunit_pico_sntp_client.c b/test/unit/modunit_pico_sntp_client.c index c2acbbdc..2ca8174c 100644 --- a/test/unit/modunit_pico_sntp_client.c +++ b/test/unit/modunit_pico_sntp_client.c @@ -16,7 +16,7 @@ struct pico_socket *pico_socket_open(struct pico_stack *S, uint16_t net, uint16_ (void) net; (void) proto; (void) wakeup; - fail_unless (sock != NULL); + fail_unless(sock != NULL); sock->stack = S; return sock; } @@ -61,7 +61,7 @@ int pico_string_to_ipv6(const char *ipstr, uint8_t *ip) } /* Used in pico_sntp_sync_start_ipv4 */ -int pico_ipv4_to_string(char* ipbuf, const uint32_t ip) +int pico_ipv4_to_string(char*ipbuf, const uint32_t ip) { (void) ipbuf; (void) ip; @@ -69,7 +69,7 @@ int pico_ipv4_to_string(char* ipbuf, const uint32_t ip) } /* Used in pico_sntp_sync_start_ipv6 */ -int pico_ipv6_to_string(char* ipbuf, const uint8_t ip[PICO_SIZE_IP6]) +int pico_ipv6_to_string(char*ipbuf, const uint8_t ip[PICO_SIZE_IP6]) { (void) ipbuf; (void) ip; @@ -201,9 +201,9 @@ START_TEST(tc_pico_sntp_cleanup) pico_stack_init(&S); ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); - fail_unless (ck != NULL); + fail_unless(ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); - fail_unless (ck->hostname != NULL); + fail_unless(ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; @@ -228,9 +228,9 @@ START_TEST(tc_pico_sntp_parse) pico_stack_init(&S); ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); - fail_unless (ck != NULL); + fail_unless(ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); - fail_unless (ck->hostname != NULL); + fail_unless(ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; @@ -259,9 +259,9 @@ START_TEST(tc_pico_sntp_client_wakeup) pico_stack_init(&S); ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); - fail_unless (ck != NULL); + fail_unless(ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); - fail_unless (ck->hostname != NULL); + fail_unless(ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; @@ -284,9 +284,9 @@ START_TEST(tc_sntp_receive_timeout) pico_stack_init(&S); ck = PICO_ZALLOC(sizeof(struct sntp_server_ns_cookie)); - fail_unless (ck != NULL); + fail_unless(ck != NULL); ck->hostname = PICO_ZALLOC(sizeof(char) * 5); - fail_unless (ck->hostname != NULL); + fail_unless(ck->hostname != NULL); ck->stamp = 0ull; ck->cb_synced = cb_synced; @@ -310,7 +310,7 @@ START_TEST(tc_pico_sntp_send) struct pico_stack *S = NULL; pico_stack_init(&S); - + sock.priv = &ck; sock.stack = S; @@ -337,7 +337,7 @@ START_TEST(tc_dnsCallback) END_TEST START_TEST(tc_pico_sntp_sync) { - const char *sntp_server= "ntp.nasa.gov"; + const char *sntp_server = "ntp.nasa.gov"; struct pico_stack *S = NULL; pico_stack_init(&S); @@ -370,7 +370,7 @@ END_TEST START_TEST(tc_pico_sntp_sync_start) { struct sntp_server_ns_cookie ck = { 0 }; - union pico_address sntp_addr = { .ip4.addr= 0ul }; + union pico_address sntp_addr = { .ip4.addr = 0ul }; struct pico_stack *S = NULL; pico_stack_init(&S); @@ -410,7 +410,7 @@ START_TEST(tc_pico_sntp_sync_start_ipv4) END_TEST START_TEST(tc_pico_sntp_sync_start_ipv6) { - union pico_address sntp_addr = { .ip6.addr = { 0 } }; + union pico_address sntp_addr = { .ip6.addr = { 0 }}; struct pico_stack *S = NULL; pico_stack_init(&S); diff --git a/test/unit/modunit_pico_strings.c b/test/unit/modunit_pico_strings.c index 6b76cb22..6f14d85c 100644 --- a/test/unit/modunit_pico_strings.c +++ b/test/unit/modunit_pico_strings.c @@ -7,27 +7,27 @@ Suite *pico_suite(void); START_TEST(tc_get_string_terminator_position) { char buf[6] = "unit"; - get_string_terminator_position(NULL,0); - fail_if(get_string_terminator_position(buf,2) != 0); - fail_if(get_string_terminator_position(buf,6) != &buf[4]); + get_string_terminator_position(NULL, 0); + fail_if(get_string_terminator_position(buf, 2) != 0); + fail_if(get_string_terminator_position(buf, 6) != &buf[4]); } END_TEST START_TEST(tc_pico_strncasecmp) { - fail_if(pico_strncasecmp("unit","UNIT",4) != 0); - fail_if(pico_strncasecmp("unit1","UNIT2",5) != -1); - fail_if(pico_strncasecmp("unit2","UNIT1",5) != 1); + fail_if(pico_strncasecmp("unit", "UNIT", 4) != 0); + fail_if(pico_strncasecmp("unit1", "UNIT2", 5) != -1); + fail_if(pico_strncasecmp("unit2", "UNIT1", 5) != 1); } END_TEST START_TEST(tc_num2string) { char buf[20]; - fail_if(num2string(-1,NULL,1) != -1); - fail_if(num2string(1,NULL,1) != -1); - fail_if(num2string(1,buf,1) != -1); - fail_if(num2string(1,buf,3) != 2); - fail_if(num2string(11,buf,3) != 3); - fail_if(num2string(112,buf,4) != 4); + fail_if(num2string(-1, NULL, 1) != -1); + fail_if(num2string(1, NULL, 1) != -1); + fail_if(num2string(1, buf, 1) != -1); + fail_if(num2string(1, buf, 3) != 2); + fail_if(num2string(11, buf, 3) != 3); + fail_if(num2string(112, buf, 4) != 4); } END_TEST @@ -41,9 +41,9 @@ Suite *pico_suite(void) tcase_add_test(TCase_get_string_terminator_position, tc_get_string_terminator_position); suite_add_tcase(s, TCase_get_string_terminator_position); - tcase_add_test(TCase_num2string,tc_num2string); + tcase_add_test(TCase_num2string, tc_num2string); suite_add_tcase(s, TCase_num2string); - tcase_add_test(TCase_pico_strncasecmp,tc_pico_strncasecmp); + tcase_add_test(TCase_pico_strncasecmp, tc_pico_strncasecmp); suite_add_tcase(s, TCase_pico_strncasecmp); return s; diff --git a/test/unit/modunit_pico_tftp.c b/test/unit/modunit_pico_tftp.c index b501f319..9b8cf8ff 100644 --- a/test/unit/modunit_pico_tftp.c +++ b/test/unit/modunit_pico_tftp.c @@ -244,7 +244,7 @@ END_TEST START_TEST(tc_pico_tftp_abort) { int ret; - struct pico_stack * S; + struct pico_stack *S; pico_stack_init(&S); diff --git a/test/unit/modunit_queue.c b/test/unit/modunit_queue.c index c317eb25..1daeb1cd 100644 --- a/test/unit/modunit_queue.c +++ b/test/unit/modunit_queue.c @@ -26,17 +26,17 @@ START_TEST(tc_q) q1.max_frames = 4; q2.max_size = 4 * 100; - fail_if (pico_enqueue(&q1, pico_frame_copy(f0)) < 0); - fail_if (pico_enqueue(&q1, pico_frame_copy(f1)) < 0); - fail_if (pico_enqueue(&q1, pico_frame_copy(f2)) < 0); - fail_if (pico_enqueue(&q1, pico_frame_copy(f3)) < 0); - fail_if (pico_enqueue(&q1, pico_frame_copy(f4)) >= 0); - - fail_if (pico_enqueue(&q2, pico_frame_copy(f0)) < 0); - fail_if (pico_enqueue(&q2, pico_frame_copy(f1)) < 0); - fail_if (pico_enqueue(&q2, pico_frame_copy(f2)) < 0); - fail_if (pico_enqueue(&q2, pico_frame_copy(f3)) < 0); - fail_if (pico_enqueue(&q2, pico_frame_copy(f4)) >= 0); + fail_if(pico_enqueue(&q1, pico_frame_copy(f0)) < 0); + fail_if(pico_enqueue(&q1, pico_frame_copy(f1)) < 0); + fail_if(pico_enqueue(&q1, pico_frame_copy(f2)) < 0); + fail_if(pico_enqueue(&q1, pico_frame_copy(f3)) < 0); + fail_if(pico_enqueue(&q1, pico_frame_copy(f4)) >= 0); + + fail_if(pico_enqueue(&q2, pico_frame_copy(f0)) < 0); + fail_if(pico_enqueue(&q2, pico_frame_copy(f1)) < 0); + fail_if(pico_enqueue(&q2, pico_frame_copy(f2)) < 0); + fail_if(pico_enqueue(&q2, pico_frame_copy(f3)) < 0); + fail_if(pico_enqueue(&q2, pico_frame_copy(f4)) >= 0); fail_if((pico_dequeue(&q1))->buffer != f0->buffer); fail_if((pico_dequeue(&q1))->buffer != f1->buffer); diff --git a/test/unit/unit_arp.c b/test/unit/unit_arp.c index e817fe4f..8106feeb 100644 --- a/test/unit/unit_arp.c +++ b/test/unit/unit_arp.c @@ -8,7 +8,7 @@ static struct pico_frame *init_frame(struct pico_device *dev) return f; } -START_TEST (arp_update_max_arp_reqs_test) +START_TEST(arp_update_max_arp_reqs_test) { struct pico_stack *S = NULL; diff --git a/test/unit/unit_dhcp.c b/test/unit/unit_dhcp.c index b49e37dd..0c73cbd7 100644 --- a/test/unit/unit_dhcp.c +++ b/test/unit/unit_dhcp.c @@ -10,7 +10,7 @@ void callback_dhcpclient(void*cli, int code) char gw_txt_addr[30]; IGNORE_PARAMETER(cli); - if(code == PICO_DHCP_SUCCESS) { + if (code == PICO_DHCP_SUCCESS) { gateway = pico_dhcp_get_gateway(&dhcp_client_ptr); pico_ipv4_to_string(gw_txt_addr, gateway.addr); } @@ -20,7 +20,7 @@ void callback_dhcpclient(void*cli, int code) int generate_dhcp_msg(uint8_t *buf, uint32_t *len, uint8_t type) { - if(type == DHCP_MSG_TYPE_DISCOVER) { + if (type == DHCP_MSG_TYPE_DISCOVER) { uint8_t buffer[] = { 0x01, 0x01, 0x06, 0x00, 0x0c, 0x10, 0x53, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -42,9 +42,9 @@ int generate_dhcp_msg(uint8_t *buf, uint32_t *len, uint8_t type) }; *len = sizeof(buffer); memcpy(&(buf[0]), buffer, *len); - }else if(type == DHCP_MSG_TYPE_OFFER) { + } else if (type == DHCP_MSG_TYPE_OFFER) { return 1; - }else if(type == DHCP_MSG_TYPE_REQUEST) { + } else if (type == DHCP_MSG_TYPE_REQUEST) { uint32_t i = 0; uint8_t buffer1[] = { /* 0x63,0x82,0x53,0x63,// MAGIC COOKIE */ @@ -61,18 +61,18 @@ int generate_dhcp_msg(uint8_t *buf, uint32_t *len, uint8_t type) memcpy(&(buf[0x123]), &(buffer1[0]), sizeof(buffer1)); *len = sizeof(buffer1) + 0x123; - for(i = *len; i < 0x150; i++) { + for (i = *len; i < 0x150; i++) { buf[i + 10] = 0x00; } return 0; - }else if(type == DHCP_MSG_TYPE_ACK) { + } else if (type == DHCP_MSG_TYPE_ACK) { return 1; } return 0; } -START_TEST (test_dhcp_server_api) +START_TEST(test_dhcp_server_api) { /************************************************************************ * Check if dhcp recv works correctly if @@ -458,7 +458,7 @@ START_TEST (test_dhcp_client) tick_it(S, 3); /* read discover message from network */ - len = pico_mock_network_read(mock, buf, BUFLEN ); + len = pico_mock_network_read(mock, buf, BUFLEN); fail_unless(len, "No msg received on network!"); printbuf(&(buf[0]), len, "DHCP-DISCOVER packet", printbufactive); fail_unless(buf[0x011c] == 0x01, "No DHCP Discover received after initiate negotiation"); diff --git a/test/unit/unit_dns.c b/test/unit/unit_dns.c index 85165eb2..9ec65a6a 100644 --- a/test/unit/unit_dns.c +++ b/test/unit/unit_dns.c @@ -16,7 +16,7 @@ void cb_dns(char *ip, void *arg) } -START_TEST (test_dns) +START_TEST(test_dns) { int ret; char url[] = "www.google.com"; diff --git a/test/unit/unit_icmp4.c b/test/unit/unit_icmp4.c index 7c63338e..26b9f37c 100644 --- a/test/unit/unit_icmp4.c +++ b/test/unit/unit_icmp4.c @@ -16,14 +16,14 @@ void cb_ping(struct pico_icmp4_stats *s) ping_test_var++; } - fail_if (s->seq > NUM_PING); + fail_if(s->seq > NUM_PING); } else { dbg("PING %lu to %s: Error %d\n", s->seq, host, s->err); exit(1); } } -START_TEST (test_icmp4_ping) +START_TEST(test_icmp4_ping) { struct pico_ip4 local = { 0 @@ -122,7 +122,7 @@ START_TEST (test_icmp4_ping) memcpy(temp_buf, buffer + 12, 4); memcpy(buffer + 12, buffer + 16, 4); memcpy(buffer + 16, temp_buf, 4); - buffer[26] = (uint8_t)~buffer[26]; /* flip some bits in the sequence number, to see if the packet gets ignored properly */ + buffer[26] = (uint8_t) ~buffer[26]; /* flip some bits in the sequence number, to see if the packet gets ignored properly */ /* using the mock-device because otherwise I have to put everything in a pico_frame correctly myself. */ pico_mock_network_write(mock, buffer, len); @@ -197,10 +197,10 @@ START_TEST (test_icmp4_incoming_ping) len = pico_mock_network_read(mock, buffer2, buffer2len); /* inspect it */ - while(cntr < len) { + while (cntr < len) { printf("0x%02x ", buffer2[cntr]); cntr++; - if(cntr % 4 == 0) + if (cntr % 4 == 0) printf("\n"); } fail_unless(len == buffer2len, "ping reply length does not match, expected len: %d, got: %d", buffer2len, len); @@ -338,7 +338,7 @@ void icmp4_unreach_socket_cb(uint16_t ev, struct pico_socket *s) } } -START_TEST (test_icmp4_unreachable_recv) +START_TEST(test_icmp4_unreachable_recv) { struct pico_ip4 local = { .addr = long_be(0x0a280064) diff --git a/test/unit/unit_ipv4.c b/test/unit/unit_ipv4.c index d4fbd8f1..367e9bfa 100644 --- a/test/unit/unit_ipv4.c +++ b/test/unit/unit_ipv4.c @@ -1,5 +1,5 @@ -START_TEST (test_ipv4) +START_TEST(test_ipv4) { #define IP_TST_SIZ 256 uint32_t i; @@ -739,10 +739,8 @@ START_TEST (test_igmp_sockopts) source = index->keyValue; if (source->ip4.addr == mreq_source[0].mcast_source_addr.ip4.addr) { /* OK */ - } - else if (source->ip4.addr == mreq_source[1].mcast_source_addr.ip4.addr) { /* OK */ - } - else { + } else if (source->ip4.addr == mreq_source[1].mcast_source_addr.ip4.addr) { /* OK */ + } else { fail("MCASTFilter (INCLUDE + INCLUDE) incorrect\n"); } } @@ -770,8 +768,7 @@ START_TEST (test_igmp_sockopts) source = index->keyValue; if (source->ip4.addr == mreq_source[2].mcast_source_addr.ip4.addr) { /* OK */ - } - else { + } else { fail("MCASTFilter (INCLUDE + EXCLUDE) incorrect\n"); } } @@ -803,10 +800,8 @@ START_TEST (test_igmp_sockopts) source = index->keyValue; if (source->ip4.addr == mreq_source[0].mcast_source_addr.ip4.addr) { /* OK */ - } - else if (source->ip4.addr == mreq_source[1].mcast_source_addr.ip4.addr) { /* OK */ - } - else { + } else if (source->ip4.addr == mreq_source[1].mcast_source_addr.ip4.addr) { /* OK */ + } else { fail("MCASTFilter (EXCLUDE + INCLUDE) incorrect\n"); } } @@ -844,10 +839,8 @@ START_TEST (test_igmp_sockopts) source = index->keyValue; if (source->ip4.addr == mreq_source[3].mcast_source_addr.ip4.addr) { /* OK */ - } - else if (source->ip4.addr == mreq_source[4].mcast_source_addr.ip4.addr) { /* OK */ - } - else { + } else if (source->ip4.addr == mreq_source[4].mcast_source_addr.ip4.addr) { /* OK */ + } else { fail("MCASTFilter (EXCLUDE + EXCLUDE) incorrect\n"); } } diff --git a/test/unit/unit_ipv6.c b/test/unit/unit_ipv6.c index a0162d41..ffc3ae7b 100644 --- a/test/unit/unit_ipv6.c +++ b/test/unit/unit_ipv6.c @@ -1,6 +1,6 @@ #ifdef PICO_SUPPORT_IPV6 -START_TEST (test_ipv6) +START_TEST(test_ipv6) { char ipstr[40] = { 0 @@ -254,9 +254,9 @@ START_TEST (test_ipv6) } /* add 2 links to dev[0] */ _link = pico_ipv6_link_add(dev[0], a[0], nm64); - fail_if (!_link, "Error adding link"); + fail_if(!_link, "Error adding link"); _link = pico_ipv6_link_add(dev[0], a[1], nm64); - fail_if (!_link, "Error adding link"); + fail_if(!_link, "Error adding link"); /* add 2 routes to each of the links */ ret = pico_ipv6_route_add(S, r[0], nm128, a[0], 1, l[0]); fail_if(ret != 0, "Error adding route"); @@ -269,9 +269,9 @@ START_TEST (test_ipv6) /* add 2 links to dev[1] */ _link = pico_ipv6_link_add(dev[1], a[8], nm64); - fail_if (!_link, "Error adding link"); + fail_if(!_link, "Error adding link"); _link = pico_ipv6_link_add(dev[1], a[9], nm64); - fail_if (!_link, "Error adding link"); + fail_if(!_link, "Error adding link"); /* add 2 routes to each of the links */ ret = pico_ipv6_route_add(S, r[6], nm128, a[8], 1, l[8]); fail_if(ret != 0, "Error adding route"); @@ -629,10 +629,8 @@ START_TEST (test_mld_sockopts) source = index->keyValue; if (memcmp(&source->ip6, &mreq_source[0].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else if (memcmp(&source->ip6, &mreq_source[1].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else { + } else if (memcmp(&source->ip6, &mreq_source[1].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ + } else { fail("MCASTFilter (INCLUDE + INCLUDE) incorrect\n"); } } @@ -662,8 +660,7 @@ START_TEST (test_mld_sockopts) source = index->keyValue; if (memcmp(&source->ip6, &mreq_source[2].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else { + } else { fail("MCASTFilter (INCLUDE + EXCLUDE) incorrect\n"); } } @@ -696,10 +693,8 @@ START_TEST (test_mld_sockopts) source = index->keyValue; if (memcmp(&source->ip6, &mreq_source[0].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else if (memcmp(&source->ip6, &mreq_source[1].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else { + } else if (memcmp(&source->ip6, &mreq_source[1].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ + } else { fail("MCASTFilter (EXCLUDE + INCLUDE) incorrect\n"); } } @@ -737,10 +732,8 @@ START_TEST (test_mld_sockopts) source = index->keyValue; if (memcmp(&source->ip6, &mreq_source[3].mcast_source_addr, sizeof(struct pico_ip6) == 0)) { /* OK */ - } - else if (memcmp(&source->ip6, &mreq_source[4].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ - } - else { + } else if (memcmp(&source->ip6, &mreq_source[4].mcast_source_addr, sizeof(struct pico_ip6)) == 0) { /* OK */ + } else { fail("MCASTFilter (EXCLUDE + EXCLUDE) incorrect\n"); } } diff --git a/test/unit/unit_mem_manager.c b/test/unit/unit_mem_manager.c index 26ef9318..ae6bc090 100644 --- a/test/unit/unit_mem_manager.c +++ b/test/unit/unit_mem_manager.c @@ -11,7 +11,7 @@ volatile pico_err_t pico_err; -START_TEST (test_compare_slab_keys) +START_TEST(test_compare_slab_keys) { uint32_t len1 = 1200; @@ -487,10 +487,8 @@ START_TEST (test_init_page) tree_node = pico_tree_findNode(&manager->tree, &doublelenptr); ck_assert(tree_node != NULL); slab_node = tree_node->keyValue; - while(slab_node != NULL) - { - if(slab_node->slab == slab) - { + while (slab_node != NULL) { + if (slab_node->slab == slab) { vlag = 1; break; } @@ -499,16 +497,13 @@ START_TEST (test_init_page) } ck_assert(vlag != 0); vlag = 0; - for(i = 0; i < page1->slabs_max - 1; i++) - { + for (i = 0; i < page1->slabs_max - 1; i++) { byteptr += sizeof(struct pico_mem_block); byteptr += page1->slab_size; slab = (struct pico_mem_block*) byteptr; slab_node = tree_node->keyValue; - while(slab_node != NULL) - { - if(slab_node->slab == slab) - { + while (slab_node != NULL) { + if (slab_node->slab == slab) { vlag = 1; break; } @@ -528,10 +523,8 @@ START_TEST (test_init_page) tree_node = pico_tree_findNode(&manager->tree, &doublelenptr); ck_assert(tree_node != NULL); slab_node = tree_node->keyValue; - while(slab_node != NULL) - { - if(slab_node->slab == slab) - { + while (slab_node != NULL) { + if (slab_node->slab == slab) { vlag = 1; break; } @@ -540,16 +533,13 @@ START_TEST (test_init_page) } ck_assert(vlag != 0); vlag = 0; - for(i = 0; i < page2->slabs_max - 1; i++) - { + for (i = 0; i < page2->slabs_max - 1; i++) { byteptr += sizeof(struct pico_mem_block); byteptr += page2->slab_size; slab = (struct pico_mem_block*) byteptr; slab_node = tree_node->keyValue; - while(slab_node != NULL) - { - if(slab_node->slab == slab) - { + while (slab_node != NULL) { + if (slab_node->slab == slab) { vlag = 1; break; } @@ -1136,16 +1126,12 @@ START_TEST (test_zero_initialize) memset(bytestream, 'a', size); _pico_mem_zero_initialize(bytestream + leftBound, size - leftBound - rightBound); - for(i = 0; i < size; i++) - { - if(i < leftBound || i >= size - rightBound) - { + for (i = 0; i < size; i++) { + if (i < leftBound || i >= size - rightBound) { /* printf("Bytestream[%i] = '%c' ?= '%c'\n", i, bytestream[i], 'a'); */ ck_assert(bytestream[i] == 'a'); uninitialized++; - } - else - { + } else { /* printf("Bytestream[%i] = '%c' ?= '%c'\n", i, bytestream[i], 0); */ ck_assert(bytestream[i] == 0); initialized++; @@ -2130,7 +2116,7 @@ Suite *pico_suite(void) tcase_add_test(mm, test_manager_extra_alloc); tcase_add_test(mm, test_page0_zalloc); tcase_add_test(mm, test_init_page); - tcase_add_test(mm, test_mem_init_whitebox ); + tcase_add_test(mm, test_mem_init_whitebox); tcase_add_test(mm, test_free_and_merge_heap_block); tcase_add_test(mm, test_determine_max_free_space); tcase_add_test(mm, test_free_slab_block); diff --git a/test/unit/unit_mocks.c b/test/unit/unit_mocks.c index 145d2299..bd4f06c6 100644 --- a/test/unit/unit_mocks.c +++ b/test/unit/unit_mocks.c @@ -23,29 +23,29 @@ int printbuf(uint8_t *buf, uint32_t len, const char *str, uint8_t printbufactive uint8_t printMethod = 0; uint32_t cntr = 0; uint32_t cntr2 = 0; - if((printbufactive) && (printMethod == 0)) { + if ((printbufactive) && (printMethod == 0)) { printf("\n%s:\n", str); - for(cntr = 0; cntr < len; cntr++) { - if((cntr % 8) == 0 && cntr != 0) + for (cntr = 0; cntr < len; cntr++) { + if ((cntr % 8) == 0 && cntr != 0) printf(" "); - if((cntr % 16) == 0 && cntr != 0) + if ((cntr % 16) == 0 && cntr != 0) printf("\n"); - if((cntr % 16) == 0) + if ((cntr % 16) == 0) printf("%03x0 ", cntr2++); printf("%02x ", buf[cntr]); } printf("\n"); - }else if((printbufactive) && (printMethod == 1)) { + } else if ((printbufactive) && (printMethod == 1)) { printf("\n%s:\n", str); printf("Buf = {"); - for(cntr = 0; cntr < len; cntr++) { - if(cntr != 0) + for (cntr = 0; cntr < len; cntr++) { + if (cntr != 0) printf(","); - if((cntr % 16 == 0) && (cntr != 0)) + if ((cntr % 16 == 0) && (cntr != 0)) printf("\n"); printf("0x%02x", buf[cntr]); diff --git a/test/unit/unit_pico_device.c b/test/unit/unit_pico_device.c index ebecec8d..6f3ce153 100644 --- a/test/unit/unit_pico_device.c +++ b/test/unit/unit_pico_device.c @@ -2,21 +2,21 @@ START_TEST(test_pico_device) { - /* - * There is no real test performed here - * This test just inits a device and destroys it again - * This is just to check there are no asan errors, mem leaks, ... - */ - struct pico_device *dummy_device = NULL; - const uint8_t mac[PICO_SIZE_ETH] = { - 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 - }; - const char *name = "device_test"; + /* + * There is no real test performed here + * This test just inits a device and destroys it again + * This is just to check there are no asan errors, mem leaks, ... + */ + struct pico_device *dummy_device = NULL; + const uint8_t mac[PICO_SIZE_ETH] = { + 0x09, 0x00, 0x27, 0x39, 0xd0, 0xc6 + }; + const char *name = "device_test"; - struct pico_stack *S; - pico_stack_init(&S); - dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); - pico_device_init(S, dummy_device, name, mac); - pico_device_destroy(dummy_device); + struct pico_stack *S; + pico_stack_init(&S); + dummy_device = PICO_ZALLOC(sizeof(struct pico_device)); + pico_device_init(S, dummy_device, name, mac); + pico_device_destroy(dummy_device); } END_TEST diff --git a/test/unit/unit_rbtree.c b/test/unit/unit_rbtree.c index ceb00669..3d836269 100644 --- a/test/unit/unit_rbtree.c +++ b/test/unit/unit_rbtree.c @@ -21,7 +21,7 @@ static PICO_TREE_DECLARE(test_tree, compare); static PICO_TREE_DECLARE(test_tree2, compare); #define RBTEST_SIZE 20000 -START_TEST (test_rbtree2) +START_TEST(test_rbtree2) { struct pico_tree_node *s; elem *e; @@ -30,8 +30,7 @@ START_TEST (test_rbtree2) gettimeofday(&start, 0); srand48(RBTEST_SIZE); /* use test-size as salt */ - for (i = 0; i < (RBTEST_SIZE >> 1); i++) - { + for (i = 0; i < (RBTEST_SIZE >> 1); i++) { e = malloc(sizeof(elem)); e->value = (int)lrand48() % RBTEST_SIZE; if (pico_tree_findKey(&test_tree2, e)) { @@ -45,7 +44,7 @@ START_TEST (test_rbtree2) (int)((end.tv_sec - start.tv_sec) * 1000 + (end.tv_usec - start.tv_usec) / 1000)); last = 0; pico_tree_foreach(s, &test_tree2){ - fail_if (last > ((elem *)(s->keyValue))->value, "error"); + fail_if(last > ((elem *)(s->keyValue))->value, "error"); last = ((elem *)(s->keyValue))->value; } @@ -76,7 +75,7 @@ START_TEST (test_rbtree) } i = 0; pico_tree_foreach(s, &test_tree){ - fail_if (i++ != ((elem *)(s->keyValue))->value, "error"); + fail_if(i++ != ((elem *)(s->keyValue))->value, "error"); } t.value = RBTEST_SIZE >> 2; diff --git a/test/unit/unit_socket.c b/test/unit/unit_socket.c index 940195d5..04b39703 100644 --- a/test/unit/unit_socket.c +++ b/test/unit/unit_socket.c @@ -4,7 +4,7 @@ int pico_aodv_init(struct pico_stack *S) (void)S; return 0; } -START_TEST (test_socket) +START_TEST(test_socket) { int ret = 0; uint16_t port_be = 0, porta, proto, port_got; @@ -91,8 +91,8 @@ START_TEST (test_socket) ret = pico_socket_bind(sk_udp, &inaddr_link, &port_be); fail_if(ret < 0, "socket> udp socket bind failed"); - fail_if (pico_count_sockets(S, PICO_PROTO_UDP) != (1 + olsr_socket_udp_count)); - fail_if (pico_count_sockets(S, 0) != (2 + olsr_socket_udp_count)); + fail_if(pico_count_sockets(S, PICO_PROTO_UDP) != (1 + olsr_socket_udp_count)); + fail_if(pico_count_sockets(S, 0) != (2 + olsr_socket_udp_count)); ret = pico_socket_getname(sk_udp, &inaddr_got, &port_got, &proto); diff --git a/test/unit/unit_timer.c b/test/unit/unit_timer.c index c659a4b4..1006c2e4 100644 --- a/test/unit/unit_timer.c +++ b/test/unit/unit_timer.c @@ -1,7 +1,7 @@ #define EXISTING_TIMERS 9 -START_TEST (test_timers) +START_TEST(test_timers) { uint32_t T[128]; int i; @@ -12,14 +12,14 @@ START_TEST (test_timers) for (i = 0; i < 128; i++) { pico_time expire = (pico_time)(999999 + i); - void (*timer)(pico_time, void *) =(void (*)(pico_time, void *))0xff00 + i; + void (*timer)(pico_time, void *) = (void (*)(pico_time, void *)) 0xff00 + i; void *arg = ((void*)0xaa00 + i); T[i] = pico_timer_add(S, expire, timer, arg); printf("New timer %u\n", T[i]); } for (i = 0; i < 128; i++) { - void (*timer)(pico_time, void *) =(void (*)(pico_time, void *))0xff00 + i; + void (*timer)(pico_time, void *) = (void (*)(pico_time, void *)) 0xff00 + i; void *arg = ((void*)0xaa00 + i); fail_if((uint32_t)(i + 1) > S->Timers->n); @@ -29,9 +29,9 @@ START_TEST (test_timers) fail_unless(tref->tmr->arg == arg); } for (i = 127; i >= 0; i--) { - printf("Deleting timer %d \n", i ); + printf("Deleting timer %d \n", i); pico_timer_cancel(S, T[i]); - printf("Deleted timer %d \n", i ); + printf("Deleted timer %d \n", i); tref = heap_get_element(S->Timers, (uint32_t)i + EXISTING_TIMERS); fail_unless(tref->tmr == NULL); } diff --git a/test/units.c b/test/units.c index 545d9087..a35ca32a 100644 --- a/test/units.c +++ b/test/units.c @@ -77,7 +77,7 @@ Suite *pico_suite(void); -START_TEST (test_frame) +START_TEST(test_frame) { struct pico_frame *f1; struct pico_frame *cpy; diff --git a/uncrustify.cfg b/uncrustify.cfg index ba664df2..b9d82c08 100644 --- a/uncrustify.cfg +++ b/uncrustify.cfg @@ -1,1579 +1,3709 @@ -# Uncrustify 0.60 +# Uncrustify_d-0.78.1_f # # General options # -# The type of line endings -newlines = lf # auto/lf/crlf/cr +# The type of line endings. +# +# Default: auto +newlines = lf # lf/crlf/cr/auto + +# The original size of tabs in the input. +# +# Default: 8 +input_tab_size = 4 # unsigned number -# The original size of tabs in the input -input_tab_size = 4 # number +# The size of tabs in the output (only used if align_with_tabs=true). +# +# Default: 8 +output_tab_size = 4 # unsigned number -# The size of tabs in the output (only used if align_with_tabs=true) -output_tab_size = 4 # number +# The ASCII value of the string escape char, usually 92 (\) or (Pawn) 94 (^). +# +# Default: 92 +string_escape_char = 92 # unsigned number -# The ASCII value of the string escape char, usually 92 (\) or 94 (^). (Pawn) -string_escape_char = 92 # number +# Alternate string escape char (usually only used for Pawn). +# Only works right before the quote char. +string_escape_char2 = 0 # unsigned number -# Alternate string escape char for Pawn. Only works right before the quote char. -string_escape_char2 = 0 # number +# Replace tab characters found in string literals with the escape sequence \t +# instead. +string_replace_tab_chars = false # true/false -# Allow interpreting '>=' and '>>=' as part of a template in 'void f(list>=val);'. -# If true (default), 'assert(x<0 && y>=3)' will be broken. +# Allow interpreting '>=' and '>>=' as part of a template in code like +# 'void f(list>=val);'. If true, 'assert(x<0 && y>=3)' will be broken. # Improvements to template detection may make this option obsolete. -tok_split_gte = false # false/true +tok_split_gte = false # true/false + +# Disable formatting of NL_CONT ('\\n') ended lines (e.g. multi-line macros). +disable_processing_nl_cont = false # true/false + +# Specify the marker used in comments to disable processing of part of the +# file. +# +# Default: *INDENT-OFF* +disable_processing_cmt = " *INDENT-OFF*" # string -# Control what to do with the UTF-8 BOM (recommend 'remove') -utf8_bom = ignore # ignore/add/remove/force +# Specify the marker used in comments to (re)enable processing in a file. +# +# Default: *INDENT-ON* +enable_processing_cmt = " *INDENT-ON*" # string + +# Enable parsing of digraphs. +enable_digraphs = false # true/false + +# Option to allow both disable_processing_cmt and enable_processing_cmt +# strings, if specified, to be interpreted as ECMAScript regular expressions. +# If true, a regex search will be performed within comments according to the +# specified patterns in order to disable/enable processing. +processing_cmt_as_regex = false # true/false + +# Add or remove the UTF-8 BOM (recommend 'remove'). +utf8_bom = ignore # ignore/add/remove/force/not_defined -# If the file contains bytes with values between 128 and 255, but is not UTF-8, then output as UTF-8 -utf8_byte = false # false/true +# If the file contains bytes with values between 128 and 255, but is not +# UTF-8, then output as UTF-8. +utf8_byte = false # true/false -# Force the output encoding to UTF-8 -utf8_force = false # false/true +# Force the output encoding to UTF-8. +utf8_force = false # true/false # -# Indenting +# Spacing options # -# The number of columns to indent per level. -# Usually 2, 3, 4, or 8. -indent_columns = 4 # number +# Add or remove space around non-assignment symbolic operators ('+', '/', '%', +# '<<', and so forth). +sp_arith = add # ignore/add/remove/force/not_defined -# The continuation indent. If non-zero, this overrides the indent of '(' and '=' continuation indents. -# For FreeBSD, this is set to 4. Negative value is absolute and not increased for each ( level -indent_continue = 0 # number +# Add or remove space around arithmetic operators '+' and '-'. +# +# Overrides sp_arith. +sp_arith_additive = ignore # ignore/add/remove/force/not_defined -# How to use tabs when indenting code -# 0=spaces only -# 1=indent with tabs to brace level, align with spaces -# 2=indent and align with tabs, using spaces when not on a tabstop -indent_with_tabs = 0 # number +# Add or remove space around assignment operator '=', '+=', etc. +sp_assign = add # ignore/add/remove/force/not_defined -# Comments that are not a brace level are indented with tabs on a tabstop. -# Requires indent_with_tabs=2. If false, will use spaces. -indent_cmt_with_tabs = false # false/true +# Add or remove space around '=' in C++11 lambda capture specifications. +# +# Overrides sp_assign. +sp_cpp_lambda_assign = ignore # ignore/add/remove/force/not_defined -# Whether to indent strings broken by '\' so that they line up -indent_align_string = false # false/true +# Add or remove space after the capture specification of a C++11 lambda when +# an argument list is present, as in '[] (int x){ ... }'. +sp_cpp_lambda_square_paren = ignore # ignore/add/remove/force/not_defined -# The number of spaces to indent multi-line XML strings. -# Requires indent_align_string=True -indent_xml_string = 0 # number +# Add or remove space after the capture specification of a C++11 lambda with +# no argument list is present, as in '[] { ... }'. +sp_cpp_lambda_square_brace = ignore # ignore/add/remove/force/not_defined -# Spaces to indent '{' from level -indent_brace = 0 # number +# Add or remove space after the opening parenthesis and before the closing +# parenthesis of a argument list of a C++11 lambda, as in +# '[]( ){ ... }' +# with an empty list. +sp_cpp_lambda_argument_list_empty = ignore # ignore/add/remove/force/not_defined -# Whether braces are indented to the body level -indent_braces = false # false/true +# Add or remove space after the opening parenthesis and before the closing +# parenthesis of a argument list of a C++11 lambda, as in +# '[]( int x ){ ... }'. +sp_cpp_lambda_argument_list = ignore # ignore/add/remove/force/not_defined -# Disabled indenting function braces if indent_braces is true -indent_braces_no_func = false # false/true +# Add or remove space after the argument list of a C++11 lambda, as in +# '[](int x) { ... }'. +sp_cpp_lambda_paren_brace = ignore # ignore/add/remove/force/not_defined -# Disabled indenting class braces if indent_braces is true -indent_braces_no_class = false # false/true +# Add or remove space between a lambda body and its call operator of an +# immediately invoked lambda, as in '[]( ... ){ ... } ( ... )'. +sp_cpp_lambda_fparen = ignore # ignore/add/remove/force/not_defined -# Disabled indenting struct braces if indent_braces is true -indent_braces_no_struct = false # false/true +# Add or remove space around assignment operator '=' in a prototype. +# +# If set to ignore, use sp_assign. +sp_assign_default = add # ignore/add/remove/force/not_defined -# Indent based on the size of the brace parent, i.e. 'if' => 3 spaces, 'for' => 4 spaces, etc. -indent_brace_parent = false # false/true +# Add or remove space before assignment operator '=', '+=', etc. +# +# Overrides sp_assign. +sp_before_assign = add # ignore/add/remove/force/not_defined -# Whether the 'namespace' body is indented -indent_namespace = false # false/true +# Add or remove space after assignment operator '=', '+=', etc. +# +# Overrides sp_assign. +sp_after_assign = add # ignore/add/remove/force/not_defined -# The number of spaces to indent a namespace block -indent_namespace_level = 0 # number +# Add or remove space in 'enum {'. +# +# Default: add +sp_enum_brace = add # ignore/add/remove/force/not_defined -# If the body of the namespace is longer than this number, it won't be indented. -# Requires indent_namespace=true. Default=0 (no limit) -indent_namespace_limit = 0 # number +# Add or remove space in 'NS_ENUM ('. +sp_enum_paren = ignore # ignore/add/remove/force/not_defined -# Whether the 'extern "C"' body is indented -indent_extern = false # false/true +# Add or remove space around assignment '=' in enum. +sp_enum_assign = add # ignore/add/remove/force/not_defined -# Whether the 'class' body is indented -indent_class = false # false/true +# Add or remove space before assignment '=' in enum. +# +# Overrides sp_enum_assign. +sp_enum_before_assign = add # ignore/add/remove/force/not_defined -# Whether to indent the stuff after a leading class colon -indent_class_colon = false # false/true +# Add or remove space after assignment '=' in enum. +# +# Overrides sp_enum_assign. +sp_enum_after_assign = add # ignore/add/remove/force/not_defined -# Virtual indent from the ':' for member initializers. Default is 2 -indent_ctor_init_leading = 2 # number +# Add or remove space around assignment ':' in enum. +sp_enum_colon = ignore # ignore/add/remove/force/not_defined -# Additional indenting for constructor initializer list -indent_ctor_init = 0 # number +# Add or remove space around preprocessor '##' concatenation operator. +# +# Default: add +sp_pp_concat = add # ignore/add/remove/force/not_defined -# False=treat 'else\nif' as 'else if' for indenting purposes -# True=indent the 'if' one level -indent_else_if = false # false/true +# Add or remove space after preprocessor '#' stringify operator. +# Also affects the '#@' charizing operator. +sp_pp_stringify = ignore # ignore/add/remove/force/not_defined -# Amount to indent variable declarations after a open brace. neg=relative, pos=absolute -indent_var_def_blk = 0 # number +# Add or remove space before preprocessor '#' stringify operator +# as in '#define x(y) L#y'. +sp_before_pp_stringify = ignore # ignore/add/remove/force/not_defined -# Indent continued variable declarations instead of aligning. -indent_var_def_cont = false # false/true +# Add or remove space around boolean operators '&&' and '||'. +sp_bool = add # ignore/add/remove/force/not_defined -# True: force indentation of function definition to start in column 1 -# False: use the default behavior -indent_func_def_force_col1 = false # false/true +# Add or remove space around compare operator '<', '>', '==', etc. +sp_compare = add # ignore/add/remove/force/not_defined -# True: indent continued function call parameters one indent level -# False: align parameters under the open paren -indent_func_call_param = false # false/true +# Add or remove space inside '(' and ')'. +sp_inside_paren = remove # ignore/add/remove/force/not_defined -# Same as indent_func_call_param, but for function defs -indent_func_def_param = false # false/true +# Add or remove space between nested parentheses, i.e. '((' vs. ') )'. +sp_paren_paren = remove # ignore/add/remove/force/not_defined -# Same as indent_func_call_param, but for function protos -indent_func_proto_param = false # false/true +# Add or remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. +sp_cparen_oparen = ignore # ignore/add/remove/force/not_defined -# Same as indent_func_call_param, but for class declarations -indent_func_class_param = false # false/true +# Whether to balance spaces inside nested parentheses. +sp_balance_nested_parens = false # true/false -# Same as indent_func_call_param, but for class variable constructors -indent_func_ctor_var_param = false # false/true +# Add or remove space between ')' and '{'. +sp_paren_brace = ignore # ignore/add/remove/force/not_defined -# Same as indent_func_call_param, but for templates -indent_template_param = false # false/true +# Add or remove space between nested braces, i.e. '{{' vs. '{ {'. +sp_brace_brace = ignore # ignore/add/remove/force/not_defined -# Double the indent for indent_func_xxx_param options -indent_func_param_double = false # false/true +# Add or remove space before pointer star '*'. +sp_before_ptr_star = ignore # ignore/add/remove/force/not_defined -# Indentation column for standalone 'const' function decl/proto qualifier -indent_func_const = 0 # number +# Add or remove space before pointer star '*' that isn't followed by a +# variable name. If set to ignore, sp_before_ptr_star is used instead. +sp_before_unnamed_ptr_star = ignore # ignore/add/remove/force/not_defined -# Indentation column for standalone 'throw' function decl/proto qualifier -indent_func_throw = 0 # number +# Add or remove space before pointer star '*' that is followed by a qualifier. +# If set to ignore, sp_before_unnamed_ptr_star is used instead. +sp_before_qualifier_ptr_star = ignore # ignore/add/remove/force/not_defined -# The number of spaces to indent a continued '->' or '.' -# Usually set to 0, 1, or indent_columns. -indent_member = 0 # number +# Add or remove space before pointer star '*' that is followed by 'operator' keyword. +# If set to ignore, sp_before_unnamed_ptr_star is used instead. +sp_before_operator_ptr_star = ignore # ignore/add/remove/force/not_defined -# Spaces to indent single line ('//') comments on lines before code -indent_sing_line_comments = 0 # number +# Add or remove space before pointer star '*' that is followed by +# a class scope (as in 'int *MyClass::method()') or namespace scope +# (as in 'int *my_ns::func()'). +# If set to ignore, sp_before_unnamed_ptr_star is used instead. +sp_before_scope_ptr_star = ignore # ignore/add/remove/force/not_defined -# If set, will indent trailing single line ('//') comments relative -# to the code instead of trying to keep the same absolute column -indent_relative_single_line_comments = false # false/true +# Add or remove space before pointer star '*' that is followed by '::', +# as in 'int *::func()'. +# If set to ignore, sp_before_unnamed_ptr_star is used instead. +sp_before_global_scope_ptr_star = ignore # ignore/add/remove/force/not_defined -# Spaces to indent 'case' from 'switch' -# Usually 0 or indent_columns. -indent_switch_case = 0 # number +# Add or remove space between a qualifier and a pointer star '*' that isn't +# followed by a variable name, as in '(char const *)'. If set to ignore, +# sp_before_ptr_star is used instead. +sp_qualifier_unnamed_ptr_star = ignore # ignore/add/remove/force/not_defined -# Spaces to shift the 'case' line, without affecting any other lines -# Usually 0. -indent_case_shift = 0 # number +# Add or remove space between pointer stars '*', as in 'int ***a;'. +sp_between_ptr_star = ignore # ignore/add/remove/force/not_defined -# Spaces to indent '{' from 'case'. -# By default, the brace will appear under the 'c' in case. -# Usually set to 0 or indent_columns. -indent_case_brace = 0 # number +# Add or remove space between pointer star '*' and reference '&', as in 'int *& a;'. +sp_between_ptr_ref = ignore # ignore/add/remove/force/not_defined -# Whether to indent comments found in first column -indent_col1_comment = false # false/true +# Add or remove space after pointer star '*', if followed by a word. +# +# Overrides sp_type_func. +sp_after_ptr_star = remove # ignore/add/remove/force/not_defined -# How to indent goto labels -# >0 : absolute column where 1 is the leftmost column -# <=0 : subtract from brace indent -indent_label = 1 # number +# Add or remove space after pointer caret '^', if followed by a word. +sp_after_ptr_block_caret = ignore # ignore/add/remove/force/not_defined -# Same as indent_label, but for access specifiers that are followed by a colon -indent_access_spec = 1 # number +# Add or remove space after pointer star '*', if followed by a qualifier. +sp_after_ptr_star_qualifier = ignore # ignore/add/remove/force/not_defined -# Indent the code after an access specifier by one level. -# If set, this option forces 'indent_access_spec=0' -indent_access_spec_body = false # false/true +# Add or remove space after a pointer star '*', if followed by a function +# prototype or function definition. +# +# Overrides sp_after_ptr_star and sp_type_func. +sp_after_ptr_star_func = ignore # ignore/add/remove/force/not_defined -# If an open paren is followed by a newline, indent the next line so that it lines up after the open paren (not recommended) -indent_paren_nl = false # false/true +# Add or remove space after a pointer star '*' in the trailing return of a +# function prototype or function definition. +sp_after_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined -# Controls the indent of a close paren after a newline. -# 0: Indent to body level -# 1: Align under the open paren -# 2: Indent to the brace level -indent_paren_close = 0 # number +# Add or remove space between the pointer star '*' and the name of the variable +# in a function pointer definition. +sp_ptr_star_func_var = ignore # ignore/add/remove/force/not_defined -# Controls the indent of a comma when inside a paren.If TRUE, aligns under the open paren -indent_comma_paren = false # false/true +# Add or remove space between the pointer star '*' and the name of the type +# in a function pointer type definition. +sp_ptr_star_func_type = ignore # ignore/add/remove/force/not_defined -# Controls the indent of a BOOL operator when inside a paren.If TRUE, aligns under the open paren -indent_bool_paren = false # false/true +# Add or remove space after a pointer star '*', if followed by an open +# parenthesis, as in 'void* (*)()'. +sp_ptr_star_paren = ignore # ignore/add/remove/force/not_defined -# If 'indent_bool_paren' is true, controls the indent of the first expression. If TRUE, aligns the first expression to the following ones -indent_first_bool_expr = false # false/true +# Add or remove space before a pointer star '*', if followed by a function +# prototype or function definition. If set to ignore, sp_before_ptr_star is +# used instead. +sp_before_ptr_star_func = ignore # ignore/add/remove/force/not_defined -# If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended) -indent_square_nl = false # false/true +# Add or remove space between a qualifier and a pointer star '*' followed by +# the name of the function in a function prototype or definition, as in +# 'char const *foo()`. If set to ignore, sp_before_ptr_star is used instead. +sp_qualifier_ptr_star_func = ignore # ignore/add/remove/force/not_defined -# Don't change the relative indent of ESQL/C 'EXEC SQL' bodies -indent_preserve_sql = false # false/true +# Add or remove space before a pointer star '*' in the trailing return of a +# function prototype or function definition. +sp_before_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined -# Align continued statements at the '='. Default=True -# If FALSE or the '=' is followed by a newline, the next line is indent one tab. -indent_align_assign = true # false/true +# Add or remove space between a qualifier and a pointer star '*' in the +# trailing return of a function prototype or function definition, as in +# 'auto foo() -> char const *'. +sp_qualifier_ptr_star_trailing = ignore # ignore/add/remove/force/not_defined -# Indent OC blocks at brace level instead of usual rules. -indent_oc_block = false # false/true +# Add or remove space before a reference sign '&'. +sp_before_byref = ignore # ignore/add/remove/force/not_defined -# Indent OC blocks in a message relative to the parameter name. -# 0=use indent_oc_block rules, 1+=spaces to indent -indent_oc_block_msg = 0 # number +# Add or remove space before a reference sign '&' that isn't followed by a +# variable name. If set to ignore, sp_before_byref is used instead. +sp_before_unnamed_byref = ignore # ignore/add/remove/force/not_defined -# Minimum indent for subsequent parameters -indent_oc_msg_colon = 0 # number +# Add or remove space after reference sign '&', if followed by a word. +# +# Overrides sp_type_func. +sp_after_byref = remove # ignore/add/remove/force/not_defined +# Add or remove space after a reference sign '&', if followed by a function +# prototype or function definition. # -# Spacing options +# Overrides sp_after_byref and sp_type_func. +sp_after_byref_func = remove # ignore/add/remove/force/not_defined + +# Add or remove space before a reference sign '&', if followed by a function +# prototype or function definition. +sp_before_byref_func = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after a reference sign '&', if followed by an open +# parenthesis, as in 'char& (*)()'. +sp_byref_paren = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between type and word. In cases where total removal of +# whitespace would be a syntax error, a value of 'remove' is treated the same +# as 'force'. # +# This also affects some other instances of space following a type that are +# not covered by other options; for example, between the return type and +# parenthesis of a function type template argument, between the type and +# parenthesis of an array parameter, or between 'decltype(...)' and the +# following word. +# +# Default: force +sp_after_type = force # ignore/add/remove/force/not_defined + +# Add or remove space between 'decltype(...)' and word, +# brace or function call. +sp_after_decltype = ignore # ignore/add/remove/force/not_defined -# Add or remove space around arithmetic operator '+', '-', '/', '*', etc -sp_arith = add # ignore/add/remove/force +# (D) Add or remove space before the parenthesis in the D constructs +# 'template Foo(' and 'class Foo('. +sp_before_template_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space around assignment operator '=', '+=', etc -sp_assign = add # ignore/add/remove/force +# Add or remove space between 'template' and '<'. +# If set to ignore, sp_before_angle is used. +sp_template_angle = ignore # ignore/add/remove/force/not_defined -# Add or remove space around '=' in C++11 lambda capture specifications. Overrides sp_assign -sp_cpp_lambda_assign = ignore # ignore/add/remove/force +# Add or remove space before '<'. +sp_before_angle = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the capture specification in C++11 lambda. -sp_cpp_lambda_paren = ignore # ignore/add/remove/force +# Add or remove space inside '<' and '>'. +sp_inside_angle = ignore # ignore/add/remove/force/not_defined -# Add or remove space around assignment operator '=' in a prototype -sp_assign_default = add # ignore/add/remove/force +# Add or remove space inside '<>'. +# if empty. +sp_inside_angle_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space before assignment operator '=', '+=', etc. Overrides sp_assign. -sp_before_assign = add # ignore/add/remove/force +# Add or remove space between '>' and ':'. +sp_angle_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space after assignment operator '=', '+=', etc. Overrides sp_assign. -sp_after_assign = add # ignore/add/remove/force +# Add or remove space after '>'. +sp_after_angle = ignore # ignore/add/remove/force/not_defined -# Add or remove space around assignment '=' in enum -sp_enum_assign = add # ignore/add/remove/force +# Add or remove space between '>' and '(' as found in 'new List(foo);'. +sp_angle_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before assignment '=' in enum. Overrides sp_enum_assign. -sp_enum_before_assign = add # ignore/add/remove/force +# Add or remove space between '>' and '()' as found in 'new List();'. +sp_angle_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space after assignment '=' in enum. Overrides sp_enum_assign. -sp_enum_after_assign = add # ignore/add/remove/force +# Add or remove space between '>' and a word as in 'List m;' or +# 'template static ...'. +sp_angle_word = ignore # ignore/add/remove/force/not_defined -# Add or remove space around preprocessor '##' concatenation operator. Default=Add -sp_pp_concat = add # ignore/add/remove/force +# Add or remove space between '>' and '>' in '>>' (template stuff). +# +# Default: add +sp_angle_shift = add # ignore/add/remove/force/not_defined -# Add or remove space after preprocessor '#' stringify operator. Also affects the '#@' charizing operator. -sp_pp_stringify = ignore # ignore/add/remove/force +# (C++11) Permit removal of the space between '>>' in 'foo >'. Note +# that sp_angle_shift cannot remove the space without this option. +sp_permit_cpp11_shift = false # true/false -# Add or remove space before preprocessor '#' stringify operator as in '#define x(y) L#y'. -sp_before_pp_stringify = ignore # ignore/add/remove/force +# Add or remove space before '(' of control statements ('if', 'for', 'switch', +# 'while', etc.). +sp_before_sparen = add # ignore/add/remove/force/not_defined -# Add or remove space around boolean operators '&&' and '||' -sp_bool = add # ignore/add/remove/force +# Add or remove space inside '(' and ')' of control statements other than +# 'for'. +sp_inside_sparen = remove # ignore/add/remove/force/not_defined -# Add or remove space around compare operator '<', '>', '==', etc -sp_compare = add # ignore/add/remove/force +# Add or remove space after '(' of control statements other than 'for'. +# +# Overrides sp_inside_sparen. +sp_inside_sparen_open = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside '(' and ')' -sp_inside_paren = remove # ignore/add/remove/force +# Add or remove space before ')' of control statements other than 'for'. +# +# Overrides sp_inside_sparen. +sp_inside_sparen_close = ignore # ignore/add/remove/force/not_defined -# Add or remove space between nested parens -sp_paren_paren = remove # ignore/add/remove/force +# Add or remove space inside '(' and ')' of 'for' statements. +sp_inside_for = ignore # ignore/add/remove/force/not_defined -# Whether to balance spaces inside nested parens -sp_balance_nested_parens = false # false/true +# Add or remove space after '(' of 'for' statements. +# +# Overrides sp_inside_for. +sp_inside_for_open = ignore # ignore/add/remove/force/not_defined -# Add or remove space between ')' and '{' -sp_paren_brace = ignore # ignore/add/remove/force +# Add or remove space before ')' of 'for' statements. +# +# Overrides sp_inside_for. +sp_inside_for_close = ignore # ignore/add/remove/force/not_defined -# Add or remove space before pointer star '*' -sp_before_ptr_star = ignore # ignore/add/remove/force +# Add or remove space between '((' or '))' of control statements. +sp_sparen_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before pointer star '*' that isn't followed by a variable name -# If set to 'ignore', sp_before_ptr_star is used instead. -sp_before_unnamed_ptr_star = ignore # ignore/add/remove/force +# Add or remove space after ')' of control statements. +sp_after_sparen = ignore # ignore/add/remove/force/not_defined -# Add or remove space between pointer stars '*' -sp_between_ptr_star = ignore # ignore/add/remove/force +# Add or remove space between ')' and '{' of control statements. +sp_sparen_brace = add # ignore/add/remove/force/not_defined -# Add or remove space after pointer star '*', if followed by a word. -sp_after_ptr_star = remove # ignore/add/remove/force +# Add or remove space between 'do' and '{'. +sp_do_brace_open = ignore # ignore/add/remove/force/not_defined -# Add or remove space after a pointer star '*', if followed by a func proto/def. -sp_after_ptr_star_func = ignore # ignore/add/remove/force +# Add or remove space between '}' and 'while'. +sp_brace_close_while = ignore # ignore/add/remove/force/not_defined -# Add or remove space after a pointer star '*', if followed by an open paren (function types). -sp_ptr_star_paren = ignore # ignore/add/remove/force +# Add or remove space between 'while' and '('. Overrides sp_before_sparen. +sp_while_paren_open = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a pointer star '*', if followed by a func proto/def. -sp_before_ptr_star_func = ignore # ignore/add/remove/force +# (D) Add or remove space between 'invariant' and '('. +sp_invariant_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a reference sign '&' -sp_before_byref = ignore # ignore/add/remove/force +# (D) Add or remove space after the ')' in 'invariant (C) c'. +sp_after_invariant_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a reference sign '&' that isn't followed by a variable name -# If set to 'ignore', sp_before_byref is used instead. -sp_before_unnamed_byref = ignore # ignore/add/remove/force +# Add or remove space before empty statement ';' on 'if', 'for' and 'while'. +sp_special_semi = ignore # ignore/add/remove/force/not_defined -# Add or remove space after reference sign '&', if followed by a word. -sp_after_byref = remove # ignore/add/remove/force +# Add or remove space before ';'. +# +# Default: remove +sp_before_semi = remove # ignore/add/remove/force/not_defined -# Add or remove space after a reference sign '&', if followed by a func proto/def. -sp_after_byref_func = remove # ignore/add/remove/force +# Add or remove space before ';' in non-empty 'for' statements. +sp_before_semi_for = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a reference sign '&', if followed by a func proto/def. -sp_before_byref_func = ignore # ignore/add/remove/force +# Add or remove space before a semicolon of an empty left part of a for +# statement, as in 'for ( ; ; )'. +sp_before_semi_for_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space between type and word. Default=Force -sp_after_type = force # ignore/add/remove/force +# Add or remove space between the semicolons of an empty middle part of a for +# statement, as in 'for ( ; ; )'. +sp_between_semi_for_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space before the paren in the D constructs 'template Foo(' and 'class Foo('. -sp_before_template_paren = ignore # ignore/add/remove/force +# Add or remove space after ';', except when followed by a comment. +# +# Default: add +sp_after_semi = remove # ignore/add/remove/force/not_defined -# Add or remove space in 'template <' vs 'template<'. -# If set to ignore, sp_before_angle is used. -sp_template_angle = ignore # ignore/add/remove/force +# Add or remove space after ';' in non-empty 'for' statements. +# +# Default: force +sp_after_semi_for = force # ignore/add/remove/force/not_defined + +# Add or remove space after the final semicolon of an empty part of a for +# statement, as in 'for ( ; ; )'. +sp_after_semi_for_empty = ignore # ignore/add/remove/force/not_defined + +# Add or remove space before '[' (except '[]'). +sp_before_square = ignore # ignore/add/remove/force/not_defined + +# Add or remove space before '[' for a variable definition. +# +# Default: remove +sp_before_vardef_square = remove # ignore/add/remove/force/not_defined + +# Add or remove space before '[' for asm block. +sp_before_square_asm_block = ignore # ignore/add/remove/force/not_defined + +# Add or remove space before '[]'. +sp_before_squares = ignore # ignore/add/remove/force/not_defined + +# Add or remove space before C++17 structured bindings. +sp_cpp_before_struct_binding = ignore # ignore/add/remove/force/not_defined + +# Add or remove space inside a non-empty '[' and ']'. +sp_inside_square = ignore # ignore/add/remove/force/not_defined + +# Add or remove space inside '[]'. +# if empty. +sp_inside_square_empty = ignore # ignore/add/remove/force/not_defined + +# (OC) Add or remove space inside a non-empty Objective-C boxed array '@[' and +# ']'. If set to ignore, sp_inside_square is used. +sp_inside_square_oc_array = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after ',', i.e. 'a,b' vs. 'a, b'. +sp_after_comma = add # ignore/add/remove/force/not_defined + +# Add or remove space before ',', i.e. 'a,b' vs. 'a ,b'. +# +# Default: remove +sp_before_comma = remove # ignore/add/remove/force/not_defined + +# (C#, Vala) Add or remove space between ',' and ']' in multidimensional array type +# like 'int[,,]'. +sp_after_mdatype_commas = ignore # ignore/add/remove/force/not_defined + +# (C#, Vala) Add or remove space between '[' and ',' in multidimensional array type +# like 'int[,,]'. +sp_before_mdatype_commas = ignore # ignore/add/remove/force/not_defined + +# (C#, Vala) Add or remove space between ',' in multidimensional array type +# like 'int[,,]'. +sp_between_mdatype_commas = ignore # ignore/add/remove/force/not_defined -# Add or remove space before '<>' -sp_before_angle = ignore # ignore/add/remove/force +# Add or remove space between an open parenthesis and comma, +# i.e. '(,' vs. '( ,'. +# +# Default: force +sp_paren_comma = force # ignore/add/remove/force/not_defined + +# Add or remove space between a type and ':'. +sp_type_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside '<' and '>' -sp_inside_angle = ignore # ignore/add/remove/force +# Add or remove space after the variadic '...' when preceded by a +# non-punctuator. +# The value REMOVE will be overridden with FORCE +sp_after_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space after '<>' -sp_after_angle = ignore # ignore/add/remove/force +# Add or remove space before the variadic '...' when preceded by a +# non-punctuator. +# The value REMOVE will be overridden with FORCE +sp_before_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '<>' and '(' as found in 'new List();' -sp_angle_paren = ignore # ignore/add/remove/force +# Add or remove space between a type and '...'. +sp_type_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '<>' and a word as in 'List m;' -sp_angle_word = ignore # ignore/add/remove/force +# Add or remove space between a '*' and '...'. +sp_ptr_type_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '>' and '>' in '>>' (template stuff C++/C# only). Default=Add -sp_angle_shift = add # ignore/add/remove/force +# Add or remove space between ')' and '...'. +sp_paren_ellipsis = ignore # ignore/add/remove/force/not_defined -# Permit removal of the space between '>>' in 'foo >' (C++11 only). Default=False -# sp_angle_shift cannot remove the space without this option. -sp_permit_cpp11_shift = false # false/true +# Add or remove space between '&&' and '...'. +sp_byref_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space before '(' of 'if', 'for', 'switch', and 'while' -sp_before_sparen = ignore # ignore/add/remove/force +# Add or remove space between ')' and a qualifier such as 'const'. +sp_paren_qualifier = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside if-condition '(' and ')' -sp_inside_sparen = ignore # ignore/add/remove/force +# Add or remove space between ')' and 'noexcept'. +sp_paren_noexcept = ignore # ignore/add/remove/force/not_defined -# Add or remove space before if-condition ')'. Overrides sp_inside_sparen. -sp_inside_sparen_close = ignore # ignore/add/remove/force +# Add or remove space after class ':'. +sp_after_class_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space before if-condition '('. Overrides sp_inside_sparen. -sp_inside_sparen_open = ignore # ignore/add/remove/force +# Add or remove space before class ':'. +sp_before_class_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space after ')' of 'if', 'for', 'switch', and 'while' -sp_after_sparen = ignore # ignore/add/remove/force +# Add or remove space after class constructor ':'. +# +# Default: add +sp_after_constr_colon = add # ignore/add/remove/force/not_defined -# Add or remove space between ')' and '{' of 'if', 'for', 'switch', and 'while' -sp_sparen_brace = ignore # ignore/add/remove/force +# Add or remove space before class constructor ':'. +# +# Default: add +sp_before_constr_colon = add # ignore/add/remove/force/not_defined -# Add or remove space between 'invariant' and '(' in the D language. -sp_invariant_paren = ignore # ignore/add/remove/force +# Add or remove space before case ':'. +# +# Default: remove +sp_before_case_colon = remove # ignore/add/remove/force/not_defined -# Add or remove space after the ')' in 'invariant (C) c' in the D language. -sp_after_invariant_paren = ignore # ignore/add/remove/force +# Add or remove space between 'operator' and operator sign. +sp_after_operator = ignore # ignore/add/remove/force/not_defined -# Add or remove space before empty statement ';' on 'if', 'for' and 'while' -sp_special_semi = ignore # ignore/add/remove/force +# Add or remove space between the operator symbol and the open parenthesis, as +# in 'operator ++('. +sp_after_operator_sym = ignore # ignore/add/remove/force/not_defined -# Add or remove space before ';'. Default=Remove -sp_before_semi = remove # ignore/add/remove/force +# Overrides sp_after_operator_sym when the operator has no arguments, as in +# 'operator *()'. +sp_after_operator_sym_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space before ';' in non-empty 'for' statements -sp_before_semi_for = ignore # ignore/add/remove/force +# Add or remove space after C/D cast, i.e. 'cast(int)a' vs. 'cast(int) a' or +# '(int)a' vs. '(int) a'. +sp_after_cast = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a semicolon of an empty part of a for statement. -sp_before_semi_for_empty = ignore # ignore/add/remove/force +# Add or remove spaces inside cast parentheses. +sp_inside_paren_cast = ignore # ignore/add/remove/force/not_defined -# Add or remove space after ';', except when followed by a comment. Default=Add -sp_after_semi = remove # ignore/add/remove/force +# Add or remove space between the type and open parenthesis in a C++ cast, +# i.e. 'int(exp)' vs. 'int (exp)'. +sp_cpp_cast_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space after ';' in non-empty 'for' statements. Default=Force -sp_after_semi_for = force # ignore/add/remove/force +# Add or remove space between 'sizeof' and '('. +sp_sizeof_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the final semicolon of an empty part of a for statement: for ( ; ; ). -sp_after_semi_for_empty = ignore # ignore/add/remove/force +# Add or remove space between 'sizeof' and '...'. +sp_sizeof_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space before '[' (except '[]') -sp_before_square = ignore # ignore/add/remove/force +# Add or remove space between 'sizeof...' and '('. +sp_sizeof_ellipsis_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before '[]' -sp_before_squares = ignore # ignore/add/remove/force +# Add or remove space between '...' and a parameter pack. +sp_ellipsis_parameter_pack = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside a non-empty '[' and ']' -sp_inside_square = ignore # ignore/add/remove/force +# Add or remove space between a parameter pack and '...'. +sp_parameter_pack_ellipsis = ignore # ignore/add/remove/force/not_defined -# Add or remove space after ',' -sp_after_comma = add # ignore/add/remove/force +# Add or remove space between 'decltype' and '('. +sp_decltype_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space before ',' -sp_before_comma = remove # ignore/add/remove/force +# (Pawn) Add or remove space after the tag keyword. +sp_after_tag = ignore # ignore/add/remove/force/not_defined -# Add or remove space between an open paren and comma: '(,' vs '( ,' -sp_paren_comma = force # ignore/add/remove/force +# Add or remove space inside enum '{' and '}'. +sp_inside_braces_enum = ignore # ignore/add/remove/force/not_defined -# Add or remove space before the variadic '...' when preceded by a non-punctuator -sp_before_ellipsis = ignore # ignore/add/remove/force +# Add or remove space inside struct/union '{' and '}'. +sp_inside_braces_struct = ignore # ignore/add/remove/force/not_defined -# Add or remove space after class ':' -sp_after_class_colon = ignore # ignore/add/remove/force +# (OC) Add or remove space inside Objective-C boxed dictionary '{' and '}' +sp_inside_braces_oc_dict = ignore # ignore/add/remove/force/not_defined -# Add or remove space before class ':' -sp_before_class_colon = ignore # ignore/add/remove/force +# Add or remove space after open brace in an unnamed temporary +# direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore. +sp_after_type_brace_init_lst_open = ignore # ignore/add/remove/force/not_defined -# Add or remove space before case ':'. Default=Remove -sp_before_case_colon = remove # ignore/add/remove/force +# Add or remove space before close brace in an unnamed temporary +# direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore. +sp_before_type_brace_init_lst_close = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'operator' and operator sign -sp_after_operator = ignore # ignore/add/remove/force +# Add or remove space inside an unnamed temporary direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore +# works only if sp_before_type_brace_init_lst_close is set to ignore. +sp_inside_type_brace_init_lst = ignore # ignore/add/remove/force/not_defined -# Add or remove space between the operator symbol and the open paren, as in 'operator ++(' -sp_after_operator_sym = ignore # ignore/add/remove/force +# Add or remove space inside '{' and '}'. +sp_inside_braces = ignore # ignore/add/remove/force/not_defined -# Add or remove space after C/D cast, i.e. 'cast(int)a' vs 'cast(int) a' or '(int)a' vs '(int) a' -sp_after_cast = ignore # ignore/add/remove/force +# Add or remove space inside '{}'. +# if empty. +sp_inside_braces_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove spaces inside cast parens -sp_inside_paren_cast = ignore # ignore/add/remove/force +# Add or remove space around trailing return operator '->'. +sp_trailing_return = ignore # ignore/add/remove/force/not_defined -# Add or remove space between the type and open paren in a C++ cast, i.e. 'int(exp)' vs 'int (exp)' -sp_cpp_cast_paren = ignore # ignore/add/remove/force +# Add or remove space between return type and function name. A minimum of 1 +# is forced except for pointer return types. +sp_type_func = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'sizeof' and '(' -sp_sizeof_paren = ignore # ignore/add/remove/force +# Add or remove space between type and open brace of an unnamed temporary +# direct-list-initialization. +sp_type_brace_init_lst = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the tag keyword (Pawn) -sp_after_tag = ignore # ignore/add/remove/force +# Add or remove space between function name and '(' on function declaration. +sp_func_proto_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside enum '{' and '}' -sp_inside_braces_enum = ignore # ignore/add/remove/force +# Add or remove space between function name and '()' on function declaration +# if empty. +sp_func_proto_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside struct/union '{' and '}' -sp_inside_braces_struct = ignore # ignore/add/remove/force +# Add or remove space between function name and '(' with a typedef specifier. +sp_func_type_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside '{' and '}' -sp_inside_braces = ignore # ignore/add/remove/force +# Add or remove space between alias name and '(' of a non-pointer function type typedef. +sp_func_def_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside '{}' -sp_inside_braces_empty = ignore # ignore/add/remove/force +# Add or remove space between function name and '()' on function definition +# if empty. +sp_func_def_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space between return type and function name -# A minimum of 1 is forced except for pointer return types. -sp_type_func = ignore # ignore/add/remove/force +# Add or remove space inside empty function '()'. +# Overrides sp_after_angle unless use_sp_after_angle_always is set to true. +sp_inside_fparens = ignore # ignore/add/remove/force/not_defined -# Add or remove space between function name and '(' on function declaration -sp_func_proto_paren = ignore # ignore/add/remove/force +# Add or remove space inside function '(' and ')'. +sp_inside_fparen = remove # ignore/add/remove/force/not_defined -# Add or remove space between function name and '(' on function definition -sp_func_def_paren = ignore # ignore/add/remove/force +# Add or remove space inside user functor '(' and ')'. +sp_func_call_user_inside_rparen = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside empty function '()' -sp_inside_fparens = ignore # ignore/add/remove/force +# Add or remove space inside empty functor '()'. +# Overrides sp_after_angle unless use_sp_after_angle_always is set to true. +sp_inside_rparens = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside function '(' and ')' -sp_inside_fparen = ignore # ignore/add/remove/force +# Add or remove space inside functor '(' and ')'. +sp_inside_rparen = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside the first parens in the function type: 'void (*x)(...)' -sp_inside_tparen = ignore # ignore/add/remove/force +# Add or remove space inside the first parentheses in a function type, as in +# 'void (*x)(...)'. +sp_inside_tparen = ignore # ignore/add/remove/force/not_defined -# Add or remove between the parens in the function type: 'void (*x)(...)' -sp_after_tparen_close = ignore # ignore/add/remove/force +# Add or remove space between the ')' and '(' in a function type, as in +# 'void (*x)(...)'. +sp_after_tparen_close = ignore # ignore/add/remove/force/not_defined # Add or remove space between ']' and '(' when part of a function call. -sp_square_fparen = ignore # ignore/add/remove/force +sp_square_fparen = ignore # ignore/add/remove/force/not_defined -# Add or remove space between ')' and '{' of function -sp_fparen_brace = ignore # ignore/add/remove/force +# Add or remove space between ')' and '{' of function. +sp_fparen_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove space between function name and '(' on function calls -sp_func_call_paren = ignore # ignore/add/remove/force +# Add or remove space between ')' and '{' of a function call in object +# initialization. +# +# Overrides sp_fparen_brace. +sp_fparen_brace_initializer = ignore # ignore/add/remove/force/not_defined -# Add or remove space between function name and '()' on function calls without parameters. -# If set to 'ignore' (the default), sp_func_call_paren is used. -sp_func_call_paren_empty = ignore # ignore/add/remove/force +# (Java) Add or remove space between ')' and '{{' of double brace initializer. +sp_fparen_dbrace = ignore # ignore/add/remove/force/not_defined -# Add or remove space between the user function name and '(' on function calls -# You need to set a keyword to be a user function, like this: 'set func_call_user _' in the config file. -sp_func_call_user_paren = ignore # ignore/add/remove/force +# Add or remove space between function name and '(' on function calls. +sp_func_call_paren = remove # ignore/add/remove/force/not_defined -# Add or remove space between a constructor/destructor and the open paren -sp_func_class_paren = ignore # ignore/add/remove/force +# Add or remove space between function name and '()' on function calls without +# parameters. If set to ignore (the default), sp_func_call_paren is used. +sp_func_call_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'return' and '(' -sp_return_paren = ignore # ignore/add/remove/force +# Add or remove space between the user function name and '(' on function +# calls. You need to set a keyword to be a user function in the config file, +# like: +# set func_call_user tr _ i18n +sp_func_call_user_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '__attribute__' and '(' -sp_attribute_paren = ignore # ignore/add/remove/force +# Add or remove space inside user function '(' and ')'. +sp_func_call_user_inside_fparen = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'defined' and '(' in '#if defined (FOO)' -sp_defined_paren = ignore # ignore/add/remove/force +# Add or remove space between nested parentheses with user functions, +# i.e. '((' vs. '( ('. +sp_func_call_user_paren_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'throw' and '(' in 'throw (something)' -sp_throw_paren = ignore # ignore/add/remove/force +# Add or remove space between a constructor/destructor and the open +# parenthesis. +sp_func_class_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'throw' and anything other than '(' as in '@throw [...];' -sp_after_throw = ignore # ignore/add/remove/force +# Add or remove space between a constructor without parameters or destructor +# and '()'. +sp_func_class_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'catch' and '(' in 'catch (something) { }' -# If set to ignore, sp_before_sparen is used. -sp_catch_paren = ignore # ignore/add/remove/force +# Add or remove space after 'return'. +# +# Default: force +sp_return = force # ignore/add/remove/force/not_defined -# Add or remove space between 'version' and '(' in 'version (something) { }' (D language) -# If set to ignore, sp_before_sparen is used. -sp_version_paren = ignore # ignore/add/remove/force +# Add or remove space between 'return' and '('. +sp_return_paren = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between 'return' and '{'. +sp_return_brace = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between '__attribute__' and '('. +sp_attribute_paren = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between 'defined' and '(' in '#if defined (FOO)'. +sp_defined_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'scope' and '(' in 'scope (something) { }' (D language) +# Add or remove space between 'throw' and '(' in 'throw (something)'. +sp_throw_paren = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between 'throw' and anything other than '(' as in +# '@throw [...];'. +sp_after_throw = ignore # ignore/add/remove/force/not_defined + +# Add or remove space between 'catch' and '(' in 'catch (something) { }'. # If set to ignore, sp_before_sparen is used. -sp_scope_paren = ignore # ignore/add/remove/force +sp_catch_paren = ignore # ignore/add/remove/force/not_defined + +# (OC) Add or remove space between '@catch' and '(' +# in '@catch (something) { }'. If set to ignore, sp_catch_paren is used. +sp_oc_catch_paren = ignore # ignore/add/remove/force/not_defined + +# (OC) Add or remove space before Objective-C protocol list +# as in '@protocol Protocol' or '@interface MyClass : NSObject'. +sp_before_oc_proto_list = ignore # ignore/add/remove/force/not_defined -# Add or remove space between macro and value -sp_macro = ignore # ignore/add/remove/force +# (OC) Add or remove space between class name and '(' +# in '@interface className(categoryName):BaseClass' +sp_oc_classname_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between macro function ')' and value -sp_macro_func = ignore # ignore/add/remove/force +# (D) Add or remove space between 'version' and '(' +# in 'version (something) { }'. If set to ignore, sp_before_sparen is used. +sp_version_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'else' and '{' if on the same line -sp_else_brace = ignore # ignore/add/remove/force +# (D) Add or remove space between 'scope' and '(' +# in 'scope (something) { }'. If set to ignore, sp_before_sparen is used. +sp_scope_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '}' and 'else' if on the same line -sp_brace_else = ignore # ignore/add/remove/force +# Add or remove space between 'super' and '(' in 'super (something)'. +# +# Default: remove +sp_super_paren = remove # ignore/add/remove/force/not_defined + +# Add or remove space between 'this' and '(' in 'this (something)'. +# +# Default: remove +sp_this_paren = remove # ignore/add/remove/force/not_defined + +# Add or remove space between a macro name and its definition. +sp_macro = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '}' and the name of a typedef on the same line -sp_brace_typedef = ignore # ignore/add/remove/force +# Add or remove space between a macro function ')' and its definition. +sp_macro_func = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'catch' and '{' if on the same line -sp_catch_brace = ignore # ignore/add/remove/force +# Add or remove space between 'else' and '{' if on the same line. +sp_else_brace = add # ignore/add/remove/force/not_defined -# Add or remove space between '}' and 'catch' if on the same line -sp_brace_catch = ignore # ignore/add/remove/force +# Add or remove space between '}' and 'else' if on the same line. +sp_brace_else = add # ignore/add/remove/force/not_defined -# Add or remove space between 'finally' and '{' if on the same line -sp_finally_brace = ignore # ignore/add/remove/force +# Add or remove space between '}' and the name of a typedef on the same line. +sp_brace_typedef = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '}' and 'finally' if on the same line -sp_brace_finally = ignore # ignore/add/remove/force +# Add or remove space before the '{' of a 'catch' statement, if the '{' and +# 'catch' are on the same line, as in 'catch (decl) {'. +sp_catch_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove space between 'try' and '{' if on the same line -sp_try_brace = ignore # ignore/add/remove/force +# (OC) Add or remove space before the '{' of a '@catch' statement, if the '{' +# and '@catch' are on the same line, as in '@catch (decl) {'. +# If set to ignore, sp_catch_brace is used. +sp_oc_catch_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove space between get/set and '{' if on the same line -sp_getset_brace = ignore # ignore/add/remove/force +# Add or remove space between '}' and 'catch' if on the same line. +sp_brace_catch = ignore # ignore/add/remove/force/not_defined -# Add or remove space before the '::' operator -sp_before_dc = ignore # ignore/add/remove/force +# (OC) Add or remove space between '}' and '@catch' if on the same line. +# If set to ignore, sp_brace_catch is used. +sp_oc_brace_catch = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the '::' operator -sp_after_dc = ignore # ignore/add/remove/force +# Add or remove space between 'finally' and '{' if on the same line. +sp_finally_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove around the D named array initializer ':' operator -sp_d_array_colon = ignore # ignore/add/remove/force +# Add or remove space between '}' and 'finally' if on the same line. +sp_brace_finally = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the '!' (not) operator. Default=Remove -sp_not = remove # ignore/add/remove/force +# Add or remove space between 'try' and '{' if on the same line. +sp_try_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the '~' (invert) operator. Default=Remove -sp_inv = remove # ignore/add/remove/force +# Add or remove space between get/set and '{' if on the same line. +sp_getset_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the '&' (address-of) operator. Default=Remove -# This does not affect the spacing after a '&' that is part of a type. -sp_addr = remove # ignore/add/remove/force +# Add or remove space between a variable and '{' for C++ uniform +# initialization. +sp_word_brace_init_lst = ignore # ignore/add/remove/force/not_defined -# Add or remove space around the '.' or '->' operators. Default=Remove -sp_member = remove # ignore/add/remove/force +# Add or remove space between a variable and '{' for a namespace. +# +# Default: add +sp_word_brace_ns = add # ignore/add/remove/force/not_defined + +# Add or remove space before the '::' operator. +sp_before_dc = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the '*' (dereference) operator. Default=Remove -# This does not affect the spacing after a '*' that is part of a type. -sp_deref = remove # ignore/add/remove/force +# Add or remove space after the '::' operator. +sp_after_dc = ignore # ignore/add/remove/force/not_defined -# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7'. Default=Remove -sp_sign = remove # ignore/add/remove/force +# (D) Add or remove around the D named array initializer ':' operator. +sp_d_array_colon = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after the '!' (not) unary operator. +# +# Default: remove +sp_not = remove # ignore/add/remove/force/not_defined -# Add or remove space before or after '++' and '--', as in '(--x)' or 'y++;'. Default=Remove -sp_incdec = remove # ignore/add/remove/force +# Add or remove space between two '!' (not) unary operators. +# If set to ignore, sp_not will be used. +sp_not_not = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a backslash-newline at the end of a line. Default=Add -sp_before_nl_cont = add # ignore/add/remove/force +# Add or remove space after the '~' (invert) unary operator. +# +# Default: remove +sp_inv = remove # ignore/add/remove/force/not_defined -# Add or remove space after the scope '+' or '-', as in '-(void) foo;' or '+(int) bar;' -sp_after_oc_scope = ignore # ignore/add/remove/force +# Add or remove space after the '&' (address-of) unary operator. This does not +# affect the spacing after a '&' that is part of a type. +# +# Default: remove +sp_addr = remove # ignore/add/remove/force/not_defined -# Add or remove space after the colon in message specs -# '-(int) f:(int) x;' vs '-(int) f: (int) x;' -sp_after_oc_colon = ignore # ignore/add/remove/force +# Add or remove space around the '.' or '->' operators. +# +# Default: remove +sp_member = remove # ignore/add/remove/force/not_defined -# Add or remove space before the colon in message specs -# '-(int) f: (int) x;' vs '-(int) f : (int) x;' -sp_before_oc_colon = ignore # ignore/add/remove/force +# Add or remove space after the '*' (dereference) unary operator. This does +# not affect the spacing after a '*' that is part of a type. +# +# Default: remove +sp_deref = remove # ignore/add/remove/force/not_defined -# Add or remove space after the colon in immutable dictionary expression -# 'NSDictionary *test = @{@"foo" :@"bar"};' -sp_after_oc_dict_colon = ignore # ignore/add/remove/force +# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7'. +# +# Default: remove +sp_sign = remove # ignore/add/remove/force/not_defined -# Add or remove space before the colon in immutable dictionary expression -# 'NSDictionary *test = @{@"foo" :@"bar"};' -sp_before_oc_dict_colon = ignore # ignore/add/remove/force +# Add or remove space between '++' and '--' the word to which it is being +# applied, as in '(--x)' or 'y++;'. +# +# Default: remove +sp_incdec = remove # ignore/add/remove/force/not_defined -# Add or remove space after the colon in message specs -# '[object setValue:1];' vs '[object setValue: 1];' -sp_after_send_oc_colon = ignore # ignore/add/remove/force +# Add or remove space before a backslash-newline at the end of a line. +# +# Default: add +sp_before_nl_cont = add # ignore/add/remove/force/not_defined -# Add or remove space before the colon in message specs -# '[object setValue:1];' vs '[object setValue :1];' -sp_before_send_oc_colon = ignore # ignore/add/remove/force +# (OC) Add or remove space after the scope '+' or '-', as in '-(void) foo;' +# or '+(int) bar;'. +sp_after_oc_scope = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the (type) in message specs -# '-(int)f: (int) x;' vs '-(int)f: (int)x;' -sp_after_oc_type = ignore # ignore/add/remove/force +# (OC) Add or remove space after the colon in message specs, +# i.e. '-(int) f:(int) x;' vs. '-(int) f: (int) x;'. +sp_after_oc_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space after the first (type) in message specs -# '-(int) f:(int)x;' vs '-(int)f:(int)x;' -sp_after_oc_return_type = ignore # ignore/add/remove/force +# (OC) Add or remove space before the colon in message specs, +# i.e. '-(int) f: (int) x;' vs. '-(int) f : (int) x;'. +sp_before_oc_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '@selector' and '(' -# '@selector(msgName)' vs '@selector (msgName)' -# Also applies to @protocol() constructs -sp_after_oc_at_sel = ignore # ignore/add/remove/force +# (OC) Add or remove space after the colon in immutable dictionary expression +# 'NSDictionary *test = @{@"foo" :@"bar"};'. +sp_after_oc_dict_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space between '@selector(x)' and the following word -# '@selector(foo) a:' vs '@selector(foo)a:' -sp_after_oc_at_sel_parens = ignore # ignore/add/remove/force +# (OC) Add or remove space before the colon in immutable dictionary expression +# 'NSDictionary *test = @{@"foo" :@"bar"};'. +sp_before_oc_dict_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside '@selector' parens -# '@selector(foo)' vs '@selector( foo )' -# Also applies to @protocol() constructs -sp_inside_oc_at_sel_parens = ignore # ignore/add/remove/force +# (OC) Add or remove space after the colon in message specs, +# i.e. '[object setValue:1];' vs. '[object setValue: 1];'. +sp_after_send_oc_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space before a block pointer caret -# '^int (int arg){...}' vs. ' ^int (int arg){...}' -sp_before_oc_block_caret = ignore # ignore/add/remove/force +# (OC) Add or remove space before the colon in message specs, +# i.e. '[object setValue:1];' vs. '[object setValue :1];'. +sp_before_send_oc_colon = ignore # ignore/add/remove/force/not_defined -# Add or remove space after a block pointer caret -# '^int (int arg){...}' vs. '^ int (int arg){...}' -sp_after_oc_block_caret = ignore # ignore/add/remove/force +# (OC) Add or remove space after the (type) in message specs, +# i.e. '-(int)f: (int) x;' vs. '-(int)f: (int)x;'. +sp_after_oc_type = ignore # ignore/add/remove/force/not_defined -# Add or remove space between the receiver and selector in a message. -# '[receiver selector ...]' -sp_after_oc_msg_receiver = ignore # ignore/add/remove/force +# (OC) Add or remove space after the first (type) in message specs, +# i.e. '-(int) f:(int)x;' vs. '-(int)f:(int)x;'. +sp_after_oc_return_type = ignore # ignore/add/remove/force/not_defined -# Add or remove space after @property. -sp_after_oc_property = ignore # ignore/add/remove/force +# (OC) Add or remove space between '@selector' and '(', +# i.e. '@selector(msgName)' vs. '@selector (msgName)'. +# Also applies to '@protocol()' constructs. +sp_after_oc_at_sel = ignore # ignore/add/remove/force/not_defined -# Add or remove space around the ':' in 'b ? t : f' -sp_cond_colon = ignore # ignore/add/remove/force +# (OC) Add or remove space between '@selector(x)' and the following word, +# i.e. '@selector(foo) a:' vs. '@selector(foo)a:'. +sp_after_oc_at_sel_parens = ignore # ignore/add/remove/force/not_defined -# Add or remove space around the '?' in 'b ? t : f' -sp_cond_question = ignore # ignore/add/remove/force +# (OC) Add or remove space inside '@selector' parentheses, +# i.e. '@selector(foo)' vs. '@selector( foo )'. +# Also applies to '@protocol()' constructs. +sp_inside_oc_at_sel_parens = ignore # ignore/add/remove/force/not_defined -# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make sense here. -sp_case_label = ignore # ignore/add/remove/force +# (OC) Add or remove space before a block pointer caret, +# i.e. '^int (int arg){...}' vs. ' ^int (int arg){...}'. +sp_before_oc_block_caret = ignore # ignore/add/remove/force/not_defined -# Control the space around the D '..' operator. -sp_range = ignore # ignore/add/remove/force +# (OC) Add or remove space after a block pointer caret, +# i.e. '^int (int arg){...}' vs. '^ int (int arg){...}'. +sp_after_oc_block_caret = ignore # ignore/add/remove/force/not_defined -# Control the spacing after ':' in 'for (TYPE VAR : EXPR)' (Java) -sp_after_for_colon = ignore # ignore/add/remove/force +# (OC) Add or remove space between the receiver and selector in a message, +# as in '[receiver selector ...]'. +sp_after_oc_msg_receiver = ignore # ignore/add/remove/force/not_defined -# Control the spacing before ':' in 'for (TYPE VAR : EXPR)' (Java) -sp_before_for_colon = ignore # ignore/add/remove/force +# (OC) Add or remove space after '@property'. +sp_after_oc_property = ignore # ignore/add/remove/force/not_defined -# Control the spacing in 'extern (C)' (D) -sp_extern_paren = ignore # ignore/add/remove/force +# (OC) Add or remove space between '@synchronized' and the open parenthesis, +# i.e. '@synchronized(foo)' vs. '@synchronized (foo)'. +sp_after_oc_synchronized = ignore # ignore/add/remove/force/not_defined -# Control the space after the opening of a C++ comment '// A' vs '//A' -sp_cmt_cpp_start = ignore # ignore/add/remove/force +# Add or remove space around the ':' in 'b ? t : f'. +sp_cond_colon = ignore # ignore/add/remove/force/not_defined -# Controls the spaces between #else or #endif and a trailing comment -sp_endif_cmt = ignore # ignore/add/remove/force +# Add or remove space before the ':' in 'b ? t : f'. +# +# Overrides sp_cond_colon. +sp_cond_colon_before = ignore # ignore/add/remove/force/not_defined -# Controls the spaces after 'new', 'delete', and 'delete[]' -sp_after_new = ignore # ignore/add/remove/force +# Add or remove space after the ':' in 'b ? t : f'. +# +# Overrides sp_cond_colon. +sp_cond_colon_after = ignore # ignore/add/remove/force/not_defined -# Controls the spaces before a trailing or embedded comment -sp_before_tr_emb_cmt = ignore # ignore/add/remove/force +# Add or remove space around the '?' in 'b ? t : f'. +sp_cond_question = ignore # ignore/add/remove/force/not_defined -# Number of spaces before a trailing or embedded comment -sp_num_before_tr_emb_cmt = 0 # number +# Add or remove space before the '?' in 'b ? t : f'. +# +# Overrides sp_cond_question. +sp_cond_question_before = ignore # ignore/add/remove/force/not_defined -# Control space between a Java annotation and the open paren. -sp_annotation_paren = ignore # ignore/add/remove/force +# Add or remove space after the '?' in 'b ? t : f'. +# +# Overrides sp_cond_question. +sp_cond_question_after = ignore # ignore/add/remove/force/not_defined +# In the abbreviated ternary form '(a ?: b)', add or remove space between '?' +# and ':'. # -# Code alignment (not left column spaces/tabs) +# Overrides all other sp_cond_* options. +sp_cond_ternary_short = ignore # ignore/add/remove/force/not_defined + +# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make +# sense here. +sp_case_label = ignore # ignore/add/remove/force/not_defined + +# (D) Add or remove space around the D '..' operator. +sp_range = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after ':' in a Java/C++11 range-based 'for', +# as in 'for (Type var : expr)'. +sp_after_for_colon = ignore # ignore/add/remove/force/not_defined + +# Add or remove space before ':' in a Java/C++11 range-based 'for', +# as in 'for (Type var : expr)'. +sp_before_for_colon = ignore # ignore/add/remove/force/not_defined + +# (D) Add or remove space between 'extern' and '(' as in 'extern (C)'. +sp_extern_paren = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after the opening of a C++ comment, as in '// A'. +sp_cmt_cpp_start = ignore # ignore/add/remove/force/not_defined + +# remove space after the '//' and the pvs command '-V1234', +# only works with sp_cmt_cpp_start set to add or force. +sp_cmt_cpp_pvs = false # true/false + +# remove space after the '//' and the command 'lint', +# only works with sp_cmt_cpp_start set to add or force. +sp_cmt_cpp_lint = false # true/false + +# Add or remove space in a C++ region marker comment, as in '// BEGIN'. +# A region marker is defined as a comment which is not preceded by other text +# (i.e. the comment is the first non-whitespace on the line), and which starts +# with either 'BEGIN' or 'END'. # +# Overrides sp_cmt_cpp_start. +sp_cmt_cpp_region = ignore # ignore/add/remove/force/not_defined + +# If true, space added with sp_cmt_cpp_start will be added after Doxygen +# sequences like '///', '///<', '//!' and '//!<'. +sp_cmt_cpp_doxygen = false # true/false + +# If true, space added with sp_cmt_cpp_start will be added after Qt translator +# or meta-data comments like '//:', '//=', and '//~'. +sp_cmt_cpp_qttr = false # true/false + +# Add or remove space between #else or #endif and a trailing comment. +sp_endif_cmt = ignore # ignore/add/remove/force/not_defined + +# Add or remove space after 'new', 'delete' and 'delete[]'. +sp_after_new = ignore # ignore/add/remove/force/not_defined -# Whether to keep non-indenting tabs -align_keep_tabs = false # false/true +# Add or remove space between 'new' and '(' in 'new()'. +sp_between_new_paren = ignore # ignore/add/remove/force/not_defined -# Whether to use tabs for aligning -align_with_tabs = false # false/true +# Add or remove space between ')' and type in 'new(foo) BAR'. +sp_after_newop_paren = ignore # ignore/add/remove/force/not_defined -# Whether to bump out to the next tab when aligning -align_on_tabstop = false # false/true +# Add or remove space inside parentheses of the new operator +# as in 'new(foo) BAR'. +sp_inside_newop_paren = ignore # ignore/add/remove/force/not_defined -# Whether to left-align numbers -align_number_left = false # false/true +# Add or remove space after the open parenthesis of the new operator, +# as in 'new(foo) BAR'. +# +# Overrides sp_inside_newop_paren. +sp_inside_newop_paren_open = ignore # ignore/add/remove/force/not_defined -# Align variable definitions in prototypes and functions -align_func_params = false # false/true +# Add or remove space before the close parenthesis of the new operator, +# as in 'new(foo) BAR'. +# +# Overrides sp_inside_newop_paren. +sp_inside_newop_paren_close = ignore # ignore/add/remove/force/not_defined -# Align parameters in single-line functions that have the same name. -# The function names must already be aligned with each other. -align_same_func_call_params = false # false/true +# Add or remove space before a trailing comment. +sp_before_tr_cmt = ignore # ignore/add/remove/force/not_defined -# The span for aligning variable definitions (0=don't align) -align_var_def_span = 0 # number +# Number of spaces before a trailing comment. +sp_num_before_tr_cmt = 0 # unsigned number -# How to align the star in variable definitions. -# 0=Part of the type 'void * foo;' -# 1=Part of the variable 'void *foo;' -# 2=Dangling 'void *foo;' -align_var_def_star_style = 1 # number +# Add or remove space before an embedded comment. +# +# Default: force +sp_before_emb_cmt = force # ignore/add/remove/force/not_defined -# How to align the '&' in variable definitions. -# 0=Part of the type -# 1=Part of the variable -# 2=Dangling -align_var_def_amp_style = 1 # number +# Number of spaces before an embedded comment. +# +# Default: 1 +sp_num_before_emb_cmt = 1 # unsigned number -# The threshold for aligning variable definitions (0=no limit) -align_var_def_thresh = 0 # number +# Add or remove space after an embedded comment. +# +# Default: force +sp_after_emb_cmt = force # ignore/add/remove/force/not_defined -# The gap for aligning variable definitions -align_var_def_gap = 0 # number +# Number of spaces after an embedded comment. +# +# Default: 1 +sp_num_after_emb_cmt = 1 # unsigned number -# Whether to align the colon in struct bit fields -align_var_def_colon = false # false/true +# (Java) Add or remove space between an annotation and the open parenthesis. +sp_annotation_paren = ignore # ignore/add/remove/force/not_defined -# Whether to align any attribute after the variable name -align_var_def_attribute = false # false/true +# If true, vbrace tokens are dropped to the previous token and skipped. +sp_skip_vbrace_tokens = false # true/false -# Whether to align inline struct/enum/union variable definitions -align_var_def_inline = false # false/true +# Add or remove space after 'noexcept'. +sp_after_noexcept = ignore # ignore/add/remove/force/not_defined -# The span for aligning on '=' in assignments (0=don't align) -align_assign_span = 0 # number +# Add or remove space after '_'. +sp_vala_after_translation = ignore # ignore/add/remove/force/not_defined -# The threshold for aligning on '=' in assignments (0=no limit) -align_assign_thresh = 0 # number +# Add or remove space before a bit colon ':'. +sp_before_bit_colon = ignore # ignore/add/remove/force/not_defined -# The span for aligning on '=' in enums (0=don't align) -align_enum_equ_span = 0 # number +# Add or remove space after a bit colon ':'. +sp_after_bit_colon = ignore # ignore/add/remove/force/not_defined -# The threshold for aligning on '=' in enums (0=no limit) -align_enum_equ_thresh = 0 # number +# If true, a is inserted after #define. +force_tab_after_define = false # true/false -# The span for aligning struct/union (0=don't align) -align_var_struct_span = 0 # number +# +# Indenting options +# -# The threshold for aligning struct/union member definitions (0=no limit) -align_var_struct_thresh = 0 # number +# The number of columns to indent per level. Usually 2, 3, 4, or 8. +# +# Default: 8 +indent_columns = 4 # unsigned number -# The gap for aligning struct/union member definitions -align_var_struct_gap = 0 # number +# Whether to ignore indent for the first continuation line. Subsequent +# continuation lines will still be indented to match the first. +indent_ignore_first_continue = false # true/false -# The span for aligning struct initializer values (0=don't align) -align_struct_init_span = 0 # number +# The continuation indent. If non-zero, this overrides the indent of '(', '[' +# and '=' continuation indents. Negative values are OK; negative value is +# absolute and not increased for each '(' or '[' level. +# +# For FreeBSD, this is set to 4. +# Requires indent_ignore_first_continue=false. +indent_continue = 0 # number -# The minimum space between the type and the synonym of a typedef -align_typedef_gap = 0 # number +# The continuation indent, only for class header line(s). If non-zero, this +# overrides the indent of 'class' continuation indents. +# Requires indent_ignore_first_continue=false. +indent_continue_class_head = 0 # unsigned number -# The span for aligning single-line typedefs (0=don't align) -align_typedef_span = 0 # number +# Whether to indent empty lines (i.e. lines which contain only spaces before +# the newline character). +indent_single_newlines = false # true/false -# How to align typedef'd functions with other typedefs -# 0: Don't mix them at all -# 1: align the open paren with the types -# 2: align the function type name with the other type names -align_typedef_func = 0 # number +# The continuation indent for func_*_param if they are true. If non-zero, this +# overrides the indent. +indent_param = 0 # unsigned number -# Controls the positioning of the '*' in typedefs. Just try it. -# 0: Align on typedef type, ignore '*' -# 1: The '*' is part of type name: typedef int *pint; -# 2: The '*' is part of the type, but dangling: typedef int *pint; -align_typedef_star_style = 0 # number +# How to use tabs when indenting code. +# +# 0: Spaces only +# 1: Indent with tabs to brace level, align with spaces (default) +# 2: Indent and align with tabs, using spaces when not on a tabstop +# +# Default: 1 +indent_with_tabs = 0 # unsigned number -# Controls the positioning of the '&' in typedefs. Just try it. -# 0: Align on typedef type, ignore '&' -# 1: The '&' is part of type name: typedef int &pint; -# 2: The '&' is part of the type, but dangling: typedef int &pint; -align_typedef_amp_style = 0 # number +# Whether to indent comments that are not at a brace level with tabs on a +# tabstop. Requires indent_with_tabs=2. If false, will use spaces. +indent_cmt_with_tabs = false # true/false -# The span for aligning comments that end lines (0=don't align) -align_right_cmt_span = 0 # number +# Whether to indent strings broken by '\' so that they line up. +indent_align_string = false # true/false -# If aligning comments, mix with comments after '}' and #endif with less than 3 spaces before the comment -align_right_cmt_mix = false # false/true +# The number of spaces to indent multi-line XML strings. +# Requires indent_align_string=true. +indent_xml_string = 0 # unsigned number -# If a trailing comment is more than this number of columns away from the text it follows, -# it will qualify for being aligned. This has to be > 0 to do anything. -align_right_cmt_gap = 0 # number +# Spaces to indent '{' from level. +indent_brace = 0 # unsigned number -# Align trailing comment at or beyond column N; 'pulls in' comments as a bonus side effect (0=ignore) -align_right_cmt_at_col = 0 # number +# Whether braces are indented to the body level. +indent_braces = false # true/false -# The span for aligning function prototypes (0=don't align) -align_func_proto_span = 0 # number +# Whether to disable indenting function braces if indent_braces=true. +indent_braces_no_func = false # true/false -# Minimum gap between the return type and the function name. -align_func_proto_gap = 0 # number +# Whether to disable indenting class braces if indent_braces=true. +indent_braces_no_class = false # true/false -# Align function protos on the 'operator' keyword instead of what follows -align_on_operator = false # false/true +# Whether to disable indenting struct braces if indent_braces=true. +indent_braces_no_struct = false # true/false -# Whether to mix aligning prototype and variable declarations. -# If true, align_var_def_XXX options are used instead of align_func_proto_XXX options. -align_mix_var_proto = false # false/true +# Whether to indent based on the size of the brace parent, +# i.e. 'if' => 3 spaces, 'for' => 4 spaces, etc. +indent_brace_parent = false # true/false -# Align single-line functions with function prototypes, uses align_func_proto_span -align_single_line_func = false # false/true +# Whether to indent based on the open parenthesis instead of the open brace +# in '({\n'. +indent_paren_open_brace = false # true/false -# Aligning the open brace of single-line functions. -# Requires align_single_line_func=true, uses align_func_proto_span -align_single_line_brace = false # false/true +# (C#) Whether to indent the brace of a C# delegate by another level. +indent_cs_delegate_brace = false # true/false -# Gap for align_single_line_brace. -align_single_line_brace_gap = 0 # number +# (C#) Whether to indent a C# delegate (to handle delegates with no brace) by +# another level. +indent_cs_delegate_body = false # true/false -# The span for aligning ObjC msg spec (0=don't align) -align_oc_msg_spec_span = 0 # number +# Whether to indent the body of a 'namespace'. +indent_namespace = false # true/false -# Whether to align macros wrapped with a backslash and a newline. -# This will not work right if the macro contains a multi-line comment. -align_nl_cont = false # false/true +# Whether to indent only the first namespace, and not any nested namespaces. +# Requires indent_namespace=true. +indent_namespace_single_indent = false # true/false -# # Align macro functions and variables together -align_pp_define_together = false # false/true +# The number of spaces to indent a namespace block. +# If set to zero, use the value indent_columns +indent_namespace_level = 0 # unsigned number -# The minimum space between label and value of a preprocessor define -align_pp_define_gap = 0 # number +# If the body of the namespace is longer than this number, it won't be +# indented. Requires indent_namespace=true. 0 means no limit. +indent_namespace_limit = 0 # unsigned number -# The span for aligning on '#define' bodies (0=don't align) -align_pp_define_span = 0 # number +# Whether to indent only in inner namespaces (nested in other namespaces). +# Requires indent_namespace=true. +indent_namespace_inner_only = false # true/false -# Align lines that start with '<<' with previous '<<'. Default=true -align_left_shift = true # false/true +# Whether the 'extern "C"' body is indented. +indent_extern = false # true/false -# Span for aligning parameters in an Obj-C message call on the ':' (0=don't align) -align_oc_msg_colon_span = 0 # number +# Whether the 'class' body is indented. +indent_class = false # true/false -# If true, always align with the first parameter, even if it is too short. -align_oc_msg_colon_first = false # false/true +# Whether to ignore indent for the leading base class colon. +indent_ignore_before_class_colon = false # true/false -# Aligning parameters in an Obj-C '+' or '-' declaration on the ':' -align_oc_decl_colon = false # false/true +# Additional indent before the leading base class colon. +# Negative values decrease indent down to the first column. +# Requires indent_ignore_before_class_colon=false and a newline break before +# the colon (see pos_class_colon and nl_class_colon) +indent_before_class_colon = 0 # number +# Whether to indent the stuff after a leading base class colon. +indent_class_colon = false # true/false + +# Whether to indent based on a class colon instead of the stuff after the +# colon. Requires indent_class_colon=true. +indent_class_on_colon = false # true/false + +# Whether to ignore indent for a leading class initializer colon. +indent_ignore_before_constr_colon = false # true/false + +# Whether to indent the stuff after a leading class initializer colon. +indent_constr_colon = false # true/false + +# Virtual indent from the ':' for leading member initializers. # -# Newline adding and removing options +# Default: 2 +indent_ctor_init_leading = 2 # unsigned number + +# Virtual indent from the ':' for following member initializers. +# +# Default: 2 +indent_ctor_init_following = 2 # unsigned number + +# Additional indent for constructor initializer list. +# Negative values decrease indent down to the first column. +indent_ctor_init = 0 # number + +# Whether to indent 'if' following 'else' as a new block under the 'else'. +# If false, 'else\nif' is treated as 'else if' for indenting purposes. +indent_else_if = false # true/false + +# Amount to indent variable declarations after a open brace. +# +# <0: Relative +# >=0: Absolute +indent_var_def_blk = 0 # number + +# Whether to indent continued variable declarations instead of aligning. +indent_var_def_cont = false # true/false + +# How to indent continued shift expressions ('<<' and '>>'). +# Set align_left_shift=false when using this. +# 0: Align shift operators instead of indenting them (default) +# 1: Indent by one level +# -1: Preserve original indentation +indent_shift = 0 # number + +# Whether to force indentation of function definitions to start in column 1. +indent_func_def_force_col1 = false # true/false + +# Whether to indent continued function call parameters one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_call_param = false # true/false + +# Whether to indent continued function definition parameters one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_def_param = false # true/false + +# for function definitions, only if indent_func_def_param is false +# Allows to align params when appropriate and indent them when not +# behave as if it was true if paren position is more than this value +# if paren position is more than the option value +indent_func_def_param_paren_pos_threshold = 0 # unsigned number + +# Whether to indent continued function call prototype one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_proto_param = false # true/false + +# Whether to indent continued function call declaration one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_class_param = false # true/false + +# Whether to indent continued class variable constructors one indent level, +# rather than aligning parameters under the open parenthesis. +indent_func_ctor_var_param = false # true/false + +# Whether to indent continued template parameter list one indent level, +# rather than aligning parameters under the open parenthesis. +indent_template_param = false # true/false + +# Double the indent for indent_func_xxx_param options. +# Use both values of the options indent_columns and indent_param. +indent_func_param_double = false # true/false + +# Indentation column for standalone 'const' qualifier on a function +# prototype. +indent_func_const = 0 # unsigned number + +# Indentation column for standalone 'throw' qualifier on a function +# prototype. +indent_func_throw = 0 # unsigned number + +# How to indent within a macro followed by a brace on the same line +# This allows reducing the indent in macros that have (for example) +# `do { ... } while (0)` blocks bracketing them. +# +# true: add an indent for the brace on the same line as the macro +# false: do not add an indent for the brace on the same line as the macro # +# Default: true +indent_macro_brace = true # true/false -# Whether to collapse empty blocks between '{' and '}' -nl_collapse_empty_body = false # false/true +# The number of spaces to indent a continued '->' or '.'. +# Usually set to 0, 1, or indent_columns. +indent_member = 0 # unsigned number -# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };' -nl_assign_leave_one_liners = false # false/true +# Whether lines broken at '.' or '->' should be indented by a single indent. +# The indent_member option will not be effective if this is set to true. +indent_member_single = false # true/false -# Don't split one-line braced statements inside a class xx { } body -nl_class_leave_one_liners = false # false/true +# Spaces to indent single line ('//') comments on lines before code. +indent_single_line_comments_before = 0 # unsigned number -# Don't split one-line enums: 'enum foo { BAR = 15 };' -nl_enum_leave_one_liners = false # false/true +# Spaces to indent single line ('//') comments on lines after code. +indent_single_line_comments_after = 0 # unsigned number -# Don't split one-line get or set functions -nl_getset_leave_one_liners = false # false/true +# When opening a paren for a control statement (if, for, while, etc), increase +# the indent level by this value. Negative values decrease the indent level. +indent_sparen_extra = 0 # number -# Don't split one-line function definitions - 'int foo() { return 0; }' -nl_func_leave_one_liners = false # false/true +# Whether to indent trailing single line ('//') comments relative to the code +# instead of trying to keep the same absolute column. +indent_relative_single_line_comments = false # true/false -# Don't split one-line if/else statements - 'if(a) b++;' -nl_if_leave_one_liners = false # false/true +# Spaces to indent 'case' from 'switch'. Usually 0 or indent_columns. +# It might be wise to choose the same value for the option indent_case_brace. +indent_switch_case = 0 # unsigned number -# Don't split one-line OC messages -nl_oc_msg_leave_one_liner = false # false/true +# Spaces to indent the body of a 'switch' before any 'case'. +# Usually the same as indent_columns or indent_switch_case. +indent_switch_body = 0 # unsigned number -# Add or remove newlines at the start of the file -nl_start_of_file = ignore # ignore/add/remove/force +# Whether to ignore indent for '{' following 'case'. +indent_ignore_case_brace = false # true/false -# The number of newlines at the start of the file (only used if nl_start_of_file is 'add' or 'force' -nl_start_of_file_min = 0 # number +# Spaces to indent '{' from 'case'. By default, the brace will appear under +# the 'c' in case. Usually set to 0 or indent_columns. Negative values are OK. +# It might be wise to choose the same value for the option indent_switch_case. +indent_case_brace = 0 # number -# Add or remove newline at the end of the file -nl_end_of_file = ignore # ignore/add/remove/force +# indent 'break' with 'case' from 'switch'. +indent_switch_break_with_case = false # true/false -# The number of newlines at the end of the file (only used if nl_end_of_file is 'add' or 'force') -nl_end_of_file_min = 0 # number +# Whether to indent preprocessor statements inside of switch statements. +# +# Default: true +indent_switch_pp = true # true/false -# Add or remove newline between '=' and '{' -nl_assign_brace = ignore # ignore/add/remove/force +# Spaces to shift the 'case' line, without affecting any other lines. +# Usually 0. +indent_case_shift = 0 # unsigned number -# Add or remove newline between '=' and '[' (D only) -nl_assign_square = ignore # ignore/add/remove/force +# Whether to align comments before 'case' with the 'case'. +# +# Default: true +indent_case_comment = true # true/false -# Add or remove newline after '= [' (D only). Will also affect the newline before the ']' -nl_after_square_assign = ignore # ignore/add/remove/force +# Whether to indent comments not found in first column. +# +# Default: true +indent_comment = true # true/false -# The number of blank lines after a block of variable definitions at the top of a function body -# 0 = No change (default) -nl_func_var_def_blk = 0 # number +# Whether to indent comments found in first column. +indent_col1_comment = false # true/false -# The number of newlines before a block of typedefs -# 0 = No change (default) -nl_typedef_blk_start = 0 # number +# Whether to indent multi string literal in first column. +indent_col1_multi_string_literal = false # true/false -# The number of newlines after a block of typedefs -# 0 = No change (default) -nl_typedef_blk_end = 0 # number +# Align comments on adjacent lines that are this many columns apart or less. +# +# Default: 3 +indent_comment_align_thresh = 3 # unsigned number -# The maximum consecutive newlines within a block of typedefs -# 0 = No change (default) -nl_typedef_blk_in = 0 # number +# Whether to ignore indent for goto labels. +indent_ignore_label = false # true/false -# The number of newlines before a block of variable definitions not at the top of a function body -# 0 = No change (default) -nl_var_def_blk_start = 0 # number +# How to indent goto labels. Requires indent_ignore_label=false. +# +# >0: Absolute column where 1 is the leftmost column +# <=0: Subtract from brace indent +# +# Default: 1 +indent_label = 1 # number -# The number of newlines after a block of variable definitions not at the top of a function body -# 0 = No change (default) -nl_var_def_blk_end = 0 # number +# How to indent access specifiers that are followed by a +# colon. +# +# >0: Absolute column where 1 is the leftmost column +# <=0: Subtract from brace indent +# +# Default: 1 +indent_access_spec = 1 # number -# The maximum consecutive newlines within a block of variable definitions -# 0 = No change (default) -nl_var_def_blk_in = 0 # number +# Whether to indent the code after an access specifier by one level. +# If true, this option forces 'indent_access_spec=0'. +indent_access_spec_body = false # true/false -# Add or remove newline between a function call's ')' and '{', as in: -# list_for_each(item, &list) { } -nl_fcall_brace = ignore # ignore/add/remove/force +# If an open parenthesis is followed by a newline, whether to indent the next +# line so that it lines up after the open parenthesis (not recommended). +indent_paren_nl = false # true/false -# Add or remove newline between 'enum' and '{' -nl_enum_brace = ignore # ignore/add/remove/force +# How to indent a close parenthesis after a newline. +# +# 0: Indent to body level (default) +# 1: Align under the open parenthesis +# 2: Indent to the brace level +# -1: Preserve original indentation +indent_paren_close = 0 # number + +# Whether to indent the open parenthesis of a function definition, +# if the parenthesis is on its own line. +indent_paren_after_func_def = false # true/false + +# Whether to indent the open parenthesis of a function declaration, +# if the parenthesis is on its own line. +indent_paren_after_func_decl = false # true/false + +# Whether to indent the open parenthesis of a function call, +# if the parenthesis is on its own line. +indent_paren_after_func_call = false # true/false + +# How to indent a comma when inside braces. +# 0: Indent by one level (default) +# 1: Align under the open brace +# -1: Preserve original indentation +indent_comma_brace = 0 # number + +# How to indent a comma when inside parentheses. +# 0: Indent by one level (default) +# 1: Align under the open parenthesis +# -1: Preserve original indentation +indent_comma_paren = 0 # number + +# How to indent a Boolean operator when inside parentheses. +# 0: Indent by one level (default) +# 1: Align under the open parenthesis +# -1: Preserve original indentation +indent_bool_paren = 0 # number + +# Whether to ignore the indentation of a Boolean operator when outside +# parentheses. +indent_ignore_bool = false # true/false + +# Whether to ignore the indentation of an arithmetic operator. +indent_ignore_arith = false # true/false + +# Whether to indent a semicolon when inside a for parenthesis. +# If true, aligns under the open for parenthesis. +indent_semicolon_for_paren = false # true/false + +# Whether to ignore the indentation of a semicolon outside of a 'for' +# statement. +indent_ignore_semicolon = false # true/false + +# Whether to align the first expression to following ones +# if indent_bool_paren=1. +indent_first_bool_expr = false # true/false + +# Whether to align the first expression to following ones +# if indent_semicolon_for_paren=true. +indent_first_for_expr = false # true/false + +# If an open square is followed by a newline, whether to indent the next line +# so that it lines up after the open square (not recommended). +indent_square_nl = false # true/false + +# (ESQL/C) Whether to preserve the relative indent of 'EXEC SQL' bodies. +indent_preserve_sql = false # true/false + +# Whether to ignore the indentation of an assignment operator. +indent_ignore_assign = false # true/false + +# Whether to align continued statements at the '='. If false or if the '=' is +# followed by a newline, the next line is indent one tab. +# +# Default: true +indent_align_assign = true # true/false -# Add or remove newline between 'struct and '{' -nl_struct_brace = ignore # ignore/add/remove/force +# If true, the indentation of the chunks after a '=' sequence will be set at +# LHS token indentation column before '='. +indent_off_after_assign = false # true/false -# Add or remove newline between 'union' and '{' -nl_union_brace = ignore # ignore/add/remove/force +# Whether to align continued statements at the '('. If false or the '(' is +# followed by a newline, the next line indent is one tab. +# +# Default: true +indent_align_paren = true # true/false -# Add or remove newline between 'if' and '{' -nl_if_brace = ignore # ignore/add/remove/force +# (OC) Whether to indent Objective-C code inside message selectors. +indent_oc_inside_msg_sel = false # true/false -# Add or remove newline between '}' and 'else' -nl_brace_else = ignore # ignore/add/remove/force +# (OC) Whether to indent Objective-C blocks at brace level instead of usual +# rules. +indent_oc_block = false # true/false -# Add or remove newline between 'else if' and '{' -# If set to ignore, nl_if_brace is used instead -nl_elseif_brace = ignore # ignore/add/remove/force +# (OC) Indent for Objective-C blocks in a message relative to the parameter +# name. +# +# =0: Use indent_oc_block rules +# >0: Use specified number of spaces to indent +indent_oc_block_msg = 0 # unsigned number -# Add or remove newline between 'else' and '{' -nl_else_brace = ignore # ignore/add/remove/force +# (OC) Minimum indent for subsequent parameters +indent_oc_msg_colon = 0 # unsigned number -# Add or remove newline between 'else' and 'if' -nl_else_if = ignore # ignore/add/remove/force +# (OC) Whether to prioritize aligning with initial colon (and stripping spaces +# from lines, if necessary). +# +# Default: true +indent_oc_msg_prioritize_first_colon = true # true/false -# Add or remove newline between '}' and 'finally' -nl_brace_finally = ignore # ignore/add/remove/force +# (OC) Whether to indent blocks the way that Xcode does by default +# (from the keyword if the parameter is on its own line; otherwise, from the +# previous indentation level). Requires indent_oc_block_msg=true. +indent_oc_block_msg_xcode_style = false # true/false -# Add or remove newline between 'finally' and '{' -nl_finally_brace = ignore # ignore/add/remove/force +# (OC) Whether to indent blocks from where the brace is, relative to a +# message keyword. Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_keyword = false # true/false -# Add or remove newline between 'try' and '{' -nl_try_brace = ignore # ignore/add/remove/force +# (OC) Whether to indent blocks from where the brace is, relative to a message +# colon. Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_colon = false # true/false -# Add or remove newline between get/set and '{' -nl_getset_brace = ignore # ignore/add/remove/force +# (OC) Whether to indent blocks from where the block caret is. +# Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_caret = false # true/false -# Add or remove newline between 'for' and '{' -nl_for_brace = ignore # ignore/add/remove/force +# (OC) Whether to indent blocks from where the brace caret is. +# Requires indent_oc_block_msg=true. +indent_oc_block_msg_from_brace = false # true/false -# Add or remove newline between 'catch' and '{' -nl_catch_brace = ignore # ignore/add/remove/force +# When indenting after virtual brace open and newline add further spaces to +# reach this minimum indent. +indent_min_vbrace_open = 0 # unsigned number -# Add or remove newline between '}' and 'catch' -nl_brace_catch = ignore # ignore/add/remove/force +# Whether to add further spaces after regular indent to reach next tabstop +# when indenting after virtual brace open and newline. +indent_vbrace_open_on_tabstop = false # true/false -# Add or remove newline between 'while' and '{' -nl_while_brace = ignore # ignore/add/remove/force +# How to indent after a brace followed by another token (not a newline). +# true: indent all contained lines to match the token +# false: indent all contained lines to match the brace +# +# Default: true +indent_token_after_brace = true # true/false -# Add or remove newline between 'scope (x)' and '{' (D) -nl_scope_brace = ignore # ignore/add/remove/force +# Whether to indent the body of a C++11 lambda. +indent_cpp_lambda_body = false # true/false -# Add or remove newline between 'unittest' and '{' (D) -nl_unittest_brace = ignore # ignore/add/remove/force +# How to indent compound literals that are being returned. +# true: add both the indent from return & the compound literal open brace +# (i.e. 2 indent levels) +# false: only indent 1 level, don't add the indent for the open brace, only +# add the indent for the return. +# +# Default: true +indent_compound_literal_return = true # true/false -# Add or remove newline between 'version (x)' and '{' (D) -nl_version_brace = ignore # ignore/add/remove/force +# (C#) Whether to indent a 'using' block if no braces are used. +# +# Default: true +indent_using_block = true # true/false -# Add or remove newline between 'using' and '{' -nl_using_brace = ignore # ignore/add/remove/force +# How to indent the continuation of ternary operator. +# +# 0: Off (default) +# 1: When the `if_false` is a continuation, indent it under the `if_true` branch +# 2: When the `:` is a continuation, indent it under `?` +indent_ternary_operator = 0 # unsigned number -# Add or remove newline between two open or close braces. -# Due to general newline/brace handling, REMOVE may not work. -nl_brace_brace = ignore # ignore/add/remove/force +# Whether to indent the statements inside ternary operator. +indent_inside_ternary_operator = false # true/false -# Add or remove newline between 'do' and '{' -nl_do_brace = ignore # ignore/add/remove/force +# If true, the indentation of the chunks after a `return` sequence will be set at return indentation column. +indent_off_after_return = false # true/false -# Add or remove newline between '}' and 'while' of 'do' statement -nl_brace_while = ignore # ignore/add/remove/force +# If true, the indentation of the chunks after a `return new` sequence will be set at return indentation column. +indent_off_after_return_new = false # true/false -# Add or remove newline between 'switch' and '{' -nl_switch_brace = ignore # ignore/add/remove/force +# If true, the tokens after return are indented with regular single indentation. By default (false) the indentation is after the return token. +indent_single_after_return = false # true/false -# Add a newline between ')' and '{' if the ')' is on a different line than the if/for/etc. -# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch, and nl_catch_brace. -nl_multi_line_cond = false # false/true +# Whether to ignore indent and alignment for 'asm' blocks (i.e. assume they +# have their own indentation). +indent_ignore_asm_block = false # true/false -# Force a newline in a define after the macro name for multi-line defines. -nl_multi_line_define = false # false/true +# Don't indent the close parenthesis of a function definition, +# if the parenthesis is on its own line. +donot_indent_func_def_close_paren = false # true/false -# Whether to put a newline before 'case' statement -nl_before_case = false # false/true +# +# Newline adding and removing options +# -# Add or remove newline between ')' and 'throw' -nl_before_throw = ignore # ignore/add/remove/force +# Whether to collapse empty blocks between '{' and '}' except for functions. +# Use nl_collapse_empty_body_functions to specify how empty function braces +# should be formatted. +nl_collapse_empty_body = true # true/false -# Whether to put a newline after 'case' statement -nl_after_case = false # false/true +# Whether to collapse empty blocks between '{' and '}' for functions only. +# If true, overrides nl_inside_empty_func. +nl_collapse_empty_body_functions = false # true/false -# Add or remove a newline between a case ':' and '{'. Overrides nl_after_case. -nl_case_colon_brace = ignore # ignore/add/remove/force +# Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'. +nl_assign_leave_one_liners = true # true/false -# Newline between namespace and { -nl_namespace_brace = ignore # ignore/add/remove/force +# Don't split one-line braced statements inside a 'class xx { }' body. +nl_class_leave_one_liners = false # true/false -# Add or remove newline between 'template<>' and whatever follows. -nl_template_class = ignore # ignore/add/remove/force +# Don't split one-line enums, as in 'enum foo { BAR = 15 };' +nl_enum_leave_one_liners = false # true/false -# Add or remove newline between 'class' and '{' -nl_class_brace = ignore # ignore/add/remove/force +# Don't split one-line get or set functions. +nl_getset_leave_one_liners = false # true/false -# Add or remove newline after each ',' in the constructor member initialization -nl_class_init_args = ignore # ignore/add/remove/force +# (C#) Don't split one-line property get or set functions. +nl_cs_property_leave_one_liners = false # true/false -# Add or remove newline between return type and function name in a function definition -nl_func_type_name = ignore # ignore/add/remove/force +# Don't split one-line function definitions, as in 'int foo() { return 0; }'. +# might modify nl_func_type_name +nl_func_leave_one_liners = false # true/false -# Add or remove newline between return type and function name inside a class {} -# Uses nl_func_type_name or nl_func_proto_type_name if set to ignore. -nl_func_type_name_class = ignore # ignore/add/remove/force +# Don't split one-line C++11 lambdas, as in '[]() { return 0; }'. +nl_cpp_lambda_leave_one_liners = false # true/false -# Add or remove newline between function scope and name in a definition -# Controls the newline after '::' in 'void A::f() { }' -nl_func_scope_name = ignore # ignore/add/remove/force +# Don't split one-line if/else statements, as in 'if(...) b++;'. +nl_if_leave_one_liners = false # true/false -# Add or remove newline between return type and function name in a prototype -nl_func_proto_type_name = ignore # ignore/add/remove/force +# Don't split one-line while statements, as in 'while(...) b++;'. +nl_while_leave_one_liners = false # true/false -# Add or remove newline between a function name and the opening '(' -nl_func_paren = remove # ignore/add/remove/force +# Don't split one-line do statements, as in 'do { b++; } while(...);'. +nl_do_leave_one_liners = false # true/false -# Add or remove newline between a function name and the opening '(' in the definition -nl_func_def_paren = remove # ignore/add/remove/force +# Don't split one-line for statements, as in 'for(...) b++;'. +nl_for_leave_one_liners = false # true/false -# Add or remove newline after '(' in a function declaration -nl_func_decl_start = remove # ignore/add/remove/force +# (OC) Don't split one-line Objective-C messages. +nl_oc_msg_leave_one_liner = false # true/false -# Add or remove newline after '(' in a function definition -nl_func_def_start = remove # ignore/add/remove/force +# (OC) Add or remove newline between method declaration and '{'. +nl_oc_mdef_brace = ignore # ignore/add/remove/force/not_defined -# Overrides nl_func_decl_start when there is only one parameter. -nl_func_decl_start_single = ignore # ignore/add/remove/force +# (OC) Add or remove newline between Objective-C block signature and '{'. +nl_oc_block_brace = ignore # ignore/add/remove/force/not_defined -# Overrides nl_func_def_start when there is only one parameter. -nl_func_def_start_single = ignore # ignore/add/remove/force +# (OC) Add or remove blank line before '@interface' statement. +nl_oc_before_interface = ignore # ignore/add/remove/force/not_defined -# Add or remove newline after each ',' in a function declaration -nl_func_decl_args = ignore # ignore/add/remove/force +# (OC) Add or remove blank line before '@implementation' statement. +nl_oc_before_implementation = ignore # ignore/add/remove/force/not_defined -# Add or remove newline after each ',' in a function definition -nl_func_def_args = ignore # ignore/add/remove/force +# (OC) Add or remove blank line before '@end' statement. +nl_oc_before_end = ignore # ignore/add/remove/force/not_defined -# Add or remove newline before the ')' in a function declaration -nl_func_decl_end = ignore # ignore/add/remove/force +# (OC) Add or remove newline between '@interface' and '{'. +nl_oc_interface_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove newline before the ')' in a function definition -nl_func_def_end = remove # ignore/add/remove/force +# (OC) Add or remove newline between '@implementation' and '{'. +nl_oc_implementation_brace = ignore # ignore/add/remove/force/not_defined -# Overrides nl_func_decl_end when there is only one parameter. -nl_func_decl_end_single = ignore # ignore/add/remove/force +# Add or remove newlines at the start of the file. +nl_start_of_file = ignore # ignore/add/remove/force/not_defined -# Overrides nl_func_def_end when there is only one parameter. -nl_func_def_end_single = ignore # ignore/add/remove/force +# The minimum number of newlines at the start of the file (only used if +# nl_start_of_file is 'add' or 'force'). +nl_start_of_file_min = 0 # unsigned number -# Add or remove newline between '()' in a function declaration. -nl_func_decl_empty = ignore # ignore/add/remove/force +# Add or remove newline at the end of the file. +nl_end_of_file = ignore # ignore/add/remove/force/not_defined -# Add or remove newline between '()' in a function definition. -nl_func_def_empty = ignore # ignore/add/remove/force +# The minimum number of newlines at the end of the file (only used if +# nl_end_of_file is 'add' or 'force'). +nl_end_of_file_min = 0 # unsigned number -# Whether to put each OC message parameter on a separate line -# See nl_oc_msg_leave_one_liner -nl_oc_msg_args = false # false/true +# Add or remove newline between '=' and '{'. +nl_assign_brace = remove # ignore/add/remove/force/not_defined -# Add or remove newline between function signature and '{' -nl_fdef_brace = add # ignore/add/remove/force +# (D) Add or remove newline between '=' and '['. +nl_assign_square = ignore # ignore/add/remove/force/not_defined -# Add or remove a newline between the return keyword and return expression. -nl_return_expr = ignore # ignore/add/remove/force +# Add or remove newline between '[]' and '{'. +nl_tsquare_brace = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after semicolons, except in 'for' statements -nl_after_semicolon = true # false/true +# (D) Add or remove newline after '= ['. Will also affect the newline before +# the ']'. +nl_after_square_assign = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after brace open. -# This also adds a newline before the matching brace close. -nl_after_brace_open = true # false/true +# Add or remove newline between a function call's ')' and '{', as in +# 'list_for_each(item, &list) { }'. +nl_fcall_brace = ignore # ignore/add/remove/force/not_defined -# If nl_after_brace_open and nl_after_brace_open_cmt are true, a newline is -# placed between the open brace and a trailing single-line comment. -nl_after_brace_open_cmt = false # false/true +# Add or remove newline between 'enum' and '{'. +nl_enum_brace = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after a virtual brace open with a non-empty body. -# These occur in un-braced if/while/do/for statement bodies. -nl_after_vbrace_open = false # false/true +# Add or remove newline between 'enum' and 'class'. +nl_enum_class = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after a virtual brace open with an empty body. -# These occur in un-braced if/while/do/for statement bodies. -nl_after_vbrace_open_empty = false # false/true +# Add or remove newline between 'enum class' and the identifier. +nl_enum_class_identifier = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after a brace close. -# Does not apply if followed by a necessary ';'. -nl_after_brace_close = false # false/true +# Add or remove newline between 'enum class' type and ':'. +nl_enum_identifier_colon = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline after a virtual brace close. -# Would add a newline before return in: 'if (foo) a++; return;' -nl_after_vbrace_close = false # false/true +# Add or remove newline between 'enum class identifier :' and type. +nl_enum_colon_type = ignore # ignore/add/remove/force/not_defined -# Control the newline between the close brace and 'b' in: 'struct { int a; } b;' -# Affects enums, unions, and structures. If set to ignore, uses nl_after_brace_close -nl_brace_struct_var = ignore # ignore/add/remove/force +# Add or remove newline between 'struct and '{'. +nl_struct_brace = ignore # ignore/add/remove/force/not_defined -# Whether to alter newlines in '#define' macros -nl_define_macro = false # false/true +# Add or remove newline between 'union' and '{'. +nl_union_brace = ignore # ignore/add/remove/force/not_defined -# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif' -nl_squeeze_ifdef = false # false/true +# Add or remove newline between 'if' and '{'. +nl_if_brace = remove # ignore/add/remove/force/not_defined -# Add or remove blank line before 'if' -nl_before_if = ignore # ignore/add/remove/force +# Add or remove newline between '}' and 'else'. +nl_brace_else = remove # ignore/add/remove/force/not_defined -# Add or remove blank line after 'if' statement -nl_after_if = add # ignore/add/remove/force +# Add or remove newline between 'else if' and '{'. If set to ignore, +# nl_if_brace is used instead. +nl_elseif_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line before 'for' -nl_before_for = ignore # ignore/add/remove/force +# Add or remove newline between 'else' and '{'. +nl_else_brace = remove # ignore/add/remove/force/not_defined -# Add or remove blank line after 'for' statement -nl_after_for = remove # ignore/add/remove/force +# Add or remove newline between 'else' and 'if'. +nl_else_if = remove # ignore/add/remove/force/not_defined -# Add or remove blank line before 'while' -nl_before_while = ignore # ignore/add/remove/force +# Add or remove newline before '{' opening brace +nl_before_opening_brace_func_class_def = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line after 'while' statement -nl_after_while = remove # ignore/add/remove/force +# Add or remove newline before 'if'/'else if' closing parenthesis. +nl_before_if_closing_paren = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line before 'switch' -nl_before_switch = ignore # ignore/add/remove/force +# Add or remove newline between '}' and 'finally'. +nl_brace_finally = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line after 'switch' statement -nl_after_switch = ignore # ignore/add/remove/force +# Add or remove newline between 'finally' and '{'. +nl_finally_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line before 'do' -nl_before_do = ignore # ignore/add/remove/force +# Add or remove newline between 'try' and '{'. +nl_try_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove blank line after 'do/while' statement -nl_after_do = ignore # ignore/add/remove/force +# Add or remove newline between get/set and '{'. +nl_getset_brace = ignore # ignore/add/remove/force/not_defined -# Whether to double-space commented-entries in struct/enum -nl_ds_struct_enum_cmt = false # false/true +# Add or remove newline between 'for' and '{'. +nl_for_brace = remove # ignore/add/remove/force/not_defined -# Whether to double-space before the close brace of a struct/union/enum -# (lower priority than 'eat_blanks_before_close_brace') -nl_ds_struct_enum_close_brace = false # false/true +# Add or remove newline before the '{' of a 'catch' statement, as in +# 'catch (decl) {'. +nl_catch_brace = ignore # ignore/add/remove/force/not_defined -# Add or remove a newline around a class colon. -# Related to pos_class_colon, nl_class_init_args, and pos_comma. -nl_class_colon = ignore # ignore/add/remove/force +# (OC) Add or remove newline before the '{' of a '@catch' statement, as in +# '@catch (decl) {'. If set to ignore, nl_catch_brace is used. +nl_oc_catch_brace = ignore # ignore/add/remove/force/not_defined -# Change simple unbraced if statements into a one-liner -# 'if(b)\n i++;' => 'if(b) i++;' -nl_create_if_one_liner = false # false/true +# Add or remove newline between '}' and 'catch'. +nl_brace_catch = ignore # ignore/add/remove/force/not_defined -# Change simple unbraced for statements into a one-liner -# 'for (i=0;i<5;i++)\n foo(i);' => 'for (i=0;i<5;i++) foo(i);' -nl_create_for_one_liner = false # false/true +# (OC) Add or remove newline between '}' and '@catch'. If set to ignore, +# nl_brace_catch is used. +nl_oc_brace_catch = ignore # ignore/add/remove/force/not_defined -# Change simple unbraced while statements into a one-liner -# 'while (i<5)\n foo(i++);' => 'while (i<5) foo(i++);' -nl_create_while_one_liner = false # false/true +# Add or remove newline between '}' and ']'. +nl_brace_square = ignore # ignore/add/remove/force/not_defined +# Add or remove newline between '}' and ')' in a function invocation. +nl_brace_fparen = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline between 'while' and '{'. +nl_while_brace = remove # ignore/add/remove/force/not_defined + +# (D) Add or remove newline between 'scope (x)' and '{'. +nl_scope_brace = ignore # ignore/add/remove/force/not_defined + +# (D) Add or remove newline between 'unittest' and '{'. +nl_unittest_brace = ignore # ignore/add/remove/force/not_defined + +# (D) Add or remove newline between 'version (x)' and '{'. +nl_version_brace = ignore # ignore/add/remove/force/not_defined + +# (C#) Add or remove newline between 'using' and '{'. +nl_using_brace = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline between two open or close braces. Due to general +# newline/brace handling, REMOVE may not work. +nl_brace_brace = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline between 'do' and '{'. +nl_do_brace = remove # ignore/add/remove/force/not_defined + +# Add or remove newline between '}' and 'while' of 'do' statement. +nl_brace_while = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline between 'switch' and '{'. +nl_switch_brace = remove # ignore/add/remove/force/not_defined + +# Add or remove newline between 'synchronized' and '{'. +nl_synchronized_brace = ignore # ignore/add/remove/force/not_defined + +# Add a newline between ')' and '{' if the ')' is on a different line than the +# if/for/etc. # -# Positioning options -# +# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch and +# nl_catch_brace. +nl_multi_line_cond = false # true/false -# The position of arithmetic operators in wrapped expressions -pos_arith = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add a newline after '(' if an if/for/while/switch condition spans multiple +# lines +nl_multi_line_sparen_open = ignore # ignore/add/remove/force/not_defined -# The position of assignment in wrapped expressions. -# Do not affect '=' followed by '{' -pos_assign = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add a newline before ')' if an if/for/while/switch condition spans multiple +# lines. Overrides nl_before_if_closing_paren if both are specified. +nl_multi_line_sparen_close = ignore # ignore/add/remove/force/not_defined -# The position of boolean operators in wrapped expressions -pos_bool = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Force a newline in a define after the macro name for multi-line defines. +nl_multi_line_define = false # true/false + +# Whether to add a newline before 'case', and a blank line before a 'case' +# statement that follows a ';' or '}'. +nl_before_case = false # true/false -# The position of comparison operators in wrapped expressions -pos_compare = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Whether to add a newline after a 'case' statement. +nl_after_case = false # true/false -# The position of conditional (b ? t : f) operators in wrapped expressions -pos_conditional = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add or remove newline between a case ':' and '{'. +# +# Overrides nl_after_case. +nl_case_colon_brace = ignore # ignore/add/remove/force/not_defined -# The position of the comma in wrapped expressions -pos_comma = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add or remove newline between ')' and 'throw'. +nl_before_throw = ignore # ignore/add/remove/force/not_defined -# The position of the comma in the constructor initialization list -pos_class_comma = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add or remove newline between 'namespace' and '{'. +nl_namespace_brace = ignore # ignore/add/remove/force/not_defined -# The position of colons between constructor and member initialization -pos_class_colon = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force +# Add or remove newline after 'template<...>' of a template class. +nl_template_class = ignore # ignore/add/remove/force/not_defined +# Add or remove newline after 'template<...>' of a template class declaration. # -# Line Splitting options +# Overrides nl_template_class. +nl_template_class_decl = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline after 'template<>' of a specialized class declaration. # +# Overrides nl_template_class_decl. +nl_template_class_decl_special = ignore # ignore/add/remove/force/not_defined -# Try to limit code width to N number of columns -code_width = 0 # number +# Add or remove newline after 'template<...>' of a template class definition. +# +# Overrides nl_template_class. +nl_template_class_def = ignore # ignore/add/remove/force/not_defined -# Whether to fully split long 'for' statements at semi-colons -ls_for_split_full = false # false/true +# Add or remove newline after 'template<>' of a specialized class definition. +# +# Overrides nl_template_class_def. +nl_template_class_def_special = ignore # ignore/add/remove/force/not_defined -# Whether to fully split long function protos/calls at commas -ls_func_split_full = false # false/true +# Add or remove newline after 'template<...>' of a template function. +nl_template_func = ignore # ignore/add/remove/force/not_defined -# Whether to split lines as close to code_width as possible and ignore some groupings -ls_code_width = false # false/true +# Add or remove newline after 'template<...>' of a template function +# declaration. +# +# Overrides nl_template_func. +nl_template_func_decl = ignore # ignore/add/remove/force/not_defined +# Add or remove newline after 'template<>' of a specialized function +# declaration. # -# Blank line options +# Overrides nl_template_func_decl. +nl_template_func_decl_special = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline after 'template<...>' of a template function +# definition. # +# Overrides nl_template_func. +nl_template_func_def = ignore # ignore/add/remove/force/not_defined -# The maximum consecutive newlines -nl_max = 0 # number +# Add or remove newline after 'template<>' of a specialized function +# definition. +# +# Overrides nl_template_func_def. +nl_template_func_def_special = ignore # ignore/add/remove/force/not_defined -# The number of newlines after a function prototype, if followed by another function prototype -nl_after_func_proto = 0 # number +# Add or remove newline after 'template<...>' of a template variable. +nl_template_var = ignore # ignore/add/remove/force/not_defined -# The number of newlines after a function prototype, if not followed by another function prototype -nl_after_func_proto_group = 0 # number +# Add or remove newline between 'template<...>' and 'using' of a templated +# type alias. +nl_template_using = ignore # ignore/add/remove/force/not_defined -# The number of newlines after '}' of a multi-line function body -nl_after_func_body = 0 # number +# Add or remove newline between 'class' and '{'. +nl_class_brace = ignore # ignore/add/remove/force/not_defined -# The number of newlines after '}' of a multi-line function body in a class declaration -nl_after_func_body_class = 0 # number +# Add or remove newline before or after (depending on pos_class_comma, +# may not be IGNORE) each',' in the base class list. +nl_class_init_args = ignore # ignore/add/remove/force/not_defined -# The number of newlines after '}' of a single line function body -nl_after_func_body_one_liner = 0 # number +# Add or remove newline after each ',' in the constructor member +# initialization. Related to nl_constr_colon, pos_constr_colon and +# pos_constr_comma. +nl_constr_init_args = ignore # ignore/add/remove/force/not_defined -# The minimum number of newlines before a multi-line comment. -# Doesn't apply if after a brace open or another multi-line comment. -nl_before_block_comment = 0 # number +# Add or remove newline before first element, after comma, and after last +# element, in 'enum'. +nl_enum_own_lines = ignore # ignore/add/remove/force/not_defined -# The minimum number of newlines before a single-line C comment. -# Doesn't apply if after a brace open or other single-line C comments. -nl_before_c_comment = 0 # number +# Add or remove newline between return type and function name in a function +# definition. +# might be modified by nl_func_leave_one_liners +nl_func_type_name = ignore # ignore/add/remove/force/not_defined -# The minimum number of newlines before a CPP comment. -# Doesn't apply if after a brace open or other CPP comments. -nl_before_cpp_comment = 0 # number +# Add or remove newline between return type and function name inside a class +# definition. If set to ignore, nl_func_type_name or nl_func_proto_type_name +# is used instead. +nl_func_type_name_class = ignore # ignore/add/remove/force/not_defined -# Whether to force a newline after a multi-line comment. -nl_after_multiline_comment = false # false/true +# Add or remove newline between class specification and '::' +# in 'void A::f() { }'. Only appears in separate member implementation (does +# not appear with in-line implementation). +nl_func_class_scope = ignore # ignore/add/remove/force/not_defined -# The number of newlines after '}' or ';' of a struct/enum/union definition -nl_after_struct = 0 # number +# Add or remove newline between function scope and name, as in +# 'void A :: f() { }'. +nl_func_scope_name = ignore # ignore/add/remove/force/not_defined -# The number of newlines after '}' or ';' of a class definition -nl_after_class = 0 # number +# Add or remove newline between return type and function name in a prototype. +nl_func_proto_type_name = ignore # ignore/add/remove/force/not_defined -# The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. -# Will not change the newline count if after a brace open. -# 0 = No change. -nl_before_access_spec = 0 # number +# Add or remove newline between a function name and the opening '(' in the +# declaration. +nl_func_paren = remove # ignore/add/remove/force/not_defined -# The number of newlines after a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. -# 0 = No change. -nl_after_access_spec = 0 # number +# Overrides nl_func_paren for functions with no parameters. +nl_func_paren_empty = ignore # ignore/add/remove/force/not_defined -# The number of newlines between a function def and the function comment. -# 0 = No change. -nl_comment_func_def = 0 # number +# Add or remove newline between a function name and the opening '(' in the +# definition. +nl_func_def_paren = remove # ignore/add/remove/force/not_defined -# The number of newlines after a try-catch-finally block that isn't followed by a brace close. -# 0 = No change. -nl_after_try_catch_finally = 0 # number +# Overrides nl_func_def_paren for functions with no parameters. +nl_func_def_paren_empty = ignore # ignore/add/remove/force/not_defined -# The number of newlines before and after a property, indexer or event decl. -# 0 = No change. -nl_around_cs_property = 0 # number +# Add or remove newline between a function name and the opening '(' in the +# call. +nl_func_call_paren = ignore # ignore/add/remove/force/not_defined -# The number of newlines between the get/set/add/remove handlers in C#. -# 0 = No change. -nl_between_get_set = 0 # number +# Overrides nl_func_call_paren for functions with no parameters. +nl_func_call_paren_empty = ignore # ignore/add/remove/force/not_defined -# Add or remove newline between C# property and the '{' -nl_property_brace = ignore # ignore/add/remove/force +# Add or remove newline after '(' in a function declaration. +nl_func_decl_start = remove # ignore/add/remove/force/not_defined -# Whether to remove blank lines after '{' -eat_blanks_after_open_brace = false # false/true +# Add or remove newline after '(' in a function definition. +nl_func_def_start = remove # ignore/add/remove/force/not_defined -# Whether to remove blank lines before '}' -eat_blanks_before_close_brace = false # false/true +# Overrides nl_func_decl_start when there is only one parameter. +nl_func_decl_start_single = ignore # ignore/add/remove/force/not_defined -# How aggressively to remove extra newlines not in preproc. -# 0: No change -# 1: Remove most newlines not handled by other config -# 2: Remove all newlines and reformat completely by config -nl_remove_extra_newlines = 0 # number +# Overrides nl_func_def_start when there is only one parameter. +nl_func_def_start_single = ignore # ignore/add/remove/force/not_defined -# Whether to put a blank line before 'return' statements, unless after an open brace. -nl_before_return = false # false/true +# Whether to add a newline after '(' in a function declaration if '(' and ')' +# are in different lines. If false, nl_func_decl_start is used instead. +nl_func_decl_start_multi_line = false # true/false -# Whether to put a blank line after 'return' statements, unless followed by a close brace. -nl_after_return = false # false/true +# Whether to add a newline after '(' in a function definition if '(' and ')' +# are in different lines. If false, nl_func_def_start is used instead. +nl_func_def_start_multi_line = false # true/false -# Whether to put a newline after a Java annotation statement. -# Only affects annotations that are after a newline. -nl_after_annotation = ignore # ignore/add/remove/force +# Add or remove newline after each ',' in a function declaration. +nl_func_decl_args = ignore # ignore/add/remove/force/not_defined -# Controls the newline between two annotations. -nl_between_annotation = ignore # ignore/add/remove/force +# Add or remove newline after each ',' in a function definition. +nl_func_def_args = ignore # ignore/add/remove/force/not_defined -# -# Code modifying options (non-whitespace) -# +# Add or remove newline after each ',' in a function call. +nl_func_call_args = ignore # ignore/add/remove/force/not_defined -# Add or remove braces on single-line 'do' statement -mod_full_brace_do = ignore # ignore/add/remove/force +# Whether to add a newline after each ',' in a function declaration if '(' +# and ')' are in different lines. If false, nl_func_decl_args is used instead. +nl_func_decl_args_multi_line = false # true/false -# Add or remove braces on single-line 'for' statement -mod_full_brace_for = ignore # ignore/add/remove/force +# Whether to add a newline after each ',' in a function definition if '(' +# and ')' are in different lines. If false, nl_func_def_args is used instead. +nl_func_def_args_multi_line = false # true/false -# Add or remove braces on single-line function definitions. (Pawn) -mod_full_brace_function = ignore # ignore/add/remove/force +# Add or remove newline before the ')' in a function declaration. +nl_func_decl_end = ignore # ignore/add/remove/force/not_defined -# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'. -mod_full_brace_if = ignore # ignore/add/remove/force +# Add or remove newline before the ')' in a function definition. +nl_func_def_end = remove # ignore/add/remove/force/not_defined -# Make all if/elseif/else statements in a chain be braced or not. Overrides mod_full_brace_if. -# If any must be braced, they are all braced. If all can be unbraced, then the braces are removed. -mod_full_brace_if_chain = false # false/true +# Overrides nl_func_decl_end when there is only one parameter. +nl_func_decl_end_single = ignore # ignore/add/remove/force/not_defined -# Don't remove braces around statements that span N newlines -mod_full_brace_nl = 0 # number +# Overrides nl_func_def_end when there is only one parameter. +nl_func_def_end_single = ignore # ignore/add/remove/force/not_defined -# Add or remove braces on single-line 'while' statement -mod_full_brace_while = ignore # ignore/add/remove/force +# Whether to add a newline before ')' in a function declaration if '(' and ')' +# are in different lines. If false, nl_func_decl_end is used instead. +nl_func_decl_end_multi_line = false # true/false -# Add or remove braces on single-line 'using ()' statement -mod_full_brace_using = ignore # ignore/add/remove/force +# Whether to add a newline before ')' in a function definition if '(' and ')' +# are in different lines. If false, nl_func_def_end is used instead. +nl_func_def_end_multi_line = false # true/false -# Add or remove unnecessary paren on 'return' statement -mod_paren_on_return = ignore # ignore/add/remove/force +# Add or remove newline between '()' in a function declaration. +nl_func_decl_empty = ignore # ignore/add/remove/force/not_defined -# Whether to change optional semicolons to real semicolons -mod_pawn_semicolon = false # false/true +# Add or remove newline between '()' in a function definition. +nl_func_def_empty = ignore # ignore/add/remove/force/not_defined -# Add parens on 'while' and 'if' statement around bools -mod_full_paren_if_bool = false # false/true +# Add or remove newline between '()' in a function call. +nl_func_call_empty = ignore # ignore/add/remove/force/not_defined -# Whether to remove superfluous semicolons -mod_remove_extra_semicolon = false # false/true +# Whether to add a newline after '(' in a function call, +# has preference over nl_func_call_start_multi_line. +nl_func_call_start = ignore # ignore/add/remove/force/not_defined -# If a function body exceeds the specified number of newlines and doesn't have a comment after -# the close brace, a comment will be added. -mod_add_long_function_closebrace_comment = 0 # number +# Whether to add a newline before ')' in a function call. +nl_func_call_end = ignore # ignore/add/remove/force/not_defined -# If a switch body exceeds the specified number of newlines and doesn't have a comment after -# the close brace, a comment will be added. -mod_add_long_switch_closebrace_comment = 0 # number +# Whether to add a newline after '(' in a function call if '(' and ')' are in +# different lines. +nl_func_call_start_multi_line = false # true/false -# If an #ifdef body exceeds the specified number of newlines and doesn't have a comment after -# the #endif, a comment will be added. -mod_add_long_ifdef_endif_comment = 0 # number +# Whether to add a newline after each ',' in a function call if '(' and ')' +# are in different lines. +nl_func_call_args_multi_line = false # true/false -# If an #ifdef or #else body exceeds the specified number of newlines and doesn't have a comment after -# the #else, a comment will be added. -mod_add_long_ifdef_else_comment = 0 # number +# Whether to add a newline before ')' in a function call if '(' and ')' are in +# different lines. +nl_func_call_end_multi_line = false # true/false -# If TRUE, will sort consecutive single-line 'import' statements [Java, D] -mod_sort_import = false # false/true +# Whether to respect nl_func_call_XXX option in case of closure args. +nl_func_call_args_multi_line_ignore_closures = false # true/false -# If TRUE, will sort consecutive single-line 'using' statements [C#] -mod_sort_using = false # false/true +# Whether to add a newline after '<' of a template parameter list. +nl_template_start = false # true/false -# If TRUE, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C] -# This is generally a bad idea, as it may break your code. -mod_sort_include = false # false/true +# Whether to add a newline after each ',' in a template parameter list. +nl_template_args = false # true/false -# If TRUE, it will move a 'break' that appears after a fully braced 'case' before the close brace. -mod_move_case_break = false # false/true +# Whether to add a newline before '>' of a template parameter list. +nl_template_end = false # true/false -# Will add or remove the braces around a fully braced case statement. -# Will only remove the braces if there are no variable declarations in the block. -mod_case_brace = ignore # ignore/add/remove/force +# (OC) Whether to put each Objective-C message parameter on a separate line. +# See nl_oc_msg_leave_one_liner. +nl_oc_msg_args = false # true/false -# If TRUE, it will remove a void 'return;' that appears as the last statement in a function. -mod_remove_empty_return = false # false/true +# (OC) Minimum number of Objective-C message parameters before applying nl_oc_msg_args. +nl_oc_msg_args_min_params = 0 # unsigned number -# -# Comment modifications -# +# (OC) Max code width of Objective-C message before applying nl_oc_msg_args. +nl_oc_msg_args_max_code_width = 0 # unsigned number -# Try to wrap comments at cmt_width columns -cmt_width = 0 # number +# Add or remove newline between function signature and '{'. +nl_fdef_brace = add # ignore/add/remove/force/not_defined -# Set the comment reflow mode (default: 0) -# 0: no reflowing (apart from the line wrapping due to cmt_width) -# 1: no touching at all -# 2: full reflow -cmt_reflow_mode = 0 # number +# Add or remove newline between function signature and '{', +# if signature ends with ')'. Overrides nl_fdef_brace. +nl_fdef_brace_cond = ignore # ignore/add/remove/force/not_defined -# If false, disable all multi-line comment changes, including cmt_width. keyword substitution, and leading chars. -# Default is true. -cmt_indent_multi = true # false/true +# Add or remove newline between C++11 lambda signature and '{'. +nl_cpp_ldef_brace = ignore # ignore/add/remove/force/not_defined -# Whether to group c-comments that look like they are in a block -cmt_c_group = false # false/true +# Add or remove newline between 'return' and the return expression. +nl_return_expr = ignore # ignore/add/remove/force/not_defined -# Whether to put an empty '/*' on the first line of the combined c-comment -cmt_c_nl_start = false # false/true +# Add or remove newline between 'throw' and the throw expression. +nl_throw_expr = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline before the closing '*/' of the combined c-comment -cmt_c_nl_end = false # false/true +# Whether to add a newline after semicolons, except in 'for' statements. +nl_after_semicolon = true # true/false -# Whether to group cpp-comments that look like they are in a block -cmt_cpp_group = false # false/true +# (Java) Add or remove newline between the ')' and '{{' of the double brace +# initializer. +nl_paren_dbrace_open = ignore # ignore/add/remove/force/not_defined -# Whether to put an empty '/*' on the first line of the combined cpp-comment -cmt_cpp_nl_start = false # false/true +# Whether to add a newline after the type in an unnamed temporary +# direct-list-initialization, better: +# before a direct-list-initialization. +nl_type_brace_init_lst = ignore # ignore/add/remove/force/not_defined + +# Whether to add a newline after the open brace in an unnamed temporary +# direct-list-initialization. +nl_type_brace_init_lst_open = ignore # ignore/add/remove/force/not_defined + +# Whether to add a newline before the close brace in an unnamed temporary +# direct-list-initialization. +nl_type_brace_init_lst_close = ignore # ignore/add/remove/force/not_defined + +# Whether to add a newline before '{'. +nl_before_brace_open = false # true/false + +# Whether to add a newline after '{'. +nl_after_brace_open = false # true/false + +# Whether to add a newline between the open brace and a trailing single-line +# comment. Requires nl_after_brace_open=true. +nl_after_brace_open_cmt = false # true/false + +# Whether to add a newline after a virtual brace open with a non-empty body. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open = false # true/false + +# Whether to add a newline after a virtual brace open with an empty body. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open_empty = false # true/false + +# Whether to add a newline after '}'. Does not apply if followed by a +# necessary ';'. +nl_after_brace_close = false # true/false + +# Whether to add a newline after a virtual brace close, +# as in 'if (foo) a++; return;'. +nl_after_vbrace_close = false # true/false + +# Add or remove newline between the close brace and identifier, +# as in 'struct { int a; } b;'. Affects enumerations, unions and +# structures. If set to ignore, uses nl_after_brace_close. +nl_brace_struct_var = ignore # ignore/add/remove/force/not_defined + +# Whether to alter newlines in '#define' macros. +nl_define_macro = false # true/false + +# Whether to alter newlines between consecutive parenthesis closes. The number +# of closing parentheses in a line will depend on respective open parenthesis +# lines. +nl_squeeze_paren_close = false # true/false + +# Whether to remove blanks after '#ifxx' and '#elxx', or before '#elxx' and +# '#endif'. Does not affect top-level #ifdefs. +nl_squeeze_ifdef = false # true/false + +# Makes the nl_squeeze_ifdef option affect the top-level #ifdefs as well. +nl_squeeze_ifdef_top_level = false # true/false + +# Add or remove blank line before 'if'. +nl_before_if = ignore # ignore/add/remove/force/not_defined + +# Add or remove blank line after 'if' statement. Add/Force work only if the +# next token is not a closing brace. +nl_after_if = ignore # ignore/add/remove/force/not_defined + +# Add or remove blank line before 'for'. +nl_before_for = ignore # ignore/add/remove/force/not_defined + +# Add or remove blank line after 'for' statement. +nl_after_for = remove # ignore/add/remove/force/not_defined + +# Add or remove blank line before 'while'. +nl_before_while = ignore # ignore/add/remove/force/not_defined + +# Add or remove blank line after 'while' statement. +nl_after_while = remove # ignore/add/remove/force/not_defined + +# Add or remove blank line before 'switch'. +nl_before_switch = ignore # ignore/add/remove/force/not_defined + +# Add or remove blank line after 'switch' statement. +nl_after_switch = ignore # ignore/add/remove/force/not_defined -# Whether to put a newline before the closing '*/' of the combined cpp-comment -cmt_cpp_nl_end = false # false/true +# Add or remove blank line before 'synchronized'. +nl_before_synchronized = ignore # ignore/add/remove/force/not_defined -# Whether to change cpp-comments into c-comments -cmt_cpp_to_c = true # false/true +# Add or remove blank line after 'synchronized' statement. +nl_after_synchronized = ignore # ignore/add/remove/force/not_defined -# Whether to put a star on subsequent comment lines -cmt_star_cont = false # false/true +# Add or remove blank line before 'do'. +nl_before_do = ignore # ignore/add/remove/force/not_defined -# The number of spaces to insert at the start of subsequent comment lines -cmt_sp_before_star_cont = 0 # number +# Add or remove blank line after 'do/while' statement. +nl_after_do = ignore # ignore/add/remove/force/not_defined -# The number of spaces to insert after the star on subsequent comment lines -cmt_sp_after_star_cont = 0 # number +# Ignore nl_before_{if,for,switch,do,synchronized} if the control +# statement is immediately after a case statement. +# if nl_before_{if,for,switch,do} is set to remove, this option +# does nothing. +nl_before_ignore_after_case = false # true/false -# For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of -# the comment are the same length. Default=True -cmt_multi_check_last = false # false/true +# Whether to put a blank line before 'return' statements, unless after an open +# brace. +nl_before_return = false # true/false -# The filename that contains text to insert at the head of a file if the file doesn't start with a C/C++ comment. -# Will substitute $(filename) with the current file's name. -cmt_insert_file_header = "" # string +# Whether to put a blank line after 'return' statements, unless followed by a +# close brace. +nl_after_return = false # true/false -# The filename that contains text to insert at the end of a file if the file doesn't end with a C/C++ comment. -# Will substitute $(filename) with the current file's name. -cmt_insert_file_footer = "" # string +# Whether to put a blank line before a member '.' or '->' operators. +nl_before_member = ignore # ignore/add/remove/force/not_defined -# The filename that contains text to insert before a function implementation if the function isn't preceded with a C/C++ comment. -# Will substitute $(function) with the function name and $(javaparam) with the javadoc @param and @return stuff. -# Will also substitute $(fclass) with the class name: void CFoo::Bar() { ... } -cmt_insert_func_header = "" # string +# (Java) Whether to put a blank line after a member '.' or '->' operators. +nl_after_member = ignore # ignore/add/remove/force/not_defined -# The filename that contains text to insert before a class if the class isn't preceded with a C/C++ comment. -# Will substitute $(class) with the class name. -cmt_insert_class_header = "" # string +# Whether to double-space commented-entries in 'struct'/'union'/'enum'. +nl_ds_struct_enum_cmt = false # true/false -# The filename that contains text to insert before a Obj-C message specification if the method isn't preceeded with a C/C++ comment. -# Will substitute $(message) with the function name and $(javaparam) with the javadoc @param and @return stuff. -cmt_insert_oc_msg_header = "" # string +# Whether to force a newline before '}' of a 'struct'/'union'/'enum'. +# (Lower priority than eat_blanks_before_close_brace.) +nl_ds_struct_enum_close_brace = false # true/false -# If a preprocessor is encountered when stepping backwards from a function name, then -# this option decides whether the comment should be inserted. -# Affects cmt_insert_oc_msg_header, cmt_insert_func_header and cmt_insert_class_header. -cmt_insert_before_preproc = false # false/true +# Add or remove newline before or after (depending on pos_class_colon) a class +# colon, as in 'class Foo : public Bar'. +nl_class_colon = ignore # ignore/add/remove/force/not_defined + +# Add or remove newline around a class constructor colon. The exact position +# depends on nl_constr_init_args, pos_constr_colon and pos_constr_comma. +nl_constr_colon = ignore # ignore/add/remove/force/not_defined + +# Whether to collapse a two-line namespace, like 'namespace foo\n{ decl; }' +# into a single line. If true, prevents other brace newline rules from turning +# such code into four lines. If true, it also preserves one-liner namespaces. +nl_namespace_two_to_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced if statements, turning them +# into one-liners, as in 'if(b)\n i++;' => 'if(b) i++;'. +nl_create_if_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced for statements, turning them +# into one-liners, as in 'for (...)\n stmt;' => 'for (...) stmt;'. +nl_create_for_one_liner = false # true/false + +# Whether to remove a newline in simple unbraced while statements, turning +# them into one-liners, as in 'while (expr)\n stmt;' => 'while (expr) stmt;'. +nl_create_while_one_liner = false # true/false + +# Whether to collapse a function definition whose body (not counting braces) +# is only one line so that the entire definition (prototype, braces, body) is +# a single line. +nl_create_func_def_one_liner = false # true/false + +# Whether to split one-line simple list definitions into three lines by +# adding newlines, as in 'int a[12] = { 0 };'. +nl_create_list_one_liner = false # true/false + +# Whether to split one-line simple unbraced if statements into two lines by +# adding a newline, as in 'if(b) i++;'. +nl_split_if_one_liner = false # true/false + +# Whether to split one-line simple unbraced for statements into two lines by +# adding a newline, as in 'for (...) stmt;'. +nl_split_for_one_liner = false # true/false + +# Whether to split one-line simple unbraced while statements into two lines by +# adding a newline, as in 'while (expr) stmt;'. +nl_split_while_one_liner = false # true/false + +# Don't add a newline before a cpp-comment in a parameter list of a function +# call. +donot_add_nl_before_cpp_comment = false # true/false # -# Preprocessor options +# Blank line options # -# Control indent of preprocessors inside #if blocks at brace level 0 -pp_indent = ignore # ignore/add/remove/force +# The maximum number of consecutive newlines (3 = 2 blank lines). +nl_max = 0 # unsigned number + +# The maximum number of consecutive newlines in a function. +nl_max_blank_in_func = 0 # unsigned number -# Whether to indent #if/#else/#endif at the brace level (true) or from column 1 (false) -pp_indent_at_level = false # false/true +# The number of newlines inside an empty function body. +# This option overrides eat_blanks_after_open_brace and +# eat_blanks_before_close_brace, but is ignored when +# nl_collapse_empty_body_functions=true +nl_inside_empty_func = 0 # unsigned number -# If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1. -pp_indent_count = 1 # number +# The number of newlines before a function prototype. +nl_before_func_body_proto = 0 # unsigned number -# Add or remove space after # based on pp_level of #if blocks -pp_space = ignore # ignore/add/remove/force +# The number of newlines before a multi-line function definition. Where +# applicable, this option is overridden with eat_blanks_after_open_brace=true +nl_before_func_body_def = 0 # unsigned number -# Sets the number of spaces added with pp_space -pp_space_count = 0 # number +# The number of newlines before a class constructor/destructor prototype. +nl_before_func_class_proto = 0 # unsigned number -# The indent for #region and #endregion in C# and '#pragma region' in C/C++ -pp_indent_region = 0 # number +# The number of newlines before a class constructor/destructor definition. +nl_before_func_class_def = 0 # unsigned number -# Whether to indent the code between #region and #endregion -pp_region_indent_code = false # false/true +# The number of newlines after a function prototype. +nl_after_func_proto = 0 # unsigned number -# If pp_indent_at_level=true, sets the indent for #if, #else, and #endif when not at file-level -pp_indent_if = 0 # number +# The number of newlines after a function prototype, if not followed by +# another function prototype. +nl_after_func_proto_group = 0 # unsigned number -# Control whether to indent the code between #if, #else and #endif when not at file-level -pp_if_indent_code = false # false/true +# The number of newlines after a class constructor/destructor prototype. +nl_after_func_class_proto = 0 # unsigned number -# Whether to indent '#define' at the brace level (true) or from column 1 (false) -pp_define_at_level = false # false/true +# The number of newlines after a class constructor/destructor prototype, +# if not followed by another constructor/destructor prototype. +nl_after_func_class_proto_group = 0 # unsigned number + +# Whether one-line method definitions inside a class body should be treated +# as if they were prototypes for the purposes of adding newlines. +# +# Requires nl_class_leave_one_liners=true. Overrides nl_before_func_body_def +# and nl_before_func_class_def for one-liners. +nl_class_leave_one_liner_groups = false # true/false -# You can force a token to be a type with the 'type' option. -# Example: -# type myfoo1 myfoo2 +# The number of newlines after '}' of a multi-line function body. +# +# Overrides nl_min_after_func_body and nl_max_after_func_body. +nl_after_func_body = 0 # unsigned number + +# The minimum number of newlines after '}' of a multi-line function body. +# +# Only works when nl_after_func_body is 0. +nl_min_after_func_body = 0 # unsigned number + +# The maximum number of newlines after '}' of a multi-line function body. +# +# Only works when nl_after_func_body is 0. +# Takes precedence over nl_min_after_func_body. +nl_max_after_func_body = 0 # unsigned number + +# The number of newlines after '}' of a multi-line function body in a class +# declaration. Also affects class constructors/destructors. +# +# Overrides nl_after_func_body. +nl_after_func_body_class = 0 # unsigned number + +# The number of newlines after '}' of a single line function body. Also +# affects class constructors/destructors. +# +# Overrides nl_after_func_body and nl_after_func_body_class. +nl_after_func_body_one_liner = 0 # unsigned number + +# The number of newlines before a block of typedefs. If nl_after_access_spec +# is non-zero, that option takes precedence. +# +# 0: No change (default). +nl_typedef_blk_start = 0 # unsigned number + +# The number of newlines after a block of typedefs. +# +# 0: No change (default). +nl_typedef_blk_end = 0 # unsigned number + +# The maximum number of consecutive newlines within a block of typedefs. +# +# 0: No change (default). +nl_typedef_blk_in = 0 # unsigned number + +# The minimum number of blank lines after a block of variable definitions +# at the top of a function body. If any preprocessor directives appear +# between the opening brace of the function and the variable block, then +# it is considered as not at the top of the function.Newlines are added +# before trailing preprocessor directives, if any exist. +# +# 0: No change (default). +nl_var_def_blk_end_func_top = 0 # unsigned number + +# The minimum number of empty newlines before a block of variable definitions +# not at the top of a function body. If nl_after_access_spec is non-zero, +# that option takes precedence. Newlines are not added at the top of the +# file or just after an opening brace. Newlines are added above any +# preprocessor directives before the block. +# +# 0: No change (default). +nl_var_def_blk_start = 0 # unsigned number + +# The minimum number of empty newlines after a block of variable definitions +# not at the top of a function body. Newlines are not added if the block +# is at the bottom of the file or just before a preprocessor directive. +# +# 0: No change (default). +nl_var_def_blk_end = 0 # unsigned number + +# The maximum number of consecutive newlines within a block of variable +# definitions. +# +# 0: No change (default). +nl_var_def_blk_in = 0 # unsigned number + +# The minimum number of newlines before a multi-line comment. +# Doesn't apply if after a brace open or another multi-line comment. +nl_before_block_comment = 0 # unsigned number + +# The minimum number of newlines before a single-line C comment. +# Doesn't apply if after a brace open or other single-line C comments. +nl_before_c_comment = 0 # unsigned number + +# The minimum number of newlines before a CPP comment. +# Doesn't apply if after a brace open or other CPP comments. +nl_before_cpp_comment = 0 # unsigned number + +# Whether to force a newline after a multi-line comment. +nl_after_multiline_comment = false # true/false + +# Whether to force a newline after a label's colon. +nl_after_label_colon = false # true/false + +# The number of newlines before a struct definition. +nl_before_struct = 0 # unsigned number + +# The number of newlines after '}' or ';' of a struct/enum/union definition. +nl_after_struct = 0 # unsigned number + +# The number of newlines before a class definition. +nl_before_class = 0 # unsigned number + +# The number of newlines after '}' or ';' of a class definition. +nl_after_class = 0 # unsigned number + +# The number of newlines before a namespace. +nl_before_namespace = 0 # unsigned number + +# The number of newlines after '{' of a namespace. This also adds newlines +# before the matching '}'. +# +# 0: Apply eat_blanks_after_open_brace or eat_blanks_before_close_brace if +# applicable, otherwise no change. +# +# Overrides eat_blanks_after_open_brace and eat_blanks_before_close_brace. +nl_inside_namespace = 0 # unsigned number + +# The number of newlines after '}' of a namespace. +nl_after_namespace = 0 # unsigned number + +# The number of newlines before an access specifier label. This also includes +# the Qt-specific 'signals:' and 'slots:'. Will not change the newline count +# if after a brace open. +# +# 0: No change (default). +nl_before_access_spec = 0 # unsigned number + +# The number of newlines after an access specifier label. This also includes +# the Qt-specific 'signals:' and 'slots:'. Will not change the newline count +# if after a brace open. +# +# 0: No change (default). +# +# Overrides nl_typedef_blk_start and nl_var_def_blk_start. +nl_after_access_spec = 0 # unsigned number + +# The number of newlines between a function definition and the function +# comment, as in '// comment\n void foo() {...}'. +# +# 0: No change (default). +nl_comment_func_def = 0 # unsigned number + +# The number of newlines after a try-catch-finally block that isn't followed +# by a brace close. +# +# 0: No change (default). +nl_after_try_catch_finally = 0 # unsigned number + +# (C#) The number of newlines before and after a property, indexer or event +# declaration. +# +# 0: No change (default). +nl_around_cs_property = 0 # unsigned number + +# (C#) The number of newlines between the get/set/add/remove handlers. +# +# 0: No change (default). +nl_between_get_set = 0 # unsigned number + +# (C#) Add or remove newline between property and the '{'. +nl_property_brace = ignore # ignore/add/remove/force/not_defined + +# Whether to remove blank lines after '{'. +eat_blanks_after_open_brace = false # true/false + +# Whether to remove blank lines before '}'. +eat_blanks_before_close_brace = false # true/false + +# How aggressively to remove extra newlines not in preprocessor. +# +# 0: No change (default) +# 1: Remove most newlines not handled by other config +# 2: Remove all newlines and reformat completely by config +nl_remove_extra_newlines = 0 # unsigned number + +# (Java) Add or remove newline after an annotation statement. Only affects +# annotations that are after a newline. +nl_after_annotation = ignore # ignore/add/remove/force/not_defined + +# (Java) Add or remove newline between two annotations. +nl_between_annotation = ignore # ignore/add/remove/force/not_defined + +# The number of newlines before a whole-file #ifdef. +# +# 0: No change (default). +nl_before_whole_file_ifdef = 0 # unsigned number + +# The number of newlines after a whole-file #ifdef. +# +# 0: No change (default). +nl_after_whole_file_ifdef = 0 # unsigned number + +# The number of newlines before a whole-file #endif. +# +# 0: No change (default). +nl_before_whole_file_endif = 0 # unsigned number + +# The number of newlines after a whole-file #endif. +# +# 0: No change (default). +nl_after_whole_file_endif = 0 # unsigned number + +# +# Positioning options +# + +# The position of arithmetic operators in wrapped expressions. +pos_arith = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of assignment in wrapped expressions. Do not affect '=' +# followed by '{'. +pos_assign = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of Boolean operators in wrapped expressions. +pos_bool = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of comparison operators in wrapped expressions. +pos_compare = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of conditional operators, as in the '?' and ':' of +# 'expr ? stmt : stmt', in wrapped expressions. +pos_conditional = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in wrapped expressions. +pos_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in enum entries. +pos_enum_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in the base class list if there is more than one +# line. Affects nl_class_init_args. +pos_class_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of the comma in the constructor initialization list. +# Related to nl_constr_colon, nl_constr_init_args and pos_constr_colon. +pos_constr_comma = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of trailing/leading class colon, between class and base class +# list. Affects nl_class_colon. +pos_class_colon = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of colons between constructor and member initialization. +# Related to nl_constr_colon, nl_constr_init_args and pos_constr_comma. +pos_constr_colon = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# The position of shift operators in wrapped expressions. +pos_shift = ignore # ignore/break/force/lead/trail/join/lead_break/lead_force/trail_break/trail_force + +# +# Line splitting options +# + +# Try to limit code width to N columns. +code_width = 0 # unsigned number + +# Whether to fully split long 'for' statements at semi-colons. +ls_for_split_full = false # true/false + +# Whether to fully split long function prototypes/calls at commas. +# The option ls_code_width has priority over the option ls_func_split_full. +ls_func_split_full = false # true/false + +# Whether to split lines as close to code_width as possible and ignore some +# groupings. +# The option ls_code_width has priority over the option ls_func_split_full. +ls_code_width = false # true/false + +# +# Code alignment options (not left column spaces/tabs) +# + +# Whether to keep non-indenting tabs. +align_keep_tabs = false # true/false + +# Whether to use tabs for aligning. +align_with_tabs = false # true/false + +# Whether to bump out to the next tab when aligning. +align_on_tabstop = false # true/false + +# Whether to right-align numbers. +align_number_right = false # true/false + +# Whether to keep whitespace not required for alignment. +align_keep_extra_space = false # true/false + +# Whether to align variable definitions in prototypes and functions. +align_func_params = false # true/false + +# The span for aligning parameter definitions in function on parameter name. +# +# 0: Don't align (default). +align_func_params_span = 0 # unsigned number + +# The threshold for aligning function parameter definitions. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_func_params_thresh = 0 # number + +# The gap for aligning function parameter definitions. +align_func_params_gap = 0 # unsigned number + +# The span for aligning constructor value. +# +# 0: Don't align (default). +align_constr_value_span = 0 # unsigned number + +# The threshold for aligning constructor value. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_constr_value_thresh = 0 # number + +# The gap for aligning constructor value. +align_constr_value_gap = 0 # unsigned number + +# Whether to align parameters in single-line functions that have the same +# name. The function names must already be aligned with each other. +align_same_func_call_params = false # true/false + +# The span for aligning function-call parameters for single line functions. +# +# 0: Don't align (default). +align_same_func_call_params_span = 0 # unsigned number + +# The threshold for aligning function-call parameters for single line +# functions. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_same_func_call_params_thresh = 0 # number + +# The span for aligning variable definitions. +# +# 0: Don't align (default). +align_var_def_span = 0 # unsigned number + +# How to consider (or treat) the '*' in the alignment of variable definitions. +# +# 0: Part of the type 'void * foo;' (default) +# 1: Part of the variable 'void *foo;' +# 2: Dangling 'void *foo;' +# Dangling: the '*' will not be taken into account when aligning. +align_var_def_star_style = 1 # unsigned number + +# How to consider (or treat) the '&' in the alignment of variable definitions. +# +# 0: Part of the type 'long & foo;' (default) +# 1: Part of the variable 'long &foo;' +# 2: Dangling 'long &foo;' +# Dangling: the '&' will not be taken into account when aligning. +align_var_def_amp_style = 1 # unsigned number + +# The threshold for aligning variable definitions. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_var_def_thresh = 0 # number + +# The gap for aligning variable definitions. +align_var_def_gap = 0 # unsigned number + +# Whether to align the colon in struct bit fields. +align_var_def_colon = false # true/false + +# The gap for aligning the colon in struct bit fields. +align_var_def_colon_gap = 0 # unsigned number + +# Whether to align any attribute after the variable name. +align_var_def_attribute = false # true/false + +# Whether to align inline struct/enum/union variable definitions. +align_var_def_inline = false # true/false + +# The span for aligning on '=' in assignments. +# +# 0: Don't align (default). +align_assign_span = 0 # unsigned number + +# The span for aligning on '=' in function prototype modifier. +# +# 0: Don't align (default). +align_assign_func_proto_span = 0 # unsigned number + +# The threshold for aligning on '=' in assignments. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_assign_thresh = 0 # number + +# Whether to align on the left most assignment when multiple +# definitions are found on the same line. +# Depends on 'align_assign_span' and 'align_assign_thresh' settings. +align_assign_on_multi_var_defs = false # true/false + +# The span for aligning on '{' in braced init list. +# +# 0: Don't align (default). +align_braced_init_list_span = 0 # unsigned number + +# The threshold for aligning on '{' in braced init list. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_braced_init_list_thresh = 0 # number + +# How to apply align_assign_span to function declaration "assignments", i.e. +# 'virtual void foo() = 0' or '~foo() = {default|delete}'. +# +# 0: Align with other assignments (default) +# 1: Align with each other, ignoring regular assignments +# 2: Don't align +align_assign_decl_func = 0 # unsigned number + +# The span for aligning on '=' in enums. +# +# 0: Don't align (default). +align_enum_equ_span = 0 # unsigned number + +# The threshold for aligning on '=' in enums. +# Use a negative number for absolute thresholds. +# +# 0: no limit (default). +align_enum_equ_thresh = 0 # number + +# The span for aligning class member definitions. +# +# 0: Don't align (default). +align_var_class_span = 0 # unsigned number + +# The threshold for aligning class member definitions. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_var_class_thresh = 0 # number + +# The gap for aligning class member definitions. +align_var_class_gap = 0 # unsigned number + +# The span for aligning struct/union member definitions. +# +# 0: Don't align (default). +align_var_struct_span = 0 # unsigned number + +# The threshold for aligning struct/union member definitions. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_var_struct_thresh = 0 # number + +# The gap for aligning struct/union member definitions. +align_var_struct_gap = 0 # unsigned number + +# The span for aligning struct initializer values. +# +# 0: Don't align (default). +align_struct_init_span = 0 # unsigned number + +# The span for aligning single-line typedefs. +# +# 0: Don't align (default). +align_typedef_span = 0 # unsigned number + +# The minimum space between the type and the synonym of a typedef. +align_typedef_gap = 0 # unsigned number + +# How to align typedef'd functions with other typedefs. +# +# 0: Don't mix them at all (default) +# 1: Align the open parenthesis with the types +# 2: Align the function type name with the other type names +align_typedef_func = 0 # unsigned number + +# How to consider (or treat) the '*' in the alignment of typedefs. +# +# 0: Part of the typedef type, 'typedef int * pint;' (default) +# 1: Part of type name: 'typedef int *pint;' +# 2: Dangling: 'typedef int *pint;' +# Dangling: the '*' will not be taken into account when aligning. +align_typedef_star_style = 0 # unsigned number + +# How to consider (or treat) the '&' in the alignment of typedefs. +# +# 0: Part of the typedef type, 'typedef int & intref;' (default) +# 1: Part of type name: 'typedef int &intref;' +# 2: Dangling: 'typedef int &intref;' +# Dangling: the '&' will not be taken into account when aligning. +align_typedef_amp_style = 0 # unsigned number + +# The span for aligning comments that end lines. +# +# 0: Don't align (default). +align_right_cmt_span = 0 # unsigned number + +# Minimum number of columns between preceding text and a trailing comment in +# order for the comment to qualify for being aligned. Must be non-zero to have +# an effect. +align_right_cmt_gap = 0 # unsigned number + +# If aligning comments, whether to mix with comments after '}' and #endif with +# less than three spaces before the comment. +align_right_cmt_mix = false # true/false + +# Whether to only align trailing comments that are at the same brace level. +align_right_cmt_same_level = false # true/false + +# Minimum column at which to align trailing comments. Comments which are +# aligned beyond this column, but which can be aligned in a lesser column, +# may be "pulled in". +# +# 0: Ignore (default). +align_right_cmt_at_col = 0 # unsigned number + +# The span for aligning function prototypes. +# +# 0: Don't align (default). +align_func_proto_span = 0 # unsigned number + +# Whether to ignore continuation lines when evaluating the number of +# new lines for the function prototype alignment's span. +# +# false: continuation lines are part of the newlines count +# true: continuation lines are not counted +align_func_proto_span_ignore_cont_lines = false # true/false + +# How to consider (or treat) the '*' in the alignment of function prototypes. +# +# 0: Part of the type 'void * foo();' (default) +# 1: Part of the function 'void *foo();' +# 2: Dangling 'void *foo();' +# Dangling: the '*' will not be taken into account when aligning. +align_func_proto_star_style = 0 # unsigned number + +# How to consider (or treat) the '&' in the alignment of function prototypes. +# +# 0: Part of the type 'long & foo();' (default) +# 1: Part of the function 'long &foo();' +# 2: Dangling 'long &foo();' +# Dangling: the '&' will not be taken into account when aligning. +align_func_proto_amp_style = 0 # unsigned number + +# The threshold for aligning function prototypes. +# Use a negative number for absolute thresholds. +# +# 0: No limit (default). +align_func_proto_thresh = 0 # number + +# Minimum gap between the return type and the function name. +align_func_proto_gap = 0 # unsigned number + +# Whether to align function prototypes on the 'operator' keyword instead of +# what follows. +align_on_operator = false # true/false + +# Whether to mix aligning prototype and variable declarations. If true, +# align_var_def_XXX options are used instead of align_func_proto_XXX options. +align_mix_var_proto = false # true/false + +# Whether to align single-line functions with function prototypes. +# Uses align_func_proto_span. +align_single_line_func = false # true/false + +# Whether to align the open brace of single-line functions. +# Requires align_single_line_func=true. Uses align_func_proto_span. +align_single_line_brace = false # true/false + +# Gap for align_single_line_brace. +align_single_line_brace_gap = 0 # unsigned number + +# (OC) The span for aligning Objective-C message specifications. +# +# 0: Don't align (default). +align_oc_msg_spec_span = 0 # unsigned number + +# Whether and how to align backslashes that split a macro onto multiple lines. +# This will not work right if the macro contains a multi-line comment. +# +# 0: Do nothing (default) +# 1: Align the backslashes in the column at the end of the longest line +# 2: Align with the backslash that is farthest to the left, or, if that +# backslash is farther left than the end of the longest line, at the end of +# the longest line +# 3: Align with the backslash that is farthest to the right +align_nl_cont = 0 # unsigned number + +# The minimum number of spaces between the end of a line and its continuation +# backslash. Requires align_nl_cont. +# +# Default: 1 +align_nl_cont_spaces = 1 # unsigned number + +# Whether to align macro functions and variables together. +align_pp_define_together = false # true/false + +# The span for aligning on '#define' bodies. +# +# =0: Don't align (default) +# >0: Number of lines (including comments) between blocks +align_pp_define_span = 0 # unsigned number + +# The minimum space between label and value of a preprocessor define. +align_pp_define_gap = 0 # unsigned number + +# Whether to align lines that start with '<<' with previous '<<'. +# +# Default: true +align_left_shift = true # true/false + +# Whether to align comma-separated statements following '<<' (as used to +# initialize Eigen matrices). +align_eigen_comma_init = false # true/false + +# Whether to align text after 'asm volatile ()' colons. +align_asm_colon = false # true/false + +# (OC) Span for aligning parameters in an Objective-C message call +# on the ':'. +# +# 0: Don't align. +align_oc_msg_colon_span = 0 # unsigned number + +# (OC) Whether to always align with the first parameter, even if it is too +# short. +align_oc_msg_colon_first = false # true/false + +# (OC) Whether to align parameters in an Objective-C '+' or '-' declaration +# on the ':'. +align_oc_decl_colon = false # true/false + +# (OC) Whether to not align parameters in an Objectve-C message call if first +# colon is not on next line of the message call (the same way Xcode does +# alignment) +align_oc_msg_colon_xcode_like = false # true/false + +# +# Comment modification options +# + +# Try to wrap comments at N columns. +cmt_width = 0 # unsigned number + +# How to reflow comments. +# +# 0: No reflowing (apart from the line wrapping due to cmt_width) (default) +# 1: No touching at all +# 2: Full reflow (enable cmt_indent_multi for indent with line wrapping due to cmt_width) +cmt_reflow_mode = 0 # unsigned number + +# Path to a file that contains regular expressions describing patterns for +# which the end of one line and the beginning of the next will be folded into +# the same sentence or paragraph during full comment reflow. The regular +# expressions are described using ECMAScript syntax. The syntax for this +# specification is as follows, where "..." indicates the custom regular +# expression and "n" indicates the nth end_of_prev_line_regex and +# beg_of_next_line_regex regular expression pair: +# +# end_of_prev_line_regex[1] = "...$" +# beg_of_next_line_regex[1] = "^..." +# end_of_prev_line_regex[2] = "...$" +# beg_of_next_line_regex[2] = "^..." +# . +# . +# . +# end_of_prev_line_regex[n] = "...$" +# beg_of_next_line_regex[n] = "^..." +# +# Note that use of this option overrides the default reflow fold regular +# expressions, which are internally defined as follows: +# +# end_of_prev_line_regex[1] = "[\w,\]\)]$" +# beg_of_next_line_regex[1] = "^[\w,\[\(]" +# end_of_prev_line_regex[2] = "\.$" +# beg_of_next_line_regex[2] = "^[A-Z]" +cmt_reflow_fold_regex_file = "" # string + +# Whether to indent wrapped lines to the start of the encompassing paragraph +# during full comment reflow (cmt_reflow_mode = 2). Overrides the value +# specified by cmt_sp_after_star_cont. +# +# Note that cmt_align_doxygen_javadoc_tags overrides this option for +# paragraphs associated with javadoc tags +cmt_reflow_indent_to_paragraph_start = false # true/false + +# Whether to convert all tabs to spaces in comments. If false, tabs in +# comments are left alone, unless used for indenting. +cmt_convert_tab_to_spaces = false # true/false + +# Whether to apply changes to multi-line comments, including cmt_width, +# keyword substitution and leading chars. +# +# Default: true +cmt_indent_multi = true # true/false + +# Whether to align doxygen javadoc-style tags ('@param', '@return', etc.) +# and corresponding fields such that groups of consecutive block tags, +# parameter names, and descriptions align with one another. Overrides that +# which is specified by the cmt_sp_after_star_cont. If cmt_width > 0, it may +# be necessary to enable cmt_indent_multi and set cmt_reflow_mode = 2 +# in order to achieve the desired alignment for line-wrapping. +cmt_align_doxygen_javadoc_tags = false # true/false + +# The number of spaces to insert after the star and before doxygen +# javadoc-style tags (@param, @return, etc). Requires enabling +# cmt_align_doxygen_javadoc_tags. Overrides that which is specified by the +# cmt_sp_after_star_cont. +# +# Default: 1 +cmt_sp_before_doxygen_javadoc_tags = 1 # unsigned number + +# Whether to change trailing, single-line c-comments into cpp-comments. +cmt_trailing_single_line_c_to_cpp = false # true/false + +# Whether to group c-comments that look like they are in a block. +cmt_c_group = false # true/false + +# Whether to put an empty '/*' on the first line of the combined c-comment. +cmt_c_nl_start = false # true/false + +# Whether to add a newline before the closing '*/' of the combined c-comment. +cmt_c_nl_end = false # true/false + +# Whether to change cpp-comments into c-comments. +cmt_cpp_to_c = true # true/false + +# Whether to group cpp-comments that look like they are in a block. Only +# meaningful if cmt_cpp_to_c=true. +cmt_cpp_group = false # true/false + +# Whether to put an empty '/*' on the first line of the combined cpp-comment +# when converting to a c-comment. +# +# Requires cmt_cpp_to_c=true and cmt_cpp_group=true. +cmt_cpp_nl_start = false # true/false + +# Whether to add a newline before the closing '*/' of the combined cpp-comment +# when converting to a c-comment. +# +# Requires cmt_cpp_to_c=true and cmt_cpp_group=true. +cmt_cpp_nl_end = false # true/false + +# Whether to put a star on subsequent comment lines. +cmt_star_cont = false # true/false + +# The number of spaces to insert at the start of subsequent comment lines. +cmt_sp_before_star_cont = 0 # unsigned number + +# The number of spaces to insert after the star on subsequent comment lines. +cmt_sp_after_star_cont = 0 # unsigned number + +# For multi-line comments with a '*' lead, remove leading spaces if the first +# and last lines of the comment are the same length. +# +# Default: true +cmt_multi_check_last = false # true/false + +# For multi-line comments with a '*' lead, remove leading spaces if the first +# and last lines of the comment are the same length AND if the length is +# bigger as the first_len minimum. +# +# Default: 4 +cmt_multi_first_len_minimum = 4 # unsigned number + +# Path to a file that contains text to insert at the beginning of a file if +# the file doesn't start with a C/C++ comment. If the inserted text contains +# '$(filename)', that will be replaced with the current file's name. +cmt_insert_file_header = "" # string + +# Path to a file that contains text to insert at the end of a file if the +# file doesn't end with a C/C++ comment. If the inserted text contains +# '$(filename)', that will be replaced with the current file's name. +cmt_insert_file_footer = "" # string + +# Path to a file that contains text to insert before a function definition if +# the function isn't preceded by a C/C++ comment. If the inserted text +# contains '$(function)', '$(javaparam)' or '$(fclass)', these will be +# replaced with, respectively, the name of the function, the javadoc '@param' +# and '@return' stuff, or the name of the class to which the member function +# belongs. +cmt_insert_func_header = "" # string + +# Path to a file that contains text to insert before a class if the class +# isn't preceded by a C/C++ comment. If the inserted text contains '$(class)', +# that will be replaced with the class name. +cmt_insert_class_header = "" # string + +# Path to a file that contains text to insert before an Objective-C message +# specification, if the method isn't preceded by a C/C++ comment. If the +# inserted text contains '$(message)' or '$(javaparam)', these will be +# replaced with, respectively, the name of the function, or the javadoc +# '@param' and '@return' stuff. +cmt_insert_oc_msg_header = "" # string + +# Whether a comment should be inserted if a preprocessor is encountered when +# stepping backwards from a function name. +# +# Applies to cmt_insert_oc_msg_header, cmt_insert_func_header and +# cmt_insert_class_header. +cmt_insert_before_preproc = false # true/false + +# Whether a comment should be inserted if a function is declared inline to a +# class definition. +# +# Applies to cmt_insert_func_header. +# +# Default: true +cmt_insert_before_inlines = true # true/false + +# Whether a comment should be inserted if the function is a class constructor +# or destructor. +# +# Applies to cmt_insert_func_header. +cmt_insert_before_ctor_dtor = false # true/false + +# +# Code modifying options (non-whitespace) +# + +# Add or remove braces on a single-line 'do' statement. +mod_full_brace_do = ignore # ignore/add/remove/force/not_defined + +# Add or remove braces on a single-line 'for' statement. +mod_full_brace_for = ignore # ignore/add/remove/force/not_defined + +# (Pawn) Add or remove braces on a single-line function definition. +mod_full_brace_function = ignore # ignore/add/remove/force/not_defined + +# Add or remove braces on a single-line 'if' statement. Braces will not be +# removed if the braced statement contains an 'else'. +mod_full_brace_if = ignore # ignore/add/remove/force/not_defined + +# Whether to enforce that all blocks of an 'if'/'else if'/'else' chain either +# have, or do not have, braces. Overrides mod_full_brace_if. +# +# 0: Don't override mod_full_brace_if +# 1: Add braces to all blocks if any block needs braces and remove braces if +# they can be removed from all blocks +# 2: Add braces to all blocks if any block already has braces, regardless of +# whether it needs them +# 3: Add braces to all blocks if any block needs braces and remove braces if +# they can be removed from all blocks, except if all blocks have braces +# despite none needing them +mod_full_brace_if_chain = 0 # unsigned number + +# Whether to add braces to all blocks of an 'if'/'else if'/'else' chain. +# If true, mod_full_brace_if_chain will only remove braces from an 'if' that +# does not have an 'else if' or 'else'. +mod_full_brace_if_chain_only = false # true/false + +# Add or remove braces on single-line 'while' statement. +mod_full_brace_while = ignore # ignore/add/remove/force/not_defined + +# Add or remove braces on single-line 'using ()' statement. +mod_full_brace_using = ignore # ignore/add/remove/force/not_defined + +# Don't remove braces around statements that span N newlines +mod_full_brace_nl = 0 # unsigned number + +# Whether to prevent removal of braces from 'if'/'for'/'while'/etc. blocks +# which span multiple lines. +# +# Affects: +# mod_full_brace_for +# mod_full_brace_if +# mod_full_brace_if_chain +# mod_full_brace_if_chain_only +# mod_full_brace_while +# mod_full_brace_using +# +# Does not affect: +# mod_full_brace_do +# mod_full_brace_function +mod_full_brace_nl_block_rem_mlcond = false # true/false + +# Add or remove unnecessary parentheses on 'return' statement. +mod_paren_on_return = ignore # ignore/add/remove/force/not_defined + +# Add or remove unnecessary parentheses on 'throw' statement. +mod_paren_on_throw = ignore # ignore/add/remove/force/not_defined + +# (Pawn) Whether to change optional semicolons to real semicolons. +mod_pawn_semicolon = false # true/false + +# Whether to fully parenthesize Boolean expressions in 'while' and 'if' +# statement, as in 'if (a && b > c)' => 'if (a && (b > c))'. +mod_full_paren_if_bool = false # true/false + +# Whether to fully parenthesize Boolean expressions after '=' +# statement, as in 'x = a && b > c;' => 'x = (a && (b > c));'. +mod_full_paren_assign_bool = false # true/false + +# Whether to fully parenthesize Boolean expressions after '=' +# statement, as in 'return a && b > c;' => 'return (a && (b > c));'. +mod_full_paren_return_bool = false # true/false + +# Whether to remove superfluous semicolons. +mod_remove_extra_semicolon = false # true/false + +# Whether to remove duplicate include. +mod_remove_duplicate_include = false # true/false + +# the following options (mod_XX_closebrace_comment) use different comment, +# depending of the setting of the next option. +# false: Use the c comment (default) +# true : Use the cpp comment +mod_add_force_c_closebrace_comment = false # true/false + +# If a function body exceeds the specified number of newlines and doesn't have +# a comment after the close brace, a comment will be added. +mod_add_long_function_closebrace_comment = 0 # unsigned number + +# If a namespace body exceeds the specified number of newlines and doesn't +# have a comment after the close brace, a comment will be added. +mod_add_long_namespace_closebrace_comment = 0 # unsigned number + +# If a class body exceeds the specified number of newlines and doesn't have a +# comment after the close brace, a comment will be added. +mod_add_long_class_closebrace_comment = 0 # unsigned number + +# If a switch body exceeds the specified number of newlines and doesn't have a +# comment after the close brace, a comment will be added. +mod_add_long_switch_closebrace_comment = 0 # unsigned number + +# If an #ifdef body exceeds the specified number of newlines and doesn't have +# a comment after the #endif, a comment will be added. +mod_add_long_ifdef_endif_comment = 0 # unsigned number + +# If an #ifdef or #else body exceeds the specified number of newlines and +# doesn't have a comment after the #else, a comment will be added. +mod_add_long_ifdef_else_comment = 0 # unsigned number + +# Whether to take care of the case by the mod_sort_xx options. +mod_sort_case_sensitive = false # true/false + +# Whether to sort consecutive single-line 'import' statements. +mod_sort_import = false # true/false + +# (C#) Whether to sort consecutive single-line 'using' statements. +mod_sort_using = false # true/false + +# Whether to sort consecutive single-line '#include' statements (C/C++) and +# '#import' statements (Objective-C). Be aware that this has the potential to +# break your code if your includes/imports have ordering dependencies. +mod_sort_include = false # true/false + +# Whether to prioritize '#include' and '#import' statements that contain +# filename without extension when sorting is enabled. +mod_sort_incl_import_prioritize_filename = false # true/false + +# Whether to prioritize '#include' and '#import' statements that does not +# contain extensions when sorting is enabled. +mod_sort_incl_import_prioritize_extensionless = false # true/false + +# Whether to prioritize '#include' and '#import' statements that contain +# angle over quotes when sorting is enabled. +mod_sort_incl_import_prioritize_angle_over_quotes = false # true/false + +# Whether to ignore file extension in '#include' and '#import' statements +# for sorting comparison. +mod_sort_incl_import_ignore_extension = false # true/false + +# Whether to group '#include' and '#import' statements when sorting is enabled. +mod_sort_incl_import_grouping_enabled = false # true/false + +# Whether to move a 'break' that appears after a fully braced 'case' before +# the close brace, as in 'case X: { ... } break;' => 'case X: { ... break; }'. +mod_move_case_break = false # true/false + +# Whether to move a 'return' that appears after a fully braced 'case' before +# the close brace, as in 'case X: { ... } return;' => 'case X: { ... return; }'. +mod_move_case_return = false # true/false + +# Add or remove braces around a fully braced case statement. Will only remove +# braces if there are no variable declarations in the block. +mod_case_brace = ignore # ignore/add/remove/force/not_defined + +# Whether to remove a void 'return;' that appears as the last statement in a +# function. +mod_remove_empty_return = false # true/false + +# Add or remove the comma after the last value of an enumeration. +mod_enum_last_comma = ignore # ignore/add/remove/force/not_defined + +# Syntax to use for infinite loops. +# +# 0: Leave syntax alone (default) +# 1: Rewrite as `for(;;)` +# 2: Rewrite as `while(true)` +# 3: Rewrite as `do`...`while(true);` +# 4: Rewrite as `while(1)` +# 5: Rewrite as `do`...`while(1);` +# +# Infinite loops that do not already match one of these syntaxes are ignored. +# Other options that affect loop formatting will be applied after transforming +# the syntax. +mod_infinite_loop = 0 # unsigned number + +# Add or remove the 'int' keyword in 'int short'. +mod_int_short = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'short int'. +mod_short_int = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'int long'. +mod_int_long = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'long int'. +mod_long_int = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'int signed'. +mod_int_signed = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'signed int'. +mod_signed_int = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'int unsigned'. +mod_int_unsigned = ignore # ignore/add/remove/force/not_defined + +# Add or remove the 'int' keyword in 'unsigned int'. +mod_unsigned_int = ignore # ignore/add/remove/force/not_defined + +# If there is a situation where mod_int_* and mod_*_int would result in +# multiple int keywords, whether to keep the rightmost int (the default) or the +# leftmost int. +mod_int_prefer_int_on_left = false # true/false + +# (OC) Whether to organize the properties. If true, properties will be +# rearranged according to the mod_sort_oc_property_*_weight factors. +mod_sort_oc_properties = false # true/false + +# (OC) Weight of a class property modifier. +mod_sort_oc_property_class_weight = 0 # number + +# (OC) Weight of 'atomic' and 'nonatomic'. +mod_sort_oc_property_thread_safe_weight = 0 # number + +# (OC) Weight of 'readwrite' when organizing properties. +mod_sort_oc_property_readwrite_weight = 0 # number + +# (OC) Weight of a reference type specifier ('retain', 'copy', 'assign', +# 'weak', 'strong') when organizing properties. +mod_sort_oc_property_reference_weight = 0 # number + +# (OC) Weight of getter type ('getter=') when organizing properties. +mod_sort_oc_property_getter_weight = 0 # number + +# (OC) Weight of setter type ('setter=') when organizing properties. +mod_sort_oc_property_setter_weight = 0 # number + +# (OC) Weight of nullability type ('nullable', 'nonnull', 'null_unspecified', +# 'null_resettable') when organizing properties. +mod_sort_oc_property_nullability_weight = 0 # number + +# +# Preprocessor options +# + +# How to use tabs when indenting preprocessor code. +# +# -1: Use 'indent_with_tabs' setting (default) +# 0: Spaces only +# 1: Indent with tabs to brace level, align with spaces +# 2: Indent and align with tabs, using spaces when not on a tabstop +# +# Default: -1 +pp_indent_with_tabs = -1 # number + +# Add or remove indentation of preprocessor directives inside #if blocks +# at brace level 0 (file-level). +pp_indent = ignore # ignore/add/remove/force/not_defined + +# Whether to indent #if/#else/#endif at the brace level. If false, these are +# indented from column 1. +pp_indent_at_level = false # true/false + +# Whether to indent #if/#else/#endif at the parenthesis level if the brace +# level is 0. If false, these are indented from column 1. +pp_indent_at_level0 = false # true/false + +# Specifies the number of columns to indent preprocessors per level +# at brace level 0 (file-level). If pp_indent_at_level=false, also specifies +# the number of columns to indent preprocessors per level +# at brace level > 0 (function-level). +# +# Default: 1 +pp_indent_count = 1 # unsigned number + +# Add or remove space after # based on pp level of #if blocks. +pp_space_after = ignore # ignore/add/remove/force/not_defined + +# Sets the number of spaces per level added with pp_space_after. +pp_space_count = 0 # unsigned number + +# The indent for '#region' and '#endregion' in C# and '#pragma region' in +# C/C++. Negative values decrease indent down to the first column. +pp_indent_region = 0 # number + +# Whether to indent the code between #region and #endregion. +pp_region_indent_code = false # true/false + +# If pp_indent_at_level=true, sets the indent for #if, #else and #endif when +# not at file-level. Negative values decrease indent down to the first column. +# +# =0: Indent preprocessors using output_tab_size +# >0: Column at which all preprocessors will be indented +pp_indent_if = 0 # number + +# Whether to indent the code between #if, #else and #endif. +pp_if_indent_code = false # true/false + +# Whether to indent the body of an #if that encompasses all the code in the file. +pp_indent_in_guard = false # true/false + +# Whether to indent '#define' at the brace level. If false, these are +# indented from column 1. +pp_define_at_level = false # true/false + +# Whether to indent '#include' at the brace level. +pp_include_at_level = false # true/false + +# Whether to ignore the '#define' body while formatting. +pp_ignore_define_body = true # true/false + +# An offset value that controls the indentation of the body of a multiline #define. +# 'body' refers to all the lines of a multiline #define except the first line. +# Requires 'pp_ignore_define_body = false'. +# +# <0: Absolute column: the body indentation starts off at the specified column +# (ex. -3 ==> the body is indented starting from column 3) +# >=0: Relative to the column of the '#' of '#define' +# (ex. 3 ==> the body is indented starting 3 columns at the right of '#') +# +# Default: 8 +pp_multiline_define_body_indent = 4 # number + +# Whether to indent case statements between #if, #else, and #endif. +# Only applies to the indent of the preprocessor that the case statements +# directly inside of. +# +# Default: true +pp_indent_case = true # true/false + +# Whether to indent whole function definitions between #if, #else, and #endif. +# Only applies to the indent of the preprocessor that the function definition +# is directly inside of. +# +# Default: true +pp_indent_func_def = true # true/false + +# Whether to indent extern C blocks between #if, #else, and #endif. +# Only applies to the indent of the preprocessor that the extern block is +# directly inside of. +# +# Default: true +pp_indent_extern = true # true/false + +# How to indent braces directly inside #if, #else, and #endif. +# Requires pp_if_indent_code=true and only applies to the indent of the +# preprocessor that the braces are directly inside of. +# 0: No extra indent +# 1: Indent by one level +# -1: Preserve original indentation +# +# Default: 1 +pp_indent_brace = 1 # number + +# Whether to print warning messages for unbalanced #if and #else blocks. +# This will print a message in the following cases: +# - if an #ifdef block ends on a different indent level than +# where it started from. Example: +# +# #ifdef TEST +# int i; +# { +# int j; +# #endif +# +# - an #elif/#else block ends on a different indent level than +# the corresponding #ifdef block. Example: +# +# #ifdef TEST +# int i; +# #else +# } +# int j; +# #endif +pp_warn_unbalanced_if = false # true/false + +# +# Sort includes options +# + +# The regex for include category with priority 0. +include_category_0 = "" # string + +# The regex for include category with priority 1. +include_category_1 = "" # string + +# The regex for include category with priority 2. +include_category_2 = "" # string + +# +# Use or Do not Use options +# + +# true: indent_func_call_param will be used (default) +# false: indent_func_call_param will NOT be used +# +# Default: true +use_indent_func_call_param = true # true/false + +# The value of the indentation for a continuation line is calculated +# differently if the statement is: +# - a declaration: your case with QString fileName ... +# - an assignment: your case with pSettings = new QSettings( ... +# +# At the second case the indentation value might be used twice: +# - at the assignment +# - at the function call (if present) +# +# To prevent the double use of the indentation value, use this option with the +# value 'true'. +# +# true: indent_continue will be used only once +# false: indent_continue will be used every time (default) +# +# Requires indent_ignore_first_continue=false. +use_indent_continue_only_once = false # true/false + +# The indentation can be: +# - after the assignment, at the '[' character +# - at the beginning of the lambda body +# +# true: indentation will be at the beginning of the lambda body +# false: indentation will be after the assignment (default) +indent_cpp_lambda_only_once = false # true/false + +# Whether sp_after_angle takes precedence over sp_inside_fparen. This was the +# historic behavior, but is probably not the desired behavior, so this is off +# by default. +use_sp_after_angle_always = false # true/false + +# Whether to apply special formatting for Qt SIGNAL/SLOT macros. Essentially, +# this tries to format these so that they match Qt's normalized form (i.e. the +# result of QMetaObject::normalizedSignature), which can slightly improve the +# performance of the QObject::connect call, rather than how they would +# otherwise be formatted. +# +# See options_for_QT.cpp for details. +# +# Default: true +use_options_overriding_for_qt_macros = true # true/false + +# If true: the form feed character is removed from the list of whitespace +# characters. See https://en.cppreference.com/w/cpp/string/byte/isspace. +use_form_feed_no_more_as_whitespace_character = false # true/false + +# +# Warn levels - 1: error, 2: warning (default), 3: note +# + +# (C#) Warning is given if doing tab-to-\t replacement and we have found one +# in a C# verbatim string literal. +# +# Default: 2 +warn_level_tabs_found_in_verbatim_string_literals = 2 # unsigned number + +# Limit the number of loops. +# Used by uncrustify.cpp to exit from infinite loop. +# 0: no limit. +debug_max_number_of_loops = 0 # number + +# Set the number of the line to protocol; +# Used in the function prot_the_line if the 2. parameter is zero. +# 0: nothing protocol. +debug_line_number_to_protocol = 0 # number + +# Set the number of second(s) before terminating formatting the current file, +# 0: no timeout. +# only for linux +debug_timeout = 0 # number + +# Set the number of characters to be printed if the text is too long, +# 0: do not truncate. +debug_truncate = 0 # unsigned number + +# sort (or not) the tracking info. +# +# Default: true +debug_sort_the_tracks = true # true/false + +# decode (or not) the flags as a new line. +# only if the -p option is set. +debug_decode_the_flags = false # true/false + +# use (or not) the exit(EX_SOFTWARE) function. +# +# Default: true +debug_use_the_exit_function_pop = true # true/false + +# insert the number of the line at the beginning of each line +set_numbering_for_html_output = false # true/false + +# Meaning of the settings: +# Ignore - do not do any changes +# Add - makes sure there is 1 or more space/brace/newline/etc +# Force - makes sure there is exactly 1 space/brace/newline/etc, +# behaves like Add in some contexts +# Remove - removes space/brace/newline/etc +# +# +# - Token(s) can be treated as specific type(s) with the 'set' option: +# `set tokenType tokenString [tokenString...]` +# +# Example: +# `set BOOL __AND__ __OR__` +# +# tokenTypes are defined in src/token_enum.h, use them without the +# 'CT_' prefix: 'CT_BOOL' => 'BOOL' +# +# +# - Token(s) can be treated as type(s) with the 'type' option. +# `type tokenString [tokenString...]` +# +# Example: +# `type int c_uint_8 Rectangle` +# +# This can also be achieved with `set TYPE int c_uint_8 Rectangle` +# +# +# To embed whitespace in tokenStrings use the '\' escape character, or quote +# the tokenStrings. These quotes are supported: "'` +# +# +# - Support for the auto detection of languages through the file ending can be +# added using the 'file_ext' command. +# `file_ext langType langString [langString..]` +# +# Example: +# `file_ext CPP .ch .cxx .cpp.in` # -# You can create custom macro-based indentation using macro-open, -# macro-else and macro-close. -# Example: -# macro-open BEGIN_TEMPLATE_MESSAGE_MAP -# macro-open BEGIN_MESSAGE_MAP -# macro-close END_MESSAGE_MAP +# langTypes are defined in uncrusify_types.h in the lang_flag_e enum, use +# them without the 'LANG_' prefix: 'LANG_CPP' => 'CPP' # -# You can assign any keyword to any type with the set option. -# set func_call_user _ N_ # -# The full syntax description of all custom definition config entries -# is shown below: +# - Custom macro-based indentation can be set up using 'macro-open', +# 'macro-else' and 'macro-close'. +# `(macro-open | macro-else | macro-close) tokenString` # -# define custom tokens as: -# - embed whitespace in token using '' escape character, or -# put token in quotes -# - these: ' " and ` are recognized as quote delimiters +# Example: +# `macro-open BEGIN_TEMPLATE_MESSAGE_MAP` +# `macro-open BEGIN_MESSAGE_MAP` +# `macro-close END_MESSAGE_MAP` # -# type token1 token2 token3 ... -# ^ optionally specify multiple tokens on a single line -# define def_token output_token -# ^ output_token is optional, then NULL is assumed -# macro-open token -# macro-close token -# macro-else token -# set id token1 token2 ... -# ^ optionally specify multiple tokens on a single line -# ^ id is one of the names in token_enum.h sans the CT_ prefix, -# e.g. PP_PRAGMA # -# all tokens are separated by any mix of ',' commas, '=' equal signs -# and whitespace (space, tab) +set IF IF_APPNAME +# option(s) with 'not default' value: 55 # -set IF IF_APPNAME From 5eff6f31e4d195a1c1c7e8143393e8c1e89afc92 Mon Sep 17 00:00:00 2001 From: scribam Date: Fri, 29 May 2026 16:32:58 +0200 Subject: [PATCH 2/2] Normalize EOL and header guard names --- include/arch/pico_cortex_m.h | 7 +++---- include/arch/pico_esp8266.h | 4 ++-- include/arch/pico_generic_gcc.h | 9 ++++----- include/arch/pico_msp430.h | 4 ++-- include/arch/pico_none.h | 1 - include/arch/pico_pic32.h | 7 +++---- include/arch/pico_posix.h | 1 - include/pico_socket.h | 1 - modules/pico_arp.c | 1 - modules/pico_dev_ipc.h | 1 - modules/pico_dev_loop.c | 1 - modules/pico_dev_loop.h | 1 - modules/pico_dev_null.c | 1 - modules/pico_dev_null.h | 1 - modules/pico_dev_pcap.h | 1 - modules/pico_dev_radiotest.c | 1 - modules/pico_dev_tap.c | 1 - modules/pico_dev_tap.h | 1 - modules/pico_dev_tap_windows.h | 1 - modules/pico_dev_tun.c | 1 - modules/pico_dev_tun.h | 1 - modules/pico_dev_vde.c | 1 - modules/pico_dev_vde.h | 1 - modules/pico_dhcp_server.h | 2 +- modules/pico_dns_client.c | 1 - modules/pico_dns_client.h | 2 +- modules/pico_dns_common.h | 2 +- modules/pico_dns_sd.h | 4 +--- modules/pico_ethernet.c | 2 -- modules/pico_hotplug_detection.c | 1 - modules/pico_hotplug_detection.h | 3 +-- modules/pico_icmp6.h | 4 ++-- modules/pico_igmp.h | 3 ++- modules/pico_ipfilter.c | 1 - modules/pico_ipfilter.h | 3 +-- modules/pico_ipv4.h | 4 +--- modules/pico_ipv6.c | 2 -- modules/pico_ipv6.h | 4 ++-- modules/pico_ipv6_nd.h | 4 ++-- modules/pico_ipv6_pmtu.h | 4 ++-- modules/pico_mdns.h | 2 +- modules/pico_mld.h | 3 ++- modules/pico_mm.c | 1 - modules/pico_mm.h | 6 +++--- modules/pico_nat.h | 3 +-- modules/pico_slaacv4.h | 3 +-- modules/pico_sntp_client.h | 2 +- modules/pico_socket_ll.h | 2 -- modules/pico_socket_tcp.h | 1 - modules/pico_socket_udp.c | 1 - modules/pico_socket_udp.h | 1 - modules/pico_udp.c | 1 - stack/pico_frame.c | 1 - stack/pico_protocol.c | 1 - stack/pico_socket_multicast.c | 1 - test/examples/iperfc.c | 1 - test/examples/ping.c | 1 - test/pico_faulty.h | 1 - test/unit/modunit_pico_dns_common.c | 1 - test/unit/modunit_pico_mdns.c | 1 - test/unit/modunit_seq.c | 1 - 61 files changed, 40 insertions(+), 90 deletions(-) diff --git a/include/arch/pico_cortex_m.h b/include/arch/pico_cortex_m.h index de3f475b..d801b9f4 100644 --- a/include/arch/pico_cortex_m.h +++ b/include/arch/pico_cortex_m.h @@ -3,10 +3,9 @@ See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_CORTEX_M -#define _INCLUDE_PICO_CORTEX_M +#ifndef INCLUDE_PICO_CORTEX_M +#define INCLUDE_PICO_CORTEX_M #include "pico_generic_gcc.h" -#endif /* PICO_CORTEX_M */ - +#endif /* INCLUDE_PICO_CORTEX_M */ diff --git a/include/arch/pico_esp8266.h b/include/arch/pico_esp8266.h index e07478e5..29588bf8 100644 --- a/include/arch/pico_esp8266.h +++ b/include/arch/pico_esp8266.h @@ -3,8 +3,8 @@ See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_ESP8266 -#define _INCLUDE_PICO_ESP8266 +#ifndef INCLUDE_PICO_ESP8266 +#define INCLUDE_PICO_ESP8266 #include diff --git a/include/arch/pico_generic_gcc.h b/include/arch/pico_generic_gcc.h index 6a295011..7d2ba2ca 100644 --- a/include/arch/pico_generic_gcc.h +++ b/include/arch/pico_generic_gcc.h @@ -3,8 +3,8 @@ See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_GCC -#define _INCLUDE_PICO_GCC +#ifndef INCLUDE_PICO_GCC +#define INCLUDE_PICO_GCC #include #include @@ -111,7 +111,6 @@ static inline void PICO_IDLE(void) while (now == pico_ms_tick); } -#endif /* IFNDEF RTOS */ - -#endif /* PICO_GCC */ +#endif /* PICO_SUPPORT_RTOS */ +#endif /* INCLUDE_PICO_GCC */ diff --git a/include/arch/pico_msp430.h b/include/arch/pico_msp430.h index b6cc7ab6..25c1ea4c 100644 --- a/include/arch/pico_msp430.h +++ b/include/arch/pico_msp430.h @@ -3,8 +3,8 @@ See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_LPC -#define _INCLUDE_PICO_LPC +#ifndef INCLUDE_PICO_LPC +#define INCLUDE_PICO_LPC #include #include diff --git a/include/arch/pico_none.h b/include/arch/pico_none.h index b4a35995..dc8dcfa8 100644 --- a/include/arch/pico_none.h +++ b/include/arch/pico_none.h @@ -19,4 +19,3 @@ #define PICO_IDLE() do {} while(0) #endif /* PICO_SUPPORT_ARCHNONE */ - diff --git a/include/arch/pico_pic32.h b/include/arch/pico_pic32.h index 227c306f..7f14430f 100644 --- a/include/arch/pico_pic32.h +++ b/include/arch/pico_pic32.h @@ -4,8 +4,8 @@ See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage. *********************************************************************/ -#ifndef _INCLUDE_PICO_PIC32 -#define _INCLUDE_PICO_PIC32 +#ifndef INCLUDE_PICO_PIC32 +#define INCLUDE_PICO_PIC32 #include #include @@ -50,5 +50,4 @@ static inline void PICO_IDLE(void) while (now == pico_ms_tick); } -#endif /* PICO_PIC32 */ - +#endif /* INCLUDE_PICO_PIC32 */ diff --git a/include/arch/pico_posix.h b/include/arch/pico_posix.h index dfe561e0..f24363a6 100644 --- a/include/arch/pico_posix.h +++ b/include/arch/pico_posix.h @@ -140,4 +140,3 @@ static inline void PICO_IDLE(void) } #endif /* PICO_SUPPORT_POSIX */ - diff --git a/include/pico_socket.h b/include/pico_socket.h index 1452d24b..1bd7a1f8 100644 --- a/include/pico_socket.h +++ b/include/pico_socket.h @@ -303,5 +303,4 @@ void pico_socket_destroy_all(struct pico_stack *S); #define PICO_SOCKET_SETOPT_DIS(socket, index) (socket->opt_flags &= (uint16_t) ~(1 << index)) #define PICO_SOCKET_GETOPT(socket, index) ((socket->opt_flags & (1u << index)) != 0) - #endif diff --git a/modules/pico_arp.c b/modules/pico_arp.c index b0a9ff99..7ba122c8 100644 --- a/modules/pico_arp.c +++ b/modules/pico_arp.c @@ -545,4 +545,3 @@ void pico_arp_register_ipconflict(struct pico_stack *S, struct pico_ip4 *ip, str if (mac != NULL) memcpy(S->conflict_ipv4.mac.addr, mac, 6); } - diff --git a/modules/pico_dev_ipc.h b/modules/pico_dev_ipc.h index 4dcb40fa..d6c0c8ea 100644 --- a/modules/pico_dev_ipc.h +++ b/modules/pico_dev_ipc.h @@ -33,4 +33,3 @@ void pico_ipc_destroy(struct pico_device *ipc); struct pico_device *pico_ipc_create(struct pico_stack *S, const char *sock_path, const char *name, const uint8_t *mac); #endif - diff --git a/modules/pico_dev_loop.c b/modules/pico_dev_loop.c index 54fcefae..29114985 100644 --- a/modules/pico_dev_loop.c +++ b/modules/pico_dev_loop.c @@ -82,4 +82,3 @@ struct pico_device *pico_loop_create(struct pico_stack *S) dbg("Device %s created.\n", loop->name); return loop; } - diff --git a/modules/pico_dev_loop.h b/modules/pico_dev_loop.h index 43611db9..a9527385 100644 --- a/modules/pico_dev_loop.h +++ b/modules/pico_dev_loop.h @@ -33,4 +33,3 @@ void pico_loop_destroy(struct pico_device *loop); struct pico_device *pico_loop_create(struct pico_stack *S); #endif - diff --git a/modules/pico_dev_null.c b/modules/pico_dev_null.c index cc854854..b237cb34 100644 --- a/modules/pico_dev_null.c +++ b/modules/pico_dev_null.c @@ -76,4 +76,3 @@ struct pico_device *pico_null_create(struct pico_stack *S, const char *name) dbg("Device %s created.\n", null->dev.name); return (struct pico_device *)null; } - diff --git a/modules/pico_dev_null.h b/modules/pico_dev_null.h index f8e8f561..f1bb197b 100644 --- a/modules/pico_dev_null.h +++ b/modules/pico_dev_null.h @@ -33,4 +33,3 @@ void pico_null_destroy(struct pico_device *null); struct pico_device *pico_null_create(struct pico_stack *S, const char *name); #endif - diff --git a/modules/pico_dev_pcap.h b/modules/pico_dev_pcap.h index e7af23bb..63e5d093 100644 --- a/modules/pico_dev_pcap.h +++ b/modules/pico_dev_pcap.h @@ -16,4 +16,3 @@ struct pico_device *pico_pcap_create_live(struct pico_stack *S, char *ifname, ch struct pico_device *pico_pcap_create_fromfile(struct pico_stack *S, char *filename, char *name, uint8_t *mac); #endif - diff --git a/modules/pico_dev_radiotest.c b/modules/pico_dev_radiotest.c index bf399413..2e2554a0 100644 --- a/modules/pico_dev_radiotest.c +++ b/modules/pico_dev_radiotest.c @@ -510,4 +510,3 @@ struct pico_device *pico_radiotest_create(struct pico_stack *S, uint8_t addr, ui return (struct pico_device *)lp; } - diff --git a/modules/pico_dev_tap.c b/modules/pico_dev_tap.c index 2335d513..d26d20f7 100644 --- a/modules/pico_dev_tap.c +++ b/modules/pico_dev_tap.c @@ -278,4 +278,3 @@ struct pico_device *pico_tap_create(struct pico_stack *S, char *name) dbg("Device %s created.\n", tap->dev.name); return (struct pico_device *)tap; } - diff --git a/modules/pico_dev_tap.h b/modules/pico_dev_tap.h index 65af9eab..8a6a7440 100644 --- a/modules/pico_dev_tap.h +++ b/modules/pico_dev_tap.h @@ -35,4 +35,3 @@ int pico_tap_WFI(struct pico_device *dev, int timeout_ms); void pico_tap_dsr(void *arg); #endif - diff --git a/modules/pico_dev_tap_windows.h b/modules/pico_dev_tap_windows.h index 87e6e12b..4da285a1 100644 --- a/modules/pico_dev_tap_windows.h +++ b/modules/pico_dev_tap_windows.h @@ -35,4 +35,3 @@ struct pico_device *pico_tap_create(struct pico_stack *S, char *name, uint8_t *m /* void pico_tap_destroy(struct pico_device *null); */ #endif - diff --git a/modules/pico_dev_tun.c b/modules/pico_dev_tun.c index ed0533ab..4900e167 100644 --- a/modules/pico_dev_tun.c +++ b/modules/pico_dev_tun.c @@ -126,4 +126,3 @@ struct pico_device *pico_tun_create(struct pico_stack *S, char *name) dbg("Device %s created.\n", tun->dev.name); return (struct pico_device *)tun; } - diff --git a/modules/pico_dev_tun.h b/modules/pico_dev_tun.h index 7cb64196..5cab7873 100644 --- a/modules/pico_dev_tun.h +++ b/modules/pico_dev_tun.h @@ -33,4 +33,3 @@ void pico_tun_destroy(struct pico_device *tun); struct pico_device *pico_tun_create(struct pico_stack *S, char *name); #endif - diff --git a/modules/pico_dev_vde.c b/modules/pico_dev_vde.c index df55a053..8a16ef78 100644 --- a/modules/pico_dev_vde.c +++ b/modules/pico_dev_vde.c @@ -165,4 +165,3 @@ struct pico_device *MOCKABLE pico_vde_create(struct pico_stack *S, char *sock, c dbg("Device %s created.\n", vde->dev.name); return (struct pico_device *)vde; } - diff --git a/modules/pico_dev_vde.h b/modules/pico_dev_vde.h index 95a64915..0f8bf2ff 100644 --- a/modules/pico_dev_vde.h +++ b/modules/pico_dev_vde.h @@ -40,4 +40,3 @@ void pico_vde_dsr(void *arg); #endif #endif - diff --git a/modules/pico_dhcp_server.h b/modules/pico_dhcp_server.h index 1e7e6468..7feff519 100644 --- a/modules/pico_dhcp_server.h +++ b/modules/pico_dhcp_server.h @@ -53,5 +53,5 @@ int pico_dhcp_server_initiate(struct pico_dhcp_server_setting *setting); /* To destroy an existing DHCP server configuration, running on a given interface */ int pico_dhcp_server_destroy(struct pico_device *dev); -#endif /* _INCLUDE_PICO_DHCP_SERVER */ #endif +#endif /* INCLUDE_PICO_DHCP_SERVER */ diff --git a/modules/pico_dns_client.c b/modules/pico_dns_client.c index dcd7b02f..5e518ade 100644 --- a/modules/pico_dns_client.c +++ b/modules/pico_dns_client.c @@ -870,4 +870,3 @@ int pico_dns_client_init(struct pico_stack *S) #endif /* PICO_SUPPORT_DNS_CLIENT */ - diff --git a/modules/pico_dns_client.h b/modules/pico_dns_client.h index 5918bc60..eff7ae6b 100644 --- a/modules/pico_dns_client.h +++ b/modules/pico_dns_client.h @@ -66,4 +66,4 @@ int pico_dns_client_getaddr6(struct pico_stack *S, const char *url, void (*callb int pico_dns_client_getname6(struct pico_stack *S, const char *ip, void (*callback)(char *, void *), void *arg); #endif -#endif /* _INCLUDE_PICO_DNS_CLIENT */ +#endif /* INCLUDE_PICO_DNS_CLIENT */ diff --git a/modules/pico_dns_common.h b/modules/pico_dns_common.h index 62932761..0ad4c616 100644 --- a/modules/pico_dns_common.h +++ b/modules/pico_dns_common.h @@ -547,4 +547,4 @@ pico_dns_answer_create(struct pico_tree *antree, struct pico_tree *artree, uint16_t *len); -#endif /* _INCLUDE_PICO_DNS_COMMON */ +#endif /* INCLUDE_PICO_DNS_COMMON */ diff --git a/modules/pico_dns_sd.h b/modules/pico_dns_sd.h index 4355bcbd..cb01b55d 100644 --- a/modules/pico_dns_sd.h +++ b/modules/pico_dns_sd.h @@ -107,6 +107,4 @@ pico_dns_sd_browse_service(const char *type, int pico_dns_sd_kv_vector_add(kv_vector *vector, char *key, char *value); - -#endif /* _INCLUDE_PICO_DNS_SD */ - +#endif /* INCLUDE_PICO_DNS_SD */ diff --git a/modules/pico_ethernet.c b/modules/pico_ethernet.c index d59ecb87..584b4f8b 100644 --- a/modules/pico_ethernet.c +++ b/modules/pico_ethernet.c @@ -449,5 +449,3 @@ int32_t MOCKABLE pico_ethernet_send(struct pico_stack *S, struct pico_frame *f) } #endif /* PICO_SUPPORT_ETH */ - - diff --git a/modules/pico_hotplug_detection.c b/modules/pico_hotplug_detection.c index f98dd9c1..41e60683 100644 --- a/modules/pico_hotplug_detection.c +++ b/modules/pico_hotplug_detection.c @@ -196,4 +196,3 @@ int pico_hotplug_deregister(struct pico_device *dev, void (*cb)(struct pico_devi return 0; } - diff --git a/modules/pico_hotplug_detection.h b/modules/pico_hotplug_detection.h index 0e8ad1d2..deba3e8e 100644 --- a/modules/pico_hotplug_detection.h +++ b/modules/pico_hotplug_detection.h @@ -40,5 +40,4 @@ int pico_hotplug_dev_cmp(void *ka, void *kb); int pico_hotplug_register(struct pico_device *dev, void (*cb)(struct pico_device *dev, int event)); int pico_hotplug_deregister(struct pico_device *dev, void (*cb)(struct pico_device *dev, int event)); -#endif /* _INCLUDE_PICO_SUPPORT_HOTPLUG */ - +#endif /* INCLUDE_PICO_SUPPORT_HOTPLUG */ diff --git a/modules/pico_icmp6.h b/modules/pico_icmp6.h index 2f569ad6..885f3d56 100644 --- a/modules/pico_icmp6.h +++ b/modules/pico_icmp6.h @@ -24,8 +24,8 @@ * * *********************************************************************/ -#ifndef _INCLUDE_PICO_ICMP6 -#define _INCLUDE_PICO_ICMP6 +#ifndef INCLUDE_PICO_ICMP6 +#define INCLUDE_PICO_ICMP6 #include "pico_addressing.h" #include "pico_protocol.h" #include "pico_mld.h" diff --git a/modules/pico_igmp.h b/modules/pico_igmp.h index 3da6c8f0..1c110717 100644 --- a/modules/pico_igmp.h +++ b/modules/pico_igmp.h @@ -45,4 +45,5 @@ int igmp_parameters_cmp(void *ka, void *kb); int igmp_sources_cmp(void *ka, void *kb); int pico_igmp_state_change(struct pico_stack *S, struct pico_ip4 *mcast_link, struct pico_ip4 *mcast_group, uint8_t filter_mode, struct pico_tree *_MCASTFilter, uint8_t state); -#endif /* _INCLUDE_PICO_IGMP */ + +#endif /* INCLUDE_PICO_IGMP */ diff --git a/modules/pico_ipfilter.c b/modules/pico_ipfilter.c index 42b0d7a4..bd5a68dd 100644 --- a/modules/pico_ipfilter.c +++ b/modules/pico_ipfilter.c @@ -473,4 +473,3 @@ int ipfilter(struct pico_frame *f) temp.tos = ipv4_hdr->tos; return ipfilter_apply_filter(f, &temp); } - diff --git a/modules/pico_ipfilter.h b/modules/pico_ipfilter.h index aba83467..4abfb8ac 100644 --- a/modules/pico_ipfilter.h +++ b/modules/pico_ipfilter.h @@ -46,5 +46,4 @@ int pico_ipv4_filter_del(struct pico_stack *S, uint32_t filter_id); int ipfilter(struct pico_frame *f); int filter_compare(void *filterA, void *filterB); -#endif /* _INCLUDE_PICO_IPFILTER */ - +#endif /* INCLUDE_PICO_IPFILTER */ diff --git a/modules/pico_ipv4.h b/modules/pico_ipv4.h index 7933f16e..2ccf9bad 100644 --- a/modules/pico_ipv4.h +++ b/modules/pico_ipv4.h @@ -167,6 +167,4 @@ int pico_getsockopt_ipv4(struct pico_socket *s, int option, void *value); int pico_socket_ipv4_close(struct pico_socket *arg); int ipv4_route_compare(void *ka, void *kb); - - -#endif /* _INCLUDE_PICO_IPV4 */ +#endif /* INCLUDE_PICO_IPV4 */ diff --git a/modules/pico_ipv6.c b/modules/pico_ipv6.c index 992708e1..8a4c9caa 100644 --- a/modules/pico_ipv6.c +++ b/modules/pico_ipv6.c @@ -2229,6 +2229,4 @@ void pico_ipv6_unreachable(struct pico_stack *S, struct pico_frame *f, uint8_t c #endif } - - #endif diff --git a/modules/pico_ipv6.h b/modules/pico_ipv6.h index 3967227a..4645c356 100644 --- a/modules/pico_ipv6.h +++ b/modules/pico_ipv6.h @@ -24,8 +24,8 @@ * * *********************************************************************/ -#ifndef _INCLUDE_PICO_IPV6 -#define _INCLUDE_PICO_IPV6 +#ifndef INCLUDE_PICO_IPV6 +#define INCLUDE_PICO_IPV6 #include "pico_addressing.h" #include "pico_protocol.h" #include "pico_ipv4.h" diff --git a/modules/pico_ipv6_nd.h b/modules/pico_ipv6_nd.h index 215c95e2..66e5a580 100644 --- a/modules/pico_ipv6_nd.h +++ b/modules/pico_ipv6_nd.h @@ -24,8 +24,8 @@ * * *********************************************************************/ -#ifndef _INCLUDE_PICO_ND -#define _INCLUDE_PICO_ND +#ifndef INCLUDE_PICO_ND +#define INCLUDE_PICO_ND #include "pico_frame.h" #include "pico_ipv6.h" diff --git a/modules/pico_ipv6_pmtu.h b/modules/pico_ipv6_pmtu.h index 6a0f9798..3cc9e21a 100644 --- a/modules/pico_ipv6_pmtu.h +++ b/modules/pico_ipv6_pmtu.h @@ -24,8 +24,8 @@ * * *********************************************************************/ -#ifndef _INCLUDE_PICO_IPV6_PMTU -#define _INCLUDE_PICO_IPV6_PMTU +#ifndef INCLUDE_PICO_IPV6_PMTU +#define INCLUDE_PICO_IPV6_PMTU #include "pico_addressing.h" #include "pico_stack.h" diff --git a/modules/pico_mdns.h b/modules/pico_mdns.h index e161ce8a..71aa6bf1 100644 --- a/modules/pico_mdns.h +++ b/modules/pico_mdns.h @@ -230,4 +230,4 @@ pico_mdns_init(struct pico_stack *S, int pico_mdns_cookie_cmp(void *ka, void *kb); int pico_mdns_record_cmp_name_type(void *a, void *b); -#endif /* _INCLUDE_PICO_MDNS */ +#endif /* INCLUDE_PICO_MDNS */ diff --git a/modules/pico_mld.h b/modules/pico_mld.h index b1541dac..3aa304fd 100644 --- a/modules/pico_mld.h +++ b/modules/pico_mld.h @@ -140,4 +140,5 @@ int mcast_parameters_cmp(void *ka, void *kb); uint16_t pico_mld_checksum(struct pico_frame *f); int pico_mld_process_in(struct pico_stack *S, struct pico_frame *f); int pico_mld_state_change(struct pico_stack *S, struct pico_ip6 *mcast_link, struct pico_ip6 *mcast_group, uint8_t filter_mode, struct pico_tree *_MCASTFilter, uint8_t state); -#endif /* _INCLUDE_PICO_MLD */ + +#endif /* INCLUDE_PICO_MLD */ diff --git a/modules/pico_mm.c b/modules/pico_mm.c index ce1e86c8..cf4ea0bf 100644 --- a/modules/pico_mm.c +++ b/modules/pico_mm.c @@ -1474,4 +1474,3 @@ struct pico_mem_manager*pico_mem_profile_manager() return manager; } #endif /* PICO_SUPPORT_MM_PROFILING */ - diff --git a/modules/pico_mm.h b/modules/pico_mm.h index 25710a04..2f472576 100644 --- a/modules/pico_mm.h +++ b/modules/pico_mm.h @@ -26,8 +26,8 @@ *********************************************************************/ -#ifndef _INCLUDE_PICO_MM -#define _INCLUDE_PICO_MM +#ifndef INCLUDE_PICO_MM +#define INCLUDE_PICO_MM #include "pico_config.h" @@ -115,4 +115,4 @@ void*pico_mem_profile_manager(void); void pico_mem_init_profiling(void*manager, uint32_t memsize); #endif /* PICO_SUPPORT_MM_PROFILING */ -#endif /* _INCLUDE_PICO_MM */ +#endif /* INCLUDE_PICO_MM */ diff --git a/modules/pico_nat.h b/modules/pico_nat.h index aa99734e..e25d032f 100644 --- a/modules/pico_nat.h +++ b/modules/pico_nat.h @@ -106,5 +106,4 @@ static inline int pico_ipv4_port_forward(struct pico_ip4 nat_addr, uint16_t nat_ } #endif -#endif /* _INCLUDE_PICO_NAT */ - +#endif /* INCLUDE_PICO_NAT */ diff --git a/modules/pico_slaacv4.h b/modules/pico_slaacv4.h index 3e2c60e2..fb0542ef 100644 --- a/modules/pico_slaacv4.h +++ b/modules/pico_slaacv4.h @@ -34,5 +34,4 @@ int pico_slaacv4_claimip(struct pico_device *dev, void (*cb)(struct pico_ip4 *ip, uint8_t code)); void pico_slaacv4_unregisterip(void); -#endif /* _INCLUDE_PICO_SUPPORT_SLAACV4 */ - +#endif /* INCLUDE_PICO_SUPPORT_SLAACV4 */ diff --git a/modules/pico_sntp_client.h b/modules/pico_sntp_client.h index f5cf8368..119f8864 100644 --- a/modules/pico_sntp_client.h +++ b/modules/pico_sntp_client.h @@ -40,4 +40,4 @@ int pico_sntp_sync(struct pico_stack *S, const char *sntp_server, void (*cb_sync int pico_sntp_sync_ip(struct pico_stack *S, union pico_address *sntp_addr, void (*cb_synced)(pico_err_t status)); int pico_sntp_gettimeofday(struct pico_stack *S, struct pico_timeval *tv); -#endif /* _INCLUDE_PICO_SNTP_CLIENT */ +#endif /* INCLUDE_PICO_SNTP_CLIENT */ diff --git a/modules/pico_socket_ll.h b/modules/pico_socket_ll.h index 7f8cf25b..30fe60bb 100644 --- a/modules/pico_socket_ll.h +++ b/modules/pico_socket_ll.h @@ -54,6 +54,4 @@ int pico_setsockopt_ll(struct pico_socket *s, int option, void *value); int pico_getsockopt_ll(struct pico_socket *s, int option, void *value); int pico_socket_ll_close(struct pico_socket *arg); - - #endif /* INCLUDE_PICO_SOCKET_LL */ diff --git a/modules/pico_socket_tcp.h b/modules/pico_socket_tcp.h index f748d9a2..6d9c0364 100644 --- a/modules/pico_socket_tcp.h +++ b/modules/pico_socket_tcp.h @@ -55,5 +55,4 @@ void transport_flags_update(struct pico_frame *, struct pico_socket *); #endif - #endif diff --git a/modules/pico_socket_udp.c b/modules/pico_socket_udp.c index c7161577..b1228822 100644 --- a/modules/pico_socket_udp.c +++ b/modules/pico_socket_udp.c @@ -274,4 +274,3 @@ int pico_getsockopt_udp(struct pico_socket *s, int option, void *value) return -1; #endif } - diff --git a/modules/pico_socket_udp.h b/modules/pico_socket_udp.h index 3fe2055a..7932e4a2 100644 --- a/modules/pico_socket_udp.h +++ b/modules/pico_socket_udp.h @@ -44,5 +44,4 @@ int pico_getsockopt_udp(struct pico_socket *s, int option, void *value); # define pico_setsockopt_udp(...) (-1) #endif - #endif diff --git a/modules/pico_udp.c b/modules/pico_udp.c index 81a897de..f00a421e 100644 --- a/modules/pico_udp.c +++ b/modules/pico_udp.c @@ -229,4 +229,3 @@ uint16_t pico_udp_recv(struct pico_socket *s, void *buf, uint16_t len, void *src } } else return 0; } - diff --git a/stack/pico_frame.c b/stack/pico_frame.c index 03bf9db8..05db3e40 100644 --- a/stack/pico_frame.c +++ b/stack/pico_frame.c @@ -346,4 +346,3 @@ uint16_t pico_dualbuffer_checksum(void *inbuf1, uint32_t len1, void *inbuf2, uin sum = pico_checksum_adder(sum, inbuf2, len2); return pico_checksum_finalize(sum); } - diff --git a/stack/pico_protocol.c b/stack/pico_protocol.c index 0b63d23a..cf8f3aeb 100644 --- a/stack/pico_protocol.c +++ b/stack/pico_protocol.c @@ -263,4 +263,3 @@ void pico_protocol_init(struct pico_stack *S, struct pico_protocol *p) proto_layer_rr_reset(proto); dbg("Protocol %s registered (layer: %d).\n", p->name, p->layer); } - diff --git a/stack/pico_socket_multicast.c b/stack/pico_socket_multicast.c index 7eeb0398..035a80b8 100644 --- a/stack/pico_socket_multicast.c +++ b/stack/pico_socket_multicast.c @@ -1493,4 +1493,3 @@ int pico_setsockopt_mcast(struct pico_socket *s, int option, void *value) } #endif /* PICO_SUPPORT_MCAST */ - diff --git a/test/examples/iperfc.c b/test/examples/iperfc.c index 709b37b1..292d09b5 100644 --- a/test/examples/iperfc.c +++ b/test/examples/iperfc.c @@ -141,4 +141,3 @@ void app_iperfc(struct pico_stack *S, char *arg) dbg("Error parsing options!\n"); exit(1); } - diff --git a/test/examples/ping.c b/test/examples/ping.c index effd254d..34ec3cf6 100644 --- a/test/examples/ping.c +++ b/test/examples/ping.c @@ -137,4 +137,3 @@ void app_ping(struct pico_stack *S, char *arg) } #endif /*** END PING ***/ - diff --git a/test/pico_faulty.h b/test/pico_faulty.h index 70ecf796..f52c6b58 100644 --- a/test/pico_faulty.h +++ b/test/pico_faulty.h @@ -132,4 +132,3 @@ static inline void PICO_IDLE(void) void memory_stats(void); #endif /* PICO_SUPPORT_POSIX */ - diff --git a/test/unit/modunit_pico_dns_common.c b/test/unit/modunit_pico_dns_common.c index 95000fb5..3a595dee 100644 --- a/test/unit/modunit_pico_dns_common.c +++ b/test/unit/modunit_pico_dns_common.c @@ -1474,4 +1474,3 @@ int main(void) srunner_free(sr); return fails; } - diff --git a/test/unit/modunit_pico_mdns.c b/test/unit/modunit_pico_mdns.c index bfac90bf..eb5f85d3 100644 --- a/test/unit/modunit_pico_mdns.c +++ b/test/unit/modunit_pico_mdns.c @@ -2356,4 +2356,3 @@ int main(void) srunner_free(sr); return fails; } - diff --git a/test/unit/modunit_seq.c b/test/unit/modunit_seq.c index aa8ad0af..a1ace07b 100644 --- a/test/unit/modunit_seq.c +++ b/test/unit/modunit_seq.c @@ -58,4 +58,3 @@ int main(void) srunner_free(sr); return fails; } -