1 #ifndef included_vnet_mpls_packet_h
2 #define included_vnet_mpls_packet_h
7 * Copyright (c) 2012 Cisco and/or its affiliates.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at:
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * A label value only, i.e. 20bits.
24 typedef u32 mpls_label_t;
27 /* Label: top 20 bits [in network byte order] */
28 /* Experimental: 3 bits ... */
29 /* S (bottom of label stack): 1 bit */
31 mpls_label_t label_exp_s_ttl;
32 } mpls_unicast_header_t;
34 typedef enum mpls_eos_bit_t_
40 #define MPLS_EOS_BITS { \
41 [MPLS_NON_EOS] = "neos", \
45 #define FOR_EACH_MPLS_EOS_BIT(_eos) \
46 for (_eos = MPLS_NON_EOS; _eos <= MPLS_EOS; _eos++)
48 #define MPLS_ENTRY_LABEL_OFFSET 0
49 #define MPLS_ENTRY_LABEL_SHIFT 12
50 #define MPLS_ENTRY_LABEL_MASK 0x000fffff
51 #define MPLS_ENTRY_LABEL_BITS \
52 (MPLS_ENTRY_LABEL_MASK << MPLS_ENTRY_LABEL_SHIFT)
54 #define MPLS_ENTRY_EXP_OFFSET 2 /* byte offset to EXP bits */
55 #define MPLS_ENTRY_EXP_SHIFT 9
56 #define MPLS_ENTRY_EXP_MASK 0x07
57 #define MPLS_ENTRY_EXP(mpls) \
58 (((mpls)>>MPLS_ENTRY_EXP_SHIFT) & MPLS_ENTRY_EXP_MASK)
59 #define MPLS_ENTRY_EXP_BITS \
60 (MPLS_ENTRY_EXP_MASK << MPLS_ENTRY_EXP_SHIFT)
62 #define MPLS_ENTRY_EOS_OFFSET 2 /* byte offset to EOS bit */
63 #define MPLS_ENTRY_EOS_SHIFT 8
64 #define MPLS_ENTRY_EOS_MASK 0x01 /* EOS bit in its byte */
65 #define MPLS_ENTRY_EOS(mpls) \
66 (((mpls) >> MPLS_ENTRY_EOS_SHIFT) & MPLS_ENTRY_EOS_MASK)
67 #define MPLS_ENTRY_EOS_BIT (MPLS_ENTRY_EOS_MASK << MPLS_ENTRY_EOS_SHIFT)
69 #define MPLS_ENTRY_TTL_OFFSET 3 /* byte offset to ttl field */
70 #define MPLS_ENTRY_TTL_SHIFT 0
71 #define MPLS_ENTRY_TTL_MASK 0xff
72 #define MPLS_ENTRY_TTL(mpls) \
73 (((mpls) >> MPLS_ENTRY_TTL_SHIFT) & MPLS_ENTRY_TTL_MASK)
74 #define MPLS_ENTRY_TTL_BITS \
75 (MPLS_ENTRY_TTL_MASK << MPLS_ENTRY_TTL_SHIFT)
77 static inline u32 vnet_mpls_uc_get_label (mpls_label_t label_exp_s_ttl)
79 return (label_exp_s_ttl>>MPLS_ENTRY_LABEL_SHIFT);
82 static inline u32 vnet_mpls_uc_get_exp (mpls_label_t label_exp_s_ttl)
84 return (MPLS_ENTRY_EXP(label_exp_s_ttl));
87 static inline u32 vnet_mpls_uc_get_s (mpls_label_t label_exp_s_ttl)
89 return (MPLS_ENTRY_EOS(label_exp_s_ttl));
92 static inline u32 vnet_mpls_uc_get_ttl (mpls_label_t label_exp_s_ttl)
94 return (MPLS_ENTRY_TTL(label_exp_s_ttl));
97 static inline void vnet_mpls_uc_set_label (mpls_label_t *label_exp_s_ttl,
100 *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_LABEL_BITS)) |
101 ((value & MPLS_ENTRY_LABEL_MASK) << MPLS_ENTRY_LABEL_SHIFT));
104 static inline void vnet_mpls_uc_set_exp (mpls_label_t *label_exp_s_ttl,
107 *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_EXP_BITS)) |
108 ((exp & MPLS_ENTRY_EXP_MASK) << MPLS_ENTRY_EXP_SHIFT));
111 static inline void vnet_mpls_uc_set_s (mpls_label_t *label_exp_s_ttl,
114 *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_EOS_BIT)) |
115 ((eos & MPLS_ENTRY_EOS_MASK) << MPLS_ENTRY_EOS_SHIFT));
118 static inline void vnet_mpls_uc_set_ttl (mpls_label_t *label_exp_s_ttl,
121 *label_exp_s_ttl = (((*label_exp_s_ttl) & ~(MPLS_ENTRY_TTL_BITS)) |
122 ((ttl & MPLS_ENTRY_TTL_MASK)));
125 #endif /* included_vnet_mpls_packet_h */