Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /*--------------------------------------------------------------------------- |
| 2 | * Copyright (c) 2009-2014 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 | */ |
| 16 | #include <stdbool.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 17 | #include <vnet/fib/ip6_fib.h> |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 18 | #include <vnet/ip/ip.h> |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame^] | 19 | #include <vnet/ipip/ipip.h> |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 20 | #include <vnet/vnet.h> |
| 21 | #include <vppinfra/error.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 22 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 23 | #define SIXRD_DEFAULT_MTU 1480 /* 1500 - IPv4 header */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 25 | #define foreach_sixrd_error \ |
| 26 | /* Must be first. */ \ |
| 27 | _(NONE, "valid SIXRD packets") \ |
| 28 | _(BAD_PROTOCOL, "bad protocol") \ |
| 29 | _(SEC_CHECK, "security check failed") \ |
| 30 | _(NO_TUNNEL, "no tunnel") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 32 | |
| 33 | typedef enum |
| 34 | { |
| 35 | #define _(sym, str) SIXRD_ERROR_##sym, |
| 36 | foreach_sixrd_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | #undef _ |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 38 | SIXRD_N_ERROR, |
| 39 | } sixrd_error_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 41 | extern sixrd_main_t sixrd_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 43 | static_always_inline sixrd_tunnel_t * |
| 44 | find_tunnel_by_ip4_address (ip4_address_t * ip) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | { |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 46 | sixrd_main_t *sm = &sixrd_main; |
| 47 | uword *p; |
| 48 | p = hash_get (sm->tunnel_by_ip, ip->as_u32); |
| 49 | if (!p) |
| 50 | return NULL; |
| 51 | return pool_elt_at_index (sm->tunnels, p[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 54 | static_always_inline sixrd_tunnel_t * |
| 55 | ip4_sixrd_get_tunnel (u32 sdi, ip4_address_t * addr, u8 * error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | { |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 57 | sixrd_tunnel_t *t = find_tunnel_by_ip4_address (addr); |
| 58 | if (!t) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 59 | { |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 60 | *error = SIXRD_ERROR_NO_TUNNEL; |
| 61 | return NULL; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 62 | } |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 63 | return t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | } |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | * fd.io coding-style-patch-verification: ON |
| 68 | * |
| 69 | * Local Variables: |
| 70 | * eval: (c-set-style "gnu") |
| 71 | * End: |
| 72 | */ |