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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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 *---------------------------------------------------------------------------
17 #include <vnet/fib/ip6_fib.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/vnet.h>
20 #include <vppinfra/error.h>
22 #define SIXRD_DEFAULT_MTU 1480 /* 1500 - IPv4 header */
30 ip6_address_t ip6_prefix;
31 ip4_address_t ip4_prefix;
32 ip4_address_t ip4_src;
47 /* pool of SIXRD domains */
48 sixrd_tunnel_t *tunnels;
49 u32 *tunnel_index_by_sw_if_index;
54 #define foreach_sixrd_error \
55 /* Must be first. */ \
56 _(NONE, "valid SIXRD packets") \
57 _(BAD_PROTOCOL, "bad protocol") \
58 _(SEC_CHECK, "security check failed") \
59 _(NO_TUNNEL, "no tunnel")
64 #define _(sym, str) SIXRD_ERROR_##sym,
70 extern sixrd_main_t sixrd_main;
75 static_always_inline u32
76 sixrd_get_addr_net (const sixrd_tunnel_t * t, u64 dal)
79 if (t->ip4_prefix_len == 32)
80 return (t->ip4_prefix.as_u32);
82 dal = clib_net_to_host_u64 (dal);
84 /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset
86 u32 mask = ~(~0ULL << (32 - t->ip4_prefix_len));
88 clib_net_to_host_u32 (t->
89 ip4_prefix.as_u32) | ((u32) (dal >> t->
91 return clib_host_to_net_u32 (ip4);
94 static_always_inline sixrd_tunnel_t *
95 find_tunnel_by_ip4_address (ip4_address_t * ip)
97 sixrd_main_t *sm = &sixrd_main;
99 p = hash_get (sm->tunnel_by_ip, ip->as_u32);
102 return pool_elt_at_index (sm->tunnels, p[0]);
105 static_always_inline sixrd_tunnel_t *
106 ip4_sixrd_get_tunnel (u32 sdi, ip4_address_t * addr, u8 * error)
108 sixrd_tunnel_t *t = find_tunnel_by_ip4_address (addr);
111 *error = SIXRD_ERROR_NO_TUNNEL;
118 * fd.io coding-style-patch-verification: ON
121 * eval: (c-set-style "gnu")