]>
Commit | Line | Data |
---|---|---|
50f34207 | 1 | /* |
2 | * MPLS definitions | |
3 | * Copyright 2015 Cumulus Networks, Inc. | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published | |
9 | * by the Free Software Foundation; either version 2, or (at your | |
10 | * option) any later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
50f34207 | 20 | */ |
21 | ||
22 | #ifndef _QUAGGA_MPLS_H | |
23 | #define _QUAGGA_MPLS_H | |
24 | ||
fea12efb | 25 | #include <arpa/inet.h> |
26 | ||
50f34207 | 27 | /* Well-known MPLS label values (RFC 3032 etc). */ |
28 | #define MPLS_V4_EXP_NULL_LABEL 0 | |
29 | #define MPLS_RA_LABEL 1 | |
30 | #define MPLS_V6_EXP_NULL_LABEL 2 | |
31 | #define MPLS_IMP_NULL_LABEL 3 | |
32 | #define MPLS_ENTROPY_LABEL_INDICATOR 7 | |
33 | #define MPLS_GAL_LABEL 13 | |
34 | #define MPLS_OAM_ALERT_LABEL 14 | |
35 | #define MPLS_EXTENSION_LABEL 15 | |
36 | ||
37 | /* Minimum and maximum label values */ | |
38 | #define MPLS_MIN_RESERVED_LABEL 0 | |
39 | #define MPLS_MAX_RESERVED_LABEL 15 | |
40 | #define MPLS_MIN_UNRESERVED_LABEL 16 | |
41 | #define MPLS_MAX_UNRESERVED_LABEL 1048575 | |
42 | ||
12929668 DS |
43 | /* Default min and max SRGB label range */ |
44 | #define MPLS_DEFAULT_MIN_SRGB_LABEL 16000 | |
45 | #define MPLS_DEFAULT_MAX_SRGB_LABEL 23999 | |
46 | ||
52dd3aa4 RW |
47 | /* Maximum # labels that can be pushed. */ |
48 | #define MPLS_MAX_LABELS 16 | |
49 | ||
d62a17ae | 50 | #define IS_MPLS_RESERVED_LABEL(label) \ |
51 | (label >= MPLS_MIN_RESERVED_LABEL && label <= MPLS_MAX_RESERVED_LABEL) | |
50f34207 | 52 | |
d62a17ae | 53 | #define IS_MPLS_UNRESERVED_LABEL(label) \ |
54 | (label >= MPLS_MIN_UNRESERVED_LABEL \ | |
55 | && label <= MPLS_MAX_UNRESERVED_LABEL) | |
50f34207 | 56 | |
57 | /* Definitions for a MPLS label stack entry (RFC 3032). This encodes the | |
58 | * label, EXP, BOS and TTL fields. | |
59 | */ | |
60 | typedef unsigned int mpls_lse_t; | |
61 | ||
62 | #define MPLS_LS_LABEL_MASK 0xFFFFF000 | |
63 | #define MPLS_LS_LABEL_SHIFT 12 | |
64 | #define MPLS_LS_EXP_MASK 0x00000E00 | |
65 | #define MPLS_LS_EXP_SHIFT 9 | |
66 | #define MPLS_LS_S_MASK 0x00000100 | |
67 | #define MPLS_LS_S_SHIFT 8 | |
68 | #define MPLS_LS_TTL_MASK 0x000000FF | |
69 | #define MPLS_LS_TTL_SHIFT 0 | |
70 | ||
d62a17ae | 71 | #define MPLS_LABEL_VALUE(lse) \ |
72 | ((lse & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT) | |
73 | #define MPLS_LABEL_EXP(lse) ((lse & MPLS_LS_EXP_MASK) >> MPLS_LS_EXP_SHIFT) | |
74 | #define MPLS_LABEL_BOS(lse) ((lse & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT) | |
75 | #define MPLS_LABEL_TTL(lse) ((lse & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT) | |
50f34207 | 76 | |
77 | #define IS_MPLS_LABEL_BOS(ls) (MPLS_LABEL_BOS(ls) == 1) | |
78 | ||
79 | #define MPLS_LABEL_LEN_BITS 20 | |
80 | ||
81 | /* MPLS label value as a 32-bit (mostly we only care about the label value). */ | |
82 | typedef unsigned int mpls_label_t; | |
83 | ||
9bedbb1e DW |
84 | /* The MPLS explicit-null label is 0 which means when you memset a mpls_label_t |
85 | * to zero you have set that variable to explicit-null which was probably not | |
86 | * your intent. The work-around is to use one bit to indicate if the | |
87 | * mpls_label_t has been set by the user. MPLS_INVALID_LABEL has this bit clear | |
88 | * so that we can use MPLS_INVALID_LABEL to initialize mpls_label_t variables. | |
89 | */ | |
90 | #define MPLS_INVALID_LABEL 0xFFFDFFFF | |
50f34207 | 91 | |
ce549947 | 92 | /* LSP types. */ |
d62a17ae | 93 | enum lsp_types_t { |
94 | ZEBRA_LSP_NONE = 0, /* No LSP. */ | |
95 | ZEBRA_LSP_STATIC = 1, /* Static LSP. */ | |
96 | ZEBRA_LSP_LDP = 2, /* LDP LSP. */ | |
97 | ZEBRA_LSP_BGP = 3 /* BGP LSP. */ | |
ce549947 RW |
98 | }; |
99 | ||
50f34207 | 100 | /* Functions for basic label operations. */ |
101 | ||
102 | /* Encode a label stack entry from fields; convert to network byte-order as | |
103 | * the Netlink interface expects MPLS labels to be in this format. | |
104 | */ | |
d62a17ae | 105 | static inline mpls_lse_t mpls_lse_encode(mpls_label_t label, u_int32_t ttl, |
106 | u_int32_t exp, u_int32_t bos) | |
50f34207 | 107 | { |
d62a17ae | 108 | mpls_lse_t lse; |
109 | lse = htonl((label << MPLS_LS_LABEL_SHIFT) | (exp << MPLS_LS_EXP_SHIFT) | |
110 | | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | |
111 | | (ttl << MPLS_LS_TTL_SHIFT)); | |
112 | return lse; | |
50f34207 | 113 | } |
114 | ||
115 | /* Extract the fields from a label stack entry after converting to host-byte | |
116 | * order. This is expected to be called only for messages received over the | |
117 | * Netlink interface. | |
118 | */ | |
d62a17ae | 119 | static inline void mpls_lse_decode(mpls_lse_t lse, mpls_label_t *label, |
120 | u_int32_t *ttl, u_int32_t *exp, | |
121 | u_int32_t *bos) | |
50f34207 | 122 | { |
d62a17ae | 123 | mpls_lse_t local_lse; |
50f34207 | 124 | |
d62a17ae | 125 | local_lse = ntohl(lse); |
126 | *label = MPLS_LABEL_VALUE(local_lse); | |
127 | *exp = MPLS_LABEL_EXP(local_lse); | |
128 | *bos = MPLS_LABEL_BOS(local_lse); | |
129 | *ttl = MPLS_LABEL_TTL(local_lse); | |
50f34207 | 130 | } |
131 | ||
28d58fd7 VV |
132 | /* Invalid label index value (when used with BGP Prefix-SID). Should |
133 | * match the BGP definition. | |
134 | */ | |
135 | #define MPLS_INVALID_LABEL_INDEX 0xFFFFFFFF | |
136 | ||
50f34207 | 137 | /* Printable string for labels (with consideration for reserved values). */ |
d62a17ae | 138 | static inline char *label2str(mpls_label_t label, char *buf, size_t len) |
50f34207 | 139 | { |
d62a17ae | 140 | switch (label) { |
141 | case MPLS_V4_EXP_NULL_LABEL: | |
142 | strlcpy(buf, "IPv4 Explicit Null", len); | |
143 | return (buf); | |
144 | case MPLS_RA_LABEL: | |
145 | strlcpy(buf, "Router Alert", len); | |
146 | return (buf); | |
147 | case MPLS_V6_EXP_NULL_LABEL: | |
148 | strlcpy(buf, "IPv6 Explict Null", len); | |
149 | return (buf); | |
150 | case MPLS_IMP_NULL_LABEL: | |
151 | strlcpy(buf, "implicit-null", len); | |
152 | return (buf); | |
153 | case MPLS_ENTROPY_LABEL_INDICATOR: | |
154 | strlcpy(buf, "Entropy Label Indicator", len); | |
155 | return (buf); | |
156 | case MPLS_GAL_LABEL: | |
157 | strlcpy(buf, "Generic Associated Channel", len); | |
158 | return (buf); | |
159 | case MPLS_OAM_ALERT_LABEL: | |
160 | strlcpy(buf, "OAM Alert", len); | |
161 | return (buf); | |
162 | case MPLS_EXTENSION_LABEL: | |
163 | strlcpy(buf, "Extension", len); | |
164 | return (buf); | |
165 | default: | |
166 | if (label < 16) | |
167 | snprintf(buf, len, "Reserved (%u)", label); | |
168 | else | |
169 | snprintf(buf, len, "%u", label); | |
170 | return (buf); | |
171 | } | |
50f34207 | 172 | } |
173 | ||
eac6e3f0 RW |
174 | /* constants used by ldpd */ |
175 | #define MPLS_LABEL_IPV4NULL 0 /* IPv4 Explicit NULL Label */ | |
176 | #define MPLS_LABEL_RTALERT 1 /* Router Alert Label */ | |
177 | #define MPLS_LABEL_IPV6NULL 2 /* IPv6 Explicit NULL Label */ | |
178 | #define MPLS_LABEL_IMPLNULL 3 /* Implicit NULL Label */ | |
9d303b37 | 179 | /* MPLS_LABEL_RESERVED 4-15 */ /* Values 4-15 are reserved */ |
eac6e3f0 RW |
180 | #define MPLS_LABEL_RESERVED_MAX 15 |
181 | #define MPLS_LABEL_MAX ((1 << 20) - 1) | |
182 | ||
50f34207 | 183 | #endif |