]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_label.h
Merge pull request #9440 from dlqs/dplanehook2
[mirror_frr.git] / bgpd / bgp_label.h
CommitLineData
cd1964ff
DS
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 *
896014f4
DL
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
cd1964ff
DS
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
13b7e7f0 27#define BGP_PREVENT_VRF_2_VRF_LEAK 0xFFFFFFFE
cd1964ff 28
9bcb3eef 29struct bgp_dest;
4b7e6066 30struct bgp_path_info;
cd1964ff
DS
31struct peer;
32
57592a53
AD
33extern int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid,
34 bool allocated);
9bcb3eef 35extern void bgp_reg_dereg_for_label(struct bgp_dest *dest,
57592a53 36 struct bgp_path_info *pi, bool reg);
cd1964ff 37extern int bgp_parse_fec_update(void);
9bcb3eef
DS
38extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
39 struct bgp_path_info *pi, struct peer *to,
40 afi_t afi, safi_t safi);
cd1964ff 41
d62a17ae 42extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
43 struct bgp_nlri *packet);
cd1964ff 44
d62a17ae 45static inline int bgp_labeled_safi(safi_t safi)
cd1964ff 46{
d62a17ae 47 /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN
48 * routes will have a label.
49 */
50 if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN)
51 || (safi == SAFI_EVPN))
52 return 1;
53 return 0;
cd1964ff
DS
54}
55
d62a17ae 56static inline int bgp_is_withdraw_label(mpls_label_t *label)
cd1964ff 57{
d7c0a89a 58 uint8_t *pkt = (uint8_t *)label;
d62a17ae 59
60 /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label()
61 * was called on the withdraw label */
6b9ce3dc 62 if (((pkt[0] == 0x80) || (pkt[0] == 0x00)) && (pkt[1] == 0x00)
d62a17ae 63 && ((pkt[2] == 0x00) || (pkt[2] == 0x02)))
64 return 1;
65 return 0;
cd1964ff
DS
66}
67
d62a17ae 68static inline int bgp_is_valid_label(mpls_label_t *label)
cd1964ff 69{
d7c0a89a 70 uint8_t *t = (uint8_t *)label;
d62a17ae 71 if (!t)
72 return 0;
73 return (t[2] & 0x02);
cd1964ff
DS
74}
75
d62a17ae 76static inline void bgp_set_valid_label(mpls_label_t *label)
cd1964ff 77{
d7c0a89a 78 uint8_t *t = (uint8_t *)label;
d62a17ae 79 if (t)
80 t[2] |= 0x02;
cd1964ff
DS
81}
82
d62a17ae 83static inline void bgp_unset_valid_label(mpls_label_t *label)
cd1964ff 84{
d7c0a89a 85 uint8_t *t = (uint8_t *)label;
d62a17ae 86 if (t)
87 t[2] &= ~0x02;
cd1964ff
DS
88}
89
9bcb3eef 90static inline void bgp_register_for_label(struct bgp_dest *dest,
40381db7 91 struct bgp_path_info *pi)
cd1964ff 92{
9bcb3eef 93 bgp_reg_dereg_for_label(dest, pi, true);
cd1964ff
DS
94}
95
9bcb3eef 96static inline void bgp_unregister_for_label(struct bgp_dest *dest)
cd1964ff 97{
9bcb3eef 98 bgp_reg_dereg_for_label(dest, NULL, false);
cd1964ff
DS
99}
100
101/* Label stream to value */
d7c0a89a 102static inline uint32_t label_pton(mpls_label_t *label)
cd1964ff 103{
d7c0a89a 104 uint8_t *t = (uint8_t *)label;
d62a17ae 105 return ((((unsigned int)t[0]) << 12) | (((unsigned int)t[1]) << 4)
106 | ((unsigned int)((t[2] & 0xF0) >> 4)));
cd1964ff
DS
107}
108
109/* Encode label values */
d7c0a89a 110static inline void label_ntop(uint32_t l, int bos, mpls_label_t *label)
cd1964ff 111{
d7c0a89a 112 uint8_t *t = (uint8_t *)label;
d62a17ae 113 t[0] = ((l & 0x000FF000) >> 12);
114 t[1] = ((l & 0x00000FF0) >> 4);
115 t[2] = ((l & 0x0000000F) << 4);
116 if (bos)
117 t[2] |= 0x01;
cd1964ff
DS
118}
119
120/* Return BOS value of label stream */
d7c0a89a 121static inline uint8_t label_bos(mpls_label_t *label)
cd1964ff 122{
d7c0a89a 123 uint8_t *t = (uint8_t *)label;
d62a17ae 124 return (t[2] & 0x01);
cd1964ff
DS
125};
126
127#endif /* _BGP_LABEL_H */