#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <sys/socket.h>
#include "byte-order.h"
#include "connectivity.h"
uint32_t rmt_disc; /* bfd.RemoteDiscr. */
- uint8_t eth_dst[ETH_ADDR_LEN];/* Ethernet destination address. */
- bool eth_dst_set; /* 'eth_dst' set through database. */
+ uint8_t local_eth_src[ETH_ADDR_LEN]; /* Local eth src address. */
+ uint8_t local_eth_dst[ETH_ADDR_LEN]; /* Local eth dst address. */
+
+ uint8_t rmt_eth_dst[ETH_ADDR_LEN]; /* Remote eth dst address. */
ovs_be32 ip_src; /* IPv4 source address. */
ovs_be32 ip_dst; /* IPv4 destination address. */
struct netdev *netdev) OVS_EXCLUDED(mutex)
{
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
- static atomic_uint16_t udp_src = ATOMIC_VAR_INIT(0);
+ static atomic_count udp_src = ATOMIC_COUNT_INIT(0);
int decay_min_rx;
long long int min_tx, min_rx;
* 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. */
- atomic_add(&udp_src, 1, &bfd->udp_src);
- bfd->udp_src = (bfd->udp_src % 16384) + 49152;
+ bfd->udp_src = (atomic_count_inc(&udp_src) % 16384) + 49152;
bfd_set_state(bfd, STATE_DOWN, DIAG_NONE);
- memcpy(bfd->eth_dst, eth_addr_bfd, ETH_ADDR_LEN);
-
bfd_status_changed(bfd);
}
- atomic_store(&bfd->check_tnl_key,
- smap_get_bool(cfg, "check_tnl_key", false));
+ atomic_store_relaxed(&bfd->check_tnl_key,
+ smap_get_bool(cfg, "check_tnl_key", false));
min_tx = smap_get_int(cfg, "min_tx", 100);
min_tx = MAX(min_tx, 100);
if (bfd->cfg_min_tx != min_tx) {
need_poll = true;
}
- hwaddr = smap_get(cfg, "bfd_dst_mac");
- if (hwaddr && eth_addr_from_string(hwaddr, ea) && !eth_addr_is_zero(ea)) {
- memcpy(bfd->eth_dst, ea, ETH_ADDR_LEN);
- bfd->eth_dst_set = true;
- } else if (bfd->eth_dst_set) {
- memcpy(bfd->eth_dst, eth_addr_bfd, ETH_ADDR_LEN);
- bfd->eth_dst_set = false;
+ hwaddr = smap_get(cfg, "bfd_local_src_mac");
+ if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
+ memcpy(bfd->local_eth_src, ea, ETH_ADDR_LEN);
+ } else {
+ memset(bfd->local_eth_src, 0, ETH_ADDR_LEN);
+ }
+
+ hwaddr = smap_get(cfg, "bfd_local_dst_mac");
+ if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
+ memcpy(bfd->local_eth_dst, ea, ETH_ADDR_LEN);
+ } else {
+ memset(bfd->local_eth_dst, 0, ETH_ADDR_LEN);
+ }
+
+ hwaddr = smap_get(cfg, "bfd_remote_dst_mac");
+ if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
+ memcpy(bfd->rmt_eth_dst, ea, ETH_ADDR_LEN);
+ } else {
+ memset(bfd->rmt_eth_dst, 0, ETH_ADDR_LEN);
}
ip_src = smap_get(cfg, "bfd_src_ip");
if (ip_src && bfd_lookup_ip(ip_src, &in_addr)) {
memcpy(&bfd->ip_src, &in_addr, sizeof in_addr);
} else {
- bfd->ip_src = htonl(0xA9FE0100); /* 169.254.1.0. */
+ bfd->ip_src = htonl(0xA9FE0101); /* 169.254.1.1. */
}
ip_dst = smap_get(cfg, "bfd_dst_ip");
if (ip_dst && bfd_lookup_ip(ip_dst, &in_addr)) {
memcpy(&bfd->ip_dst, &in_addr, sizeof in_addr);
} else {
- bfd->ip_dst = htonl(0xA9FE0101); /* 169.254.1.1. */
+ bfd->ip_dst = htonl(0xA9FE0100); /* 169.254.1.0. */
}
forwarding_if_rx = smap_get_bool(cfg, "forwarding_if_rx", false);
void
bfd_unref(struct bfd *bfd) OVS_EXCLUDED(mutex)
{
- if (bfd && ovs_refcount_unref(&bfd->ref_cnt) == 1) {
+ if (bfd && ovs_refcount_unref_relaxed(&bfd->ref_cnt) == 1) {
ovs_mutex_lock(&mutex);
bfd_status_changed(bfd);
hmap_remove(all_bfds, &bfd->node);
ofpbuf_reserve(p, 2); /* Properly align after the ethernet header. */
eth = ofpbuf_put_uninit(p, sizeof *eth);
- memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
- memcpy(eth->eth_dst, bfd->eth_dst, ETH_ADDR_LEN);
+ memcpy(eth->eth_src,
+ eth_addr_is_zero(bfd->local_eth_src) ? eth_src
+ : bfd->local_eth_src,
+ ETH_ADDR_LEN);
+ memcpy(eth->eth_dst,
+ eth_addr_is_zero(bfd->local_eth_dst) ? eth_addr_bfd
+ : bfd->local_eth_dst,
+ ETH_ADDR_LEN);
eth->eth_type = htons(ETH_TYPE_IP);
ip = ofpbuf_put_zeros(p, sizeof *ip);
struct flow_wildcards *wc)
{
struct bfd *bfd = CONST_CAST(struct bfd *, bfd_);
- bool check_tnl_key;
- memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
- if (bfd->eth_dst_set && memcmp(bfd->eth_dst, flow->dl_dst, ETH_ADDR_LEN)) {
- return false;
- }
+ if (!eth_addr_is_zero(bfd->rmt_eth_dst)) {
+ memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
- memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
- memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
+ if (memcmp(bfd->rmt_eth_dst, flow->dl_dst, ETH_ADDR_LEN)) {
+ return false;
+ }
+ }
- atomic_read(&bfd->check_tnl_key, &check_tnl_key);
- if (check_tnl_key) {
- memset(&wc->masks.tunnel.tun_id, 0xff, sizeof wc->masks.tunnel.tun_id);
+ if (flow->dl_type == htons(ETH_TYPE_IP)) {
+ memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
+ if (flow->nw_proto == IPPROTO_UDP) {
+ memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
+ if (flow->tp_dst == htons(BFD_DEST_PORT)) {
+ bool check_tnl_key;
+
+ atomic_read_relaxed(&bfd->check_tnl_key, &check_tnl_key);
+ if (check_tnl_key) {
+ memset(&wc->masks.tunnel.tun_id, 0xff,
+ sizeof wc->masks.tunnel.tun_id);
+ return flow->tunnel.tun_id == htonll(0);
+ }
+ return true;
+ }
+ }
}
- return (flow->dl_type == htons(ETH_TYPE_IP)
- && flow->nw_proto == IPPROTO_UDP
- && flow->tp_dst == htons(BFD_DEST_PORT)
- && (!check_tnl_key || flow->tunnel.tun_id == htonll(0)));
+ return false;
}
void