Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 25 | typedef struct |
| 26 | { |
| 27 | /* ip6 addresses */ |
| 28 | ip6_address_t our_address; |
| 29 | ip6_address_t client_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 31 | /* l2tpv3 header parameters */ |
| 32 | u64 local_cookie[2]; |
| 33 | u64 remote_cookie; |
| 34 | u32 local_session_id; |
| 35 | u32 remote_session_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 37 | /* tunnel interface */ |
| 38 | u32 hw_if_index; |
| 39 | u32 sw_if_index; |
Pierre Pfister | 08e0312 | 2016-07-15 09:19:39 +0100 | [diff] [blame] | 40 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 41 | /* fib index used for outgoing encapsulated packets */ |
| 42 | u32 encap_fib_index; |
Pierre Pfister | 80ee213 | 2016-06-22 12:54:48 +0100 | [diff] [blame] | 43 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 44 | u8 l2tp_hdr_size; |
| 45 | u8 l2_sublayer_present; |
| 46 | u8 cookie_flags; /* in host byte order */ |
| 47 | |
| 48 | u8 admin_up; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | } l2t_session_t; |
| 50 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 51 | typedef enum |
| 52 | { |
| 53 | L2T_LOOKUP_SRC_ADDRESS = 0, |
| 54 | L2T_LOOKUP_DST_ADDRESS, |
| 55 | L2T_LOOKUP_SESSION_ID, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | } ip6_to_l2_lookup_t; |
| 57 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 58 | typedef struct |
| 59 | { |
| 60 | /* session pool */ |
| 61 | l2t_session_t *sessions; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 63 | /* ip6 -> l2 hash tables. Make up your minds, people... */ |
| 64 | uword *session_by_src_address; |
| 65 | uword *session_by_dst_address; |
| 66 | uword *session_by_session_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 68 | ip6_to_l2_lookup_t lookup_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 70 | /* Counters */ |
| 71 | vlib_combined_counter_main_t counter_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 73 | /* vector of free l2tpv3 tunnel interfaces */ |
| 74 | u32 *free_l2tpv3_tunnel_hw_if_indices; |
| 75 | |
| 76 | /* show device instance by real device instance */ |
| 77 | u32 *dev_inst_by_real; |
| 78 | |
| 79 | /* convenience */ |
| 80 | vlib_main_t *vlib_main; |
| 81 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
| 83 | } l2t_main_t; |
| 84 | |
| 85 | /* Packet trace structure */ |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 86 | typedef struct |
| 87 | { |
| 88 | int is_user_to_network; |
| 89 | u32 session_index; |
| 90 | ip6_address_t our_address; |
| 91 | ip6_address_t client_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | } l2t_trace_t; |
| 93 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame^] | 94 | extern l2t_main_t l2t_main; |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 95 | extern vlib_node_registration_t l2t_encap_node; |
| 96 | extern vlib_node_registration_t l2t_decap_node; |
Pierre Pfister | a026eb1 | 2016-06-20 14:52:22 +0100 | [diff] [blame] | 97 | extern vlib_node_registration_t l2t_decap_local_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 99 | enum |
| 100 | { |
| 101 | SESSION_COUNTER_USER_TO_NETWORK = 0, |
| 102 | SESSION_COUNTER_NETWORK_TO_USER, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 105 | static inline u32 |
| 106 | session_index_to_counter_index (u32 session_index, u32 counter_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | { |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 108 | return ((session_index << 1) + counter_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 111 | u8 *format_l2t_trace (u8 * s, va_list * args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 113 | typedef struct |
| 114 | { |
| 115 | /* Any per-interface config would go here */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | } ip6_l2tpv3_config_t; |
| 117 | |
| 118 | uword unformat_pg_l2tp_header (unformat_input_t * input, va_list * args); |
| 119 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 120 | void l2tp_encap_init (vlib_main_t * vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | void l2tp_decap_init (void); |
| 122 | int create_l2tpv3_ipv6_tunnel (l2t_main_t * lm, |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 123 | ip6_address_t * client_address, |
| 124 | ip6_address_t * our_address, |
| 125 | u32 local_session_id, |
| 126 | u32 remote_session_id, |
| 127 | u64 local_cookie, |
| 128 | u64 remote_cookie, |
| 129 | int l2_sublayer_present, |
| 130 | u32 encap_fib_index, u32 * sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
| 132 | int l2tpv3_set_tunnel_cookies (l2t_main_t * lm, |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 133 | u32 sw_if_index, |
| 134 | u64 new_local_cookie, u64 new_remote_cookie); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 136 | int l2tpv3_interface_enable_disable (vnet_main_t * vnm, |
| 137 | u32 sw_if_index, int enable_disable); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | |
| 139 | #endif /* __included_l2tp_h__ */ |
Calvin | ee275a7 | 2016-08-10 11:01:41 -0400 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * fd.io coding-style-patch-verification: ON |
| 143 | * |
| 144 | * Local Variables: |
| 145 | * eval: (c-set-style "gnu") |
| 146 | * End: |
| 147 | */ |