]>
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 | ||
70e98a7f DS |
27 | #ifdef MPLS_LABEL_MAX |
28 | #undef MPLS_LABEL_MAX | |
29 | #endif | |
30 | ||
50f34207 | 31 | /* Well-known MPLS label values (RFC 3032 etc). */ |
70e98a7f DS |
32 | #define MPLS_LABEL_IPV4_EXPLICIT_NULL 0 /* [RFC3032] */ |
33 | #define MPLS_LABEL_ROUTER_ALERT 1 /* [RFC3032] */ | |
34 | #define MPLS_LABEL_IPV6_EXPLICIT_NULL 2 /* [RFC3032] */ | |
35 | #define MPLS_LABEL_IMPLICIT_NULL 3 /* [RFC3032] */ | |
36 | #define MPLS_LABEL_ELI 7 /* [RFC6790] */ | |
37 | #define MPLS_LABEL_GAL 13 /* [RFC5586] */ | |
38 | #define MPLS_LABEL_OAM_ALERT 14 /* [RFC3429] */ | |
39 | #define MPLS_LABEL_EXTENSION 15 /* [RFC7274] */ | |
40 | #define MPLS_LABEL_MAX 1048575 | |
42567e00 | 41 | #define MPLS_LABEL_NONE 0xFFFFFFFF /* for internal use only */ |
50f34207 | 42 | |
43 | /* Minimum and maximum label values */ | |
70e98a7f DS |
44 | #define MPLS_LABEL_RESERVED_MIN 0 |
45 | #define MPLS_LABEL_RESERVED_MAX 15 | |
46 | #define MPLS_LABEL_UNRESERVED_MIN 16 | |
47 | #define MPLS_LABEL_UNRESERVED_MAX 1048575 | |
50f34207 | 48 | |
12929668 | 49 | /* Default min and max SRGB label range */ |
7726c479 OD |
50 | /* Even if the SRGB allows to manage different Label space between routers, |
51 | * if an operator want to use the same SRGB for all its router, we must fix | |
52 | * a common range. However, Cisco start its SRGB at 16000 and Juniper ends | |
53 | * its SRGB at 16384 for OSPF. Thus, by fixing the minimum SRGB label to | |
54 | * 8000 we could deal with both Cisco and Juniper. | |
55 | */ | |
56 | #define MPLS_DEFAULT_MIN_SRGB_LABEL 8000 | |
cf9b9f77 OD |
57 | #define MPLS_DEFAULT_MAX_SRGB_LABEL 50000 |
58 | #define MPLS_DEFAULT_MIN_SRGB_SIZE 5000 | |
59 | #define MPLS_DEFAULT_MAX_SRGB_SIZE 20000 | |
12929668 | 60 | |
52dd3aa4 RW |
61 | /* Maximum # labels that can be pushed. */ |
62 | #define MPLS_MAX_LABELS 16 | |
63 | ||
d62a17ae | 64 | #define IS_MPLS_RESERVED_LABEL(label) \ |
70e98a7f | 65 | (label >= MPLS_LABEL_RESERVED_MIN && label <= MPLS_LABEL_RESERVED_MAX) |
50f34207 | 66 | |
d62a17ae | 67 | #define IS_MPLS_UNRESERVED_LABEL(label) \ |
70e98a7f DS |
68 | (label >= MPLS_LABEL_UNRESERVED_MIN \ |
69 | && label <= MPLS_LABEL_UNRESERVED_MAX) | |
50f34207 | 70 | |
71 | /* Definitions for a MPLS label stack entry (RFC 3032). This encodes the | |
72 | * label, EXP, BOS and TTL fields. | |
73 | */ | |
74 | typedef unsigned int mpls_lse_t; | |
75 | ||
76 | #define MPLS_LS_LABEL_MASK 0xFFFFF000 | |
77 | #define MPLS_LS_LABEL_SHIFT 12 | |
78 | #define MPLS_LS_EXP_MASK 0x00000E00 | |
79 | #define MPLS_LS_EXP_SHIFT 9 | |
80 | #define MPLS_LS_S_MASK 0x00000100 | |
81 | #define MPLS_LS_S_SHIFT 8 | |
82 | #define MPLS_LS_TTL_MASK 0x000000FF | |
83 | #define MPLS_LS_TTL_SHIFT 0 | |
84 | ||
d62a17ae | 85 | #define MPLS_LABEL_VALUE(lse) \ |
86 | ((lse & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT) | |
87 | #define MPLS_LABEL_EXP(lse) ((lse & MPLS_LS_EXP_MASK) >> MPLS_LS_EXP_SHIFT) | |
88 | #define MPLS_LABEL_BOS(lse) ((lse & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT) | |
89 | #define MPLS_LABEL_TTL(lse) ((lse & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT) | |
50f34207 | 90 | |
91 | #define IS_MPLS_LABEL_BOS(ls) (MPLS_LABEL_BOS(ls) == 1) | |
92 | ||
93 | #define MPLS_LABEL_LEN_BITS 20 | |
94 | ||
95 | /* MPLS label value as a 32-bit (mostly we only care about the label value). */ | |
96 | typedef unsigned int mpls_label_t; | |
97 | ||
8ecdb26e DS |
98 | struct mpls_label_stack { |
99 | uint8_t num_labels; | |
100 | uint8_t reserved[3]; | |
101 | mpls_label_t label[0]; /* 1 or more labels */ | |
102 | }; | |
103 | ||
9bedbb1e DW |
104 | /* The MPLS explicit-null label is 0 which means when you memset a mpls_label_t |
105 | * to zero you have set that variable to explicit-null which was probably not | |
106 | * your intent. The work-around is to use one bit to indicate if the | |
107 | * mpls_label_t has been set by the user. MPLS_INVALID_LABEL has this bit clear | |
108 | * so that we can use MPLS_INVALID_LABEL to initialize mpls_label_t variables. | |
109 | */ | |
110 | #define MPLS_INVALID_LABEL 0xFFFDFFFF | |
50f34207 | 111 | |
ce549947 | 112 | /* LSP types. */ |
d62a17ae | 113 | enum lsp_types_t { |
114 | ZEBRA_LSP_NONE = 0, /* No LSP. */ | |
115 | ZEBRA_LSP_STATIC = 1, /* Static LSP. */ | |
116 | ZEBRA_LSP_LDP = 2, /* LDP LSP. */ | |
cf9b9f77 | 117 | ZEBRA_LSP_BGP = 3, /* BGP LSP. */ |
339e36d2 DS |
118 | ZEBRA_LSP_SR = 4, /* Segment Routing LSP. */ |
119 | ZEBRA_LSP_SHARP = 5, /* Identifier for test protocol */ | |
ce549947 RW |
120 | }; |
121 | ||
50f34207 | 122 | /* Functions for basic label operations. */ |
123 | ||
124 | /* Encode a label stack entry from fields; convert to network byte-order as | |
125 | * the Netlink interface expects MPLS labels to be in this format. | |
126 | */ | |
d62a17ae | 127 | static inline mpls_lse_t mpls_lse_encode(mpls_label_t label, u_int32_t ttl, |
128 | u_int32_t exp, u_int32_t bos) | |
50f34207 | 129 | { |
d62a17ae | 130 | mpls_lse_t lse; |
131 | lse = htonl((label << MPLS_LS_LABEL_SHIFT) | (exp << MPLS_LS_EXP_SHIFT) | |
132 | | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | |
133 | | (ttl << MPLS_LS_TTL_SHIFT)); | |
134 | return lse; | |
50f34207 | 135 | } |
136 | ||
137 | /* Extract the fields from a label stack entry after converting to host-byte | |
138 | * order. This is expected to be called only for messages received over the | |
139 | * Netlink interface. | |
140 | */ | |
d62a17ae | 141 | static inline void mpls_lse_decode(mpls_lse_t lse, mpls_label_t *label, |
142 | u_int32_t *ttl, u_int32_t *exp, | |
143 | u_int32_t *bos) | |
50f34207 | 144 | { |
d62a17ae | 145 | mpls_lse_t local_lse; |
50f34207 | 146 | |
d62a17ae | 147 | local_lse = ntohl(lse); |
148 | *label = MPLS_LABEL_VALUE(local_lse); | |
149 | *exp = MPLS_LABEL_EXP(local_lse); | |
150 | *bos = MPLS_LABEL_BOS(local_lse); | |
151 | *ttl = MPLS_LABEL_TTL(local_lse); | |
50f34207 | 152 | } |
153 | ||
28d58fd7 VV |
154 | /* Invalid label index value (when used with BGP Prefix-SID). Should |
155 | * match the BGP definition. | |
156 | */ | |
157 | #define MPLS_INVALID_LABEL_INDEX 0xFFFFFFFF | |
158 | ||
50f34207 | 159 | /* Printable string for labels (with consideration for reserved values). */ |
d62a17ae | 160 | static inline char *label2str(mpls_label_t label, char *buf, size_t len) |
50f34207 | 161 | { |
d62a17ae | 162 | switch (label) { |
70e98a7f | 163 | case MPLS_LABEL_IPV4_EXPLICIT_NULL: |
d62a17ae | 164 | strlcpy(buf, "IPv4 Explicit Null", len); |
165 | return (buf); | |
70e98a7f | 166 | case MPLS_LABEL_ROUTER_ALERT: |
d62a17ae | 167 | strlcpy(buf, "Router Alert", len); |
168 | return (buf); | |
70e98a7f | 169 | case MPLS_LABEL_IPV6_EXPLICIT_NULL: |
d62a17ae | 170 | strlcpy(buf, "IPv6 Explict Null", len); |
171 | return (buf); | |
70e98a7f | 172 | case MPLS_LABEL_IMPLICIT_NULL: |
d62a17ae | 173 | strlcpy(buf, "implicit-null", len); |
174 | return (buf); | |
70e98a7f | 175 | case MPLS_LABEL_ELI: |
d62a17ae | 176 | strlcpy(buf, "Entropy Label Indicator", len); |
177 | return (buf); | |
70e98a7f | 178 | case MPLS_LABEL_GAL: |
d62a17ae | 179 | strlcpy(buf, "Generic Associated Channel", len); |
180 | return (buf); | |
70e98a7f | 181 | case MPLS_LABEL_OAM_ALERT: |
d62a17ae | 182 | strlcpy(buf, "OAM Alert", len); |
183 | return (buf); | |
70e98a7f | 184 | case MPLS_LABEL_EXTENSION: |
d62a17ae | 185 | strlcpy(buf, "Extension", len); |
186 | return (buf); | |
187 | default: | |
188 | if (label < 16) | |
189 | snprintf(buf, len, "Reserved (%u)", label); | |
190 | else | |
191 | snprintf(buf, len, "%u", label); | |
192 | return (buf); | |
193 | } | |
50f34207 | 194 | } |
195 | ||
eac6e3f0 | 196 | |
50f34207 | 197 | #endif |