Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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_packet_h__ |
| 16 | #define __included_vxlan_packet_h__ 1 |
| 17 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 18 | /* |
John Lo | 69c2a58 | 2020-01-04 00:32:46 -0500 | [diff] [blame] | 19 | * From RFC-7348 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 21 | * |R|R|R|R|I|R|R|R| Reserved | |
| 22 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 23 | * | VXLAN Network Identifier (VNI) | Reserved | |
| 24 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 25 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | * VXLAN Header: This is an 8-byte field that has: |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 27 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | * - Flags (8 bits): where the I flag MUST be set to 1 for a valid |
| 29 | * VXLAN Network ID (VNI). The other 7 bits (designated "R") are |
| 30 | * reserved fields and MUST be set to zero on transmission and |
| 31 | * ignored on receipt. |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 32 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 33 | * - VXLAN Segment ID/VXLAN Network Identifier (VNI): this is a |
| 34 | * 24-bit value used to designate the individual VXLAN overlay |
| 35 | * network on which the communicating VMs are situated. VMs in |
| 36 | * different VXLAN overlay networks cannot communicate with each |
| 37 | * other. |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 38 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | * - Reserved fields (24 bits and 8 bits): MUST be set to zero on |
| 40 | * transmission and ignored on receipt. |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 41 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | */ |
| 43 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 44 | typedef struct |
| 45 | { |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 46 | u8 flags; |
| 47 | u8 res1; |
| 48 | u8 res2; |
| 49 | u8 res3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | u32 vni_reserved; |
| 51 | } vxlan_header_t; |
| 52 | |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 53 | #define VXLAN_FLAGS_I 0x08 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 55 | static inline u32 |
| 56 | vnet_get_vni (vxlan_header_t * h) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | { |
| 58 | u32 vni_reserved_host_byte_order; |
| 59 | |
| 60 | vni_reserved_host_byte_order = clib_net_to_host_u32 (h->vni_reserved); |
| 61 | return vni_reserved_host_byte_order >> 8; |
| 62 | } |
| 63 | |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 64 | static inline void |
| 65 | vnet_set_vni_and_flags (vxlan_header_t * h, u32 vni) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | { |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 67 | h->vni_reserved = clib_host_to_net_u32 (vni << 8); |
| 68 | *(u32 *) h = 0; |
John Lo | c42912d | 2016-11-07 18:30:47 -0500 | [diff] [blame] | 69 | h->flags = VXLAN_FLAGS_I; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | #endif /* __included_vxlan_packet_h__ */ |
Mohsin Kazmi | 21a1de4 | 2020-06-02 15:12:30 +0200 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * fd.io coding-style-patch-verification: ON |
| 76 | * |
| 77 | * Local Variables: |
| 78 | * eval: (c-set-style "gnu") |
| 79 | * End: |
| 80 | */ |