blob: 8899c49ce9c44f5358d5084bae7f248804e2405c [file] [log] [blame]
Dave Barachced48e72016-02-08 15:57:35 -05001/*
2 * Copyright (c) 2011-2016 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#include <vnet/cdp/cdp_node.h>
16#include <vppinfra/hash.h>
17#include <vnet/unix/pcap.h>
18#include <vnet/srp/srp.h>
19#include <vnet/ppp/ppp.h>
20#include <vnet/hdlc/hdlc.h>
21#include <vnet/srp/packet.h>
22
23/*
24 * Generate a set of specific CDP TLVs.
25 *
26 * $$$ eventually these need to fish better data from
27 * other data structures; e.g. the hostname, software version info
28 * etc.
29 */
30
Dave Barach861bd212016-08-09 08:55:49 -040031static void
32add_device_name_tlv (vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050033{
Dave Barach861bd212016-08-09 08:55:49 -040034 cdp_tlv_t *t = (cdp_tlv_t *) * t0p;
Dave Barachced48e72016-02-08 15:57:35 -050035
Dave Barach861bd212016-08-09 08:55:49 -040036 t->t = htons (CDP_TLV_device_name);
37 t->l = htons (3 + sizeof (*t));
38 clib_memcpy (&t->v, "VPP", 3);
39
40 *t0p += ntohs (t->l);
Dave Barachced48e72016-02-08 15:57:35 -050041}
42
Dave Barach861bd212016-08-09 08:55:49 -040043static void
44add_port_id_tlv (vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050045{
Dave Barach861bd212016-08-09 08:55:49 -040046 cdp_tlv_t *t = (cdp_tlv_t *) * t0p;
Dave Barachced48e72016-02-08 15:57:35 -050047
Dave Barach861bd212016-08-09 08:55:49 -040048 t->t = htons (CDP_TLV_port_id);
49 t->l = htons (vec_len (hw->name) + sizeof (*t));
50 clib_memcpy (&t->v, hw->name, vec_len (hw->name));
51 *t0p += ntohs (t->l);
Dave Barachced48e72016-02-08 15:57:35 -050052}
53
Dave Barach861bd212016-08-09 08:55:49 -040054static void
55add_version_tlv (vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050056{
Dave Barach861bd212016-08-09 08:55:49 -040057 cdp_tlv_t *t = (cdp_tlv_t *) * t0p;
Dave Barachced48e72016-02-08 15:57:35 -050058
Dave Barach861bd212016-08-09 08:55:49 -040059 t->t = htons (CDP_TLV_version);
60 t->l = htons (12 + sizeof (*t));
61 clib_memcpy (&t->v, "VPP Software", 12);
62 *t0p += ntohs (t->l);
Dave Barachced48e72016-02-08 15:57:35 -050063}
64
Dave Barach861bd212016-08-09 08:55:49 -040065static void
66add_platform_tlv (vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050067{
Dave Barach861bd212016-08-09 08:55:49 -040068 cdp_tlv_t *t = (cdp_tlv_t *) * t0p;
Dave Barachced48e72016-02-08 15:57:35 -050069
Dave Barach861bd212016-08-09 08:55:49 -040070 t->t = htons (CDP_TLV_platform);
71 t->l = htons (2 + sizeof (*t));
72 clib_memcpy (&t->v, "SW", 2);
73 *t0p += ntohs (t->l);
Dave Barachced48e72016-02-08 15:57:35 -050074}
75
Dave Barach861bd212016-08-09 08:55:49 -040076static void
77add_capability_tlv (vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050078{
Dave Barach861bd212016-08-09 08:55:49 -040079 cdp_tlv_t *t = (cdp_tlv_t *) * t0p;
80 u32 capabilities;
Dave Barachced48e72016-02-08 15:57:35 -050081
Dave Barach861bd212016-08-09 08:55:49 -040082 t->t = htons (CDP_TLV_capabilities);
83 t->l = htons (4 + sizeof (*t));
84 capabilities = CDP_ROUTER_DEVICE;
85 capabilities = htonl (capabilities);
86 clib_memcpy (&t->v, &capabilities, sizeof (capabilities));
87 *t0p += ntohs (t->l);
Dave Barachced48e72016-02-08 15:57:35 -050088}
89
Dave Barach861bd212016-08-09 08:55:49 -040090static void
91add_tlvs (cdp_main_t * cm, vnet_hw_interface_t * hw, u8 ** t0p)
Dave Barachced48e72016-02-08 15:57:35 -050092{
Dave Barach861bd212016-08-09 08:55:49 -040093 add_device_name_tlv (hw, t0p);
94 add_port_id_tlv (hw, t0p);
95 add_version_tlv (hw, t0p);
96 add_platform_tlv (hw, t0p);
97 add_capability_tlv (hw, t0p);
Dave Barachced48e72016-02-08 15:57:35 -050098}
99
100/*
101 * send a cdp pkt on an ethernet interface
102 */
Dave Barach861bd212016-08-09 08:55:49 -0400103static void
104send_ethernet_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
Dave Barachced48e72016-02-08 15:57:35 -0500105{
Dave Barach861bd212016-08-09 08:55:49 -0400106 u32 *to_next;
107 ethernet_llc_snap_and_cdp_header_t *h0;
108 vnet_hw_interface_t *hw;
109 u32 bi0;
110 vlib_buffer_t *b0;
111 u8 *t0;
112 u16 checksum;
113 int nbytes_to_checksum;
114 int i;
115 vlib_frame_t *f;
116 vlib_main_t *vm = cm->vlib_main;
117 vnet_main_t *vnm = cm->vnet_main;
Dave Barachced48e72016-02-08 15:57:35 -0500118
Dave Barach861bd212016-08-09 08:55:49 -0400119 for (i = 0; i < count; i++)
120 {
Damjan Marion607de1a2016-08-16 22:53:54 +0200121 /*
Dave Barach861bd212016-08-09 08:55:49 -0400122 * see cdp_periodic_init() to understand what's already painted
Damjan Marion607de1a2016-08-16 22:53:54 +0200123 * into the buffer by the packet template mechanism
Dave Barach861bd212016-08-09 08:55:49 -0400124 */
125 h0 = vlib_packet_template_get_packet
126 (vm, &cm->packet_templates[n->packet_template_index], &bi0);
Dave Barachced48e72016-02-08 15:57:35 -0500127
Steven0ff5c562017-09-28 16:38:56 -0700128 if (!h0)
129 break;
130
Dave Barach861bd212016-08-09 08:55:49 -0400131 /* Add the interface's ethernet source address */
132 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
Dave Barachced48e72016-02-08 15:57:35 -0500133
Dave Barach861bd212016-08-09 08:55:49 -0400134 clib_memcpy (h0->ethernet.src_address, hw->hw_address,
135 vec_len (hw->hw_address));
Dave Barachf60a8222016-02-08 16:57:13 -0500136
Dave Barach861bd212016-08-09 08:55:49 -0400137 t0 = (u8 *) & h0->cdp.data;
Dave Barachced48e72016-02-08 15:57:35 -0500138
Dave Barach861bd212016-08-09 08:55:49 -0400139 /* add TLVs */
140 add_tlvs (cm, hw, &t0);
Dave Barachced48e72016-02-08 15:57:35 -0500141
Dave Barach861bd212016-08-09 08:55:49 -0400142 /* add the cdp packet checksum */
143 nbytes_to_checksum = t0 - (u8 *) & h0->cdp;
144 checksum = cdp_checksum (&h0->cdp, nbytes_to_checksum);
145 h0->cdp.checksum = htons (checksum);
146
147 /* Set the outbound packet length */
148 b0 = vlib_get_buffer (vm, bi0);
149 b0->current_length = nbytes_to_checksum + sizeof (*h0)
150 - sizeof (cdp_hdr_t);
151
152 /* And the outbound interface */
153 vnet_buffer (b0)->sw_if_index[VLIB_TX] = hw->sw_if_index;
154
155 /* Set the 802.3 ethernet length */
156 h0->ethernet.len = htons (b0->current_length
157 - sizeof (ethernet_802_3_header_t));
158
159 /* And output the packet on the correct interface */
160 f = vlib_get_frame_to_node (vm, hw->output_node_index);
161 to_next = vlib_frame_vector_args (f);
162 to_next[0] = bi0;
163 f->n_vectors = 1;
164
165 vlib_put_frame_to_node (vm, hw->output_node_index, f);
166 n->last_sent = vlib_time_now (vm);
Dave Barachced48e72016-02-08 15:57:35 -0500167 }
168}
169
170/*
171 * send a cdp pkt on an hdlc interface
172 */
Dave Barach861bd212016-08-09 08:55:49 -0400173static void
174send_hdlc_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
Dave Barachced48e72016-02-08 15:57:35 -0500175{
Dave Barach861bd212016-08-09 08:55:49 -0400176 u32 *to_next;
177 hdlc_and_cdp_header_t *h0;
178 vnet_hw_interface_t *hw;
179 u32 bi0;
180 vlib_buffer_t *b0;
181 u8 *t0;
182 u16 checksum;
183 int nbytes_to_checksum;
184 int i;
185 vlib_frame_t *f;
186 vlib_main_t *vm = cm->vlib_main;
187 vnet_main_t *vnm = cm->vnet_main;
Dave Barachced48e72016-02-08 15:57:35 -0500188
Dave Barach861bd212016-08-09 08:55:49 -0400189 for (i = 0; i < count; i++)
190 {
Damjan Marion607de1a2016-08-16 22:53:54 +0200191 /*
Dave Barach861bd212016-08-09 08:55:49 -0400192 * see cdp_periodic_init() to understand what's already painted
Damjan Marion607de1a2016-08-16 22:53:54 +0200193 * into the buffer by the packet template mechanism
Dave Barach861bd212016-08-09 08:55:49 -0400194 */
195 h0 = vlib_packet_template_get_packet
196 (vm, &cm->packet_templates[n->packet_template_index], &bi0);
Dave Barachced48e72016-02-08 15:57:35 -0500197
Dave Barach861bd212016-08-09 08:55:49 -0400198 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
Dave Barachced48e72016-02-08 15:57:35 -0500199
Dave Barach861bd212016-08-09 08:55:49 -0400200 t0 = (u8 *) & h0->cdp.data;
Dave Barachced48e72016-02-08 15:57:35 -0500201
Dave Barach861bd212016-08-09 08:55:49 -0400202 /* add TLVs */
203 add_tlvs (cm, hw, &t0);
Dave Barachced48e72016-02-08 15:57:35 -0500204
Dave Barach861bd212016-08-09 08:55:49 -0400205 /* add the cdp packet checksum */
206 nbytes_to_checksum = t0 - (u8 *) & h0->cdp;
207 checksum = cdp_checksum (&h0->cdp, nbytes_to_checksum);
208 h0->cdp.checksum = htons (checksum);
209
210 /* Set the outbound packet length */
211 b0 = vlib_get_buffer (vm, bi0);
212 b0->current_length = nbytes_to_checksum + sizeof (*h0)
213 - sizeof (cdp_hdr_t);
214
215 /* And output the packet on the correct interface */
216 f = vlib_get_frame_to_node (vm, hw->output_node_index);
217 to_next = vlib_frame_vector_args (f);
218 to_next[0] = bi0;
219 f->n_vectors = 1;
220
221 vlib_put_frame_to_node (vm, hw->output_node_index, f);
222 n->last_sent = vlib_time_now (vm);
Dave Barachced48e72016-02-08 15:57:35 -0500223 }
224}
225
226/*
227 * send a cdp pkt on an srp interface
228 */
Dave Barach861bd212016-08-09 08:55:49 -0400229static void
230send_srp_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
Dave Barachced48e72016-02-08 15:57:35 -0500231{
Dave Barach861bd212016-08-09 08:55:49 -0400232 u32 *to_next;
233 srp_and_cdp_header_t *h0;
234 vnet_hw_interface_t *hw;
235 u32 bi0;
236 vlib_buffer_t *b0;
237 u8 *t0;
238 u16 checksum;
239 int nbytes_to_checksum;
240 int i;
241 vlib_frame_t *f;
242 vlib_main_t *vm = cm->vlib_main;
243 vnet_main_t *vnm = cm->vnet_main;
Dave Barachced48e72016-02-08 15:57:35 -0500244
Dave Barach861bd212016-08-09 08:55:49 -0400245 for (i = 0; i < count; i++)
246 {
Damjan Marion607de1a2016-08-16 22:53:54 +0200247 /*
Dave Barach861bd212016-08-09 08:55:49 -0400248 * see cdp_periodic_init() to understand what's already painted
Damjan Marion607de1a2016-08-16 22:53:54 +0200249 * into the buffer by the packet template mechanism
Dave Barach861bd212016-08-09 08:55:49 -0400250 */
251 h0 = vlib_packet_template_get_packet
252 (vm, &cm->packet_templates[n->packet_template_index], &bi0);
Dave Barachced48e72016-02-08 15:57:35 -0500253
Dave Barach861bd212016-08-09 08:55:49 -0400254 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
Dave Barachced48e72016-02-08 15:57:35 -0500255
Dave Barach861bd212016-08-09 08:55:49 -0400256 t0 = (u8 *) & h0->cdp.data;
Dave Barachced48e72016-02-08 15:57:35 -0500257
Dave Barach861bd212016-08-09 08:55:49 -0400258 /* add TLVs */
259 add_tlvs (cm, hw, &t0);
Dave Barachced48e72016-02-08 15:57:35 -0500260
Dave Barach861bd212016-08-09 08:55:49 -0400261 /* Add the interface's ethernet source address */
262 clib_memcpy (h0->ethernet.src_address, hw->hw_address,
263 vec_len (hw->hw_address));
Dave Barachced48e72016-02-08 15:57:35 -0500264
Dave Barach861bd212016-08-09 08:55:49 -0400265 /* add the cdp packet checksum */
266 nbytes_to_checksum = t0 - (u8 *) & h0->cdp;
267 checksum = cdp_checksum (&h0->cdp, nbytes_to_checksum);
268 h0->cdp.checksum = htons (checksum);
269
270 /* Set the outbound packet length */
271 b0 = vlib_get_buffer (vm, bi0);
272 b0->current_length = nbytes_to_checksum + sizeof (*h0)
273 - sizeof (cdp_hdr_t);
274
275 /* And output the packet on the correct interface */
276 f = vlib_get_frame_to_node (vm, hw->output_node_index);
277 to_next = vlib_frame_vector_args (f);
278 to_next[0] = bi0;
279 f->n_vectors = 1;
280
281 vlib_put_frame_to_node (vm, hw->output_node_index, f);
282 n->last_sent = vlib_time_now (vm);
Dave Barachced48e72016-02-08 15:57:35 -0500283 }
284}
285
286/*
287 * Decide which cdp packet template to use
288 */
Dave Barach861bd212016-08-09 08:55:49 -0400289static int
290pick_packet_template (cdp_main_t * cm, cdp_neighbor_t * n)
Dave Barachced48e72016-02-08 15:57:35 -0500291{
Dave Barach861bd212016-08-09 08:55:49 -0400292 n->packet_template_index = CDP_PACKET_TEMPLATE_ETHERNET;
Dave Barachced48e72016-02-08 15:57:35 -0500293
Dave Barach861bd212016-08-09 08:55:49 -0400294 return 0;
Dave Barachced48e72016-02-08 15:57:35 -0500295}
296
297/* Send a cdp neighbor announcement */
Dave Barach861bd212016-08-09 08:55:49 -0400298static void
299send_hello (cdp_main_t * cm, cdp_neighbor_t * n, int count)
Dave Barachced48e72016-02-08 15:57:35 -0500300{
Dave Barach861bd212016-08-09 08:55:49 -0400301 if (n->packet_template_index == (u8) ~ 0)
302 {
303 /* If we don't know how to talk to this peer, don't try again */
304 if (pick_packet_template (cm, n))
305 {
306 n->last_sent = 1e70;
307 return;
308 }
Dave Barachced48e72016-02-08 15:57:35 -0500309 }
310
Dave Barach861bd212016-08-09 08:55:49 -0400311 switch (n->packet_template_index)
Dave Barachced48e72016-02-08 15:57:35 -0500312 {
313 case CDP_PACKET_TEMPLATE_ETHERNET:
Dave Barach861bd212016-08-09 08:55:49 -0400314 send_ethernet_hello (cm, n, count);
315 break;
Dave Barachced48e72016-02-08 15:57:35 -0500316
317 case CDP_PACKET_TEMPLATE_HDLC:
Dave Barach861bd212016-08-09 08:55:49 -0400318 send_hdlc_hello (cm, n, count);
319 break;
Dave Barachced48e72016-02-08 15:57:35 -0500320
321 case CDP_PACKET_TEMPLATE_SRP:
Dave Barach861bd212016-08-09 08:55:49 -0400322 send_srp_hello (cm, n, count);
323 break;
Dave Barachced48e72016-02-08 15:57:35 -0500324
325 default:
Dave Barach861bd212016-08-09 08:55:49 -0400326 ASSERT (0);
Dave Barachced48e72016-02-08 15:57:35 -0500327 }
Dave Barach861bd212016-08-09 08:55:49 -0400328 n->last_sent = vlib_time_now (cm->vlib_main);
Dave Barachced48e72016-02-08 15:57:35 -0500329}
330
Dave Barach861bd212016-08-09 08:55:49 -0400331static void
332delete_neighbor (cdp_main_t * cm, cdp_neighbor_t * n, int want_broadcast)
Dave Barachced48e72016-02-08 15:57:35 -0500333{
Dave Barach861bd212016-08-09 08:55:49 -0400334 hash_unset (cm->neighbor_by_sw_if_index, n->sw_if_index);
335 vec_free (n->device_name);
336 vec_free (n->version);
337 vec_free (n->port_id);
338 vec_free (n->platform);
339 vec_free (n->last_rx_pkt);
340 pool_put (cm->neighbors, n);
Dave Barachced48e72016-02-08 15:57:35 -0500341}
342
Dave Barach861bd212016-08-09 08:55:49 -0400343void
344cdp_periodic (vlib_main_t * vm)
Dave Barachced48e72016-02-08 15:57:35 -0500345{
Dave Barach861bd212016-08-09 08:55:49 -0400346 cdp_main_t *cm = &cdp_main;
347 cdp_neighbor_t *n;
348 f64 now = vlib_time_now (vm);
349 vnet_sw_interface_t *sw;
350 static u32 *delete_list = 0;
351 int i;
352 static cdp_neighbor_t **n_list = 0;
Dave Barachced48e72016-02-08 15:57:35 -0500353
Dave Barach861bd212016-08-09 08:55:49 -0400354 /* *INDENT-OFF* */
Damjan Marion607de1a2016-08-16 22:53:54 +0200355 pool_foreach (n, cm->neighbors,
Dave Barach861bd212016-08-09 08:55:49 -0400356 ({
357 vec_add1 (n_list, n);
358 }));
359 /* *INDENT-ON* */
Dave Barachced48e72016-02-08 15:57:35 -0500360
Dave Barach861bd212016-08-09 08:55:49 -0400361 /* Across all cdp neighbors known to the system */
362 for (i = 0; i < vec_len (n_list); i++)
363 {
364 n = n_list[i];
Dave Barachced48e72016-02-08 15:57:35 -0500365
Dave Barach861bd212016-08-09 08:55:49 -0400366 /* "no cdp run" provisioned on the interface? */
367 if (n->disabled == 1)
368 continue;
Dave Barachced48e72016-02-08 15:57:35 -0500369
Dave Barach861bd212016-08-09 08:55:49 -0400370 sw = vnet_get_sw_interface (cm->vnet_main, n->sw_if_index);
Dave Barachced48e72016-02-08 15:57:35 -0500371
Dave Barach861bd212016-08-09 08:55:49 -0400372 /* Interface shutdown or rx timeout? */
373 if (!(sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
374 || (now > (n->last_heard + (f64) n->ttl_in_seconds)))
375 /* add to list of neighbors to delete */
376 vec_add1 (delete_list, n - cm->neighbors);
377 else if (n->last_sent == 0.0)
378 /* First time, send 3 hellos */
379 send_hello (cm, n, 3 /* three to begin with */ );
380 else if (now > (n->last_sent + (((f64) n->ttl_in_seconds) / 6.0)))
381 /* Normal keepalive, send one */
382 send_hello (cm, n, 1 /* one as a keepalive */ );
Dave Barachced48e72016-02-08 15:57:35 -0500383 }
Dave Barach861bd212016-08-09 08:55:49 -0400384
385 for (i = 0; i < vec_len (delete_list); i++)
386 {
387 n = vec_elt_at_index (cm->neighbors, delete_list[i]);
388 delete_neighbor (cm, n, 1);
Dave Barachced48e72016-02-08 15:57:35 -0500389 }
Dave Barach861bd212016-08-09 08:55:49 -0400390 if (delete_list)
391 _vec_len (delete_list) = 0;
392 if (n_list)
393 _vec_len (n_list) = 0;
Dave Barachced48e72016-02-08 15:57:35 -0500394}
395
Dave Barach861bd212016-08-09 08:55:49 -0400396static clib_error_t *
397cdp_periodic_init (vlib_main_t * vm)
Dave Barachced48e72016-02-08 15:57:35 -0500398{
Dave Barach861bd212016-08-09 08:55:49 -0400399 cdp_main_t *cm = &cdp_main;
Dave Barachced48e72016-02-08 15:57:35 -0500400
Dave Barach861bd212016-08-09 08:55:49 -0400401 /* Create the ethernet cdp hello packet template */
402 {
403 ethernet_llc_snap_and_cdp_header_t h;
Dave Barachced48e72016-02-08 15:57:35 -0500404
Dave Barach861bd212016-08-09 08:55:49 -0400405 memset (&h, 0, sizeof (h));
Dave Barachced48e72016-02-08 15:57:35 -0500406
Dave Barach861bd212016-08-09 08:55:49 -0400407 /* Send to 01:00:0c:cc:cc */
408 h.ethernet.dst_address[0] = 0x01;
409 /* h.ethernet.dst_address[1] = 0x00; (memset) */
410 h.ethernet.dst_address[2] = 0x0C;
411 h.ethernet.dst_address[3] = 0xCC;
412 h.ethernet.dst_address[4] = 0xCC;
413 h.ethernet.dst_address[5] = 0xCC;
Dave Barachced48e72016-02-08 15:57:35 -0500414
Dave Barach861bd212016-08-09 08:55:49 -0400415 /* leave src address blank (fill in at send time) */
Dave Barachced48e72016-02-08 15:57:35 -0500416
Dave Barach861bd212016-08-09 08:55:49 -0400417 /* leave length blank (fill in at send time) */
Dave Barachced48e72016-02-08 15:57:35 -0500418
Dave Barach861bd212016-08-09 08:55:49 -0400419 /* LLC */
420 h.llc.dst_sap = h.llc.src_sap = 0xAA; /* SNAP */
421 h.llc.control = 0x03; /* UI (no extended control bytes) */
Dave Barachced48e72016-02-08 15:57:35 -0500422
Dave Barach861bd212016-08-09 08:55:49 -0400423 /* SNAP */
424 /* h.snap.oui[0] = 0x00; (memset) */
425 /* h.snap.oui[1] = 0x00; (memset) */
426 h.snap.oui[2] = 0x0C; /* Cisco = 0x00000C */
427 h.snap.protocol = htons (0x2000); /* CDP = 0x2000 */
Dave Barachced48e72016-02-08 15:57:35 -0500428
Dave Barach861bd212016-08-09 08:55:49 -0400429 /* CDP */
430 h.cdp.version = 2;
431 h.cdp.ttl = 180;
Dave Barachced48e72016-02-08 15:57:35 -0500432
Dave Barach861bd212016-08-09 08:55:49 -0400433 vlib_packet_template_init
434 (vm, &cm->packet_templates[CDP_PACKET_TEMPLATE_ETHERNET],
435 /* data */ &h,
436 sizeof (h),
437 /* alloc chunk size */ 8,
438 "cdp-ethernet");
439 }
Dave Barachced48e72016-02-08 15:57:35 -0500440
Dave Barach861bd212016-08-09 08:55:49 -0400441#if 0 /* retain for reference */
Dave Barachced48e72016-02-08 15:57:35 -0500442
Dave Barach861bd212016-08-09 08:55:49 -0400443 /* Create the hdlc cdp hello packet template */
444 {
445 hdlc_and_cdp_header_t h;
Dave Barachced48e72016-02-08 15:57:35 -0500446
Dave Barach861bd212016-08-09 08:55:49 -0400447 memset (&h, 0, sizeof (h));
Dave Barachced48e72016-02-08 15:57:35 -0500448
Dave Barach861bd212016-08-09 08:55:49 -0400449 h.hdlc.address = 0x0f;
450 /* h.hdlc.control = 0; (memset) */
451 h.hdlc.protocol = htons (0x2000); /* CDP = 0x2000 */
452
453 /* CDP */
454 h.cdp.version = 2;
455 h.cdp.ttl = 180;
456
457 vlib_packet_template_init
458 (vm, &cm->packet_templates[CDP_PACKET_TEMPLATE_HDLC],
459 /* data */ &h,
460 sizeof (h),
461 /* alloc chunk size */ 8,
462 "cdp-hdlc");
463 }
464
465 /* Create the srp cdp hello packet template */
466 {
467 srp_and_cdp_header_t h;
468
469 memset (&h, 0, sizeof (h));
470
471 /* Send to 01:00:0c:cc:cc */
472 h.ethernet.dst_address[0] = 0x01;
473 /* h.ethernet.dst_address[1] = 0x00; (memset) */
474 h.ethernet.dst_address[2] = 0x0C;
475 h.ethernet.dst_address[3] = 0xCC;
476 h.ethernet.dst_address[4] = 0xCC;
477 h.ethernet.dst_address[5] = 0xCC;
478
479 /* leave src address blank (fill in at send time) */
480
481 /* The srp header is filled in at xmt */
482 h.srp.ttl = 1;
483 h.srp.priority = 7;
484 h.srp.mode = SRP_MODE_data;
485 srp_header_compute_parity (&h.srp);
486
487 /* Inner ring and parity will be set at send time */
488
489 h.ethernet.type = htons (0x2000); /* CDP = 0x2000 */
490
491 /* CDP */
492 h.cdp.version = 2;
493 h.cdp.ttl = 180;
494
495 vlib_packet_template_init
496 (vm, &cm->packet_templates[CDP_PACKET_TEMPLATE_SRP],
497 /* data */ &h,
498 sizeof (h),
499 /* alloc chunk size */ 8,
500 "cdp-srp");
501 }
Dave Barachced48e72016-02-08 15:57:35 -0500502#endif
503
Dave Barach861bd212016-08-09 08:55:49 -0400504 return 0;
Dave Barachced48e72016-02-08 15:57:35 -0500505}
506
507VLIB_INIT_FUNCTION (cdp_periodic_init);
Dave Barach861bd212016-08-09 08:55:49 -0400508
509/*
510 * fd.io coding-style-patch-verification: ON
511 *
512 * Local Variables:
513 * eval: (c-set-style "gnu")
514 * End:
515 */