]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_label.h
Merge pull request #5644 from donaldsharp/more_pim_doc
[mirror_frr.git] / bgpd / bgp_label.h
1 /* BGP carrying Label information
2 * Copyright (C) 2013 Cumulus Networks, Inc.
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _BGP_LABEL_H
22 #define _BGP_LABEL_H
23
24 #define BGP_LABEL_BYTES 3
25 #define BGP_LABEL_BITS 24
26 #define BGP_WITHDRAW_LABEL 0x800000
27 #define BGP_PREVENT_VRF_2_VRF_LEAK 0xFFFFFFFE
28
29 struct bgp_node;
30 struct bgp_path_info;
31 struct peer;
32
33 extern int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid,
34 bool allocated);
35 extern void bgp_reg_dereg_for_label(struct bgp_node *rn,
36 struct bgp_path_info *pi, bool reg);
37 extern int bgp_parse_fec_update(void);
38 extern mpls_label_t bgp_adv_label(struct bgp_node *rn, struct bgp_path_info *pi,
39 struct peer *to, afi_t afi, safi_t safi);
40
41 extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
42 struct bgp_nlri *packet);
43
44 static inline int bgp_labeled_safi(safi_t safi)
45 {
46 /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN
47 * routes will have a label.
48 */
49 if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN)
50 || (safi == SAFI_EVPN))
51 return 1;
52 return 0;
53 }
54
55 static inline int bgp_is_withdraw_label(mpls_label_t *label)
56 {
57 uint8_t *pkt = (uint8_t *)label;
58
59 /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label()
60 * was called on the withdraw label */
61 if (((pkt[0] == 0x80) || (pkt[0] == 0x00)) && (pkt[1] == 0x00)
62 && ((pkt[2] == 0x00) || (pkt[2] == 0x02)))
63 return 1;
64 return 0;
65 }
66
67 static inline int bgp_is_valid_label(mpls_label_t *label)
68 {
69 uint8_t *t = (uint8_t *)label;
70 if (!t)
71 return 0;
72 return (t[2] & 0x02);
73 }
74
75 static inline void bgp_set_valid_label(mpls_label_t *label)
76 {
77 uint8_t *t = (uint8_t *)label;
78 if (t)
79 t[2] |= 0x02;
80 }
81
82 static inline void bgp_unset_valid_label(mpls_label_t *label)
83 {
84 uint8_t *t = (uint8_t *)label;
85 if (t)
86 t[2] &= ~0x02;
87 }
88
89 static inline void bgp_register_for_label(struct bgp_node *rn,
90 struct bgp_path_info *pi)
91 {
92 bgp_reg_dereg_for_label(rn, pi, true);
93 }
94
95 static inline void bgp_unregister_for_label(struct bgp_node *rn)
96 {
97 bgp_reg_dereg_for_label(rn, NULL, false);
98 }
99
100 /* Label stream to value */
101 static inline uint32_t label_pton(mpls_label_t *label)
102 {
103 uint8_t *t = (uint8_t *)label;
104 return ((((unsigned int)t[0]) << 12) | (((unsigned int)t[1]) << 4)
105 | ((unsigned int)((t[2] & 0xF0) >> 4)));
106 }
107
108 /* Encode label values */
109 static inline void label_ntop(uint32_t l, int bos, mpls_label_t *label)
110 {
111 uint8_t *t = (uint8_t *)label;
112 t[0] = ((l & 0x000FF000) >> 12);
113 t[1] = ((l & 0x00000FF0) >> 4);
114 t[2] = ((l & 0x0000000F) << 4);
115 if (bos)
116 t[2] |= 0x01;
117 }
118
119 /* Return BOS value of label stream */
120 static inline uint8_t label_bos(mpls_label_t *label)
121 {
122 uint8_t *t = (uint8_t *)label;
123 return (t[2] & 0x01);
124 };
125
126 #endif /* _BGP_LABEL_H */