Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_vxlan_gbp_packet_h__ |
| 16 | #define __included_vxlan_gbp_packet_h__ 1 |
| 17 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 18 | #include <vlib/vlib.h> |
| 19 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 20 | /* |
| 21 | * From draft-smith-vxlan-group-policy-04.txt |
| 22 | * |
| 23 | * 0 1 2 3 |
| 24 | * 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 |
| 25 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 | * |G|R|R|R|I|R|R|R|R|D|E|S|A|R|R|R| Group Policy ID | |
| 27 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 | * | VXLAN Network Identifier (VNI) | Reserved | |
| 29 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 | * |
| 31 | * G bit: Bit 0 of the initial word is defined as the G (Group Based |
| 32 | * Policy Extension) bit. |
| 33 | * |
| 34 | * I bit: where the I flag MUST be set to 1 for a valid |
| 35 | * VXLAN Network ID (VNI). |
| 36 | * |
| 37 | * D bit: Bit 9 of the initial word is defined as the Don't Learn bit. |
| 38 | * When set, this bit indicates that the egress VTEP MUST NOT learn the |
| 39 | * source address of the encapsulated frame. |
| 40 | * |
| 41 | * E bit: Bit 10 of the initial word is defined as the bounce packet. |
| 42 | * When set, this bit indicates that packet is bounced and must be |
| 43 | * dropped. |
| 44 | * |
| 45 | * S bit: Bit 11 of the initial word is defined as the source policy |
| 46 | * applied bit. |
| 47 | * |
| 48 | * A bit: Bit 12 of the initial word is defined as the A (Policy |
| 49 | * Applied) bit. This bit is only defined as the A bit when the G bit |
| 50 | * is set to 1. |
| 51 | * |
| 52 | * A = 1 indicates that the group policy has already been applied to |
| 53 | * this packet. Policies MUST NOT be applied by devices when the A |
| 54 | * bit is set. |
| 55 | * |
| 56 | * A = 0 indicates that the group policy has not been applied to this |
| 57 | * packet. Group policies MUST be applied by devices when the A bit |
| 58 | * is set to 0 and the destination Group has been determined. |
| 59 | * Devices that apply the Group policy MUST set the A bit to 1 after |
| 60 | * the policy has been applied. |
| 61 | * |
| 62 | * Group Policy ID: 16 bit identifier that indicates the source TSI |
| 63 | * Group membership being encapsulated by VXLAN. Its value is source |
| 64 | * class id. |
| 65 | * |
Neale Ranns | 2b60018 | 2019-03-29 05:08:27 -0700 | [diff] [blame] | 66 | * FOR INTERNAL USE ONLY |
| 67 | * R bit: Bit 12 of the initial word is defined as the reflection bit |
| 68 | * Set on packet rx checked on tx and dropped if set. this prevents |
| 69 | * packets recieved on an iVXLAN tunnel being reflected back to |
| 70 | * another. |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 71 | */ |
| 72 | |
| 73 | typedef struct |
| 74 | { |
| 75 | union |
| 76 | { |
| 77 | struct |
| 78 | { |
| 79 | union |
| 80 | { |
| 81 | struct |
| 82 | { |
| 83 | u8 flag_g_i; |
| 84 | u8 gpflags; |
| 85 | }; |
| 86 | u16 flags; |
| 87 | }; |
| 88 | u16 sclass; |
| 89 | }; |
| 90 | u32 flags_sclass_as_u32; |
| 91 | }; |
| 92 | u32 vni_reserved; |
| 93 | } vxlan_gbp_header_t; |
| 94 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 95 | #define foreach_vxlan_gbp_flags \ |
| 96 | _ (0x80, G) \ |
| 97 | _ (0x08, I) |
| 98 | |
| 99 | typedef enum |
| 100 | { |
| 101 | VXLAN_GBP_FLAGS_NONE = 0, |
| 102 | #define _(n,f) VXLAN_GBP_FLAGS_##f = n, |
| 103 | foreach_vxlan_gbp_flags |
| 104 | #undef _ |
| 105 | } __attribute__ ((packed)) vxlan_gbp_flags_t; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 106 | |
Neale Ranns | 81cfa9c | 2019-07-04 14:12:50 +0000 | [diff] [blame] | 107 | #define VXLAN_GBP_FLAGS_GI (VXLAN_GBP_FLAGS_G|VXLAN_GBP_FLAGS_I) |
| 108 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 109 | #define foreach_vxlan_gbp_gpflags \ |
| 110 | _ (0x40, D) \ |
| 111 | _ (0x20, E) \ |
| 112 | _ (0x10, S) \ |
Neale Ranns | 2b60018 | 2019-03-29 05:08:27 -0700 | [diff] [blame] | 113 | _ (0x08, A) \ |
| 114 | _ (0x04, R) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 115 | |
| 116 | typedef enum |
| 117 | { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 118 | VXLAN_GBP_GPFLAGS_NONE = 0, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 119 | #define _(n,f) VXLAN_GBP_GPFLAGS_##f = n, |
| 120 | foreach_vxlan_gbp_gpflags |
| 121 | #undef _ |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 122 | } __attribute__ ((packed)) vxlan_gbp_gpflags_t; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 123 | |
| 124 | static inline u32 |
| 125 | vxlan_gbp_get_vni (vxlan_gbp_header_t * h) |
| 126 | { |
| 127 | u32 vni_reserved_host_byte_order; |
| 128 | |
| 129 | vni_reserved_host_byte_order = clib_net_to_host_u32 (h->vni_reserved); |
| 130 | return vni_reserved_host_byte_order >> 8; |
| 131 | } |
| 132 | |
| 133 | static inline u16 |
| 134 | vxlan_gbp_get_sclass (vxlan_gbp_header_t * h) |
| 135 | { |
| 136 | u16 sclass_host_byte_order; |
| 137 | |
| 138 | sclass_host_byte_order = clib_net_to_host_u16 (h->sclass); |
| 139 | return sclass_host_byte_order; |
| 140 | } |
| 141 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 142 | static inline vxlan_gbp_gpflags_t |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 143 | vxlan_gbp_get_gpflags (vxlan_gbp_header_t * h) |
| 144 | { |
| 145 | return h->gpflags; |
| 146 | } |
| 147 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 148 | static inline vxlan_gbp_flags_t |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 149 | vxlan_gbp_get_flags (vxlan_gbp_header_t * h) |
| 150 | { |
| 151 | return h->flag_g_i; |
| 152 | } |
| 153 | |
| 154 | static inline void |
| 155 | vxlan_gbp_set_header (vxlan_gbp_header_t * h, u32 vni) |
| 156 | { |
| 157 | h->vni_reserved = clib_host_to_net_u32 (vni << 8); |
| 158 | h->flags_sclass_as_u32 = 0; |
| 159 | h->flag_g_i = VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G; |
| 160 | } |
| 161 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 162 | extern u8 *format_vxlan_gbp_header_flags (u8 * s, va_list * args); |
| 163 | extern u8 *format_vxlan_gbp_header_gpflags (u8 * s, va_list * args); |
| 164 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 165 | #endif /* __included_vxlan_gbp_packet_h__ */ |
| 166 | |
| 167 | /* |
| 168 | * fd.io coding-style-patch-verification: ON |
| 169 | * |
| 170 | * Local Variables: |
| 171 | * eval: (c-set-style "gnu") |
| 172 | * End: |
| 173 | */ |