Initial commit of vpp code.
[vpp.git] / vnet / vnet / nsh-gre / nsh_gre.h
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_vnet_nsh_gre_h
16 #define included_vnet_nsh_gre_h
17
18 #include <vnet/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/nsh-gre/nsh_gre_packet.h>
21 #include <vnet/ip/ip4_packet.h>
22
23 typedef CLIB_PACKED (struct {
24   ip4_header_t ip4;             /* 20 bytes */
25   gre_header_t gre;             /* 4 bytes */
26   nsh_header_t nsh;             /* 28 bytes */
27 }) ip4_gre_and_nsh_header_t;
28
29 typedef struct {
30   /* Rewrite string. $$$$ embed vnet_rewrite header */
31   u8 * rewrite;
32
33   /* tunnel src and dst addresses */
34   ip4_address_t src;
35   ip4_address_t dst;
36
37   /* FIB indices */
38   u32 encap_fib_index;          /* tunnel partner lookup here */
39   u32 decap_fib_index;          /* inner IP lookup here */
40
41   /* when decapsulating, send pkts here */
42   u32 decap_next_index;
43
44   /* vnet intfc hw/sw_if_index */
45   u32 hw_if_index;
46   u32 sw_if_index;
47
48   /* NSH header fields in HOST byte order */
49   u8 ver_o_c;
50   u8 length;
51   u8 md_type;
52   u8 next_protocol;
53   u32 spi_si;
54     
55   /* Context headers, always present, in HOST byte order */
56   u32 c1, c2, c3, c4;
57   u32 * tlvs;
58 } nsh_gre_tunnel_t;
59
60 #define foreach_nsh_gre_input_next              \
61   _ (DROP, "error-drop")                        \
62   _ (IP4_INPUT, "ip4-input")                    \
63   _ (IP6_INPUT, "ip6-input")                    \
64   _ (ETHERNET_INPUT, "ethernet-input")
65
66 typedef enum {
67 #define _(s,n) NSH_INPUT_NEXT_##s,
68   foreach_nsh_gre_input_next
69 #undef _
70   NSH_INPUT_N_NEXT,
71 } nsh_gre_input_next_t;
72
73 typedef enum {
74 #define nsh_gre_error(n,s) NSH_GRE_ERROR_##n,
75 #include <vnet/nsh-gre/nsh_gre_error.def>
76 #undef nsh_gre_error
77   NSH_GRE_N_ERROR,
78 } nsh_gre_input_error_t;
79
80 typedef struct {
81   /* vector of encap tunnel instances */
82   nsh_gre_tunnel_t *tunnels;
83
84   /* lookup tunnel by tunnel partner src address */
85   uword * nsh_gre_tunnel_by_src_address;
86
87   /* Free vlib hw_if_indices */
88   u32 * free_nsh_gre_tunnel_hw_if_indices;
89
90   /* show device instance by real device instance */
91   u32 * dev_inst_by_real;
92
93   /* convenience */
94   vlib_main_t * vlib_main;
95   vnet_main_t * vnet_main;
96 } nsh_gre_main_t;
97
98 nsh_gre_main_t nsh_gre_main;
99
100 vlib_node_registration_t nsh_gre_input_node;
101 vlib_node_registration_t nsh_gre_encap_node;
102
103 u8 * format_nsh_gre_encap_trace (u8 * s, va_list * args);
104
105 typedef struct {
106   u8 is_add;
107   ip4_address_t src, dst;
108   u32 encap_fib_index;
109   u32 decap_fib_index;
110   u32 decap_next_index;
111   u8 ver_o_c;
112   u8 length;
113   u8 md_type;
114   u8 next_protocol;
115   u32 spi_si;
116   u32 c1, c2, c3, c4;
117   u32 * tlvs;
118 } vnet_nsh_gre_add_del_tunnel_args_t;
119
120 int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, 
121                                  u32 * sw_if_indexp);
122
123 #endif /* included_vnet_nsh_gre_h */