]>
Commit | Line | Data |
---|---|---|
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 | |
27 | ||
28 | struct bgp_node; | |
29 | struct bgp_info; | |
30 | struct peer; | |
31 | ||
d62a17ae | 32 | extern void bgp_reg_dereg_for_label(struct bgp_node *rn, struct bgp_info *ri, |
33 | int reg); | |
cd1964ff | 34 | extern int bgp_parse_fec_update(void); |
9bedbb1e | 35 | extern mpls_label_t bgp_adv_label(struct bgp_node *rn, struct bgp_info *ri, |
d62a17ae | 36 | struct peer *to, afi_t afi, safi_t safi); |
cd1964ff | 37 | |
d62a17ae | 38 | extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, |
39 | struct bgp_nlri *packet); | |
cd1964ff | 40 | |
d62a17ae | 41 | static inline int bgp_labeled_safi(safi_t safi) |
cd1964ff | 42 | { |
d62a17ae | 43 | /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN |
44 | * routes will have a label. | |
45 | */ | |
46 | if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN) | |
47 | || (safi == SAFI_EVPN)) | |
48 | return 1; | |
49 | return 0; | |
cd1964ff DS |
50 | } |
51 | ||
d62a17ae | 52 | static inline int bgp_is_withdraw_label(mpls_label_t *label) |
cd1964ff | 53 | { |
d7c0a89a | 54 | uint8_t *pkt = (uint8_t *)label; |
d62a17ae | 55 | |
56 | /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label() | |
57 | * was called on the withdraw label */ | |
58 | if ((pkt[0] == 0x80) && (pkt[1] == 0x00) | |
59 | && ((pkt[2] == 0x00) || (pkt[2] == 0x02))) | |
60 | return 1; | |
61 | return 0; | |
cd1964ff DS |
62 | } |
63 | ||
d62a17ae | 64 | static inline int bgp_is_valid_label(mpls_label_t *label) |
cd1964ff | 65 | { |
d7c0a89a | 66 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 67 | if (!t) |
68 | return 0; | |
69 | return (t[2] & 0x02); | |
cd1964ff DS |
70 | } |
71 | ||
d62a17ae | 72 | static inline void bgp_set_valid_label(mpls_label_t *label) |
cd1964ff | 73 | { |
d7c0a89a | 74 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 75 | if (t) |
76 | t[2] |= 0x02; | |
cd1964ff DS |
77 | } |
78 | ||
d62a17ae | 79 | static inline void bgp_unset_valid_label(mpls_label_t *label) |
cd1964ff | 80 | { |
d7c0a89a | 81 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 82 | if (t) |
83 | t[2] &= ~0x02; | |
cd1964ff DS |
84 | } |
85 | ||
d62a17ae | 86 | static inline void bgp_register_for_label(struct bgp_node *rn, |
87 | struct bgp_info *ri) | |
cd1964ff | 88 | { |
d62a17ae | 89 | bgp_reg_dereg_for_label(rn, ri, 1); |
cd1964ff DS |
90 | } |
91 | ||
d62a17ae | 92 | static inline void bgp_unregister_for_label(struct bgp_node *rn) |
cd1964ff | 93 | { |
d62a17ae | 94 | bgp_reg_dereg_for_label(rn, NULL, 0); |
cd1964ff DS |
95 | } |
96 | ||
97 | /* Label stream to value */ | |
d7c0a89a | 98 | static inline uint32_t label_pton(mpls_label_t *label) |
cd1964ff | 99 | { |
d7c0a89a | 100 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 101 | return ((((unsigned int)t[0]) << 12) | (((unsigned int)t[1]) << 4) |
102 | | ((unsigned int)((t[2] & 0xF0) >> 4))); | |
cd1964ff DS |
103 | } |
104 | ||
105 | /* Encode label values */ | |
d7c0a89a | 106 | static inline void label_ntop(uint32_t l, int bos, mpls_label_t *label) |
cd1964ff | 107 | { |
d7c0a89a | 108 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 109 | t[0] = ((l & 0x000FF000) >> 12); |
110 | t[1] = ((l & 0x00000FF0) >> 4); | |
111 | t[2] = ((l & 0x0000000F) << 4); | |
112 | if (bos) | |
113 | t[2] |= 0x01; | |
cd1964ff DS |
114 | } |
115 | ||
116 | /* Return BOS value of label stream */ | |
d7c0a89a | 117 | static inline uint8_t label_bos(mpls_label_t *label) |
cd1964ff | 118 | { |
d7c0a89a | 119 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 120 | return (t[2] & 0x01); |
cd1964ff DS |
121 | }; |
122 | ||
123 | #endif /* _BGP_LABEL_H */ |