summaryrefslogtreecommitdiffstats
path: root/bgpd/rfapi/rfapi_encap_tlv.c
blob: 171ea8f24dc53dc0f7123261754e8d1b7bc4f4f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/* 
 * Copyright 2015-2016, LabN Consulting, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include "lib/zebra.h"

#include "lib/memory.h"
#include "lib/prefix.h"
#include "lib/table.h"
#include "lib/vty.h"

#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"

#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_encap_tlv.h"

#include "bgpd/rfapi/rfapi.h"
#include "bgpd/rfapi/rfapi_encap_tlv.h"
#include "bgpd/rfapi/rfapi_private.h"
#include "bgpd/rfapi/rfapi_monitor.h"
#include "bgpd/rfapi/rfapi_vty.h"
#include "bgpd/rfapi/bgp_rfapi_cfg.h"
#include "bgpd/rfapi/vnc_debug.h"

static void
rfapi_add_endpoint_address_to_subtlv (
  struct bgp				*bgp,
  struct rfapi_ip_addr			*ea,
  struct bgp_tea_subtlv_remote_endpoint	*subtlv)
{
  subtlv->family = ea->addr_family;
  if (subtlv->family == AF_INET)
    subtlv->ip_address.v4 = ea->addr.v4;
  else
    subtlv->ip_address.v6 = ea->addr.v6;
  subtlv->as4 = htonl (bgp->as);
}

bgp_encap_types
rfapi_tunneltype_option_to_tlv (
  struct bgp				*bgp,
  struct rfapi_ip_addr			*ea,
  struct rfapi_tunneltype_option	*tto,
  struct attr				*attr,
  int					always_add)
{

#define _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(ttype)                               \
    if ((always_add || (bgp->rfapi_cfg &&                                     \
                        !CHECK_FLAG(bgp->rfapi_cfg->flags,                    \
                                    BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP))) &&  \
        ea && !CHECK_SUBTLV_FLAG(&tto->bgpinfo.ttype,                         \
                                 BGP_TEA_SUBTLV_REMOTE_ENDPOINT)) {           \
        rfapi_add_endpoint_address_to_subtlv(bgp, ea,                         \
                                           &tto->bgpinfo.ttype.st_endpoint);  \
        SET_SUBTLV_FLAG(&tto->bgpinfo.ttype, BGP_TEA_SUBTLV_REMOTE_ENDPOINT); \
    }

  struct rfapi_tunneltype_option dto;
  if (tto == NULL)
    {                           /* create default type */
      tto = &dto;
      memset (tto, 0, sizeof (dto));
      tto->type = RFAPI_BGP_ENCAP_TYPE_DEFAULT;
    }
  switch (tto->type)
    {
    case BGP_ENCAP_TYPE_L2TPV3_OVER_IP:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (l2tpv3_ip);
      bgp_encap_type_l2tpv3overip_to_tlv (&tto->bgpinfo.l2tpv3_ip, attr);
      break;

    case BGP_ENCAP_TYPE_GRE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (gre);
      bgp_encap_type_gre_to_tlv (&tto->bgpinfo.gre, attr);
      break;

    case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (transmit_tunnel_endpoint);
      bgp_encap_type_transmit_tunnel_endpoint (&tto->bgpinfo.transmit_tunnel_endpoint,
                                               attr);
      break;

    case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (ipsec_tunnel);
      bgp_encap_type_ipsec_in_tunnel_mode_to_tlv (&tto->bgpinfo.ipsec_tunnel,
                                                  attr);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (ip_ipsec);
      bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv
        (&tto->bgpinfo.ip_ipsec, attr);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (mpls_ipsec);
      bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv
        (&tto->bgpinfo.mpls_ipsec, attr);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (ip_ip);
      bgp_encap_type_ip_in_ip_to_tlv (&tto->bgpinfo.ip_ip, attr);
      break;

    case BGP_ENCAP_TYPE_VXLAN:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (vxlan);
      bgp_encap_type_vxlan_to_tlv (&tto->bgpinfo.vxlan, attr);
      break;

    case BGP_ENCAP_TYPE_NVGRE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (nvgre);
      bgp_encap_type_nvgre_to_tlv (&tto->bgpinfo.nvgre, attr);
      break;

    case BGP_ENCAP_TYPE_MPLS:
      /* nothing to do for MPLS */
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_GRE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (mpls_gre);
      bgp_encap_type_mpls_in_gre_to_tlv (&tto->bgpinfo.mpls_gre, attr);
      break;

    case BGP_ENCAP_TYPE_VXLAN_GPE:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (vxlan_gpe);
      bgp_encap_type_vxlan_gpe_to_tlv (&tto->bgpinfo.vxlan_gpe, attr);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_UDP:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (mpls_udp);
      bgp_encap_type_mpls_in_udp_to_tlv (&tto->bgpinfo.mpls_udp, attr);
      break;

    case BGP_ENCAP_TYPE_PBB:
      _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS (pbb);
      bgp_encap_type_pbb_to_tlv (&tto->bgpinfo.pbb, attr);
      break;

    default:
      assert (0);
    }
  return tto->type;
}

struct rfapi_un_option *
rfapi_encap_tlv_to_un_option (struct attr *attr)
{
  struct attr_extra *attre = attr->extra;
  struct rfapi_un_option *uo = NULL;
  struct rfapi_tunneltype_option *tto;
  int rc;
  struct bgp_attr_encap_subtlv *stlv;

  if (!attre)
    return NULL;

  /* no tunnel encap attr stored */
  if (!attre->encap_tunneltype)
    return NULL;

  stlv = attre->encap_subtlvs;

  uo = XCALLOC (MTYPE_RFAPI_UN_OPTION, sizeof (struct rfapi_un_option));
  assert (uo);
  uo->type = RFAPI_UN_OPTION_TYPE_TUNNELTYPE;
  uo->v.tunnel.type = attre->encap_tunneltype;
  tto = &uo->v.tunnel;

  switch (attre->encap_tunneltype)
    {
    case BGP_ENCAP_TYPE_L2TPV3_OVER_IP:
      rc = tlv_to_bgp_encap_type_l2tpv3overip (stlv, &tto->bgpinfo.l2tpv3_ip);
      break;

    case BGP_ENCAP_TYPE_GRE:
      rc = tlv_to_bgp_encap_type_gre (stlv, &tto->bgpinfo.gre);
      break;

    case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT:
      rc = tlv_to_bgp_encap_type_transmit_tunnel_endpoint (stlv,
                                                           &tto->bgpinfo.transmit_tunnel_endpoint);
      break;

    case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE:
      rc = tlv_to_bgp_encap_type_ipsec_in_tunnel_mode (stlv,
                                                       &tto->bgpinfo.ipsec_tunnel);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      rc =
        tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode (stlv,
                                                                         &tto->bgpinfo.ip_ipsec);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      rc =
        tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
        (stlv, &tto->bgpinfo.mpls_ipsec);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP:
      rc = tlv_to_bgp_encap_type_ip_in_ip (stlv, &tto->bgpinfo.ip_ip);
      break;

    case BGP_ENCAP_TYPE_VXLAN:
      rc = tlv_to_bgp_encap_type_vxlan (stlv, &tto->bgpinfo.vxlan);
      break;

    case BGP_ENCAP_TYPE_NVGRE:
      rc = tlv_to_bgp_encap_type_nvgre (stlv, &tto->bgpinfo.nvgre);
      break;

    case BGP_ENCAP_TYPE_MPLS:
      rc = tlv_to_bgp_encap_type_mpls (stlv, &tto->bgpinfo.mpls);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_GRE:
      rc = tlv_to_bgp_encap_type_mpls_in_gre (stlv, &tto->bgpinfo.mpls_gre);
      break;

    case BGP_ENCAP_TYPE_VXLAN_GPE:
      rc = tlv_to_bgp_encap_type_vxlan_gpe (stlv, &tto->bgpinfo.vxlan_gpe);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_UDP:
      rc = tlv_to_bgp_encap_type_mpls_in_udp (stlv, &tto->bgpinfo.mpls_udp);
      break;

    case BGP_ENCAP_TYPE_PBB:
      rc = tlv_to_bgp_encap_type_pbb (stlv, &tto->bgpinfo.pbb);
      break;

    default:
      vnc_zlog_debug_verbose ("%s: unknown tunnel type %d",
                  __func__, attre->encap_tunneltype);
      rc = -1;
      break;
    }
  if (rc)
    {
      XFREE (MTYPE_RFAPI_UN_OPTION, uo);
      uo = NULL;
    }
  return uo;
}

/***********************************************************************
 *			SUBTLV PRINT
 ***********************************************************************/

static void
subtlv_print_encap_l2tpv3_over_ip (
  void						*stream,
  int						column_offset,
  struct bgp_tea_subtlv_encap_l2tpv3_over_ip	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: Encap(L2TPv3 over IP)",
      vty_newline);
  fp (out, "%*s  SessionID: %d%s", column_offset, "", st->sessionid,
      vty_newline);
  fp (out, "%*s  Cookie: (length %d)%s", column_offset, "", st->cookie_length,
      vty_newline);
}

static void
subtlv_print_encap_gre (
  void					*stream,
  int					column_offset,
  struct bgp_tea_subtlv_encap_gre_key	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: Encap(GRE)", vty_newline);
  fp (out, "%*s  GRE key: %d (0x%x)%s", column_offset, "", st->gre_key,
      st->gre_key, vty_newline);
}

static void
subtlv_print_encap_pbb (
  void					*stream,
  int					column_offset,
  struct bgp_tea_subtlv_encap_pbb	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: Encap(PBB)", vty_newline);
  if (st->flag_isid)
    {
      fp (out, "%*s  ISID: %d (0x%x)%s", column_offset, "", st->isid,
          st->isid, vty_newline);
    }
  if (st->flag_vid)
    {
      fp (out, "%*s  VID: %d (0x%x)%s", column_offset, "", st->vid, st->vid,
          vty_newline);
    }
  fp (out, "%*s  MACADDR %02x:%02x:%02x:%02x:%02x:%02x%s",
      column_offset, "",
      st->macaddr[0],
      st->macaddr[1],
      st->macaddr[2],
      st->macaddr[3], st->macaddr[4], st->macaddr[5], vty_newline);
}

static void
subtlv_print_proto_type (
  void					*stream,
  int					column_offset,
  struct bgp_tea_subtlv_proto_type	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: Encap(Proto Type)",
      vty_newline);
  fp (out, "%*s  Proto %d (0x%x)%s", column_offset, "", st->proto, st->proto,
      vty_newline);
}

static void
subtlv_print_color (
  void				*stream,
  int				column_offset,
  struct bgp_tea_subtlv_color	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: Color", vty_newline);
  fp (out, "%*s  Color: %d (0x%x)", column_offset, "", st->color, st->color,
      vty_newline);
}

static void
subtlv_print_ipsec_ta (
  void					*stream,
  int					column_offset,
  struct bgp_tea_subtlv_ipsec_ta	*st)
{
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!st)
    return;

  fp (out, "%*s%s%s", column_offset, "", "SubTLV: IPSEC TA", vty_newline);
  fp (out, "%*s  Authenticator Type: %d (0x%x)", column_offset, "",
      st->authenticator_type, st->authenticator_type, vty_newline);
  fp (out, "%*s  Authenticator: (length %d)", column_offset, "",
      st->authenticator_length, vty_newline);
}

/***********************************************************************
 *			TLV PRINT
 ***********************************************************************/

static void
print_encap_type_l2tpv3overip (
  void					*stream,
  int					column_offset,
  struct bgp_encap_type_l2tpv3_over_ip	*bet)
{
  const char *type = "L2TPv3 over IP";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_encap_l2tpv3_over_ip (stream, column_offset + 2,
                                     &bet->st_encap);
  subtlv_print_proto_type (stream, column_offset + 2, &bet->st_proto);
  subtlv_print_color (stream, column_offset + 2, &bet->st_color);
}

static void
print_encap_type_gre (
  void				*stream,
  int				column_offset,
  struct bgp_encap_type_gre	*bet)
{
  const char *type = "GRE";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_encap_gre (stream, column_offset + 2, &bet->st_encap);
  subtlv_print_proto_type (stream, column_offset + 2, &bet->st_proto);
  subtlv_print_color (stream, column_offset + 2, &bet->st_color);
}

static void
print_encap_type_ip_in_ip (
  void					*stream,
  int					column_offset,
  struct bgp_encap_type_ip_in_ip	*bet)
{
  const char *type = "IP in IP";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_proto_type (stream, column_offset + 2, &bet->st_proto);
  subtlv_print_color (stream, column_offset + 2, &bet->st_color);
}

static void
print_encap_type_transmit_tunnel_endpoint (
  void							*stream,
  int							column_offset,
  struct bgp_encap_type_transmit_tunnel_endpoint	*bet)
{
  const char *type = "Transmit Tunnel Endpoint";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

static void
print_encap_type_ipsec_in_tunnel_mode (
  void						*stream,
  int						column_offset,
  struct bgp_encap_type_ipsec_in_tunnel_mode	*bet)
{
  const char *type = "IPSEC in Tunnel mode";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);
  subtlv_print_ipsec_ta (stream, column_offset + 2, &bet->st_ipsec_ta);
}

static void
print_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode (
  void	*stream,
  int	column_offset,
  struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode	*bet)
{
  const char *type = "IP in IP Tunnel with IPSEC transport mode";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_ipsec_ta (stream, column_offset + 2, &bet->st_ipsec_ta);
}

static void
print_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode (
  void	*stream,
  int	column_offset,
  struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode	*bet)
{
  const char *type = "MPLS in IP Tunnel with IPSEC transport mode";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_ipsec_ta (stream, column_offset + 2, &bet->st_ipsec_ta);
}


static void
print_encap_type_pbb (
  void				*stream,
  int				column_offset,
  struct bgp_encap_type_pbb	*bet)
{
  const char *type = "PBB";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  subtlv_print_encap_pbb (stream, column_offset + 2, &bet->st_encap);
}


static void
print_encap_type_vxlan (
  void				*stream,
  int				column_offset,
  struct bgp_encap_type_vxlan	*bet)
{
  const char *type = "VXLAN";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}


static void
print_encap_type_nvgre (
  void				*stream,
  int				column_offset,
  struct bgp_encap_type_nvgre	*bet)
{
  const char *type = "NVGRE";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

static void
print_encap_type_mpls (
  void				*stream,
  int				column_offset,
  struct bgp_encap_type_mpls	*bet)
{
  const char *type = "MPLS";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

static void
print_encap_type_mpls_in_gre (
  void					*stream,
  int					column_offset,
  struct bgp_encap_type_mpls_in_gre	*bet)
{
  const char *type = "MPLS in GRE";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

static void
print_encap_type_vxlan_gpe (
  void					*stream,
  int					column_offset,
  struct bgp_encap_type_vxlan_gpe	*bet)
{
  const char *type = "VXLAN GPE";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

static void
print_encap_type_mpls_in_udp (
  void					*stream,
  int					column_offset,
  struct bgp_encap_type_mpls_in_udp	*bet)
{
  const char *type = "MPLS in UDP";
  int (*fp) (void *, const char *, ...);
  struct vty *vty;
  void *out;
  const char *vty_newline;

  if (rfapiStream2Vty (stream, &fp, &vty, &out, &vty_newline) == 0)
    return;
  if (!bet)
    return;

  fp (out, "%*sTEA type %s%s", column_offset, "", type, vty_newline);

  /* no subtlvs for this type */
}

void
rfapi_print_tunneltype_option (
  void					*stream,
  int					column_offset,
  struct rfapi_tunneltype_option	*tto)
{
  switch (tto->type)
    {
    case BGP_ENCAP_TYPE_L2TPV3_OVER_IP:
      print_encap_type_l2tpv3overip (stream, column_offset,
                                     &tto->bgpinfo.l2tpv3_ip);
      break;

    case BGP_ENCAP_TYPE_GRE:
      print_encap_type_gre (stream, column_offset, &tto->bgpinfo.gre);
      break;

    case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT:
      print_encap_type_transmit_tunnel_endpoint (stream, column_offset,
                                                 &tto->bgpinfo.transmit_tunnel_endpoint);
      break;

    case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE:
      print_encap_type_ipsec_in_tunnel_mode (stream, column_offset,
                                             &tto->bgpinfo.ipsec_tunnel);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      print_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode (stream,
                                                                  column_offset,
                                                                  &tto->bgpinfo.ip_ipsec);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE:
      print_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode (stream,
                                                                    column_offset,
                                                                    &tto->bgpinfo.mpls_ipsec);
      break;

    case BGP_ENCAP_TYPE_IP_IN_IP:
      print_encap_type_ip_in_ip (stream, column_offset, &tto->bgpinfo.ip_ip);
      break;

    case BGP_ENCAP_TYPE_VXLAN:
      print_encap_type_vxlan (stream, column_offset, &tto->bgpinfo.vxlan);
      break;

    case BGP_ENCAP_TYPE_NVGRE:
      print_encap_type_nvgre (stream, column_offset, &tto->bgpinfo.nvgre);
      break;

    case BGP_ENCAP_TYPE_MPLS:
      print_encap_type_mpls (stream, column_offset, &tto->bgpinfo.mpls);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_GRE:
      print_encap_type_mpls_in_gre (stream, column_offset,
                                    &tto->bgpinfo.mpls_gre);
      break;

    case BGP_ENCAP_TYPE_VXLAN_GPE:
      print_encap_type_vxlan_gpe (stream, column_offset,
                                  &tto->bgpinfo.vxlan_gpe);
      break;

    case BGP_ENCAP_TYPE_MPLS_IN_UDP:
      print_encap_type_mpls_in_udp (stream, column_offset,
                                    &tto->bgpinfo.mpls_udp);
      break;

    case BGP_ENCAP_TYPE_PBB:
      print_encap_type_pbb (stream, column_offset, &tto->bgpinfo.pbb);
      break;

    default:
      assert (0);
    }
}