]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_label.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / bgp_label.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP carrying Label information
3 * Copyright (C) 2013 Cumulus Networks, Inc.
4 */
5
6 #ifndef _BGP_LABEL_H
7 #define _BGP_LABEL_H
8
9 #define BGP_LABEL_BYTES 3
10 #define BGP_LABEL_BITS 24
11 #define BGP_WITHDRAW_LABEL 0x800000
12 #define BGP_PREVENT_VRF_2_VRF_LEAK 0xFFFFFFFE
13
14 struct bgp_dest;
15 struct bgp_path_info;
16 struct peer;
17
18 extern int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid,
19 bool allocated);
20 extern void bgp_reg_dereg_for_label(struct bgp_dest *dest,
21 struct bgp_path_info *pi, bool reg);
22 extern int bgp_parse_fec_update(void);
23 extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
24 struct bgp_path_info *pi, struct peer *to,
25 afi_t afi, safi_t safi);
26
27 extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
28 struct bgp_nlri *packet);
29
30 static inline int bgp_labeled_safi(safi_t safi)
31 {
32 /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN
33 * routes will have a label.
34 */
35 if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN)
36 || (safi == SAFI_EVPN))
37 return 1;
38 return 0;
39 }
40
41 static inline int bgp_is_withdraw_label(mpls_label_t *label)
42 {
43 uint8_t *pkt = (uint8_t *)label;
44
45 /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label()
46 * was called on the withdraw label */
47 if (((pkt[0] == 0x80) || (pkt[0] == 0x00)) && (pkt[1] == 0x00)
48 && ((pkt[2] == 0x00) || (pkt[2] == 0x02)))
49 return 1;
50 return 0;
51 }
52
53 static inline int bgp_is_valid_label(const mpls_label_t *label)
54 {
55 uint8_t *t = (uint8_t *)label;
56 if (!t)
57 return 0;
58 return (t[2] & 0x02);
59 }
60
61 static inline void bgp_set_valid_label(mpls_label_t *label)
62 {
63 uint8_t *t = (uint8_t *)label;
64 if (t)
65 t[2] |= 0x02;
66 }
67
68 static inline void bgp_unset_valid_label(mpls_label_t *label)
69 {
70 uint8_t *t = (uint8_t *)label;
71 if (t)
72 t[2] &= ~0x02;
73 }
74
75 static inline void bgp_register_for_label(struct bgp_dest *dest,
76 struct bgp_path_info *pi)
77 {
78 bgp_reg_dereg_for_label(dest, pi, true);
79 }
80
81 static inline void bgp_unregister_for_label(struct bgp_dest *dest)
82 {
83 bgp_reg_dereg_for_label(dest, NULL, false);
84 }
85
86 /* Return BOS value of label stream */
87 static inline uint8_t label_bos(mpls_label_t *label)
88 {
89 uint8_t *t = (uint8_t *)label;
90 return (t[2] & 0x01);
91 };
92
93 #endif /* _BGP_LABEL_H */