VPP-1576: fix a set of coverity warnings
[vpp.git] / src / vnet / gre / gre.c
1 /*
2  * gre.c: gre
3  *
4  * Copyright (c) 2012 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/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/adj/adj_midchain.h>
21
22 #ifndef CLIB_MARCH_VARIANT
23 gre_main_t gre_main;
24
25 typedef struct
26 {
27   union
28   {
29     ip4_and_gre_header_t ip4_and_gre;
30     u64 as_u64[3];
31   };
32 } ip4_and_gre_union_t;
33
34 typedef struct
35 {
36   union
37   {
38     ip6_and_gre_header_t ip6_and_gre;
39     u64 as_u64[3];
40   };
41 } ip6_and_gre_union_t;
42 #endif /* CLIB_MARCH_VARIANT */
43
44
45 /* Packet trace structure */
46 typedef struct
47 {
48   /* Tunnel-id / index in tunnel vector */
49   u32 tunnel_id;
50
51   /* pkt length */
52   u32 length;
53
54   /* tunnel ip addresses */
55   ip46_address_t src;
56   ip46_address_t dst;
57 } gre_tx_trace_t;
58
59 static u8 *
60 format_gre_tx_trace (u8 * s, va_list * args)
61 {
62   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
63   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
64   gre_tx_trace_t *t = va_arg (*args, gre_tx_trace_t *);
65
66   s = format (s, "GRE: tunnel %d len %d src %U dst %U",
67               t->tunnel_id, t->length,
68               format_ip46_address, &t->src, IP46_TYPE_ANY,
69               format_ip46_address, &t->dst, IP46_TYPE_ANY);
70   return s;
71 }
72
73 #ifndef CLIB_MARCH_VARIANT
74 u8 *
75 format_gre_protocol (u8 * s, va_list * args)
76 {
77   gre_protocol_t p = va_arg (*args, u32);
78   gre_main_t *gm = &gre_main;
79   gre_protocol_info_t *pi = gre_get_protocol_info (gm, p);
80
81   if (pi)
82     s = format (s, "%s", pi->name);
83   else
84     s = format (s, "0x%04x", p);
85
86   return s;
87 }
88
89 u8 *
90 format_gre_header_with_length (u8 * s, va_list * args)
91 {
92   gre_main_t *gm = &gre_main;
93   gre_header_t *h = va_arg (*args, gre_header_t *);
94   u32 max_header_bytes = va_arg (*args, u32);
95   gre_protocol_t p = clib_net_to_host_u16 (h->protocol);
96   u32 indent, header_bytes;
97
98   header_bytes = sizeof (h[0]);
99   if (max_header_bytes != 0 && header_bytes > max_header_bytes)
100     return format (s, "gre header truncated");
101
102   indent = format_get_indent (s);
103
104   s = format (s, "GRE %U", format_gre_protocol, p);
105
106   if (max_header_bytes != 0 && header_bytes < max_header_bytes)
107     {
108       gre_protocol_info_t *pi = gre_get_protocol_info (gm, p);
109       vlib_node_t *node = vlib_get_node (gm->vlib_main, pi->node_index);
110       if (node->format_buffer)
111         s = format (s, "\n%U%U",
112                     format_white_space, indent,
113                     node->format_buffer, (void *) (h + 1),
114                     max_header_bytes - header_bytes);
115     }
116
117   return s;
118 }
119
120 u8 *
121 format_gre_header (u8 * s, va_list * args)
122 {
123   gre_header_t *h = va_arg (*args, gre_header_t *);
124   return format (s, "%U", format_gre_header_with_length, h, 0);
125 }
126
127 /* Returns gre protocol as an int in host byte order. */
128 uword
129 unformat_gre_protocol_host_byte_order (unformat_input_t * input,
130                                        va_list * args)
131 {
132   u16 *result = va_arg (*args, u16 *);
133   gre_main_t *gm = &gre_main;
134   int i;
135
136   /* Named type. */
137   if (unformat_user (input, unformat_vlib_number_by_name,
138                      gm->protocol_info_by_name, &i))
139     {
140       gre_protocol_info_t *pi = vec_elt_at_index (gm->protocol_infos, i);
141       *result = pi->protocol;
142       return 1;
143     }
144
145   return 0;
146 }
147
148 uword
149 unformat_gre_protocol_net_byte_order (unformat_input_t * input,
150                                       va_list * args)
151 {
152   u16 *result = va_arg (*args, u16 *);
153   if (!unformat_user (input, unformat_gre_protocol_host_byte_order, result))
154     return 0;
155   *result = clib_host_to_net_u16 ((u16) * result);
156   return 1;
157 }
158
159 uword
160 unformat_gre_header (unformat_input_t * input, va_list * args)
161 {
162   u8 **result = va_arg (*args, u8 **);
163   gre_header_t _h, *h = &_h;
164   u16 p;
165
166   if (!unformat (input, "%U", unformat_gre_protocol_host_byte_order, &p))
167     return 0;
168
169   h->protocol = clib_host_to_net_u16 (p);
170
171   /* Add header to result. */
172   {
173     void *p;
174     u32 n_bytes = sizeof (h[0]);
175
176     vec_add2 (*result, p, n_bytes);
177     clib_memcpy (p, h, n_bytes);
178   }
179
180   return 1;
181 }
182
183 static int
184 gre_proto_from_vnet_link (vnet_link_t link)
185 {
186   switch (link)
187     {
188     case VNET_LINK_IP4:
189       return (GRE_PROTOCOL_ip4);
190     case VNET_LINK_IP6:
191       return (GRE_PROTOCOL_ip6);
192     case VNET_LINK_MPLS:
193       return (GRE_PROTOCOL_mpls_unicast);
194     case VNET_LINK_ETHERNET:
195       return (GRE_PROTOCOL_teb);
196     case VNET_LINK_ARP:
197       return (GRE_PROTOCOL_arp);
198     case VNET_LINK_NSH:
199       ASSERT (0);
200       break;
201     }
202   ASSERT (0);
203   return (GRE_PROTOCOL_ip4);
204 }
205
206 static u8 *
207 gre_build_rewrite (vnet_main_t * vnm,
208                    u32 sw_if_index,
209                    vnet_link_t link_type, const void *dst_address)
210 {
211   gre_main_t *gm = &gre_main;
212   ip4_and_gre_header_t *h4;
213   ip6_and_gre_header_t *h6;
214   gre_header_t *gre;
215   u8 *rewrite = NULL;
216   gre_tunnel_t *t;
217   u32 ti;
218   u8 is_ipv6;
219
220   ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
221
222   if (~0 == ti)
223     /* not one of ours */
224     return (0);
225
226   t = pool_elt_at_index (gm->tunnels, ti);
227
228   is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
229
230   if (!is_ipv6)
231     {
232       vec_validate (rewrite, sizeof (*h4) - 1);
233       h4 = (ip4_and_gre_header_t *) rewrite;
234       gre = &h4->gre;
235       h4->ip4.ip_version_and_header_length = 0x45;
236       h4->ip4.ttl = 254;
237       h4->ip4.protocol = IP_PROTOCOL_GRE;
238       /* fixup ip4 header length and checksum after-the-fact */
239       h4->ip4.src_address.as_u32 = t->tunnel_src.ip4.as_u32;
240       h4->ip4.dst_address.as_u32 = t->tunnel_dst.fp_addr.ip4.as_u32;
241       h4->ip4.checksum = ip4_header_checksum (&h4->ip4);
242     }
243   else
244     {
245       vec_validate (rewrite, sizeof (*h6) - 1);
246       h6 = (ip6_and_gre_header_t *) rewrite;
247       gre = &h6->gre;
248       h6->ip6.ip_version_traffic_class_and_flow_label =
249         clib_host_to_net_u32 (6 << 28);
250       h6->ip6.hop_limit = 255;
251       h6->ip6.protocol = IP_PROTOCOL_GRE;
252       /* fixup ip6 header length and checksum after-the-fact */
253       h6->ip6.src_address.as_u64[0] = t->tunnel_src.ip6.as_u64[0];
254       h6->ip6.src_address.as_u64[1] = t->tunnel_src.ip6.as_u64[1];
255       h6->ip6.dst_address.as_u64[0] = t->tunnel_dst.fp_addr.ip6.as_u64[0];
256       h6->ip6.dst_address.as_u64[1] = t->tunnel_dst.fp_addr.ip6.as_u64[1];
257     }
258
259   if (PREDICT_FALSE (t->type == GRE_TUNNEL_TYPE_ERSPAN))
260     {
261       gre->protocol = clib_host_to_net_u16 (GRE_PROTOCOL_erspan);
262       gre->flags_and_version = clib_host_to_net_u16 (GRE_FLAGS_SEQUENCE);
263     }
264   else
265     gre->protocol =
266       clib_host_to_net_u16 (gre_proto_from_vnet_link (link_type));
267
268   return (rewrite);
269 }
270
271 #define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
272
273 static void
274 gre4_fixup (vlib_main_t * vm,
275             ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
276 {
277   ip4_header_t *ip0;
278
279   ip0 = vlib_buffer_get_current (b0);
280
281   /* Fixup the checksum and len fields in the GRE tunnel encap
282    * that was applied at the midchain node */
283   ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
284   ip0->checksum = ip4_header_checksum (ip0);
285 }
286
287 static void
288 gre6_fixup (vlib_main_t * vm,
289             ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
290 {
291   ip6_header_t *ip0;
292
293   ip0 = vlib_buffer_get_current (b0);
294
295   /* Fixup the payload length field in the GRE tunnel encap that was applied
296    * at the midchain node */
297   ip0->payload_length =
298     clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
299                           sizeof (*ip0));
300 }
301
302 void
303 gre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
304 {
305   gre_main_t *gm = &gre_main;
306   gre_tunnel_t *t;
307   adj_flags_t af;
308   u8 is_ipv6;
309   u32 ti;
310
311   ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
312   t = pool_elt_at_index (gm->tunnels, ti);
313   is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
314   af = ADJ_FLAG_MIDCHAIN_IP_STACK;
315
316   if (VNET_LINK_ETHERNET == adj_get_link_type (ai))
317     af |= ADJ_FLAG_MIDCHAIN_NO_COUNT;
318
319   adj_nbr_midchain_update_rewrite
320     (ai, !is_ipv6 ? gre4_fixup : gre6_fixup, NULL, af,
321      gre_build_rewrite (vnm, sw_if_index, adj_get_link_type (ai), NULL));
322
323   gre_tunnel_stack (ai);
324 }
325 #endif /* CLIB_MARCH_VARIANT */
326
327
328 typedef enum
329 {
330   GRE_ENCAP_NEXT_L2_MIDCHAIN,
331   GRE_ENCAP_N_NEXT,
332 } gre_encap_next_t;
333
334 /**
335  * @brief TX function. Only called for L2 payload including TEB or ERSPAN.
336  *        L3 traffic uses the adj-midchains.
337  */
338 VLIB_NODE_FN (gre_encap_node) (vlib_main_t * vm,
339                                vlib_node_runtime_t * node,
340                                vlib_frame_t * frame)
341 {
342   gre_main_t *gm = &gre_main;
343   vnet_main_t *vnm = gm->vnet_main;
344   u32 next_index;
345   u32 *from, *to_next, n_left_from, n_left_to_next;
346   u32 sw_if_index0 = ~0;
347   u32 sw_if_index1 = ~0;
348   adj_index_t adj_index0 = ADJ_INDEX_INVALID;
349   adj_index_t adj_index1 = ADJ_INDEX_INVALID;
350   gre_tunnel_t *gt0 = NULL;
351   gre_tunnel_t *gt1 = NULL;
352
353   /* Vector of buffer / pkt indices we're supposed to process */
354   from = vlib_frame_vector_args (frame);
355
356   /* Number of buffers / pkts */
357   n_left_from = frame->n_vectors;
358
359   /* Speculatively send the first buffer to the last disposition we used */
360   next_index = GRE_ENCAP_NEXT_L2_MIDCHAIN;
361
362   while (n_left_from > 0)
363     {
364       /* set up to enqueue to our disposition with index = next_index */
365       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
366
367       while (n_left_from >= 4 && n_left_to_next >= 2)
368         {
369           u32 bi0 = from[0];
370           u32 bi1 = from[1];
371           vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
372           vlib_buffer_t *b1 = vlib_get_buffer (vm, bi1);
373
374           to_next[0] = bi0;
375           to_next[1] = bi1;
376           from += 2;
377           to_next += 2;
378           n_left_to_next -= 2;
379           n_left_from -= 2;
380
381           if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX])
382             {
383               sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
384               vnet_hw_interface_t *hi0 =
385                 vnet_get_sup_hw_interface (vnm, sw_if_index0);
386               gt0 = &gm->tunnels[hi0->dev_instance];
387               adj_index0 = gt0->l2_adj_index;
388             }
389
390           if (sw_if_index1 != vnet_buffer (b1)->sw_if_index[VLIB_TX])
391             {
392               if (sw_if_index0 == vnet_buffer (b1)->sw_if_index[VLIB_TX])
393                 {
394                   sw_if_index1 = sw_if_index0;
395                   gt1 = gt0;
396                   adj_index1 = adj_index0;
397                 }
398               else
399                 {
400                   sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
401                   vnet_hw_interface_t *hi1 =
402                     vnet_get_sup_hw_interface (vnm, sw_if_index1);
403                   gt1 = &gm->tunnels[hi1->dev_instance];
404                   adj_index1 = gt1->l2_adj_index;
405                 }
406             }
407
408           vnet_buffer (b0)->ip.adj_index[VLIB_TX] = adj_index0;
409           vnet_buffer (b1)->ip.adj_index[VLIB_TX] = adj_index1;
410
411           if (PREDICT_FALSE (gt0->type == GRE_TUNNEL_TYPE_ERSPAN))
412             {
413               /* Encap GRE seq# and ERSPAN type II header */
414               vlib_buffer_advance (b0, -sizeof (erspan_t2_t));
415               erspan_t2_t *h0 = vlib_buffer_get_current (b0);
416               u32 seq_num = clib_atomic_fetch_add (&gt0->gre_sn->seq_num, 1);
417               u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
418               h0->seq_num = clib_host_to_net_u32 (seq_num);
419               h0->t2_u64 = hdr;
420               h0->t2.cos_en_t_session |=
421                 clib_host_to_net_u16 (gt0->session_id);
422             }
423           if (PREDICT_FALSE (gt1->type == GRE_TUNNEL_TYPE_ERSPAN))
424             {
425               /* Encap GRE seq# and ERSPAN type II header */
426               vlib_buffer_advance (b1, -sizeof (erspan_t2_t));
427               erspan_t2_t *h1 = vlib_buffer_get_current (b1);
428               u32 seq_num = clib_atomic_fetch_add (&gt1->gre_sn->seq_num, 1);
429               u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
430               h1->seq_num = clib_host_to_net_u32 (seq_num);
431               h1->t2_u64 = hdr;
432               h1->t2.cos_en_t_session |=
433                 clib_host_to_net_u16 (gt1->session_id);
434             }
435
436           if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
437             {
438               gre_tx_trace_t *tr0 = vlib_add_trace (vm, node,
439                                                     b0, sizeof (*tr0));
440               tr0->tunnel_id = gt0 - gm->tunnels;
441               tr0->src = gt0->tunnel_src;
442               tr0->dst = gt0->tunnel_dst.fp_addr;
443               tr0->length = vlib_buffer_length_in_chain (vm, b0);
444             }
445           if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
446             {
447               gre_tx_trace_t *tr1 = vlib_add_trace (vm, node,
448                                                     b1, sizeof (*tr1));
449               tr1->tunnel_id = gt1 - gm->tunnels;
450               tr1->src = gt1->tunnel_src;
451               tr1->dst = gt1->tunnel_dst.fp_addr;
452               tr1->length = vlib_buffer_length_in_chain (vm, b1);
453             }
454         }
455
456       while (n_left_from > 0 && n_left_to_next > 0)
457         {
458           u32 bi0 = from[0];
459           vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
460
461           to_next[0] = bi0;
462           from += 1;
463           to_next += 1;
464           n_left_from -= 1;
465           n_left_to_next -= 1;
466
467           if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX])
468             {
469               sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
470               vnet_hw_interface_t *hi0 =
471                 vnet_get_sup_hw_interface (vnm, sw_if_index0);
472               gt0 = &gm->tunnels[hi0->dev_instance];
473               adj_index0 = gt0->l2_adj_index;
474             }
475
476           vnet_buffer (b0)->ip.adj_index[VLIB_TX] = adj_index0;
477
478           if (PREDICT_FALSE (gt0->type == GRE_TUNNEL_TYPE_ERSPAN))
479             {
480               /* Encap GRE seq# and ERSPAN type II header */
481               vlib_buffer_advance (b0, -sizeof (erspan_t2_t));
482               erspan_t2_t *h0 = vlib_buffer_get_current (b0);
483               u32 seq_num = clib_atomic_fetch_add (&gt0->gre_sn->seq_num, 1);
484               u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
485               h0->seq_num = clib_host_to_net_u32 (seq_num);
486               h0->t2_u64 = hdr;
487               h0->t2.cos_en_t_session |=
488                 clib_host_to_net_u16 (gt0->session_id);
489             }
490
491           if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
492             {
493               gre_tx_trace_t *tr = vlib_add_trace (vm, node,
494                                                    b0, sizeof (*tr));
495               tr->tunnel_id = gt0 - gm->tunnels;
496               tr->src = gt0->tunnel_src;
497               tr->dst = gt0->tunnel_dst.fp_addr;
498               tr->length = vlib_buffer_length_in_chain (vm, b0);
499             }
500         }
501
502       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
503     }
504
505   vlib_node_increment_counter (vm, node->node_index,
506                                GRE_ERROR_PKTS_ENCAP, frame->n_vectors);
507
508   return frame->n_vectors;
509 }
510
511 static char *gre_error_strings[] = {
512 #define gre_error(n,s) s,
513 #include "error.def"
514 #undef gre_error
515 };
516
517 /* *INDENT-OFF* */
518 VLIB_REGISTER_NODE (gre_encap_node) =
519 {
520   .name = "gre-encap",
521   .vector_size = sizeof (u32),
522   .format_trace = format_gre_tx_trace,
523   .type = VLIB_NODE_TYPE_INTERNAL,
524   .n_errors = GRE_N_ERROR,
525   .error_strings = gre_error_strings,
526   .n_next_nodes = GRE_ENCAP_N_NEXT,
527   .next_nodes = {
528     [GRE_ENCAP_NEXT_L2_MIDCHAIN] = "adj-l2-midchain",
529   },
530 };
531 /* *INDENT-ON* */
532
533 static u8 *
534 format_gre_tunnel_name (u8 * s, va_list * args)
535 {
536   u32 dev_instance = va_arg (*args, u32);
537   gre_main_t *gm = &gre_main;
538   gre_tunnel_t *t;
539
540   if (dev_instance >= vec_len (gm->tunnels))
541     return format (s, "<improperly-referenced>");
542
543   t = pool_elt_at_index (gm->tunnels, dev_instance);
544   return format (s, "gre%d", t->user_instance);
545 }
546
547 static u8 *
548 format_gre_device (u8 * s, va_list * args)
549 {
550   u32 dev_instance = va_arg (*args, u32);
551   CLIB_UNUSED (int verbose) = va_arg (*args, int);
552
553   s = format (s, "GRE tunnel: id %d\n", dev_instance);
554   return s;
555 }
556
557 /* *INDENT-OFF* */
558 VNET_DEVICE_CLASS (gre_device_class) = {
559   .name = "GRE tunnel device",
560   .format_device_name = format_gre_tunnel_name,
561   .format_device = format_gre_device,
562   .format_tx_trace = format_gre_tx_trace,
563   .admin_up_down_function = gre_interface_admin_up_down,
564 #ifdef SOON
565   .clear counter = 0;
566 #endif
567 };
568
569 #ifndef CLIB_MARCH_VARIANT
570 VNET_HW_INTERFACE_CLASS (gre_hw_interface_class) = {
571   .name = "GRE",
572   .format_header = format_gre_header_with_length,
573   .unformat_header = unformat_gre_header,
574   .build_rewrite = gre_build_rewrite,
575   .update_adjacency = gre_update_adj,
576   .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
577 };
578 /* *INDENT-ON* */
579
580 static void
581 add_protocol (gre_main_t * gm, gre_protocol_t protocol, char *protocol_name)
582 {
583   gre_protocol_info_t *pi;
584   u32 i;
585
586   vec_add2 (gm->protocol_infos, pi, 1);
587   i = pi - gm->protocol_infos;
588
589   pi->name = protocol_name;
590   pi->protocol = protocol;
591   pi->next_index = pi->node_index = ~0;
592
593   hash_set (gm->protocol_info_by_protocol, protocol, i);
594   hash_set_mem (gm->protocol_info_by_name, pi->name, i);
595 }
596
597 static clib_error_t *
598 gre_init (vlib_main_t * vm)
599 {
600   gre_main_t *gm = &gre_main;
601   clib_error_t *error;
602   ip_main_t *im = &ip_main;
603   ip_protocol_info_t *pi;
604
605   clib_memset (gm, 0, sizeof (gm[0]));
606   gm->vlib_main = vm;
607   gm->vnet_main = vnet_get_main ();
608
609   if ((error = vlib_call_init_function (vm, ip_main_init)))
610     return error;
611
612   if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
613     return error;
614
615   if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
616     return error;
617
618   /* Set up the ip packet generator */
619   pi = ip_get_protocol_info (im, IP_PROTOCOL_GRE);
620   pi->format_header = format_gre_header;
621   pi->unformat_pg_edit = unformat_pg_gre_header;
622
623   gm->protocol_info_by_name = hash_create_string (0, sizeof (uword));
624   gm->protocol_info_by_protocol = hash_create (0, sizeof (uword));
625   gm->tunnel_by_key4 =
626     hash_create_mem (0, sizeof (gre_tunnel_key4_t), sizeof (uword));
627   gm->tunnel_by_key6 =
628     hash_create_mem (0, sizeof (gre_tunnel_key6_t), sizeof (uword));
629   gm->seq_num_by_key =
630     hash_create_mem (0, sizeof (gre_sn_key_t), sizeof (uword));
631
632 #define _(n,s) add_protocol (gm, GRE_PROTOCOL_##s, #s);
633   foreach_gre_protocol
634 #undef _
635     return vlib_call_init_function (vm, gre_input_init);
636 }
637
638 VLIB_INIT_FUNCTION (gre_init);
639
640 #endif /* CLIB_MARCH_VARIANT */
641
642 /*
643  * fd.io coding-style-patch-verification: ON
644  *
645  * Local Variables:
646  * eval: (c-set-style "gnu")
647  * End:
648  */