]>
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 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with GNU Zebra; see the file COPYING. If not, write to the | |
19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | * Boston, MA 02111-1307, USA. | |
21 | */ | |
22 | ||
23 | #ifndef _QUAGGA_MPLS_H | |
24 | #define _QUAGGA_MPLS_H | |
25 | ||
fea12efb | 26 | #include <arpa/inet.h> |
27 | ||
50f34207 | 28 | /* Well-known MPLS label values (RFC 3032 etc). */ |
29 | #define MPLS_V4_EXP_NULL_LABEL 0 | |
30 | #define MPLS_RA_LABEL 1 | |
31 | #define MPLS_V6_EXP_NULL_LABEL 2 | |
32 | #define MPLS_IMP_NULL_LABEL 3 | |
33 | #define MPLS_ENTROPY_LABEL_INDICATOR 7 | |
34 | #define MPLS_GAL_LABEL 13 | |
35 | #define MPLS_OAM_ALERT_LABEL 14 | |
36 | #define MPLS_EXTENSION_LABEL 15 | |
37 | ||
38 | /* Minimum and maximum label values */ | |
39 | #define MPLS_MIN_RESERVED_LABEL 0 | |
40 | #define MPLS_MAX_RESERVED_LABEL 15 | |
41 | #define MPLS_MIN_UNRESERVED_LABEL 16 | |
42 | #define MPLS_MAX_UNRESERVED_LABEL 1048575 | |
43 | ||
44 | #define IS_MPLS_RESERVED_LABEL(label) \ | |
45 | (label >= MPLS_MIN_RESERVED_LABEL && label <= MPLS_MAX_RESERVED_LABEL) | |
46 | ||
47 | #define IS_MPLS_UNRESERVED_LABEL(label) \ | |
48 | (label >= MPLS_MIN_UNRESERVED_LABEL && label <= MPLS_MAX_UNRESERVED_LABEL) | |
49 | ||
50 | /* Definitions for a MPLS label stack entry (RFC 3032). This encodes the | |
51 | * label, EXP, BOS and TTL fields. | |
52 | */ | |
53 | typedef unsigned int mpls_lse_t; | |
54 | ||
55 | #define MPLS_LS_LABEL_MASK 0xFFFFF000 | |
56 | #define MPLS_LS_LABEL_SHIFT 12 | |
57 | #define MPLS_LS_EXP_MASK 0x00000E00 | |
58 | #define MPLS_LS_EXP_SHIFT 9 | |
59 | #define MPLS_LS_S_MASK 0x00000100 | |
60 | #define MPLS_LS_S_SHIFT 8 | |
61 | #define MPLS_LS_TTL_MASK 0x000000FF | |
62 | #define MPLS_LS_TTL_SHIFT 0 | |
63 | ||
64 | #define MPLS_LABEL_VALUE(lse) \ | |
65 | ((lse & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT) | |
66 | #define MPLS_LABEL_EXP(lse) \ | |
67 | ((lse & MPLS_LS_EXP_MASK) >> MPLS_LS_EXP_SHIFT) | |
68 | #define MPLS_LABEL_BOS(lse) \ | |
69 | ((lse & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT) | |
70 | #define MPLS_LABEL_TTL(lse) \ | |
71 | ((lse & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT) | |
72 | ||
73 | #define IS_MPLS_LABEL_BOS(ls) (MPLS_LABEL_BOS(ls) == 1) | |
74 | ||
75 | #define MPLS_LABEL_LEN_BITS 20 | |
76 | ||
77 | /* MPLS label value as a 32-bit (mostly we only care about the label value). */ | |
78 | typedef unsigned int mpls_label_t; | |
79 | ||
ce549947 | 80 | #define MPLS_NO_LABEL 0xFFFFFFFF |
50f34207 | 81 | #define MPLS_INVALID_LABEL 0xFFFFFFFF |
82 | ||
ce549947 RW |
83 | /* LSP types. */ |
84 | enum lsp_types_t | |
85 | { | |
86 | ZEBRA_LSP_NONE = 0, /* No LSP. */ | |
87 | ZEBRA_LSP_STATIC = 1, /* Static LSP. */ | |
a64448ba DS |
88 | ZEBRA_LSP_LDP = 2, /* LDP LSP. */ |
89 | ZEBRA_LSP_BGP = 3 /* BGP LSP. */ | |
ce549947 RW |
90 | }; |
91 | ||
50f34207 | 92 | /* Functions for basic label operations. */ |
93 | ||
94 | /* Encode a label stack entry from fields; convert to network byte-order as | |
95 | * the Netlink interface expects MPLS labels to be in this format. | |
96 | */ | |
97 | static inline mpls_lse_t | |
98 | mpls_lse_encode (mpls_label_t label, u_int32_t ttl, | |
99 | u_int32_t exp, u_int32_t bos) | |
100 | { | |
101 | mpls_lse_t lse; | |
102 | lse = htonl ((label << MPLS_LS_LABEL_SHIFT) | | |
103 | (exp << MPLS_LS_EXP_SHIFT) | | |
104 | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | | |
105 | (ttl << MPLS_LS_TTL_SHIFT)); | |
106 | return lse; | |
107 | } | |
108 | ||
109 | /* Extract the fields from a label stack entry after converting to host-byte | |
110 | * order. This is expected to be called only for messages received over the | |
111 | * Netlink interface. | |
112 | */ | |
113 | static inline void | |
114 | mpls_lse_decode (mpls_lse_t lse, mpls_label_t *label, | |
115 | u_int32_t *ttl, u_int32_t *exp, u_int32_t *bos) | |
116 | { | |
117 | mpls_lse_t local_lse; | |
118 | ||
119 | local_lse = ntohl (lse); | |
120 | *label = MPLS_LABEL_VALUE(local_lse); | |
121 | *exp = MPLS_LABEL_EXP(local_lse); | |
122 | *bos = MPLS_LABEL_BOS(local_lse); | |
123 | *ttl = MPLS_LABEL_TTL(local_lse); | |
124 | } | |
125 | ||
28d58fd7 VV |
126 | /* Invalid label index value (when used with BGP Prefix-SID). Should |
127 | * match the BGP definition. | |
128 | */ | |
129 | #define MPLS_INVALID_LABEL_INDEX 0xFFFFFFFF | |
130 | ||
50f34207 | 131 | |
132 | /* Printable string for labels (with consideration for reserved values). */ | |
133 | static inline char * | |
14878121 | 134 | label2str (mpls_label_t label, char *buf, size_t len) |
50f34207 | 135 | { |
136 | switch(label) { | |
137 | case MPLS_V4_EXP_NULL_LABEL: | |
14878121 | 138 | strlcpy(buf, "IPv4 Explicit Null", len); |
50f34207 | 139 | return(buf); |
50f34207 | 140 | case MPLS_RA_LABEL: |
14878121 | 141 | strlcpy(buf, "Router Alert", len); |
50f34207 | 142 | return(buf); |
50f34207 | 143 | case MPLS_V6_EXP_NULL_LABEL: |
14878121 | 144 | strlcpy(buf, "IPv6 Explict Null", len); |
50f34207 | 145 | return(buf); |
50f34207 | 146 | case MPLS_IMP_NULL_LABEL: |
14878121 | 147 | strlcpy(buf, "implicit-null", len); |
50f34207 | 148 | return(buf); |
50f34207 | 149 | case MPLS_ENTROPY_LABEL_INDICATOR: |
14878121 | 150 | strlcpy(buf, "Entropy Label Indicator", len); |
50f34207 | 151 | return(buf); |
50f34207 | 152 | case MPLS_GAL_LABEL: |
14878121 | 153 | strlcpy(buf, "Generic Associated Channel", len); |
50f34207 | 154 | return(buf); |
50f34207 | 155 | case MPLS_OAM_ALERT_LABEL: |
14878121 | 156 | strlcpy(buf, "OAM Alert", len); |
50f34207 | 157 | return(buf); |
50f34207 | 158 | case MPLS_EXTENSION_LABEL: |
14878121 | 159 | strlcpy(buf, "Extension", len); |
50f34207 | 160 | return(buf); |
50f34207 | 161 | default: |
14878121 DL |
162 | if (label < 16) |
163 | snprintf(buf, len, "Reserved (%u)", label); | |
164 | else | |
165 | snprintf(buf, len, "%u", label); | |
50f34207 | 166 | return(buf); |
167 | } | |
50f34207 | 168 | } |
169 | ||
eac6e3f0 RW |
170 | /* constants used by ldpd */ |
171 | #define MPLS_LABEL_IPV4NULL 0 /* IPv4 Explicit NULL Label */ | |
172 | #define MPLS_LABEL_RTALERT 1 /* Router Alert Label */ | |
173 | #define MPLS_LABEL_IPV6NULL 2 /* IPv6 Explicit NULL Label */ | |
174 | #define MPLS_LABEL_IMPLNULL 3 /* Implicit NULL Label */ | |
175 | /* MPLS_LABEL_RESERVED 4-15 */ /* Values 4-15 are reserved */ | |
176 | #define MPLS_LABEL_RESERVED_MAX 15 | |
177 | #define MPLS_LABEL_MAX ((1 << 20) - 1) | |
178 | ||
50f34207 | 179 | #endif |