]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_label.h
*: make consistent & update GPLv2 file headers
[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
28 struct bgp_node;
29 struct bgp_info;
30 struct peer;
31
32 extern void bgp_reg_dereg_for_label (struct bgp_node *rn, struct bgp_info *ri,
33 int reg);
34 extern int bgp_parse_fec_update(void);
35 extern u_char * bgp_adv_label(struct bgp_node *rn, struct bgp_info *ri,
36 struct peer *to, afi_t afi, safi_t safi);
37
38 extern int bgp_nlri_parse_label (struct peer *peer, struct attr *attr,
39 struct bgp_nlri *packet);
40
41 static inline int
42 bgp_labeled_safi (safi_t safi)
43 {
44 if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN) ||
45 (safi == SAFI_EVPN))
46 return 1;
47 return 0;
48 }
49
50 static inline int
51 bgp_is_withdraw_label (u_char *pkt)
52 {
53 if ((pkt[0] == 0x80) && (pkt[1] == 0x00) && (pkt[2] == 0x00))
54 return 1;
55 return 0;
56 }
57
58 static inline u_char *
59 bgp_encode_withdraw_label (u_char *pkt)
60 {
61 *pkt++ = 0x80; *pkt++ = 0x00; *pkt++ = 0x00;
62 return pkt;
63 }
64
65 static inline int
66 bgp_is_valid_label (u_char *t)
67 {
68 if (!t)
69 return 0;
70 return (t[2] & 0x02);
71 }
72
73 static inline void
74 bgp_set_valid_label (u_char *t)
75 {
76 if (t)
77 t[2] |= 0x02;
78 }
79
80 static inline void
81 bgp_unset_valid_label (u_char *t)
82 {
83 if (t)
84 t[2] &= ~0x02;
85 }
86
87 static inline void
88 bgp_register_for_label (struct bgp_node *rn, struct bgp_info *ri)
89 {
90 bgp_reg_dereg_for_label (rn, ri, 1);
91 }
92
93 static inline void
94 bgp_unregister_for_label (struct bgp_node *rn)
95 {
96 bgp_reg_dereg_for_label (rn, NULL, 0);
97 }
98
99 /* Label stream to value */
100 static inline u_int32_t
101 label_pton (u_char t[])
102 {
103 return ((((unsigned int) t[0]) << 12) | (((unsigned int) t[1]) << 4) |
104 ((unsigned int) ((t[2] & 0xF0) >> 4)));
105 }
106
107 /* Encode label values */
108 static inline void
109 label_ntop (u_int32_t l, int bos, u_char t[])
110 {
111 t[0] = ((l & 0x000FF000) >> 12);
112 t[1] = ((l & 0x00000FF0) >> 4);
113 t[2] = ((l & 0x0000000F) << 4);
114 if (bos)
115 t[2] |= 0x01;
116 }
117
118 /* Return BOS value of label stream */
119 static inline u_char
120 label_bos (u_char t[])
121 {
122 return (t[2] & 0x01);
123 };
124
125 #endif /* _BGP_LABEL_H */