]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
cd1964ff DS |
2 | /* BGP carrying Label information |
3 | * Copyright (C) 2013 Cumulus Networks, Inc. | |
cd1964ff DS |
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 | |
13b7e7f0 | 12 | #define BGP_PREVENT_VRF_2_VRF_LEAK 0xFFFFFFFE |
cd1964ff | 13 | |
9bcb3eef | 14 | struct bgp_dest; |
4b7e6066 | 15 | struct bgp_path_info; |
cd1964ff DS |
16 | struct peer; |
17 | ||
57592a53 AD |
18 | extern int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid, |
19 | bool allocated); | |
9bcb3eef | 20 | extern void bgp_reg_dereg_for_label(struct bgp_dest *dest, |
57592a53 | 21 | struct bgp_path_info *pi, bool reg); |
cd1964ff | 22 | extern int bgp_parse_fec_update(void); |
9bcb3eef DS |
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); | |
cd1964ff | 26 | |
d62a17ae | 27 | extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, |
28 | struct bgp_nlri *packet); | |
cd1964ff | 29 | |
d62a17ae | 30 | static inline int bgp_labeled_safi(safi_t safi) |
cd1964ff | 31 | { |
d62a17ae | 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; | |
cd1964ff DS |
39 | } |
40 | ||
d62a17ae | 41 | static inline int bgp_is_withdraw_label(mpls_label_t *label) |
cd1964ff | 42 | { |
d7c0a89a | 43 | uint8_t *pkt = (uint8_t *)label; |
d62a17ae | 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 */ | |
6b9ce3dc | 47 | if (((pkt[0] == 0x80) || (pkt[0] == 0x00)) && (pkt[1] == 0x00) |
d62a17ae | 48 | && ((pkt[2] == 0x00) || (pkt[2] == 0x02))) |
49 | return 1; | |
50 | return 0; | |
cd1964ff DS |
51 | } |
52 | ||
edfee30d | 53 | static inline int bgp_is_valid_label(const mpls_label_t *label) |
cd1964ff | 54 | { |
d7c0a89a | 55 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 56 | if (!t) |
57 | return 0; | |
58 | return (t[2] & 0x02); | |
cd1964ff DS |
59 | } |
60 | ||
d62a17ae | 61 | static inline void bgp_set_valid_label(mpls_label_t *label) |
cd1964ff | 62 | { |
d7c0a89a | 63 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 64 | if (t) |
65 | t[2] |= 0x02; | |
cd1964ff DS |
66 | } |
67 | ||
d62a17ae | 68 | static inline void bgp_unset_valid_label(mpls_label_t *label) |
cd1964ff | 69 | { |
d7c0a89a | 70 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 71 | if (t) |
72 | t[2] &= ~0x02; | |
cd1964ff DS |
73 | } |
74 | ||
9bcb3eef | 75 | static inline void bgp_register_for_label(struct bgp_dest *dest, |
40381db7 | 76 | struct bgp_path_info *pi) |
cd1964ff | 77 | { |
9bcb3eef | 78 | bgp_reg_dereg_for_label(dest, pi, true); |
cd1964ff DS |
79 | } |
80 | ||
9bcb3eef | 81 | static inline void bgp_unregister_for_label(struct bgp_dest *dest) |
cd1964ff | 82 | { |
9bcb3eef | 83 | bgp_reg_dereg_for_label(dest, NULL, false); |
cd1964ff DS |
84 | } |
85 | ||
cd1964ff | 86 | /* Return BOS value of label stream */ |
d7c0a89a | 87 | static inline uint8_t label_bos(mpls_label_t *label) |
cd1964ff | 88 | { |
d7c0a89a | 89 | uint8_t *t = (uint8_t *)label; |
d62a17ae | 90 | return (t[2] & 0x01); |
cd1964ff DS |
91 | }; |
92 | ||
93 | #endif /* _BGP_LABEL_H */ |