FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
sixrd.h
Go to the documentation of this file.
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>
17 #include <vppinfra/error.h>
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/fib/ip6_fib.h>
21 
22 #include "sixrd_dpo.h"
23 
24 int sixrd_create_domain(ip6_address_t *ip6_prefix, u8 ip6_prefix_len,
25  ip4_address_t *ip4_prefix, u8 ip4_prefix_len,
26  ip4_address_t *ip4_src, u32 *sixrd_domain_index, u16 mtu);
27 int sixrd_delete_domain(u32 sixrd_domain_index);
28 u8 *format_sixrd_trace(u8 *s, va_list *args);
29 
30 typedef struct {
36 
37  /* helpers */
39 
42 
43 typedef struct {
44  /* pool of SIXRD domains */
46 
47  /* convenience */
50 } sixrd_main_t;
51 
52 #define foreach_sixrd_error \
53  /* Must be first. */ \
54  _(NONE, "valid SIXRD packets") \
55  _(BAD_PROTOCOL, "bad protocol") \
56  _(WRONG_ICMP_TYPE, "wrong icmp type") \
57  _(SEC_CHECK, "security check failed") \
58  _(ICMP, "unable to translate ICMP") \
59  _(UNKNOWN, "unknown") \
60  _(NO_DOMAIN, "no domain") \
61  _(ENCAPSULATED, "encapsulated") \
62  _(DECAPSULATED, "decapsulated") \
63  _(TRANSLATED_4TO6, "translated 4 to 6") \
64  _(TRANSLATED_6TO4, "translated 6 to 4") \
65  _(FRAGMENT, "fragment handling error") \
66  _(FRAGMENT_QUEUED, "dropped, missing first fragment") \
67  _(FRAGMENTED, "packets requiring fragmentation") \
68  _(FRAGMENT_PARTS, "fragment parts") \
69  _(MALFORMED, "malformed packet")
70 
71 typedef enum {
72 #define _(sym,str) SIXRD_ERROR_##sym,
74 #undef _
76  } sixrd_error_t;
77 
78 typedef struct {
81 
83 
84 /*
85  * sixrd_get_addr
86  */
89 {
90 
91  /* 1:1 mode */
92  if (d->ip4_prefix_len == 32) return (d->ip4_prefix.as_u32);
93 
94  /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset ip6_prefix_len */
95  return (d->ip4_prefix.as_u32 | (u32)(dal >> d->shift));
96 }
97 
98 /*
99  * Get the SIXRD domain from an IPv6 lookup adjacency.
100  */
102 ip6_sixrd_get_domain (u32 sdi, u32 *sixrd_domain_index)
103 {
104  sixrd_main_t *mm = &sixrd_main;
105  sixrd_dpo_t *sd;
106 
107  sd = sixrd_dpo_get(sdi);
108 
109  ASSERT(sd);
110  *sixrd_domain_index = sd->sd_domain;
111  return pool_elt_at_index(mm->domains, *sixrd_domain_index);
112 }
113 
114 /*
115  * Get the SIXRD domain from an IPv4 lookup adjacency.
116  * If the IPv4 address is not shared, no lookup is required.
117  * The IPv6 address is used otherwise.
118  */
121  u32 *sixrd_domain_index, u8 *error)
122 {
123  sixrd_main_t *mm = &sixrd_main;
124  sixrd_dpo_t *sd;
125 
126  sd = sixrd_dpo_get(sdi);
127  *sixrd_domain_index = sd->sd_domain;
128  if (*sixrd_domain_index != ~0)
129  return pool_elt_at_index(mm->domains, *sixrd_domain_index);
130 
131  u32 lbi = ip6_fib_table_fwding_lookup(&ip6_main, 0, addr);
132  const dpo_id_t *dpo = load_balance_get_bucket(lbi, 0);
134  {
135  sd = sixrd_dpo_get(dpo->dpoi_index);
136  *sixrd_domain_index = sd->sd_domain;
137  return pool_elt_at_index(mm->domains, *sixrd_domain_index);
138  }
139  *error = SIXRD_ERROR_NO_DOMAIN;
140  return NULL;
141 }
ip4_address_t ip4_src
Definition: sixrd.h:33
sixrd_error_t
Definition: sixrd.h:71
vlib_main_t * vlib_main
Definition: sixrd.h:48
static_always_inline sixrd_domain_t * ip6_sixrd_get_domain(u32 sdi, u32 *sixrd_domain_index)
Definition: sixrd.h:102
static_always_inline sixrd_domain_t * ip4_sixrd_get_domain(u32 sdi, ip6_address_t *addr, u32 *sixrd_domain_index, u8 *error)
Definition: sixrd.h:120
dpo_type_t sixrd_dpo_type
The register SIXRD DPO type.
Definition: sixrd_dpo.c:27
#define PREDICT_TRUE(x)
Definition: clib.h:106
#define NULL
Definition: clib.h:55
static u32 ip6_fib_table_fwding_lookup(ip6_main_t *im, u32 fib_index, const ip6_address_t *dst)
Definition: ip6_fib.h:67
static_always_inline u32 sixrd_get_addr(sixrd_domain_t *d, u64 dal)
Definition: sixrd.h:88
u8 ip4_prefix_len
Definition: sixrd.h:35
u32 sd_domain
the SIXRD domain index
Definition: sixrd_dpo.h:35
#define static_always_inline
Definition: clib.h:93
vnet_main_t * vnet_main
Definition: sixrd.h:49
unsigned long u64
Definition: types.h:89
ip4_address_t ip4_prefix
Definition: sixrd.h:32
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
dpo_type_t dpoi_type
the type
Definition: dpo.h:170
#define foreach_sixrd_error
Definition: sixrd.h:52
static sixrd_dpo_t * sixrd_dpo_get(index_t index)
Definition: sixrd_dpo.h:54
sixrd_main_t sixrd_main
Definition: sixrd.c:35
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
Definition: load_balance.c:294
int sixrd_delete_domain(u32 sixrd_domain_index)
Definition: sixrd.c:148
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
ip6_main_t ip6_main
Definition: ip6_forward.c:3009
ip6_address_t ip6_prefix
Definition: sixrd.h:31
sixrd_domain_t * domains
Definition: sixrd.h:45
u32 sixrd_domain_index
Definition: sixrd.h:79
unsigned short u16
Definition: types.h:57
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:182
unsigned char u8
Definition: types.h:56
u8 * format_sixrd_trace(u8 *s, va_list *args)
Definition: sixrd.c:324
A representation of a 6RD DPO.
Definition: sixrd_dpo.h:25
u8 ip6_prefix_len
Definition: sixrd.h:34
int sixrd_create_domain(ip6_address_t *ip6_prefix, u8 ip6_prefix_len, ip4_address_t *ip4_prefix, u8 ip4_prefix_len, ip4_address_t *ip4_src, u32 *sixrd_domain_index, u16 mtu)
Definition: sixrd.c:38
vhost_vring_addr_t addr
Definition: vhost-user.h:83