]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_label.h
1 /* BGP carrying Label information
2 * Copyright (C) 2013 Cumulus Networks, Inc.
4 * This file is part of GNU Zebra.
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
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.
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
24 #define BGP_LABEL_BYTES 3
25 #define BGP_LABEL_BITS 24
26 #define BGP_WITHDRAW_LABEL 0x800000
32 extern void bgp_reg_dereg_for_label (struct bgp_node
*rn
, struct bgp_info
*ri
,
34 extern int bgp_parse_fec_update(void);
35 extern mpls_label_t
bgp_adv_label(struct bgp_node
*rn
, struct bgp_info
*ri
,
36 struct peer
*to
, afi_t afi
, safi_t safi
);
38 extern int bgp_nlri_parse_label (struct peer
*peer
, struct attr
*attr
,
39 struct bgp_nlri
*packet
);
42 bgp_labeled_safi (safi_t safi
)
44 /* NOTE: This API really says a label (tag) MAY be present. Not all EVPN
45 * routes will have a label.
47 if ((safi
== SAFI_LABELED_UNICAST
) || (safi
== SAFI_MPLS_VPN
) ||
54 bgp_is_withdraw_label (mpls_label_t
*label
)
56 u_char
*pkt
= (u_char
*) label
;
58 /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label()
59 * was called on the withdraw label */
60 if ((pkt
[0] == 0x80) && (pkt
[1] == 0x00) && ((pkt
[2] == 0x00) || (pkt
[2] == 0x02)))
66 bgp_is_valid_label (mpls_label_t
*label
)
68 u_char
*t
= (u_char
*) label
;
75 bgp_set_valid_label (mpls_label_t
*label
)
77 u_char
*t
= (u_char
*) label
;
83 bgp_unset_valid_label (mpls_label_t
*label
)
85 u_char
*t
= (u_char
*) label
;
91 bgp_register_for_label (struct bgp_node
*rn
, struct bgp_info
*ri
)
93 bgp_reg_dereg_for_label (rn
, ri
, 1);
97 bgp_unregister_for_label (struct bgp_node
*rn
)
99 bgp_reg_dereg_for_label (rn
, NULL
, 0);
102 /* Label stream to value */
103 static inline u_int32_t
104 label_pton (mpls_label_t
*label
)
106 u_char
*t
= (u_char
*) label
;
107 return ((((unsigned int) t
[0]) << 12) | (((unsigned int) t
[1]) << 4) |
108 ((unsigned int) ((t
[2] & 0xF0) >> 4)));
111 /* Encode label values */
113 label_ntop (u_int32_t l
, int bos
, mpls_label_t
*label
)
115 u_char
*t
= (u_char
*) label
;
116 t
[0] = ((l
& 0x000FF000) >> 12);
117 t
[1] = ((l
& 0x00000FF0) >> 4);
118 t
[2] = ((l
& 0x0000000F) << 4);
123 /* Return BOS value of label stream */
125 label_bos (mpls_label_t
*label
)
127 u_char
*t
= (u_char
*) label
;
128 return (t
[2] & 0x01);
131 #endif /* _BGP_LABEL_H */