From 1e7a618e7d0b2300e23384906569ae3d0f20f52d Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Sun, 21 Feb 2021 17:30:12 +0100 Subject: [PATCH] Revert "Improve computation of alternate nets" This reverts commit c75d0cf6c5ef8df7ca1f77552c11a5e01b0c5f68. --- .github/workflows/build-with-cmake.yml | 57 +++++++++++++++++ fuzzer/build-fuzzer.sh | 2 +- usrsctplib/netinet/sctp_pcb.c | 6 +- usrsctplib/netinet/sctp_timer.c | 84 ++++++++++++-------------- 4 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/build-with-cmake.yml diff --git a/.github/workflows/build-with-cmake.yml b/.github/workflows/build-with-cmake.yml new file mode 100644 index 000000000..5ba9d69c3 --- /dev/null +++ b/.github/workflows/build-with-cmake.yml @@ -0,0 +1,57 @@ +name: Build with CMake + +on: + push: + branches: [ master, github-actions ] + pull_request: + branches: [ master ] + +jobs: + build: + + strategy: + matrix: + platform: [ubuntu-latest, macos-latest, windows-latest] + cmake_build_type: [Debug, RelWithDebInfo] + sctp_invariants: [ON, OFF] + sctp_inet6: [ON, OFF] + sctp_inet: [ON, OFF] + sctp_debug: [ON, OFF] + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v2 + with: + path: 'usrsctp_source' + + - name: Prepare dirs + shell: bash + run: | + mkdir -p cmake_build + mkdir -p cmake_install + + - name: Generate CMake project + shell: bash + run: | + cd cmake_build + cmake -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ + -Dsctp_debug=${{ matrix.sctp_debug }} \ + -Dsctp_invariants=${{ matrix.sctp_invariants }} \ + -Dsctp_inet6=${{ matrix.sctp_inet6 }} \ + -Dsctp_inet=${{ matrix.sctp_inet }} \ + -Dsctp_build_programs=ON \ + -Dsctp_build_fuzzer=OFF \ + -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/cmake_install \ + ${GITHUB_WORKSPACE}/usrsctp_source + + - name: Build and install project + shell: bash + run: | + cmake --build cmake_build \ + --parallel 2 \ + --config ${{ matrix.cmake_build_type }} \ + --target install \ + --clean-first diff --git a/fuzzer/build-fuzzer.sh b/fuzzer/build-fuzzer.sh index a0033b7ef..65a5cc903 100755 --- a/fuzzer/build-fuzzer.sh +++ b/fuzzer/build-fuzzer.sh @@ -41,7 +41,7 @@ pwd find . -iwholename '*cmake*' -not -name CMakeLists.txt -delete # Build with ASAN / MSAN -cmake -Dsctp_build_shared_lib=1 -Dsctp_build_fuzzer=1 -Dsctp_build_programs=0 -Dsctp_invariants=1 -Dsctp_sanitizer_address=1 -DCMAKE_LINKER="$CC" -DCMAKE_C_COMPILER="$CC" . +cmake -Dsctp_build_fuzzer=1 -Dsctp_build_programs=0 -Dsctp_invariants=1 -Dsctp_sanitizer_address=1 -DCMAKE_LINKER="$CC" -DCMAKE_C_COMPILER="$CC" . #cmake -Dsctp_build_fuzzer=1 -Dsctp_build_programs=0 -Dsctp_invariants=1 -Dsctp_sanitizer_memory=1 -DCMAKE_LINKER="$CC" -DCMAKE_C_COMPILER="$CC" . make -j"$NPROC" diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c index 612c867c6..89a66bce8 100755 --- a/usrsctplib/netinet/sctp_pcb.c +++ b/usrsctplib/netinet/sctp_pcb.c @@ -34,7 +34,7 @@ #if defined(__FreeBSD__) && !defined(__Userspace__) #include -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.c 366483 2020-10-06 11:29:08Z tuexen $"); #endif #include @@ -5181,10 +5181,6 @@ sctp_remove_net(struct sctp_tcb *stcb, struct sctp_nets *net) /* Clear net */ asoc->last_control_chunk_from = NULL; } - if (net == asoc->last_net_cmt_send_started) { - /* Clear net */ - asoc->last_net_cmt_send_started = NULL; - } if (net == stcb->asoc.alternate) { sctp_free_remote_addr(stcb->asoc.alternate); stcb->asoc.alternate = NULL; diff --git a/usrsctplib/netinet/sctp_timer.c b/usrsctplib/netinet/sctp_timer.c index f248305e2..a0ca4aabf 100755 --- a/usrsctplib/netinet/sctp_timer.c +++ b/usrsctplib/netinet/sctp_timer.c @@ -34,7 +34,7 @@ #if defined(__FreeBSD__) && !defined(__Userspace__) #include -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 365071 2020-09-01 21:19:14Z mjg $"); #endif #define _IP_VHL @@ -171,8 +171,8 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb, } /* - * sctp_find_alternate_net() returns a non-NULL pointer as long as there - * exists nets, which are not being deleted. + * sctp_find_alternate_net() returns a non-NULL pointer as long + * the argument net is non-NULL. */ struct sctp_nets * sctp_find_alternate_net(struct sctp_tcb *stcb, @@ -181,13 +181,13 @@ sctp_find_alternate_net(struct sctp_tcb *stcb, { /* Find and return an alternate network if possible */ struct sctp_nets *alt, *mnet, *min_errors_net = NULL , *max_cwnd_net = NULL; - bool looped; + int once; /* JRS 5/14/07 - Initialize min_errors to an impossible value. */ int min_errors = -1; uint32_t max_cwnd = 0; if (stcb->asoc.numnets == 1) { - /* No selection can be made. */ + /* No others but net */ return (TAILQ_FIRST(&stcb->asoc.nets)); } /* @@ -323,22 +323,25 @@ sctp_find_alternate_net(struct sctp_tcb *stcb, return (max_cwnd_net); } } - /* Look for an alternate net, which is active. */ - if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) { - alt = TAILQ_NEXT(net, sctp_next);; - } else { - alt = TAILQ_FIRST(&stcb->asoc.nets); + mnet = net; + once = 0; + + if (mnet == NULL) { + mnet = TAILQ_FIRST(&stcb->asoc.nets); + if (mnet == NULL) { + return (NULL); + } } - looped = false; for (;;) { + alt = TAILQ_NEXT(mnet, sctp_next); if (alt == NULL) { - if (!looped) { - alt = TAILQ_FIRST(&stcb->asoc.nets); - looped = true; + once++; + if (once > 1) { + break; } - /* Definitely out of candidates. */ + alt = TAILQ_FIRST(&stcb->asoc.nets); if (alt == NULL) { - break; + return (NULL); } } #if defined(__FreeBSD__) && !defined(__Userspace__) @@ -358,56 +361,43 @@ sctp_find_alternate_net(struct sctp_tcb *stcb, #else (alt->ro.ro_rt != NULL) && #endif - (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) && - (alt != net)) { - /* Found an alternate net, which is reachable. */ + (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))) { + /* Found a reachable address */ break; } - alt = TAILQ_NEXT(alt, sctp_next); + mnet = alt; } if (alt == NULL) { - /* - * In case no active alternate net has been found, look for - * an alternate net, which is confirmed. - */ - if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) { - alt = TAILQ_NEXT(net, sctp_next);; - } else { - alt = TAILQ_FIRST(&stcb->asoc.nets); - } - looped = false; + /* Case where NO insv network exists (dormant state) */ + /* we rotate destinations */ + once = 0; + mnet = net; for (;;) { + if (mnet == NULL) { + return (TAILQ_FIRST(&stcb->asoc.nets)); + } + alt = TAILQ_NEXT(mnet, sctp_next); if (alt == NULL) { - if (!looped) { - alt = TAILQ_FIRST(&stcb->asoc.nets); - looped = true; + once++; + if (once > 1) { + break; } - /* Definitely out of candidates. */ + alt = TAILQ_FIRST(&stcb->asoc.nets); if (alt == NULL) { break; } } if ((!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) && (alt != net)) { - /* Found an alternate net, which is confirmed. */ + /* Found an alternate address */ break; } - alt = TAILQ_NEXT(alt, sctp_next); + mnet = alt; } } if (alt == NULL) { - /* - * In case no confirmed alternate net has been found, just - * return net, if it is not being deleted. In the other case - * just return the first net. - */ - if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) { - alt = net; - } - if (alt == NULL) { - alt = TAILQ_FIRST(&stcb->asoc.nets); - } + return (net); } return (alt); }