aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/gbp/gbp.c
blob: 0b87d0b4d89527f9452d4e361c1ca597b85aca9c (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
/*
 * gbp.h : Group Based Policy
 *
 * Copyright (c) 2013 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <plugins/gbp/gbp.h>

/**
 * IP4 destintion address to destination EPG mapping table
 */
typedef struct gbp_ip4_to_epg_db_t_
{
  /**
   * use a simple hash table
   */
  uword *g4ie_hash;
} gbp_ip4_to_epg_db_t;

static gbp_ip4_to_epg_db_t gbp_ip4_to_epg_db;

/**
 * IP6 destintion address to destination EPG mapping table
 */
typedef struct gbp_ip6_to_epg_db_t_
{
  /**
   * use a memroy hash table
   */
  uword *g6ie_hash;
} gbp_ip6_to_epg_db_t;

static gbp_ip6_to_epg_db_t gbp_ip6_to_epg_db;

/**
 * Result of a interface to EPG mapping.
 * multiple Endpoints can occur on the same interface, so this
 * mapping needs to be reference counted.
 */
typedef struct gbp_itf_t_
{
  epg_id_t gi_epg;
  u32 gi_ref_count;
} gbp_itf_t;

const static gbp_itf_t ITF_INVALID = {
  .gi_epg = EPG_INVALID,
  .gi_ref_count = 0,
};

/**
 * Interface to source EPG DB - a per-interface vector
 */
typedef struct gbp_itf_to_epg_db_t_
{
  gbp_itf_t *gte_vec;
} gbp_itf_to_epg_db_t;

static gbp_itf_to_epg_db_t gbp_itf_to_epg_db;

/**
 * Pool of GBP endpoints
 */
static gbp_endpoint_t *gbp_endpoint_pool;

/**
 * DB of endpoints
 */
static uword *gbp_endpoint_db;

/**
 * EPG src,dst pair to ACL mapping table, aka contract DB
 */
typedef struct gbp_contract_db_t_
{
  /**
   * We can form a u64 key from the pair, so use a simple hash table
   */
  uword *gc_hash;
} gbp_contract_db_t;

/**
 * Since contract DB instance
 */
static gbp_contract_db_t gbp_contract_db;

static void
gbp_ip_epg_update (const ip46_address_t * ip, epg_id_t epg_id)
{
  /*
   * we are dealing only with addresses here so this limited
   * is_ip4 check is ok
   */
  if (ip46_address_is_ip4 (ip))
    {
      hash_set (gbp_ip4_to_epg_db.g4ie_hash, ip->ip4.as_u32, epg_id);
    }
  else
    {
      hash_set_mem (gbp_ip6_to_epg_db.g6ie_hash, &ip->ip6, epg_id);
    }
}

static void
gbp_ip_epg_delete (const ip46_address_t * ip)
{
  if (ip46_address_is_ip4 (ip))
    {
      hash_unset (gbp_ip4_to_epg_db.g4ie_hash, ip->ip4.as_u32);
    }
  else
    {
      hash_unset_mem (gbp_ip6_to_epg_db.g6ie_hash, &ip->ip6);
    }
}

static void
gbp_itf_epg_update (u32 sw_if_index, epg_id_t src_epg)
{
  vec_validate_init_empty (gbp_itf_to_epg_db.gte_vec,
			   sw_if_index, ITF_INVALID);

  if (0 == gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_ref_count)
    {
      vnet_feature_enable_disable ("ip4-unicast", "gbp4",
				   sw_if_index, 1, NULL, 0);
      vnet_feature_enable_disable ("ip6-unicast", "gbp6",
				   sw_if_index, 1, NULL, 0);
    }
  gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_epg = src_epg;
  gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_ref_count++;
}

static void
gbp_itf_epg_delete (u32 sw_if_index)
{
  if (vec_len (gbp_itf_to_epg_db.gte_vec) <= sw_if_index)
    return;

  if (1 == gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_ref_count)
    {
      gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_epg = EPG_INVALID;

      vnet_feature_enable_disable ("ip4-unicast", "gbp4",
				   sw_if_index, 0, NULL, 0);
      vnet_feature_enable_disable ("ip6-unicast", "gbp6",
				   sw_if_index, 0, NULL, 0);
    }
  gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_ref_count--;
}

void
gbp_endpoint_update (u32 sw_if_index,
		     const ip46_address_t * ip, epg_id_t epg_id)
{
  gbp_endpoint_key_t key = {
    .gek_ip = *ip,
    .gek_sw_if_index = sw_if_index,
  };
  gbp_endpoint_t *gbpe;
  uword *p;

  p = hash_get_mem (gbp_endpoint_db, &key);

  if (p)
    {
      gbpe = pool_elt_at_index (gbp_endpoint_pool, p[0]);
    }
  else
    {
      pool_get (gbp_endpoint_pool, gbpe);

      gbpe->ge_key = clib_mem_alloc (sizeof (gbp_endpoint_key_t));
      clib_memcpy (gbpe->ge_key, &key, sizeof (gbp_endpoint_key_t));

      hash_set_mem (gbp_endpoint_db, gbpe->ge_key, gbpe - gbp_endpoint_pool);
    }

  gbpe->ge_epg_id = epg_id;

  gbp_itf_epg_update (gbpe->ge_key->gek_sw_if_index, gbpe->ge_epg_id);
  gbp_ip_epg_update (&gbpe->ge_key->gek_ip, gbpe->ge_epg_id);
}

void
gbp_endpoint_delete (u32 sw_if_index, const ip46_address_t * ip)
{
  gbp_endpoint_key_t key = {
    .gek_ip = *ip,
    .gek_sw_if_index = sw_if_index,
  };
  gbp_endpoint_t *gbpe;
  uword *p;

  p = hash_get_mem (gbp_endpoint_db, &key);

  if (p)
    {
      gbpe = pool_elt_at_index (gbp_endpoint_pool, p[0]);

      hash_unset_mem (gbp_endpoint_db, gbpe->ge_key);

      gbp_itf_epg_delete (gbpe->ge_key->gek_sw_if_index);
      gbp_ip_epg_delete (&gbpe->ge_key->gek_ip);

      clib_mem_free (gbpe->ge_key);

      pool_put (gbp_endpoint_pool, gbpe);
    }
}

void
gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx)
{
  gbp_endpoint_t *gbpe;

  /* *INDENT-OFF* */
  pool_foreach(gbpe, gbp_endpoint_pool,
  {
    if (!cb(gbpe, ctx))
      break;
  });
  /* *INDENT-ON* */
}

void
gbp_contract_update (epg_id_t src_epg, epg_id_t dst_epg, u32 acl_index)
{
  gbp_contract_key_t key = {
    .gck_src = src_epg,
    .gck_dst = dst_epg,
  };

  hash_set (gbp_contract_db.gc_hash, key.as_u64, acl_index);
}

void
gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg)
{
  gbp_contract_key_t key = {
    .gck_src = src_epg,
    .gck_dst = dst_epg,
  };

  hash_unset (gbp_contract_db.gc_hash, key.as_u64);
}

void
gbp_contract_walk (gbp_contract_cb_t cb, void *ctx)
{
  gbp_contract_key_t key;
  u32 acl_index;

  /* *INDENT-OFF* */
  hash_foreach(key.as_u64, acl_index, gbp_contract_db.gc_hash,
  ({
    gbp_contract_t gbpc = {
      .gc_key = key,
      .gc_acl_index = acl_index,
    };

    if (!cb(&gbpc, ctx))
      break;
  }));
  /* *INDENT-ON* */
}

static clib_error_t *
gbp_endpoint_cli (vlib_main_t * vm,
		  unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vnet_main_t *vnm = vnet_get_main ();
  epg_id_t epg_id = EPG_INVALID;
  ip46_address_t ip = { };
  u32 sw_if_index = ~0;
  u8 add = 1;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "%U", unformat_vnet_sw_interface,
		    vnm, &sw_if_index))
	;
      else if (unformat (input, "add"))
	add = 1;
      else if (unformat (input, "del"))
	add = 0;
      else if (unformat (input, "epg %d", &epg_id))
	;
      else if (unformat (input, "ip %U", unformat_ip4_address, &ip.ip4))
	;
      else if (unformat (input, "ip %U", unformat_ip6_address, &ip.ip6))
	;
      else
	break;
    }

  if (~0 == sw_if_index)
    return clib_error_return (0, "interface must be specified");
  if (EPG_INVALID == epg_id)
    return clib_error_return (0, "EPG-ID must be specified");
  if (ip46_address_is_zero (&ip))
    return clib_error_return (0, "IP address must be specified");

  if (add)
    gbp_endpoint_update (sw_if_index, &ip, epg_id);
  else
    gbp_endpoint_delete (sw_if_index, &ip);

  return (NULL);
}

static clib_error_t *
gbp_contract_cli (vlib_main_t * vm,
		  unformat_input_t * input, vlib_cli_command_t * cmd)
{
  epg_id_t src_epg_id = EPG_INVALID, dst_epg_id = EPG_INVALID;
  u32 acl_index = ~0;
  u8 add = 1;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "add"))
	add = 1;
      else if (unformat (input, "del"))
	add = 0;
      else if (unformat (input, "src-epg %d", &src_epg_id))
	;
      else if (unformat (input, "dst-epg %d", &dst_epg_id))
	;
      else if (unformat (input, "acl-index %d", &acl_index))
	;
      else
	break;
    }

  if (EPG_INVALID == src_epg_id)
    return clib_error_return (0, "Source EPG-ID must be specified");
  if (EPG_INVALID == dst_epg_id)
    return clib_error_return (0, "Destination EPG-ID must be specified");

  if (add)
    {
      gbp_contract_update (src_epg_id, dst_epg_id, acl_index);
    }
  else
    {
      gbp_contract_delete (src_epg_id, dst_epg_id);
    }

  return (NULL);
}

/*?
 * Configure a GBP Endpoint
 *
 * @cliexpar
 * @cliexstart{set gbp endpoint [del] <interface> epg <ID> ip <IP>}
 * @cliexend
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (gbp_endpoint_cli_node, static) = {
  .path = "gbp endpoint",
  .short_help = "gbp endpoint [del] <interface> epg <ID> ip <IP>",
  .function = gbp_endpoint_cli,
};

/*?
 * Configure a GBP Contract
 *
 * @cliexpar
 * @cliexstart{set gbp contract [del] src-epg <ID> dst-epg <ID> acl-index <ACL>}
 * @cliexend
 ?*/
VLIB_CLI_COMMAND (gbp_contract_cli_node, static) = {
  .path = "gbp contract",
  .short_help = "gbp contract [del] src-epg <ID> dst-epg <ID> acl-index <ACL>",
  .function = gbp_contract_cli,
};
/* *INDENT-ON* */

static int
gbp_endpoint_show_one (gbp_endpoint_t * gbpe, void *ctx)
{
  vnet_main_t *vnm = vnet_get_main ();
  vlib_main_t *vm;

  vm = ctx;
  vlib_cli_output (vm, "  {%U, %U} -> %d",
		   format_vnet_sw_if_index_name, vnm,
		   gbpe->ge_key->gek_sw_if_index,
		   format_ip46_address, &gbpe->ge_key->gek_ip, IP46_TYPE_ANY,
		   gbpe->ge_epg_id);

  return (1);
}

static clib_error_t *
gbp_endpoint_show (vlib_main_t * vm,
		   unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vnet_main_t *vnm = vnet_get_main ();
  ip46_address_t ip, *ipp;
  epg_id_t epg_id;
  u32 sw_if_index;

  vlib_cli_output (vm, "Endpoints:");
  gbp_endpoint_walk (gbp_endpoint_show_one, vm);

  vlib_cli_output (vm, "\nSource interface to EPG:");

  vec_foreach_index (sw_if_index, gbp_itf_to_epg_db.gte_vec)
  {
    if (EPG_INVALID != gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_epg)
      {
	vlib_cli_output (vm, "  %U -> %d",
			 format_vnet_sw_if_index_name, vnm, sw_if_index,
			 gbp_itf_to_epg_db.gte_vec[sw_if_index].gi_epg);
      }
  }

  vlib_cli_output (vm, "\nDestination IP4 to EPG:");

  /* *INDENT-OFF* */
  hash_foreach (ip.ip4.as_u32, epg_id, gbp_ip4_to_epg_db.g4ie_hash,
  {
    vlib_cli_output (vm, "  %U -> %d", format_ip46_address, &ip,
                     IP46_TYPE_IP4, epg_id);
  });
  /* *INDENT-ON* */

  vlib_cli_output (vm, "\nDestination IP6 to EPG:");

  /* *INDENT-OFF* */
  hash_foreach_mem (ipp, epg_id, gbp_ip6_to_epg_db.g6ie_hash,
  {
    vlib_cli_output (vm, "  %U -> %d", format_ip46_address, ipp,
                     IP46_TYPE_IP6, epg_id);
  });
  /* *INDENT-ON* */

  return (NULL);
}

static clib_error_t *
gbp_contract_show (vlib_main_t * vm,
		   unformat_input_t * input, vlib_cli_command_t * cmd)
{
  gbp_contract_key_t key;
  epg_id_t epg_id;

  vlib_cli_output (vm, "Contracts:");

  /* *INDENT-OFF* */
  hash_foreach (key.as_u64, epg_id, gbp_contract_db.gc_hash,
  {
    vlib_cli_output (vm, "  {%d,%d} -> %d", key.gck_src,
                     key.gck_dst, epg_id);
  });
  /* *INDENT-ON* */

  return (NULL);
}

/*?
 * Show Group Based Policy Endpoints and derived information
 *
 * @cliexpar
 * @cliexstart{show gbp endpoint}
 * @cliexend
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (gbp_endpoint_show_node, static) = {
  .path = "show gbp endpoint",
  .short_help = "show gbp endpoint\n",
  .function = gbp_endpoint_show,
};
/* *INDENT-ON* */

/*?
 * Show Group Based Policy Contracts
 *
 * @cliexpar
 * @cliexstart{show gbp contract}
 * @cliexend
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (gbp_contract_show_node, static) = {
  .path = "show gbp contract",
  .short_help = "show gbp contract\n",
  .function = gbp_contract_show,
};
/* *INDENT-ON* */

#define foreach_gbp                    \
  _(DENY,    "deny")

typedef enum
{
#define _(sym,str) GBP_ERROR_##sym,
  foreach_gbp
#undef _
    GBP_N_ERROR,
} gbp_error_t;

static char *gbp_error_strings[] = {
#define _(sym,string) string,
  foreach_gbp
#undef _
};

typedef enum
{
#define _(sym,str) GBP_NEXT_##sym,
  foreach_gbp
#undef _
    GBP_N_NEXT,
} gbp_next_t;

/**
 * per-packet trace data
 */
typedef struct gbp_trace_t_
{
  /* per-pkt trace data */
  epg_id_t src_epg;
  epg_id_t dst_epg;
  u32 acl_index;
} gbp_trace_t;

static inline uword
gbp_inline (vlib_main_t * vm,
	    vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6)
{
  u32 n_left_from, *from, *to_next;
  gbp_next_t next_index;

  next_index = 0;
  n_left_from = frame->n_vectors;
  from = vlib_frame_vector_args (frame);

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

      vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  vlib_buffer_t *b0;
	  u32 sw_if_index0;
	  gbp_next_t next0;
	  u32 bi0;
	  ip4_header_t *ip4_0;
	  ip6_header_t *ip6_0;
	  gbp_contract_key_t key0;
	  u32 acl_index0;
	  uword *p;

	  bi0 = from[0];
	  to_next[0] = bi0;
	  from += 1;
	  to_next += 1;
	  n_left_from -= 1;
	  n_left_to_next -= 1;

	  /* deny by default */
	  next0 = GBP_NEXT_DENY;

	  b0 = vlib_get_buffer (vm, bi0);
	  if (is_ip6)
	    ip6_0 = vlib_buffer_get_current (b0);
	  else
	    ip4_0 = vlib_buffer_get_current (b0);
	  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];

	  /*
	   * determine the src and dst EPG
	   */
	  key0.gck_src = gbp_itf_to_epg_db.gte_vec[sw_if_index0].gi_epg;

	  if (is_ip6)
	    p = hash_get_mem (gbp_ip6_to_epg_db.g6ie_hash,
			      &ip6_0->dst_address);
	  else
	    p = hash_get (gbp_ip4_to_epg_db.g4ie_hash,
			  ip4_0->dst_address.as_u32);

	  if (NULL != p)
	    {
	      key0.gck_dst = p[0];

	      /*
	       * If the src and dst are the same, then let it through
	       */
	      if (key0.gck_dst == key0.gck_src)
		{
		  vnet_feature_next (sw_if_index0, &next0, b0);
		  acl_index0 = ~0;
		}
	      else
		{
		  /*
		   * find this src,dst pair in the egp->acl DB
		   */
		  p = hash_get (gbp_contract_db.gc_hash, key0.as_u64);

		  if (NULL != p)
		    {
		      acl_index0 = p[0];

		      /*
		       * the ACL index stored is NULL, this means any-any so let it pass
		       */
		      if (~0 == acl_index0)
			{
			  vnet_feature_next (sw_if_index0, &next0, b0);
			}
		      else
			{
			  /*
			   * TODO tests against the ACL
			   */
			  /*
			   * ACL tables are not available outside of ACL plugin
			   * until then bypass the ACL to next node
			   */
			  vnet_feature_next (sw_if_index0, &next0, b0);
			}
		    }
		  else
		    {
		      /*
		       * no ACL to apply for packets between these two EPGs.
		       * GBP is a whitelist model, so no ACL implies deny, which
		       * is the default result
		       */
		      acl_index0 = ~0;
		    }
		}
	    }
	  else
	    {
	      /*
	       * cannot determine the destinaiotn EPG, so we cannot enforce policy
	       * on this node. permit.
	       */
	      vnet_feature_next (sw_if_index0, &next0, b0);

	      key0.gck_dst = ~0;
	      acl_index0 = ~0;
	    }

	  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
			     (b0->flags & VLIB_BUFFER_IS_TRACED)))
	    {
	      gbp_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
	      t->src_epg = key0.gck_src;
	      t->dst_epg = key0.gck_dst;
	      t->acl_index = acl_index0;
	    }

	  /* verify speculative enqueue, maybe switch current next frame */
	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, next0);
	}

      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }

  return frame->n_vectors;
}

/* packet trace format function */
static u8 *
format_gbp_trace (u8 * s, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
  gbp_trace_t *t = va_arg (*args, gbp_trace_t *);

  s = format (s, "gbp: src:%d dst:%d acl:%d",
	      t->src_epg, t->dst_epg, t->acl_index);

  return s;
}

static inline uword
gbp_4 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  return (gbp_inline (vm, node, frame, 0));
}

static inline uword
gbp_6 (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  return (gbp_inline (vm, node, frame, 1));
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (gbp_4_node) = {
  .function = gbp_4,
  .name = "gbp4",
  .vector_size = sizeof (u32),
  .format_trace = format_gbp_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,

  .n_errors = ARRAY_LEN(gbp_error_strings),
  .error_strings = gbp_error_strings,

  .n_next_nodes = GBP_N_NEXT,

  .next_nodes = {
    [GBP_NEXT_DENY] = "ip4-drop",
  },
};

VLIB_NODE_FUNCTION_MULTIARCH (gbp_4_node, gbp_4);

VNET_FEATURE_INIT (gbp_4_node, static) = {
    .arc_name = "ip4-unicast",
    .node_name = "gbp4",
    .runs_after = VNET_FEATURES ("acl-plugin-in-ip4-fa"),
};

VLIB_REGISTER_NODE (gbp_6_node) = {
  .function = gbp_6,
  .name = "gbp6",
  .vector_size = sizeof (u32),
  .format_trace = format_gbp_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,

  .n_errors = ARRAY_LEN(gbp_error_strings),
  .error_strings = gbp_error_strings,

  .n_next_nodes = GBP_N_NEXT,

  .next_nodes = {
    [GBP_NEXT_DENY] = "ip6-drop",
  },
};

VLIB_NODE_FUNCTION_MULTIARCH (gbp_6_node, gbp_6);

VNET_FEATURE_INIT (gbp_6_node, static) = {
    .arc_name = "ip6-unicast",
    .node_name = "gbp6",
    .runs_after = VNET_FEATURES ("acl-plugin-in-ip6-fa"),
};
/* *INDENT-ON* */

static clib_error_t *
gbp_init (vlib_main_t * vm)
{
  gbp_endpoint_db = hash_create_mem (0,
				     sizeof (gbp_endpoint_key_t),
				     sizeof (u32));
  gbp_ip6_to_epg_db.g6ie_hash =
    hash_create_mem (0, sizeof (ip6_address_t), sizeof (u32));
  return 0;
}

VLIB_INIT_FUNCTION (gbp_init);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */