[PATCH 4/9] Netlink supports SADR.
Dean Luga
dluga93 at gmail.com
Tue Mar 7 00:56:28 CET 2017
From: dean <dluga93 at gmail.com>
If SADR is enabled, to specify a source constraint for a route,
the RTA_SRC attribute, which contains the source address, is added
to the netlink message, and the source prefix length is set.
If SADR is enabled, the source attribute is also handled when
parsing routes in nl_parse_route.
---
sysdep/linux/netlink.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c
index 79dd140..f4ec633 100644
--- a/sysdep/linux/netlink.c
+++ b/sysdep/linux/netlink.c
@@ -902,6 +902,11 @@ nl_send_route(struct krt_proto *p, rte *e, struct ea_list *eattrs, int op, int d
r.r.rtm_scope = RT_SCOPE_NOWHERE;
nl_add_attr_ipa(&r.h, sizeof(r), RTA_DST, net->n.prefix);
+ #ifdef SADR_OSPF
+ r.r.rtm_src_len = net->n.src_pxlen;
+ nl_add_attr_ipa(&r.h, sizeof(r), RTA_SRC, net->n.src_prefix);
+ #endif
+
/*
* Strange behavior for RTM_DELROUTE:
* 1) rtm_family is ignored in IPv6, works for IPv4
@@ -1138,6 +1143,7 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
int new = h->nlmsg_type == RTM_NEWROUTE;
ip_addr dst = IPA_NONE;
+ ip_addr srcaddr = IPA_NONE;
u32 oif = ~0;
u32 table;
u32 priority = 0;
@@ -1169,6 +1175,11 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
memcpy(&dst, RTA_DATA(a[RTA_DST]), sizeof(dst));
ipa_ntoh(dst);
}
+ if (a[RTA_SRC])
+ {
+ memcpy(&srcaddr, RTA_DATA(a[RTA_SRC]), sizeof(srcaddr));
+ ipa_ntoh(srcaddr);
+ }
if (a[RTA_OIF])
oif = rta_get_u32(a[RTA_OIF]);
@@ -1225,7 +1236,15 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
src = KRT_SRC_ALIEN;
}
- net *net = net_get(p->p.table, dst, i->rtm_dst_len);
+ addr_data addr = addr_data_init_empty();
+ addr.prefix = &dst;
+ addr.pxlen = i->rtm_dst_len;
+
+ #ifdef SADR_OSPF
+ addr.src_prefix = &srcaddr;
+ addr.src_pxlen = i->rtm_src_len;
+ #endif
+ net *net = net_get2(p->p.table, addr);
if (s->net && !nl_mergable_route(s, net, p, priority, i->rtm_type))
nl_announce_route(s);
--
2.7.4
More information about the Bird-users
mailing list