^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #ifndef __NET_NSH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #define __NET_NSH_H 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Network Service Header:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * 0 1 2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * |Ver|O|U| TTL | Length |U|U|U|U|MD Type| Next Protocol |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * | Service Path Identifier (SPI) | Service Index |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * ~ Mandatory/Optional Context Headers ~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Version: The version field is used to ensure backward compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * going forward with future NSH specification updates. It MUST be set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * to 0x0 by the sender, in this first revision of NSH. Given the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * widespread implementation of existing hardware that uses the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * nibble after an MPLS label stack for ECMP decision processing, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * document reserves version 01b and this value MUST NOT be used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * future versions of the protocol. Please see [RFC7325] for further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * discussion of MPLS-related forwarding requirements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * O bit: Setting this bit indicates an Operations, Administration, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Maintenance (OAM) packet. The actual format and processing of SFC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * OAM packets is outside the scope of this specification (see for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * example [I-D.ietf-sfc-oam-framework] for one approach).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * The O bit MUST be set for OAM packets and MUST NOT be set for non-OAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * packets. The O bit MUST NOT be modified along the SFP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * SF/SFF/SFC Proxy/Classifier implementations that do not support SFC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * OAM procedures SHOULD discard packets with O bit set, but MAY support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * a configurable parameter to enable forwarding received SFC OAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * packets unmodified to the next element in the chain. Forwarding OAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * packets unmodified by SFC elements that do not support SFC OAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * procedures may be acceptable for a subset of OAM functions, but can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * result in unexpected outcomes for others, thus it is recommended to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * analyze the impact of forwarding an OAM packet for all OAM functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * prior to enabling this behavior. The configurable parameter MUST be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * disabled by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * TTL: Indicates the maximum SFF hops for an SFP. This field is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * for service plane loop detection. The initial TTL value SHOULD be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * configurable via the control plane; the configured initial value can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * be specific to one or more SFPs. If no initial value is explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * provided, the default initial TTL value of 63 MUST be used. Each SFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * involved in forwarding an NSH packet MUST decrement the TTL value by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * 1 prior to NSH forwarding lookup. Decrementing by 1 from an incoming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * value of 0 shall result in a TTL value of 63. The packet MUST NOT be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * forwarded if TTL is, after decrement, 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * All other flag fields, marked U, are unassigned and available for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * future use, see Section 11.2.1. Unassigned bits MUST be set to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * upon origination, and MUST be ignored and preserved unmodified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * other NSH supporting elements. Elements which do not understand the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * meaning of any of these bits MUST NOT modify their actions based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * those unknown bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Length: The total length, in 4-byte words, of NSH including the Base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * Header, the Service Path Header, the Fixed Length Context Header or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Variable Length Context Header(s). The length MUST be 0x6 for MD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Type equal to 0x1, and MUST be 0x2 or greater for MD Type equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * 0x2. The length of the NSH header MUST be an integer multiple of 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * bytes, thus variable length metadata is always padded out to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * multiple of 4 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * MD Type: Indicates the format of NSH beyond the mandatory Base Header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * and the Service Path Header. MD Type defines the format of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * metadata being carried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * 0x0 - This is a reserved value. Implementations SHOULD silently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * discard packets with MD Type 0x0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * 0x1 - This indicates that the format of the header includes a fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * length Context Header (see Figure 4 below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * 0x2 - This does not mandate any headers beyond the Base Header and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Service Path Header, but may contain optional variable length Context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * Header(s). The semantics of the variable length Context Header(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * are not defined in this document. The format of the optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * variable length Context Headers is provided in Section 2.5.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * 0xF - This value is reserved for experimentation and testing, as per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * [RFC3692]. Implementations not explicitly configured to be part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * an experiment SHOULD silently discard packets with MD Type 0xF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Next Protocol: indicates the protocol type of the encapsulated data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * NSH does not alter the inner payload, and the semantics on the inner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * protocol remain unchanged due to NSH service function chaining.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Please see the IANA Considerations section below, Section 11.2.5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * This document defines the following Next Protocol values:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * 0x1: IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * 0x2: IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * 0x3: Ethernet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * 0x4: NSH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * 0x5: MPLS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * 0xFE: Experiment 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * 0xFF: Experiment 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Packets with Next Protocol values not supported SHOULD be silently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * dropped by default, although an implementation MAY provide a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * configuration parameter to forward them. Additionally, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * implementation not explicitly configured for a specific experiment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * [RFC3692] SHOULD silently drop packets with Next Protocol values 0xFE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * and 0xFF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * Service Path Identifier (SPI): Identifies a service path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Participating nodes MUST use this identifier for Service Function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Path selection. The initial classifier MUST set the appropriate SPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * for a given classification result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * Service Index (SI): Provides location within the SFP. The initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * classifier for a given SFP SHOULD set the SI to 255, however the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * control plane MAY configure the initial value of SI as appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * (i.e., taking into account the length of the service function path).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * The Service Index MUST be decremented by a value of 1 by Service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Functions or by SFC Proxy nodes after performing required services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * and the new decremented SI value MUST be used in the egress packet's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * NSH. The initial Classifier MUST send the packet to the first SFF in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * the identified SFP for forwarding along an SFP. If re-classification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * occurs, and that re-classification results in a new SPI, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * (re)classifier is, in effect, the initial classifier for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * resultant SPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * The SI is used in conjunction the with Service Path Identifier for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Service Function Path Selection and for determining the next SFF/SF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * in the path. The SI is also valuable when troubleshooting or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * reporting service paths. Additionally, while the TTL field is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * main mechanism for service plane loop detection, the SI can also be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * used for detecting service plane loops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * When the Base Header specifies MD Type = 0x1, a Fixed Length Context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Header (16-bytes) MUST be present immediately following the Service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Path Header. The value of a Fixed Length Context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * Header that carries no metadata MUST be set to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * When the base header specifies MD Type = 0x2, zero or more Variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * Length Context Headers MAY be added, immediately following the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Service Path Header (see Figure 5). Therefore, Length = 0x2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * indicates that only the Base Header followed by the Service Path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Header are present. The optional Variable Length Context Headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * MUST be of an integer number of 4-bytes. The base header Length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * field MUST be used to determine the offset to locate the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * packet or frame for SFC nodes that require access to that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * The format of the optional variable length Context Headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * 0 1 2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * 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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * | Metadata Class | Type |U| Length |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * | Variable Metadata |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Metadata Class (MD Class): Defines the scope of the 'Type' field to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * provide a hierarchical namespace. The IANA Considerations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * Section 11.2.4 defines how the MD Class values can be allocated to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * standards bodies, vendors, and others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Type: Indicates the explicit type of metadata being carried. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * definition of the Type is the responsibility of the MD Class owner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Unassigned bit: One unassigned bit is available for future use. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * bit MUST NOT be set, and MUST be ignored on receipt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Length: Indicates the length of the variable metadata, in bytes. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * case the metadata length is not an integer number of 4-byte words,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * the sender MUST add pad bytes immediately following the last metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * byte to extend the metadata to an integer number of 4-byte words.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * The receiver MUST round up the length field to the nearest 4-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * word boundary, to locate and process the next field in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * The receiver MUST access only those bytes in the metadata indicated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * by the length field (i.e., actual number of bytes) and MUST ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * the remaining bytes up to the nearest 4-byte word boundary. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Length may be 0 or greater.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * A value of 0 denotes a Context Header without a Variable Metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * [0] https://datatracker.ietf.org/doc/draft-ietf-sfc-nsh/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * struct nsh_md1_ctx - Keeps track of NSH context data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * @nshc<1-4>: NSH Contexts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct nsh_md1_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) __be32 context[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct nsh_md2_tlv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) __be16 md_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u8 md_value[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct nshhdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) __be16 ver_flags_ttl_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 mdtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) u8 np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) __be32 path_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct nsh_md1_ctx md1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct nsh_md2_tlv md2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Masking NSH header fields. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define NSH_VER_MASK 0xc000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define NSH_VER_SHIFT 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define NSH_FLAGS_MASK 0x3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define NSH_FLAGS_SHIFT 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #define NSH_TTL_MASK 0x0fc0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define NSH_TTL_SHIFT 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define NSH_LEN_MASK 0x003f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define NSH_LEN_SHIFT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #define NSH_MDTYPE_MASK 0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #define NSH_MDTYPE_SHIFT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define NSH_SPI_MASK 0xffffff00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define NSH_SPI_SHIFT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define NSH_SI_MASK 0x000000ff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define NSH_SI_SHIFT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* MD Type Registry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define NSH_M_TYPE1 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define NSH_M_TYPE2 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define NSH_M_EXP1 0xFE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define NSH_M_EXP2 0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* NSH Base Header Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define NSH_BASE_HDR_LEN 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* NSH MD Type 1 header Length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define NSH_M_TYPE1_LEN 24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* NSH header maximum Length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define NSH_HDR_MAX_LEN 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* NSH context headers maximum Length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define NSH_CTX_HDRS_MAX_LEN 248
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline struct nshhdr *nsh_hdr(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return (struct nshhdr *)skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static inline u16 nsh_hdr_len(const struct nshhdr *nsh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return ((ntohs(nsh->ver_flags_ttl_len) & NSH_LEN_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) >> NSH_LEN_SHIFT) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static inline u8 nsh_get_ver(const struct nshhdr *nsh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return (ntohs(nsh->ver_flags_ttl_len) & NSH_VER_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) >> NSH_VER_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline u8 nsh_get_flags(const struct nshhdr *nsh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return (ntohs(nsh->ver_flags_ttl_len) & NSH_FLAGS_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) >> NSH_FLAGS_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static inline u8 nsh_get_ttl(const struct nshhdr *nsh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return (ntohs(nsh->ver_flags_ttl_len) & NSH_TTL_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) >> NSH_TTL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static inline void __nsh_set_xflag(struct nshhdr *nsh, u16 xflag, u16 xmask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) nsh->ver_flags_ttl_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) = (nsh->ver_flags_ttl_len & ~htons(xmask)) | htons(xflag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static inline void nsh_set_flags_and_ttl(struct nshhdr *nsh, u8 flags, u8 ttl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) __nsh_set_xflag(nsh, ((flags << NSH_FLAGS_SHIFT) & NSH_FLAGS_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ((ttl << NSH_TTL_SHIFT) & NSH_TTL_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) NSH_FLAGS_MASK | NSH_TTL_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline void nsh_set_flags_ttl_len(struct nshhdr *nsh, u8 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) u8 ttl, u8 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) len = len >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) __nsh_set_xflag(nsh, ((flags << NSH_FLAGS_SHIFT) & NSH_FLAGS_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ((ttl << NSH_TTL_SHIFT) & NSH_TTL_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ((len << NSH_LEN_SHIFT) & NSH_LEN_MASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) NSH_FLAGS_MASK | NSH_TTL_MASK | NSH_LEN_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int nsh_push(struct sk_buff *skb, const struct nshhdr *pushed_nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int nsh_pop(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #endif /* __NET_NSH_H */