summaryrefslogtreecommitdiff
path: root/lib/route-table.c
diff options
context:
space:
mode:
authorNobuhiro MIKI <nmiki@yahoo-corp.jp>2023-03-06 11:49:19 +0900
committerIlya Maximets <i.maximets@ovn.org>2023-03-07 19:16:20 +0100
commit49e534cd3764e853f70f01b63196f320c9a5790e (patch)
tree1e2e6d5a82a500fa01853327c0aaa5be1f42c0cd /lib/route-table.c
parentb801f1aa001cf0537cc64b268a49c7988b78cbf5 (diff)
downloadopenvswitch-49e534cd3764e853f70f01b63196f320c9a5790e.tar.gz
route-table: Retrieving the preferred source address from Netlink.
We can use the "ip route add ... src ..." command to set the preferred source address for each entry in the kernel FIB. OVS has a mechanism to cache the FIB, but the preferred source address is ignored and calculated with its own logic. This patch resolves the difference between kernel FIB and OVS route table cache by retrieving the RTA_PREFSRC attribute of Netlink messages. Acked-by: Eelco Chaudron <echaudro@redhat.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'lib/route-table.c')
-rw-r--r--lib/route-table.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/route-table.c b/lib/route-table.c
index ac82cf262..9927dcc18 100644
--- a/lib/route-table.c
+++ b/lib/route-table.c
@@ -51,6 +51,7 @@ struct route_data {
/* Extracted from Netlink attributes. */
struct in6_addr rta_dst; /* 0 if missing. */
+ struct in6_addr rta_prefsrc; /* 0 if missing. */
struct in6_addr rta_gw;
char ifname[IFNAMSIZ]; /* Interface name. */
uint32_t mark;
@@ -201,6 +202,7 @@ route_table_parse(struct ofpbuf *buf, struct route_table_msg *change)
[RTA_OIF] = { .type = NL_A_U32, .optional = true },
[RTA_GATEWAY] = { .type = NL_A_U32, .optional = true },
[RTA_MARK] = { .type = NL_A_U32, .optional = true },
+ [RTA_PREFSRC] = { .type = NL_A_U32, .optional = true },
};
static const struct nl_policy policy6[] = {
@@ -208,6 +210,7 @@ route_table_parse(struct ofpbuf *buf, struct route_table_msg *change)
[RTA_OIF] = { .type = NL_A_U32, .optional = true },
[RTA_MARK] = { .type = NL_A_U32, .optional = true },
[RTA_GATEWAY] = { .type = NL_A_IPV6, .optional = true },
+ [RTA_PREFSRC] = { .type = NL_A_IPV6, .optional = true },
};
struct nlattr *attrs[ARRAY_SIZE(policy)];
@@ -274,6 +277,16 @@ route_table_parse(struct ofpbuf *buf, struct route_table_msg *change)
} else if (ipv4) {
in6_addr_set_mapped_ipv4(&change->rd.rta_dst, 0);
}
+ if (attrs[RTA_PREFSRC]) {
+ if (ipv4) {
+ ovs_be32 prefsrc;
+ prefsrc = nl_attr_get_be32(attrs[RTA_PREFSRC]);
+ in6_addr_set_mapped_ipv4(&change->rd.rta_prefsrc, prefsrc);
+ } else {
+ change->rd.rta_prefsrc =
+ nl_attr_get_in6_addr(attrs[RTA_PREFSRC]);
+ }
+ }
if (attrs[RTA_GATEWAY]) {
if (ipv4) {
ovs_be32 gw;
@@ -309,7 +322,8 @@ route_table_handle_msg(const struct route_table_msg *change)
const struct route_data *rd = &change->rd;
ovs_router_insert(rd->mark, &rd->rta_dst, rd->rtm_dst_len,
- rd->local, rd->ifname, &rd->rta_gw);
+ rd->local, rd->ifname, &rd->rta_gw,
+ &rd->rta_prefsrc);
}
}