FD.io VPP  v16.06
Vector Packet Processing
sr_packet.h
Go to the documentation of this file.
1 #ifndef included_vnet_sr_packet_h
2 #define included_vnet_sr_packet_h
3 
4 #include <vnet/ip/ip.h>
5 
6 /*
7  * ipv6 segment-routing header format
8  *
9  * Copyright (c) 2013 Cisco and/or its affiliates.
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at:
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 /*
24  * The Segment Routing Header (SRH) is defined as follows:
25  *
26  *
27  * 0 1 2 3
28  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
29  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30  * | Next Header | Hdr Ext Len | Routing Type | Segments Left |
31  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32  * | First Segment | Flags | HMAC Key ID |
33  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34  * | |
35  * | Segment List[0] (128 bits ipv6 address) |
36  * | |
37  * | |
38  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39  * | |
40  * | |
41  * ...
42  * | |
43  * | |
44  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45  * | |
46  * | Segment List[n] (128 bits ipv6 address) |
47  * | |
48  * | |
49  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50  * | |
51  * | Policy List[0] (optional) |
52  * | |
53  * | |
54  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55  * | |
56  * | Policy List[1] (optional) |
57  * | |
58  * | |
59  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60  * | |
61  * | Policy List[2] (optional) |
62  * | |
63  * | |
64  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65  * | |
66  * | |
67  * | |
68  * | HMAC (256 bits) |
69  * | (optional) |
70  * | |
71  * | |
72  * | |
73  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74  *
75  * where:
76  *
77  * o Next Header: 8-bit selector. Identifies the type of header
78  * immediately following the SRH.
79  *
80  * o Hdr Ext Len: 8-bit unsigned integer, is the length of the SRH
81  * header in 8-octet units, not including the first 8 octets.
82  *
83  * o Routing Type: TBD, to be assigned by IANA (suggested value: 4).
84  *
85  * o Segments Left. Defined in [RFC2460], it contains the index, in
86  * the Segment List, of the next segment to inspect. Segments Left
87  * is decremented at each segment and it is used as an index in the
88  * segment list.
89  *
90  * o First Segment: offset in the SRH, not including the first 8 octets
91  * and expressed in 16-octet units, pointing to the last element of
92  * the segment list, which is in fact the first segment of the
93  * segment routing path.
94  *
95  * o Flags: 16 bits of flags. Following flags are defined:
96  *
97  * 1
98  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
99  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100  * |C|P|R|R| Policy Flags |
101  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
102  *
103  * C-flag: Clean-up flag. Set when the SRH has to be removed from
104  * the packet when packet reaches the last segment.
105  *
106  * P-flag: Protected flag. Set when the packet has been rerouted
107  * through FRR mechanism by a SR endpoint node. See Section 6.3
108  * for more details.
109  *
110  * R-flags. Reserved and for future use.
111  *
112  * Policy Flags. Define the type of the IPv6 addresses encoded
113  * into the Policy List (see below). The following have been
114  * defined:
115  *
116  * Bits 4-6: determine the type of the first element after the
117  * segment list.
118  *
119  * Bits 7-9: determine the type of the second element.
120  *
121  * Bits 10-12: determine the type of the third element.
122  *
123  * Bits 13-15: determine the type of the fourth element.
124  *
125  * The following values are used for the type:
126  *
127  * 0x0: Not present. If value is set to 0x0, it means the
128  * element represented by these bits is not present.
129  *
130  * 0x1: SR Ingress.
131  *
132  * 0x2: SR Egress.
133  *
134  * 0x3: Original Source Address.
135  *
136  * o HMAC Key ID and HMAC field, and their use are defined in
137  * [I-D.vyncke-6man-segment-routing-security].
138  *
139  * o Segment List[n]: 128 bit IPv6 addresses representing the nth
140  * segment in the Segment List. The Segment List is encoded starting
141  * from the last segment of the path. I.e., the first element of the
142  * segment list (Segment List [0]) contains the last segment of the
143  * path while the last segment of the Segment List (Segment List[n])
144  * contains the first segment of the path. The index contained in
145  * "Segments Left" identifies the current active segment.
146  *
147  * o Policy List. Optional addresses representing specific nodes in
148  * the SR path such as:
149  *
150  * SR Ingress: a 128 bit generic identifier representing the
151  * ingress in the SR domain (i.e.: it needs not to be a valid IPv6
152  * address).
153  *
154  * SR Egress: a 128 bit generic identifier representing the egress
155  * in the SR domain (i.e.: it needs not to be a valid IPv6
156  * address).
157  *
158  * Original Source Address: IPv6 address originally present in the
159  * SA field of the packet.
160  *
161  * The segments in the Policy List are encoded after the segment list
162  * and they are optional. If none are in the SRH, all bits of the
163  * Policy List Flags MUST be set to 0x0.
164  */
165 
166 #ifndef IPPROTO_IPV6_ROUTE
167 #define IPPROTO_IPV6_ROUTE 43
168 #endif
169 
170 #define ROUTING_HEADER_TYPE_SR 4
171 
172 typedef struct {
173  /* Protocol for next header. */
175  /*
176  * Length of routing header in 8 octet units,
177  * not including the first 8 octets
178  */
180 
181  /* Type of routing header; type 4 = segement routing */
183 
184  /* Next segment in the segment list */
186 
187  /*
188  * Policy list pointer: offset in the SRH of the policy
189  * list - in 16-octet units - not including the first 8 octets.
190  */
192 
193  /* Flag bits */
194 #define IP6_SR_HEADER_FLAG_CLEANUP (0x8000)
195 #define IP6_SR_HEADER_FLAG_PROTECTED (0x4000)
196 #define IP6_SR_HEADER_FLAG_RESERVED (0x3000)
197 
198 #define IP6_SR_HEADER_FLAG_PL_ELT_NOT_PRESENT (0x0)
199 #define IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE (0x1)
200 #define IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE (0x2)
201 #define IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR (0x3)
202  /* values 0x4 - 0x7 are reserved */
205 
206  /* The segment + policy list elts */
207  ip6_address_t segments[0];
208 } __attribute__((packed)) ip6_sr_header_t;
209 
210 static inline int
212 {
213  return (-3 * pl_index) + 12;
214 }
215 
216 /* pl_index is one-origined, to match the text above */
217 static inline int
218 ip6_sr_policy_list_flags (u16 flags_host_byte_order, int pl_index)
219 {
220  int shift;
221 
222  if (pl_index <= 0 || pl_index > 4)
223  return 0;
224 
225  shift = (-3 * pl_index) + 12;
226  flags_host_byte_order >>= shift;
227 
228  return (flags_host_byte_order & 7);
229 }
230 
231 #endif /* included_vnet_sr_packet_h */
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
static int ip6_sr_policy_list_shift_from_index(int pl_index)
Definition: sr_packet.h:211
static int ip6_sr_policy_list_flags(u16 flags_host_byte_order, int pl_index)
Definition: sr_packet.h:218