gso: use the header offsets from buffer metadata
[vpp.git] / src / vnet / ip-neighbor / ip_neighbor_types.c
1 /*
2  * ip_neighboor.h: ip neighbor generic services
3  *
4  * Copyright (c) 2018 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 #include <vnet/ip-neighbor/ip_neighbor_types.h>
19
20 void
21 ip_neighbor_clone (const ip_neighbor_t * ipn, ip_neighbor_t * clone)
22 {
23   clib_memcpy (clone, ipn, sizeof (*ipn));
24
25   clone->ipn_key = clib_mem_alloc (sizeof (ip_neighbor_key_t));
26   clib_memcpy (clone->ipn_key, ipn->ipn_key, sizeof (ip_neighbor_key_t));
27 }
28
29 void
30 ip_neighbor_free (ip_neighbor_t * ipn)
31 {
32   clib_mem_free (ipn->ipn_key);
33 }
34
35 u8 *
36 format_ip_neighbor_flags (u8 * s, va_list * args)
37 {
38   ip_neighbor_flags_t flags = va_arg (*args, int);
39
40 #define _(a,b,c,d)                              \
41   if (flags & IP_NEIGHBOR_FLAG_##a)             \
42     s = format (s, "%s", d);
43   foreach_ip_neighbor_flag
44 #undef _
45     return s;
46 }
47
48 u8 *
49 format_ip_neighbor_key (u8 * s, va_list * va)
50 {
51   ip_neighbor_key_t *key = va_arg (*va, ip_neighbor_key_t *);
52
53   return (format (s, "[%U, %U]",
54                   format_vnet_sw_if_index_name, vnet_get_main (),
55                   key->ipnk_sw_if_index, format_ip_address, &key->ipnk_ip));
56 }
57
58 u8 *
59 format_ip_neighbor_watcher (u8 * s, va_list * va)
60 {
61   ip_neighbor_watcher_t *watcher = va_arg (*va, ip_neighbor_watcher_t *);
62
63   return (format (s, "[pid:%d, client:%d]",
64                   clib_host_to_net_u32 (watcher->ipw_pid),
65                   clib_host_to_net_u32 (watcher->ipw_client)));
66 }
67
68 u8 *
69 format_ip_neighbor (u8 * s, va_list * va)
70 {
71   index_t ipni = va_arg (*va, index_t);
72   ip_neighbor_t *ipn;
73
74   ipn = ip_neighbor_get (ipni);
75
76   return (format (s, "%=12U%=40U%=6U%=20U%U",
77                   format_vlib_time, vlib_get_main (),
78                   ipn->ipn_time_last_updated,
79                   format_ip_address, &ipn->ipn_key->ipnk_ip,
80                   format_ip_neighbor_flags, ipn->ipn_flags,
81                   format_mac_address_t, &ipn->ipn_mac,
82                   format_vnet_sw_if_index_name, vnet_get_main (),
83                   ipn->ipn_key->ipnk_sw_if_index));
84 }
85
86 static void
87 ip_neighbor_alloc_one_ctr (ip_neighbor_counters_t *ctr, vlib_dir_t dir,
88                            ip_neighbor_counter_type_t type, u32 sw_if_index)
89 {
90   vlib_validate_simple_counter (&(ctr->ipnc[dir][type]), sw_if_index);
91   vlib_zero_simple_counter (&(ctr->ipnc[dir][type]), sw_if_index);
92 }
93
94 void
95 ip_neighbor_alloc_ctr (ip_neighbor_counters_t *ctr, u32 sw_if_index)
96 {
97   ip_neighbor_counter_type_t type;
98   vlib_dir_t dir;
99
100   FOREACH_VLIB_DIR (dir)
101   {
102     FOREACH_IP_NEIGHBOR_CTR (type)
103     {
104       ip_neighbor_alloc_one_ctr (ctr, dir, type, sw_if_index);
105     }
106   }
107 }
108
109 u8 *
110 format_ip_neighbor_counters (u8 *s, va_list *args)
111 {
112   ip_neighbor_counters_t *ctr = va_arg (*args, ip_neighbor_counters_t *);
113   u32 sw_if_index = va_arg (*args, u32);
114   vlib_dir_t dir;
115
116   FOREACH_VLIB_DIR (dir)
117   {
118     s = format (s, " %U:[", format_vlib_rx_tx, dir);
119
120 #define _(a, b)                                                               \
121   s = format (s, "%s:%lld ", b,                                               \
122               vlib_get_simple_counter (&ctr->ipnc[dir][IP_NEIGHBOR_CTR_##a],  \
123                                        sw_if_index));
124     foreach_ip_neighbor_counter_type
125 #undef _
126
127       s = format (s, "]");
128   }
129
130   return (s);
131 }
132
133 /*
134  * fd.io coding-style-patch-verification: ON
135  *
136  * Local Variables:
137  * eval: (c-set-style "gnu")
138  * End:
139  */