L2TP: Add option for custom fib id for outgoing encapsulated packets
[vpp.git] / vnet / vnet / l2tp / l2tp.h
1 /*
2  * l2tp.h : L2TPv3 tunnel support
3  *
4  * Copyright (c) 2013 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef __included_l2tp_h__
19 #define __included_l2tp_h__
20
21 #include <vlib/vlib.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/l2tp/packet.h>
24
25 typedef struct {
26     /* ip6 addresses */
27     ip6_address_t our_address;
28     ip6_address_t client_address;
29
30     /* l2tpv3 header parameters */
31     u64 local_cookie[2];
32     u64 remote_cookie;
33     u32 local_session_id;
34     u32 remote_session_id;
35     
36     /* tunnel interface */
37     u32 hw_if_index;
38     u32 sw_if_index;
39
40     u32 encap_fib_index; //fib index used for outgoing encapsulated packets
41
42     u8  l2tp_hdr_size;
43     u8  l2_sublayer_present;
44     u8  cookie_flags;           /* in host byte order */
45
46     u8 admin_up;
47 } l2t_session_t;
48
49 typedef enum {
50     L2T_LOOKUP_SRC_ADDRESS = 0,
51     L2T_LOOKUP_DST_ADDRESS,
52     L2T_LOOKUP_SESSION_ID,
53 } ip6_to_l2_lookup_t;
54
55 typedef struct {
56     /* session pool */
57     l2t_session_t *sessions;
58     
59     /* ip6 -> l2 hash tables. Make up your minds, people... */
60     uword *session_by_src_address;
61     uword *session_by_dst_address;
62     uword *session_by_session_id;
63
64     ip6_to_l2_lookup_t lookup_type;
65
66     /* Counters */
67     vlib_combined_counter_main_t counter_main;
68     
69     /* vector of free l2tpv3 tunnel interfaces */
70     u32 * free_l2tpv3_tunnel_hw_if_indices;
71
72     /* show device instance by real device instance */
73     u32 * dev_inst_by_real;
74
75     /* convenience */
76     vlib_main_t *vlib_main;
77     vnet_main_t *vnet_main;
78
79 } l2t_main_t;
80
81 /* Packet trace structure */
82 typedef struct {
83     int is_user_to_network;
84     u32 session_index;
85     ip6_address_t our_address;
86     ip6_address_t client_address;
87 } l2t_trace_t;
88
89 l2t_main_t l2t_main;
90 extern vlib_node_registration_t l2t_encap_node;
91 extern vlib_node_registration_t l2t_decap_node;
92 extern vlib_node_registration_t l2t_decap_local_node;
93
94 enum {
95     SESSION_COUNTER_USER_TO_NETWORK=0,
96     SESSION_COUNTER_NETWORK_TO_USER,
97 };
98
99 static inline u32 session_index_to_counter_index (u32 session_index, 
100                                                   u32 counter_id)
101 {
102     return ((session_index << 1) + counter_id);
103 }
104
105 u8 * format_l2t_trace (u8 * s, va_list * args);
106
107 typedef struct {
108   // Any per-interface config would go here
109 } ip6_l2tpv3_config_t;
110
111 uword unformat_pg_l2tp_header (unformat_input_t * input, va_list * args);
112
113 void l2tp_encap_init (vlib_main_t *vm);
114 void l2tp_decap_init (void);
115 int create_l2tpv3_ipv6_tunnel (l2t_main_t * lm,
116                                ip6_address_t * client_address,
117                                ip6_address_t * our_address,
118                                u32 local_session_id,
119                                u32 remote_session_id,
120                                u64 local_cookie,
121                                u64 remote_cookie,
122                                int l2_sublayer_present,
123                                u32 encap_fib_index,
124                                u32 * sw_if_index);
125
126 int l2tpv3_set_tunnel_cookies (l2t_main_t * lm,
127                                u32 sw_if_index,
128                                u64 new_local_cookie,
129                                u64 new_remote_cookie);
130
131 int l2tpv3_interface_enable_disable (vnet_main_t * vnm, 
132                                      u32 sw_if_index, 
133                                      int enable_disable);
134
135 #endif /* __included_l2tp_h__ */