blob: f107d5e76cdab7e3d25e5287ddf53d4025367be3 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*---------------------------------------------------------------------------
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 Ranns0bfe5d82016-08-25 15:29:12 +010017#include <vnet/fib/ip6_fib.h>
Ole Troan6ee40512018-02-12 18:14:39 +010018#include <vnet/ip/ip.h>
Ole Troan298c6952018-03-08 12:30:43 +010019#include <vnet/ipip/ipip.h>
Ole Troan6ee40512018-02-12 18:14:39 +010020#include <vnet/vnet.h>
21#include <vppinfra/error.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010022
Ole Troan6ee40512018-02-12 18:14:39 +010023#define SIXRD_DEFAULT_MTU 1480 /* 1500 - IPv4 header */
Ed Warnickecb9cada2015-12-08 15:45:58 -070024
Ole Troan6ee40512018-02-12 18:14:39 +010025#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 Warnickecb9cada2015-12-08 15:45:58 -070031
Ole Troan6ee40512018-02-12 18:14:39 +010032
33typedef enum
34{
35#define _(sym, str) SIXRD_ERROR_##sym,
36 foreach_sixrd_error
Ed Warnickecb9cada2015-12-08 15:45:58 -070037#undef _
Ole Troan6ee40512018-02-12 18:14:39 +010038 SIXRD_N_ERROR,
39} sixrd_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070040
Dave Wallace71612d62017-10-24 01:32:41 -040041extern sixrd_main_t sixrd_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
Ole Troan6ee40512018-02-12 18:14:39 +010043static_always_inline sixrd_tunnel_t *
44find_tunnel_by_ip4_address (ip4_address_t * ip)
Ed Warnickecb9cada2015-12-08 15:45:58 -070045{
Ole Troan6ee40512018-02-12 18:14:39 +010046 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 Warnickecb9cada2015-12-08 15:45:58 -070052}
53
Ole Troan6ee40512018-02-12 18:14:39 +010054static_always_inline sixrd_tunnel_t *
55ip4_sixrd_get_tunnel (u32 sdi, ip4_address_t * addr, u8 * error)
Ed Warnickecb9cada2015-12-08 15:45:58 -070056{
Ole Troan6ee40512018-02-12 18:14:39 +010057 sixrd_tunnel_t *t = find_tunnel_by_ip4_address (addr);
58 if (!t)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010059 {
Ole Troan6ee40512018-02-12 18:14:39 +010060 *error = SIXRD_ERROR_NO_TUNNEL;
61 return NULL;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010062 }
Ole Troan6ee40512018-02-12 18:14:39 +010063 return t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070064}
Ole Troan6ee40512018-02-12 18:14:39 +010065
66/*
67 * fd.io coding-style-patch-verification: ON
68 *
69 * Local Variables:
70 * eval: (c-set-style "gnu")
71 * End:
72 */