summaryrefslogtreecommitdiff
path: root/bgpd/bgp_ecommunity.h
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2023-04-05 15:51:45 +0300
committerDonatas Abraitis <donatas@opensourcerouting.org>2023-04-14 21:04:40 +0300
commitc9a256144479bb0836491b6bdad6a79df85e6960 (patch)
tree85f637616dc8b1dbd11722acf44255847efbaa6c /bgpd/bgp_ecommunity.h
parent068c4dfe0b8196e6f67d1211e492f5d265801c9e (diff)
bgpd: Implement Node Target Extended Communities
kttps://datatracker.ietf.org/doc/html/draft-ietf-idr-node-target-ext-comm unet> sh r1 vtysh -c 'sh ip bgp nei 192.168.1.2 adver' BGP table version is 1, local router ID is 192.168.1.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.10.10.10/32 0.0.0.0 0 32768 i Total number of prefixes 1 unet> sh r1 vtysh -c 'sh ip bgp nei 192.168.1.3 adver' BGP table version is 1, local router ID is 192.168.1.1, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 10.10.10.10/32 0.0.0.0 0 32768 i Total number of prefixes 1 unet> sh r2 vtysh -c 'show ip bgp 10.10.10.10/32' % Network not in table unet> sh r3 vtysh -c 'show ip bgp 10.10.10.10/32' BGP routing table entry for 10.10.10.10/32, version 1 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.1.1 65001 192.168.1.1 from 192.168.1.1 (192.168.1.1) Origin IGP, metric 0, valid, external, best (First path received) Extended Community: NT:192.168.1.3 NT:192.168.1.4 Last update: Tue Apr 11 23:19:33 2023 unet> Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_ecommunity.h')
-rw-r--r--bgpd/bgp_ecommunity.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h
index 83a1584489..1efb0276d0 100644
--- a/bgpd/bgp_ecommunity.h
+++ b/bgpd/bgp_ecommunity.h
@@ -101,6 +101,10 @@ enum ecommunity_origin_validation_states {
/* Extended Community readable string length */
#define ECOMMUNITY_STRLEN 64
+/* Node Target Extended Communities */
+#define ECOMMUNITY_NODE_TARGET 0x09
+#define ECOMMUNITY_NODE_TARGET_RESERVED 0
+
/* Extended Communities attribute. */
struct ecommunity {
/* Reference counter. */
@@ -257,6 +261,26 @@ static inline void encode_origin_validation_state(enum rpki_states state,
eval->val[7] = ovs_state;
}
+static inline void encode_node_target(struct in_addr *node_id,
+ struct ecommunity_val *eval, bool trans)
+{
+ /*
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | 0x01 or 0x41 | Sub-Type(0x09) | Target BGP Identifier |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Target BGP Identifier (cont.) | Reserved |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ memset(eval, 0, sizeof(*eval));
+ eval->val[0] = ECOMMUNITY_ENCODE_IP;
+ if (!trans)
+ eval->val[0] |= ECOMMUNITY_ENCODE_IP_NON_TRANS;
+ eval->val[1] = ECOMMUNITY_NODE_TARGET;
+ memcpy(&eval->val[2], node_id, sizeof(*node_id));
+ eval->val[6] = ECOMMUNITY_NODE_TARGET_RESERVED;
+ eval->val[7] = ECOMMUNITY_NODE_TARGET_RESERVED;
+}
+
extern void ecommunity_init(void);
extern void ecommunity_finish(void);
extern void ecommunity_free(struct ecommunity **);
@@ -338,4 +362,9 @@ static inline void ecommunity_strip_rts(struct ecommunity *ecom)
extern struct ecommunity *
ecommunity_add_origin_validation_state(enum rpki_states rpki_state,
struct ecommunity *ecom);
+extern struct ecommunity *ecommunity_add_node_target(struct in_addr *node_id,
+ struct ecommunity *old,
+ bool non_trans);
+extern bool ecommunity_node_target_match(struct ecommunity *ecomm,
+ struct in_addr *local_id);
#endif /* _QUAGGA_BGP_ECOMMUNITY_H */