]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_label.h
Merge pull request #531 from qlyoung/fix-stack-ref
[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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #ifndef _BGP_LABEL_H
23 #define _BGP_LABEL_H
24
25 #define BGP_LABEL_BYTES 3
26 #define BGP_LABEL_BITS 24
27 #define BGP_WITHDRAW_LABEL 0x800000
28
29 struct bgp_node;
30 struct bgp_info;
31 struct peer;
32
33 extern void bgp_reg_dereg_for_label (struct bgp_node *rn, struct bgp_info *ri,
34 int reg);
35 extern int bgp_parse_fec_update(void);
36 extern u_char * bgp_adv_label(struct bgp_node *rn, struct bgp_info *ri,
37 struct peer *to, afi_t afi, safi_t safi);
38
39 extern int bgp_nlri_parse_label (struct peer *peer, struct attr *attr,
40 struct bgp_nlri *packet);
41
42 static inline int
43 bgp_labeled_safi (safi_t safi)
44 {
45 if ((safi == SAFI_LABELED_UNICAST) || (safi == SAFI_MPLS_VPN) ||
46 (safi == SAFI_EVPN))
47 return 1;
48 return 0;
49 }
50
51 static inline int
52 bgp_is_withdraw_label (u_char *pkt)
53 {
54 if ((pkt[0] == 0x80) && (pkt[1] == 0x00) && (pkt[2] == 0x00))
55 return 1;
56 return 0;
57 }
58
59 static inline u_char *
60 bgp_encode_withdraw_label (u_char *pkt)
61 {
62 *pkt++ = 0x80; *pkt++ = 0x00; *pkt++ = 0x00;
63 return pkt;
64 }
65
66 static inline int
67 bgp_is_valid_label (u_char *t)
68 {
69 if (!t)
70 return 0;
71 return (t[2] & 0x02);
72 }
73
74 static inline void
75 bgp_set_valid_label (u_char *t)
76 {
77 if (t)
78 t[2] |= 0x02;
79 }
80
81 static inline void
82 bgp_unset_valid_label (u_char *t)
83 {
84 if (t)
85 t[2] &= ~0x02;
86 }
87
88 static inline void
89 bgp_register_for_label (struct bgp_node *rn, struct bgp_info *ri)
90 {
91 bgp_reg_dereg_for_label (rn, ri, 1);
92 }
93
94 static inline void
95 bgp_unregister_for_label (struct bgp_node *rn)
96 {
97 bgp_reg_dereg_for_label (rn, NULL, 0);
98 }
99
100 /* Label stream to value */
101 static inline u_int32_t
102 label_pton (u_char t[])
103 {
104 return ((((unsigned int) t[0]) << 12) | (((unsigned int) t[1]) << 4) |
105 ((unsigned int) ((t[2] & 0xF0) >> 4)));
106 }
107
108 /* Encode label values */
109 static inline void
110 label_ntop (u_int32_t l, int bos, u_char t[])
111 {
112 t[0] = ((l & 0x000FF000) >> 12);
113 t[1] = ((l & 0x00000FF0) >> 4);
114 t[2] = ((l & 0x0000000F) << 4);
115 if (bos)
116 t[2] |= 0x01;
117 }
118
119 /* Return BOS value of label stream */
120 static inline u_char
121 label_bos (u_char t[])
122 {
123 return (t[2] & 0x01);
124 };
125
126 #endif /* _BGP_LABEL_H */