diff options
author | Klement Sekera <ksekera@cisco.com> | 2017-02-09 06:03:46 +0100 |
---|---|---|
committer | Klement Sekera <ksekera@cisco.com> | 2017-02-14 03:08:15 +0100 |
commit | 2bce0332d368901ea66c7e582119719757e37e42 (patch) | |
tree | 067e8ee9b6ad60604945afe1a38269ed286a60ee | |
parent | b05f1f0255b9a9b20381b621d187dd8b54911d9f (diff) |
BFD: set per session UDP source port per RFC
Change-Id: Id294dbbd6499ae8221cc8143e1027adc08866ae6
Signed-off-by: Klement Sekera <ksekera@cisco.com>
-rw-r--r-- | src/vnet/bfd/bfd_main.c | 9 | ||||
-rw-r--r-- | src/vnet/bfd/bfd_main.h | 2 | ||||
-rw-r--r-- | src/vnet/bfd/bfd_udp.c | 40 | ||||
-rw-r--r-- | src/vnet/bfd/bfd_udp.h | 8 |
4 files changed, 43 insertions, 16 deletions
diff --git a/src/vnet/bfd/bfd_main.c b/src/vnet/bfd/bfd_main.c index 0c5f1986768..7e06962a785 100644 --- a/src/vnet/bfd/bfd_main.c +++ b/src/vnet/bfd/bfd_main.c @@ -35,11 +35,6 @@ bfd_usec_to_clocks (const bfd_main_t * bm, u64 us) return bm->cpu_cps * ((f64) us / USEC_PER_SECOND); } -// static u64 bfd_clocks_to_usec (const bfd_main_t *bm, u64 clocks) -//{ -// return (clocks / bm->cpu_cps) * USEC_PER_SECOND; -//} - static vlib_node_registration_t bfd_process_node; /* set to 0 here, real values filled at startup */ @@ -464,11 +459,11 @@ bfd_add_transport_layer (vlib_main_t * vm, vlib_buffer_t * b, { case BFD_TRANSPORT_UDP4: BFD_DBG ("Transport bfd via udp4, bs_idx=%u", bs->bs_idx); - bfd_add_udp4_transport (vm, b, &bs->udp); + bfd_add_udp4_transport (vm, b, bs); break; case BFD_TRANSPORT_UDP6: BFD_DBG ("Transport bfd via udp6, bs_idx=%u", bs->bs_idx); - bfd_add_udp6_transport (vm, b, &bs->udp); + bfd_add_udp6_transport (vm, b, bs); break; } } diff --git a/src/vnet/bfd/bfd_main.h b/src/vnet/bfd/bfd_main.h index 361ff0b7e1c..14a54d6f3df 100644 --- a/src/vnet/bfd/bfd_main.h +++ b/src/vnet/bfd/bfd_main.h @@ -76,7 +76,7 @@ typedef enum #undef F } bfd_poll_state_e; -typedef struct +typedef struct bfd_session_s { /* index in bfd_main.sessions pool */ u32 bs_idx; diff --git a/src/vnet/bfd/bfd_udp.c b/src/vnet/bfd/bfd_udp.c index e1ff8a9d887..75b35974329 100644 --- a/src/vnet/bfd/bfd_udp.c +++ b/src/vnet/bfd/bfd_udp.c @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2011-2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include <vppinfra/types.h> #include <vlibmemory/api.h> #include <vlib/vlib.h> @@ -31,10 +45,25 @@ static vlib_node_registration_t bfd_udp6_input_node; bfd_udp_main_t bfd_udp_main; +static u16 +bfd_udp_bs_idx_to_sport (u32 bs_idx) +{ + /* The source port MUST be in the range 49152 through 65535. The same UDP + * source port number MUST be used for all BFD Control packets associated + * with a particular session. The source port number SHOULD be unique among + * all BFD sessions on the system. If more than 16384 BFD sessions are + * simultaneously active, UDP source port numbers MAY be reused on + * multiple sessions, but the number of distinct uses of the same UDP + * source port number SHOULD be minimized. + */ + return 49152 + bs_idx % (65535 - 49152 + 1); +} + void bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b, - bfd_udp_session_t * bus) + const bfd_session_t * bs) { + const bfd_udp_session_t *bus = &bs->udp; const bfd_udp_key_t *key = &bus->key; b->flags |= VNET_BUFFER_LOCALLY_ORIGINATED; @@ -55,7 +84,8 @@ bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b, headers->ip4.src_address.as_u32 = key->local_addr.ip4.as_u32; headers->ip4.dst_address.as_u32 = key->peer_addr.ip4.as_u32; - headers->udp.src_port = clib_host_to_net_u16 (50000); /* FIXME */ + headers->udp.src_port = + clib_host_to_net_u16 (bfd_udp_bs_idx_to_sport (bs->bs_idx)); headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4); /* fix ip length, checksum and udp length */ @@ -70,8 +100,9 @@ bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b, void bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b, - bfd_udp_session_t * bus) + const bfd_session_t * bs) { + const bfd_udp_session_t *bus = &bs->udp; const bfd_udp_key_t *key = &bus->key; b->flags |= VNET_BUFFER_LOCALLY_ORIGINATED; @@ -95,7 +126,8 @@ bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b, clib_memcpy (&headers->ip6.dst_address, &key->peer_addr.ip6, sizeof (headers->ip6.dst_address)); - headers->udp.src_port = clib_host_to_net_u16 (50000); /* FIXME */ + headers->udp.src_port = + clib_host_to_net_u16 (bfd_udp_bs_idx_to_sport (bs->bs_idx)); headers->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd6); /* fix ip payload length and udp length */ diff --git a/src/vnet/bfd/bfd_udp.h b/src/vnet/bfd/bfd_udp.h index 2cd89ca28ce..26e89851873 100644 --- a/src/vnet/bfd/bfd_udp.h +++ b/src/vnet/bfd/bfd_udp.h @@ -23,8 +23,6 @@ #include <vnet/adj/adj_types.h> #include <vnet/ip/ip6_packet.h> -#define BFD_UDP_KEY_BODY - /* *INDENT-OFF* */ typedef CLIB_PACKED (struct { @@ -42,10 +40,12 @@ typedef struct adj_index_t adj_index; } bfd_udp_session_t; +struct bfd_session_s; + void bfd_add_udp4_transport (vlib_main_t * vm, vlib_buffer_t * b, - bfd_udp_session_t * bs); + const struct bfd_session_s *bs); void bfd_add_udp6_transport (vlib_main_t * vm, vlib_buffer_t * b, - bfd_udp_session_t * bs); + const struct bfd_session_s *bs); #endif /* __included_bfd_udp_h__ */ |