2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-19 14:37:21 +00:00

bfd: Add configuration for setting and matching mac address.

This commit adds options for configuring the MAC addresses
in BFD state machine.  Therein, the "bfd_local_src_mac" and
"bfd_local_dst_mac" configure the MAC address for transmitted
BFD packets.  The "bfd_remote_dst_mac" configure the matching
of MAC address on received BFD packets.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
This commit is contained in:
Alex Wang
2014-08-08 16:41:27 -07:00
parent 1314739ca7
commit 873b049f23
2 changed files with 52 additions and 18 deletions

View File

@@ -169,8 +169,10 @@ struct bfd {
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. */
@@ -388,8 +390,6 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg,
bfd_set_state(bfd, STATE_DOWN, DIAG_NONE);
memcpy(bfd->eth_dst, eth_addr_bfd, ETH_ADDR_LEN);
bfd_status_changed(bfd);
}
@@ -440,13 +440,25 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg,
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");
@@ -600,8 +612,14 @@ bfd_put_packet(struct bfd *bfd, struct ofpbuf *p,
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);
@@ -657,7 +675,8 @@ bfd_should_process_flow(const struct bfd *bfd_, const struct flow *flow,
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)) {
if (!eth_addr_is_zero(bfd->rmt_eth_dst)
&& memcmp(bfd->rmt_eth_dst, flow->dl_dst, ETH_ADDR_LEN)) {
return false;
}