sr_packet.h revision be83704c
1cb9cadadSEd Warnicke#ifndef included_vnet_sr_packet_h
2cb9cadadSEd Warnicke#define included_vnet_sr_packet_h
3cb9cadadSEd Warnicke
4cb9cadadSEd Warnicke#include <vnet/ip/ip.h>
5cb9cadadSEd Warnicke
6cb9cadadSEd Warnicke/*
7cb9cadadSEd Warnicke * ipv6 segment-routing header format
8cb9cadadSEd Warnicke *
9cb9cadadSEd Warnicke * Copyright (c) 2013 Cisco and/or its affiliates.
10cb9cadadSEd Warnicke * Licensed under the Apache License, Version 2.0 (the "License");
11cb9cadadSEd Warnicke * you may not use this file except in compliance with the License.
12cb9cadadSEd Warnicke * You may obtain a copy of the License at:
13cb9cadadSEd Warnicke *
14cb9cadadSEd Warnicke *     http://www.apache.org/licenses/LICENSE-2.0
15cb9cadadSEd Warnicke *
16cb9cadadSEd Warnicke * Unless required by applicable law or agreed to in writing, software
17cb9cadadSEd Warnicke * distributed under the License is distributed on an "AS IS" BASIS,
18cb9cadadSEd Warnicke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19cb9cadadSEd Warnicke * See the License for the specific language governing permissions and
20cb9cadadSEd Warnicke * limitations under the License.
21cb9cadadSEd Warnicke */
22cb9cadadSEd Warnicke
23fb38095dSPablo Camarillo/*
24fb38095dSPablo Camarillo *   The Segment Routing Header (SRH) is defined as follows:
25fb38095dSPablo Camarillo *
26fb38095dSPablo Camarillo *    0                   1                   2                   3
27fb38095dSPablo Camarillo *    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
28fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29fb38095dSPablo Camarillo *   | Next Header   |  Hdr Ext Len  | Routing Type  | Segments Left |
30fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31be83704cSAhmed Abdelsalam *   |  Last Entry   |     Flags     |              Tag              |
32fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33fb38095dSPablo Camarillo *   |                                                               |
34fb38095dSPablo Camarillo *   |            Segment List[0] (128 bits IPv6 address)            |
35fb38095dSPablo Camarillo *   |                                                               |
36fb38095dSPablo Camarillo *   |                                                               |
37fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38fb38095dSPablo Camarillo *   |                                                               |
39fb38095dSPablo Camarillo *   |                                                               |
40fb38095dSPablo Camarillo *                                 ...
41fb38095dSPablo Camarillo *   |                                                               |
42fb38095dSPablo Camarillo *   |                                                               |
43fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44fb38095dSPablo Camarillo *   |                                                               |
45fb38095dSPablo Camarillo *   |            Segment List[n] (128 bits IPv6 address)            |
46fb38095dSPablo Camarillo *   |                                                               |
47fb38095dSPablo Camarillo *   |                                                               |
48fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49fb38095dSPablo Camarillo *   //                                                             //
50fb38095dSPablo Camarillo *   //         Optional Type Length Value objects (variable)       //
51fb38095dSPablo Camarillo *   //                                                             //
52fb38095dSPablo Camarillo *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53cb9cadadSEd Warnicke *
54cb9cadadSEd Warnicke *   where:
55cb9cadadSEd Warnicke *
56cb9cadadSEd Warnicke *   o  Next Header: 8-bit selector.  Identifies the type of header
57cb9cadadSEd Warnicke *      immediately following the SRH.
58cb9cadadSEd Warnicke *
59cb9cadadSEd Warnicke *   o  Hdr Ext Len: 8-bit unsigned integer, is the length of the SRH
60cb9cadadSEd Warnicke *      header in 8-octet units, not including the first 8 octets.
61cb9cadadSEd Warnicke *
62cb9cadadSEd Warnicke *   o  Routing Type: TBD, to be assigned by IANA (suggested value: 4).
63cb9cadadSEd Warnicke *
64be83704cSAhmed Abdelsalam *   o  Segments Left.  Defined in [RFC8200], it contains the index, in
65cb9cadadSEd Warnicke *      the Segment List, of the next segment to inspect.  Segments Left
66fb38095dSPablo Camarillo *      is decremented at each segment.
67cb9cadadSEd Warnicke *
68be83704cSAhmed Abdelsalam *   o  Last Entry: contains the index (zero based), in the Segment List,
69be83704cSAhmed Abdelsalam *      of the the last element of the Segment List
70cb9cadadSEd Warnicke *
71fb38095dSPablo Camarillo *   o  Flags: 8 bits of flags.  Following flags are defined:
72cb9cadadSEd Warnicke *
73fb38095dSPablo Camarillo *         0 1 2 3 4 5 6 7
74fb38095dSPablo Camarillo *        +-+-+-+-+-+-+-+-+
75fb38095dSPablo Camarillo *        |U|P|O|A|H|  U  |
76fb38095dSPablo Camarillo *        +-+-+-+-+-+-+-+-+
77cb9cadadSEd Warnicke *
78fb38095dSPablo Camarillo *        U: Unused and for future use.  SHOULD be unset on transmission
79fb38095dSPablo Camarillo *        and MUST be ignored on receipt.
80cb9cadadSEd Warnicke *
81fb38095dSPablo Camarillo *        P-flag: Protected flag.  Set when the packet has been rerouted
82fb38095dSPablo Camarillo *        through FRR mechanism by an SR endpoint node.
83cb9cadadSEd Warnicke *
84fb38095dSPablo Camarillo *        O-flag: OAM flag.  When set, it indicates that this packet is
85fb38095dSPablo Camarillo *        an operations and management (OAM) packet.
86cb9cadadSEd Warnicke *
87fb38095dSPablo Camarillo *        A-flag: Alert flag.  If present, it means important Type Length
88fb38095dSPablo Camarillo *        Value (TLV) objects are present.  See Section 3.1 for details
89fb38095dSPablo Camarillo *        on TLVs objects.
90cb9cadadSEd Warnicke *
91fb38095dSPablo Camarillo *        H-flag: HMAC flag.  If set, the HMAC TLV is present and is
92fb38095dSPablo Camarillo *        encoded as the last TLV of the SRH.  In other words, the last
93fb38095dSPablo Camarillo *        36 octets of the SRH represent the HMAC information.  See
94fb38095dSPablo Camarillo *        Section 3.1.5 for details on the HMAC TLV.
95cb9cadadSEd Warnicke *
96be83704cSAhmed Abdelsalam *   o  Tag: tag a packet as part of a class or group of packets, e.g.,
97be83704cSAhmed Abdelsalam *      packets sharing the same set of properties. When tag is not used
98be83704cSAhmed Abdelsalam *      at source it MUST be set to zero on transmission. When tag is not
99be83704cSAhmed Abdelsalam *      used during SRH Processing it SHOULD be ignored.
100cb9cadadSEd Warnicke *
101cb9cadadSEd Warnicke *   o  Segment List[n]: 128 bit IPv6 addresses representing the nth
102cb9cadadSEd Warnicke *      segment in the Segment List.  The Segment List is encoded starting
103cb9cadadSEd Warnicke *      from the last segment of the path.  I.e., the first element of the
104cb9cadadSEd Warnicke *      segment list (Segment List [0]) contains the last segment of the
105cb9cadadSEd Warnicke *      path while the last segment of the Segment List (Segment List[n])
106cb9cadadSEd Warnicke *      contains the first segment of the path.  The index contained in
107cb9cadadSEd Warnicke *      "Segments Left" identifies the current active segment.
108cb9cadadSEd Warnicke *
109fb38095dSPablo Camarillo *   o  Type Length Value (TLV) are described in Section 3.1.
110cb9cadadSEd Warnicke *
111cb9cadadSEd Warnicke */
112cb9cadadSEd Warnicke
1134b8b718fSChris Luke#ifndef IPPROTO_IPV6_ROUTE
1144b8b718fSChris Luke#define IPPROTO_IPV6_ROUTE        43
1154b8b718fSChris Luke#endif
1164b8b718fSChris Luke
1174b8b718fSChris Luke#define ROUTING_HEADER_TYPE_SR    4
118fb38095dSPablo Camarillo
11906c5ffd6SKeith Burns (alagalah)typedef struct
12006c5ffd6SKeith Burns (alagalah){
121fb38095dSPablo Camarillo  /* Protocol for next header. */
122cb9cadadSEd Warnicke  u8 protocol;
123fb38095dSPablo Camarillo  /*
124607de1a0SDamjan Marion   * Length of routing header in 8 octet units,
125cb9cadadSEd Warnicke   * not including the first 8 octets
126cb9cadadSEd Warnicke   */
127cb9cadadSEd Warnicke  u8 length;
128cb9cadadSEd Warnicke
129fb38095dSPablo Camarillo  /* Type of routing header; type 4 = segement routing */
130cb9cadadSEd Warnicke  u8 type;
131cb9cadadSEd Warnicke
132fb38095dSPablo Camarillo  /* Next segment in the segment list */
133cb9cadadSEd Warnicke  u8 segments_left;
134cb9cadadSEd Warnicke
135fb38095dSPablo Camarillo  /* Pointer to the first segment in the header */
136be83704cSAhmed Abdelsalam  u8 last_entry;
137cb9cadadSEd Warnicke
138fb38095dSPablo Camarillo  /* Flag bits */
139fb38095dSPablo Camarillo#define IP6_SR_HEADER_FLAG_PROTECTED  (0x40)
140fb38095dSPablo Camarillo#define IP6_SR_HEADER_FLAG_OAM        (0x20)
141fb38095dSPablo Camarillo#define IP6_SR_HEADER_FLAG_ALERT      (0x10)
142fb38095dSPablo Camarillo#define IP6_SR_HEADER_FLAG_HMAC       (0x80)
143fb38095dSPablo Camarillo
144fb38095dSPablo Camarillo  /* values 0x0, 0x4 - 0x7 are reserved */
145fb38095dSPablo Camarillo  u8 flags;
146be83704cSAhmed Abdelsalam  u16 tag;
14706c5ffd6SKeith Burns (alagalah)
148fb38095dSPablo Camarillo  /* The segment elts */
149cb9cadadSEd Warnicke  ip6_address_t segments[0];
15006c5ffd6SKeith Burns (alagalah)} __attribute__ ((packed)) ip6_sr_header_t;
151cb9cadadSEd Warnicke
152fb38095dSPablo Camarillo/*
153fb38095dSPablo Camarillo* fd.io coding-style-patch-verification: ON
154fb38095dSPablo Camarillo*
155fb38095dSPablo Camarillo* Local Variables:
156fb38095dSPablo Camarillo* eval: (c-set-style "gnu")
157fb38095dSPablo Camarillo* End:
158fb38095dSPablo Camarillo*/
159cb9cadadSEd Warnicke
160cb9cadadSEd Warnicke#endif /* included_vnet_sr_packet_h */
161